Описание
(Нет описания для триггера RouteSilChema_CalcsWeight)
Определение
CREATE TRIGGER "RouteSilChema_CalcsWeight" FOR ROUTESILAGECHEMA
ACTIVE BEFORE DELETE POSITION 0
AS
declare variable itClassID Integer;
declare variable OldPersentWeight Integer;
declare variable oldSilageQualityID Integer;
declare variable oldSQID Integer;
declare variable itNet Integer;
declare variable partNet Integer;
begin
for
select
IT.net,
Quality.ClassID,
routesilagechema.percentweight,
SilagePacks.silagequalityid
from IT
join Quality on (IT.samplerqualityid = Quality.qualityid)
join routesilagechema on (IT.routeid = routesilagechema.routechemaid)
join Silage on (routesilagechema.silageid = Silage.silageid)
join silagepacks on (SilagePacks.silagepackid = Silage.silagepackid)
where IT.routeid = old.routechemaid
and IT.state <> -1
and routesilagechema.silageid = old.silageid
and IT.operationid = 5
group by
IT.net,
Quality.ClassID,
routesilagechema.percentweight,
SilagePacks.silagequalityid
into :itNet,
:itclassid,
:oldpersentweight,
:oldsilagequalityid
do begin
-- 1. Увеличить вес в Silage по silageID [Silage.weight = Silage.weight + DELTA ]
partNet = cast( cast(:itNet * :oldpersentweight as numeric (15,2))/ 100 as integer);
update Silage set Silage.Weight = Silage.Weight + :partNet
where Silage.silageid = old.SilageID;
-- 2. Увеличить вес в SilageQuality по silagepackID и качеству
select
SilageQuality.QualityID
from SilageQuality
join Quality on (SilageQuality.QualityID = Quality.QualityID)
where SilageQuality.silagequalityid = :oldsilagequalityid
and Quality.ClassID = :itClassID
into :oldSQID;
update SilageQuality set SilageQuality.weight = SilageQuality.weight + :partNet
where SilageQuality.silagequalityid = :oldSilageQualityID
and SilageQuality.qualityid = :oldSQID;
end
-- exception OOPS;
end