unit P_ftp;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, backup, FileCtrl, ComCtrls, RzButton,
  IvDictio, IvMulti, Mask, ToolEdit, DBTables, Db, Psock, NMFtp, DBCtrls,
  RzDBCmbo, AdvCircularProgress, frxpngimage, ExtCtrls, EXLReportExcelTLB,
  EXLReportBand, EXLReport, Menus;

type
  Tf_ftp = class(TForm)
    Label1: TLabel;
    BitBtn1: TBitBtn;
    l_file: TLabel;
    prog: TProgressBar;
    list: TListBox;
    Back: TBackupFile;
    IvTranslator1: TIvTranslator;
    fomcomp: TFilenameEdit;
    bmstock: TBatchMove;
    tostock: TTable;
    bmuser: TBatchMove;
    touser: TTable;
    bmcurr: TBatchMove;
    tocurr: TTable;
    fromstock: TQuery;
    bminv: TBatchMove;
    toinv: TTable;
    bmitems: TBatchMove;
    destitems: TTable;
    toitems: TTable;
    sourceinvoice: TTable;
    frombar: TTable;
    bmbar: TBatchMove;
    tobar: TTable;
    fromuser: TTable;
    bmmyinv: TBatchMove;
    myINVOICE: TTable;
    fromsub: TTable;
    Bmsub: TBatchMove;
    tosub: TTable;
    sourceitems2: TTable;
    bmitemsnovat: TBatchMove;
    fromall: TTable;
    destall: TTable;
    bmall: TBatchMove;
    mysinvoice: TTable;
    ittriggerbd: TQuery;
    NMFTP1: TNMFTP;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    sourcesub: TTable;
    bmsub2: TBatchMove;
    destsub: TTable;
    sourcestock: TTable;
    bmstock2: TBatchMove;
    deststock: TTable;
    sourcebar: TTable;
    bmbar2: TBatchMove;
    destbar: TTable;
    sourceuser: TTable;
    bmuser2: TBatchMove;
    destuser: TTable;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    RzBitBtn5: TRzBitBtn;
    myinv: TQuery;
    myitems: TQuery;
    mypaym: TQuery;
    topaym: TTable;
    bmpaym: TBatchMove;
    mydescr: TQuery;
    mydescrID: TIntegerField;
    mydescrMID: TIntegerField;
    mydescrDESCR: TStringField;
    DataSource1: TDataSource;
    myinv2: TTable;
    myitems2: TTable;
    mypaym2: TTable;
    bminv2: TBatchMove;
    bmitems2: TBatchMove;
    bmpaym2: TBatchMove;
    toinv2: TTable;
    toitems2: TTable;
    topaym2: TTable;
    bmdelinv: TBatchMove;
    bmdelpaym: TBatchMove;
    DateEdit1: TDateEdit;
    DateEdit2: TDateEdit;
    RzBitBtn2: TRzBitBtn;
    fromsub2: TTable;
    bmsub22: TBatchMove;
    tosub2: TTable;
    RzBitBtn6: TRzBitBtn;
    fromdescr: TQuery;
    bmdescr: TBatchMove;
    Table1: TTable;
    sourcedescr: TTable;
    bmdescr2: TBatchMove;
    Table3: TTable;
    bminv2old: TBatchMove;
    Animate1: TAdvCircularProgress;
    RzBitBtn7: TRzBitBtn;
    RzBitBtn8: TRzBitBtn;
    Image1: TImage;
    fromjob: TTable;
    tojob: TTable;
    bmjob: TBatchMove;
    FromDepart: TTable;
    bmdepart: TBatchMove;
    todepart: TTable;
    fromcontact: TTable;
    bmcontact: TBatchMove;
    tocontact: TTable;
    fromware: TTable;
    bmware: TBatchMove;
    toware: TTable;
    bmjob2: TBatchMove;
    bmdepart2: TBatchMove;
    bmcontact2: TBatchMove;
    bmware2: TBatchMove;
    Query1: TQuery;
    uuu: TDatabase;
    fDEPOSIT: TQuery;
    bmDEPOSIT: TBatchMove;
    bmDEPOSIT2: TBatchMove;
    toDEPOSIT: TTable;
    fDDEPOSIT: TQuery;
    bmDDEPOSIT: TBatchMove;
    bmDDEPOSIT2: TBatchMove;
    toDDEPOSIT: TTable;
    bmdeldeposit: TBatchMove;
    toDEPOSIT2: TTable;
    toDDEPOSIT2: TTable;
    fdeposit2: TTable;
    fddeposit2: TTable;
    bmfcurr: TBatchMove;
    bmfcurr2: TBatchMove;
    tocurr2: TTable;
    fcurr: TQuery;
    fcurr2: TTable;
    CONFIGS: TTable;
    CONFIGSFTPDAYS: TIntegerField;
    myfile: TLabel;
    CONFIGSFTPPASS: TStringField;
    CONFIGSFTPFILEST: TStringField;
    CONFIGSFTPFILEJOB: TStringField;
    CONFIGSID: TIntegerField;
    wwww: TRzBitBtn;
    items3: TQuery;
    EXLReport1: TEXLReport;
    CONTACT: TQuery;
    Query1ID: TIntegerField;
    Query1NAME: TStringField;
    Query1COMPANY: TStringField;
    Query1JOBDESCR: TStringField;
    Query1WPHONE: TStringField;
    Query1HPHONE: TStringField;
    Query1CELL: TStringField;
    Query1ADDRESS1: TStringField;
    Query1ADDRESS2: TStringField;
    Query1FAX: TStringField;
    Query1EMAIL: TStringField;
    Query1POBOX: TStringField;
    Query1NOTE: TStringField;
    Query1CRADNO: TStringField;
    Query1POINTIN: TFloatField;
    Query1POINTOUT: TFloatField;
    Query1BALANCE: TFloatField;
    Query1TOTAL: TFloatField;
    Query1BAL: TFloatField;
    items3ID: TIntegerField;
    items3MID: TStringField;
    items3ITEM: TStringField;
    items3SITE: TStringField;
    items3STTYPE: TStringField;
    items3QTY: TFloatField;
    items3FRAC: TFloatField;
    items3PACK: TFloatField;
    items3PRICE: TFloatField;
    items3DISCOUNT: TFloatField;
    items3VAT: TFloatField;
    items3COSTUS: TFloatField;
    items3COSTLC: TFloatField;
    items3CATREGORYID: TIntegerField;
    items3VATAMOUNT: TFloatField;
    items3DEBITUS: TFloatField;
    items3CREDITUS: TFloatField;
    items3BARCODE: TStringField;
    items3BONENO: TStringField;
    items3DEBITQTY: TFloatField;
    items3CREDITQTY: TFloatField;
    items3YESNO: TStringField;
    items3TOTAL: TFloatField;
    items3FDATE: TDateTimeField;
    items3ALLQTY: TFloatField;
    items3JOB: TIntegerField;
    items3SID: TStringField;
    items3SALESMAN: TIntegerField;
    items3CONTACT: TIntegerField;
    items3TSITE: TStringField;
    items3DEBITLC: TFloatField;
    items3CLC: TFloatField;
    items3CREDITLC: TFloatField;
    items3STQTY: TFloatField;
    items3CURRFAC: TIntegerField;
    items3AUTOCURRFAC: TIntegerField;
    items3PRN: TStringField;
    items3DESCR: TStringField;
    items3MYPRN: TStringField;
    items3EXTYESNO: TIntegerField;
    items3FIDATE: TDateTimeField;
    items3CRADNO: TStringField;
    PopupMenu1: TPopupMenu;
    designexcel1: TMenuItem;
    OpenD: TOpenDialog;
    items3WPHONE: TStringField;
    items3ftime: TTimeField;
    upitems3: TQuery;
    items3FAX: TStringField;
    procedure BitBtn2Click(Sender: TObject);
    procedure BackProgress(Sender: TObject; Filename: String;
      Percent: TPercentage; var Continue: Boolean);
    procedure BitBtn3Click(Sender: TObject);
    procedure BackRestoreFile(Sender: TObject; var Filename: String;
      FA: Integer; var DoRestore: Boolean);
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure RzBitBtn3Click(Sender: TObject);
    procedure NMFTP1ConnectionFailed(Sender: TObject);
    procedure RzBitBtn5Click(Sender: TObject);
    procedure RzBitBtn4Click(Sender: TObject);
    procedure RzBitBtn6Click(Sender: TObject);
    procedure NMFTP1Connect(Sender: TObject);
    procedure NMFTP1Disconnect(Sender: TObject);
    procedure NMFTP1Failure(var Handled: Boolean; Trans_Type: TCmdType);
    procedure RzBitBtn7Click(Sender: TObject);
    procedure RzBitBtn8Click(Sender: TObject);
    procedure uuuBeforeConnect(Sender: TObject);
    procedure items3BeforeOpen(DataSet: TDataSet);
    procedure wwwwClick(Sender: TObject);
    procedure EXLReport1GetReportFileName(Sender: TObject;
      var FileName: String);
    procedure items3AfterClose(DataSet: TDataSet);
    procedure designexcel1Click(Sender: TObject);
    procedure items3CalcFields(DataSet: TDataSet);
    procedure upitems3BeforeOpen(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_ftp: Tf_ftp; i:integer; filennn:string;

implementation

uses p_repmodule, p_posmodule;





{$R *.DFM}

procedure Tf_ftp.BitBtn2Click(Sender: TObject);
var s:string;
begin


   try
      mkdir(EXTRACTFILEPATH(application.ExeName) +'export');
   except
   end;
   try

   try

 fromstock.open;
bmstock.Execute;
frombar.open;
bmbar.Execute;
fromsub.open;
 fromuser.open;
bmuser.Execute;
bmcurr.execute;
bmsub.execute;
except
end;
fromstock.close;
  fromuser.close;
  fromsub.close;
   list.Clear;

   list.Items.Add(EXTRACTFILEPATH(application.ExeName) +'export\*.*');


   back.Backup(list.Items,fomcomp.FileName+'.dsz');
  except
showmessage('Error to export..');
  end;
  prog.Position:=0;
showmessage('Export To File Is Done..');
  end;

procedure Tf_ftp.BackProgress(Sender: TObject; Filename: String;
  Percent: TPercentage; var Continue: Boolean);
begin
l_file.Caption:=filename;
prog.Position:=percent;
end;

procedure Tf_ftp.BitBtn3Click(Sender: TObject);
var s:string;
begin

TRY
ITTRIGGERBD.ExecSQL;
EXCEPT
END;

i:=1;



   s:=EXTRACTFILEPATH(application.ExeName)+'import';


   try
      mkdir(s);
   except
   end;


  try


  {
   TRY
   mkdir(EXTRACTFILEPATH(application.ExeName)+'RESTORE\')
   EXCEPT
   END;
  }
   back.restore(fomcomp.FileName,s);

  prog.Position:=0;
   except
   end;

try
posmodule.server.StartTransaction;
posmodule.server.Execute('delete from allitems');
posmodule.server.Execute('delete from myinvoice');
posmodule.server.Commit;
except
if posmodule.server.InTransaction then
posmodule.server.Rollback;
end;


// module.master.StartTransaction;

   sourceinvoice.open;




try
sourceitems2.open;
except
end;
try
   myitems.open;
   except
   end;


   if CheckBox1.Checked then
   begin


    bmitems2.Execute;


   end
   else
   begin





if (checkbox2.Checked) then
bmitemsnovat.Execute
else
   bmitems.Execute;

   end;

TRY
 bmmyinv.Execute;

EXCEPT
SHOWMESSAGE('MYINVOI');
exit;
END;

//module.master.execute('delete from myinvoice where id  in (select transno from saccount where closing=''True'')');
//module.master.Execute('delete from allitems where mid in (select transno from saccount where closing=''True'')');
//module.master.Execute('delete from allitems where mid not in (select id from myinvoice)');

//module.master.StartTransaction;
TRY
posmodule.server.StartTransaction;
posmodule.server.Execute('delete from invoice where id in (select id from myinvoice ) ');

posmodule.server.Commit;

bminv.Execute;

 if CheckBox1.Checked then
BMALL.Mappings.Text:= bmitems2.Mappings.Text

 else
if CheckBox2.Checked then
BMALL.Mappings.Text:= bmitemsnovat.Mappings.Text
else
BMALL.Mappings.Text:= bmitems.Mappings.Text;

FROMALL.OPEN;
BMALL.Execute;
//module.master.Commit;

try
posmodule.server.Execute('update saccount set closing=''True'' where atype=1 and transno in (select id from myinvoice)');
except
end;

showmessage('Import From File Is Done..');
  except
showmessage('Error to Import..');
if posmodule.server.InTransaction then posmodule.server.Rollback;
  end;

  prog.Position:=0;

  sourceinvoice.close;
   myitems.close;
   sourceitems2.close;
  FROMALL.CLOSE;


end;

procedure Tf_ftp.BackRestoreFile(Sender: TObject; var Filename: String;
  FA: Integer; var DoRestore: Boolean);
begin
l_file.Caption:=filename;
prog.Position:=fa;
end;

procedure Tf_ftp.FormShow(Sender: TObject);
var f:textfile;s:string;
begin
try
if FileExists(extractfilepath(application.ExeName)+'ip.txt') then
begin
assignfile(f,extractfilepath(application.ExeName)+'ip.txt');
reset(f);
readln(f,s);
 closefile(f);
myfile.Caption:=ExtractFileName(s)+'.dsz';
 end
else
begin
showmessage('Ftpdata.txt Not Fount');
close;
end;
except
end;


i:=0;
try
configs.open;
except
end;

dateedit2.Text:=datetostr(date);
dateedit1.Text:=datetostr(date-CONFIGSFTPDAYS.AsInteger);

 mydescr.open;

end;

procedure Tf_ftp.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
{if (i=1) then
begin

try
module.master.StartTransaction;


repmodule.sourcesite.open;

repmodule.bmsites.Execute;
module.master.commit;


except
showmessage('Try Again Later!!');
module.master.Rollback;
end;
repmodule.sourcesite.close;

end;
}
mydescr.close;
configs.close;

TRY
UUU.Connected:=FALSE;
EXCEPT
END;
end;

procedure Tf_ftp.RzBitBtn2Click(Sender: TObject);
var s,s1,s2,s3,s4,s5:string; f:textfile;
begin

 if posmodule.touser.FieldByName('FTPDSTOCK').AsString<>'True' then
 begin
showmessage('No priviligies!!' );
exit;
 end;

if FileExists(extractfilepath(application.ExeName)+'ftp.txt') then
begin
assignfile(f,extractfilepath(application.ExeName)+'ftp.txt');
reset(f);
readln(f,s1);
readln(f,s2);
readln(f,s3);
readln(f,s4);
readln(f,s5);
 closefile(f);

if (trim(CONFIGSFTPFILEST.AsString)>'') then
s5:=CONFIGSFTPFILEST.AsString;
s3:=CONFIGSFTPPASS.AsString;
 if trim(s3)='' then
s3:=inputbox('Enter The Password : ','','');
NMFTP1.Host:=s1;
NMFTP1.UserID:=s2;
NMFTP1.Password:=s3;

NMFTP1.Connect;

NMFTP1.ChangeDir(s4);

  NMFTP1.Mode(MODE_BYTE);
Animate1.visible:=true;
Animate1.Enabled:=true;
  NMFTP1.Download(s5,'c:\myminerva.dsz');
 prog.Position:=0;
 Animate1.visible:=false;
Animate1.Enabled:=false;
showmessage('complete');

NMFTP1.Disconnect;






   s:=EXTRACTFILEPATH(application.ExeName)+'import';


   try
      mkdir(s);
   except
   end;
try


  {
   TRY
   mkdir(EXTRACTFILEPATH(application.ExeName)+'RESTORE\')
   EXCEPT
   END;
  }
   back.restore('c:\myminerva.dsz',s);


   except
   end;

// sourcesub.open;
// bmsub2.execute;
// sourcesub.close;
try
 sourcestock.open;
 bmstock2.execute;
 except
 end;
 sourcestock.close;
try
 sourcebar.open;

 bmbar2.execute;
except
end;
 sourcebar.close;
 try
 fromsub2.open;
 bmsub22.execute;
except
end;
 fromsub2.close;
try
 sourceuser.open;
 bmuser2.execute;
except
end;
 sourceuser.close;
try
  sourcedescr.open;
 bmdescr2.execute;
except
end;
 sourcedescr.close;
 prog.Position:=0;
end;

end;

procedure Tf_ftp.RzBitBtn3Click(Sender: TObject);
var s,s1,s2,s3,s4,s5:string; f:textfile;
begin
 if posmodule.touser.FieldByName('FTPuSTOCK').AsString<>'True' then
 begin
showmessage('No priviligies!!' );
exit;
 end;
if FileExists(extractfilepath(application.ExeName)+'ftp.txt') then
begin
assignfile(f,extractfilepath(application.ExeName)+'ftp.txt');
reset(f);
readln(f,s1);
readln(f,s2);
readln(f,s3);
readln(f,s4);
readln(f,s5);
 closefile(f);
 if (trim(CONFIGSFTPFILEST.AsString)>'') then
s5:=CONFIGSFTPFILEST.AsString;
s3:=CONFIGSFTPPASS.AsString;

end;

   try
      mkdir(EXTRACTFILEPATH(application.ExeName) +'export');
   except
   end;
   try

   try
fromstock.sql.Strings[1]:=' ';
 fromstock.open;
bmstock.Execute;
fromstock.close;
frombar.open;
bmbar.Execute;
  frombar.close;
fromsub.open;
 fromuser.open;
bmuser.Execute;
  fromuser.close;
//bmcurr.execute;
bmsub.execute;
fromdescr.Open;
bmdescr.Execute;
fromdescr.close;
except
end;



   list.Clear;

   list.Items.Add(EXTRACTFILEPATH(application.ExeName) +'export\*.*');


   back.Backup(list.Items,s5);
  except
showmessage('Error to export..');
  end;

//showmessage('Export To File Is Done..');
 if trim(s3)='' then
s3:=inputbox('Enter The Password : ','','');
NMFTP1.Host:=s1;
NMFTP1.UserID:=s2;
NMFTP1.Password:=s3;

NMFTP1.Connect;

NMFTP1.ChangeDir(s4);

NMFTP1.Mode(MODE_BYTE);
Animate1.visible:=true;
Animate1.Enabled:=true;

NMFTP1.Upload(s5,s5);
Animate1.visible:=false;
Animate1.Enabled:=false;
 prog.Position:=0;

showmessage('complete');

NMFTP1.Disconnect;
end;


procedure Tf_ftp.NMFTP1ConnectionFailed(Sender: TObject);
begin
showmessage(' The Password Is Not Correct!!!')
end;

procedure Tf_ftp.RzBitBtn5Click(Sender: TObject);
var s,s1,s2,s3,s4,s5:string; f:textfile;
begin
 if posmodule.touser.FieldByName('FTPuTRANS').AsString<>'True' then
 begin
showmessage('No priviligies!!' );
exit;
 end;
if FileExists(extractfilepath(application.ExeName)+'ftp.txt') then
begin
assignfile(f,extractfilepath(application.ExeName)+'ftp.txt');
reset(f);
readln(f,s1);
readln(f,s2);
readln(f,s3);
readln(f,s4);
readln(f,s5);
 closefile(f);
 IF CONFIGS.Active=FALSE THEN
 CONFIGS.OPEN;
 s3:=CONFIGSFTPPASS.AsString;
end;

   try
      mkdir(EXTRACTFILEPATH(application.ExeName) +'ftpexport');
   except
   end;
   try

   try
               mypaym.ParamByName('fromdate').AsDate:=strtodate(dateedit1.text);
mypaym.ParamByName('todate').AsDate:=strtodate(dateedit2.text);

myinv.ParamByName('fromdate').AsDate:=strtodate(dateedit1.text);
myinv.ParamByName('todate').AsDate:=strtodate(dateedit2.text);
myitems.ParamByName('fromdate').AsDate:=strtodate(dateedit1.text);
myitems.ParamByName('todate').AsDate:=strtodate(dateedit2.text);




mypaym.open;
bmpaym.Execute;
mypaym.close;
myinv.open;
bminv.Execute;
myinv.close;
myitems.open;
bmitems.Execute;
myitems.close;
 try
fdeposit.ParamByName('fromdate').AsDate:=strtodate(dateedit1.text);
fdeposit.ParamByName('todate').AsDate:=strtodate(dateedit2.text);
fddeposit.ParamByName('fromdate').AsDate:=strtodate(dateedit1.text);
fddeposit.ParamByName('todate').AsDate:=strtodate(dateedit2.text);


fdeposit.Open;
bmDEPOSIT.Execute;
fddeposit.Open;
bmdDEPOSIT.Execute;
 except
 end;
fdeposit.close;
fddeposit.close;
//bmcurr.execute;
//bmsub.execute;
except
end;

s5:= myfile.Caption ;

   list.Clear;

   list.Items.Add(EXTRACTFILEPATH(application.ExeName) +'ftpexport\*.*');


   back.Backup(list.Items,s5);
  except
showmessage('Error to export..');
  end;

//showmessage('Export To File Is Done..');
 if trim(s3)='' then
s3:=inputbox('Enter The Password : ','','');
NMFTP1.Host:=s1;
NMFTP1.UserID:=s2;
NMFTP1.Password:=s3;

NMFTP1.Connect;

NMFTP1.ChangeDir(s4);

NMFTP1.Mode(MODE_BYTE);
Animate1.visible:=true;
Animate1.Enabled:=true;

NMFTP1.Upload(s5,s5);
Animate1.visible:=false;
Animate1.Enabled:=false;
 prog.Position:=0;

showmessage('complete');

NMFTP1.Disconnect;

end;

procedure Tf_ftp.RzBitBtn4Click(Sender: TObject);
var s,s1,s2,s3,s4,s5:string; f:textfile;
begin
 if posmodule.touser.FieldByName('FTPDTRANS').AsString<>'True' then
 begin
showmessage('No priviligies!!' );
exit;
 end;
if FileExists(extractfilepath(application.ExeName)+'ftp.txt') then
begin
assignfile(f,extractfilepath(application.ExeName)+'ftp.txt');
reset(f);
readln(f,s1);
readln(f,s2);
readln(f,s3);
readln(f,s4);
readln(f,s5);
 closefile(f);
s3:=CONFIGSFTPPASS.AsString;
s5:=mydescrDESCR.AsString+'.dsz';

 if trim(s3)='' then
s3:=inputbox('Enter The Password : ','','');
NMFTP1.Host:=s1;
NMFTP1.UserID:=s2;
NMFTP1.Password:=s3;

NMFTP1.Connect;

NMFTP1.ChangeDir(s4);

  NMFTP1.Mode(MODE_BYTE);
Animate1.visible:=true;
Animate1.Enabled:=true;
  NMFTP1.Download(s5,'c:\myminerva.dsz');
 prog.Position:=0;
 Animate1.visible:=false;
Animate1.Enabled:=false;
showmessage('complete');

NMFTP1.Disconnect;






   s:=EXTRACTFILEPATH(application.ExeName)+'import';


   try
      mkdir(s);
   except
   end;
try


  {
   TRY
   mkdir(EXTRACTFILEPATH(application.ExeName)+'RESTORE\')
   EXCEPT
   END;
  }
   back.restore('c:\myminerva.dsz',s);


   except
   end;

try
 UUU.Connected:=TRUE;

 uuu.Execute('alter table invoice add tsite varchar(3)');

  UUU.Connected:=FALSE;
  UUU.Connected:=TRUE;
 uuu.Execute('alter table INVOICE add NOTE varchar(100)');
  UUU.Connected:=FALSE;
  UUU.Connected:=TRUE;
 uuu.Execute('alter table INVOICE add PAID NUMERIC');
 except
end;
  UUU.Connected:=FALSE;

// sourcesub.open;
// bmsub2.execute;
// sourcesub.close;
TRY
 mypaym2.open;
bmdelpaym.Execute;
bmpaym2.Execute;
mypaym2.close;
myinv2.open;
bmdelinv.Execute;
try
posmodule.server.execute('delete from items where mid not in (select id from invoice)');
except
end;
try
bminv2.Execute;
except
bminv2old.Execute;
end;
myinv2.close;
myitems2.open;
bmitems2.Execute;
myitems2.close;

 try

//fdeposit.SQL.Strings[1]:=' ';
//fdeposit.ParamByName('todate').AsDate:=strtodate(dateedit2.text);
//fddeposit.ParamByName('fromdate').AsDate:=strtodate(dateedit1.text);
//fddeposit.SQL.Strings[1]:=' ';



todeposit2.Open;
bmdeldeposit.Execute;
try
posmodule.server.execute('delete from ddeposit where mid not in (select id from deposit)');
except
end;



bmDEPOSIT2.Execute;
toddeposit2.Open;
bmdDEPOSIT2.Execute;
 except
 SHOWMESSAGE('Multi Voucher No Downloaded!!!');
 end;
todeposit2.close;
toddeposit2.close;

EXCEPT
SHOWMESSAGE('Import Fail');
END;
 prog.Position:=0;


 end;

end;

procedure Tf_ftp.RzBitBtn6Click(Sender: TObject);
var s,s1,s2,s3,s4,s5:string; f:textfile;
begin
 if posmodule.touser.FieldByName('FTPDSTOCK').AsString<>'True' then
 begin
showmessage('No priviligies!!' );
exit;
 end;
if FileExists(extractfilepath(application.ExeName)+'ftp.txt') then
begin
assignfile(f,extractfilepath(application.ExeName)+'ftp.txt');
reset(f);
readln(f,s1);
readln(f,s2);
readln(f,s3);
readln(f,s4);
readln(f,s5);
 closefile(f);
//s5:='s'+s5;
if (trim(CONFIGSFTPFILEST.AsString)>'') then
s5:=CONFIGSFTPFILEST.AsString;
s3:=CONFIGSFTPPASS.AsString;
 if trim(s3)='' then
s3:=inputbox('Enter The Password : ','','');
NMFTP1.Host:=s1;
NMFTP1.UserID:=s2;
NMFTP1.Password:=s3;

NMFTP1.Connect;

NMFTP1.ChangeDir(s4);

  NMFTP1.Mode(MODE_BYTE);
Animate1.visible:=true;
Animate1.Enabled:=true;
  NMFTP1.Download(s5,'c:\myminerva.dsz');
 prog.Position:=0;
 Animate1.visible:=false;
Animate1.Enabled:=false;
showmessage('complete');

NMFTP1.Disconnect;






   s:=EXTRACTFILEPATH(application.ExeName)+'import';


   try
      mkdir(s);
   except
   end;
try


  {
   TRY
   mkdir(EXTRACTFILEPATH(application.ExeName)+'RESTORE\')
   EXCEPT
   END;
  }
   back.restore('c:\myminerva.dsz',s);


   except
   end;

// sourcesub.open;
// bmsub2.execute;
// sourcesub.close;
try
 sourcestock.open;
 bmstock2.execute;
except
end;

 sourcestock.close;
try
 sourcebar.open;
 bmbar2.execute;
except
end;
 sourcebar.close;
try
 sourcedescr.open;
 bmdescr2.execute;
except
end;
 sourcedescr.close;


// sourceuser.open;
// bmuser2.execute;
// sourceuser.close;
 prog.Position:=0;
end;

end;

procedure Tf_ftp.NMFTP1Connect(Sender: TObject);
begin
GroupBox2.Enabled:=false;
GroupBox1.Enabled:=false;
end;

procedure Tf_ftp.NMFTP1Disconnect(Sender: TObject);
begin
GroupBox2.Enabled:=true;
GroupBox1.Enabled:=true;
end;

procedure Tf_ftp.NMFTP1Failure(var Handled: Boolean; Trans_Type: TCmdType);
begin
showmessage('Connection Error!!');
end;

procedure Tf_ftp.RzBitBtn7Click(Sender: TObject);
var s,s1,s2,s3,s4,s5,s6:string; f:textfile;
begin
 if posmodule.touser.FieldByName('FTPuSTOCK').AsString<>'True' then
 begin
showmessage('No priviligies!!' );
exit;
 end;
if FileExists(extractfilepath(application.ExeName)+'ftp.txt') then
begin
assignfile(f,extractfilepath(application.ExeName)+'ftp.txt');
reset(f);
readln(f,s1);
readln(f,s2);
readln(f,s3);
readln(f,s4);
readln(f,s5);
readln(f,s6);
 closefile(f);
if (trim(CONFIGSFTPFILEJOB.AsString)<>'') then
s6:=CONFIGSFTPFILEJOB.AsString;
if trim(s6)='' then
begin
showmessage('File name must Be In Ftp.txt File After Stockname!!!');
exit;
end;


//s5:='s'+s5;
s3:=CONFIGSFTPPASS.AsString;
end;

   try
      mkdir(EXTRACTFILEPATH(application.ExeName) +'exportjob');
   except
   end;
   try

   try

 fromjob.open;
bmjob.Execute;
fromjob.close;
fromdepart.open;
bmdepart.Execute;
fromdepart.close;
fromcontact.Open;
bmcontact.Execute;
fromcontact.close;
fromware.Open;
bmware.Execute;
fromware.close;

 fcurr.open;
bmfcurr.Execute;
 fcurr.close;

//fromsub.open;
// fromuser.open;
//bmuser.Execute;
//  fromuser.close;
//bmcurr.execute;
//bmsub.execute;
except
end;



   list.Clear;

   list.Items.Add(EXTRACTFILEPATH(application.ExeName) +'exportjob\*.*');


   back.Backup(list.Items,s6);
  except
showmessage('Error to export..');
  end;

//showmessage('Export To File Is Done..');
 if trim(s3)='' then
s3:=inputbox('Enter The Password : ','','');
NMFTP1.Host:=s1;
NMFTP1.UserID:=s2;
NMFTP1.Password:=s3;

NMFTP1.Connect;

NMFTP1.ChangeDir(s4);

NMFTP1.Mode(MODE_BYTE);
Animate1.visible:=true;
Animate1.Enabled:=true;

NMFTP1.Upload(s6,s6);

Animate1.visible:=false;
Animate1.Enabled:=false;
 prog.Position:=0;

showmessage('complete');

NMFTP1.Disconnect;
end;

procedure Tf_ftp.RzBitBtn8Click(Sender: TObject);
var s,s1,s2,s3,s4,s5,s6:string; f:textfile;
begin
 if posmodule.touser.FieldByName('FTPDSTOCK').AsString<>'True' then
 begin
showmessage('No priviligies!!' );
exit;
 end;
if FileExists(extractfilepath(application.ExeName)+'ftp.txt') then
begin
assignfile(f,extractfilepath(application.ExeName)+'ftp.txt');
reset(f);
readln(f,s1);
readln(f,s2);
readln(f,s3);
readln(f,s4);
readln(f,s5);
readln(f,s6);
 closefile(f);
if (trim(CONFIGSFTPFILEJOB.AsString)<>'') then
s6:=CONFIGSFTPFILEJOB.AsString;

//s5:='s'+s5;
s3:=CONFIGSFTPPASS.AsString;
 if trim(s3)='' then
s3:=inputbox('Enter The Password : ','','');
NMFTP1.Host:=s1;
NMFTP1.UserID:=s2;
NMFTP1.Password:=s3;

NMFTP1.Connect;

NMFTP1.ChangeDir(s4);

  NMFTP1.Mode(MODE_BYTE);
Animate1.visible:=true;
Animate1.Enabled:=true;
  NMFTP1.Download(s6,'c:\myminerva.dsz');
 prog.Position:=0;
 Animate1.visible:=false;
Animate1.Enabled:=false;
showmessage('complete');

NMFTP1.Disconnect;






   s:=EXTRACTFILEPATH(application.ExeName)+'exportjob';


   try
      mkdir(s);
   except
   end;
try


  {
   TRY
   mkdir(EXTRACTFILEPATH(application.ExeName)+'RESTORE\')
   EXCEPT
   END;
  }
   back.restore('c:\myminerva.dsz',s);


   except
   end;

// sourcesub.open;
// bmsub2.execute;
// sourcesub.close;
try
 tojob.open;
 bmjob2.execute;
except
end;
 tojob.close;

try
 todepart.open;
 bmdepart2.execute;
except
end;
 todepart.close;

try
 tocontact.open;
 bmcontact2.execute;
except
end;
 tocontact.close;

try
 toware.open;
 bmware2.execute;
except
end;
 toware.close;
 try
 tocurr2.open;
 bmfcurr2.execute;
except
end;
 tocurr2.close;

// sourceuser.open;
// bmuser2.execute;
// sourceuser.close;
 prog.Position:=0;
end;

end;

procedure Tf_ftp.uuuBeforeConnect(Sender: TObject);
begin
UUU.Params.Values['PATH']:=EXTRACTFILEPATH(application.ExeName)+'import';
end;

procedure Tf_ftp.items3BeforeOpen(DataSet: TDataSet);
begin
items3.ParamByName('fromdate').AsDate:=strtodate(dateedit1.text);
items3.ParamByName('todate').AsDate:=strtodate(dateedit2.text);

CONTACT.OPEN;

end;

procedure Tf_ftp.wwwwClick(Sender: TObject);
var s,s1,s2,s3,s4,s5:string; f:textfile;
begin
try
//opend.InitialDir:=extractfilepath(application.ExeName);


ITEMS3.OPEN;
exlreport1.Template:=extractfilepath(application.ExeName)+'items3.xls';
exlreport1.Show;
except
end;
ITEMS3.CLOSE;
 if posmodule.touser.FieldByName('FTPuTRANS').AsString<>'True' then
 begin
showmessage('No priviligies!!' );
exit;
 end;
if messagedlg('Transfer To Ftp?',mtwarning,mbokcancel,0)<>mrok then exit;
NMFTP1.Host:='ftp.wfp.org';
NMFTP1.UserID:='retailcomp01';
NMFTP1.Password:='&Longoa43';
//showmessage(filennn);
//FILENNN[LENGTH(FILENNN)]:=' ';
//FILENNN:=TRIM(FILENNN);
//showmessage(filennn);
s4:='c:\'+filennn+'1.xls';
s5:=filennn+'.xls';


NMFTP1.Connect;

//NMFTP1.ChangeDir('/minerva');

NMFTP1.Mode(MODE_BYTE);
Animate1.visible:=true;
Animate1.Enabled:=true;

NMFTP1.Upload(s4,s5);
Animate1.visible:=false;
Animate1.Enabled:=false;
 prog.Position:=0;
TRY
UPITEMS3.ExecSQL;
EXCEPT
END;
showmessage('complete');

NMFTP1.Disconnect;

end;

procedure Tf_ftp.EXLReport1GetReportFileName(Sender: TObject;
  var FileName: String);
begin
filename:=posmodule.CONFIGSCASHNAME.AsString+'_'+FormatDateTime('yyyymmdd',date)+'_'+FormatDateTime('HHmm',time);
filennn:=filename;

end;

procedure Tf_ftp.items3AfterClose(DataSet: TDataSet);
begin
CONTACT.CLOSE;
end;

procedure Tf_ftp.designexcel1Click(Sender: TObject);
begin

exlreport1.EditTemplate;
end;

procedure Tf_ftp.items3CalcFields(DataSet: TDataSet);
begin
items3ftime.Value:=items3fidate.Value;
end;

procedure Tf_ftp.upitems3BeforeOpen(DataSet: TDataSet);
begin
upitems3.ParamByName('fromdate').AsDate:=strtodate(dateedit1.text);
upitems3.ParamByName('todate').AsDate:=strtodate(dateedit2.text);

end;

end.
