unit p_merge;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  RzButton, ExtCtrls, RzPanel, DBCtrls, StdCtrls, cxGridLevel,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses,
  cxControls, cxGridCustomView, cxGrid, Db, DBTables, fcButton, fcImgBtn,
  frxClass, frxDBSet;

type
  Tf_merge = class(TForm)
    RzPanel1: TRzPanel;
    RzPanel2: TRzPanel;
    RzPanel3: TRzPanel;
    RzPanel5: TRzPanel;
    RzPanel6: TRzPanel;
    RzPanel4: TRzPanel;
    RzBitBtn1: TRzBitBtn;
    RzBitBtn2: TRzBitBtn;
    RzPanel7: TRzPanel;
    tttt: TcxGrid;
    ttttDBTableView1: TcxGridDBTableView;
    ttttDBTableView1Column1: TcxGridDBColumn;
    ttttDBTableView1DESCR: TcxGridDBColumn;
    ttttDBTableView1FRAC: TcxGridDBColumn;
    ttttDBTableView1TOTAL: TcxGridDBColumn;
    ttttLevel1: TcxGridLevel;
    RzPanel8: TRzPanel;
    cxGrid1: TcxGrid;
    cxGridDBTableView1: TcxGridDBTableView;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridDBColumn2: TcxGridDBColumn;
    cxGridDBColumn3: TcxGridDBColumn;
    cxGridDBColumn4: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label1: TLabel;
    Label2: TLabel;
    DBText1: TDBText;
    CURRFAC: TTable;
    CURRFACID: TIntegerField;
    CURRFACAUTONO: TIntegerField;
    CURRFACFNO: TStringField;
    CURRFACVAT: TFloatField;
    CURRFACSUBTOTAL: TFloatField;
    CURRFACTOTAL: TFloatField;
    CURRFACCASHIN: TFloatField;
    CURRFACCASHOUT: TFloatField;
    CURRFACTABLENO: TStringField;
    CURRFACIACTIVE: TStringField;
    CURRFACNAME: TStringField;
    CURRFACCOVER: TIntegerField;
    CURRFACISTATE: TIntegerField;
    CURRFACLASTTIME: TDateTimeField;
    CURRFACCREATETIME: TDateTimeField;
    CURRFACDISCOUNT: TFloatField;
    CURRFACPRN: TStringField;
    CURRFACCHEF: TStringField;
    CURRFACSID: TStringField;
    CURRFACCONTACT: TIntegerField;
    CURRFACZALEID: TIntegerField;
    CURRFACSDISC: TFloatField;
    dCURRFAC: TDataSource;
    dsitems: TDataSource;
    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;
    currfac2: TTable;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    items2: TTable;
    items2ID: TIntegerField;
    items2MID: TStringField;
    items2ITEM: TStringField;
    items2SITE: TStringField;
    items2STTYPE: TStringField;
    items2QTY: TFloatField;
    items2FRAC: TFloatField;
    items2PACK: TFloatField;
    items2PRICE: TFloatField;
    items2DISCOUNT: TFloatField;
    items2VAT: TFloatField;
    items2COSTUS: TFloatField;
    items2COSTLC: TFloatField;
    items2CATREGORYID: TIntegerField;
    items2VATAMOUNT: TFloatField;
    items2DEBITUS: TFloatField;
    items2CREDITUS: TFloatField;
    items2BARCODE: TStringField;
    items2BONENO: TStringField;
    items2DEBITQTY: TFloatField;
    items2CREDITQTY: TFloatField;
    items2YESNO: TStringField;
    items2TOTAL: TFloatField;
    items2FDATE: TDateTimeField;
    items2ALLQTY: TFloatField;
    items2JOB: TIntegerField;
    items2SID: TStringField;
    items2SALESMAN: TIntegerField;
    items2CONTACT: TIntegerField;
    items2TSITE: TStringField;
    items2DEBITLC: TFloatField;
    items2CLC: TFloatField;
    items2CREDITLC: TFloatField;
    items2STQTY: TFloatField;
    items2CURRFAC: TIntegerField;
    items2AUTOCURRFAC: TIntegerField;
    items2PRN: TStringField;
    items2DESCR: TStringField;
    items2MYPRN: TStringField;
    items2EXTYESNO: TIntegerField;
    items2FIDATE: TDateTimeField;
    currfac2ID: TIntegerField;
    currfac2AUTONO: TIntegerField;
    currfac2FNO: TStringField;
    currfac2VAT: TFloatField;
    currfac2SUBTOTAL: TFloatField;
    currfac2TOTAL: TFloatField;
    currfac2CASHIN: TFloatField;
    currfac2CASHOUT: TFloatField;
    currfac2TABLENO: TStringField;
    currfac2IACTIVE: TStringField;
    currfac2NAME: TStringField;
    currfac2COVER: TIntegerField;
    currfac2ISTATE: TIntegerField;
    currfac2LASTTIME: TDateTimeField;
    currfac2CREATETIME: TDateTimeField;
    currfac2DISCOUNT: TFloatField;
    currfac2PRN: TStringField;
    currfac2CHEF: TStringField;
    currfac2SID: TStringField;
    currfac2CONTACT: TIntegerField;
    currfac2ZALEID: TIntegerField;
    currfac2SDISC: TFloatField;
    RzBitBtn3: TRzBitBtn;
    RzBitBtn4: TRzBitBtn;
    fcImageBtn1: TfcImageBtn;
    DBText2: TDBText;
    DBNavigator1: TDBNavigator;
    DBNavigator2: TDBNavigator;
    RzBitBtn5: TRzBitBtn;
    frominv: TfrxDBDataset;
    toinv: TfrxDBDataset;
    procedure RzBitBtn1Click(Sender: TObject);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure RzBitBtn3Click(Sender: TObject);
    procedure RzBitBtn4Click(Sender: TObject);
    procedure DBText1Click(Sender: TObject);
    procedure DBText2Click(Sender: TObject);
    procedure fcImageBtn1Click(Sender: TObject);
    procedure RzBitBtn5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_merge: Tf_merge;

