"localhost:/firebird/data/ILICHEVSK2.FDB". Процедуры Previous topic Chapter index Next topic

FORM36_REMS

 

Входные параметры

Параметр

Тип

Описание

DATE1

DATE

 

DATE2

DATE

 

STORAGEID

INTEGER

 

SILAGEID

INTEGER

 

STORINGID

INTEGER

 

CLASSID

INTEGER

 

DOCROP

INTEGER

 

CROPID

INTEGER

 

PARTYID

INTEGER

 

PARTYDATE

DATE

 

 

Выходные параметры

Параметр

Тип

Описание

OUTNET

BIGINT

 

OUTHUMCP

INTEGER

 

OUTDIRTCP

INTEGER

 

OUTDIRT

NUMERIC(5,2)

 

OUTHUM

NUMERIC(5,2)

 

INNET

BIGINT

 

INHUMCP

INTEGER

 

INDIRTCP

INTEGER

 

INDIRT

NUMERIC(5,2)

 

INHUM

NUMERIC(5,2)

 

OUTWOREBNET

BIGINT

 

OUTWOREBHUMCP

INTEGER

 

OUTWOREBDIRTCP

INTEGER

 

OUTWOREBHUM

NUMERIC(5,2)

 

OUTWOREBDIRT

NUMERIC(5,2)

 

INWOREBNET

BIGINT

 

INWOREBHUMCP

INTEGER

 

INWOREBDIRTCP

INTEGER

 

INWOREBHUM

NUMERIC(5,2)

 

INWOREBDIRT

NUMERIC(5,2)

 

OUTWOREBFROMST_NET

BIGINT

 

OUTWOREBFROMST_HUMCP

INTEGER

 

OUTWOREBFROMST_DIRTCP

INTEGER

 

OUTWOREBFROMST_HUM

NUMERIC(5,2)

 

OUTWOREBFROMST_DIRT

NUMERIC(5,2)

 

INWOREBFROMST_NET

BIGINT

 

INWOREBFROMST_HUMCP

INTEGER

 

INWOREBFROMST_DIRTCP

INTEGER

 

INWOREBFROMST_HUM

NUMERIC(5,2)

 

INWOREBFROMST_DIRT

NUMERIC(5,2)

 

INPERIODNET

BIGINT

 

INPERIOD_HUMCP

INTEGER

 

INPERIOD_DIRTCP

NUMERIC(9,2)

 

INPERIOD_HUM

NUMERIC(5,2)

 

INPERIOD_DIRT

NUMERIC(5,2)

 

OUTPERIODNET

BIGINT

 

OUTPERIOD_HUMCP

INTEGER

 

OUTPERIOD_DIRTCP

INTEGER

 

OUTPERIOD_HUM

NUMERIC(15,2)

 

OUTPERIOD_DIRT

NUMERIC(5,2)

 

INFROMSTARTNET

BIGINT

 

INFROMSTART_HUMCP

INTEGER

 

INFROMSTART_DIRTCP

INTEGER

 

INFROMSTART_HUM

NUMERIC(5,2)

 

INFROMSTART_DIRT

NUMERIC(5,2)

 

OUTFROMSTARTNET

BIGINT

 

OUTFROMSTART_HUMCP

INTEGER

 

OUTFROMSTART_DIRTCP

INTEGER

 

OUTFROMSTART_HUM

NUMERIC(5,2)

 

OUTFROMSTART_DIRT

NUMERIC(5,2)

 

INREBNET

BIGINT

 

INREBHUMCP

INTEGER

 

INREBDIRTCP

INTEGER

 

INREBHUM

NUMERIC(5,2)

 

INREBDIRT

NUMERIC(5,2)

 

OUTREBLNET

BIGINT

 

OUTREBLHUMCP

INTEGER

 

OUTREBLDIRTCP

INTEGER

 

OUTREBLHUM

NUMERIC(5,2)

 

OUTREBLDIRT

NUMERIC(5,2)

 

INREB_FROMST_NET

BIGINT

 

INREB_FROMST_HUMCP

INTEGER

 

INREB_FROMST_DIRTCP

INTEGER

 

INREB_FROMST_HUM

NUMERIC(5,2)

 

INREB_FROMST_DIRT

NUMERIC(5,2)

 

OUTREB_FROMST_NET

BIGINT

 

OUTREB_FROMST_HUMCP

INTEGER

 

OUTREB_FROMST_DIRTCP

INTEGER

 

OUTREB_FROMST_HUM

