unit p_pospr;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  SUIMgr, ExtCtrls, AdvMenus, Abcutil, AHMSystemClass, AHMTSystemDetails,
  AdvTouchKeyboard, Menus, DBSearch, Db, IvDictio, IvMulti, IvAMulti,
  IvBinDic, jpeg, Abcspla, DBTables, SUIDlg, RzStatus, RzPanel, DBCtrls,
  AdvGlassButton, RzDBLbl, StdCtrls, RzLabel, EnJpgGr, DBCGrids;

type
  Tf_pospr = class(TForm)
    Utilities1: TMenuItem;
    About1: TMenuItem;
    Maintenance1: TMenuItem;
    exit1: TMenuItem;
    RzPanel2: TRzPanel;
    RzPanel3: TRzPanel;
    TransferdatetoServer1: TMenuItem;
    mypass: TsuiInputDialog;
    touser: TTable;
    RestaurentConfiguration1: TMenuItem;
    PrintZReport1: TMenuItem;
    PrintDetailReport1: TMenuItem;
    sourceinv: TQuery;
    bminv: TBatchMove;
    destinv: TTable;
    sourceitems: TQuery;
    bmitems: TBatchMove;
    destitems: TTable;
    sourceitems2: TQuery;
    bmitems2: TBatchMove;
    destitems2: TTable;
    RzPanel4: TRzPanel;
    PopupMenu1: TPopupMenu;
    StockRefres1: TMenuItem;
    IvBinaryDictionary1: TIvBinaryDictionary;
    IvTranslator1: TIvTranslator;
    Language1: TMenuItem;
    Arabic1: TMenuItem;
    English1: TMenuItem;
    Portuguese1: TMenuItem;
    Frensh1: TMenuItem;
    N1: TMenuItem;
    N2: TMenuItem;
    ImportExportToFiles1: TMenuItem;
    N3: TMenuItem;
    ExternalCompanies1: TMenuItem;
    PrintOldZReport1: TMenuItem;
    maxdate: TQuery;
    maxdateMAX: TDateTimeField;
    N4: TMenuItem;
    PrintInvoiceByNo1: TMenuItem;
    ssss: TRaDBSearch;
    EmptyPosdata1: TMenuItem;
    fromcurrfac: TQuery;
    Table1: TTable;
    DBText2: TDBText;
    Image2: TImage;
    RzPanel1: TRzPanel;
    DBText1: TDBText;
    suiMainMenu1: TMainMenu;
    RzStatusBar1: TRzStatusBar;
    RzMarqueeStatus1: TRzMarqueeStatus;
    RzClockStatus1: TRzClockStatus;
    RzFieldStatus1: TRzFieldStatus;
    AdvGlassButton4: TAdvGlassButton;
    AdvGlassButton2: TAdvGlassButton;
    AdvGlassButton9: TAdvGlassButton;
    openinv: TQuery;
    PrintChefDetail1: TMenuItem;
    ttt: TAdvPopupTouchKeyBoard;
    RzURLLabel1: TRzURLLabel;
    RzURLLabel23: TRzURLLabel;
    RzDBLabel2: TRzDBLabel;
    btnbar: TAdvGlassButton;
    btncash: TAdvGlassButton;
    btnrest: TAdvGlassButton;
    AdvGlassButton3: TAdvGlassButton;
    AdvGlassButton5: TAdvGlassButton;
    AdvGlassButton8: TAdvGlassButton;
    Image1: TImage;
    N5: TMenuItem;
    DatabaseMaintenance1: TMenuItem;
    RzFieldStatus2: TRzFieldStatus;
    MYSYS: TAHMSystemDetails;
    N6: TMenuItem;
    Register1: TMenuItem;
    c3: TQuery;
    c2: TQuery;
    c1: TQuery;
    Ftp1: TMenuItem;
    N7: TMenuItem;
    AdvMenuStyler1: TAdvMenuStyler;
    AdvMainMenu1: TAdvMainMenu;
    HKJH1: TMenuItem;
    JHKHJ1: TMenuItem;
    KJJKLJLK1: TMenuItem;
    DBCtrlGrid1: TDBCtrlGrid;
    DBText6: TDBText;
    DBText7: TDBText;
    query3: TTable;
    query3Iid: TAutoIncField;
    query3Name: TStringField;
    query3Ip: TStringField;
    DataSource1: TDataSource;
    PosList1: TMenuItem;
    procedure AdvGlowButton4Click(Sender: TObject);
    procedure AdvGlowButton1Click(Sender: TObject);
    procedure AdvGlowButton5Click(Sender: TObject);
    procedure RestaurentConfiguration1Click(Sender: TObject);
    procedure AdvGlowButton8Click(Sender: TObject);
    procedure exit1Click(Sender: TObject);
    procedure AdvGlowButton2Click(Sender: TObject);
    procedure AdvGlowButton3Click(Sender: TObject);
    procedure TransferdatetoServer1Click(Sender: TObject);
    procedure PrintZReport1Click(Sender: TObject);
    procedure PrintDetailReport1Click(Sender: TObject);
    procedure RzBitBtn6Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure StockRefres1Click(Sender: TObject);
    procedure Maintenance1Click(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure Arabic1Click(Sender: TObject);
    procedure English1Click(Sender: TObject);
    procedure Portuguese1Click(Sender: TObject);
    procedure Frensh1Click(Sender: TObject);
    procedure ImportExportToFiles1Click(Sender: TObject);
    procedure ExternalCompanies1Click(Sender: TObject);
    procedure PrintOldZReport1Click(Sender: TObject);
    procedure PrintInvoiceByNo1Click(Sender: TObject);
    procedure EmptyPosdata1Click(Sender: TObject);
    procedure F91Click(Sender: TObject);
    procedure BarCash1Click(Sender: TObject);
    procedure RzFieldStatus1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure sssRestartRequest(Sender: TObject; var RebootNow: Boolean);
    procedure btnbarClick(Sender: TObject);
    procedure AdvGlassButton3Click(Sender: TObject);
    procedure AdvGlassButton5Click(Sender: TObject);
    procedure AdvGlassButton4Click(Sender: TObject);
    procedure AdvGlassButton2Click(Sender: TObject);
    procedure AdvGlassButton8Click(Sender: TObject);
    procedure btncashClick(Sender: TObject);
    procedure btnrestClick(Sender: TObject);
    procedure AdvGlassButton9Click(Sender: TObject);
    procedure PrintChefDetail1Click(Sender: TObject);
    procedure DatabaseMaintenance1Click(Sender: TObject);
    procedure Register1Click(Sender: TObject);
    procedure Ftp1Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure DBCtrlGrid1Click(Sender: TObject);
    procedure query3AfterPost(DataSet: TDataSet);
    procedure PosList1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_pospr: Tf_pospr; mymode:string;

implementation

uses p_posmodule, p_cashinv, p_repmodule, p_zale, p_rest, p_searsh,
  p_config, P_pasdlg, p_mytoush,   P_impexp,
  p_extcomp, p_control, p_touchcash2, p_touchcash3, p_validate, p_register,
  p_ftp, p_ips;

{$R *.DFM}

procedure Tf_pospr.AdvGlowButton4Click(Sender: TObject);
begin

close;
end;

procedure Tf_pospr.AdvGlowButton1Click(Sender: TObject);
//label 1;
var b:boolean;  mydel:integer;
begin
repeat
try
mydel:=0;
p_posmodule.mycontact:=0;
posmodule.CURrFAC.open;
posmodule.items.open;
posmodule.CURrFAC.Insert;
posmodule.CURRFACIACTIVE.AsString:='False';
posmodule.CURrFAC.POST;
//1: b:=false;
 f_cashinv.Label2.Caption:='0';
 f_cashinv.ShowModal;

try
if (posmodule.CURrFAC.State in [dsedit]) or (posmodule.CURrFAC.State in [dsinsert]) then
 posmodule.CURrFAC.post;

if posmodule.ITEMS.IsEmpty then
begin
 posmodule.CURrFAC.delete;
 mydel:=1;
 end;

except

posmodule.ITEMS.cancel;
posmodule.CURrFAC.cancel;


end;
//if b then goto 1;

posmodule.ITEMS.close;


posmodule.CURrFAC.close;
 except
 end;

until   (f_cashinv.ModalResult=mrabort) or (mydel=1);



end;


procedure Tf_pospr.AdvGlowButton5Click(Sender: TObject);
begin
if touser.active=False then
touser.open;
mypass.ValueText:='';
mypass.ShowModal;

try
if posmodule.invoice.Active=false then
posmodule.invoice.open;

posmodule.invoice.edit;
posmodule.invoiceFTYPE.AsInteger:=1;

posmodule.invoicefdate.AsDateTime:=date;
posmodule.invoicefidate.AsDateTime:=date;

posmodule.invoiceuser_.AsString:=myuser;




posmodule.invoice.Post;


except
end;





try
maxdate.open;

if maxdatemax.AsString<>'' then
begin
if date<maxdatemax.AsDateTime then
begin
Showmessage('Check The Date Of System!!!!');
maxdate.close;
exit;
end;

end;
except
end;

maxdate.close;
if touser.Locate('pass',mypass.ValueText,[]) then
begin
if touser.FieldByName('ACCREPRATIO').AsString<>'True' then
begin

exit;
end;

end
else
begin

exit;
end;

touser.close;

posmodule.invoice.close;
posmodule.invoice.open;

 try
repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+'zed.fr3') ;

