Входные параметры
Параметр | Тип | Описание |
---|---|---|
INVENTORYID |
INTEGER |
|
SOURCESILAGEPACKID |
INTEGER |
|
DESTINATIONSILAGEPACKID |
INTEGER |
|
WEIGHT |
INTEGER |
|
RELATIONID |
INTEGER |
|
MIX |
INTEGER |
|
Выходные параметры
(Нет выходных параметров)
Описание
Перемещение зерна между силосами на помольную партию
Определение
CREATE PROCEDURE SILAGEPACKS_MOVEWEIGHT(
INVENTORYID INTEGER,
SOURCESILAGEPACKID INTEGER,
DESTINATIONSILAGEPACKID INTEGER,
WEIGHT INTEGER,
RELATIONID INTEGER,
MIX INTEGER)
AS
declare variable ssilageid integer;
declare variable sweight integer;
declare variable squalityid integer;
declare variable dsilageid integer;
declare variable dweight integer;
declare variable dfullweight integer;
declare variable dneedupdate integer;
declare variable aqualityid integer;
declare variable asilagequalityid integer;
declare variable savedweight integer;
declare variable tmp_qualityid integer;
begin
SELECT SILAGEQUALITYID FROM SILAGEPACKS WHERE SILAGEPACKID = :DESTINATIONSILAGEPACKID
INTO :ASILAGEQUALITYID;
SAVEDWEIGHT = WEIGHT;
for
SELECT SILAGE.SILAGEID, SILAGE.WEIGHT, SILAGE.FULLWEIGHT
FROM SILAGE
WHERE SILAGEPACKID = :DESTINATIONSILAGEPACKID
INTO :DSILAGEID, :DWEIGHT, :DFULLWEIGHT
do
begin
DNEEDUPDATE = 0;
for
SELECT SILAGE.SILAGEID, SILAGE.WEIGHT
FROM SILAGE
WHERE SILAGEPACKID = :SOURCESILAGEPACKID
INTO :SSILAGEID, :SWEIGHT
do
if (WEIGHT > 0) then
begin
DNEEDUPDATE = 1;
if (DWEIGHT IS NULL) then DWEIGHT = 0;
if (WEIGHT + DWEIGHT < DFULLWEIGHT) then
begin
if (SWEIGHT > WEIGHT) then
if (DFULLWEIGHT - DWEIGHT > WEIGHT) then
begin
DWEIGHT = DWEIGHT + WEIGHT;
SWEIGHT = SWEIGHT - WEIGHT;
WEIGHT = 0;
end
else
begin
WEIGHT = WEIGHT + DWEIGHT - DFULLWEIGHT;
SWEIGHT = SWEIGHT + DWEIGHT - DFULLWEIGHT;
DWEIGHT = DFULLWEIGHT;
end
else
if (DFULLWEIGHT - DWEIGHT > SWEIGHT) then
begin
WEIGHT = WEIGHT - SWEIGHT;
DWEIGHT = DWEIGHT + SWEIGHT;
SWEIGHT = 0;
end
else
begin
WEIGHT = WEIGHT - DWEIGHT;
SWEIGHT = SWEIGHT - DWEIGHT;
DWEIGHT = 0;
end
end
UPDATE SILAGE SET WEIGHT = :SWEIGHT WHERE SILAGEID = :SSILAGEID;
end
if (DNEEDUPDATE = 1) then
BEGIN
UPDATE SILAGEPACKS SET SILAGEQUALITYID = NULL WHERE SILAGEPACKID = :DESTINATIONSILAGEPACKID;
UPDATE SILAGE SET WEIGHT = :DWEIGHT WHERE SILAGEID = :DSILAGEID;
END
end
WEIGHT = SAVEDWEIGHT;
if (ASILAGEQUALITYID is null) then
begin
ASILAGEQUALITYID = GEN_ID(SILAGEQUALITYIDGEN, 1);
AQUALITYID = 0;
end
else AQUALITYID = 1;
--
SELECT QUALITYID FROM SILAGEPACKS
WHERE SILAGEPACKS.SILAGEPACKID = :SOURCESILAGEPACKID
INTO :SQUALITYID;
SELECT QUALITYID FROM SILAGEQUALITY
WHERE SILAGEQUALITYID = :ASILAGEQUALITYID
AND QUALITYID = :SQUALITYID
INTO :TMP_QUALITYID;
IF(TMP_QUALITYID = SQUALITYID) THEN
BEGIN
UPDATE SILAGEQUALITY SET WEIGHT = WEIGHT + :WEIGHT
WHERE SILAGEQUALITYID = :ASILAGEQUALITYID
AND QUALITYID = :SQUALITYID;
END
ELSE
INSERT INTO SILAGEQUALITY (SILAGEQUALITYID, QUALITYID, WEIGHT)
VALUES (:ASILAGEQUALITYID, :SQUALITYID, :WEIGHT);
--
if (MIX = 0) then
UPDATE SILAGEPACKS
SET SILAGEPACKS.SILAGEQUALITYID = null
WHERE SILAGEPACKS.SILAGEPACKID = :DESTINATIONSILAGEPACKID;
--
UPDATE SILAGEPACKS
SET SILAGEPACKS.SILAGEQUALITYID = :ASILAGEQUALITYID, SILAGEPACKS.RECIPEID = :RELATIONID
WHERE SILAGEPACKS.SILAGEPACKID = :DESTINATIONSILAGEPACKID;
SELECT QUALITYID FROM SILAGEPACKS
WHERE SILAGEPACKS.SILAGEPACKID = :DESTINATIONSILAGEPACKID
INTO :AQUALITYID;
if (AQUALITYID = SQUALITYID) then
begin
EXECUTE PROCEDURE QUALITY_COPY(:AQUALITYID) RETURNING_VALUES :AQUALITYID;
end
/* Убрано ввиду сохранения помольной партии в "SILAGEPACKS.RECIPEID"
DELETE FROM QUALITYDATA
WHERE QUALITYID = :AQUALITYID and qualitytypeid = 99; --99 = ID п/п
insert into QUALITYDATA
values (:AQUALITYID, 99, :RELATIONID);*/
--
if (mix = 1) then
begin
SELECT SILAGEPACKS.WEIGHT
FROM SILAGEPACKS
WHERE SILAGEPACKS.SILAGEPACKID = :DESTINATIONSILAGEPACKID
INTO :DWEIGHT;
DELETE FROM SILAGEQUALITY WHERE SILAGEQUALITY.SILAGEQUALITYID = :ASILAGEQUALITYID;
INSERT INTO SILAGEQUALITY values (:ASILAGEQUALITYID, :AQUALITYID, :DWEIGHT);
end
suspend;
END