NUMERIC(5,2)

 

OUTREB_FROMST_DIRT

NUMERIC(5,2)

 

 

Описание

(Нет описания для процедуры FORM36_REMS)

 

Определение

CREATE PROCEDURE FORM36_REMS(
    DATE1 DATE,
    DATE2 DATE,
    STORAGEID INTEGER,
    SILAGEID INTEGER,
    STORINGID INTEGER,
    CLASSID INTEGER,
    DOCROP INTEGER,
    CROPID INTEGER,
    PARTYID INTEGER,
    PARTYDATE DATE)
RETURNS (
    OUTNET BIGINT,
    OUTHUMCP INTEGER,
    OUTDIRTCP INTEGER,
    OUTDIRT NUMERIC(5,2),
    OUTHUM NUMERIC(5,2),
    INNET BIGINT,
    INHUMCP INTEGER,
    INDIRTCP INTEGER,
    INDIRT NUMERIC(5,2),
    INHUM NUMERIC(5,2),
    OUTWOREBNET BIGINT,
    OUTWOREBHUMCP INTEGER,
    OUTWOREBDIRTCP INTEGER,
    OUTWOREBHUM NUMERIC(5,2),
    OUTWOREBDIRT NUMERIC(5,2),
    INWOREBNET BIGINT,
    INWOREBHUMCP INTEGER,
    INWOREBDIRTCP INTEGER,
    INWOREBHUM NUMERIC(5,2),
    INWOREBDIRT NUMERIC(5,2),
    OUTWOREBFROMST_NET BIGINT,
    OUTWOREBFROMST_HUMCP INTEGER,
    OUTWOREBFROMST_DIRTCP INTEGER,
    OUTWOREBFROMST_HUM NUMERIC(5,2),
    OUTWOREBFROMST_DIRT NUMERIC(5,2),
    INWOREBFROMST_NET BIGINT,
    INWOREBFROMST_HUMCP INTEGER,
    INWOREBFROMST_DIRTCP INTEGER,
    INWOREBFROMST_HUM NUMERIC(5,2),
    INWOREBFROMST_DIRT NUMERIC(5,2),
    INPERIODNET BIGINT,
    INPERIOD_HUMCP INTEGER,
    INPERIOD_DIRTCP NUMERIC(9,2),
    INPERIOD_HUM NUMERIC(5,2),
    INPERIOD_DIRT NUMERIC(5,2),
    OUTPERIODNET BIGINT,
    OUTPERIOD_HUMCP INTEGER,
    OUTPERIOD_DIRTCP INTEGER,
    OUTPERIOD_HUM NUMERIC(15,2),
    OUTPERIOD_DIRT NUMERIC(5,2),
    INFROMSTARTNET BIGINT,
    INFROMSTART_HUMCP INTEGER,
    INFROMSTART_DIRTCP INTEGER,
    INFROMSTART_HUM NUMERIC(5,2),
    INFROMSTART_DIRT NUMERIC(5,2),
    OUTFROMSTARTNET BIGINT,
    OUTFROMSTART_HUMCP INTEGER,
    OUTFROMSTART_DIRTCP INTEGER,
    OUTFROMSTART_HUM NUMERIC(5,2),
    OUTFROMSTART_DIRT NUMERIC(5,2),
    INREBNET BIGINT,
    INREBHUMCP INTEGER,
    INREBDIRTCP INTEGER,
    INREBHUM NUMERIC(5,2),
    INREBDIRT NUMERIC(5,2),
    OUTREBLNET BIGINT,
    OUTREBLHUMCP INTEGER,
    OUTREBLDIRTCP INTEGER,
    OUTREBLHUM NUMERIC(5,2),
    OUTREBLDIRT NUMERIC(5,2),
    INREB_FROMST_NET BIGINT,
    INREB_FROMST_HUMCP INTEGER,
    INREB_FROMST_DIRTCP INTEGER,
    INREB_FROMST_HUM NUMERIC(5,2),
    INREB_FROMST_DIRT NUMERIC(5,2),
    OUTREB_FROMST_NET BIGINT,
    OUTREB_FROMST_HUMCP INTEGER,
    OUTREB_FROMST_DIRTCP INTEGER,
    OUTREB_FROMST_HUM NUMERIC(5,2),
    OUTREB_FROMST_DIRT NUMERIC(5,2))