repmodule.frxReport1.PrepareReport;
repmodule.frxReport1.PrintOptions.ShowDialog:=false;
repmodule.frxReport1.print;
except
end;




posmodule.pos.StartTransaction;
try
posmodule.DOEMPTY.ExecProc;
posmodule.pos.Commit;

except
posmodule.pos.Rollback;
showmessage('Error To local Posting');
exit;

end;



 try
if posmodule.CONFIGSTRSERVER.AsBoolean then

begin
TransferdatetoServer1Click(TransferdatetoServer1);
end;


 except
 end;





close;


end;

procedure Tf_pospr.RestaurentConfiguration1Click(Sender: TObject);
begin
{f_zale:=tf_zale.Create(self);
try
f_zale.ShowModal;
 except
 end;
f_zale.Release;

 }




end;

procedure Tf_pospr.AdvGlowButton8Click(Sender: TObject);
begin
p_posmodule.mycontact:=0;
try
 //  Application.CreateForm(Tf_MYTOUSH, f_MYTOUSH);
 if not assigned(f_MYTOUSH) then
 f_MYTOUSH:=tf_MYTOUSH.Create(self);

f_MYTOUSH.ShowModal;
 except
 end;
 if  assigned(f_mytoush) then
 FreeAndNil(f_mytoush);
end;

procedure Tf_pospr.exit1Click(Sender: TObject);
begin
close;
end;

procedure Tf_pospr.AdvGlowButton2Click(Sender: TObject);
begin
//  Application.CreateForm(Tf_searsh, f_searsh);
if not assigned(f_searsh) then
f_searsh:=tf_searsh.create(self);
try
f_searsh.ShowModal;
except
end;
 if  assigned(f_searsh) then
