// ïåðåäà÷à äåôåêòóðû ïî ñêðèïòó â xprice-rtl

const subscriber = 365; // Îôèñ Ýôåäðû

var DATASET :TClientDataset; // äàòàñåò, ïåðåäàþùèé äàííûå


var
  Table :TTable;
begin

  with tMyWait.create('Èäåò ýêñïîðò çàÿâêè') do
  try
    ForceDirectories(ExportPath);

    TAble := TTable.create(nil);
    try
      Table.tablename := ExportPath+ExportFileName;
      table.exclusive := true;

      if fileexists(BulkFILEName)
      then begin
        CopyFile(BulkFileName,Table.tablename);
        table.emptyTable;
      end
      else begin
        table.fielddefs.clear;
        Table.fielddefs.add('CODE',ftString,20,false);
        table.fielddefs.add('NAME',ftSTring,200,false);
        Table.fielddefs.add('PRICE',ftFloat,0,false);
        Table.FieldDefs.add('QUANTITY',ftFLoat,0,false);
        Table.CreateTable;
      end;

      Table.open;

      Dataset.filter := '[KOL] > 0';
      Dataset.filtered := true;

      progressbarmax := dataset.recordcount;
      progressbarpos := 0;

      dataset.first;
      while not dataset.eof do
      begin
        table.append;
        table.fieldbyname('CODE').asString := dataset.fieldbyname('NN').asString;
        table.fieldbyname('NAME').asstring := dataset.fieldbyname('name').asstring;
        table.fieldbyname('price').asfloat := dataset.fieldbyname('cena').asfloat;
        table.fieldbyname('Quantity').asfloat := dataset.fieldbyname('kol').asfloat;
        table.post;
        dataset.next;
        IncProgress;
      end;



    finally
      Table.free
    end;

    hide; // wsitform
    CreateHintI('Îïåðàöèÿ çàâåðøåíà','Ïåðåäà÷à äåôåêòóðû',20);
  finally
    free
  end;


end.