AS
DECLARE VARIABLE outrebnet BIGINT;
DECLARE VARIABLE outrebhum INTEGER;
DECLARE VARIABLE outrebdirt INTEGER;
DECLARE VARIABLE outperiod BIGINT;
DECLARE VARIABLE outperiodwr_hum INTEGER;
DECLARE VARIABLE outperiodwr_dirt INTEGER;
DECLARE VARIABLE outfromstartnetwr INTEGER;
DECLARE VARIABLE outfromstart_humcpwr INTEGER;
DECLARE VARIABLE outfromstart_dirtcpwr INTEGER;
BEGIN
    SELECT COALESCE(SUM(it.net),0) net,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqh.qualityvalue *it.net/100),0)) END humcp,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue *it.net/100),0)) END dirtcp

    FROM it
       join getworkparties(:partyid,:partydate,null,null,null)
         on (it.partyid = getworkparties.partyid)
       LEFT JOIN operation ON (operation.operationid = it.operationid)
       LEFT JOIN quality squality ON (it.samplerqualityid = squality.qualityid)
       left join qualitydata labqh on (it.labqualityid = labqh.qualityid and labqh.qualitytypeid = 2)
       left join qualitydata labqd on (it.labqualityid = labqd.qualityid and labqd.qualitytypeid = 13)
       WHERE
        (operation.operationsubtype =1)
        AND it.regdate < :date1
        AND it.storageid = :storageid
        AND ((squality.classid = :classid AND :docrop = 0) OR (squality.cropid = :cropid AND :docrop = 1))
        AND operation.operationtype <> 2
        AND it.state >= 0
        AND it.parentid >= 0
        AND ((it.silageid = :silageid) OR (:silageid = 0))
        AND ((it.storingid = :storingid) OR (:storingid = 0))
--        and ((:USEAFTERQUALTY = 0) or (it.operationid <> 7))
    INTO :outnet,
         :outhumcp,
         :outdirtcp;


    SELECT COALESCE(SUM(it.net*-1),0) net,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqh.qualityvalue *it.net/100),0)*-1) END humcp,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue*it.net/100),0) *-1) END dirtcp

    FROM it
       join getworkparties(:partyid,:partydate,null,null,null)
        on (it.partyid = getworkparties.partyid)
       LEFT JOIN operation ON (operation.operationid = it.operationid)
       LEFT JOIN quality squality ON (it.samplerqualityid = squality.qualityid)
       left join qualitydata labqh on (it.labqualityid = labqh.qualityid and labqh.qualitytypeid = 2)
       left join qualitydata labqd on (it.labqualityid = labqd.qualityid and labqd.qualitytypeid = 13)

       WHERE
        ((it.operationid = 17) AND (it.net < 0))
        AND it.regdate < :date1
        AND it.storageid = :storageid
        AND ((squality.classid = :classid AND :docrop = 0) OR (squality.cropid = :cropid AND :docrop = 1))
        AND operation.operationtype <> 2
        AND it.state >= 0
        AND it.parentid >= 0
        AND ((it.silageid = :silageid) OR (:silageid = 0))
        AND ((it.storingid = :storingid) OR (:storingid = 0))
    INTO :outrebnet,
         :outrebhum,
         :outrebdirt;

    outnet = :outnet + :outrebnet;
    outdirtcp = :outdirtcp + :outrebdirt;
    outhumcp = :outhumcp + :outrebhum;


    IF (:outnet = 0) THEN
    BEGIN
        outdirt = 0;
        outhum = 0;
    END
    ELSE
    BEGIN
        outhum = cast (:outhumcp as double precision) * 100 / :outnet;
        outdirt = cast(:outdirtcp as double precision) * 100 / :outnet;
    END

    SELECT COALESCE(SUM(it.net),0) net,

    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqh.qualityvalue *it.net/100),0)) END humcp,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue *it.net/100),0)) END dirtcp

    FROM it
      join getworkparties(:partyid,:partydate,null,null,null)
       on (it.partyid = getworkparties.partyid)
       LEFT JOIN operation ON (it.operationid = operation.operationid)
       LEFT JOIN quality  sampq ON (it.samplerqualityid = sampq.qualityid)
       left join qualitydata labqh on (it.labqualityid = labqh.qualityid and labqh.qualitytypeid = 2)
       left join qualitydata labqd on (it.labqualityid = labqd.qualityid and labqd.qualitytypeid = 13)
   WHERE
    operation.operationsubtype = 0
