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

REGISTERS_UPDATE_BASIS

 

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

Параметр

Тип

Описание

REGID

INTEGER

 

REGNUM

INTEGER

 

HUMIDITY

NUMERIC(9,2)

 

DIRT

NUMERIC(9,2)

 

SCREENING

NUMERIC(9,2)

 

INCOMECOST

NUMERIC(12,4)

 

DRYCOST

NUMERIC(12,4)

 

UNDERWORKCOST

NUMERIC(12,4)

 

PLUGUNDERWORK

INTEGER

 

STORTICKNUM

INTEGER

 

STORTICKBLANKNUM

VARCHAR(6)

 

STORTICKBLANKSERIE

VARCHAR(2)

 

CONTRACTID

INTEGER

 

ISCALCQUALITY

INTEGER

 

ZHS

INTEGER

 

SAMPLER

INTEGER

 

USEFULLWEIGHT

INTEGER

 

PAYMENTSSERVICES

INTEGER

 

 

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

Параметр

Тип

Описание

WEIGHTALL

INTEGER

 

 

Описание

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

 

Определение

CREATE PROCEDURE REGISTERS_UPDATE_BASIS(
    REGID INTEGER,
    REGNUM INTEGER,
    HUMIDITY NUMERIC(9,2),
    DIRT NUMERIC(9,2),
    SCREENING NUMERIC(9,2),
    INCOMECOST NUMERIC(12,4),
    DRYCOST NUMERIC(12,4),
    UNDERWORKCOST NUMERIC(12,4),
    PLUGUNDERWORK INTEGER,
    STORTICKNUM INTEGER,
    STORTICKBLANKNUM VARCHAR(6),
    STORTICKBLANKSERIE VARCHAR(2),
    CONTRACTID INTEGER,
    ISCALCQUALITY INTEGER,
    ZHS INTEGER,
    SAMPLER INTEGER,
    USEFULLWEIGHT INTEGER,
    PAYMENTSSERVICES INTEGER = 0)
RETURNS (
    WEIGHTALL INTEGER)
AS
declare variable QUALITYID integer;
declare variable GROSS integer;
declare variable NET integer;
declare variable WEIGHT integer;
declare variable INVENTORYID integer;
declare variable STORTICKID integer;
declare variable BASHUM numeric(5,2);
declare variable BASDIRT numeric(5,2);
declare variable BASSCREEN numeric(5,2);
declare variable LABHUM numeric(5,2);
declare variable LABDIRT numeric(5,2);
declare variable LABSCR numeric(5,2);
declare variable HUMP numeric(5,2);
declare variable DIRTP numeric(5,2);
declare variable SCREENP numeric(5,2);
declare variable DETS numeric(5,2);
declare variable DETH numeric(9,4);
declare variable DETD numeric(9,4);
declare variable ALLDET numeric(9,4);
declare variable DETDWEIGHT integer;
declare variable DETHWEIGHT integer;
declare variable DETERIORATION integer;
declare variable LBDIRTALL numeric(5,2);
declare variable LBHUMALL numeric(5,2);
declare variable LBSCALL numeric(5,2);
declare variable NETALL integer;
declare variable MAXINV integer;
declare variable HUMWEIGHT integer = 0;
declare variable DRYWEIGHT integer = 0;
declare variable SCREENWEIGHT integer;
declare variable FLOWKG integer;
declare variable DETSWEIGHT integer = 0;
declare variable SAMPLERWEIGHT integer;
declare variable DRYQUANTITY numeric(15,3) = 0;
declare variable CLEARQUANTITY numeric(15,3) = 0;
declare variable DRYREDUCTION numeric(15,3) = 0;
declare variable CLEARREDUCTION numeric(15,3) = 0;
declare variable SDETHWEIGHT integer = 0;
declare variable SDETDWEIGHT integer = 0;
declare variable SDETSWEIGHT integer = 0;
declare variable DEFAULTVALUE numeric(4,2);
declare variable REGDATE date;
declare variable CROPID integer;
declare variable CLASSID integer;
declare variable TRANSPORTTYPEID integer;
declare variable PRECISENESS smallint;
begin
  LBDIRTALL = 0 ;
  LBHUMALL = 0;
  LBSCALL = 0;