freeandnil(f_searsh);
//if RzBorder2.visible then
//RzBorder2.setfocus;
end;

procedure Tf_pospr.AdvGlowButton3Click(Sender: TObject);
begin
if posmodule.touser.FieldByName('UDESIGN').AsBoolean=false then
begin
showmessage('You dont Have permission!!!');
exit;
end;

// Application.CreateForm(Tf_config, f_config);
if not assigned(f_config) then
f_config:=tf_config.create(self);
try
f_config.ShowModal;

except
end;
   if  assigned(f_config) then
  freeandnil(f_config);
  try
  f_pospr.OnShow(self);
  except
  end;
//if AdvGlowButton1.visible then
//AdvGlowButton1.setfocus;

end;

procedure Tf_pospr.TransferdatetoServer1Click(Sender: TObject);
VAR S:STRING; D,M,Y:WORD;
begin
if (posmodule.CONFIGSEXTYESNO.AsString='YES') THEN EXIT;
DECODEDATE(DATE,Y,M,D);


if posmodule.server.Connected=False then
posmodule.server.Connected:=true;

posmodule.pos.StartTransaction;
posmodule.server.StartTransaction;
try

sourceinv.open;
sourceitems.open;
//sourceitems2.open;



if posmodule.CONFIGSBYITEM.AsString='YES' then
begin
bminv.Execute;

//bmitems.Execute;
try
bmitems2.Destination:=destitems;
bmitems2.Execute;
except
end;
end
else
begin
bmitems2.Destination:=destitems2;
bminv.Execute;

bmitems.Execute;
try
bmitems2.Execute;
except
end;
end;

posmodule.pos.Execute('delete from invoice2');
posmodule.pos.Execute('delete from items2');
posmodule.server.Commit;
posmodule.pos.Commit;
showmessage('The Transfer Is Complete');
except
posmodule.server.Rollback;
posmodule.pos.Rollback;

showmessage('Error to transport to server!!!');
end;
sourceinv.close;
sourceitems.close;
sourceitems2.close;




end;


procedure Tf_pospr.PrintZReport1Click(Sender: TObject);
begin

if touser.active=False then
touser.open;


    if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.Create(self);
try
f_passdlg.ShowModal;
if touser.Locate('pass',f_passdlg.Password.Text,[]) then
begin
if touser.FieldByName('posreport').AsString<>'True' then
begin
     if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;

end
else
begin
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;
except
end;
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;
try
repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+ 'zreport.fr3') ;
repmodule.frxReport1.ShowReport  ;
except
end;
end;

procedure Tf_pospr.PrintDetailReport1Click(Sender: TObject);
begin
if touser.active=False then
touser.open;

    if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.Create(self);
try
f_passdlg.ShowModal;
if touser.Locate('pass',f_passdlg.Password.Text,[]) then
begin
if touser.FieldByName('posreport').AsString<>'True' then
begin
     if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;

end
else
begin
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;
except
end;
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;
try
repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+ 'zdetails.fr3') ;
repmodule.frxReport1.ShowReport  ;
except
end;
end;

procedure Tf_pospr.RzBitBtn6Click(Sender: TObject);
begin
 //Application.CreateForm(Tf_passdlg, f_passdlg);
 if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.Create(self);

  try
repeat
f_passdlg.ShowModal;

until posmodule.touser.Locate('pass',f_passdlg.Password.Text,[]);
p_posmodule.myuser:=posmodule.touser.fieldbyname('username').AsString;
except
end;
      if  assigned(f_passdlg) then
   freeandnil(f_passdlg);
//if AdvGlowButton1.visible then
//AdvGlowButton1.setfocus;

end;

procedure Tf_pospr.FormShow(Sender: TObject);
var tt:textfile;s:string;
d,y,m:word;
begin


  posmodule.pos.Connected:=false;
btnbar.Visible:=posmodule.CONFIGSPOSBAR.AsBoolean;


btncash.Visible:=posmodule.CONFIGSPOSTOUsH.AsBoolean;

btnrest.Visible:=posmodule.CONFIGSPOSTOUCH.AsBoolean;

//RzBorder7.Enabled:=posmodule.CONFIGSPOSTOUcH.AsBoolean;
//AdvGlowButton6.visible:=posmodule.CONFIGSPOSTOUsH.AsBoolean;


IvBinaryDictionary1.FileName:=extractfilepath(application.ExeName)+'pospremier.mld';



try
assignfile(tt,extractfilepath(application.ExeName)+'lang.inf');
reset(tt);
readln(tt,s);

except
end;
closefile(tt);

try
 IvBinaryDictionary1.Language :=strtoint(s);
 IvTranslator1.Translate;
except
end;
 try