--    AND it.operationid <> 17
    AND it.regdate < :date1
    AND it.storageid = :storageid
    AND ((sampq.classid = :classid AND :docrop = 0) OR (sampq.cropid = :cropid AND :docrop = 1))
    AND it.state >= 0
    AND operation.operationtype <> 2
    AND it.parentid >= 0
    AND ((it.storingid = :storingid) OR (:storingid = 0))
    AND ((it.silageid = :silageid) OR (:silageid = 0))
    AND ((it.operationid <> 17) OR (it.net > 0))
    INTO :innet,
         :inhumcp,
         :indirtcp;

    IF (:innet = 0) THEN
    BEGIN
        inhum = 0;
        indirt = 0;
    END
    ELSE
    BEGIN
        inhum = cast(:inhumcp as double precision) * 100 / :innet;
        indirt = cast(:indirtcp as double precision) * 100 / :innet;
    END


    SELECT COALESCE(SUM(it.net),0) net,

    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqh.qualityvalue *it.net/100),0)) END humcp,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue *it.net/100),0)) END dirtcp

    FROM it
       join getworkparties(:partyid,:partydate,null,null,null)
         on (it.partyid = getworkparties.partyid)
   LEFT JOIN operation ON (operation.operationid = it.operationid)
   LEFT JOIN quality squality ON (it.samplerqualityid = squality.qualityid)
       left join qualitydata labqh on (it.labqualityid = labqh.qualityid and labqh.qualitytypeid = 2)
       left join qualitydata labqd on (it.labqualityid = labqd.qualityid and labqd.qualitytypeid = 13)
   WHERE
    operation.operationsubtype = 1
    AND it.regdate BETWEEN :date1 AND :date2
    AND it.storageid = :storageid
    AND ((squality.classid = :classid AND :docrop = 0) OR (squality.cropid = :cropid AND :docrop = 1))
    AND operation.operationtype <> 2
    AND it.state >= 0
    AND it.parentid >= 0
    AND ((it.silageid = :silageid) OR (:silageid = 0))
    AND ((it.storingid = :storingid) OR (:storingid = 0))
--    and ((:USEAFTERQUALTY = 0) or (it.operationid <> 7))
    INTO :outworebnet,
         :outworebhumcp,
         :outworebdirtcp;

    IF (:outworebnet = 0) THEN
    BEGIN
        outworebhum = 0;
        outworebdirt = 0;
    END
    ELSE
    BEGIN
        outworebhum = cast(:outworebhumcp as double precision) * 100 / :outworebnet;
        outworebdirt = cast(:outworebdirtcp as double precision) * 100 / :outworebnet;
    END


    SELECT COALESCE(SUM(it.net),0) net,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqh.qualityvalue *it.net/100),0)) END humcp,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue *it.net/100),0)) END dirtcp

    FROM it
       join getworkparties(:partyid,:partydate,null,null,null)
         on (it.partyid = getworkparties.partyid)
       LEFT JOIN operation ON (it.operationid = operation.operationid)
       LEFT JOIN quality  sampq ON (it.samplerqualityid = sampq.qualityid)
       left join qualitydata labqh on (it.labqualityid = labqh.qualityid and labqh.qualitytypeid = 2)
       left join qualitydata labqd on (it.labqualityid = labqd.qualityid and labqd.qualitytypeid = 13)
   WHERE
    operation.operationsubtype = 0
    and it.operationid <> 17
    AND it.regdate BETWEEN :date1 AND :date2
    AND it.storageid = :storageid
    AND ((sampq.classid = :classid AND :docrop = 0) OR (sampq.cropid = :cropid AND :docrop = 1))
    AND it.state >= 0
    AND operation.operationtype <> 2
    AND it.parentid >= 0
    AND ((it.storingid = :storingid) OR (:storingid = 0))
    AND ((it.silageid = :silageid) OR (:silageid = 0))
    INTO :inworebnet,
         :inworebhumcp,
         :inworebdirtcp;


    IF (:inworebnet = 0) THEN
    BEGIN
      inworebhum = 0;
      inworebdirt = 0;
    END
    ELSE
    BEGIN
      inworebhum = cast(:inworebhumcp as double precision) * 100 / :inworebnet;
      inworebdirt = cast(:inworebdirtcp as double precision) * 100 / :inworebnet;
    END


    SELECT COALESCE(SUM(it.net),0) net,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqh.qualityvalue *it.net/100),0)) END humcp,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue *it.net/100),0)) END dirtcp

    FROM it
       join getworkparties(:partyid,:partydate,null,null,null)
         on (it.partyid = getworkparties.partyid)
       LEFT JOIN operation ON (operation.operationid = it.operationid)
       LEFT JOIN quality squality ON (it.samplerqualityid = squality.qualityid)
       left join qualitydata labqh on (it.labqualityid = labqh.qualityid and labqh.qualitytypeid = 2)
       left join qualitydata labqd on (it.labqualityid = labqd.qualityid and labqd.qualitytypeid = 13)
   WHERE
        (operation.operationsubtype =1)
        AND it.regdate <= :date2
        AND it.storageid = :storageid
        AND ((squality.classid = :classid AND :docrop = 0) OR (squality.cropid = :cropid AND :docrop = 1))
        AND operation.operationtype <> 2
        AND it.state >= 0
        AND it.parentid >= 0
        AND ((it.silageid = :silageid) OR (:silageid = 0))
        AND ((it.storingid = :storingid) OR (:storingid = 0))
    INTO :outworebfromst_net,
         :outworebfromst_humcp,
         :outworebfromst_dirtcp;


    IF (:outworebfromst_net = 0) THEN
    BEGIN
        outworebfromst_hum = 0;
        outworebfromst_dirt = 0;
    END
    ELSE
    BEGIN
        outworebfromst_hum = cast(:outworebfromst_humcp as double precision)* 100 / :outworebfromst_net;
        outworebfromst_dirt = cast(:outworebfromst_dirtcp as double precision) * 100 / :outworebfromst_net;
    END


    SELECT COALESCE(SUM(it.net),0) net,

    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqh.qualityvalue *it.net/100),0)) END humcp,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue *it.net/100),0)) END dirtcp

    FROM it
       join getworkparties(:partyid,:partydate,null,null,null)
         on (it.partyid = getworkparties.partyid)
       LEFT JOIN operation ON (it.operationid = operation.operationid)
       LEFT JOIN quality  sampq ON (it.samplerqualityid = sampq.qualityid)
       left join qualitydata labqh on (it.labqualityid = labqh.qualityid and labqh.qualitytypeid = 2)
       left join qualitydata labqd on (it.labqualityid = labqd.qualityid and labqd.qualitytypeid = 13)
   WHERE
        operation.operationsubtype = 0
        and (it.operationid <> 17)