--  SAMPLER = 4;
  SAMPLERWEIGHT = 0;
  
  select INVOICEREGISTERS.QUALITYID, INVOICEREGISTERS.STORAGETICKETID,
      coalesce(ENVIRONMENTOPTIONS.PRECISENESS,0) PRECISENESS
    from INVOICEREGISTERS
      left join ENVIRONMENTOPTIONS on (0=0)
    where (INVOICEREGISTERS.INVOICEREGISTERID = :REGID)
  into :QUALITYID, :STORTICKID, :PRECISENESS;

  if (:QUALITYID is null) then
    select Q.RESULTQUALITYID
      from QUALITY_INSERT(null, null, null, null, null, null, :HUMIDITY,
          null, null, null, null, null, null, :DIRT, :SCREENING, null, null,
          null, null, null) Q
    into :QUALITYID;
   else
     select Q.RESULTQUALITYID
       from QUALITY_UPDATE(0, :QUALITYID, null, null, null, null, null, :HUMIDITY,
           null, null, null, null, null, null, :DIRT, :SCREENING, null, null,
           null, null) Q
     into :QUALITYID;

  update INVOICEREGISTERS
    set INVOICEREGISTERS.INCOMECOST = :INCOMECOST,
        INVOICEREGISTERS.DRYCOST = :DRYCOST,
        INVOICEREGISTERS.UNDERWORKCOST = :UNDERWORKCOST,
        INVOICEREGISTERS.QUALITYID = :QUALITYID,
        INVOICEREGISTERS.REGISTERNUMBER = :REGNUM
    where (INVOICEREGISTERS.INVOICEREGISTERID = :REGID);

 --//-- сумма всего

  if (:ISCALCQUALITY = 1) then begin
    select
        max(ITTRANSPORT.TRANSPORTTYPEID)
      from IT
        left join ITTRANSPORT on (ITTRANSPORT.INVENTORYID = IT.INVENTORYID)
      where ((IT.REGISTERID = :REGID) and (IT.NET is not null))
        and (IT.OPERATIONID not in (4,17,18,49,50))
        and (IT.STATE >= 0) and (IT.PARENTID <> -1)
    into :TRANSPORTTYPEID;

    if ((TRANSPORTTYPEID = 2) or (coalesce(:ZHS,3) = 4)) then begin
      select
          case
            when (:PRECISENESS = 1) then
              cast(cast(sum(cast(cast(LABQD.DIRT as numeric(4,1)) * IT.NET / 100 as integer)) * 100 as numeric(14,4)) / sum(IT.NET) as numeric(4,2))
            else cast(cast(sum(cast(cast(LABQD.DIRT as numeric(4,2)) * IT.NET / 100 as integer)) * 100 as numeric(14,4)) / sum(IT.NET) as numeric(4,2))
          end,
          case
            when (:PRECISENESS = 1) then
              cast(cast(sum(cast(cast(LABQD.HUMIDITY as numeric(4,1)) * IT.NET / 100 as integer)) * 100 as numeric(14,4)) / sum(IT.NET) as numeric(4,2))
            else cast(cast(sum(cast(cast(LABQD.HUMIDITY as numeric(4,2)) * IT.NET / 100 as integer)) * 100 as numeric(14,4)) / sum(IT.NET) as numeric(4,2))
          end,
          case
            when (max(CROP.CROPTYPEID) = 5) then
              case
                when (:PRECISENESS = 1) then
                  cast(cast(sum(cast(cast(LABQD.OILSEED as numeric(4,1)) * IT.NET / 100 as integer)) * 100 as numeric(14,4)) / sum(IT.NET) as numeric(4,2))
                else cast(cast(sum(cast(cast(LABQD.OILSEED as numeric(4,1)) * IT.NET / 100 as integer)) * 100 as numeric(14,4)) / sum(IT.NET) as numeric(4,2))
              end
            else
              case
                when (:PRECISENESS = 1) then
                  cast(cast(sum(cast(cast(LABQD.SCREENING as numeric(4,1)) * IT.NET / 100 as integer)) * 100 as numeric(14,4)) / sum(IT.NET) as numeric(4,2))
                else cast(cast(sum(cast(cast(LABQD.SCREENING as numeric(4,1)) * IT.NET / 100 as integer)) * 100 as numeric(14,4)) / sum(IT.NET) as numeric(4,2))
              end
          end,
          max(case
                when (IT.NET > 0) then
                  IT.INVENTORYID
                end) MAXINV,
          sum(IT.NET), max(IT.REGDATE), max(LABQD.CROPID), max(LABQD.CLASSID)
        from IT
          left join QUALITY_SELECT(IT.BUHQUALITYID) LABQD on (0=0)
          left join ITTRANSPORT on (ITTRANSPORT.INVENTORYID = IT.INVENTORYID)
          left join CROP on (CROP.CROPID = LABQD.CROPID)
        where ((IT.REGISTERID = :REGID) and (IT.NET is not null))
          and (IT.OPERATIONID not in (4,17,18,49,50))
          and (IT.STATE >= 0) and (IT.PARENTID <> -1)
          and ((LABQD.HUMIDITY is not null) or (LABQD.DIRT is not null))
      into :LBDIRTALL, :LBHUMALL, :LBSCALL, :MAXINV, :NETALL, :REGDATE, :CROPID, :CLASSID;
    end
    else begin
      select
          LABQD.DIRT, LABQD.HUMIDITY,
          case
            when (CROP.CROPTYPEID = 5) then
              LABQD.OILSEED
            else LABQD.SCREENING
          end SCREENING,
          max(case
                when (IT.NET > 0) then
                  IT.INVENTORYID
                end) MAXINV,
          sum(IT.NET), max(IT.REGDATE), max(LABQD.CROPID), max(LABQD.CLASSID)
        from IT
          Left join QUALITY_SELECT(IT.BUHQUALITYID) LABQD on (0=0)
          left join ITTRANSPORT on (ITTRANSPORT.INVENTORYID = IT.INVENTORYID)
          left join CROP on (CROP.CROPID = LABQD.CROPID)
        where ((IT.REGISTERID = :REGID) and (IT.NET is not null))
          and (IT.OPERATIONID not in (4,17,18,49,50))
          and (IT.STATE >= 0) and (IT.PARENTID <> -1)
          and ((LABQD.HUMIDITY is not null) or (LABQD.DIRT is not null))
