; zjisti, u kterych pohybu neni evidovane seriove cislo
; verze z 10.1.2003
; Autor: WinDUO Team

Name('Faktury bez skladových pohybů')
Designed('SKL_MAN#1')
Author('Winduo Team','EMail: winduo@winduo.cz','http://www.winduo.com','http://www.winduo.cz')
Descr('Zjistí faktury, které obsahují skladový pohyb','ale tento pohyb není na skladě.');

WNSType(1);
NewWNS('NOSERNUM.WNS');

SetHeadColumn(0,TA_Left,10);
SetHeadColumn(1,TA_Left,10);
SetHeadColumn(2,TA_Left,30);
SetHeadOfHead('Pohledavka\tz data\tPopis');
SetColumn(0,TA_Left,14);
SetColumn(1,TA_Left,30);
SetColumn(2,TA_Left,12);
SetHead('Material\tNazev\tMnozstvi');

DeclareRec('Faktura')
DeclareRec('KeyFaktura1')
DeclareRec('Pohyb')
DeclareRec('KeyPohyb2')
DeclareRec('PohybSeriovehoCisla')
DeclareRec('KeyPohybSeriovehoCisla3')
ClearKey(KeySklad1)
Pozice:LongInt
InitStatus(UsedKeys(KeySklad1))
Veta:LongInt
VetaP:LongInt
VetaSNM:LongInt
CelkemSN:Double
LocBo:Boolean
LocBo2:Boolean
ItsHead:Boolean
While(NextKey(KeySklad1,Veta))
  begin
    ReadRec(Sklad,Veta)
    if((Sklad.Flags2&$1=0) and (InFilter(Sklad)))
      begin
        ItsHead=False
        KeyPohyb2.Length=4
        KeyPohyb2.CisloMat=SwapL(Sklad.Cislo)
        LocBo=SearchKey(KeyPohyb2,VetaP)
        While((LocBo) and (KeyPohyb2.CisloMat=SwapL(Sklad.Cislo)))
          begin
            ReadRec(Pohyb,VetaP);
            KeyPohybSeriovehoCisla3.Length=4;
            KeyPohybSeriovehoCisla3.CisloPH=SwapL(Pohyb.Cislo)
            CelkemSN=0
            LocBo2=SearchKey(KeyPohybSeriovehoCisla3,VetaSNM)
            While((LocBo2) and (KeyPohybSeriovehoCisla3.CisloPH=SwapL(Pohyb.Cislo)))
              begin
                ReadRec(PohybSeriovehoCisla,VetaSNM);
                if(Pohyb.Vydaj=PohybSeriovehoCisla.Vydaj)
                  CelkemSN=CelkemSN+PohybSeriovehoCisla.Mnozstvi
                else
                  CelkemSN=CelkemSN-PohybSeriovehoCisla.Mnozstvi
                LocBo2=NextKey(KeyPohybSeriovehoCisla3,VetaSNM);
              end;
            if(CelkemSN<>Pohyb.Mnozstvi)
              begin
                if(not ItsHead)
                  begin
                    AddComment('');
                    AddHeadLine(Sklad.Material,Str(Sklad.Sklad),Sklad.Nazev);
                    ItsHead=True
                  end
                if(Pohyb.Vydaj)
                  AddText('V\t')
                else
                  AddText('P\t')
                AddLine(Pohyb.Doklad,StrDate(Pohyb.Datum),StrNative(Pohyb.Mnozstvi,3),StrNative(CelkemSN,3));
              end
            LocBo=NextKey(KeyPohyb2,VetaP);
          end;
      end;
    Inc(Pozice)                  ; zvyseni citace zpracovanych vet
    SetStatus(Pozice)            ; nastaveni stavoveho prouzku
  end
END;


