unit p_mytoush;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  cxPropertiesStore, IvDictio, IvMulti, ImgList, cxStyles, Db, DBTables,
  AdvCardList, DBAdvCardList, cxGridLevel, cxGridCustomTableView,
  cxGridCardView, cxGridDBCardView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, RzButton, RzStatus, cxVGrid, cxDBVGrid,
  cxInplaceContainer, ExtCtrls, RzPanel, StdCtrls, BUThreadTimer, RzDBLbl,
  RzLabel, DBCtrls, DBCGrids;

type
  Tf_mytoush = class(TForm)
    RzPanel1: TRzPanel;
    RzPanel2: TRzPanel;
    RzPanel3: TRzPanel;
    RzPanel4: TRzPanel;
    RzPanel5: TRzPanel;
    RzPanel6: TRzPanel;
    RzPanel7: TRzPanel;
    RzBitBtn1: TRzBitBtn;
    RzBitBtn2: TRzBitBtn;
    RzBitBtn4: TRzBitBtn;
    MYREST: TQuery;
    MYRESTID: TIntegerField;
    MYRESTAUTONO: TIntegerField;
    MYRESTFNO: TStringField;
    MYRESTVAT: TFloatField;
    MYRESTSUBTOTAL: TFloatField;
    MYRESTTOTAL: TFloatField;
    MYRESTCASHIN: TFloatField;
    MYRESTCASHOUT: TFloatField;
    MYRESTTABLENO: TStringField;
    MYRESTIACTIVE: TStringField;
    MYRESTNAME: TStringField;
    MYRESTCOVER: TIntegerField;
    MYRESTISTATE: TIntegerField;
    MYRESTLASTTIME: TDateTimeField;
    MYRESTCREATETIME: TDateTimeField;
    MYRESTDISCOUNT: TFloatField;
    MYRESTPRN: TStringField;
    MYRESTCHEF: TStringField;
    MYRESTSID: TStringField;
    MYRESTCONTACT: TIntegerField;
    DMYREST: TDataSource;
    MYORDER: TQuery;
    IntegerField1: TIntegerField;
    IntegerField2: TIntegerField;
    StringField1: TStringField;
    FloatField1: TFloatField;
    FloatField2: TFloatField;
    FloatField3: TFloatField;
    FloatField4: TFloatField;
    FloatField5: TFloatField;
    StringField2: TStringField;
    StringField3: TStringField;
    StringField4: TStringField;
    IntegerField3: TIntegerField;
    IntegerField4: TIntegerField;
    DateTimeField1: TDateTimeField;
    DateTimeField2: TDateTimeField;
    FloatField6: TFloatField;
    StringField5: TStringField;
    StringField6: TStringField;
    StringField7: TStringField;
    IntegerField5: TIntegerField;
    DMYORDER: TDataSource;
    cxGrid2: TcxGrid;
    cxGridDBCardView1: TcxGridDBCardView;
    cxGridLevel1: TcxGridLevel;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    MYRESTZALEID: TIntegerField;
    ImageList1: TImageList;
    mycard: TDBAdvCardList;
    cxStyle3: TcxStyle;
    cxGridDBCardView1AUTONO: TcxGridDBCardViewRow;
    cxGridDBCardView1TABLENO: TcxGridDBCardViewRow;
    cxGridDBCardView1NAME: TcxGridDBCardViewRow;
    RzBitBtn5: TRzBitBtn;
    cxStyle4: TcxStyle;
    IvTranslator1: TIvTranslator;
    cxGrid1: TcxGrid;
    cxGrid1DBCardView1: TcxGridDBCardView;
    cxGrid1DBCardView1Row4: TcxGridDBCardViewRow;
    cxGrid1DBCardView1Row1: TcxGridDBCardViewRow;
    cxGrid1DBCardView1Row2: TcxGridDBCardViewRow;
    cxGrid1DBCardView1Row3: TcxGridDBCardViewRow;
    cxGrid1Level1: TcxGridLevel;
    MYRESThhh: TStringField;
    cxGrid1DBCardView1Row5: TcxGridDBCardViewRow;
    cxStyle5: TcxStyle;
    cxStyle6: TcxStyle;
    cxGrid1DBCardView1Row6: TcxGridDBCardViewRow;
    toush: TcxPropertiesStore;
    RzFieldStatus1: TRzFieldStatus;
    RzFieldStatus3: TRzFieldStatus;
    RzFieldStatus2: TRzFieldStatus;
    MYRESTmytime: TTimeField;
    cxGrid1DBCardView1Row7: TcxGridDBCardViewRow;
    RzBitBtn7: TRzBitBtn;
    MYRESTPAID: TStringField;
    cxGrid1DBCardView1Row8: TcxGridDBCardViewRow;
    cxStyle7: TcxStyle;
    RzBitBtn8: TRzBitBtn;
    cxGrid3: TcxGrid;
    cxGridDBCardView2: TcxGridDBCardView;
    cxGridDBCardViewRow1: TcxGridDBCardViewRow;
    cxGridDBCardViewRow2: TcxGridDBCardViewRow;
    cxGridDBCardViewRow3: TcxGridDBCardViewRow;
    cxGridDBCardViewRow4: TcxGridDBCardViewRow;
    cxGridDBCardViewRow5: TcxGridDBCardViewRow;
    cxGridDBCardViewRow6: TcxGridDBCardViewRow;
    cxGridDBCardViewRow8: TcxGridDBCardViewRow;
    cxGridLevel2: TcxGridLevel;
    Query2: TQuery;
    DMOB: TDataSource;
    Query2ID: TIntegerField;
    Query2AUTONO: TIntegerField;
    Query2FNO: TStringField;
    Query2VAT: TFloatField;
    Query2SUBTOTAL: TFloatField;
    Query2TOTAL: TFloatField;
    Query2CASHIN: TFloatField;
    Query2CASHOUT: TFloatField;
    Query2TABLENO: TStringField;
    Query2IACTIVE: TStringField;
    Query2NAME: TStringField;
    Query2COVER: TIntegerField;
    Query2ISTATE: TIntegerField;
    Query2LASTTIME: TDateTimeField;
    Query2CREATETIME: TDateTimeField;
    Query2DISCOUNT: TFloatField;
    Query2PRN: TStringField;
    Query2CHEF: TStringField;
    Query2SID: TStringField;
    Query2CONTACT: TIntegerField;
    Query2ZALEID: TIntegerField;
    Query2SDISC: TFloatField;
    Query2PAID: TStringField;
    Label1: TLabel;
    BUThreadTimer1: TBUThreadTimer;
    Query1: TQuery;
    Query1ID: TIntegerField;
    Query1AUTONO: TIntegerField;
    Query1FNO: TStringField;
    Query1VAT: TFloatField;
    Query1SUBTOTAL: TFloatField;
    Query1TOTAL: TFloatField;
    Query1CASHIN: TFloatField;
    Query1CASHOUT: TFloatField;
    Query1TABLENO: TStringField;
    Query1IACTIVE: TStringField;
    Query1NAME: TStringField;
    Query1COVER: TIntegerField;
    Query1ISTATE: TIntegerField;
    Query1LASTTIME: TDateTimeField;
    Query1CREATETIME: TDateTimeField;
    Query1DISCOUNT: TFloatField;
    Query1PRN: TStringField;
    Query1CHEF: TStringField;
    Query1ZALEID: TIntegerField;
    RzBitBtn9: TRzBitBtn;
    RzBitBtn10: TRzBitBtn;
    RzBitBtn11: TRzBitBtn;
    Query2DOPRN: TStringField;
    mysum: TQuery;
    mysumMYCOUNT: TIntegerField;
    mysumMYTOTAL: TFloatField;
    RzPanel8: TRzPanel;
    RzPanel9: TRzPanel;
    RzPanel10: TRzPanel;
    RzLabel1: TRzLabel;
    RzDBLabel1: TRzDBLabel;
    dmysum: TDataSource;
    RzDBLabel2: TRzDBLabel;
    RzLabel2: TRzLabel;
    cxGridDBCardView1Row1: TcxGridDBCardViewRow;
    cxGridDBCardView1Row2: TcxGridDBCardViewRow;
    mysumCOVER: TIntegerField;
    RzDBLabel3: TRzDBLabel;
    RzBitBtn12: TRzBitBtn;
    DBCtrlGrid1: TDBCtrlGrid;
    DBText1: TDBText;
    RzBitBtn13: TRzBitBtn;
    RzBitBtn14: TRzBitBtn;
    cxGridDBCardView1Row3: TcxGridDBCardViewRow;
    cxStyle8: TcxStyle;
    cxStyle9: TcxStyle;
    cxStyle10: TcxStyle;
    RzBitBtn16: TRzBitBtn;
    RzBitBtn6: TRzBitBtn;
    RzBitBtn3: TRzBitBtn;
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure RzBitBtn3Click(Sender: TObject);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure RzBitBtn6Click(Sender: TObject);
    procedure RzBitBtn4Click(Sender: TObject);
    procedure mycardDrawCardItemProp(Sender: TObject; Card: TAdvCard;
      Item: TAdvCardItem; AFont: TFont; ABrush: TBrush);
    procedure mycardClick(Sender: TObject);
    procedure MYRESTCalcFields(DataSet: TDataSet);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure RzBitBtn5Click(Sender: TObject);
    procedure cxGrid1DBCardView1StylesGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    procedure FormCreate(Sender: TObject);
    procedure RzBitBtn7Click(Sender: TObject);
    procedure mytttTimer(Sender: TObject);
    procedure RzBitBtn8Click(Sender: TObject);
    procedure MYRESTAfterOpen(DataSet: TDataSet);
    procedure MYRESTAfterClose(DataSet: TDataSet);
    procedure cxGridDBCardView2CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure Label1Click(Sender: TObject);
    procedure BUThreadTimer1Timer(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure RzBitBtn9Click(Sender: TObject);
    procedure RzBitBtn10Click(Sender: TObject);
    procedure RzBitBtn11Click(Sender: TObject);
    procedure cxGridDBCardView2StylesGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    procedure MYRESTBeforeOpen(DataSet: TDataSet);
    procedure Query1BeforeOpen(DataSet: TDataSet);
    procedure cxGrid1DBCardView1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure cxGridDBCardView1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure mysumBeforeOpen(DataSet: TDataSet);
    procedure RzBitBtn12Click(Sender: TObject);
    procedure RzBitBtn13Click(Sender: TObject);
    procedure RzBitBtn14Click(Sender: TObject);
    procedure cxGridDBCardView1StylesGetContentStyle(
      Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
      AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
    procedure MYORDERAfterOpen(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_mytoush: Tf_mytoush;

implementation

uses p_posmodule, p_touchinv, p_tablenoC, P_pasdlg, p_telep,
  p_merge, p_touchcash2, p_mychef, p_mynotes, p_deliv, p_repmodule, p_mob,
  p_myinput;

{$R *.DFM}

procedure Tf_mytoush.FormShow(Sender: TObject);
begin
try
if posmodule.CONFIGSCLOSINGREST.AsString='True' then
begin
rzpanel4.Visible:=false;
RzBitBtn7.Visible:=false;
end;

MYREST.OPEN;
MYORDER.OPEN;
except
end;

end;

procedure Tf_mytoush.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
try
BUThreadTimer1.Active:=false;
except
end;
MYREST.CLOSE;
MYORDER.CLOSE;


end;

procedure Tf_mytoush.RzBitBtn3Click(Sender: TObject);
begin
CLOSE;
end;

procedure Tf_mytoush.RzBitBtn2Click(Sender: TObject);
var s:string; i:integer;
begin
try
i:=0;

//Application.CreateForm(Tf_tablenoc,f_tablenoc);
  if not assigned(f_tablenoc) then
 f_tablenoc:=tf_tablenoc.create(self);
try
if f_tablenoc.ShowModal=mrok then
begin
if (trim(f_tablenoc.Edit1.Text)<>'')
 and (f_tablenoc.Edit1.Text<>'0') then
s:=trim(f_tablenoc.Edit1.Text)
else
begin
 if  assigned(f_tablenoc) then
 freeandnil(f_tablenoc);
exit;
end;


end
else
begin
  if  assigned(f_tablenoc) then
 freeandnil(f_tablenoc);
exit;
end;
except
end;
  if  assigned(f_tablenoc) then
freeandnil(f_tablenoc);





query1.close;
query1.ParamByName('mytable').asstring:=S;
query1.ParamByName('myID').ASINTEGER:=posmodule.ZALEid.AsInteger;
query1.open;
posmodule.CURrFAC.close;
posmodule.CURrFAC.open;
posmodule.CURrFAC.Refresh;
if posmodule.CURRFAC.Locate('id',query1id.AsInteger,[]) then
begin

if posmodule.touser.fieldbyname('alltable').AsString='NO' then
begin

if posmodule.CURRFACUSER_.AsString<>p_posmodule.myuser then
begin
showmessage('Table Open By Another User!!!');
posmodule.CURrFAC.close;
exit;
end;

end ;



posmodule.CURRFAC.EDIT;


end
else
begin


posmodule.CURRFAC.insert;
i:=1;
end;
posmodule.CURRFACCREATETIME.AsDateTime:=time;
posmodule.CURRFACTABLENO.AsString:=s;
posmodule.CURRFACIACTIVE.AsString:='True';





posmodule.CURrFAC.POST;

posmodule.items.open;
//1: b:=false;

//Application.CreateForm(Tf_touchinv,f_touchinv);
 // if not assigned(f_touchinv) then
f_touchinv:=tf_touchinv.create(self);
try
 if i=1 then
p_touchinv.iii:=1
else
p_touchinv.iii:=0;

if posmodule.CONFIGSMINUSQTY.AsString='YES' then
p_touchinv.iii:=0;



if f_touchinv.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;

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

posmodule.ITEMS.close;
posmodule.CURrFAC.close;

QUERY1.CLOSE;
MYREST.CLOSE;
MYREST.OPEN;


 if posmodule.touser.fieldbyname('alltable').AsString='NO' then
RzBitBtn6Click(RzBitBtn6);
except
end;

end;

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



repeat
f_passdlg.Password.Text:='';

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);
try

   MYREST.close;
MYREST.open;
if posmodule.touser.fieldbyname('alltable').AsString='NO' then
   begin
   RzPanel4.Visible:=false;
   RzBitBtn7.Visible:=false;
   end
   else
   begin
   RzPanel4.Visible:=true;
   RzBitBtn7.Visible:=true;
   end;

except
end;

except
end;

end;

procedure Tf_mytoush.RzBitBtn4Click(Sender: TObject);
label 1;
var no:integer;
begin
1:;
no:=0;


//Application.CreateForm(Tf_telep,f_telep);
    if  assigned(f_telep) then
freeandnil(f_telep);
f_telep:=tf_telep.create(self);
f_telep.myorder.open;
if f_telep.ShowModal=mrok then
begin

posmodule.CURrFAC.open;


posmodule.CURRFAC.Insert;

posmodule.CURRFACNAME.AsString:=f_telep.Query1name.AsString;
posmodule.CURRFACCONTACT.AsString:=f_telep.Query1id.AsString;
posmodule.CURRFACTABLENO.AsString:='Delivery';
posmodule.CURRFACIACTIVE.AsString:='D';

posmodule.CURrFAC.POST;

posmodule.items.open;
//1: b:=false;
//Application.CreateForm(Tf_touchcash,f_touchcash);
//  if not assigned(f_touchinv) then
f_touchinv:=tf_touchinv.create(self);
f_touchinv.btnclose.Visible:=false;
f_touchinv.rzcedit.Visible:=false;
//p_touchinv.myprn:=1;

if f_touchinv.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;
no:=1;

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

posmodule.ITEMS.close;
posmodule.CURrFAC.close;






end;
try
    if  assigned(f_telep) then
f_telep.myorder.close;
except
end;

    if  assigned(f_telep) then
freeandnil(f_telep);
  if assigned(f_touchinv) then
  freeandnil(f_touchinv);
myorder.close;
myorder.open;

 if (RzBitBtn13.Caption<>'Delivery') and (no=1) then goto 1;












end;



procedure Tf_mytoush.mycardDrawCardItemProp(Sender: TObject;
  Card: TAdvCard; Item: TAdvCardItem; AFont: TFont; ABrush: TBrush);
begin
inherited;


if Card.ItemList.Items[3].AsBoolean=true then
begin
afont.Size:=10;

ABrush.Color:=clred
end
else
if Card.ItemList.Items[5].AsString='BOOK' then
begin
afont.Size:=10;
ABrush.Color:=$00C1FFC1
end

end;

procedure Tf_mytoush.mycardClick(Sender: TObject);
var s:string;
begin
IF MYREST.IsEmpty THEN EXIT;
S:=MYRESTTABLENO.AsString;




query1.close;
query1.ParamByName('mytable').asstring:=S;
query1.ParamByName('myID').ASINTEGER:=MYRESTZALEID.AsInteger;
query1.open;
posmodule.CURrFAC.open;


posmodule.CURRFAC.Locate('id',query1id.AsInteger,[]);
posmodule.CURRFAC.EDIT;
posmodule.CURRFACIACTIVE.AsString:='True';





posmodule.CURrFAC.POST;

posmodule.items.open;
//1: b:=false;
//Application.CreateForm(Tf_touchinv,f_touchinv);
  if not assigned(f_touchinv) then
f_touchinv:=tf_touchinv.create(self);
if f_touchinv.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;
f_telep.myorder.close;
    if  assigned(f_telep) then
freeandnil(f_telep);
     if  assigned(f_touchinv) then
 freeandnil(f_touchinv);

posmodule.ITEMS.close;
posmodule.CURrFAC.close;


MYREST.CLOSE;
MYREST.OPEN;

QUERY1.CLOSE;
end;



end;

procedure Tf_mytoush.MYRESTCalcFields(DataSet: TDataSet);
var c:currency;
begin
c:=time;

MYRESTmytime.AsCurrency:=MYRESTCREATETIME.AsDateTime-time;


MYRESThhh.AsString:='    ';
end;

procedure Tf_mytoush.RzBitBtn1Click(Sender: TObject);
var s:string;
begin
//Application.CreateForm(Tf_tablenoc,f_tablenoc);
  if not assigned(f_tablenoc) then
f_tablenoc:=tf_tablenoc.create(self);
if f_tablenoc.ShowModal=mrok then
begin
if trim(f_tablenoc.Edit1.Text)<>'' then
s:=trim(f_tablenoc.Edit1.Text)
else
begin
if  assigned(f_tablenoc) then
 freeandnil(f_tablenoc);
exit;
end;


end
else
begin
 if  assigned(f_tablenoc) then
 freeandnil(f_tablenoc);
exit;
end;
try
  if assigned(f_tablenoc) then
freeandnil(f_tablenoc);
except
end;




query1.close;
query1.ParamByName('mytable').asstring:=S;
query1.ParamByName('myID').ASINTEGER:=posmodule.ZALEid.AsInteger;
query1.open;
posmodule.CURrFAC.open;

if not (posmodule.CURRFAC.Locate('id',query1id.AsInteger,[])) then


begin
posmodule.CURRFAC.insert;
posmodule.CURRFACTABLENO.AsString:=s;
posmodule.CURRFACIACTIVE.AsString:='BOOK';
posmodule.CURrFAC.POST;
posmodule.items.open;
posmodule.items.insert;
posmodule.items.post;
posmodule.items.close;
end;





posmodule.CURrFAC.close;

QUERY1.CLOSE;
MYREST.CLOSE;
MYREST.OPEN;





end;

procedure Tf_mytoush.RzBitBtn5Click(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;
//Application.CreateForm(Tf_touchcash2,f_touchcash2);
//  if not assigned(f_touchcash2) then
f_touchcash2:=tf_touchcash2.create(self);
try
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;
//if b then goto 1;
 end;

 except
 end;

 //if  assigned(f_touchcash2) then
 f_touchcash2.Release;

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




 myorder.close;
myorder.open;

end;

procedure Tf_mytoush.cxGrid1DBCardView1StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
  var c:currency;
begin
inherited;

TRY
try
astyle:=cxStyle1;

if (arecord.Values[0]='True') then
astyle.Color:=cxStyle5.Color    ;

if (arecord.Values[0]='False') then
astyle.Color:=cxStyle2.Color    ;


astyle.Color:=cxStyle1.Color;
{ c:=arecord.Values[4];
if (c>=posmodule.CONFIGSMYMIN.AsCurrency) then
astyle.Color:=posmodule.CONFIGSMYCOLOR.AsInteger    ;
 }
 if (arecord.Values[1]='BOOK') then
astyle.Color:=cxStyle6.Color;
 if (arecord.Values[7]='True') then
astyle.Color:=cxStyle7.Color ;





except
astyle:=cxStyle1;
astyle.Color:=cxStyle1.Color;
end;

EXCEPT
END;

end;

procedure Tf_mytoush.FormCreate(Sender: TObject);
begin
try
toush.active:=posmodule.touser.FieldByName('UDESIGN').AsBoolean;
except
end;
end;

procedure Tf_mytoush.RzBitBtn7Click(Sender: TObject);
begin

try
//Application.CreateForm(Tf_merge,f_merge);
  if not assigned(f_merge) then
f_merge:=tf_merge.create(self);
f_merge.CURRFAC.open;
f_merge.items.open;
f_merge.CURRFAC2.open;
f_merge.CURRFAC2.next;
f_merge.items2.open;
try
f_merge.showmodal;
except
end;
f_merge.items.close;
f_merge.items2.close;
f_merge.CURRFAC.close;

f_merge.CURRFAC2.close;


 if  assigned(f_merge) then
freeandnil(f_merge);
posmodule.pos.Execute('delete from currfac where id not in (select currfac from items)');

QUERY1.CLOSE;
MYREST.CLOSE;
MYREST.OPEN;

except
end;

end;

procedure Tf_mytoush.mytttTimer(Sender: TObject);
var S:STRING;MYID:TBookmark;
begin
{if f_mytoush.Active then
begin
 myid:=myrest.GetBookmark;
myrest.close;
myrest.open;
myrest.GotoBookmark(myid);
myrest.FreeBookmark(myid);
end;

}
end;

procedure Tf_mytoush.RzBitBtn8Click(Sender: TObject);
var s:string;
begin
//Application.CreateForm(Tf_mychef,f_mychef);
  if not assigned(f_mychef) then
f_mychef:=tf_mychef.create(self);
try
f_mychef.ShowModal;

s:=p_mychef.mys;
//Application.CreateForm(Tf_deliverycheck,f_deliverycheck);
  if not assigned(f_deliverycheck) then
f_deliverycheck:=tf_deliverycheck.create(self);
f_deliverycheck.Edit1.Text:=s;
try
f_deliverycheck.ShowModal;
except
end;
  if  assigned(f_deliverycheck) then
 freeandnil(f_deliverycheck);



except

end;
   if  assigned(f_mychef) then
 freeandnil(f_mychef);
myorder.close;
myorder.open;

end;

procedure Tf_mytoush.MYRESTAfterOpen(DataSet: TDataSet);
begin
QUERY2.OPEN;
mysum.open;

end;

procedure Tf_mytoush.MYRESTAfterClose(DataSet: TDataSet);
begin
QUERY2.CLOSE;
mysum.close;
end;

procedure Tf_mytoush.cxGridDBCardView2CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var s:string;
begin
INHERITED;

AHandled:=true ;
IF QUERY2.IsEmpty THEN EXIT;



S:=QUERY2TABLENO.AsString;




query1.close;
query1.ParamByName('mytable').asstring:=S;
query1.ParamByName('myID').ASINTEGER:=1;
query1.open;
posmodule.CURrFAC.open;


posmodule.CURRFAC.Locate('id',query1id.AsInteger,[]);
posmodule.CURRFAC.EDIT;
posmodule.CURRFACIACTIVE.AsString:='True';





posmodule.CURrFAC.POST;

posmodule.items.open;
//1: b:=false;
//Application.CreateForm(Tf_touchinv,f_touchinv);
//if not assigned(f_touchinv) then
f_touchinv:=tf_touchinv.create(self);
TRY
if f_touchinv.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_touchinv) then
 f_touchinv.Release;
TRY
posmodule.ITEMS.close;
posmodule.CURrFAC.close;


MYREST.CLOSE;
MYREST.OPEN;

QUERY1.CLOSE;

EXCEPT
END;

EXCEPT
END;
  AHandled:=true ;


end;

procedure Tf_mytoush.Label1Click(Sender: TObject);
begin

try

//query1.close;
//Query2.close;
//myorder.close;
try
 if  posmodule.CURRFAC.Active=false then
posmodule.CURRFAC.open;

posmodule.CURRFAC.Refresh;


except

end;
posmodule.CURRFAC.close;
TRY
Query2.close;
Query2.open;

MYREST.CLOSE;
MYREST.OPEN;
EXCEPT
END;
//myorder.open;


except
//SHOWMESSAGE('eROR');
end;
end;

procedure Tf_mytoush.BUThreadTimer1Timer(Sender: TObject);
begin
try
if f_mytoush.Active=true then
begin
Label1Click(Label1);
end;
except
end;
end;

procedure Tf_mytoush.FormDeactivate(Sender: TObject);
begin
try
BUThreadTimer1.Active:=false;
except
end;
end;

procedure Tf_mytoush.FormActivate(Sender: TObject);
begin
try
if posmodule.CONFIGSMOB.AsInteger=1 then
BUThreadTimer1.Active:=true;
except
end;
end;

procedure Tf_mytoush.RzBitBtn9Click(Sender: TObject);
var s:string; i:integer;
begin
try
i:=0;

 //Application.CreateForm(Tf_tablenoc,f_tablenoc);
 if not assigned(f_tablenoc) then
f_tablenoc:=tf_tablenoc.create(self);
try
if f_tablenoc.ShowModal=mrok then
begin
if (trim(f_tablenoc.Edit1.Text)<>'')
 and (f_tablenoc.Edit1.Text<>'0') then
s:=trim(f_tablenoc.Edit1.Text)
else
begin
     if  assigned(f_tablenoc) then
 freeandnil(f_tablenoc);
exit;
end;


end
else
begin
if  assigned(f_tablenoc) then
 freeandnil(f_tablenoc);
exit;
end;
except
end;
 if  assigned(f_tablenoc) then
freeandnil(f_tablenoc);





query1.close;
query1.ParamByName('mytable').asstring:=S;
query1.ParamByName('myID').ASINTEGER:=posmodule.ZALEid.AsInteger;
query1.open;
posmodule.CURrFAC.close;
posmodule.CURrFAC.open;

if posmodule.CURRFAC.Locate('id',query1id.AsInteger,[]) then
begin
posmodule.CURRFAC.EDIT;
posmodule.CURRFAC.post;

end
else
begin
showmessage('Wrong Table No!!!');
posmodule.ITEMS.close;
posmodule.CURrFAC.close;

QUERY1.CLOSE;
MYREST.CLOSE;
MYREST.OPEN;
exit;
end;


posmodule.items.open;
//1: b:=false;

 //Application.CreateForm(Tf_touchinv,f_touchinv);
 // if not assigned(f_touchinv) then
f_touchinv:=tf_touchinv.create(self);
try

p_touchinv.iii:=0;




f_touchinv.RzBitBtn1Click(f_touchinv.RzBitBtn1);

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


 posmodule.CURrFAC.post;



except

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


end;

//if b then goto 1;

except
end;

//if  assigned(f_touchinv) then
 f_touchinv.Release;

posmodule.ITEMS.close;
posmodule.CURrFAC.close;

QUERY1.CLOSE;




except
end;
 MYREST.CLOSE;
MYREST.OPEN;
end;

procedure Tf_mytoush.RzBitBtn10Click(Sender: TObject);
begin
 repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+'drawer.fr3') ;
 repmodule.frxReport1.PrepareReport;
repmodule.frxReport1.PrintOptions.ShowDialog:=false;
repmodule.frxReport1.ShowProgress:=false;
repmodule.frxReport1.print;


end;

procedure Tf_mytoush.RzBitBtn11Click(Sender: TObject);
begin
if not assigned(f_mob) then
f_mob:=tf_mob.Create(self);
try
f_mob.ShowModal;
except
end;
if assigned(f_mob) then
freeandnil(f_mob);
query2.close;
query2.open;
MYREST.CLOSE;
MYREST.OPEN;

QUERY1.CLOSE;

end;

procedure Tf_mytoush.cxGridDBCardView2StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
inherited;

TRY
try
astyle:=cxStyle7;

if (arecord.Values[0]='True') then
astyle.Color:=cxStyle5.Color    ;



except
astyle:=cxStyle7;
astyle.Color:=cxStyle1.Color;
end;

EXCEPT
END;

end;

procedure Tf_mytoush.MYRESTBeforeOpen(DataSet: TDataSet);
begin
if posmodule.touser.fieldbyname('alltable').AsString='NO' then
MYREST.SQL.Strings[2]:=' and user_='''+p_posmodule.myuser+''''
else
MYREST.SQL.Strings[2]:=' ';
end;

procedure Tf_mytoush.Query1BeforeOpen(DataSet: TDataSet);
begin
//if posmodule.touser.fieldbyname('alltable').AsString='NO' then
//query1.SQL.Strings[2]:=' and user_='''+p_posmodule.myuser+''''
//else
//query1.SQL.Strings[2]:=' ';
end;

procedure Tf_mytoush.cxGrid1DBCardView1CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
var s:string;
begin
INHERITED;
//if cxGrid1DBCardView1.in=false then exit;
 AHandled:=true ;

try
IF MYREST.IsEmpty THEN EXIT;

if (myrestIACTIVE.AsString='BOOK') then
begin
if messagedlg( 'You are sure to open a booked Table?',mtwarning,mbokcancel,0)<> mrok then exit;
end;


S:=MYRESTTABLENO.AsString;




query1.close;
query1.ParamByName('mytable').asstring:=S;
query1.ParamByName('myID').ASINTEGER:=MYRESTZALEID.AsInteger;
query1.open;
posmodule.CURrFAC.open;


posmodule.CURRFAC.Locate('id',query1id.AsInteger,[]);
posmodule.CURRFAC.EDIT;
posmodule.CURRFACIACTIVE.AsString:='True';





posmodule.CURrFAC.POST;

posmodule.items.open;
//1: b:=false;

//Application.CreateForm(Tf_touchinv,f_touchinv);
//if  not assigned(f_touchinv) then


f_touchinv:=tf_touchinv.create(SELF);
TRY
f_touchinv.ShowModal  ;

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;


TRY
posmodule.ITEMS.close;
posmodule.CURrFAC.close;

TRY
MYREST.CLOSE;
MYREST.OPEN;
EXCEPT
END;

QUERY1.CLOSE;

EXCEPT
END;

EXCEPT
END;

 try

// if  assigned(f_touchinv) then
f_touchinv.Release;
 except
 showmessage('djhjdkffdjfds');
 end;


if posmodule.touser.fieldbyname('alltable').AsString='NO' then
RzBitBtn6Click(RzBitBtn6);

except
end;

  AHandled:=true ;


end;

procedure Tf_mytoush.cxGridDBCardView1CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
inherited;
AHandled:=true ;
 try
     //    mycomp:=posmodule.tocomp.fieldbyname('NAME1').AsString;
     //    mycomp:=mycomp+'....................';
      //   ccc.PutString(#$1b#$40);

 // ccc.PutString(mycomp+'Order N Ready'+MYORDER.FieldByName('autono').AsString);
        except
        end;

  posmodule.CURrFAC.Filter:='iactive=''D''';
posmodule.CURrFAC.Filtered:=true;
posmodule.CURrFAC.open;
posmodule.CURRFAC.locate('id',IntegerField1.AsInteger,[]);

posmodule.CURRFAC.edit;

posmodule.CURRFACTABLENO.AsString:='Delivery';
posmodule.CURRFACIACTIVE.AsString:='D';


posmodule.CURrFAC.POST;

posmodule.items.open;
//1: b:=false;
//Application.CreateForm(Tf_touchcash2,f_touchcash2);
 // if not assigned(f_touchinv) then
f_touchinv:=tf_touchinv.create(self);
//f_touchcash2.btnexit.Visible:=true;
if f_touchinv.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;



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


end;
  //if  assigned(f_touchinv) then
 f_touchinv.Release;
 myorder.close;
myorder.open;
AHandled:=true ;
end;

procedure Tf_mytoush.mysumBeforeOpen(DataSet: TDataSet);
begin
if posmodule.touser.fieldbyname('alltable').AsString='NO' then
mysum.SQL.Strings[2]:=' and user_='''+p_posmodule.myuser+''''
else
mysum.SQL.Strings[2]:=' ';
end;

procedure Tf_mytoush.RzBitBtn12Click(Sender: TObject);
begin
myrest.close;
myrest.open;
MYORDER.close;
MYORDER.Open;
Query2.close;
Query2.open;
end;

procedure Tf_mytoush.RzBitBtn13Click(Sender: TObject);
begin
mysum.close;
if RzBitBtn13.Caption='Delivery' then
begin
RzPanel5.Visible:=false;
RzPanel4.Align:=alclient;
cxGrid3.Visible:=false;
RzBitBtn13.Caption:='Restaurent';
mysum.SQL.Strings[1]:='where iactive=''D'' ';
end
else
begin
RzPanel5.Visible:=true;
RzPanel4.Align:=alRight;
RzPanel4.Width:= 250 ;
cxGrid3.Visible:=true;
RzBitBtn13.Caption:='Delivery';
mysum.SQL.Strings[1]:='where iactive=''True''  ';


end ;
mysum.open;

end;

procedure Tf_mytoush.RzBitBtn14Click(Sender: TObject);
var i:integer;
begin
if myorder.IsEmpty then exit;
f_myinput:=tf_myinput.create(self);
f_myinput.mytxt.Caption:='Enter Delivery No : ';
f_myinput.ShowModal;
try
i:=strtoint(f_myinput.RzEdit1.Text);
except
end;
f_myinput.Release;
try
if myorder.locate('Autono',i,[]) then

begin

// AHandled:=true ;
 try
     //    mycomp:=posmodule.tocomp.fieldbyname('NAME1').AsString;
     //    mycomp:=mycomp+'....................';
      //   ccc.PutString(#$1b#$40);

 // ccc.PutString(mycomp+'Order N Ready'+MYORDER.FieldByName('autono').AsString);
        except
        end;

  posmodule.CURrFAC.Filter:='iactive=''D''';
posmodule.CURrFAC.Filtered:=true;
posmodule.CURrFAC.open;
posmodule.CURRFAC.locate('id',IntegerField1.AsInteger,[]);

posmodule.CURRFAC.edit;

posmodule.CURRFACTABLENO.AsString:='Delivery';
posmodule.CURRFACIACTIVE.AsString:='D';


posmodule.CURrFAC.POST;

posmodule.items.open;
//1: b:=false;
//Application.CreateForm(Tf_touchcash2,f_touchcash2);
 // if not assigned(f_touchinv) then
f_touchinv:=tf_touchinv.create(self);
//f_touchcash2.btnexit.Visible:=true;
if f_touchinv.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;



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


end;
  //if  assigned(f_touchinv) then
 f_touchinv.Release;
 myorder.close;
myorder.open;

end;

except
end;



end;

procedure Tf_mytoush.cxGridDBCardView1StylesGetContentStyle(
  Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord;
  AItem: TcxCustomGridTableItem; out AStyle: TcxStyle);
begin
inherited;
try
astyle:=cxStyle8;

if (arecord.Values[0]='True') then
astyle.Color:=cxStyle9.Color
else
astyle.Color:=cxStyle10.Color    ;



except
astyle:=cxStyle8;
astyle.Color:=cxStyle10.Color;
end;


end;

procedure Tf_mytoush.MYORDERAfterOpen(DataSet: TDataSet);
begin
 mysum.close;
 mysum.open;

end;

end.