--          and ((ITTRANSPORT.TRANSPORTTYPEID between 0 and 1) and (coalesce(:ZHS, 3) = 3))
      group by LABQD.DIRT, LABQD.HUMIDITY, 3
      into :LBDIRTALL, :LBHUMALL, :LBSCALL, :MAXINV, :NETALL, :REGDATE, :CROPID, :CLASSID;
    end

    if (SAMPLER > 2) then begin
      if (SAMPLER = 3) then
        SAMPLERWEIGHT = 2;
      else
        if (SAMPLER = 4) then begin
          if (NETALL <= 50000) then
            SAMPLERWEIGHT = 2;
          else SAMPLERWEIGHT = round(NETALL / 20000 - 0.001);
        end
      NETALL = :NETALL + SAMPLERWEIGHT;
    end

    if ((:HUMIDITY > :LBHUMALL) or (:HUMIDITY = 0)) then
      HUMP = :HUMIDITY;
    else HUMP = :LBHUMALL;

    if ((:DIRT > :LBDIRTALL) or (:DIRT = 0)) then
      DIRTP = :DIRT;
    else DIRTP = :LBDIRTALL;

    if ((:SCREENING > :LBSCALL) or (:SCREENING = 0)) then
      SCREENP = :SCREENING;
    else SCREENP = :LBSCALL;

    if (:PLUGUNDERWORK = 4) then begin --   Лисичанск
      DETH = :HUMP - :HUMIDITY;
      DRYREDUCTION = :HUMP - :HUMIDITY;
      DETD = :DIRTP - :DIRT;
      DETS = :SCREENP - :SCREENING;
      CLEARREDUCTION = (:DIRTP - :DIRT) + (:SCREENP - :SCREENING);
      ALLDET = cast((((100 - (DETH + DETD + DETS)) / 100)) as numeric (16,4));
      WEIGHTALL = NETALL * ALLDET; --/
    end
    else
      if (:PLUGUNDERWORK = 5) then begin
        DETH = cast(100 * (:HUMP - :HUMIDITY) / (100 - :HUMIDITY) as numeric (16,2));
        DRYREDUCTION = :HUMP - :HUMIDITY;
        DETD = cast((100 - DETH) * (:DIRTP - :DIRT) / (100 - :DIRT) as numeric (16,2));
        CLEARREDUCTION = :DIRTP - :DIRT;
        ALLDET = cast((100 - (DETH + DETD)) / 100 as numeric (16,4));
        WEIGHTALL = NETALL * ALLDET;
      end
      else
        if (:PLUGUNDERWORK = 6) then begin
          DETH = cast(100 * (:HUMP - :HUMIDITY) / (100 - :HUMIDITY) as numeric (16,2));
          DRYREDUCTION = :HUMP - :HUMIDITY;
          DETD = cast((100 - DETH) * (:DIRTP - :DIRT) / (100 - :DIRT) as numeric (16,2));

          if (:SCREENING < 0) then begin
            DETS = cast(DETD * abs(:SCREENING) / (abs(:SCREENING) - 2) as numeric (16,2));
            DETD = cast(DETD * (100 - abs(:SCREENING)) / 100 as numeric (16,2));
            CLEARREDUCTION = cast((:DIRTP - :DIRT) * ((100 - abs(:SCREENING)) / 100 + abs(:SCREENING) / (abs(:SCREENING) - 2)) as numeric (16,3));
          end
          else begin
            DETS = cast((100 - DETH) * (:SCREENP - :SCREENING) / (100 - :SCREENING) as numeric (16,2));
            CLEARREDUCTION = (:DIRTP - :DIRT) + (:SCREENP - :SCREENING);
          end

          ALLDET = cast((100 - (DETH + DETD + DETS)) / 100 as numeric (16,4));
          WEIGHTALL = NETALL * ALLDET;
        end
        else
          if (:PLUGUNDERWORK = 2) then begin
            DETH = cast(((:HUMP - :HUMIDITY) * 100) / (100 - :HUMIDITY) as numeric (9,2));
            DRYREDUCTION = :HUMP - :HUMIDITY;
            DETD = cast((100 - DETH) * (:DIRTP - :DIRT) / (100 - :DIRT) as numeric (9,2));
            DETS = cast((100 - DETH) * (:SCREENP - :SCREENING) / (100 - :SCREENING) as numeric (9,2));
            CLEARREDUCTION = (:DIRTP - :DIRT) + (:SCREENP - :SCREENING);
