unit p_posmodule;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, SUIDlg, frxClass, frxDBSet, ImgList, Abcutil,
  AHMSystemClass, AHMTHotKeyHolder, EnJpgGr, Abcspla;

type
  Tposmodule = class(TDataModule)
    pos: TDatabase;
    server: TDatabase;
    invoice: TTable;
    CURRFAC: TTable;
    dCURRFAC: TDataSource;
    CURRFACID: TIntegerField;
    CURRFACAUTONO: TIntegerField;
    CURRFACFNO: TStringField;
    CURRFACVAT: TFloatField;
    CURRFACSUBTOTAL: TFloatField;
    CURRFACTOTAL: TFloatField;
    CURRFACCASHIN: TFloatField;
    CURRFACCASHOUT: TFloatField;
    NEXTC: TTable;
    NEXTCNEXT_: TIntegerField;
    dsitems: TDataSource;
    dsinvoice: TDataSource;
    CONFIGS: TTable;
    DataSource1: TDataSource;
    CONFIGSID: TIntegerField;
    CONFIGSCURRID: TIntegerField;
    CONFIGSCURRVAL: TFloatField;
    CONFIGSCASHNO: TStringField;
    CONFIGSSALESNO: TStringField;
    CONFIGSSALESVATNO: TStringField;
    CONFIGSVATTYPE: TStringField;
    CONFIGSSITE: TStringField;
    CONFIGSSN: TStringField;
    stock: TQuery;
    dstock: TDataSource;
    stockITEM: TStringField;
    stockDESCR1: TStringField;
    stockDESCR2: TStringField;
    stockCATEGORY: TStringField;
    stockSUBCAT1: TStringField;
    stockSUBCAT2: TStringField;
    stockWHEREIS: TStringField;
    stockSUPPLIER: TStringField;
    stockMASDAR: TStringField;
    stockPACK: TFloatField;
    stockBCOSTUS: TFloatField;
    stockBCOSTLC: TFloatField;
    stockPOSPRICE1: TFloatField;
    stockSALESCURRID: TIntegerField;
    stockPRICEA: TFloatField;
    stockPRICEB: TFloatField;
    stockPRICEC: TFloatField;
    stockPRICED: TFloatField;
    stockPRICEE: TFloatField;
    stockPRICEF: TFloatField;
    stockBARCODE1: TStringField;
    stockBARCODE2: TStringField;
    stockBARCODE3: TStringField;
    stockBARCODE4: TStringField;
    stockPACK1: TFloatField;
    stockPACK2: TFloatField;
    stockPACK3: TFloatField;
    stockPACK4: TFloatField;
    stockPRICE1: TFloatField;
    stockPRICE2: TFloatField;
    stockPRICE3: TFloatField;
    stockPRICE4: TFloatField;
    stockMINSTOCK: TFloatField;
    stockMAXSTOCK: TFloatField;
    stockGWEIGHT: TFloatField;
    stockNWEIGHT: TFloatField;
    stockVOLUME: TFloatField;
    stockSALESDISC: TFloatField;
    stockPURCHDISC: TFloatField;
    stockSUNIT: TStringField;
    stockVAT: TFloatField;
    stockBQTY: TFloatField;
    stockQTY: TFloatField;
    stockCDATE: TDateTimeField;
    stockYESNO: TStringField;
    stockCOSTUS: TFloatField;
    stockCOSTLC: TFloatField;
    stockLCOST: TFloatField;
    stockSTYPE: TIntegerField;
    stockBUY: TFloatField;
    stockPAY: TFloatField;
    stockRBUY: TFloatField;
    stockRPAY: TFloatField;
    stockADJUSTIN: TFloatField;
    stockADJUSTOUT: TFloatField;
    stockPRODIN: TFloatField;
    stockPRODOUT: TFloatField;
    stockPROFORMAQTY: TFloatField;
    stockORDERQTY: TFloatField;
    stockOQTY: TFloatField;
    stockJQTY: TFloatField;
    stockUSER_: TStringField;
    stockMIZANE: TIntegerField;
    stockMIZANE1: TIntegerField;
    stockMIZANE2: TIntegerField;
    stockMIZANE3: TIntegerField;
    stockMIZANE4: TIntegerField;
    stockOFRE: TIntegerField;
    invoiceID: TStringField;
    invoiceAUTONO: TIntegerField;
    invoiceREF: TStringField;
    invoiceFDATE: TDateTimeField;
    invoiceFIDATE: TDateTimeField;
    invoiceCURRID: TIntegerField;
    invoiceCURRVAL: TFloatField;
    invoiceJOB: TIntegerField;
    invoiceCONTACT: TIntegerField;
    invoiceSALESMAN: TIntegerField;
    invoicePRICETYPE: TIntegerField;
    invoiceSID: TStringField;
    invoiceSITE: TStringField;
    invoiceSSID: TStringField;
    invoiceVATSID: TStringField;
    invoiceINVTYPE: TIntegerField;
    invoiceNOTE: TStringField;
    invoiceSUBTOTAL: TFloatField;
    invoiceDISCOUNT: TFloatField;
    invoiceVAT: TFloatField;
    invoiceOTHER: TFloatField;
    invoiceNET: TFloatField;
    invoiceNETLC: TFloatField;
    invoiceORDERNO: TIntegerField;
    invoiceUSER_: TStringField;
    invoiceNAME: TStringField;
    invoiceADDRESS: TStringField;
    invoiceTEL: TStringField;
    invoicePAID: TFloatField;
    invoiceRECEIPTNO: TIntegerField;
    invoiceYESNO: TStringField;
    invoiceFTYPE: TIntegerField;
    invoiceSTOTAL: TFloatField;
    invoiceYESNOVAL: TFloatField;
    invoiceTSITE: TStringField;
    invoiceCURRVALLC: TFloatField;
    GETFNO: TStoredProc;
    GETITEMS: TStoredProc;
    fromsub: TTable;
    fromstock: TTable;
    tosub: TTable;
    tostock: TTable;
    fromuser: TTable;
    touser: TTable;
    bmsub: TBatchMove;
    bmstock: TBatchMove;
    bmuser: TBatchMove;
    locstock: TTable;
    fromcurr: TTable;
    bmcurr: TBatchMove;
    tocurr: TTable;
    passdlg: TsuiInputDialog;
    dlocstock: TDataSource;
    dconfigs: TDataSource;
    CONFIGSCASHNAME: TStringField;
    dtosub: TDataSource;
    dtouser: TDataSource;
    dtocurr: TDataSource;
    DOEMPTY: TStoredProc;
    CONFIGSMIZANENO: TIntegerField;
    frxcurrfac: TfrxDBDataset;
    frxitems: TfrxDBDataset;
    frxinv: TfrxDBDataset;
    frxuser_: TfrxDBDataset;
    CONFIGSPICTURE: TBlobField;
    CONFIGSBKCOLOR: TIntegerField;
    CURRFACTABLENO: TStringField;
    CURRFACIACTIVE: TStringField;
    CURRFACNAME: TStringField;
    CURRFACCOVER: TIntegerField;
    CURRFACISTATE: TIntegerField;
    CURRFACLASTTIME: TDateTimeField;
    CURRFACCREATETIME: TDateTimeField;
    CURRFACDISCOUNT: TFloatField;
    CONFIGSPOSBAR: TStringField;
    CONFIGSPOSTOUCH: TStringField;
    CURRFACPRN: TStringField;
    CURRFACCHEF: TStringField;
    fromdescr: TTable;
    bmdescr: TBatchMove;
    todescr: TTable;
    AHMHotKeyHolder1: TAHMHotKeyHolder;
    itemsinfo: TTable;
    itemsinfoID: TIntegerField;
    itemsinfoDESCR: TStringField;
    ditemsinfo: TDataSource;
    CURRFACSID: TStringField;
    CURRFACCONTACT: TIntegerField;
    CONFIGSJOB: TIntegerField;
    CONFIGSSALESMAN: TIntegerField;
    CONFIGSCONTACT: TIntegerField;
    locstockITEM: TStringField;
    locstockDESCR1: TStringField;
    locstockDESCR2: TStringField;
    locstockCATEGORY: TStringField;
    locstockSUBCAT1: TStringField;
    locstockSUBCAT2: TStringField;
    locstockWHEREIS: TStringField;
    locstockSUPPLIER: TStringField;
    locstockMASDAR: TStringField;
    locstockPACK: TFloatField;
    locstockBCOSTUS: TFloatField;
    locstockBCOSTLC: TFloatField;
    locstockPOSPRICE1: TFloatField;
    locstockSALESCURRID: TIntegerField;
    locstockPRICEA: TFloatField;
    locstockPRICEB: TFloatField;
    locstockPRICEC: TFloatField;
    locstockPRICED: TFloatField;
    locstockPRICEE: TFloatField;
    locstockPRICEF: TFloatField;
    locstockBARCODE1: TStringField;
    locstockBARCODE2: TStringField;
    locstockBARCODE3: TStringField;
    locstockBARCODE4: TStringField;
    locstockPACK1: TFloatField;
    locstockPACK2: TFloatField;
    locstockPACK3: TFloatField;
    locstockPACK4: TFloatField;
    locstockPRICE1: TFloatField;
    locstockPRICE2: TFloatField;
    locstockPRICE3: TFloatField;
    locstockPRICE4: TFloatField;
    locstockMINSTOCK: TFloatField;
    locstockMAXSTOCK: TFloatField;
    locstockGWEIGHT: TFloatField;
    locstockNWEIGHT: TFloatField;
    locstockVOLUME: TFloatField;
    locstockSALESDISC: TFloatField;
    locstockPURCHDISC: TFloatField;
    locstockSUNIT: TStringField;
    locstockVAT: TFloatField;
    locstockBQTY: TFloatField;
    locstockQTY: TFloatField;
    locstockCDATE: TDateTimeField;
    locstockYESNO: TStringField;
    locstockCOSTUS: TFloatField;
    locstockCOSTLC: TFloatField;
    locstockLCOST: TFloatField;
    locstockSTYPE: TIntegerField;
    locstockBUY: TFloatField;
    locstockPAY: TFloatField;
    locstockRBUY: TFloatField;
    locstockRPAY: TFloatField;
    locstockADJUSTIN: TFloatField;
    locstockADJUSTOUT: TFloatField;
    locstockPRODIN: TFloatField;
    locstockPRODOUT: TFloatField;
    locstockPROFORMAQTY: TFloatField;
    locstockORDERQTY: TFloatField;
    locstockOQTY: TFloatField;
    locstockJQTY: TFloatField;
    locstockUSER_: TStringField;
    locstockMIZANE: TIntegerField;
    locstockMIZANE1: TIntegerField;
    locstockMIZANE2: TIntegerField;
    locstockMIZANE3: TIntegerField;
    locstockMIZANE4: TIntegerField;
    locstockOFRE: TIntegerField;
    locstockCARTOON: TFloatField;
    fromcontact: TTable;
    bmcontact: TBatchMove;
    tocontact: TTable;
    dtocontact: TDataSource;
    fromcomp: TTable;
    bmcomp: TBatchMove;
    tocomp: TTable;
    dtocomp: TDataSource;
    CONFIGSMYMIN: TIntegerField;
    CONFIGSMYCOLOR: TIntegerField;
    ZALE: TTable;
    ZALEID: TIntegerField;
    ZALENAME: TStringField;
    DZALE: TDataSource;
    CURRFACZALEID: TIntegerField;
    CONFIGSTRSERVER: TStringField;
    CURRFACSDISC: TFloatField;
    CONFIGSCATCOL: TIntegerField;
    CONFIGSPRICE: TIntegerField;
    CONFIGSKITCHEN: TStringField;
    CONFIGSBAR: TStringField;
    CONFIGSCOCKTAIL: TStringField;
    CONFIGSFASTFOOD: TStringField;
    CONFIGSOVEN: TStringField;
    CONFIGSBOUCHERY: TStringField;
    CONFIGSSNACK: TStringField;
    CONFIGSMYDEL: TIntegerField;
    CONFIGSWHEREIS: TIntegerField;
    CONFIGSPERCE: TIntegerField;
    CONFIGSPOSTOUSH: TStringField;
    kkk: TabcLauncher;
    ImageList1: TImageList;
    CONFIGSEXTYESNO: TStringField;
    EXTCOMP: TTable;
    EXTCOMPCODE: TStringField;
    EXTCOMPMYTYPE: TStringField;
    EXTCOMPCOMPANY: TStringField;
    dEXTCOMP: TDataSource;
    qextcomp: TQuery;
    qextcompCODE: TStringField;
    qextcompMYTYPE: TStringField;
    qextcompCOMPANY: TStringField;
    frxDBDataset1: TfrxDBDataset;
    frombar: TTable;
    bmbar: TBatchMove;
    tobar: TTable;
    barcodes: TQuery;
    updoempty: TQuery;
    CONFIGSMIZANEDIGIT: TStringField;
    CONFIGSROUNDING: TIntegerField;
    itinfo: TTable;
    bminfo: TBatchMove;
    toinfo: TTable;
    qitinfo: TQuery;
    dqitinfo: TDataSource;
    CONFIGSMYPRN: TStringField;
    stockMYPRN: TStringField;
    CONFIGSDISCOUNTTYPE: TIntegerField;
    stockDISC2: TFloatField;
    stockpricedisc: TFloatField;
    CONFIGSBYITEM: TStringField;
    CONFIGSMINUSQTY: TStringField;
    items: TTable;
    itemsID: TIntegerField;
    itemsMID: TStringField;
    itemsITEM: TStringField;
    itemsSITE: TStringField;
    itemsSTTYPE: TStringField;
    itemsQTY: TFloatField;
    itemsFRAC: TFloatField;
    itemsPACK: TFloatField;
    itemsPRICE: TFloatField;
    itemsDISCOUNT: TFloatField;
    itemsVAT: TFloatField;
    itemsCOSTUS: TFloatField;
    itemsCOSTLC: TFloatField;
    itemsCATREGORYID: TIntegerField;
    itemsVATAMOUNT: TFloatField;
    itemsDEBITUS: TFloatField;
    itemsCREDITUS: TFloatField;
    itemsBARCODE: TStringField;
    itemsBONENO: TStringField;
    itemsDEBITQTY: TFloatField;
    itemsCREDITQTY: TFloatField;
    itemsYESNO: TStringField;
    itemsTOTAL: TFloatField;
    itemsFDATE: TDateTimeField;
    itemsALLQTY: TFloatField;
    itemsJOB: TIntegerField;
    itemsSID: TStringField;
    itemsSALESMAN: TIntegerField;
    itemsCONTACT: TIntegerField;
    itemsTSITE: TStringField;
    itemsDEBITLC: TFloatField;
    itemsCLC: TFloatField;
    itemsCREDITLC: TFloatField;
    itemsSTQTY: TFloatField;
    itemsCURRFAC: TIntegerField;
    itemsAUTOCURRFAC: TIntegerField;
    itemsPRN: TStringField;
    itemsDESCR: TStringField;
    itemsMYPRN: TStringField;
    itemsEXTYESNO: TIntegerField;
    itemsFIDATE: TDateTimeField;
    CONFIGSCAFETERIA: TStringField;
    CONFIGSPATESSERIE: TStringField;
    CONFIGSPIZZA: TStringField;
    CONFIGSSHISHAZ: TStringField;
    CURRFACPAID: TStringField;
    CONFIGSFRACTIONPRICE: TStringField;
    CONFIGSMILTIPRICE: TIntegerField;
    CONFIGSTOUCHNOPRN: TStringField;
    tel: TTable;
    telId: TAutoIncField;
    telTel: TStringField;
    getNEXTC: TStoredProc;
    CONFIGSMOB: TIntegerField;
    CONFIGSCHECKQTY: TStringField;
    CONFIGSORDERCHEF: TStringField;
    CONFIGSATTENTION: TStringField;
    CONFIGSPINVOICE: TStringField;
    CONFIGSCLOSINGREST: TStringField;
    CONFIGSFALET: TStringField;
    CONFIGSMYCOM: TIntegerField;
    contdet: TQuery;
    CONFIGSPOINTAMOUNT: TFloatField;
    docheck: TQuery;
    checkpro: TStoredProc;
    CURRFACDOPRN: TStringField;
    conttrig1: TQuery;
    conttrig2: TQuery;
    CONFIGSFTPAUTO: TStringField;
    CURRFACUSER_: TStringField;
    abcSingleInstance1: TabcSingleInstance;
    abcSplash1: TabcSplash;
    procedure CURRFACNewRecord(DataSet: TDataSet);
    procedure invoiceNewRecord(DataSet: TDataSet);
    procedure itemsNewRecord(DataSet: TDataSet);
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
    procedure itemsQTYChange(Sender: TField);
    procedure CURRFACAfterPost(DataSet: TDataSet);
    procedure AHMHotKeyHolder1GlobalKeys0KeyDown(Sender: TObject;
      var Key: Word; Shift: TShiftState);
    procedure itemsinfoNewRecord(DataSet: TDataSet);
    procedure itemsBeforePost(DataSet: TDataSet);
    procedure ZALEAfterScroll(DataSet: TDataSet);
    procedure AHMHotKeyHolder1GlobalKeys1KeyDown(Sender: TObject;
      var Key: Word; Shift: TShiftState);
    procedure AHMHotKeyHolder1GlobalKeys2KeyDown(Sender: TObject;
      var Key: Word; Shift: TShiftState);
    procedure RzTrayIcon1RestoreApp(Sender: TObject);
    procedure invoiceBeforePost(DataSet: TDataSet);
    procedure itemsAfterPost(DataSet: TDataSet);
    procedure qitinfoBeforeOpen(DataSet: TDataSet);
    procedure stockCalcFields(DataSet: TDataSet);
    procedure AHMHotKeyHolder1GlobalKeys3KeyDown(Sender: TObject;
      var Key: Word; Shift: TShiftState);
    procedure CURRFACBeforeInsert(DataSet: TDataSet);
    procedure posBeforeConnect(Sender: TObject);
    procedure CURRFACBeforePost(DataSet: TDataSet);
    procedure itemsPRICEChange(Sender: TField);
    procedure itemsBeforeClose(DataSet: TDataSet);
    procedure abcSingleInstance1PreviousInstance(Sender: TObject;
      PreviousInstances: Integer; var HaltThisInstance: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  posmodule: Tposmodule; myuser:string;mycontact:integer;
       myval2:currency;
implementation

uses p_repmodule, P_pasdlg, p_mytoush, p_pospr, p_touchcash2, p_msgdlg,
  p_validate;

{$R *.DFM}

procedure Tposmodule.CURRFACNewRecord(DataSet: TDataSet);
begin
getNEXTC.ExecProc;
currfacid.AsInteger:=getNEXTC.Params.ParamByName('myjid').asinteger;



CURRFACIACTIVE.AsString:='False';
CURRFACFNO.AsString:=invoiceID.AsString;
CURRFACSID.AsString:=invoiceSID.AsString;
CURRFACCONTACT.AsInteger:=invoiceCONTACT.AsInteger;
CURRFACzaleid.AsInteger:=ZALEID.AsInteger;
CURRFACCREATETIME.AsDateTime:=time;
CURRFACSID.AsString:=CONFIGSCASHNO.AsString;
CURRFACUSER_.AsString:=myuser;

end;

procedure Tposmodule.invoiceNewRecord(DataSet: TDataSet);
begin
GETFNO.ExecProc;
invoiceid.AsString:='SI'+GETFNO.ParamByName('myjid').asSTRING+CONFIGSSN.AsString;
invoiceFTYPE.AsInteger:=1;
invoicecurrid.AsInteger:=1;
invoiceCURRVAL.AsInteger:=1;
if tocurr.Active=false then
tocurr.open;
tocurr.Locate('currid',2,[]);
invoiceCURRVALLC.AsCurrency:=tocurr.fieldbyname('currval').ascurrency;


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

invoiceYESNO.AsString:='ALL';


invoicesid.AsString:=CONFIGSCASHNO.AsString;
invoiceSSID.AsString:=CONFIGSSALESNO.AsString;
invoiceVATSID.AsString:=CONFIGSSALESVATNO.AsString;
invoiceSITE.AsString:=CONFIGSSITE.AsString;
invoiceftype.AsInteger:=1;


invoicejob.AsInteger:=configsjob.AsInteger;
invoiceSALESMAN.AsInteger:=CONFIGSSALESMAN.AsInteger;
invoiceCONTACT.AsInteger:=CONFIGSCONTACT.AsInteger;




invoiceuser_.AsString:=myuser;


end;

procedure Tposmodule.itemsNewRecord(DataSet: TDataSet);
begin
getitems.ExecProc;
itemsid.AsInteger:=getitems.ParamByName('myjid').asinteger;
itemspack.AsInteger:=1;
itemsfrac.AsInteger:=0;
itemssid.AsString:=invoicesid.AsString;
itemsmid.AsString:=invoiceid.AsString;
itemsfdate.AsString:=invoicefdate.AsString;
itemsDISCOUNT.AsCurrency:=CURRFACSDISC.AsCurrency;
itemsprn.AsString:='False';

itemsCURRFAC.AsInteger:=CURRFACID.AsInteger;
posmodule.itemsCONTACT.AsCurrency:=posmodule.CURRFACCONTACT.AsCurrency ;
posmodule.itemssid.AsString:=posmodule.CURRFACsid.AsString;


itemsfidate.AsDateTime:=time;
//mitemssname.AsString:=minvoicesname.AsString;
//mitemscontact.AsString:=minvoicecontact.AsString;
//mitemsftype.AsString:=sinvoiceftype.AsString;
//mitemsjob.AsString:=sinvoicejob.AsString;
//mitemscurrid.AsInteger:=sinvoicecurrid.AsInteger;
//mitemscurrval.AsCurrency:=sinvoicecurrval.AsCurrency;
 try
itemssite.AsString:=CONFIGSSITE.AsString;

except
end;


end;

procedure Tposmodule.DataModuleCreate(Sender: TObject);
var fv,tf,tf2:textfile;s:string;
begin

if  FileExists('C:\maint.txt') <>True then
begin
// showmessage('Validation Req..');
assignfile(fv,'C:\maint.txt');
rewrite(fv);
f_validate:=tf_validate.create(self);


try

//Application.CreateForm(Tf_validate,f_validate);



  try

//f_validate.ShowModal;
try
f_validate.SpeedButton5Click(f_validate.SpeedButton5);
except
end;
try
f_validate.SpeedButton2Click(f_validate.SpeedButton2);
except
end;



if trim(f_validate.Memo1.Text)<>'' then
begin

try
f_validate.SpeedButton3Click(f_validate.SpeedButton3);
except
end;

try
if f_validate.SpeedButton4.enabled then

f_validate.SpeedButton4Click(f_validate.SpeedButton4);
except
end;

end;


except
end;
//showmessage('Press ok To Exit The Program...');


except
end;
  try
closefile(fv);
if  FileExists('C:\maint.txt') then
DeleteFile('C:\maint.txt');
except
end;


if  assigned(f_validate) then
freeandnil(f_validate);

end;




sysutils.ShortDateFormat:='dd/MM/yyyy';
assignfile(tf,extractfilepath(application.ExeName)+'ip.txt');
reset(tf);
readln(tf,s);
closefile(tf);
server.Params.Values['SERVER NAME']:=s;
if FileExists(extractfilepath(application.ExeName)+'ip2.txt') then
begin
assignfile(tf2,extractfilepath(application.ExeName)+'ip2.txt');
reset(tf2);
readln(tf2,s);
closefile(tf2);
pos.Params.Values['SERVER NAME']:=s;


end;





 touser.close;
tosub.close;
tocurr.close;
tostock.close;
todescr.close;
tocontact.close;
tocomp.close;







{
 try
  pos.execute('ALTER TABLE configs ADD mizanedigit varchar(5)  ');


 except

 end;

 try
  pos.execute('ALTER TABLE INVOICE2  ADD CONSTRAINT INVOICE2PRIMARYKEY1  PRIMARY KEY (ID)');


 except

 end;

 try
  pos.execute('ALTER TABLE ITEMS2  ADD CONSTRAINT ITEMS2PRIMARYKEY1  PRIMARY KEY (ID)');


 except

 end;


 try
  pos.execute('ALTER TABLE ITEMS3   ADD CONSTRAINT ITEMS3PRIMARYKEY1   PRIMARY KEY (ID)');


 except

 end;




 try
  pos.execute('ALTER TABLE configs ADD myprn varchar(3)   ');


 except

 end;

  try
  pos.execute('ALTER TABLE configs ADD mizaneno integer  ');


 except

 end;

 try
  pos.execute('ALTER TABLE configs ADD rounding integer  ');


 except

 end;

try
pos.execute('alter table configs add postoush varchar(5) default ''True''');

except
end;

try
pos.execute('alter table configs add extyesno varchar(3) default ''NO''');

except
end;


try
pos.execute('alter table configs add whereis integer');

except
end;


try
pos.execute('alter table configs add catcol integer');

except
end;

try
pos.execute('alter table configs add perce integer');

except
end;


try
pos.execute('alter table configs add price integer');
pos.execute('alter table configs add KITCHEN varchar(50)');
pos.execute('alter table configs add BAR varchar(50)');
pos.execute('alter table configs add COCKTAIL varchar(50)');
pos.execute('alter table configs add FASTFOOD varchar(50)');
pos.execute('alter table configs add OVEN varchar(50)');
pos.execute('alter table configs add BOUCHERY varchar(50)');
pos.execute('alter table configs add SNACK varchar(50)');
except
end;

try
pos.execute('alter table configs add mydel integer');

except
end;





try
pos.execute('alter table configs add trserver varchar(5) default ''True''');
pos.Execute('alter table configs add mymin integer');
pos.Execute('alter table configs add mycolor integer');
except
end;
try
pos.Execute('alter table currfac add sdisc double precision');
except
end;

try
pos.Execute('alter table ITEMS add MYPRN VARCHAR(10)');
pos.Execute('alter table ITEMS2 add MYPRN VARCHAR(10)');
except
end;
try
pos.Execute('alter table ITEMS add EXTYESNO INTEGER DEFAULT 0');
pos.Execute('alter table ITEMS2 add EXTYESNO INTEGER DEFAULT 0');
except
end;

try
pos.Execute('alter table ITEMS3 add MYPRN VARCHAR(10)');
pos.Execute('alter table ITEMS3 add EXTYESNO INTEGER DEFAULT 0');
except
end;

try
pos.Execute('alter table ITEMS add fidate date');
pos.Execute('alter table ITEMS2 add fidate date');
pos.Execute('alter table ITEMS3 add fidate date');
except
end;
 }


CONFIGS.open;
try
server.Connected:=true;
if CONFIGSEXTYESNO.AsString<>'YES' then
begin


try
bmsub.Execute;
except
end;

try
bmbar.Execute;
except
end;


try
bmcomp.Execute;
except
end;

try
bmcontact.Execute;
except
end;

try
bmstock.Execute;
except
end;
try
bmuser.Execute;
except
end;
try
bmcurr.Execute;
except
end;
try
bmdescr.Execute;
except
end;

end;
except
end;




locstock.open;
touser.open;
tosub.open;
tocontact.open;
tocurr.open;
configs.open;
tocomp.open;
ZALE.Open;
  //Application.CreateForm(Tf_passdlg, f_passdlg);
    if not assigned(f_passdlg) then
f_passdlg:=tf_passdlg.Create(self);

try
repeat
if f_passdlg.ShowModal<>mrok then
begin
application.Terminate;
exit;
end;

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

end;

invoice.open;
if invoice.IsEmpty then
begin
invoice.Insert;
end
else
begin
invoice.edit;
invoiceFTYPE.AsInteger:=1;
invoicecurrid.AsInteger:=1;
invoiceCURRVAL.AsInteger:=1;
tocurr.Locate('currid',2,[]);
invoiceCURRVALLC.AsCurrency:=tocurr.fieldbyname('currval').ascurrency;
  myval2:=tocurr.fieldbyname('currval').ascurrency;


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

invoiceYESNO.AsString:='ALL';


invoicesid.AsString:=CONFIGSCASHNO.AsString;
invoiceSSID.AsString:=CONFIGSSALESNO.AsString;
invoiceVATSID.AsString:=CONFIGSSALESVATNO.AsString;
invoiceSITE.AsString:=CONFIGSSITE.AsString;
invoiceftype.AsInteger:=1;


//invoicejob.AsString:=configs.AsString;
//minvoicecontact.AsString:=(module.dmsub.DataSet as tquery).fieldbyname('contact').AsString;

invoiceuser_.AsString:=myuser;


end;

invoice.Post;










end;

procedure Tposmodule.DataModuleDestroy(Sender: TObject);
begin
if pos.Connected then
pos.Connected:=false;



if server.Connected then
server.Connected:=false;


end;


procedure Tposmodule.itemsQTYChange(Sender: TField);
var b:boolean;
begin

b:=false;
if CONFIGSFALET.AsString='True' then
begin
 try
        b:= f_touchcash2.cbsp.Checked;
        except
        end;
posMODULe.stock.close;
posMODULe.stock.ParamByName('MYITEM').ASSTRING:=itemsITEM.AsString;

posMODULe.stock.OPEN;

if    (itemsQTY.AsCurrency<0.5)    then
       BEGIN
       if (stockPRICEf.AsCurrency<>0) THEN

       itemsPRICE.AsCurrency:=stockPRICEf.AsCurrency;


         if b then
        itemsPRICE.AsCurrency:=stockPRICEe.AsCurrency


       END

       else
       begin

        if b then
        itemsPRICE.AsCurrency:=stockPRICEe.AsCurrency
        else
       itemsPRICE.AsCurrency:=stockPOSPRICE1.AsCurrency;
       end;

end;



ITEMSALLQTY.AsCurrency:=(itemsqty.AsCurrency*itemspack.AsCurrency+itemsfrac.AsCurrency);
itemstotal.AsCurrency:=ITEMSALLQTY.AsCurrency*(itemsprice.AsCurrency-
itemsprice.AsCurrency*itemsdiscount.AsCurrency/100) ;

if CONFIGSPERCE.AsInteger<>1 then
itemstotal.AsCurrency:=ITEMSQTY.AsCurrency*(itemsprice.AsCurrency-
itemsprice.AsCurrency*itemsdiscount.AsCurrency/100)  ;
//else
//itemstotal.AsCurrency:=ITEMSQTY.AsCurrency-itemsdiscount.AsCurrency;



if configsvattype.AsString='TTC' then
begin
itemsvatamount.AsCurrency:=itemstotal.AsCurrency-(itemstotal.AsCurrency)/(1+itemsvat.AsCurrency/100);
end
else
begin
itemsvatamount.AsCurrency:=itemstotal.AsCurrency*itemsvat.AsCurrency/100;
//itemstotal.AsCurrency:=itemstotal.AsCurrency+itemsvatamount.AsCurrency;


end;

//itemstotal.AsCurrency:=itemstotal.AsInteger;
 if (CONFIGSROUNDING.AsInteger>0) then
itemstotal.AsCurrency:=round(itemstotal.AsCurrency/CONFIGSROUNDING.AsCurrency)*CONFIGSROUNDING.AsCurrency;



end;

procedure Tposmodule.CURRFACAfterPost(DataSet: TDataSet);
begin
CURRFAC.Refresh;
end;

procedure Tposmodule.AHMHotKeyHolder1GlobalKeys0KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
if touser.FieldByName('UDESIGN').AsBoolean=false then
begin
f_msgdlg:=tf_msgdlg.create(self);
try
f_msgdlg.mymsg.Caption:='You dont Have permission!!!';
f_msgdlg.ShowModal;
except
end;
f_msgdlg.Release;

exit;
end;

repmodule.frxReport1.DesignReport;
end;

procedure Tposmodule.itemsinfoNewRecord(DataSet: TDataSet);
begin
itemsinfoid.AsInteger:=itemsid.AsInteger;
end;

procedure Tposmodule.itemsBeforePost(DataSet: TDataSet);
var b:boolean;
begin
TRY

itemsCONTACT.AsInteger:=mycontact;
itemssid.AsString:=CURRFACsid.AsString;
EXCEPT
END;
end;

procedure Tposmodule.ZALEAfterScroll(DataSet: TDataSet);
begin
try
f_mytoush.MYREST.close;

f_mytoush.MYREST.open;
except
end;
end;

procedure Tposmodule.AHMHotKeyHolder1GlobalKeys1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
;
end;

procedure Tposmodule.AHMHotKeyHolder1GlobalKeys2KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
;

end;

procedure Tposmodule.RzTrayIcon1RestoreApp(Sender: TObject);
begin
KKK.EXECUTE;
end;

procedure Tposmodule.invoiceBeforePost(DataSet: TDataSet);
begin
invoiceuser_.AsString:=myuser;
try

invoicesid.AsString:=CONFIGSCASHNO.AsString;
invoiceSSID.AsString:=CONFIGSSALESNO.AsString;
invoiceVATSID.AsString:=CONFIGSSALESVATNO.AsString;
invoiceSITE.AsString:=CONFIGSSITE.AsString;
invoiceftype.AsInteger:=1;


invoicejob.AsInteger:=configsjob.AsInteger;
invoiceSALESMAN.AsInteger:=CONFIGSSALESMAN.AsInteger;
invoiceCONTACT.AsInteger:=CONFIGSCONTACT.AsInteger;





if tocurr.Active=false then
tocurr.open;
tocurr.Locate('currid',2,[]);
invoiceCURRVALLC.AsCurrency:=tocurr.fieldbyname('currval').ascurrency;

except
end;

end;

procedure Tposmodule.itemsAfterPost(DataSet: TDataSet);
begin
items.Refresh;
end;

procedure Tposmodule.qitinfoBeforeOpen(DataSet: TDataSet);
begin
qitinfo.ParamByName('myitem').AsString:=stockitem.AsString;
end;

procedure Tposmodule.stockCalcFields(DataSet: TDataSet);
begin
if CONFIGSDISCOUNTTYPE.AsInteger=2 then
stockpricedisc.AsCurrency:=stockposprice1.AsCurrency-stockposprice1.AsCurrency*stockdisc2.AsCurrency/100
else
stockpricedisc.AsCurrency:=stockposprice1.AsCurrency-stockposprice1.AsCurrency*stockSALESDISC.AsCurrency/100 ;
end;

procedure Tposmodule.AHMHotKeyHolder1GlobalKeys3KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
f_pospr.ttt.Show;

end;

procedure Tposmodule.CURRFACBeforeInsert(DataSet: TDataSet);
begin
TRY
if invoice.IsEmpty then
begin
invoice.Insert;
invoice.POST;
end
EXCEPT
END;
end;

procedure Tposmodule.posBeforeConnect(Sender: TObject);
var tf:textfile;s:string;
begin
IF FileExists('ip2.txt') THEN
BEGIN
assignfile(tf,extractfilepath(application.ExeName)+'ip2.txt');
reset(tf);
readln(tf,s);
closefile(tf);

POS.Params.Values['SERVER NAME']:=s;
END;

end;

procedure Tposmodule.CURRFACBeforePost(DataSet: TDataSet);
begin
if CURRFACSID.AsString='' then
CURRFACSID.AsString:=CONFIGSCASHNO.AsString;

if CURRFACUSER_.AsString='' then
CURRFACUSER_.AsString:=myuser;

if CURRFACCHEF.AsString='' then
CURRFACCHEF.AsString:=CURRFACUSER_.AsString;






end;

procedure Tposmodule.itemsPRICEChange(Sender: TField);
begin


ITEMSALLQTY.AsCurrency:=(itemsqty.AsCurrency*itemspack.AsCurrency+itemsfrac.AsCurrency);
itemstotal.AsCurrency:=ITEMSALLQTY.AsCurrency*(itemsprice.AsCurrency-
itemsprice.AsCurrency*itemsdiscount.AsCurrency/100) ;

if CONFIGSPERCE.AsInteger<>1 then
itemstotal.AsCurrency:=ITEMSQTY.AsCurrency*(itemsprice.AsCurrency-
itemsprice.AsCurrency*itemsdiscount.AsCurrency/100)  ;
//else
//itemstotal.AsCurrency:=ITEMSQTY.AsCurrency-itemsdiscount.AsCurrency;



if configsvattype.AsString='TTC' then
begin
itemsvatamount.AsCurrency:=itemstotal.AsCurrency-(itemstotal.AsCurrency)/(1+itemsvat.AsCurrency/100);
end
else
begin
itemsvatamount.AsCurrency:=itemstotal.AsCurrency*itemsvat.AsCurrency/100;
//itemstotal.AsCurrency:=itemstotal.AsCurrency+itemsvatamount.AsCurrency;


end;

//itemstotal.AsCurrency:=itemstotal.AsInteger;
 if (CONFIGSROUNDING.AsInteger>0) then
itemstotal.AsCurrency:=round(itemstotal.AsCurrency/CONFIGSROUNDING.AsCurrency)*CONFIGSROUNDING.AsCurrency;



end;

procedure Tposmodule.itemsBeforeClose(DataSet: TDataSet);
begin
// items.ApplyUpdates;
end;

procedure Tposmodule.abcSingleInstance1PreviousInstance(Sender: TObject;
  PreviousInstances: Integer; var HaltThisInstance: Boolean);
begin
abcSingleInstance1.tag:=1;
end;

end.