implementation

uses p_tablenoC, p_posmodule, p_repmodule, p_msgdlg;

{$R *.DFM}

procedure Tf_merge.RzBitBtn1Click(Sender: TObject);
begin

if items.IsEmpty then exit;
items.edit;

itemsCONTACT.AsCurrency:=CURRFAC2CONTACT.AsCurrency ;
itemssid.AsString:=CURRFAC2sid.AsString;



itemsCURRFAC.AsInteger:=currfac2id.AsInteger;
items.post;
items.close;
items.open;
items2.close;
items2.open;



end;

procedure Tf_merge.RzBitBtn2Click(Sender: TObject);
var i:integer;
begin
if items.IsEmpty then exit;

items.First;
for i:=1 to items.RecordCount do
begin
items.edit;

itemsCONTACT.AsCurrency:=CURRFAC2CONTACT.AsCurrency ;
itemssid.AsString:=CURRFAC2sid.AsString;


//itemsAsDateTime:=CURRFAC2CREATETIME.AsDateTime;
itemsCURRFAC.AsInteger:=currfac2id.AsInteger;
items.post;
items.next;
end;
items.close;
items.open;
items2.close;
items2.open;


end;

procedure Tf_merge.RzBitBtn3Click(Sender: TObject);
begin

if items2.IsEmpty then exit;
items2.edit;

items2CONTACT.AsCurrency:=CURRFACCONTACT.AsCurrency ;
items2sid.AsString:=CURRFACsid.AsString;



items2CURRFAC.AsInteger:=currfacid.AsInteger;
items2.post;
items.close;
items.open;
items2.close;
items2.open;
end;

procedure Tf_merge.RzBitBtn4Click(Sender: TObject);

var i:integer;
begin

if items2.IsEmpty then exit;
items2.First;
for i:=1 to items2.RecordCount do
begin
items2.edit;