--            DETD = cast(((:SCREENP - :DIRT) * 100) / (100 - :DIRT) as numeric (9,2));
--            DETS = cast(((:SCREENP - :SCREENING) * 100) / (100 - :SCREENING) as numeric (9,2));
--            W1 = (NETALL - NETALL*detH/100);
--            W2 = (W1 - W1*detD/100 - W1*detS/100);
--            WeightAll =  W2 ;
            ALLDET = cast((100 - (DETH + DETD + DETS)) / 100 as numeric (16,4));
            WEIGHTALL = NETALL * ALLDET;
          end
          else begin
            DETH = (((:HUMP - :LBHUMALL) * 100) / (100 - :LBHUMALL));
            DRYREDUCTION = :HUMP - :LBHUMALL;
            DETD = (((:DIRTP - :LBDIRTALL) * 100) / (100 - :LBDIRTALL));
            CLEARREDUCTION = :DIRTP - :LBDIRTALL;
            DETHWEIGHT = ((DETH / 100) * (:NET - DETDWEIGHT));
            DETDWEIGHT = (DETD * :NET / 100);
            DETERIORATION = (100 - ((NET - (DETDWEIGHT + DETHWEIGHT)) / NET * 100));
            WEIGHT = :NET;
          end

    HUMWEIGHT = coalesce(cast((DETH * :NETALL / 100) as integer),0);
    DRYWEIGHT = coalesce(cast((DETD * :NETALL / 100) as integer),0);
    SCREENWEIGHT = coalesce(cast((DETS * :NETALL / 100) as integer),0);
    FLOWKG = WEIGHTALL - (NETALL - HUMWEIGHT - DRYWEIGHT - SCREENWEIGHT);

    if (FLOWKG <> 0) then begin          -- oops
      if (SCREENWEIGHT > 0) then
        SCREENWEIGHT = SCREENWEIGHT - FLOWKG;
      else
        if (DRYWEIGHT > 0) then
          DRYWEIGHT = DRYWEIGHT - FLOWKG;
        else
          if (HUMWEIGHT > 0) then
            HUMWEIGHT = HUMWEIGHT - FLOWKG;
    end

    if (:USEFULLWEIGHT = 1) then begin
      DRYQUANTITY = DRYREDUCTION * NETALL / 1000;
      CLEARQUANTITY = CLEARREDUCTION * NETALL / 1000;
    end
    else begin
      if (:PAYMENTSSERVICES = 0) then begin
        DRYQUANTITY = DRYREDUCTION * NETALL / 1000;
        CLEARQUANTITY = CLEARREDUCTION * (NETALL - HUMWEIGHT) / 1000;
      end

      if (:PAYMENTSSERVICES = 1) then begin
        CLEARQUANTITY = CLEARREDUCTION * NETALL / 1000;
        DRYQUANTITY = cast(DRYREDUCTION * (NETALL - cast((CLEARREDUCTION * NETALL / 100) as integer)) as numeric(15,5)) / 1000;
      end

      if (:PAYMENTSSERVICES = 2) then begin
        select coalesce(GET_CONTRACT_COSTS.DIRTB,0)
          from GET_CONTRACT_COSTS(:REGDATE, null, 3, :CROPID, :CLASSID)
        into :DEFAULTVALUE;

        if (DIRTP > DEFAULTVALUE) then begin
          CLEARQUANTITY = CLEARREDUCTION * NETALL / 1000;
          DRYQUANTITY = cast(DRYREDUCTION * (NETALL - cast((CLEARREDUCTION * NETALL / 100) as integer)) as numeric(15,5)) / 1000;
        end
        else begin
          DRYQUANTITY = DRYREDUCTION * NETALL / 1000;
          CLEARQUANTITY = cast(CLEARREDUCTION * (NETALL - cast((DRYREDUCTION * NETALL / 100) as integer)) as numeric(15,5)) / 1000;
        end
      end
    end

    update INVOICEREGISTERS
      set INVOICEREGISTERS.DRYQUANTITY = :DRYQUANTITY,
          INVOICEREGISTERS.CLEARQUANTITY = :CLEARQUANTITY
      where (INVOICEREGISTERS.INVOICEREGISTERID = :REGID);

 --//--

    for
      select
          coalesce(IT.NET,0), IT.INVENTORYID, coalesce(IT.GROSS,0),
          BASQ.HUMIDITY, BASQ.DIRT, BASQ.SCREENING,
          coalesce(LABQD.HUMIDITY,0), coalesce(LABQD.DIRT,0),
          case
            when (CROP.CROPTYPEID = 5) then
              coalesce(LABQD.OILSEED,0)
            else coalesce(LABQD.SCREENING,0)
          end SCREENING
        from IT
          left join INVOICEREGISTERS on (INVOICEREGISTERS.INVOICEREGISTERID = IT.REGISTERID)
          left join QUALITY_SELECT(IT.BUHQUALITYID) LABQD on (0=0)
          left join CROP on (CROP.CROPID = LABQD.CROPID)
          left join QUALITYDATA_SELECT_MIN(INVOICEREGISTERS.QUALITYID) BASQ on (0=0)
