unit p_deliv;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, dxGDIPlusClasses, ExtCtrls, Mask, RzEdit, RzBtnEdt,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, Db, RzButton,
  cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGrid, DBTables,
  Menus;

type
  Tf_deliverycheck = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    RzButtonEdit1: TRzButtonEdit;
    Image1: TImage;
    Image2: TImage;
    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;
    Query1SID: TStringField;
    Query1CONTACT: TIntegerField;
    Query1ZALEID: TIntegerField;
    Query1SDISC: TFloatField;
    Query1PAID: TStringField;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    RzBitBtn1: TRzBitBtn;
    DataSource1: TDataSource;
    cxGrid1DBTableView1AUTONO: TcxGridDBColumn;
    cxGrid1DBTableView1TOTAL: TcxGridDBColumn;
    cxGrid1DBTableView1NAME: TcxGridDBColumn;
    cxGrid1DBTableView1CREATETIME: TcxGridDBColumn;
    cxGrid1DBTableView1DISCOUNT: TcxGridDBColumn;
    RzBitBtn2: TRzBitBtn;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    RzBitBtn3: TRzBitBtn;
    RzBitBtn4: TRzBitBtn;
    procedure RzButtonEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure RadioButton1Click(Sender: TObject);
    procedure RzBitBtn3Click(Sender: TObject);
    procedure RzBitBtn4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_deliverycheck: Tf_deliverycheck;

implementation

uses p_posmodule;

{$R *.DFM}

procedure Tf_deliverycheck.RzButtonEdit1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
if key=13 then
begin
 try
posmodule.pos.Execute('update currfac set chef='''+edit1.text+''' where autono='+RzButtonEdit1.Text);

query1.close;
query1.open;
except
 end;
try
query1.locate('autono',strtoint(RzButtonEdit1.Text),[]);
except
end;
RzButtonEdit1.Text:='';
end;
end;

procedure Tf_deliverycheck.RzBitBtn1Click(Sender: TObject);
begin
close;
end;

procedure Tf_deliverycheck.RzBitBtn2Click(Sender: TObject);
begin
posmodule.pos.Execute('update currfac set chef='''' where autono='+Query1AUTONO.AsString);

query1.close;
query1.open;


end;

procedure Tf_deliverycheck.FormShow(Sender: TObject);
begin
query1.ParamByName('mychef').AsString:=edit1.Text;
query1.open;
end;

procedure Tf_deliverycheck.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
query1.close;
end;

procedure Tf_deliverycheck.RadioButton1Click(Sender: TObject);
begin
query1.close;
if RadioButton1.Checked then
query1.SQL.Strings[2]:=' AND iactive=''D'''
else
query1.SQL.Strings[2]:=' AND iactive<>''D''';
query1.open;

end;

procedure Tf_deliverycheck.RzBitBtn3Click(Sender: TObject);
begin

if query1.IsEmpty then exit;
if posmodule.touser.fieldbyname('closetable').AsString='False' then
exit;
if messagedlg('Are You Sure To Close The Active Invoice???',mtwarning,mbokcancel,0)<>mrok then exit;
//if messagedlg('Are You Realy Sure ???',mtwarning,mbokcancel,0)<>mrok then exit;
try
posmodule.pos.StartTransaction;
posmodule.pos.execute('update CURRFAC set iactive=''False'' where autono='+query1AUTONO.AsString);
posmodule.pos.Commit;
query1.close;
query1.open;
except
if posmodule.pos.InTransaction then
posmodule.pos.Rollback;
end;

end;

procedure Tf_deliverycheck.RzBitBtn4Click(Sender: TObject);
var i:integer;
begin
if query1.IsEmpty then exit;
if posmodule.touser.fieldbyname('closetable').AsString='False' then
exit;
if messagedlg('Are You Sure To Close The Active Invoice???',mtwarning,mbokcancel,0)<>mrok then exit;
//if messagedlg('Are You Realy Sure ???',mtwarning,mbokcancel,0)<>mrok then exit;
query1.First;
try
for i:=1 to query1.RecordCount do
begin
posmodule.pos.StartTransaction;
try
posmodule.pos.execute('update CURRFAC set iactive=''False'' where autono='+query1AUTONO.AsString);
posmodule.pos.Commit;
except
if posmodule.pos.InTransaction then
posmodule.pos.Rollback;
end;

query1.Next;
end;
 except
 end;
query1.close;
query1.open;

end;

end.