decodedate(date,y,m,d);
if (d mod 2 =0) then
copyfile(pchar('POSPREMIER.gdb'),pchar('c:\'+'POSPREMIER.gdb'+'p'),False)
else
copyfile(pchar('POSPREMIER.gdb'),pchar('c:\'+'POSPREMIER.gdb'+'U'),False);
except
end;
  query3.open;
 end;

procedure Tf_pospr.StockRefres1Click(Sender: TObject);
begin
  if posmodule.CONFIGSEXTYESNO.AsString='YES' then
exit;

  if posmodule.stock.Active then posmodule.stock.close;
    if posmodule.locstock.Active then posmodule.locstock.close;
   if posmodule.tostock.Active then posmodule.tostock.close;

TRY
  posmodule.server.close;
  posmodule.server.Connected:=true;
  posmodule.bmstock.Execute;


 EXCEPT
 END;

posmodule.locstock.open;

end;

procedure Tf_pospr.Maintenance1Click(Sender: TObject);
begin
if messagedlg('Are you SURE to do The Maintenance?',mtwarning,mbokcancel,0)<>mrok then exit;
posmodule.pos.StartTransaction;
try
posmodule.pos.Execute('update invoice set id=id||''x''');
posmodule.pos.Execute('update items set mid=mid||''x''');
posmodule.pos.Execute('update items set id=id+70000000');

posmodule.pos.Execute('update invoice2 set id=id||''y''');
posmodule.pos.Execute('update items2 set mid=mid||''y''');
posmodule.pos.Commit;
showmessage('The Maintenance is Done.');
except
posmodule.pos.Rollback;

end;

 try
posmodule.pos.StartTransaction;
 POSMODULE.pos.Execute('drop procedure doempty');
 posmodule.pos.commit;
 except
 posmodule.pos.Rollback;
 end;
try
posmodule.pos.StartTransaction;
POSMODULE.updoempty.ExecSQL;
posmodule.pos.Commit;
except
posmodule.pos.Rollback;
end;




end;

procedure Tf_pospr.RzBitBtn1Click(Sender: TObject);
var s:string;
begin
if posmodule.CONFIGSEXTYESNO.AsString='YES' then
exit;

if messagedlg('Are You Sure to Refresh  The Stock List?',mtwarning,mbokcancel,0)<> mrok then exit;

s:=posmodule.touser.fieldbyname('username').AsString;

try
posmodule.server.Connected:=false;
posmodule.server.Connected:=true



except
showmessage('No Connection To server '+posmodule.server.Params.Values['SERVER NAME']+' !!!!');
exit;
end;
posmodule.server.StartTransaction;
try
posmodule.server.Execute('delete from stock where item=''''');
posmodule.server.Execute('delete from barcodes where barcode=''''');
posmodule.server.Commit;
except
posmodule.server.Rollback;
end;


posmodule.stock.close;
posmodule.locstock.close;
posmodule.barcodes.close;
try

posmodule.tosub.close;
except
end;

try
posmodule.tocomp.close;
except
end;

try
posmodule.tocontact.close;
except
end;

try
posmodule.tostock.close;
except
end;
try
posmodule.touser.close;
except
end;
try
posmodule.tocurr.close;
except
end;
try
posmodule.todescr.close;
except
end;



 try
posmodule.tobar.close;
except
end;

 try
posmodule.qitinfo.close;
posmodule.toinfo.close;
except
end;



posmodule.fromstock.open;
try
posmodule.bmstock.Execute;
except

end;
posmodule.fromstock.close;
posmodule.frombar.open;
try
posmodule.bmbar.Execute;
except
end;

posmodule.frombar.close;


posmodule.itinfo.open;
try
posmodule.bminfo.Execute;
except
end;

posmodule.itinfo.close;




posmodule.fromsub.open;

try
posmodule.bmsub.Execute;
except
end;
posmodule.fromsub.close;

posmodule.fromcomp.open;
try
posmodule.bmcomp.Execute;
except
end;

posmodule.fromcomp.close;

posmodule.fromcontact.open;
try
posmodule.bmcontact.Execute;
except
end;


posmodule.fromuser.Open;

try
posmodule.bmuser.Execute;
except
end;
posmodule.fromuser.close;
posmodule.fromcurr.open;
try
posmodule.bmcurr.Execute;
except
end;
posmodule.fromcurr.close;
posmodule.fromdescr.open;
try
posmodule.bmdescr.Execute;
except
end;
posmodule.fromdescr.close;

posmodule.locstock.open;

posmodule.touser.open;

posmodule.tosub.open;
posmodule.tocontact.open;
posmodule.tocurr.open;
try
posmodule.tocurr.Locate('currid',2,[]);

p_posmodule.myval2:=posmodule.tocurr.fieldbyname('currval').ascurrency;

except
end;


posmodule.configs.close;
posmodule.configs.open;
posmodule.tocomp.open;



posmodule.touser.locate('username',s,[]);
// if AdvGlowButton1.visible then
//AdvGlowButton1.setfocus;

showmessage('The Refresh Is Complete');
end;

procedure Tf_pospr.Arabic1Click(Sender: TObject);
var tt:textfile;s:string;
begin
try
assignfile(tt,extractfilepath(application.ExeName)+'lang.inf');
rewrite(tt);
s:='2';
writeln(tt,s);

 IvBinaryDictionary1.Language :=2;
IvTranslator1.translate;
BiDiMode:=bdLeftToRight;



except
end;
closefile(tt);
 end;

procedure Tf_pospr.English1Click(Sender: TObject);
var tt:textfile;s:string;
begin
try
assignfile(tt,extractfilepath(application.ExeName)+'lang.inf');
rewrite(tt);
s:='1';
writeln(tt,s);

 IvBinaryDictionary1.Language :=1;
IvTranslator1.translate;

except
end;
closefile(tt);
end;
procedure Tf_pospr.Portuguese1Click(Sender: TObject);
var tt:textfile;s:string;
begin
try
assignfile(tt,extractfilepath(application.ExeName)+'lang.inf');
rewrite(tt);
s:='4';
writeln(tt,s);

 IvBinaryDictionary1.Language :=4;
IvTranslator1.translate;

except
end;
closefile(tt);

end;

procedure Tf_pospr.Frensh1Click(Sender: TObject);
var tt:textfile;s:string;
begin
try
assignfile(tt,extractfilepath(application.ExeName)+'lang.inf');
rewrite(tt);
s:='3';
writeln(tt,s);

 IvBinaryDictionary1.Language :=3;
IvTranslator1.translate;


except
end;
closefile(tt);

end;

procedure Tf_pospr.ImportExportToFiles1Click(Sender: TObject);
begin
 //Application.CreateForm(Tf_impexp, f_impexp);
  if not assigned(f_impexp) then
f_impexp:=tf_impexp.Create(self);

try
f_impexp.ShowModal;
except
end;
if  assigned(f_impexp) then
    freeandnil(f_impexp);
end;

procedure Tf_pospr.ExternalCompanies1Click(Sender: TObject);
begin
if posmodule.touser.FieldByName('posconfigs').AsBoolean=false then
begin
showmessage('You dont Have permission!!!');
exit;
end;

//Application.CreateForm(Tf_extcomp,f_extcomp);
  if not assigned(f_extcomp) then
f_extcomp:=tf_extcomp.create(self);
posmodule.EXTCOMP.open;
try
f_extcomp.ShowModal;

except
end;
posmodule.EXTCOMP.close;

freeandnil(f_extcomp);
end;

procedure Tf_pospr.PrintOldZReport1Click(Sender: TObject);
begin


if touser.active=False then
touser.open;

    if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.Create(self);
try
f_passdlg.ShowModal;
if touser.Locate('pass',f_passdlg.Password.Text,[]) then
begin
if touser.FieldByName('posoldinvoice').AsString<>'True' then
begin
     if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;

end
else
begin
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;
except
end;
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;
try
repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+ 'oldzreport.fr3') ;
repmodule.frxReport1.ShowReport  ;
except
end;
end;

procedure Tf_pospr.PrintInvoiceByNo1Click(Sender: TObject);
begin

if touser.active=False then
touser.open;


    if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.Create(self);
try
f_passdlg.ShowModal;
if touser.Locate('pass',f_passdlg.Password.Text,[]) then
begin
if touser.FieldByName('posreport').AsString<>'True' then
begin
     if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;

end
else
begin
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;
except
end;
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;
posmodule.CURrFAC.open;
posmodule.items.open;
try
ssss.Execute(posmodule.CURRFACAUTONO);


repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+'posinv.fr3') ;


repmodule.frxReport1.PrepareReport;
repmodule.frxReport1.PrintOptions.ShowDialog:=false;


repmodule.frxReport1.print;
except
end;
posmodule.items.close;
posmodule.CURrFAC.close;



end;

procedure Tf_pospr.EmptyPosdata1Click(Sender: TObject);
var d,m,y:word;  s:string;
begin
if posmodule.touser.FieldByName('UDESIGN').AsBoolean=false then
begin
showmessage('You dont Have permission!!!');
exit;
end;


 decodedate(date,y,m,d);

S:=INPUTBOX('ENTER THE PASSWORD','','');
IF STRTOINT(S)<>D+M THEN
begin
Showmessage('Not Correct Bye Bye!!');
 EXIT;
end;




copyfile(pchar(ExtractFilePath(application.ExeName)+'\POSPREMIER.gdb'),pchar('c:\'+inttostr(d+m+y)+'POSPREMIER.gdb'),true);

posmodule.pos.StartTransaction;
try
posmodule.pos.Execute('delete from invoice2');

try
posmodule.pos.Execute('delete from invoice3');
except
end;
posmodule.pos.Execute('delete from items2');

posmodule.pos.Execute('delete from items3');


posmodule.pos.Execute('delete from itemsinfo');

posmodule.pos.Execute('delete from currfac where id not in (select currfac from items)');
posmodule.pos.Commit;

showmessage('The Delete Operation Is Complete');
except
posmodule.pos.Rollback;
end;










end;

procedure Tf_pospr.F91Click(Sender: TObject);
begin
posmodule.CONFIGS.edit;
if  posmodule.CONFIGSMYPRN.AsString='ON' then
posmodule.CONFIGSMYPRN.AsString:='OFF'
else
posmodule.CONFIGSMYPRN.AsString:='ON';
posmodule.CONFIGS.post;
posmodule.CONFIGS.ApplyUpdates;
posmodule.CONFIGS.close;
posmodule.CONFIGS.open;
end;

procedure Tf_pospr.BarCash1Click(Sender: TObject);

begin
//if RzBorder2.Enabled=false then exit;
if  btnbar.Visible=false then
btncashClick(btncash)
else
btnbarClick(btnbar);
end;

procedure Tf_pospr.RzFieldStatus1Click(Sender: TObject);
begin
 f_pospr.WindowState:=wsminimized;
end;

procedure Tf_pospr.FormCreate(Sender: TObject);
begin


{try
if sss.CurrentMode<>'1024x768 (16-bit)' then

begin
mymode:=sss.CurrentMode;

sss.Mode:='1024x768 (16-bit)';
sss.Execute;
end;
except
end;}

try

SetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, 'dd/MM/yyyy')
except
end;
TRY
IF FileExists(EXTRACTFILEPATH(APPLICATION.ExeName)+'POS.jpeg') THEN
IMAGE2.Picture.LoadFromFile(EXTRACTFILEPATH(APPLICATION.ExeName)+'POS.jpeg');
EXCEPT
END;



end;

procedure Tf_pospr.sssRestartRequest(Sender: TObject;
  var RebootNow: Boolean);
begin
if MessageDlg('Your system needs to be rebooted for changes to take effect. Do you want to do that now ?',mtconfirmation,[mbyes,mbno],0)=mryes then
   Rebootnow:=true else Rebootnow:=False;
end;

procedure Tf_pospr.btnbarClick(Sender: TObject);
var b:boolean;  mydel:integer;
begin
if  btnbar.Visible=false then
exit;
   //Application.CreateForm(Tf_cashinv, f_cashinv);
if  assigned(f_cashinv) then
freeandnil(f_cashinv);

f_cashinv:=tf_cashinv.create(self);
try
repeat
f_cashinv.cbsp.Checked:=false;
try

mydel:=0;
p_posmodule.mycontact:=0;
posmodule.CURrFAC.open;
posmodule.items.open;
posmodule.CURrFAC.Insert;
posmodule.CURRFACIACTIVE.AsString:='False';
posmodule.CURrFAC.POST;
//1: b:=false;
 f_cashinv.Label2.Caption:='0';
 f_cashinv.ShowModal;

try
if (posmodule.CURrFAC.State in [dsedit]) or (posmodule.CURrFAC.State in [dsinsert]) then
 posmodule.CURrFAC.post;

if posmodule.ITEMS.IsEmpty then
begin
 posmodule.CURrFAC.delete;
 mydel:=1;
 end;

except

posmodule.ITEMS.cancel;
posmodule.CURrFAC.cancel;


end;
//if b then goto 1;

posmodule.ITEMS.close;


posmodule.CURrFAC.close;
 except
 end;

until   (f_cashinv.ModalResult=mrabort) or (mydel=1);
except
end;
if  assigned(f_cashinv) then
freeandnil(f_cashinv);

end;

procedure Tf_pospr.AdvGlassButton3Click(Sender: TObject);
var s:string;
begin
if posmodule.pos.Connected=false then
begin
showmessage('Select Pos First !!!');
exit;
end;




if touser.active=False then
touser.open;
//mypass.ValueText:='';
//mypass.ShowModal;
 //Application.CreateForm(Tf_passdlg, f_passdlg);
     if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.Create(self);
f_passdlg.ShowModal;
if touser.Locate('pass',f_passdlg.Password.Text,[]) then
begin
if touser.FieldByName('posconfigs').AsString<>'True' then
begin
  if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;

end
else
begin
  if  assigned(f_passdlg) then
freeandnil(f_passdlg);
touser.close;

exit;
end;
  if  assigned(f_passdlg) then
freeandnil(f_passdlg);
touser.close;


//  Application.CreateForm(Tf_config, f_config);
//      if not assigned(f_config) then
posmodule.CONFIGS.open;
f_config:=tf_config.create(self);
try
f_config.ShowModal;

except
end;
  //  if  assigned(f_config) then
  f_config.Release;



//RzBorder7.Enabled:=posmodule.CONFIGSPOSTOUcH.AsBoolean;
//AdvGlowButton6.visible:=posmodule.CONFIGSPOSTOUsH.AsBoolean;
   posmodule.CONFIGS.close;
      posmodule.CONFIGS.open;
   //if AdvGlowButton1.visible then
//AdvGlowButton1.setfocus;

end;

procedure Tf_pospr.AdvGlassButton5Click(Sender: TObject);
var s:string;
begin

if posmodule.pos.Connected=false then
begin
showmessage('Select Pos First !!!');
exit;
end;


if touser.active=False then
touser.open;


//mypass.ValueText:='';
//mypass.ShowModal;
// Application.CreateForm(Tf_passdlg, f_passdlg);
      if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.Create(self);
try
f_passdlg.ShowModal;
if touser.Locate('pass',f_passdlg.Password.Text,[]) then
begin
if touser.FieldByName('posconfigs').AsString<>'True' then
begin
     if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;

end
else
begin
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;
except
end;
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;


if posMODULe.stock.Active then
posMODULe.stock.close;
s:=posMODULe.stock.sql.Strings[1];
posMODULe.stock.sql.Strings[1]:='';
//MODULe.stock.ParamByName('MYITEM').ASSTRING:='''''';
posMODULe.stock.open;
 //  Application.CreateForm(Tf_control, f_control);
    //   if not assigned(f_control) then
f_control:=tf_control.create(self);
try
f_control.ShowModal;
except
end;
f_control.Release;
posMODULe.stock.close;
posMODULe.stock.sql.Strings[1]:=s;

end;

procedure Tf_pospr.AdvGlassButton4Click(Sender: TObject);
begin
If messagedlg('Are you sure To exit???',mtwarning,mbokcancel,0)<>mrok then exit;
close;
end;

procedure Tf_pospr.AdvGlassButton2Click(Sender: TObject);
begin
if posmodule.pos.Connected=false then
begin
showmessage('Select Pos First !!!');
exit;
end;
try
posmodule.checkpro.ExecProc;
except
end;

try
IF FILEEXISTS(MYSYS.DirectorySystem+'\NDDLP.DLL')=FALSE THEN
BEGIN
Showmessage('You Must register Minerva BMS On This Computer!!');
exit;

end;

except
end;



openinv.Open;
if openinv.IsEmpty=false then
begin
showmessage('Please Close All Invoices!!!!');
openinv.close;
exit;
end;

openinv.close;
if touser.active=False then
touser.open;
mypass.ValueText:='';
//mypass.ButtonCancelCaption:=' ';
//mypass.ShowModal;
 //Application.CreateForm(Tf_passdlg, f_passdlg);
   if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.create(self);
try
if f_passdlg.ShowModal<>mrok then
begin
touser.close;
exit;
end
else
begin
mypass.ValueText:=f_passdlg.Password.Text;
end;
except
end;
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
mypass.ButtonCancelCaption:='Cancel';
try
if posmodule.invoice.Active=false then
posmodule.invoice.open;

posmodule.invoice.edit;
posmodule.invoiceFTYPE.AsInteger:=1;

posmodule.invoicefdate.AsDateTime:=date;
posmodule.invoicefidate.AsDateTime:=date;

posmodule.invoiceuser_.AsString:=myuser;




posmodule.invoice.Post;


except
end;





try
maxdate.open;

if maxdatemax.AsString<>'' then
begin
if date<maxdatemax.AsDateTime then
begin
Showmessage('Check The Date Of System!!!!');
maxdate.close;
exit;
end;

end;
except
end;

maxdate.close;
if touser.Locate('pass',mypass.ValueText,[]) then
begin
if touser.FieldByName('posclose').AsString<>'True' then
begin

exit;
end;

end
else
begin

exit;
end;

touser.close;

posmodule.invoice.close;
posmodule.invoice.open;

 try
repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+'zed.fr3') ;

repmodule.frxReport1.PrepareReport;
repmodule.frxReport1.PrintOptions.ShowDialog:=false;
repmodule.frxReport1.print;
except
end;




posmodule.pos.StartTransaction;
try
posmodule.DOEMPTY.ExecProc;
posmodule.pos.Commit;

except
posmodule.pos.Rollback;
showmessage('Error To local Posting Try Again Later !!!');
try
Maintenance1Click(Maintenance1);
except
end;
exit;

end;



 try
if posmodule.CONFIGSTRSERVER.AsBoolean then

begin
TransferdatetoServer1Click(TransferdatetoServer1);
end;


 except
 end;

IF POSMODULE.CONFIGSEXTYESNO.AsString='YES' then
begin
//Application.CreateForm(Tf_impexp,f_impexp);
   if not assigned(f_impexp) then
f_impexp:=tf_impexp.create(self);
try
f_impexp.fromdate.Text:=datetostr(date);
f_impexp.todate.Text:=datetostr(date);
f_impexp.BitBtn2Click(f_impexp.BitBtn2);
except
end;

freeandnil(f_impexp);

end;


IF POSMODULE.CONFIGSFTPAUTO.AsString='AUTO' then
begin
f_ftp:=tf_ftp.Create(self);
try
f_ftp.ShowModal;
except
end;
f_ftp.Release;
end;




close;
end;

procedure Tf_pospr.AdvGlassButton8Click(Sender: TObject);
begin
 //Application.CreateForm(Tf_passdlg, f_passdlg);
  if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.Create(self);


repeat
f_passdlg.ShowModal;

until posmodule.touser.Locate('pass',f_passdlg.Password.Text,[]);
p_posmodule.myuser:=posmodule.touser.fieldbyname('username').AsString;
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);

//if AdvGlowButton1.visible then
//AdvGlowButton1.setfocus;

end;

procedure Tf_pospr.btncashClick(Sender: TObject);
begin
posmodule.CURrFAC.Filter:='iactive=''C''';
posmodule.CURrFAC.Filtered:=true;
posmodule.CURrFAC.open;


posmodule.CURRFAC.Insert;

posmodule.CURRFACTABLENO.AsString:='Take Away';
posmodule.CURRFACIACTIVE.AsString:='C';


posmodule.CURrFAC.POST;

posmodule.items.open;
//1: b:=false;
if posmodule.CONFIGSMILTIPRICE.AsCurrency=0 then
begin
 //   Application.CreateForm(Tf_touchcash2, f_touchcash2);
if  assigned(f_touchcash2) then
freeandnil(f_touchcash2);
 f_touchcash2:=tf_touchcash2.create(self);

 f_touchcash2.btnprint.Visible:=false;
if f_touchcash2.ShowModal=mrok then
begin
try
if (posmodule.CURrFAC.State in [dsedit]) or (posmodule.CURrFAC.State in [dsinsert]) then


 posmodule.CURrFAC.post;

if posmodule.ITEMS.IsEmpty then
 posmodule.CURrFAC.delete;


except

posmodule.ITEMS.cancel;
posmodule.CURrFAC.cancel;


end;
end;
//if b then goto 1;
if  assigned(f_touchcash2) then
freeandnil(f_touchcash2);


end
else
begin
//Application.CreateForm(Tf_touchcash3,f_touchcash3);
 // if not assigned(f_touchcash3) then
f_touchcash3:=tf_touchcash3.create(self);
  f_touchcash3.btnprint.Visible:=false;
if f_touchcash3.ShowModal=mrok then
begin
try
if (posmodule.CURrFAC.State in [dsedit]) or (posmodule.CURrFAC.State in [dsinsert]) then


 posmodule.CURrFAC.post;

if posmodule.ITEMS.IsEmpty then
 posmodule.CURrFAC.delete;


except

posmodule.ITEMS.cancel;
posmodule.CURrFAC.cancel;


end;
//if b then goto 1;
end;
   //  if  assigned(f_touchcash3) then
f_touchcash3.Release;

end;



posmodule.ITEMS.close;
posmodule.CURrFAC.close;
posmodule.CURrFAC.Filter:='';
posmodule.CURrFAC.Filtered:=false;



end;

procedure Tf_pospr.btnrestClick(Sender: TObject);
begin
p_posmodule.mycontact:=0;

{
try
posmodule.checkpro.ExecProc;
except
end;
 }

//  Application.CreateForm(Tf_MYTOUSH, f_MYTOUSH);
 // if not assigned(f_MYTOUSH) then
f_MYTOUSH:=tf_MYTOUSH.Create(self);
if posmodule.touser.fieldbyname('alltable').AsString='NO' then
   begin
   f_MYTOUSH.RzPanel4.Visible:=false;
   f_MYTOUSH.RzBitBtn7.Visible:=false;
   end
   else
   begin
   f_MYTOUSH.RzPanel4.Visible:=true;
   f_MYTOUSH.RzBitBtn7.Visible:=true;
   end;

try
f_MYTOUSH.ShowModal;
 except
 end;
// if  assigned(f_MYTOUSH) then
  f_MYTOUSH.Release;
end;

procedure Tf_pospr.AdvGlassButton9Click(Sender: TObject);
var s:string;
begin
if posmodule.CONFIGSEXTYESNO.AsString='YES' then
exit;

if messagedlg('Are You Sure to Refresh  The Stock List?',mtwarning,mbokcancel,0)<> mrok then exit;

s:=posmodule.touser.fieldbyname('username').AsString;

try
posmodule.server.Connected:=false;
posmodule.server.Connected:=true



except
showmessage('No Connection To server '+posmodule.server.Params.Values['SERVER NAME']+' !!!!');
exit;
end;
posmodule.server.StartTransaction;
try
posmodule.server.Execute('delete from stock where item=''''');
posmodule.server.Execute('delete from barcodes where barcode=''''');
posmodule.server.Execute('delete from barcodes where ITEM=''''');
posmodule.server.Execute('delete from iteminfo where sid='''' or sid is null ');
posmodule.server.Commit;
except
posmodule.server.Rollback;
end;


posmodule.stock.close;
posmodule.locstock.close;
posmodule.barcodes.close;
posmodule.tobar.close;
try

posmodule.tosub.close;
except
end;

try
posmodule.tocomp.close;
except
end;

try
posmodule.tocontact.close;
except
end;

try
posmodule.tostock.close;
except
end;
try
posmodule.touser.close;
except
end;
try
posmodule.tocurr.close;
except
end;
try
posmodule.todescr.close;
except
end;



 try
posmodule.tobar.close;
except
end;

 try
posmodule.qitinfo.close;
posmodule.toinfo.close;
except
end;



posmodule.fromstock.open;
try
posmodule.bmstock.Execute;
except
showmessage('Stock Refresh Error!!');
end;
posmodule.fromstock.close;
posmodule.frombar.open;
try
posmodule.bmbar.Execute;
except
end;

posmodule.frombar.close;


posmodule.itinfo.open;
try
posmodule.bminfo.Execute;
except
end;

posmodule.itinfo.close;




posmodule.fromsub.open;

try
posmodule.bmsub.Execute;
except
showmessage('Acc# Refresh Error!!');
end;
posmodule.fromsub.close;

posmodule.fromcomp.open;
try
posmodule.bmcomp.Execute;
except
end;

posmodule.fromcomp.close;

posmodule.fromcontact.open;
try
posmodule.bmcontact.Execute;
except
end;


posmodule.fromuser.Open;

try
posmodule.bmuser.Execute;
except
showmessage('User List Refresh Error!!');
end;
posmodule.fromuser.close;
posmodule.fromcurr.open;
try
posmodule.bmcurr.Execute;
except
end;
posmodule.fromcurr.close;
posmodule.fromdescr.open;
try
posmodule.bmdescr.Execute;
except
end;
posmodule.fromdescr.close;

posmodule.locstock.open;

posmodule.touser.open;

posmodule.tosub.open;
posmodule.tocontact.open;
posmodule.tocurr.open;
try
posmodule.tocurr.Locate('currid',2,[]);

p_posmodule.myval2:=posmodule.tocurr.fieldbyname('currval').ascurrency;

except
end;


posmodule.configs.close;
posmodule.configs.open;
posmodule.tocomp.open;



posmodule.touser.locate('username',s,[]);

showmessage('The Refresh Is Complete');
end;

procedure Tf_pospr.PrintChefDetail1Click(Sender: TObject);
begin

if touser.active=False then
touser.open;


    if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.Create(self);
try
f_passdlg.ShowModal;
if touser.Locate('pass',f_passdlg.Password.Text,[]) then
begin
if touser.FieldByName('posreport').AsString<>'True' then
begin
     if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;

end
else
begin
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;

exit;
end;
except
end;
       if  assigned(f_passdlg) then
  freeandnil(f_passdlg);
touser.close;
try
repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+ 'chef.fr3') ;
repmodule.frxReport1.ShowReport  ;
except
end;
end;