items2CONTACT.AsCurrency:=CURRFACCONTACT.AsCurrency ;
items2sid.AsString:=CURRFACsid.AsString;



items2CURRFAC.AsInteger:=currfacid.AsInteger;
items2.post;
items2.next;
end;
items.close;
items.open;
items2.close;
items2.open;

end;

procedure Tf_merge.DBText1Click(Sender: TObject);
var s:string;
begin
items.close;
 currfac.close;
 currfac.open;
 items.open;
    //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;

CURRFAC.Locate('tableno',s,[]);


end;

procedure Tf_merge.DBText2Click(Sender: TObject);
var s:string;
begin
items2.close;
 currfac2.close;
 currfac2.open;
 items2.open;
    //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;

if CURRFAC2.Locate('tableno',s,[])=false then
begin
if messagedlg('This Table not exist!! do you want to open a new Table',mtwarning,mbokcancel,0)<>mrok then exit;
posmodule.CURrFAC.open;
posmodule.CURRFAC.insert;
posmodule.CURRFACCREATETIME.AsDateTime:=time;
posmodule.CURRFACTABLENO.AsString:=s;
posmodule.CURRFACIACTIVE.AsString:='True';





posmodule.CURrFAC.POST;
posmodule.CURrFAC.close;
CURRFAC2.close;
CURRFAC2.open;
CURRFAC2.Locate('tableno',s,[])


end;



end;

procedure Tf_merge.fcImageBtn1Click(Sender: TObject);
var cc,i:integer;c1,cvat,CDISC,cpro:currency;mycomp:string[20];
   s:string;
begin

cvat:=0;
cc:=0;
c1:=0;
cpro:=0;
CDISC:=0;

try
items.First;

for i:=1 to items.RecordCount do
begin

c1:=c1+itemstotal.AsCurrency;
cc:=cc+1;

cvat:=cvat+itemsvatamount.ascurrency;


items.Next;
end;
CURRFAC.edit;
CURRFACvat.AsCurrency:=cvat;

if (POSmodule.CONFIGSVATTYPE.AsString = 'TTC' )  then
CURRFACSUBTOTAL.AsCurrency:=c1-cvat
else
CURRFACSUBTOTAL.AsCurrency:=c1;

CURRFACtotal.AsCurrency:=CURRFACSUBTOTAL.AsCurrency+
CURRFACvat.AsCurrency-CURRFACdiscount.AsCurrency ;


CURRFAC.post;

  except
  end;



cvat:=0;
cc:=0;
c1:=0;
cpro:=0;
CDISC:=0;

try
items2.First;

for i:=1 to items2.RecordCount do
begin

c1:=c1+items2total.AsCurrency;
cc:=cc+1;

cvat:=cvat+items2vatamount.ascurrency;


items2.Next;
end;
CURRFAC2.edit;
CURRFAC2vat.AsCurrency:=cvat;

if (POSmodule.CONFIGSVATTYPE.AsString = 'TTC' )  then
CURRFAC2SUBTOTAL.AsCurrency:=c1-cvat
else
CURRFAC2SUBTOTAL.AsCurrency:=c1;

CURRFAC2total.AsCurrency:=CURRFAC2SUBTOTAL.AsCurrency+
CURRFAC2vat.AsCurrency-CURRFAC2discount.AsCurrency ;


CURRFAC2.post;

  except
  end;














end;

procedure Tf_merge.RzBitBtn5Click(Sender: TObject);
begin
try

if FileExists(extractfilepath(application.exename)+ 'merge.fr3') then
begin
repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+ 'merge.fr3') ;
repmodule.frxReport1.ShowReport  ;
end
else
begin
f_msgdlg:=tf_msgdlg.create(self);
try
f_msgdlg.mymsg.Caption:='File No Exist : merge.fr3!!!';
f_msgdlg.ShowModal;
except
end;
f_msgdlg.Release;

//Showmessage('File No Exist : merge.fr3');
end;

except
end;
end;

end.
