Входные параметры
Параметр  | Тип  | Описание  | 
|---|---|---|
PARTYID  | 
    INTEGER  | 
    
  | 
  
PARTYDATE  | 
    DATE  | 
    
  | 
  
BEGINDATE  | 
    DATE  | 
    
  | 
  
ENDDATE  | 
    DATE  | 
    
  | 
  
CROPID  | 
    INTEGER  | 
    
  | 
  
CLASSID  | 
    INTEGER  | 
    
  | 
  
OWNERID  | 
    INTEGER  | 
    
  | 
  
Выходные параметры
Параметр  | Тип  | Описание  | 
|---|---|---|
INVENTORYID  | 
    INTEGER  | 
    
  | 
  
STARTDATE  | 
    DATE  | 
    
  | 
  
ALLWEIGHT  | 
    INTEGER  | 
    
  | 
  
DAYSTORE  | 
    INTEGER  | 
    
  | 
  
Описание
(Нет описания для процедуры AC_STORE_ILI)
Определение
CREATE PROCEDURE AC_STORE_ILI(
    PARTYID INTEGER,
    PARTYDATE DATE,
    BEGINDATE DATE,
    ENDDATE DATE,
    CROPID INTEGER,
    CLASSID INTEGER,
    OWNERID INTEGER)
RETURNS (
    INVENTORYID INTEGER,
    STARTDATE DATE,
    ALLWEIGHT INTEGER,
    DAYSTORE INTEGER)
AS
declare variable begpartydate date;
declare variable storeday integer;
declare variable minexp integer;
declare variable isfirst integer;
declare variable r1 date;
declare variable weight integer;
declare variable w1 integer;
declare variable d1 date;
declare variable ds date;
declare variable restday integer;
declare variable beg date;
BEGIN
  select first 1 ExportActs.RegDate
  from ExportActs
  where ExportActs.RegDate >= (select min(GetWorkParties.begindate)
                               from GetWorkParties(:PartyID,:PartyDate,null,null,null))
  order by RegDate
  into :BEGPARTYDATE;
  FOR
    select
      EAI.inventoryid,
      min(EA.regdate),
      min(EAI.exportactitemid),
      coalesce(Owner.storeday,0)
    from ExportActs EA
      join ExportActItems EAI on  (EA.ExportactID = EAI.ExportActID and not EAI.weight is null)
      join clients owner on (EA.ownerid = owner.clientid)
      join quality on (Ea.qualityid = quality.qualityid)
    where EA.RegDate between :BEGPARTYDATE and :EndDate
          and EA.OperationID in (1,17)
          and EA.state = 0
          and (quality.cropid = :cropid or (coalesce(:cropid,-1) = -1))
          and (quality.classid = :classid or (coalesce(:classid,-1) = -1))
          and ea.ownerid = :ownerid
    group by 1,4
    INTO :INVENTORYID,
         :STARTDATE,
         :minExp,
         :STOREDAY
  DO
  BEGIN
     w1 = null;
     ISFIRST = 1;
     allweight = 0;
     FOR
       select
         EA.regdate r1,
         case
           when (EAI.OperationID in (5,70,22))
             or (EAI.OperationID = 17 and EA.OwnerID <> :OwnerID)
           then -EAI.weight
           else EAI.weight
         end Weight
       from ExportActItems EAI
         join ExportActs EA on (EAI.exportactid = EA.exportactid and EA.state <> 10)
       where EAI.InventoryID = :InventoryID
         and (EAI.exportactitemid = :minExp or (EAI.parentitemid = :minExp))
       order by EAI.ExportActitemID, EA.regdate
       INTO :R1,
            :WEIGHT
       DO
       begin
         if (r1 >= :BEGPARTYDATE and r1 <= :EndDate) then
         begin
           if (:ISFIRST = 1) then
           begin
             ISFIRST = 0;
             w1 = :WEIGHT;
             beg = :begindate;
             ds = :STARTDATE;
             d1 = :R1;
             restday = :STOREDAY;
           end
          else
          begin
            ds = :d1;
            d1 = :r1;
            
           if (:weight < 0) then
           begin
             if (:restday > :d1 - :ds) then
               Daystore = 0;
             else
             begin
                 if (:beg <= :d1) then --дата
                   Daystore = :d1 - :ds - :restday;
                 else
                 begin
                   if (:beg - :ds >  :restday) then --дата
                     Daystore = :beg - :begindate;
                    else   begin
                      Daystore = :beg - :d1 ;
                   end
                  end
                 if (:restday > (d1 - ds)) then
                   restday = :restday - (d1 - ds);
                 else
                   restday = 0;
             end
             allweight = :w1;
             w1 = w1 + :weight;
             if (Daystore > 0) then begin
               suspend;
             end
          end
               --
          else if (:weight > 0) then
          begin
            if (:d1 = :ds) then
              w1 = w1 + :weight;
          end
        end
      if (:d1 <= :enddate and w1 > 0) then
      begin
        allweight = :w1;
        if (:restday > :enddate - :d1) then
          Daystore = 0;
        else
        begin
          if (:d1 >= :beg) then
            Daystore = :enddate - :d1 - :restday;
          else begin
            if (:beg - :d1 >=  :restday) then
              Daystore = :enddate - :beg ;--
            else   begin
              Daystore = :enddate - :d1 - :restday;
             end
           end
        end
      end
      end
      end
         if (:Daystore > 0 and :w1 > 0) then begin
           suspend;
         end
    END
END
         
         
         
       |