Name('Obnova cen po přepočtu')      ; pod tímto názvem bude sestava v menu
Designed('WinDUO');

DeclareRec('Log');
DeclareRec('KeyLog1');
DeclareRec('Pohyb');
DeclareRec('KeyPohyb1');

PohybOld:Pohyb
PohybNew:Pohyb
PohybOld2:Pohyb
PohybNew2:Pohyb
IsModify:Boolean

WNSType(1);
NewWNS('tntrade1.wns');

SetColumn(0,ta_right,6);
SetColumn(1,ta_left,14);
SetColumn(2,ta_Right,12);
SetColumn(3,ta_Right,12);
SetColumn(4,ta_Right,12);
SetColumn(5,ta_Right,12);
SetHead('p.č.\tČíslo\tJedn.cena.\tCelkem\tJedn.cena po\tCelkem po');

CurTime:LongInt=GetDate()*65536+GetTime();

KeyLog1.Length=4;
Datum:Word=ValDate('25.9.2005')
ProDen:LongInt=SwapL(Datum*65536);
KeyLog1.Kdy=ProDen;
Zmeneno:LongInt;
Veta:LongInt;
VetaP:LongInt;
LocBo:Boolean=SearchKey(KeyLog1,Veta);
While((LocBo) and (LongInt(SwapL(KeyLog1.Kdy)/65536)=Datum) and (SwapL(KeyLog1.Kdy)<CurTime))
  begin
    ReadRec(Log,Veta);
    if((Log.FileID=20)and(Log.Ident=803))
      begin
        ReadRecFromLog(PohybOld,Log.OldRec);
        ReadRecFromLog(PohybNew,Log.NewRec);
        PohybOld2=PohybOld
        PohybNew2=PohybNew
        PohybOld2.Castka=0;
        PohybOld2.JednCena=0;
        PohybNew2.Castka=0;
        PohybNew2.JednCena=0;
        if((CompareRec(PohybOld2,PohybNew2)) and (not CompareRec(PohybOld,PohybNew))) then
          begin
            KeyPohyb1.Length=4;
            KeyPohyb1.Cislo=SwapL(PohybOld.Cislo);
            if(FindKey(KeyPohyb1,VetaP))
              begin
                ReadRec(Pohyb,VetaP);
                SetStatusRemark(Pohyb.Material);
                if((Pohyb.Castka<>PohybOld.Castka) or (Pohyb.JednCena<>PohybOld.JednCena))
                  begin
                    if(not IsModify)
                      begin
                        ModifyMode(True);
                        IsModify=True
                      end;
                    Inc(Zmeneno);
                    AddLine(Str(Zmeneno),Pohyb.Material,StrPrice(Pohyb.JednCena),StrFinanc(Pohyb.JednCena),StrPrice(PohybOld.JednCena),StrFinanc(PohybOld.JednCena));
                    Pohyb=PohybOld
                    ModifyRec(Pohyb,VetaP);
                  end;
              end;
          end;
      end;
    LocBo=NextKey(KeyLog1,Veta);
  end;

Message('Přepočet byl ukončen\rzměněno vět:\r'+Str(Zmeneno));

END