--        and ((it.operationid <> 17) or (it.net > 0))
        AND it.regdate <= :date2
        AND it.storageid = :storageid
        AND ((sampq.classid = :classid AND :docrop = 0) OR (sampq.cropid = :cropid AND :docrop = 1))
        AND it.state >= 0
        AND operation.operationtype <> 2
        AND it.parentid >= 0
        AND ((it.storingid = :storingid) OR (:storingid = 0))
        AND ((it.silageid = :silageid) OR (:silageid = 0))
    INTO :inworebfromst_net,
         :inworebfromst_humcp,
         :inworebfromst_dirtcp;

    IF (:inworebfromst_net = 0) THEN
    BEGIN
        inworebfromst_hum = 0;
        inworebfromst_dirt = 0;
    END
    ELSE
    BEGIN
        inworebfromst_hum = cast(:inworebfromst_humcp as double precision) * 100 / :inworebfromst_net;
        inworebfromst_dirt = cast(:inworebfromst_dirtcp as double precision) * 100 / :inworebfromst_net;
    END


    SELECT COALESCE(SUM(it.net),0) net,

    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqh.qualityvalue *it.net/100),0)) END humcp,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue *it.net/100),0)) END dirtcp

    FROM it
       join getworkparties(:partyid,:partydate,null,null,null)
         on (it.partyid = getworkparties.partyid)
       LEFT JOIN operation ON (it.operationid = operation.operationid)
       LEFT JOIN quality  sampq ON (it.samplerqualityid = sampq.qualityid)
       left join qualitydata labqh on (it.labqualityid = labqh.qualityid and labqh.qualitytypeid = 2)
       left join qualitydata labqd on (it.labqualityid = labqd.qualityid and labqd.qualitytypeid = 13)
   WHERE
        operation.operationsubtype = 0
        and ((it.operationid <> 17) or (it.net > 0))
        AND it.regdate BETWEEN :date1 AND :date2
        AND it.storageid = :storageid
        AND ((sampq.classid = :classid AND :docrop = 0) OR (sampq.cropid = :cropid AND :docrop = 1))
        AND it.state >= 0
        AND operation.operationtype <> 2
        AND it.parentid >= 0
        AND ((it.storingid = :storingid) OR (:storingid = 0))
        AND ((it.silageid = :silageid) OR (:silageid = 0))
    INTO :inperiodnet,
         :inperiod_humcp,
         :inperiod_dirtcp;

    IF (:inperiodnet = 0) THEN
    BEGIN
      inperiod_hum = 0;
      inperiod_dirt = 0;
    END
    ELSE
    BEGIN
      inperiod_hum = cast(:inperiod_humcp as double precision) * 100 / :inperiodnet;
      inperiod_dirt = cast(:inperiod_dirtcp as double precision) * 100 / :inperiodnet;
    END

    SELECT COALESCE(SUM(it.net),0) net,

    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqh.qualityvalue *it.net/100),0)) END humcp,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue *it.net/100),0)) END dirtcp

    FROM it
       join getworkparties(:partyid,:partydate,null,null,null)
         on (it.partyid = getworkparties.partyid)
       LEFT JOIN operation ON (operation.operationid = it.operationid)
       LEFT JOIN quality squality ON (it.samplerqualityid = squality.qualityid)
       left join qualitydata labqh on (it.labqualityid = labqh.qualityid and labqh.qualitytypeid = 2)
       left join qualitydata labqd on (it.labqualityid = labqd.qualityid and labqd.qualitytypeid = 13)
       WHERE
        (operation.operationsubtype =1)
        AND it.regdate between :date1 and :date2
        AND it.storageid = :storageid
        AND ((squality.classid = :classid AND :docrop = 0) OR (squality.cropid = :cropid AND :docrop = 1))
        AND operation.operationtype <> 2
        AND it.state >= 0
        AND it.parentid >= 0
        AND ((it.silageid = :silageid) OR (:silageid = 0))
        AND ((it.storingid = :storingid) OR (:storingid = 0))