procedure Tf_pospr.DatabaseMaintenance1Click(Sender: TObject);
begin
posmodule.pos.Connected:=false;
//Application.CreateForm(Tf_validate,f_validate);
if  assigned(f_validate) then
freeandnil(f_validate);
f_validate:=tf_validate.Create(self);
try

f_validate.ShowModal;


except
end;
showmessage('Press ok To Exit The Program...');
if  assigned(f_validate) then
freeandnil(f_validate);
close;
end;

procedure Tf_pospr.Register1Click(Sender: TObject);
begin
//Application.CreateForm(Tf_register,f_register);
  if not assigned(f_register) then
f_register:=tf_register.Create(self);
try
f_register.ShowModal;
except
end;
if  assigned(f_register) then
freeandnil(f_register);
end;

procedure Tf_pospr.Ftp1Click(Sender: TObject);
begin
f_ftp:=tf_ftp.Create(self);
try
f_ftp.ShowModal;
except
end;
f_ftp.Release;
end;

procedure Tf_pospr.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  query3.close;
end;

procedure Tf_pospr.DBCtrlGrid1Click(Sender: TObject);
var s:string;
begin
s:=Query3Ip.AsString;
posmodule.pos.Connected:=false;
posmodule.pos.Params.Values['SERVER NAME']:=s;
posmodule.pos.Connected:=true;
posmodule.configs.open;
end;

procedure Tf_pospr.query3AfterPost(DataSet: TDataSet);
begin
 query3.Refresh;
end;

procedure Tf_pospr.PosList1Click(Sender: TObject);
begin
f_ips:=tf_ips.create(self);
try
f_ips.ShowModal;
except

end;
f_ips.Release;
query3.close;
query3.open;
end;

end.
