// экспорт solaris-solaris из аптечного пункта, справочники не передаются!
// STDInOutCreateFile(Storage :integer; const DirName :string; FromDate :TDateTime; ToDate :TDateTime)

const OutputDir = 'c:\mail\out\';
      Storage  = 0; // Склад, информация по которому передается. Если 0, то не фильтруется

const
    InpReasonsList ='*Р'; // приходы, которые будут включаться в отчет.
var
    OutReasonsList :string = ''; // Расходы, которые включаются в экспорт. Программа добавит сюда все расходные накладные - чеки ТЗ


function MaxVAlue (VAl1,Val2 :integer) :integer;
begin
  if VAl1 >= Val2 then result := VAl1
  else Result := Val2;
end;

var Form :TForm;
    Lab,Lab2 :TLabel;
    Lab1 :TLabel;
    EditDate :TDateTimePicker;
    EditDate1 :TdateTimePicker;
    Bevel,Bevel1 :Tbevel;
    Button1 :Tbutton;
    Button2 :tButton;

    table :ttable;
begin


  table := ttable.create(nil);
  try
    table.databasename := 'dbkassa';
    table.tablename := 'osnov';
    table.open;

    table.first;
    while not table.eof do
    begin
      if (table.fieldbyname('isrs').asinteger=1)
         and (table.fieldbyname('iscash').asinteger<>0) // чеки ТЗ
      then begin
        if outreasonsList>'' then OutReasonsList := OutReasonsList + ',';
        OutReasonsList := OutReasonsList + QuotedStr(Table.fieldbyname('id').asstring);
      end;

      table.next;
    end;
  finally
    table.free
  end;


  Form := Tform.create(nil);
  try

    begin // создаем форму

      Form.Caption := 'Экспорт данных';
      Form.BorderStyle := bsDialog;
      Form.Width := 300;
      Form.Height := 200;
      Form.position := poScreenCenter;
      Form.Font.name := 'Tahoma';
      Form.ShowHint := true;


      Bevel := tbevel.create(form);
      Bevel.Shape := bsTopLine;
      Bevel.Height := 4;
      Bevel.align := alTop;
      bevel.parent := Form;


      Lab := TLabel.create(form); // удалять не нужно, Form его owner, сам удалит
      Lab.caption := 'Укажите начальную дату:';
      //Lab.font.size := 10;
      Lab.Top := 30;
      Lab.Left := 30; //(Form.clientWidth - Lab.Width) div 2;
      Lab.parent := Form;


      Lab1 := TLabel.create(form); // удалять не нужно, Form его owner, сам удалит
      Lab1.caption := 'Укажите конечную дату:';
      //Lab.font.size := 10;
      Lab1.Top := Lab.Top + Lab.height + 20;
      Lab1.Left := 30; //(Form.clientWidth - Lab.Width) div 2;
      Lab1.parent := Form;


      EditDate := TDateTimePicker.create(Form);
      EditDate.Top := Lab.Top - (EditDAte.height - Lab.Height) div 2  ; //+Lab.Height + 10;
      EditDate.width := 100;
      EditDate.Left := Lab.LEft + maxvalue(Lab.Width,lab1.width) + 20; // (Form.clientWidth - Editdate.width) div 2;
      Editdate.parent := Form;

      Form.clientWidth := EditDate.Left + EditDate.width + 30;


      EditDate1 := TDateTimePicker.create(Form);
      EditDate1.Top := Lab1.Top - (EditDAte1.height - Lab1.Height) div 2  ; //+Lab.Height + 10;
      EditDate1.width := 100;
      EditDate1.Left := EditDate.LEft; // (Form.clientWidth - Editdate.width) div 2;
      Editdate1.parent := Form;
      Editdate1.date := date;



      Bevel1 := TBevel.create(Form);
      Bevel1.shape := bsTopLine;
      Bevel1.Height := 4;
      Bevel1.Width := Form.clientWidth - 30;
      Bevel1.Left := (Form.ClientWidth - Bevel1.Width) div 2;
      Bevel1.Top := Editdate1.Top + EditDate1.Height + 20;
      Bevel1.parent := Form;

      Button1 := Tbutton.create(Form);
      Button1.Caption := 'Старт';
      Button1.Width := 70;
      Button1.ModalResult := mrOk;
      Button1.Top := Bevel1.Top + 13;
      button1.Default := true;
      Button1.Parent := Form;


      Button2 := Tbutton.create(Form);
      Button2.Caption := 'Отмена';
      Button2.Width := 70;
      Button2.ModalResult := mrCancel;
      Button2.Top := Button1.top;
      Button2.left := Form.ClientWidth - Button2.Width - 35;
      Button2.Cancel := true;
      Button2.Parent := Form;

      Button1.left := Button2.left - Button1.width - 5;


      Form.clientHeight := Button1.Top + Button1.height + 15;

    end;

    EditDate.date := date;

    if Form.ShowModal = mrOk
    then begin
      ForceDirectories(OutputDir);
      STDInOutCreateFile(Storage, outputdir, Editdate.date,EditDate1.date,true,false,
                         InpReasonsList,
                         OutReasonsList);
    end;
  finally
    Form.free;
  end;


end.
