unit p_rest;

interface

uses
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  dxflchrt, ExtCtrls, Db, DBTables,
  StdCtrls, Grids, DBGrids,ShellAPI, dxFcEdit,
  Menus, ImgList, RzPanel, RzButton, Mask, DBCtrls, RzSplit;

type
  Tf_rest = class(TForm)
    dxFlowChart: TdxFlowChart;
    RzPanel1: TRzPanel;
    RzBitBtn2: TRzBitBtn;
    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;
    Memo1: TMemo;
    RzBitBtn1: TRzBitBtn;
    RzBitBtn3: TRzBitBtn;
    RzBitBtn4: TRzBitBtn;
    RzBitBtn5: TRzBitBtn;
    Query2: TQuery;
    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;
    Query1DISCOUNT: TFloatField;
    Query1PRN: TStringField;
    Query1CHEF: TStringField;
    qclose: TQuery;
    dqclose: TDataSource;
    qcloseCOUNT: TIntegerField;
    qcloseSUM: TFloatField;
    qopen: TQuery;
    IntegerField1: TIntegerField;
    FloatField1: TFloatField;
    DataSource1: TDataSource;
    ImageList1: TImageList;
    RzBitBtn6: TRzBitBtn;
    procedure FormShow(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure dxFlowChartDblClick(Sender: TObject);
    procedure RzBitBtn4Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure RzBitBtn3Click(Sender: TObject);
    procedure RzBitBtn5Click(Sender: TObject);
    procedure RzBitBtn6Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_rest: Tf_rest;   FUpdate : Boolean;

implementation

uses p_posmodule, p_cashinv, p_touchinv, p_touchcash, p_telep, P_pasdlg;

{$R *.DFM}

procedure Tf_rest.FormShow(Sender: TObject);

var AStream : TMemoryStream;
begin
//  if not FUpdate then Exit;
  dxFlowChart.BeginUpdate;
  dxFlowChart.Clear;
  if not (TBlobField(POSMODULE.CONFIGS.FieldByName('PICTURE')).isNull) then begin
    AStream := TMemoryStream.Create;
    TBlobField(POSMODULE.CONFIGS.FieldByName('PICTURE')).SaveToStream(AStream);
    AStream.Position := 0;
    dxFlowChart.LoadFromStream(AStream);
    AStream.Free;
  end;
  dxFlowChart.Color := POSMODULE.CONFIGS.FieldByName('BkColor').AsInteger;
  dxFlowChart.EndUpdate;
end;



procedure Tf_rest.RzBitBtn1Click(Sender: TObject);
begin


posmodule.CONFIGS.ApplyUpdates;
posmodule.CONFIGS.close;
posmodule.CONFIGS.open;



end;

procedure Tf_rest.RzBitBtn2Click(Sender: TObject);
begin
posmodule.CONFIGS.cancelUpdates;
posmodule.CONFIGS.close;
posmodule.CONFIGS.open;
close;

end;

procedure Tf_rest.dxFlowChartDblClick(Sender: TObject);


begin

if (dxFlowChart.SelectedObject.Height<60) or
    (dxFlowChart.SelectedObject.Height>100) then exit;


MEMO1.Lines.Clear;

MEMO1.Lines.TEXT:=dxFlowChart.SelectedObject.Text;






query1.close;
query1.ParamByName('mytable').asstring:=MEMO1.Lines.Strings[0];
query1.open;
posmodule.CURrFAC.open;

if query1.IsEmpty then
begin
posmodule.CURRFAC.Insert;
posmodule.CURRFACtableno.AsString:=MEMO1.Lines.Strings[0];
posmodule.CURRFACIACTIVE.AsString:='True';
end
else
begin
posmodule.CURRFAC.Locate('id',query1id.AsInteger,[]);
posmodule.CURRFAC.EDIT;
posmodule.CURRFACIACTIVE.AsString:='True';
end;




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;

 if  assigned(f_touchinv) then
freeandnil(f_touchinv);
posmodule.ITEMS.close;
posmodule.CURrFAC.close;



end;


query1.close;
query1.ParamByName('mytable').asstring:=MEMO1.Lines.Strings[0];
query1.open;
MEMO1.Lines.Text:=MEMO1.Lines.Strings[0];

if query1.IsEmpty=false then
begin
//MEMO1.Lines.ADD('   ');
MEMO1.Lines.ADD(Query1TOTAL.AsString+' L.L');
MEMO1.Lines.ADD(Query1chef.AsString);
end;
dxFlowChart.SelectedObject.Text:=MEMO1.Lines.Text;

if query1.IsEmpty then
begin
dxFlowChart.SelectedObject.BkColor:=posmodule.CONFIGSBKCOLOR.AsInteger;
dxFlowChart.SelectedObject.Transparent:=false;

end
else
begin
dxFlowChart.SelectedObject.BkColor:=$004BEF5B;
dxFlowChart.SelectedObject.Transparent:=false;


end;



end;

procedure Tf_rest.RzBitBtn4Click(Sender: TObject);
begin
if (dxFlowChart.SelectedObject.Height<60) or
    (dxFlowChart.SelectedObject.Height>100) then exit;

MEMO1.Lines.Clear;

MEMO1.Lines.TEXT:=dxFlowChart.SelectedObject.Text;




query1.close;
query1.ParamByName('mytable').asstring:=MEMO1.Lines.Strings[0];
query1.open;
IF   query1.IsEmpty=FALSE THEN
BEGIN
SHOWMESSAGE('This Table Is busy!!!');
EXIT;
END;


 query2.close;
query2.ParamByName('mytable').asstring:=MEMO1.Lines.Strings[0];
query2.open;


posmodule.CURrFAC.open;

if query2.IsEmpty then
begin
posmodule.CURRFAC.Insert;
posmodule.CURRFACtableno.AsString:=MEMO1.Lines.Strings[0];
posmodule.CURRFACIACTIVE.AsString:='BOOK';
end
else
begin
posmodule.CURRFAC.Locate('id',query2id.AsInteger,[]);
posmodule.CURRFAC.EDIT;
posmodule.CURRFACIACTIVE.AsString:='False';
end;




posmodule.CURrFAC.POST;

posmodule.CURrFAC.close;



dxFlowChart.SelectedObject.BkColor:=posmodule.CONFIGSBKCOLOR.AsInteger;

query2.close;
query2.ParamByName('mytable').asstring:=MEMO1.Lines.Strings[0];
query2.open;
 if query2.IsEmpty=FALSE then
 BEGIN
dxFlowChart.SelectedObject.BkColor:=CLRED;

 END;




end;

procedure Tf_rest.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var AStream : TMemoryStream;
begin
try
 FUpdate := False;
      POSMODULE.CONFIGS.Edit;
      AStream := TMemoryStream.Create;
      dxFlowChart.SaveToStream(AStream);
      AStream.Position := 0;
      TBlobField(POSMODULE.CONFIGS.FieldByName('PICTURE')).LoadFromStream(AStream);
      AStream.Free;
      POSMODULE.CONFIGS.FieldByName('BkColor').AsInteger := dxFlowChart.Color;
      POSMODULE.CONFIGS.Post;
      FUpdate := True;

posmodule.CONFIGS.ApplyUpdates;
posmodule.CONFIGS.close;
posmodule.CONFIGS.open;



except
end;
end;

procedure Tf_rest.RzBitBtn3Click(Sender: TObject);
begin
posmodule.CURrFAC.open;


posmodule.CURRFAC.Insert;




posmodule.CURrFAC.POST;

posmodule.items.open;
//1: b:=false;
//Application.CreateForm(Tf_touchcash,f_touchcash);
  if not assigned(f_touchcash) then
f_touchcash:=tf_touchcash.create(self);
if f_touchcash.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;

 if  assigned(f_touchcash) then
freeandnil(f_touchcash);
posmodule.ITEMS.close;
posmodule.CURrFAC.close;



end;


end;

procedure Tf_rest.RzBitBtn5Click(Sender: TObject);
begin
//Application.CreateForm(Tf_telep,f_telep);
  if not assigned(f_telep) then
f_telep:=tf_telep.create(self);
try
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.CURrFAC.POST;

posmodule.items.open;
//1: b:=false;
//Application.CreateForm(Tf_touchcash,f_touchcash);
  if not assigned(f_touchcash) then
f_touchcash:=tf_touchcash.create(self);
if f_touchcash.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;
 if  assigned(f_touchcash) then
freeandnil(f_touchcash);

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



end;

end;
except
end;
 if  assigned(f_telep) then
freeandnil(f_telep);

end;

procedure Tf_rest.RzBitBtn6Click(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);


end;

end.