--        where ((IT.REGISTERID = :REGID) and (IT.NET > 0))
        where (IT.REGISTERID = :REGID)
      order by 2
      into :NET, :INVENTORYID, :GROSS,
           :BASHUM, :BASDIRT, :BASSCREEN,
           :LABHUM, :LABDIRT, :LABSCR

      do begin
        DETH = 0;
        DETD = 0;
        DETS = 0;

        if ((:BASHUM > :LABHUM) or (:BASHUM = 0)) then
          HUMP = :BASHUM;
        else HUMP = :LABHUM;

        if ((:BASDIRT > :LABDIRT) or (:BASDIRT = 0)) then
          DIRTP = :BASDIRT;
        else DIRTP = :LABDIRT;

        if ((:BASSCREEN > :LABSCR) or (:BASSCREEN = 0)) then
          SCREENP = :BASSCREEN;
        else SCREENP = :LABSCR;

        --SimpleRoundTo

        if (:PLUGUNDERWORK = 4) then begin
          DETH = :HUMP - :BASHUM;
          DETD = :DIRTP - :BASDIRT;
          DETS = :SCREENP - :BASSCREEN;
          ALLDET = cast((((100 - (DETH + DETD + DETS)) / 100)) as numeric (16,4));
          WEIGHT = NET * ALLDET;
          WEIGHTALL = WEIGHTALL - coalesce(WEIGHT,0);

          if (:MAXINV = :INVENTORYID) then begin
            if (WEIGHTALL <> 0) then
              WEIGHT = WEIGHT + WEIGHTALL;
          end

          DETHWEIGHT = cast((DETH * :NET / 100) as integer);
          DETDWEIGHT = cast((DETD * :NET / 100) as integer);
          DETSWEIGHT = cast((DETS * :NET / 100) as integer);
        end
        else begin
          if (:PLUGUNDERWORK = 5) then begin
            DETH = cast(100 * (:HUMP - :BASHUM) / (100 - :BASHUM) as numeric (16,2));
            DETD = cast((100 - DETH) * (:DIRTP - :BASDIRT) / (100 - :BASDIRT) as numeric (16,2));
            ALLDET = cast((100 - (DETH + DETD)) / 100 as numeric (16,4));
            WEIGHT = NET * ALLDET;
            WEIGHTALL = WEIGHTALL - coalesce(WEIGHT,0);

            if (:MAXINV = :INVENTORYID) then begin
              if (WEIGHTALL <> 0) then
                WEIGHT = WEIGHT + WEIGHTALL;
            end

            DETHWEIGHT = cast((DETH * :NET / 100) as integer);
            DETDWEIGHT = cast((DETD * :NET / 100) as integer);
            DETSWEIGHT = 0;
          end
          else
            if (:PLUGUNDERWORK = 6) then begin
              DETH = cast(100 * (:HUMP - :BASHUM) / (100 - :BASHUM) as numeric (16,2));
              DETD = cast((100 - DETH) * (:DIRTP - :BASDIRT) / (100 - :BASDIRT) as numeric (16,2));

              if (:BASSCREEN < 0) then begin
                DETS = cast(DETD * abs(:BASSCREEN) / (abs(:BASSCREEN) - 2) as numeric (16,2));
                DETD = cast(DETD * (100 - abs(:SCREENING)) / 100 as numeric (16,2));
              end
              else DETS = cast((100 - DETH) * (:SCREENP - :BASSCREEN) / (100 - :BASSCREEN) as numeric (16,2));

              ALLDET = cast((100 - (DETH + DETD + DETS)) / 100 as numeric (16,4));

              if ((:SAMPLERWEIGHT > 0) and (:GROSS > 0)) then begin
                GROSS = :GROSS + :SAMPLERWEIGHT;
                NET = :NET + :SAMPLERWEIGHT;

                update IT
                  set IT.GROSS = :GROSS,
                      IT.NET = :NET
                  where (IT.INVENTORYID = :INVENTORYID);

                update ITTRANSPORT
                  set ITTRANSPORT.SAMPLERWEIGHT = :SAMPLERWEIGHT
                  where (ITTRANSPORT.INVENTORYID = :INVENTORYID);

                SAMPLERWEIGHT = 0;
              end

              WEIGHT = NET * ALLDET;
              WEIGHTALL = WEIGHTALL - coalesce(WEIGHT,0);

              if (:MAXINV = :INVENTORYID) then begin
                if (WEIGHTALL <> 0) then
                  WEIGHT = WEIGHT + WEIGHTALL;

                if (:ZHS = 3) then begin
                  DETHWEIGHT = HUMWEIGHT - SDETHWEIGHT;
                  DETDWEIGHT = DRYWEIGHT - SDETDWEIGHT;
                  DETSWEIGHT = SCREENWEIGHT - SDETSWEIGHT;
                end
              end

              if ((:MAXINV <> :INVENTORYID) or (:ZHS = 4)) then begin
                DETHWEIGHT = cast((DETH * :NET / 100) as integer);
                DETDWEIGHT = cast((DETD * :NET / 100) as integer);
                DETSWEIGHT = cast((DETS * :NET / 100) as integer);
              end
            end
            else
              if (:PLUGUNDERWORK = 2) then begin
                DETH = cast(100 * (:HUMP - :BASHUM) / (100 - :BASHUM) as numeric (16,2));
                DETD = cast((100 - DETH) * (:DIRTP - :BASDIRT) / (100 - :BASDIRT) as numeric (16,2));
                DETS = cast((100 - DETH) * (:SCREENP - :BASSCREEN) / (100 - :BASSCREEN) as numeric (16,2));
                ALLDET = cast((100 - (DETH + DETD + DETS)) / 100 as numeric (16,4));

                if ((:SAMPLERWEIGHT > 0) and (:GROSS > 0)) then begin
                  GROSS = :GROSS + :SAMPLERWEIGHT;
                  NET = :NET + :SAMPLERWEIGHT;

                  update IT
                    set IT.GROSS = :GROSS,
                        IT.NET = :NET
                    where (IT.INVENTORYID = :INVENTORYID);

                  update ITTRANSPORT
                    set ITTRANSPORT.SAMPLERWEIGHT = :SAMPLERWEIGHT
                    where (ITTRANSPORT.INVENTORYID = :INVENTORYID);

                  SAMPLERWEIGHT = 0;
                end
                WEIGHT = NET * ALLDET;
                WEIGHTALL = WEIGHTALL - coalesce(WEIGHT,0);

                if (:MAXINV = :INVENTORYID) then begin
                  if (WEIGHTALL <> 0) then
                    WEIGHT = WEIGHT + WEIGHTALL;

                  if (:ZHS = 3) then begin
                    DETHWEIGHT = HUMWEIGHT - SDETHWEIGHT;
                    DETDWEIGHT = DRYWEIGHT - SDETDWEIGHT;
                    DETSWEIGHT = SCREENWEIGHT - SDETSWEIGHT;
                  end
                end

                if ((:MAXINV <> :INVENTORYID) or (:ZHS = 4)) then begin
                  DETHWEIGHT = cast((DETH * :NET / 100) as integer);
                  DETDWEIGHT = cast((DETD * :NET / 100) as integer);
                  DETSWEIGHT = cast((DETS * :NET / 100) as integer);
                end
              end

              else begin
                DETHWEIGHT = 0;
                DETDWEIGHT = 0;
                DETSWEIGHT = 0;
                WEIGHT = :NET;
              end

       --// all

          FLOWKG = WEIGHT - (NET - DETHWEIGHT - DETDWEIGHT - DETSWEIGHT);

          if (FLOWKG <> 0) then begin          -- oops
            if (DETSWEIGHT > 0) then
              DETSWEIGHT = DETSWEIGHT - FLOWKG;
            else
              if (DETDWEIGHT > 0) then
                DETDWEIGHT = DETDWEIGHT - FLOWKG;
              else
                if (DETHWEIGHT > 0) then
                  DETHWEIGHT = DETHWEIGHT - FLOWKG;
          end

          SDETHWEIGHT = SDETHWEIGHT + DETHWEIGHT;
          SDETDWEIGHT = SDETDWEIGHT + DETDWEIGHT;
          SDETSWEIGHT = SDETSWEIGHT + DETSWEIGHT;

        end

        update IT
          set IT.WEIGHT = (case
                             when (:ISCALCQUALITY = 1) then
                               :WEIGHT
                             else IT.WEIGHT
                           end),
              IT.CONTRACTID = :CONTRACTID
          where (IT.INVENTORYID = :INVENTORYID);

        if (:PLUGUNDERWORK in (2,4,5,6)) then begin
          update ITTRANSPORT
            set ITTRANSPORT.HUMWEIGHT = :DETHWEIGHT,
                ITTRANSPORT.DIRTWEIGHT = :DETDWEIGHT,
                ITTRANSPORT.SCREENWEIGHT = :DETSWEIGHT
            where (ITTRANSPORT.INVENTORYID = :INVENTORYID);
        end
      end
  end

  if ((:STORTICKID is null) and (:STORTICKBLANKSERIE <> '')) then begin
    execute procedure STORAGETICKET_FORM(:REGID, 0, 0, null, null, null);

    select STORAGETICKETS.STORAGETICKETID
      from STORAGETICKETS
        left join INVOICEREGISTERS on (STORAGETICKETS.STORAGETICKETID = INVOICEREGISTERS.STORAGETICKETID)
        where (INVOICEREGISTERS.INVOICEREGISTERID = :REGID)
    into :STORTICKID;
  end

  if (:STORTICKBLANKSERIE <> '')  then
    update STORAGETICKETS
      set STORAGETICKETS.BLANKNUMBER = :STORTICKBLANKNUM,
          STORAGETICKETS.BLANKSERIES = :STORTICKBLANKSERIE
      where (STORAGETICKETS.STORAGETICKETID = :STORTICKID);

  if (:STORTICKNUM <> 0) then
    update STORAGETICKETS
      set STORAGETICKETS.NUMBER = :STORTICKNUM
      where (STORAGETICKETS.STORAGETICKETID = :STORTICKID);

  suspend;

end

 

     Previous topic Chapter index Next topic