--        and ((:USEAFTERQUALTY = 0) or (it.operationid <> 7))
    INTO :outperiodnet,
         :outperiod_humcp,
         :outperiod_dirtcp;


    SELECT COALESCE(SUM(it.net*-1),0) net,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqh.qualityvalue*it.net/100),0) * -1) END humcp,
    
    CASE COALESCE(SUM(it.net), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue*it.net/100),0) *-1) END dirtcp
    
    FROM it
       join getworkparties(:partyid,:partydate,null,null,null)
         on (it.partyid = getworkparties.partyid)
       LEFT JOIN operation ON (operation.operationid = it.operationid)
       LEFT JOIN quality squality ON (it.samplerqualityid = squality.qualityid)
       left join qualitydata labqh on (it.labqualityid = labqh.qualityid and labqh.qualitytypeid = 2)
       left join qualitydata labqd on (it.labqualityid = labqd.qualityid and labqd.qualitytypeid = 13)
       WHERE
        ((it.operationid = 17) AND (it.net < 0))
        AND it.regdate between :date1 and :date2
        AND it.storageid = :storageid
        AND ((squality.classid = :classid AND :docrop = 0) OR (squality.cropid = :cropid AND :docrop = 1))
        AND operation.operationtype <> 2
        AND it.state >= 0
        AND it.parentid >= 0
        AND ((it.silageid = :silageid) OR (:silageid = 0))
        AND ((it.storingid = :storingid) OR (:storingid = 0))
    INTO :outperiod,
         :outperiodwr_hum,
         :outperiodwr_dirt;

    outperiodnet = :outperiodnet + :outperiod;
    outperiod_humcp = :outperiod_humcp + :outperiodwr_hum;
    outperiod_dirtcp = :outperiod_dirtcp + :outperiodwr_dirt;

--1
    IF (:outperiodnet = 0) THEN
    BEGIN
        outperiod_hum = 0;
        outperiod_dirt = 0;
    END
    ELSE
    BEGIN
        outperiod_hum = cast(:outperiod_humcp as double precision) * 100 / :outperiodnet;
        outperiod_dirt = cast(:outperiod_dirtcp as double precision) * 100 / :outperiodnet;
    END

