Входные параметры
Параметр | Тип | Описание |
---|---|---|
REGDATEB |
DATE |
|
REGDATEE |
DATE |
|
OPERATIONID |
INTEGER |
|
STORAGEIN |
VARCHAR(50) |
|
TRANSPORTSUBTYPE |
INTEGER |
|
DELETEDRECORDSSHOW |
INTEGER |
|
NOTWEIGHTEDSHOW |
INTEGER |
|
REMOTERECORDSSHOW |
INTEGER |
|
Выходные параметры
Параметр | Тип | Описание |
---|---|---|
REGDATE |
DATE |
|
GROSS |
INTEGER |
|
TARE |
INTEGER |
|
NET |
INTEGER |
|
INVOICEID |
INTEGER |
|
INVOICENUMBER |
VARCHAR(31) |
|
INVOICEDATE |
DATE |
|
INVOICEGROSS |
INTEGER |
|
INVOICETARE |
INTEGER |
|
INVOICENET |
INTEGER |
|
DISCREPANCY |
INTEGER |
|
STATIONID |
INTEGER |
|
CLIENTID |
INTEGER |
|
CLIENTNAME |
VARCHAR(100) |
|
OWNERID |
INTEGER |
|
OWNERNAME |
VARCHAR(100) |
|
SENDERID |
INTEGER |
|
SENDERNAME |
VARCHAR(100) |
|
DRIVERS |
VARCHAR(30) |
|
ORDERLOADID |
INTEGER |
|
CONTRACTID |
INTEGER |
|
CARINVOICEGROSS |
INTEGER |
|
CARINVOICETARE |
INTEGER |
|
CARINVOICENET |
INTEGER |
|
TRAILERINVOICEGROSS |
INTEGER |
|
TRAILERINVOICETARE |
INTEGER |
|
TRAILERINVOICENET |
INTEGER |
|
CARINVENTORYID |
INTEGER |
|
TRAILERINVENTORYID |
INTEGER |
|
CARNUMBER |
VARCHAR(31) |
|
TRAILERNUMBER |
VARCHAR(31) |
|
TRANSPORTNUMBER |
VARCHAR(62) |
|
CARSAMPLERQUALITYID |
INTEGER |
|
TRAILERSAMPLERQUALITYID |
INTEGER |
|
CARORDERLOADITEMID |
INTEGER |
|
TRAILERORDERLOADITEMID |
INTEGER |
|
CARCROPID |
INTEGER |
|
CARCLASSID |
INTEGER |
|
CARSORTID |
INTEGER |
|
TRAILERCROPID |
INTEGER |
|
TRAILERCLASSID |
INTEGER |
|
TRAILERSORTID |
INTEGER |
|
CARCROP |
VARCHAR(150) |
|
TRAILERCROP |
VARCHAR(150) |
|
CROPM |
VARCHAR(300) |
|
CARGROSS |
INTEGER |
|
TRAILERGROSS |
INTEGER |
|
CARTARE |
INTEGER |
|
TRAILERTARE |
INTEGER |
|
CARNET |
INTEGER |
|
TRAILERNET |
INTEGER |
|
CARWEIGHT |
INTEGER |
|
TRAILERWEIGHT |
INTEGER |
|
WEIGHT |
INTEGER |
|
CARSTORAGEID |
INTEGER |
|
TRAILERSTORAGEID |
INTEGER |
|
CARROUTEID |
INTEGER |
|
TRAILERROUTEID |
INTEGER |
|
STORAGENAME |
VARCHAR(120) |
|
CARSTORAGENAME |
VARCHAR(60) |
|
TRAILERSTORAGENAME |
VARCHAR(60) |
|
CARSILAGEID |
INTEGER |
|
TRAILERSILAGEID |
INTEGER |
|
SILAGENAME |
VARCHAR(60) |
|
CARSILAGENAME |
VARCHAR(30) |
|
TRAILERSILAGENAME |
VARCHAR(30) |
|
CARWEIGHTNUMBER |
INTEGER |
|
TRAILERWEIGHTNUMBER |
INTEGER |
|
WEIGHTNUMBERN |
INTEGER |
|
CARBARCODE |
VARCHAR(30) |
|
TRAILERBARCODE |
VARCHAR(30) |
|
CARSTATE |
INTEGER |
|
TRAILERSTATE |
INTEGER |
|
CARTRANSPORTTYPEID |
INTEGER |
|
TRAILERTRANSPORTTYPEID |
INTEGER |
|
CARGROSSTIME |
TIMESTAMP |
|
CARTARETIME |
TIMESTAMP |
|
TRAILERGROSSTIME |
TIMESTAMP |
|
TRAILERTARETIME |
TIMESTAMP |
|
CARGROSSBYHAND |
INTEGER |
|
CARTAREBYHAND |
INTEGER |
|
TRAILERGROSSBYHAND |
INTEGER |
|
TRAILERTAREBYHAND |
INTEGER |
|
CARLABQUALITYID |
INTEGER |
|
TRAILERLABQUALITYID |
INTEGER |
|
WEIGHTUSERID |
INTEGER |
|
PARENTID |
INTEGER |
|
DELETION |
INTEGER |
|
WASTEACTNUMBER |
INTEGER |
|
SHIFT |
INTEGER |
|
FORWARDERID |
INTEGER |
|
EXPORTERID |
INTEGER |
|
Описание
(Нет описания для процедуры WEIGHER)
Определение
CREATE PROCEDURE WEIGHER(
REGDATEB DATE,
REGDATEE DATE,
OPERATIONID INTEGER,
STORAGEIN VARCHAR(50),
TRANSPORTSUBTYPE INTEGER,
DELETEDRECORDSSHOW INTEGER,
NOTWEIGHTEDSHOW INTEGER,
REMOTERECORDSSHOW INTEGER)
RETURNS (
REGDATE DATE,
GROSS INTEGER,
TARE INTEGER,
NET INTEGER,
INVOICEID INTEGER,
INVOICENUMBER VARCHAR(31),
INVOICEDATE DATE,
INVOICEGROSS INTEGER,
INVOICETARE INTEGER,
INVOICENET INTEGER,
DISCREPANCY INTEGER,
STATIONID INTEGER,
CLIENTID INTEGER,
CLIENTNAME VARCHAR(100),
OWNERID INTEGER,
OWNERNAME VARCHAR(100),
SENDERID INTEGER,
SENDERNAME VARCHAR(100),
DRIVERS VARCHAR(30),
ORDERLOADID INTEGER,
CONTRACTID INTEGER,
CARINVOICEGROSS INTEGER,
CARINVOICETARE INTEGER,
CARINVOICENET INTEGER,
TRAILERINVOICEGROSS INTEGER,
TRAILERINVOICETARE INTEGER,
TRAILERINVOICENET INTEGER,
CARINVENTORYID INTEGER,
TRAILERINVENTORYID INTEGER,
CARNUMBER VARCHAR(31),
TRAILERNUMBER VARCHAR(31),
TRANSPORTNUMBER VARCHAR(62),
CARSAMPLERQUALITYID INTEGER,
TRAILERSAMPLERQUALITYID INTEGER,
CARORDERLOADITEMID INTEGER,
TRAILERORDERLOADITEMID INTEGER,
CARCROPID INTEGER,
CARCLASSID INTEGER,
CARSORTID INTEGER,
TRAILERCROPID INTEGER,
TRAILERCLASSID INTEGER,
TRAILERSORTID INTEGER,
CARCROP VARCHAR(150),
TRAILERCROP VARCHAR(150),
CROPM VARCHAR(300),
CARGROSS INTEGER,
TRAILERGROSS INTEGER,
CARTARE INTEGER,
TRAILERTARE INTEGER,
CARNET INTEGER,
TRAILERNET INTEGER,
CARWEIGHT INTEGER,
TRAILERWEIGHT INTEGER,
WEIGHT INTEGER,
CARSTORAGEID INTEGER,
TRAILERSTORAGEID INTEGER,
CARROUTEID INTEGER,
TRAILERROUTEID INTEGER,
STORAGENAME VARCHAR(120),
CARSTORAGENAME VARCHAR(60),
TRAILERSTORAGENAME VARCHAR(60),
CARSILAGEID INTEGER,
TRAILERSILAGEID INTEGER,
SILAGENAME VARCHAR(60),
CARSILAGENAME VARCHAR(30),
TRAILERSILAGENAME VARCHAR(30),
CARWEIGHTNUMBER INTEGER,
TRAILERWEIGHTNUMBER INTEGER,
WEIGHTNUMBERN INTEGER,
CARBARCODE VARCHAR(30),
TRAILERBARCODE VARCHAR(30),
CARSTATE INTEGER,
TRAILERSTATE INTEGER,
CARTRANSPORTTYPEID INTEGER,
TRAILERTRANSPORTTYPEID INTEGER,
CARGROSSTIME TIMESTAMP,
CARTARETIME TIMESTAMP,
TRAILERGROSSTIME TIMESTAMP,
TRAILERTARETIME TIMESTAMP,
CARGROSSBYHAND INTEGER,
CARTAREBYHAND INTEGER,
TRAILERGROSSBYHAND INTEGER,
TRAILERTAREBYHAND INTEGER,
CARLABQUALITYID INTEGER,
TRAILERLABQUALITYID INTEGER,
WEIGHTUSERID INTEGER,
PARENTID INTEGER,
DELETION INTEGER,
WASTEACTNUMBER INTEGER,
SHIFT INTEGER,
FORWARDERID INTEGER,
EXPORTERID INTEGER)
AS
declare variable AREGDATE date;
declare variable AINVOICEID integer;
declare variable AINVENTORYID integer;
declare variable APROVIDERID integer;
declare variable AOWNERID integer;
declare variable ATRANSPORTNUMBER varchar(31);
declare variable AORDERLOADITEMID integer;
declare variable ASAMPLERQUALITYID integer;
declare variable ALABQUALITYID integer;
declare variable ACLASSID integer;
declare variable ACROPNAME varchar(80);
declare variable AGROSS integer;
declare variable ATARE integer;
declare variable ANET integer;
declare variable AWEIGHT integer;
declare variable AGROSSTIME timestamp;
declare variable ATARETIME timestamp;
declare variable ASTORAGEID integer;
declare variable ASILAGEID integer;
declare variable AROUTEID integer;
declare variable ASTORINGID integer;
declare variable ASTORAGENAME varchar(60);
declare variable ASILAGENAME varchar(30);
declare variable AWEIGHTNUMBER integer;
declare variable ABARCODE varchar(30);
declare variable ASTATE integer;
declare variable ATRANSPORTTYPEID integer;
declare variable AINVOICEGROSS integer;
declare variable AINVOICETARE integer;
declare variable AINVOICENET integer;
declare variable AGROSSBYHAND smallint;
declare variable ATAREBYHAND smallint;
declare variable AWEIGHTUSERID integer;
declare variable APARENTID integer;
declare variable AUWORDERID integer;
declare variable ASTEP integer;
declare variable ARELATIONID integer;
declare variable ASHIFT integer;
begin
/* Procedure Text */
INVOICEID = -1;
for
execute statement
'select cast(1 as integer), IT1.REGDATE, IT1.INVOICEID, IT1.INVENTORYID, IT1.RELATIONID,
IT1.PROVIDERID, IT1.OWNERID, (IT1.GROSS - coalesce(ITTRANSPORT.SAMPLERWEIGHT,0)),
IT1.TARE, (IT1.NET - coalesce(ITTRANSPORT.SAMPLERWEIGHT,0)), IT1.WEIGHT,
IT1.GROSSTIME, IT1.TARETIME, IT1.CONTRACTID, IT1.ORDERLOADITEMID, IT1.SAMPLERQUALITYID,
IT1.LABQUALITYID, IT1.STORAGEID, IT1.SILAGEID, IT1.ROUTEID, IT1.STORINGID,
IT1.WEIGHTNUMBER, IT1.STATE, IT1.WEIGHTUSERID, IT1.PARENTID, IT1.UWORDERID,
ITTRANSPORT.TRANSPORTNUMBER, ITTRANSPORT.BARCODE, ITTRANSPORT.TRANSPORTTYPEID,
ITTRANSPORT.INVOICEGROSS, ITTRANSPORT.INVOICETARE, ITTRANSPORT.INVOICENET,
ITTRANSPORT.GROSSBYHAND, ITTRANSPORT.TAREBYHAND, ITTRANSPORT.WEIGHTSESSION
from IT IT1
left join ITTRANSPORT on (ITTRANSPORT.INVENTORYID = IT1.INVENTORYID)
left join TRANSPORTTYPE on (TRANSPORTTYPE.TRANSPORTTYPEID = ITTRANSPORT.TRANSPORTTYPEID)
left join IT IT2 on (IT2.INVENTORYID = IT1.PARENTID)
where (IT1.OPERATIONID = ' || cast(:OPERATIONID as varchar(5)) || ')
and ((IT1.STORAGEID in (' || :STORAGEIN || ')) or (IT1.STORAGEID is null))
and ((IT1.PARENTID <= 0) or ((IT1.PARENTID > 0) and (IT2.PARENTID = 0)))
and (TRANSPORTTYPE.TRANSPORTSUBTYPE = ' || cast(:TRANSPORTSUBTYPE as varchar(5)) || ')
and (((IT1.REGDATE between ''' || cast(coalesce((:REGDATEB - 7),'01.01.1900') as varchar(15)) || ''' and ''' || cast(coalesce(:REGDATEE,'31.12.9999') as varchar(15)) || ''')
and ((((IT1.STATE >= 0) or (IT1.STATE = -5))
and ((IT1.OPERATIONID not in (70,204))
or ((IT1.OPERATIONID in (70,204))
and (IT1.REGDATE between ''' || cast(coalesce(:REGDATEB,'01.01.1900') as varchar(15)) || ''' and ''' || cast(coalesce(:REGDATEE,'31.12.9999') as varchar(15)) || '''))
)
)
or ((' || cast(:DELETEDRECORDSSHOW as varchar(5)) || ' = 1) and (IT1.STATE = -1)
and (IT1.REGDATE between ''' || cast(coalesce(:REGDATEB,'01.01.1900') as varchar(15)) || ''' and ''' || cast(coalesce(:REGDATEE,'31.12.9999') as varchar(15)) || ''')
)
or ((' || cast(:REMOTERECORDSSHOW as varchar(5)) || ' = 1) and (IT1.STATE = -3)
and (IT1.REGDATE between ''' || cast(coalesce(:REGDATEB,'01.01.1900') as varchar(15)) || ''' and ''' || cast(coalesce(:REGDATEE,'31.12.9999') as varchar(15)) || ''')
)
/*
or ((IT1.STATE = -100)
and (IT1.REGDATE between ''' || cast(coalesce((:REGDATEB - 120),'01.01.1900') as varchar(15)) || ''' and ''' || cast(coalesce(:REGDATEE,'31.12.9999') as varchar(15)) || ''')
)
*/
)
)
)
union
select cast(2 as integer), cast(null as date), cast(-1000000 as integer), cast(-1000000 as integer), cast(-1000000 as integer),
cast(null as integer), cast(null as integer), cast(null as integer), cast(null as integer), cast(null as integer), cast(null as integer),
cast(null as timestamp), cast(null as timestamp), cast(null as integer), cast(null as integer), cast(null as integer),
cast(null as integer), cast(null as integer), cast(null as integer), cast(null as integer), cast(null as integer),
cast(null as integer), cast(null as integer), cast(null as integer), cast(null as integer), cast(null as integer),
cast(null as varchar(31)), cast(null as varchar(31)), cast(null as integer),
cast(null as integer), cast(null as integer), cast(null as integer),
cast(null as smallint), cast(null as smallint), cast(null as integer)
from rdb$database
order by 1, 3, 4, 22'
into :ASTEP, :AREGDATE, :AINVOICEID, :AINVENTORYID, :ARELATIONID,
:APROVIDERID, :AOWNERID, :AGROSS, :ATARE, :ANET, :AWEIGHT,
:AGROSSTIME, :ATARETIME, :CONTRACTID, :AORDERLOADITEMID, :ASAMPLERQUALITYID,
:ALABQUALITYID, :ASTORAGEID, :ASILAGEID, :AROUTEID, :ASTORINGID,
:AWEIGHTNUMBER, :ASTATE, :AWEIGHTUSERID, :APARENTID, :AUWORDERID,
:ATRANSPORTNUMBER, :ABARCODE, :ATRANSPORTTYPEID,
:AINVOICEGROSS, :AINVOICETARE, :AINVOICENET,
:AGROSSBYHAND, :ATAREBYHAND, :ASHIFT
do begin
if (INVOICEID <> AINVOICEID) then begin
if (INVOICEID <> -1) then begin
if (PARENTID <> -2) then begin
if (((REGDATE between :REGDATEB and :REGDATEE) and
(((NET > 0) or ((GROSS > 0) and (TARE > 0))) or (((CARSTATE is null) or (CARSTATE = -3)) and
((TRAILERSTATE is null) or (TRAILERSTATE = -3)))) or
-- (((CARSTATE is null) or (CARSTATE = -1) or (CARSTATE = -100)) and
(((CARSTATE is null) or (CARSTATE in (-1,-100))) and
-- ((TRAILERSTATE is null) or (TRAILERSTATE = -1) or (TRAILERSTATE = -100)))) or
((TRAILERSTATE is null) or (TRAILERSTATE in (-1,-100))))) or
(((((((GROSS > 0) and (TARE = 0)) or ((TARE > 0) and (GROSS = 0))) and (NET = 0)) or
((GROSS = 0) and (TARE = 0) and (NET = 0) and ((CARSTATE >= 0) or (TRAILERSTATE >= 0)))) and
(:NOTWEIGHTEDSHOW = 1)))) then begin
select INVOICENUMBER, INVOICEDATE, STATIONID, DRIVERS,
S1.CLIENTNAME, S2.CLIENTNAME, SENDERID, S3.CLIENTNAME,
INVOICES.FORWARDERID, INVOICES.EXPORTERID
from INVOICES
left join CLIENTS S1 on (S1.CLIENTID = coalesce(INVOICES.MANUFACTURERID,:CLIENTID))
left join CLIENTS S2 on (S2.CLIENTID = :OWNERID)
left join CLIENTS S3 on (S3.CLIENTID = INVOICES.SENDERID)
where (INVOICES.INVOICEID = :INVOICEID)
into :INVOICENUMBER, :INVOICEDATE, :STATIONID, :DRIVERS,
:CLIENTNAME, :OWNERNAME, :SENDERID, :SENDERNAME,
:FORWARDERID, :EXPORTERID;
if (CARINVENTORYID is not null) then begin
select QUALITY.CROPID, QUALITY.CLASSID, QUALITY.SORTID,
cast(coalesce(CROP.CROPNAME,'') || coalesce(' ' || CLASS.CLASSNAME,'') ||
coalesce(' (' || CROPSORT.SORTNAME || ')','') ||
coalesce(' ' || FORAGECROP.CROPNAME,'') ||
coalesce(' ' || FORAGECLASS.CLASSNAME,'') as varchar(80))
from QUALITY
left join CROP on (CROP.CROPID = QUALITY.CROPID)
left join CLASS on (CLASS.CLASSID = QUALITY.CLASSID)
left join CROPSORT on (CROPSORT.SORTID = QUALITY.SORTID)
left join QUALITY_SELECT(:CARSAMPLERQUALITYID) on (0 = 0)
left join CROP FORAGECROP on (FORAGECROP.CROPID = QUALITY_SELECT.FORAGECROPID)
left join CLASS FORAGECLASS on (FORAGECLASS.CLASSID = QUALITY_SELECT.FORAGECLASSID)
where (QUALITY.QUALITYID = :CARSAMPLERQUALITYID)
into :CARCROPID, :CARCLASSID, :CARSORTID, :CARCROP;
CROPM = coalesce(:CARCROP,'');
select ORDERLOADID
from ORDERLOADITEMS
where (ORDERLOADITEMS.ORDERLOADITEMID = :CARORDERLOADITEMID)
into :ORDERLOADID;
select STORAGE.STORAGENAME, SILAGE.NAME
from STORAGE
-- left join ROUTESILAGECHEMA on (ROUTESILAGECHEMA.ROUTESILAGECHEMAID = :CARROUTEID)
-- left join SILAGE on (SILAGE.SILAGEID = ROUTESILAGECHEMA.SILAGEID)
left join SILAGE on (SILAGE.SILAGEID = :CARSILAGEID)
where (STORAGE.STORAGEID = :CARSTORAGEID)
into :CARSTORAGENAME, :CARSILAGENAME;
STORAGENAME = coalesce(:CARSTORAGENAME,'');
SILAGENAME = coalesce(:CARSILAGENAME,'');
end
if (TRAILERINVENTORYID is not null) then begin
if (CARINVENTORYID is null) then begin
select IT.INVENTORYID, (IT.GROSS - coalesce(ITTRANSPORT.SAMPLERWEIGHT,0)),
IT.TARE, (IT.NET - coalesce(ITTRANSPORT.SAMPLERWEIGHT,0)), IT.WEIGHT,
IT.GROSSTIME, IT.TARETIME, IT.ORDERLOADITEMID, IT.SAMPLERQUALITYID,
IT.LABQUALITYID, IT.STORAGEID, IT.SILAGEID, IT.STORINGID, IT.WEIGHTNUMBER, IT.STATE,
ITTRANSPORT.TRANSPORTNUMBER, ITTRANSPORT.BARCODE, ITTRANSPORT.INVOICEGROSS,
ITTRANSPORT.INVOICETARE, ITTRANSPORT.INVOICENET, ITTRANSPORT.GROSSBYHAND, ITTRANSPORT.TAREBYHAND
from IT
left join ITTRANSPORT on (ITTRANSPORT.INVENTORYID = IT.INVENTORYID)
left join TRANSPORTTYPE on (TRANSPORTTYPE.TRANSPORTTYPEID = ITTRANSPORT.TRANSPORTTYPEID)
where (IT.INVOICEID = :INVOICEID) and (ITTRANSPORT.TRANSPORTTYPEID = 0)
into :CARINVENTORYID, :CARGROSS, :CARTARE, :CARNET, :CARWEIGHT,
:CARGROSSTIME, :CARTARETIME, :CARORDERLOADITEMID, :CARSAMPLERQUALITYID,
:CARLABQUALITYID, :CARSTORAGEID, :CARSILAGEID, :CARROUTEID, :CARWEIGHTNUMBER, :CARSTATE,
:CARNUMBER, :CARBARCODE, :CARINVOICEGROSS, :CARINVOICETARE, :CARINVOICENET,
:CARGROSSBYHAND, :CARTAREBYHAND;
select QUALITY.CROPID, QUALITY.CLASSID, QUALITY.SORTID,
cast(coalesce(CROP.CROPNAME,'') || coalesce(' ' || CLASS.CLASSNAME,'') ||
coalesce(' (' || CROPSORT.SORTNAME || ')','') ||
coalesce(' ' || FORAGECROP.CROPNAME,'') ||
coalesce(' ' || FORAGECLASS.CLASSNAME,'') as varchar(80))
from QUALITY
left join CROP on (CROP.CROPID = QUALITY.CROPID)
left join CLASS on (CLASS.CLASSID = QUALITY.CLASSID)
left join CROPSORT on (CROPSORT.SORTID = QUALITY.SORTID)
left join QUALITY_SELECT(:CARSAMPLERQUALITYID) on (0 = 0)
left join CROP FORAGECROP on (FORAGECROP.CROPID = QUALITY_SELECT.FORAGECROPID)
left join CLASS FORAGECLASS on (FORAGECLASS.CLASSID = QUALITY_SELECT.FORAGECLASSID)
where (QUALITY.QUALITYID = :CARSAMPLERQUALITYID)
into :CARCROPID, :CARCLASSID, :CARSORTID, :CARCROP;
CROPM = coalesce(:CARCROP,'');
select ORDERLOADID
from ORDERLOADITEMS
where (ORDERLOADITEMS.ORDERLOADITEMID = :CARORDERLOADITEMID)
into :ORDERLOADID;
select STORAGE.STORAGENAME, SILAGE.NAME
from STORAGE
-- left join ROUTESILAGECHEMA on (ROUTESILAGECHEMA.ROUTESILAGECHEMAID = :CARROUTEID)
-- left join SILAGE on (SILAGE.SILAGEID = ROUTESILAGECHEMA.SILAGEID)
left join SILAGE on (SILAGE.SILAGEID = :CARSILAGEID)
where (STORAGE.STORAGEID = :CARSTORAGEID)
into :CARSTORAGENAME, :CARSILAGENAME;
STORAGENAME = coalesce(:CARSTORAGENAME,'');
SILAGENAME = coalesce(:CARSILAGENAME,'');
end
select QUALITY.CROPID, QUALITY.CLASSID, QUALITY.SORTID,
cast(coalesce(CROP.CROPNAME,'') || coalesce(' ' || CLASS.CLASSNAME,'') ||
coalesce(' (' || CROPSORT.SORTNAME || ')','') ||
coalesce(' ' || FORAGECROP.CROPNAME,'') ||
coalesce(' ' || FORAGECLASS.CLASSNAME,'') as varchar(80))
from QUALITY
left join CROP on (CROP.CROPID = QUALITY.CROPID)
left join CLASS on (CLASS.CLASSID = QUALITY.CLASSID)
left join CROPSORT on (CROPSORT.SORTID = QUALITY.SORTID)
left join QUALITY_SELECT(:CARSAMPLERQUALITYID) on (0 = 0)
left join CROP FORAGECROP on (FORAGECROP.CROPID = QUALITY_SELECT.FORAGECROPID)
left join CLASS FORAGECLASS on (FORAGECLASS.CLASSID = QUALITY_SELECT.FORAGECLASSID)
where (QUALITY.QUALITYID = :TRAILERSAMPLERQUALITYID)
into :TRAILERCROPID, :TRAILERCLASSID, :TRAILERSORTID, :TRAILERCROP;
if (TRAILERCROP is not null) then
if ((CROPM <> TRAILERCROP) or
((CARSTATE is not null) and (TRAILERSTATE is not null) and ((CARSTATE <> TRAILERSTATE) and (TRAILERSTATE <> -5)))) then begin
if (CROPM <> '') then
CROPM = :CROPM || '; ';
CROPM = :CROPM || :TRAILERCROP;
end
if (ORDERLOADID is null) then
select ORDERLOADID
from ORDERLOADITEMS
where (ORDERLOADITEMS.ORDERLOADITEMID = :TRAILERORDERLOADITEMID)
into :ORDERLOADID;
select STORAGE.STORAGENAME, SILAGE.NAME
from STORAGE
-- left join ROUTESILAGECHEMA on (ROUTESILAGECHEMA.ROUTESILAGECHEMAID = :CARROUTEID)
-- left join SILAGE on (SILAGE.SILAGEID = ROUTESILAGECHEMA.SILAGEID)
left join SILAGE on (SILAGE.SILAGEID = :TRAILERSILAGEID)
where (STORAGE.STORAGEID = :TRAILERSTORAGEID)
into :TRAILERSTORAGENAME, :TRAILERSILAGENAME;
if ((STORAGENAME <> TRAILERSTORAGENAME) and (TRAILERSTORAGENAME is not null)) then begin
if (STORAGENAME <> '') then
STORAGENAME = :STORAGENAME || '; ';
STORAGENAME = :STORAGENAME || :TRAILERSTORAGENAME;
end
if ((SILAGENAME <> TRAILERSILAGENAME) and (TRAILERSILAGENAME is not null)) then begin
if (SILAGENAME <> '') then
SILAGENAME = :SILAGENAME || '; ';
SILAGENAME = :SILAGENAME || :TRAILERSILAGENAME;
end
end
if ((CARNUMBER is not null) and (TRAILERNUMBER is not null)) then
TRANSPORTNUMBER = :CARNUMBER || '; ' || :TRAILERNUMBER;
else TRANSPORTNUMBER = coalesce(:CARNUMBER,:TRAILERNUMBER,'');
if ((INVOICENET > 0) and (NET > 0)) then
DISCREPANCY = :NET - :INVOICENET;
WEIGHT = :NET;
WEIGHTNUMBERN = coalesce(:CARWEIGHTNUMBER,:TRAILERWEIGHTNUMBER,0);
suspend;
end
end
else begin
select INVOICENUMBER, INVOICEDATE, STATIONID, DRIVERS,
S1.CLIENTNAME, S2.CLIENTNAME, SENDERID, S3.CLIENTNAME
from INVOICES
left join CLIENTS S1 on (S1.CLIENTID = coalesce(INVOICES.MANUFACTURERID,:CLIENTID))
left join CLIENTS S2 on (S2.CLIENTID = :OWNERID)
left join CLIENTS S3 on (S3.CLIENTID = INVOICES.SENDERID)
where (INVOICES.INVOICEID = :INVOICEID)
into :INVOICENUMBER, :INVOICEDATE, :STATIONID, :DRIVERS,
:CLIENTNAME, :OWNERNAME, :SENDERID, :SENDERNAME;
select STORAGE.STORAGENAME, SILAGE.NAME
from STORAGE
-- left join ROUTESILAGECHEMA on (ROUTESILAGECHEMA.ROUTESILAGECHEMAID = :CARROUTEID)
-- left join SILAGE on (SILAGE.SILAGEID = ROUTESILAGECHEMA.SILAGEID)
left join SILAGE on (SILAGE.SILAGEID = :CARSILAGEID)
where (STORAGE.STORAGEID = :CARSTORAGEID)
into :CARSTORAGENAME, :CARSILAGENAME;
STORAGENAME = coalesce(:CARSTORAGENAME,'');
SILAGENAME = coalesce(:CARSILAGENAME,'');
for
select NET, WEIGHT, WEIGHTNUMBER, PARENTID, ORDERLOADITEMID, IT.STATE, QUALITY.CLASSID,
coalesce(CROP.CROPNAME,'') || coalesce(' ' || CLASS.CLASSNAME,'') || coalesce(' (' || CROPSORT.SORTNAME || ')','')
from IT
left join QUALITY on (QUALITY.QUALITYID = IT.SAMPLERQUALITYID)
left join CROP on (CROP.CROPID = QUALITY.CROPID)
left join CLASS on (CLASS.CLASSID = QUALITY.CLASSID)
left join CROPSORT on (CROPSORT.SORTID = QUALITY.SORTID)
where ((IT.PARENTID = :CARINVENTORYID) and (IT.INVOICEID = :INVOICEID)) and
(((IT.STATE >= 0) and (:DELETEDRECORDSSHOW = 0)) or
((IT.STATE >= -1) and (:DELETEDRECORDSSHOW = 1)))
order by IT.INVOICEID, IT.INVENTORYID
into :CARNET, :CARWEIGHT, :WEIGHTNUMBERN, :PARENTID, :CARORDERLOADITEMID, :CARSTATE, :CARCLASSID,
:CARCROP
do begin
if ((CARNUMBER is not null) and (TRAILERNUMBER is not null)) then
TRANSPORTNUMBER = :CARNUMBER || '; ' || :TRAILERNUMBER;
else TRANSPORTNUMBER = coalesce(:CARNUMBER,:TRAILERNUMBER,'');
NET = :CARNET;
WEIGHT = :CARWEIGHT;
CROPM = :CARCROP;
suspend;
INVOICENUMBER = null;
CLIENTNAME = null;
OWNERNAME = null;
SENDERNAME = null;
CARNUMBER = null;
TRANSPORTNUMBER = null;
STORAGENAME = null;
end
end
end
REGDATE = :AREGDATE;
INVOICEID = :AINVOICEID;
CLIENTID = null;
CLIENTNAME = null;
OWNERID = null;
OWNERNAME = null;
GROSS = 0;
TARE = 0;
NET = 0;
INVOICEGROSS = 0;
INVOICETARE = 0;
INVOICENET = 0;
DISCREPANCY = null;
CROPM = '';
STORAGENAME = null;
WEIGHTUSERID = null;
PARENTID = null;
DELETION = 1;
WASTEACTNUMBER = null;
SHIFT = null;
CARINVENTORYID = null;
CARNUMBER = null;
CARSAMPLERQUALITYID = null;
CARORDERLOADITEMID = null;
CARCROP = null;
CARCLASSID = null;
CARGROSS = null;
CARTARE = null;
CARNET = null;
CARWEIGHT = null;
CARGROSSTIME = null;
CARTARETIME = null;
CARSTORAGEID = null;
CARSTORAGENAME = null;
CARROUTEID = null;
CARSILAGEID = null;
CARSILAGENAME = null;
CARWEIGHTNUMBER = null;
CARBARCODE = null;
CARSTATE = null;
CARTRANSPORTTYPEID = null;
CARINVOICENET = null;
CARINVOICEGROSS = null;
CARINVOICETARE = null;
CARTAREBYHAND = null;
CARGROSSBYHAND = null;
CARLABQUALITYID = null;
TRAILERINVENTORYID = null;
TRAILERNUMBER = null;
TRAILERSAMPLERQUALITYID = null;
TRAILERORDERLOADITEMID = null;
TRAILERCROPID = null;
TRAILERCLASSID = null;
TRAILERCROP = null;
TRAILERGROSS = null;
TRAILERTARE = null;
TRAILERNET = null;
TRAILERWEIGHT = null;
TRAILERGROSSTIME = null;
TRAILERTARETIME = null;
TRAILERSTORAGEID = null;
TRAILERROUTEID = null;
TRAILERSILAGEID = null;
TRAILERSILAGENAME = null;
TRAILERSTORAGENAME = null;
TRAILERWEIGHTNUMBER = null;
TRAILERBARCODE = null;
TRAILERSTATE = null;
TRAILERTRANSPORTTYPEID = null;
TRAILERINVOICENET = null;
TRAILERINVOICEGROSS = null;
TRAILERINVOICETARE = null;
TRAILERGROSSBYHAND = null;
TRAILERTAREBYHAND = null;
TRAILERLABQUALITYID = null;
end
if (ATRANSPORTTYPEID = 1) then begin
TRAILERINVENTORYID = :AINVENTORYID;
TRAILERNUMBER = :ATRANSPORTNUMBER;
TRAILERSAMPLERQUALITYID = :ASAMPLERQUALITYID;
TRAILERORDERLOADITEMID = :AORDERLOADITEMID;
TRAILERCLASSID = :ACLASSID;
TRAILERCROP = :ACROPNAME;
TRAILERGROSS = :AGROSS;
TRAILERTARE = :ATARE;
TRAILERNET = :ANET;
TRAILERWEIGHT = :AWEIGHT;
TRAILERGROSSTIME =:AGROSSTIME;
TRAILERTARETIME = :ATARETIME;
TRAILERSTORAGEID = :ASTORAGEID;
TRAILERROUTEID = :AROUTEID;
TRAILERSILAGEID = :ASILAGEID;
TRAILERSTORAGENAME = :ASTORAGENAME;
TRAILERWEIGHTNUMBER = :AWEIGHTNUMBER;
TRAILERBARCODE = :ABARCODE;
TRAILERSTATE = :ASTATE;
TRAILERTRANSPORTTYPEID = :ATRANSPORTTYPEID;
TRAILERINVOICENET = :AINVOICENET;
TRAILERINVOICEGROSS = :AINVOICEGROSS;
TRAILERINVOICETARE = :AINVOICETARE;
TRAILERGROSSBYHAND = :AGROSSBYHAND;
TRAILERTAREBYHAND = :ATAREBYHAND;
TRAILERLABQUALITYID = :ALABQUALITYID;
if (WEIGHTUSERID is null) then
WEIGHTUSERID = :AWEIGHTUSERID;
end
else begin
CARINVENTORYID = :AINVENTORYID;
CARNUMBER = :ATRANSPORTNUMBER;
CARSAMPLERQUALITYID = :ASAMPLERQUALITYID;
CARORDERLOADITEMID = :AORDERLOADITEMID;
CARCLASSID = :ACLASSID;
CARCROP = :ACROPNAME;
CARGROSS = :AGROSS;
CARTARE = :ATARE;
CARNET = :ANET;
CARWEIGHT = :AWEIGHT;
CARGROSSTIME =:AGROSSTIME;
CARTARETIME = :ATARETIME;
CARSTORAGEID = :ASTORAGEID;
CARROUTEID = :AROUTEID;
CARSILAGEID = :ASILAGEID;
CARSTORAGENAME = :ASTORAGENAME;
CARWEIGHTNUMBER = :AWEIGHTNUMBER;
CARBARCODE = :ABARCODE;
CARSTATE = :ASTATE;
CARTRANSPORTTYPEID = :ATRANSPORTTYPEID;
CARINVOICENET = :AINVOICENET;
CARINVOICEGROSS = :AINVOICEGROSS;
CARINVOICETARE = :AINVOICETARE;
CARGROSSBYHAND = :AGROSSBYHAND;
CARTAREBYHAND = :ATAREBYHAND;
CARLABQUALITYID = :ALABQUALITYID;
WEIGHTUSERID = :AWEIGHTUSERID;
end
if ((CLIENTID is null) or ((CARSTATE < 0) and (ASTATE >= 0))) then
CLIENTID = :APROVIDERID;
if ((OWNERID is null) or ((CARSTATE < 0) and (ASTATE >= 0))) then
OWNERID = :AOWNERID;
if ((ASTATE >= 0) or (:OPERATIONID = 1005)) then begin
GROSS = GROSS + coalesce(:AGROSS,0);
TARE = TARE + coalesce(:ATARE,0);
NET = NET + coalesce(:ANET,0);
INVOICEGROSS = INVOICEGROSS + coalesce(:AINVOICEGROSS,0);
INVOICETARE = INVOICETARE + coalesce(:AINVOICETARE,0);
INVOICENET = INVOICENET + coalesce(:AINVOICENET,0);
end
if (PARENTID is null) then
PARENTID = :APARENTID;
if ((AUWORDERID > 0) or (:ALABQUALITYID is not null)) then
DELETION = 0;
if (WASTEACTNUMBER is null) then
select WASTEACTNUMBER from WASTEACTS
where (WASTEACTS.WASTEACTID = :ARELATIONID)
into :WASTEACTNUMBER;
if (SHIFT is null) then
SHIFT = :ASHIFT;
end
end