== Descripción ==
Trigger del evento BEFORE UPDATE de [[TABLA:vidquoten2]]
== Composición ==
*[[TABLA:vidquoten1]]
*[[TABLA:vidquoten3]]
*[[VISTA:acomerciales]]
*[[VISTA:clientes]]
*[[PROC:AltaItemPresupuesto]]
*[[PROC:ActualizaItemPresupuesto]]

== Código ==
<small><pre>

CREATE
DEFINER=`sas_admin`@`%`
TRIGGER `fzggestion`.`Actualiza_Item_Presupuesto`
BEFORE UPDATE ON `fzggestion`.`vidquoten2`
FOR EACH ROW
BEGIN
    -- --------------------------------------------------------
    -- Changes on Price, change previous other attributes
    -- --------------------------------------------------------
    IF OLD.VidQuotePrecio = NEW.VidQuotePrecio THEN
        SELECT VidQuoteCliente,VidQuoteACom INTO @Cliente,@AComercial FROM vidquoten1 WHERE vidquoten1.VidQuoteID = OLD.VidQuoteID;
        SELECT CoeficienteAC INTO @CoeficienteAC from acomerciales WHERE acomerciales.Abreviatura = @AComercial;
        SELECT CoeficienteAC,ListaPrecio INTO @CoeficienteCL,@Lista from clientes WHERE clientes.ClienteID = @Cliente;
        CASE
        WHEN NEW.VidQuoteProdID <> OLD.VidQuoteProdID THEN
            -- --------------------------------------------------------
            -- Changes on ProdID, change previous other attributes
            -- --------------------------------------------------------
            DELETE
                FROM vidquoten3
                WHERE
                    vidquoten3.VidQuoteID = OLD.VidQuoteID AND
                    vidquoten3.VidQuoteItem = OLD.VidQuoteItem;
            CALL AltaItemPresupuesto(
                OLD.VidQuoteID,
                @Lista,
                OLD.VidQuoteItem,
                NEW.VidQuoteProdID,
                NEW.VidQuoteProdCantidad,
                NEW.VidQuoteAncho,
                NEW.VidQuoteAlto,
                @CoeficienteCL*@CoeficienteAC);
        WHEN NEW.VidQuoteProdCantidad <> OLD.VidQuoteProdCantidad OR
             NEW.VidQuoteAncho <> OLD.VidQuoteAncho OR
             NEW.VidQuoteAlto <> OLD.VidQuoteAlto THEN
            -- --------------------------------------------------------
            -- Suppose Changes other attributes
            -- --------------------------------------------------------
            CALL ActualizaItemPresupuesto(
                OLD.VidQuoteID,
                OLD.VidQuoteItem,
                NEW.VidQuoteProdCantidad,
                NEW.VidQuoteAncho,
                NEW.VidQuoteAlto,
                @Lista,
                @CoeficienteCL*@CoeficienteAC);
        ELSE
                SET @fly = NULL;
        END CASE;
        SET NEW.VidQuotePrecio = 
            (SELECT SUM(VidQuotePrecioP) AS VidQuotePrecioP
            FROM
                vidquoten3
            WHERE
                vidquoten3.VidQuoteID = OLD.VidQuoteID AND
                vidquoten3.VidQuoteItem = OLD.VidQuoteItem
            GROUP BY
                VidQuoteID,VidQuoteItem);
    END IF;
END$$
</pre></small>

== Bitácora ==
*20120925
**Lanzamiento debido a nuevo diseño de FORM:Presupuesto.
== Uso ==
*[[FORM:Presupuesto]]