/*    SELECT COALESCE(SUM(IT.NET),0) NET,
    
    CASE COALESCE(SUM(IT.NET), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqH.qualityvalue *it.net/100),0)) END humCP,
    
    CASE COALESCE(SUM(IT.NET), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqD.qualityvalue *it.net/100),0)) END dirtCP

    FROM IT
       LEFT JOIN OPERATION ON (IT.OPERATIONID = OPERATION.OPERATIONID)
       LEFT JOIN quality  sampq ON (it.samplerqualityid = quality.qualityid)
       left join qualitydata labqH on (it.labqualityid = qualitydata.qualityid and qualitydata.qualitytypeid = 2)
       left join qualitydata labqD on (it.labqualityid = qualitydata.qualityid and qualitydata.qualitytypeid = 13)
   WHERE
        OPeration.operationsubtype = 0
        and ((it.operationid <> 17) or (it.net > 0))
        AND IT.Partyid =  (SELECT partyid FROM getpartyid(:PARTYID,:PARTYDATE, sampq.cropid, sampq.classid, it.storageid))
        AND IT.REGDATE <= :date2
        AND it.STORAGEID = :storageid
        AND ((sampq.classid = :classid AND :docrop = 0) OR (sampq.cropid = :cropid AND :docrop = 1))
        AND it.state >= 0
        AND operation.Operationtype <> 2
        AND it.parentid >= 0
        AND ((it.storingid = :storingid) OR (:storingid = 0))
        AND ((it.silageid = :SILAGEID) OR (:SILAGEID = 0))
    INTO :INFROMSTARTNET,
         :INFROMSTART_HUMCP,
         :INFROMSTART_DIRTCP;     */

    infromstartnet = :innet + :inperiodnet;
    infromstart_humcp = :inhumcp + :inperiod_humcp;
    infromstart_dirtcp = :indirtcp + :inperiod_dirtcp;


    IF (:infromstartnet = 0) THEN
    BEGIN
        infromstart_hum = 0;
        infromstart_dirt = 0;
    END
    ELSE
    BEGIN
        infromstart_hum = cast(:infromstart_humcp as double precision) * 100 / :infromstartnet;
        infromstart_dirt = cast(:infromstart_dirtcp as double precision) * 100 / :infromstartnet;
    END

/*    SELECT COALESCE(SUM(IT.NET),0) NET,
    
    CASE COALESCE(SUM(IT.NET), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqH.qualityvalue *it.net/100),0)) END humCP,
    
    CASE COALESCE(SUM(IT.NET), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqD.qualityvalue *it.net/100),0)) END dirtCP

    FROM IT
       LEFT JOIN OPERATION ON (OPERATION.OPERATIONID = IT.OPERATIONID)
       LEFT JOIN quality squality ON (it.samplerqualityid = quality.qualityid)
       left join qualitydata labqH on (it.labqualityid = qualitydata.qualityid and qualitydata.qualitytypeid = 2)
       left join qualitydata labqD on (it.labqualityid = qualitydata.qualityid and qualitydata.qualitytypeid = 13)
     WHERE
        (Operation.operationsubtype =1)
        AND IT.Partyid =  (SELECT partyid FROM getpartyid(:PARTYID,:PARTYDATE, squality.cropid, squality.classid, it.storageid))
        AND IT.REGDATE <= :date2
        AND it.STORAGEID = :STORAGEID
        AND ((squality.classid = :classid AND :docrop = 0) OR (squality.cropid = :cropid AND :docrop = 1))
        AND operation.operationtype <> 2
        AND it.state >= 0
        AND it.parentid >= 0
        AND ((it.silageid = :SILAGEID) OR (:SILAGEID = 0))
        AND ((it.storingid = :storingid) OR (:storingid = 0))
    INTO :OUTFROMSTARTNET,
         :OUTFROMSTART_HUMCP,
         :OUTFROMSTART_DIRTCP;    */

    outfromstartnet  = :outnet + :outperiodnet;
    outfromstart_humcp = :outhumcp + :outperiod_humcp;
    outfromstart_dirtcp = :outdirtcp + :outperiod_dirtcp;

