Задача следующая - к каждой накладной привязана ЛЗК, в которой прописан лимит по каждой МЦ на определенный период. Мы можем посмотреть какие накладные уже сформированы по данной ЛЗК и соответственно просуммировать кол-во, чтобы посмотреть есть еще матценности в наличии или уже все распределены по накладным.. Для накладной на отпуск в производстве есть вот такой запрос:
Код: Выделить всё
.create view Lim as
select * from stepdoc(readonly),spstep(readonly),spsopr(readonly),
synonym spsopr spsopr2(readonly), sporder(readonly), sklorder(readonly)
where ((comp(BaseDocNRec)==stepdoc.cbasedoc
and comp(SPSOPRNREC)==spsopr2.nrec
and stepdoc.nrec==katsopr.cstepdoc
and katsopr.nrec==spsopr.Csopr
and katsopr.nrec==sklorder.Csopr
and word(1)==sklorder.vidorder
and sklorder.nrec== sporder.csklorder
and spsopr2.cmcusl==sporder.cmc
and spsopr2.cmcusl==spsopr.cmcusl
));
Код: Выделить всё
if (lim.getfirst stepdoc=0) then
  Do {LZK:=true;
  if (lim.getfirst spsopr2=0) then
   do { if (lim.getfirst katsopr=0) then
      do { if (lim.getfirst spsopr=0) then
      do { lim_nakl:=lim_nakl+double(lim.spsopr.kolfact);
        if (Lim.getfirst sklorder=0) then
        do { if (Lim.getfirst sporder=0)
           do{ 
              lim_ost:=lim_ost+double(lim.sporder.KOL);
           } while (Lim.getnext sporder=0)
       }while (Lim.getnext sklorder)=0
     } while (Lim.getnext spsopr)=0
  } while (Lim.getnext katsopr)=0
} while (Lim.getnext spsopr2)=0
} while (Lim.getnext stepdoc)=0
lim:=double(SUMMA_LIM)-lim_nakl/koeff+double(KOL_F);
if ((lim+0.0000000000001)< kol_f and (LZK=true)) then 
{ message(’Вы превысили лимит!  Позиция: ’+ Name.katmc.name + ’ Остаток по лимиту:  ’ +lim,tsok);
Код: Выделить всё
.create view Lim as
select * from stepdoc(readonly),spstep(readonly),spsopr(readonly),
synonym spsopr spsopr2(readonly), sporder(readonly), sklorder(readonly),katsopr katsopr2,stepdoc stepdoc2
where ((НрекДокумента ==katsopr2.nrec
    and 1109==attrnam.wtable
    and ’1_ЛЗК для МЦ-МБП’==attrnam.name
    and 1109==attrval.wtable
    and katsopr2.nrec ==attrval.crec
    and attrnam.nrec==attrval.cattrnam
and attrval.vcomp==stepdoc2.nrec
and stepdoc2.cbasedoc==basedoc.nrec
and stepdoc2.nrec==spstep.cstepdoc
and НрекПозиции ==spsopr2.nrec
and katsopr.cstepdoc== stepdoc.nrec
and katsopr.nrec==spsopr.Csopr
and katsopr.nrec==sklorder.Csopr
and word(1)==sklorder.vidorder
and sklorder.nrec== sporder.csklorder
and spsopr2.cmcusl==sporder.cmc
and spsopr2.cmcusl==spsopr.cmcusl
));
Код: Выделить всё
if (lim.getfirst katsopr2= 0) then 
if (lim.getfirst attrnam= 0) then
 if (lim.getfirst attrval= 0) then
if (lim.getfirst stepdoc2= 0) then
if (lim.getfirst basedoc= 0) then
  Do {  LZK:=true;
  if (lim.getfirst spsopr2=0) then
   do {    if (lim.getfirst katsopr=0) then
      do {    if (lim.getfirst spsopr=0) then
         do { lim_nakl:=lim_nakl+double(lim.spsopr.kolfact);
          if (Lim.getfirst sklorder=0) then
            do {   if (Lim.getfirst sporder=0)
               do{ 
                    lim_ost:=lim_ost+double(lim.sporder.KOL);
                  } while (Lim.getnext sporder=0)
             }     while (Lim.getnext sklorder)=0
            } while (Lim.getnext spsopr)=0
       } while (Lim.getnext katsopr)=0
   } while (Lim.getnext spsopr2)=0
  } while (Lim.getnext stepdoc)=0;
lim:=double(SUMMA_LIM)-lim_nakl/koeff+double(KOL_F);
if ((lim+0.0000000000001)< kol_f and (LZK=true)) then 
{ message(’Вы превысили лимит!  Позиция: ’+ Namemc + ’ Остаток по лимиту:  ’ +lim,tsok);