Name('Import sériových čísel');
Designed('Skl_Man#1');
Descr('Importuje sériová čísla z textového souboru')

WnsType(-1)
ModifyMode(True)

ImpKarta:String[14]='01 010 01'
ImpSklad:Word=1

Doklad:String[10]='IMPORT_SN';

DeclareRec('Sklad')
DeclareRec('KeySklad2')
DeclareRec('SkupinovaOperace')
DeclareRec('SerioveCislo')
DeclareRec('KeySerioveCislo3')
DeclareRec('Pohyb')
DeclareRec('Program')
DeclareRec('PohybSeriovehoCisla')

Veta:LongInt
VetaS:LongInt
VetaSO:LongInt
VetaP:LongInt
VetaSC:LongInt
VetaPSC:LongInt
Pos:LongInt

KeySklad2.Length=SizeOf(KeySklad2)-1;
KeySklad2.Sklad=Swap(ImpSklad)
StrToChars(KeySklad2.Material,ImpKarta,' ');
if(FindKey(KeySklad2,VetaS))
  begin
    ReadRec(Sklad,VetaS);
  end else
  begin
    Halt('Nebyla nalezena skladová karta číslo'+#13+ImpKarta+#13+'na skladě '+Str(ImpSklad),mb_IconStop);
  end;


ImpFileName:String=GetIni('IMPORT','SerNum');
ImpFileName=GetFileName(ImpFileName);
if(Length(ImpFileName)=0)
  Halt;
SetIni('IMPORT','SerNum',ImpFileName)

PF:TextFile;

ClearRec(SkupinovaOperace);

SkupinovaOperace.dt_Create=GetDate()
SkupinovaOperace.Create='IMPORT';
SkupinovaOperace.Cislo=GetNewIdent()
SkupinovaOperace.Datum=SkupinovaOperace.dt_Create
SkupinovaOperace.Doklad=ImpKarta

VetaSO=AddRec(SkupinovaOperace)
if(VetaSO=0)
  Halt;

Open(PF,ImpFileName)

LocStr:String;
Material:String[14];
Cena:String;
LocB:Byte;
Veta:LongInt;
Nacteno:LongInt
Zmeneno:LongInt
BezZmeny:LongInt
LocR:Real

Pohyb.dt_Create=SkupinovaOperace.dt_Create
Pohyb.Create=SkupinovaOperace.Create
Pohyb.Datum=SkupinovaOperace.Datum
Pohyb.CisloMat=Sklad.Cislo
Pohyb.Cislo=GetNewIdent();
Pohyb.Hrom=SkupinovaOperace.Cislo;
Pohyb.SubHrom=0;
Pohyb.Material=Sklad.Material
Pohyb.Popis=Sklad.Nazev
VetaP=AddRec(Pohyb)
if(VetaSO=0)
  Halt;

Counter:LongInt;

While(not EOF(PF)) do
  begin
    LocStr=ReadLn(PF);
    SetStatusRemark(LocStr);
    Inc(Nacteno)
    LocStr=ValidateStr(LocStr,'0123456789');
    if(Length(LocStr)<>0)
      begin
        ClearRec(KeySerioveCislo3);
        KeySerioveCislo3.Length=SizeOf(KeySerioveCislo3)-1;
        KeySerioveCislo3.CisloMat=Sklad.Cislo
        KeySerioveCislo3.Number=LocStr;
        if(not FindKey(KeySerioveCislo3,Veta)) then
          begin
            ClearRec(SerioveCislo);
            SerioveCislo.Cislo=GetNewIdent()
            SerioveCislo.CisloMat=Sklad.Cislo
            SerioveCislo.Number=LocStr
            SerioveCislo.VymezDate=Sklad.VymezDate
            SerioveCislo.VymezLimit=Sklad.VymezLimit
            SerioveCislo.Mnozstvi=1
            VetaSC=AddRec(SerioveCislo)
            if(VetaSC=0)
              Halt;
            ClearRec(PohybSeriovehoCisla)
            PohybSeriovehoCisla.Datum=Pohyb.Datum
            PohybSeriovehoCisla.CisloPH=Pohyb.Cislo
            PohybSeriovehoCisla.CisloSN=SerioveCislo.Cislo
            PohybSeriovehoCisla.Mnozstvi=1
            PohybSeriovehoCisla.CisloMat=Sklad.Cislo
            PohybSeriovehoCisla.CisloHP=SkupinovaOperace.Cislo
            VetaPSC=AddRec(PohybSeriovehoCisla);
            if(VetaPSC=0)
              Halt;
            Inc(Zmeneno);
            Inc(Pohyb.Mnozstvi)
          end;
      end;
  end;

ModifyRec(Pohyb,VetaP);
SkupinovaOperace.PolCount=1;
ModifyRec(SkupinovaOperace,VetaSO);
Inc(Sklad.PrijmyC)
Sklad.Prijmy=Sklad.Prijmy+Pohyb.Mnozstvi
ModifyRec(Sklad,VetaS);

Message('Načteno záznamů: '+Str(Nacteno)+#13+'Přidáno sériových čísel: '+Str(Zmeneno),mb_IconInformation);

END