/*    SELECT COALESCE(SUM(IT.NET*-1),0) NET,
    
    CASE COALESCE(SUM(IT.NET), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqH.qualityvalue *it.net/100),0)*-1) END humCP,
    
    CASE COALESCE(SUM(IT.NET), 0) WHEN 0 THEN 0
    ELSE
    SUM(COALESCE((labqd.qualityvalue*it.net/100),0) *-1) END dirtCP

    FROM IT
       LEFT JOIN OPERATION ON (OPERATION.OPERATIONID = IT.OPERATIONID)
       LEFT JOIN quality squality ON (it.samplerqualityid = quality.qualityid)
       left join qualitydata labqH on (it.labqualityid = qualitydata.qualityid and qualitydata.qualitytypeid = 2)
       left join qualitydata labqD on (it.labqualityid = qualitydata.qualityid and qualitydata.qualitytypeid = 13)
      WHERE
        ((it.operationid = 17) AND (it.net < 0))
        AND IT.Partyid =  (SELECT partyid FROM getpartyid(:PARTYID,:PARTYDATE, squality.cropid, squality.classid, it.storageid))
        AND IT.REGDATE <= :date2
        AND it.STORAGEID = :STORAGEID
        AND ((squality.classid = :classid AND :docrop = 0) OR (squality.cropid = :cropid AND :docrop = 1))
        AND operation.operationtype <> 2
        AND it.state >= 0
        AND it.parentid >= 0
        AND ((it.silageid = :SILAGEID) OR (:SILAGEID = 0))
        AND ((it.storingid = :storingid) OR (:storingid = 0))
    INTO :OUTFROMSTARTNETWR,
         :OUTFROMSTART_HUMCPWR,
         :OUTFROMSTART_DIRTCPWR;

    OUTFROMSTARTNET = :OUTFROMSTARTNET + :OUTFROMSTARTNETWR;
    OUTFROMSTART_HUMCP = :OUTFROMSTART_HUMCP + :OUTFROMSTART_HUMCPWR;
    OUTFROMSTART_DIRTCP = :OUTFROMSTART_DIRTCP + :OUTFROMSTART_DIRTCPWR;*/

    IF (:outfromstartnet = 0) THEN
    BEGIN
        outfromstart_hum = 0;
        outfromstart_dirt = 0;
    END
    ELSE
    BEGIN
        outfromstart_hum = cast(:outfromstart_humcp as double precision) * 100 / :outfromstartnet;
        outfromstart_dirt = cast(:outfromstart_dirtcp as double precision) * 100 / :outfromstartnet;
    END

   inrebnet = :inperiodnet - :inworebnet;
   inrebhumcp = :inperiod_humcp - :inworebhumcp;
   inrebdirtcp = :inperiod_dirtcp - :inworebdirtcp;

    IF (:inrebnet = 0) THEN
    BEGIN
        inrebhum = 0;
        inrebdirt = 0;
    END
    ELSE
    BEGIN
        inrebhum = cast(:inrebhumcp as double precision) * 100 / :inrebnet;
        inrebdirt = cast(:inrebdirtcp as double precision) * 100 / :inrebnet;
    END

   outreblnet = :outperiodnet - :outworebnet;
   outreblhumcp = :outperiod_humcp - :outworebhumcp;
   outrebldirtcp = :outperiod_dirtcp - :outworebdirtcp;

    IF (:outreblnet = 0) THEN
    BEGIN
        outreblhum = 0;
        outrebldirt = 0;
    END
    ELSE
    BEGIN
        outreblhum = cast(:outreblhumcp as double precision) * 100 / :outreblnet;
        outrebldirt = cast(:outrebldirtcp as double precision) * 100 / :outreblnet;
    END


   inreb_fromst_net = :infromstartnet - :inworebfromst_net;
   inreb_fromst_humcp = :infromstart_humcp - :inworebfromst_humcp;
   inreb_fromst_dirtcp = :infromstart_dirtcp - :inworebfromst_dirtcp;

    IF (:inreb_fromst_net = 0) THEN
    BEGIN
        inreb_fromst_hum = 0;
        inreb_fromst_dirt = 0;
    END
    ELSE
    BEGIN
        inreb_fromst_hum = cast(:inreb_fromst_humcp as double precision) * 100 / :inreb_fromst_net;
        inreb_fromst_dirt = cast(:inreb_fromst_dirtcp as double precision) * 100 / :inreb_fromst_net;
    END


   outreb_fromst_net = :outfromstartnet - :outworebfromst_net;
   outreb_fromst_humcp = :outfromstart_humcp - :outworebfromst_humcp;
   outreb_fromst_dirtcp = :outfromstart_dirtcp - :outworebfromst_dirtcp;

    IF (:outreb_fromst_net = 0) THEN
    BEGIN
        outreb_fromst_hum = 0;
        outreb_fromst_dirt = 0;
    END
    ELSE
    BEGIN
        outreb_fromst_hum = cast(:outreb_fromst_humcp as double precision) * 100 / :outreb_fromst_net;
        outreb_fromst_dirt = cast(:outreb_fromst_dirtcp as double precision) * 100 / :outreb_fromst_net;
    END
SUSPEND;
END

 

     Previous topic Chapter index Next topic