unit p_cashinv;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ExtCtrls, RzPanel, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, cxStyles, cxVGrid, cxDBVGrid,
  cxInplaceContainer, BULabel, BUBlinkingLabel, OoMisc, AdPort, wwdbedit,
  Mask, ToolEdit, CurrEdit, DBCtrls, Buttons, Menus, SUIDlg, Db, DBTables,
  DBSearch, RzButton,frxBDEComponents, RzEdit, RzDBEdit, IvDictio, IvAMulti, IvBinDic,
  IvMulti, dxGDIPlusClasses, Abcwav, cxContainer, cxEdit, cxImage, cxDBEdit,
  RzLabel, RzDBLbl, RzStatus;

type
  Tf_cashinv = class(TForm)
    cxGrid1: TcxGrid;
    cxGrid1DBTableView1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    RzPanel1: TRzPanel;
    RzPanel4: TRzPanel;
    e_bar: TEdit;
    RzPanel2: TRzPanel;
    cxGrid1DBTableView1QTY: TcxGridDBColumn;
    cxGrid1DBTableView1PACK: TcxGridDBColumn;
    cxGrid1DBTableView1PRICE: TcxGridDBColumn;
    cxGrid1DBTableView1DISCOUNT: TcxGridDBColumn;
    cxGrid1DBTableView1TOTAL: TcxGridDBColumn;
    cxGrid1DBTableView1Column1: TcxGridDBColumn;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle3: TcxStyle;
    cxStyle4: TcxStyle;
    Label2: TLabel;
    insp2: TcxDBVerticalGrid;
    cxDBEditorRow32: TcxDBEditorRow;
    cxDBEditorRow35: TcxDBEditorRow;
    cxDBVerticalGrid1: TcxDBVerticalGrid;
    cxDBVerticalGrid1DBEditorRow2: TcxDBEditorRow;
    cxDBVerticalGrid1DBEditorRow3: TcxDBEditorRow;
    ccc: TApdComPort;
    cxGrid1DBTableView1Column2: TcxGridDBColumn;
    bok: TBitBtn;
    DBText1: TDBText;
    DBText2: TDBText;
    payll: TRxCalcEdit;
    resultll: TwwDBEdit;
    totalll: TwwDBEdit;
    daribe: TwwDBEdit;
    PopupMenu1: TPopupMenu;
    N2: TMenuItem;
    N1: TMenuItem;
    ghzpmhghwkht1: TMenuItem;
    N5: TMenuItem;
    mypass: TsuiInputDialog;
    touser: TTable;
    fff: TRaDBSearch;
    RzBitBtn1: TRzBitBtn;
    AttachContact1: TMenuItem;
    DiscountCard1: TMenuItem;
    CashManager1: TMenuItem;
    RzPanel3: TRzPanel;
    plabel: TBUBlinkingLabel;
    cxDBVerticalGrid3: TcxDBVerticalGrid;
    cxDBEditorRow2: TcxDBEditorRow;
    cxDBEditorRow3: TcxDBEditorRow;
    RzBitBtn5: TRzBitBtn;
    cxDBVerticalGrid3DBEditorRow1: TcxDBEditorRow;
    creditacc: TQuery;
    dcreditacc: TDataSource;
    creditaccSID: TStringField;
    creditaccSNAME: TStringField;
    creditaccCREDITLIMIT: TFloatField;
    DBText3: TDBText;
    IvTranslator1: TIvTranslator;
    RzBitBtn2: TRzBitBtn;
    DeleteALL1: TMenuItem;
    cxStyle5: TcxStyle;
    Panel2: TPanel;
    RzBitBtn6: TRzBitBtn;
    RzBitBtn7: TRzBitBtn;
    RzBitBtn8: TRzBitBtn;
    RzBitBtn9: TRzBitBtn;
    RzBitBtn10: TRzBitBtn;
    RzBitBtn11: TRzBitBtn;
    RzBitBtn12: TRzBitBtn;
    RzBitBtn13: TRzBitBtn;
    RzBitBtn14: TRzBitBtn;
    RzBitBtn15: TRzBitBtn;
    RzBitBtn16: TRzBitBtn;
    RzBitBtn17: TRzBitBtn;
    RzBitBtn18: TRzBitBtn;
    RzBitBtn19: TRzBitBtn;
    Image1: TImage;
    RzBitBtn20: TRzBitBtn;
    ItemInfo1: TMenuItem;
    Edit1: TEdit;
    DiscountToALl1: TMenuItem;
    lqty: TBUBlinkingLabel;
    RzBitBtn21: TRzBitBtn;
    Invoice1: TMenuItem;
    cxStyle6: TcxStyle;
    www: TabcWaveList;
    RzBitBtn22: TRzBitBtn;
    RzPanel5: TRzPanel;
    im1: TcxDBImage;
    RzBitBtn4: TRzBitBtn;
    RzBitBtn3: TRzBitBtn;
    PrintOnoff1: TMenuItem;
    Label1: TLabel;
    DBText4: TDBText;
    RzDBLabel1: TRzDBLabel;
    RzDBLabel2: TRzDBLabel;
    cbsp: TCheckBox;
    SPINvoice1: TMenuItem;
    RzBitBtn23: TRzBitBtn;
    RzBitBtn24: TRzBitBtn;
    RzBitBtn25: TRzBitBtn;
    RzBitBtn26: TRzBitBtn;
    RzBitBtn27: TRzBitBtn;
    RzBitBtn28: TRzBitBtn;
    Label3: TLabel;
    Label4: TLabel;
    RzStatusBar1: TRzStatusBar;
    RzMarqueeStatus1: TRzMarqueeStatus;
    procedure e_barKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure bokClick(Sender: TObject);

    procedure FormShow(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure payllChange(Sender: TObject);
    procedure payllKeyPress(Sender: TObject; var Key: Char);
    procedure N2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure e_barExit(Sender: TObject);
    procedure N5Click(Sender: TObject);
    procedure ghzpmhghwkht1Click(Sender: TObject);
    procedure cxGrid1Enter(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
    procedure RzBitBtn3Click(Sender: TObject);
    procedure RzBitBtn4Click(Sender: TObject);
    procedure RzBitBtn5Click(Sender: TObject);
    procedure DBText3Click(Sender: TObject);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure DeleteALL1Click(Sender: TObject);
    procedure cxGrid1DBTableView1DblClick(Sender: TObject);
    procedure RzBitBtn16Click(Sender: TObject);
    procedure RzBitBtn17Click(Sender: TObject);
    procedure RzBitBtn18Click(Sender: TObject);
    procedure ItemInfo1Click(Sender: TObject);
    procedure payllExit(Sender: TObject);
    procedure DiscountToALl1Click(Sender: TObject);
    procedure Invoice1Click(Sender: TObject);
    procedure RzBitBtn21Click(Sender: TObject);
    procedure e_barEnter(Sender: TObject);
    procedure RzBitBtn22Click(Sender: TObject);
    procedure PrintOnoff1Click(Sender: TObject);
    procedure SPINvoice1Click(Sender: TObject);
    procedure RzBitBtn23Click(Sender: TObject);
    procedure RzBitBtn24Click(Sender: TObject);
    procedure RzBitBtn25Click(Sender: TObject);
    procedure RzBitBtn26Click(Sender: TObject);
    procedure RzBitBtn27Click(Sender: TObject);
    procedure RzBitBtn28Click(Sender: TObject);
    procedure payllEnter(Sender: TObject);
    procedure im1Click(Sender: TObject);
    procedure AttachContact1Click(Sender: TObject);
    procedure cxGrid1DBTableView1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure RzBitBtn6Click(Sender: TObject);
    procedure cbspClick(Sender: TObject);
    procedure cxDBVerticalGrid3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_cashinv: Tf_cashinv; qty:currency;bb:boolean;c:currency;LAST:STRING;
  myff:integer;PP :INTEGER; iiii:integer;

implementation

uses p_posmodule, p_repmodule, p_barcode, p_touchcash, p_cbarcode,
  p_stocklist, p_companye, p_cashinv2, P_SELprice, p_selbar, p_searsh,
  p_control, p_helpdesk, p_zoom, p_telep, p_stocklist2, p_msgdlg;

{$R *.DFM}

procedure Tf_cashinv.e_barKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var s,S2,prices:string;b,b_enter,b_tab:boolean;r,price:currency;
    i,j:integer;bep:integer;mycomp:string[20];notint:integer;myb:boolean;
    cp,cpr:real;



begin

s:=e_bar.text;
if posmodule.CONFIGSMINUSQTY.AsString='YES' then
begin
if length(s)>1 then
begin
if s[1]='-' then
begin
mypass.PasswordChar:='*';
mypass.ValueText:='';
mypass.PromptText:='Enter Password:';
mypass.ShowModal;
touser.open;

if touser.Locate('pass',mypass.ValueText,[]) then
begin
if touser.FieldByName('NADJUST').AsString<>'True' then
begin
E_BAR.Text:='';
 e_bar.SetFocus;
exit;
end;

end
else
begin
E_BAR.Text:='';
 e_bar.SetFocus;
exit;
end;
end;
end;

end;
    myb:=false;

if  (key=13)  then
begin


  myff:=0;

posMODULe.stock.cLOSE;
b:=false;



IF TRIM(S)='' THEN
BEGIN
myff:=1;
PAYLL.SetFocus;

EXIT;

END;

try

if ((s[1]='2') and (s[2]='7') and (s[3]='0')) or
    ((s[1]='2') and (s[2]='6')  ) then
begin
prices:='';
try
for i:=posmodule.CONFIGSMIZANENO.AsInteger+1 to length(s) do
prices:=prices+s[i];

IF posmodule.CONFIGSMIZANEDIGIT.AsString='YES' THEN
begin
prices:='';
for i:=posmodule.CONFIGSMIZANENO.AsInteger+1 to length(s)-1 do
prices:=prices+s[i];
end;
if (posmodule.CONFIGSFRACTIONPRICE.AsString='YES') THEN
price:=strtofloat(prices)/100
ELSE
price:=strtofloat(prices);



s2:='';
for j:=1 to posmodule.CONFIGSMIZANENO.AsInteger do
S2:=s2+s[j];
b:=true;
except
exit;
end;
S:=S2;

end;





posmodule.qextcomp.close;
posmodule.qextcomp.ParamByName('mycode').AsString:=s;
posmodule.qextcomp.open;
if posmodule.qextcomp.IsEmpty=false then
begin
if posmodule.QEXTCOMPMYTYPE.AsString='ITEM' then
begin
// mypass.PasswordChar:=#0 ;
//mypass.PromptText:='Enter The Amount:';
//mypass.ValueText:='';
//mypass.ShowModal;
f_mycompany.ShowModal   ;

 PRICE:=f_mycompany.RzNumericEdit1.Value;
 //price:=strtofloat(prices);
end;

 posmodule.items.append;
posmodule.itemsmid.AsString:=posmodule.invoiceid.AsString;
posmodule.itemssite.AsString:=posmodule.invoicesite.AsString;
posmodule.itemsfdate.AsString:=posmodule.invoicefdate.AsString;

posmodule.itemssid.AsString:=posmodule.invoicesid.AsString;
posmodule.itemscontact.AsString:=posmodule.invoicecontact.AsString;
posmodule.itemssalesman.AsString:=posmodule.invoicesalesman.AsString;

posmodule.itemsvat.AsCurrency:=0;
posmodule.itemsCONTACT.AsCurrency:=posmodule.CURRFACCONTACT.AsCurrency ;
posmodule.itemssid.AsString:=posmodule.CURRFACsid.AsString;

posmodule.itemsdescr.AsString:=posmodule.qextcompCOMPANY.AsString;
posmodule.itemsstqty.AsCurrency:=0;

posmodule.itemsitem.AsString:=S;
posmodule.itemsPACK.AsCurrency:=1;
posmodule.itemsEXTYESNO.AsInteger:=1;

//posmodule.itemssttype.AsString:=posmodule.detstocksttype.AsString;

posmodule.itemsbarcode.AsString:=s;
posmodule.itemsqty.AsCurrency:=1;
posmodule.itemsPRICE.AsCurrency:=price;
posmodule.items.Post;

E_BAR.Text:='';
e_barExit(e_bar);
E_BAR.SetFocus;
e_barEnter(e_bar);

exit;
end;


except
EXIT;
end;









{try
r:=strtofloat(s);
try
notint:=0;
j:=strtoint(s);

except
  notint:=1;
end;
except
notint:=0;
end;
}
{
notint:=0;
if ((s[1]='-') or (notint=1) ) then
begin
mypass.PasswordChar:='*';
mypass.ValueText:='';
mypass.PromptText:='Enter Password:';
mypass.ShowModal;
touser.open;

if touser.Locate('pass',mypass.ValueText,[]) then
begin
if touser.FieldByName('udelete').AsString<>'True' then
begin

exit;
end;

end
else
begin

exit;
end;
end;

}
posmodule.barcodes.close;
posmodule.barcodes.ParamByName('myitem').AsString:=s;
posmodule.barcodes.open;
if  posmodule.barcodes.IsEmpty=false then
begin
 s:=posmodule.barcodes.fieldbyname('item').AsString;
   try
  cp:=posmodule.barcodes.fieldbyname('pack').AsCurrency;
  if cbsp.Checked then
  cpr:=posmodule.barcodes.fieldbyname('price2').AsCurrency
  else
  cpr:=posmodule.barcodes.fieldbyname('price'+posmodule.CONFIGSPRICE.AsString).AsCurrency;
 except
   cpr:=posmodule.barcodes.fieldbyname('price1').AsCurrency ;
 end;

 myb:=true;

end;


posMODULe.stock.ParamByName('MYITEM').ASSTRING:=s;

posMODULe.stock.OPEN;
if posmodulE.stoCK.IsEmpty=FALSE then
begin
 plabel.Caption:='Item Exist  :';
 plabel.color:=clgreen;
 plabel.Blinking:=False;

if 1=1 then
begin
// if posmodule.items.Locate('item',posmodulE.stoCKITEM.AsString,[]) then
 if s='-' then
begin
label2.Caption:=floattostr(strtofloat(label2.Caption)-posmodule.ITEMStotal.AsInteger);
posmodule.items.edit;
posmodule.itemsqty.AsCurrency:=posmodule.itemsqty.AsCurrency+1;
label2.Caption:=floattostr(strtofloat(label2.Caption)+posmodule.ITEMStotal.AsInteger);
end
else
begin


posmodule.items.append;
posmodule.itemsmid.AsString:=posmodule.invoiceid.AsString;
posmodule.itemssite.AsString:=posmodule.invoicesite.AsString;
posmodule.itemsfdate.AsString:=posmodule.invoicefdate.AsString;

posmodule.itemssid.AsString:=posmodule.invoicesid.AsString;
posmodule.itemscontact.AsString:=posmodule.invoicecontact.AsString;
posmodule.itemssalesman.AsString:=posmodule.invoicesalesman.AsString;
if posmodule.CURRFACSDISC.AsCurrency<>0 then
posmodule.itemsDISCOUNT.AsCurrency:=posmodule.CURRFACSDISC.AsCurrency
else
begin
if posmodule.CONFIGSDISCOUNTTYPE.AsInteger=2 then
posmodule.itemsdiscount.AsCurrency :=posmodule.stockdisc2.AsCurrency
else
posmodule.itemsdiscount.AsCurrency :=posmodule.stockSALESDISC.AsCurrency;
end;
{
If (posmodule.stockQTY.AsCurrency=0) and
    (posmodule.CONFIGSCHECKQTY.AsString='YES') then
    begin

 posmodule.items.cancel;
  e_bar.Text:='';
  e_bar.SetFocus;
 exit;
end;
 }
If (posmodule.stockPOSPRICE1.AsCurrency=0) and
    (posmodule.CONFIGSCHECKQTY.AsString<>'YES') then
    begin

f_msgdlg:=tf_msgdlg.create(self);
try
f_msgdlg.mymsg.Caption:='Preco is 0 On Stock!!!';
f_msgdlg.ShowModal;
except
end;
f_msgdlg.Release;

 posmodule.items.cancel;
  e_bar.Text:='';
  e_bar.SetFocus;
 exit;
end;


posmodule.itemsvat.AsCurrency:=posmodule.stockvat.AsCurrency;
posmodule.itemsCONTACT.AsCurrency:=posmodule.CURRFACCONTACT.AsCurrency ;
posmodule.itemssid.AsString:=posmodule.CURRFACsid.AsString;
 posmodule.itemsMYPRN.AsString:=posmodule.stockMYPRN.AsString;
posmodule.itemsdescr.AsString:=posmodule.stockdescr1.AsString;
posmodule.itemsstqty.AsCurrency:=posmodule.stockQTY.AsCurrency;

posmodule.itemsitem.AsString:=posmodule.stockitem.AsString;
posmodule.itemsPACK.AsCurrency:=1;

posmodule.itemscostus.AsCurrency:=posmodule.stockcostus.AsCurrency;
posmodule.itemscostlc.AsCurrency:=posmodule.stockcostlc.AsCurrency;
//posmodule.itemssttype.AsString:=posmodule.detstocksttype.AsString;
posmodule.itemsyesno.AsString:=posmodule.stockyesno.AsString;
posmodule.itemsbarcode.AsString:=s;
posmodule.itemsqty.AsCurrency:=1;
 if posmodule.CONFIGSPRICE.AsInteger=2 then
posmodule.itemsprice.AsCurrency:=posmodule.stockPRICEc.AsCurrency
else
 if posmodule.CONFIGSPRICE.AsInteger=3 then
posmodule.itemsprice.AsCurrency:=posmodule.stockPRICEe.AsCurrency
else

posmodule.itemsprice.AsCurrency:=posmodule.stockPOSPRICE1.AsCurrency;



 if s=posmodule.stockbarcode1.AsString then
begin
posmodule.itemsqty.AsCurrency:=1;
posmodule.itemspack.AsCurrency:=posmodule.stockpack1.AsCurrency;
posmodule.itemsprice.AsCurrency:=posmodule.stockprice1.AsCurrency;
end
else
if s=posmodule.stockbarcode2.AsString then
begin
posmodule.itemsqty.AsCurrency:=1;
posmodule.itemspack.AsCurrency:=posmodule.stockpack2.AsCurrency;
posmodule.itemsprice.AsCurrency:=posmodule.stockprice2.AsCurrency;
end
else
if s=posmodule.stockbarcode3.AsString then
begin
posmodule.itemsqty.AsCurrency:=1;
posmodule.itemspack.AsCurrency:=posmodule.stockpack3.AsCurrency;
posmodule.itemsprice.AsCurrency:=posmodule.stockprice3.AsCurrency;
end
else
if s=posmodule.stockbarcode4.AsString then
begin
posmodule.itemsqty.AsCurrency:=1;
posmodule.itemspack.AsCurrency:=posmodule.stockpack4.AsCurrency;
posmodule.itemsprice.AsCurrency:=posmodule.stockprice4.AsCurrency;
end;
if cbsp.Checked then
begin
if (posmodule.itemspack.AsCurrency=1) then
BEGIN
if (posmodulE.stoCKpricee.AsCurrency<>0 ) then
posmodule.itemsprice.AsCurrency:=posmodule.stockPRICEE.AsCurrency
END
else
begin
if (posmodulE.stoCKpricef.AsCurrency<>0 ) then
posmodule.itemsprice.AsCurrency:=posmodule.stockPRICEf.AsCurrency;
end;

end;




if myb then
begin
posmodule.itemsqty.AsCurrency:=1;
posmodule.itemspack.AsCurrency:=cp;
posmodule.itemsprice.AsCurrency:=CPR;
if posmodule.itemsprice.AsCurrency=0 then
begin

posmodule.itemsprice.AsCurrency:=posmodule.stockposprice1.AsCurrency*cp;
end;

end;

  posmodule.itemsMYPRN.AsString:=posmodule.stockMYPRN.AsString;


        if b then
        begin
        posmodule.itemsqty.AsCurrency:=price/
        posmodule.itemsprice.AsCurrency
        end;




        if qty<>0 then
        begin
                 if qty>999 then qty:=1;
                posmodule.itemsqty.AsCurrency:=qty*posmodule.itemsqty.AsCurrency;

                qty:=0;
        end;
        if posmodule.CONFIGSVATTYPE.AsString='NOTTC' then
        label2.Caption:=floattostr(strtofloat(label2.Caption)+posmodule.ITEMStotal.AsInteger+posmodule.ITEMSvatamount.AsInteger)
        else
        label2.Caption:=floattostr(strtofloat(label2.Caption)+posmodule.ITEMStotal.AsInteger);
         try
           label4.Caption:=FormatFloat('$0.00',(strtofloat(label2.Caption))/posmodule.invoiceCURRVALLC.AsCurrency);
           except
           end;

        end;
end;
        if  creditacc.active then
        if  strtofloat(label2.caption)>creditaccCREDITLIMIT.AsCurrency then
        begin
        f_msgdlg:=tf_msgdlg.create(self);
try
f_msgdlg.mymsg.Caption:='The Credit Limit Are Low !!!';
f_msgdlg.ShowModal;
except
end;
f_msgdlg.Release;




        posmodule.items.delete;
         E_BAR.Text:='';
         try
e_barExit(e_bar);
except
end;

        end;

         try
         mycomp:=posmodule.tocomp.fieldbyname('NAME1').AsString;
         mycomp:=mycomp+'....................';
         if posmodule.CONFIGSMYCOM.AsInteger<>0 then
         begin
         ccc.PutString(#$1b#$40);

  ccc.PutString(mycomp+'Your amount = '+label2.Caption);
       end;
        except
        end;

        if posmodule.itemsprice.AsFloat=0 then
        begin
               // imz.Visible:=true;
              // try
              //  MessageBeep($0FFFFFFFF);

              //  for bep:=1 to 20 do
              //  Beep();
               //  except
               //  end;

               plabel.Caption:='Price Is Zero  :';
               plabel.color:=clred;
               plabel.Blinking:=true;
               www.PlayItem(1);


        end;


end
else
begin

if (length(s)<=5) then
BEGIN
TRY
qty:=strtofloat(s)
EXCEPT
END;
END
else
begin

qty:=0;
 plabel.Caption:='Item Not Exist !!!!!  :';
 plabel.color:=clred;
 plabel.Blinking:=true;
 www.PlayItem(0);


end;
end  ;

if (qty<>0) then
begin
lqty.Visible:=true;
lqty.color:=clred;
LQTY.Caption:=FLOATTOSTR(QTY);
 lqty.Blinking:=true;
 end
 else
 BEGIN
lqty.Visible:=false;
LQTY.Caption:=' ';
 lqty.Blinking:=FALSE;
 lqty.color:=clSILVER;

 END;
if (trim(e_bar.text)<>'') then
begin
E_BAR.Text:='';
 e_bar.SetFocus;
end;
E_BAR.Text:='';

POSMODULE.qitinfo.CLOSE;
POSMODULE.qitinfo.OPEN;
{
IF POSMODULE.qitinfo.FieldByName('picture').IsNull=false then
begin
f_zoom:=tf_zoom.create(self);
try

f_zoom.ShowModal;
except
end;
f_zoom.release;
end;

}


end;



END;



procedure Tf_cashinv.bokClick(Sender: TObject);

  var   i:integer;s1,s2,s3,ss4:string;ss:string[21];ss1:string[3];
       f:textfile;
       s:string;
begin
    s:=posmodule.CURRFACsid.AsString;
posmodule.CURRFAC.edit;
try
posmodule.CURRFACVAT.AsCurrency:=strtofloat(daribe.Text);
 except

 end;
try
 if  strtofloat(payll.Text)<>0 then
 begin
 try
posmodule.CURRFACcashin.AsCurrency:=strtofloat(payll.Text);
 except

 end;

try
posmodule.CURRFACcashout.AsCurrency:=strtofloat(resultll.Text);
 except

 end;

end
else
begin
 try
posmodule.CURRFACcashin.AsCurrency:=strtofloat(totalll.text);


 except

 end;

try
posmodule.CURRFACcashout.AsCurrency:=0;
 except

 end;


end;
except

end;
 posmodule.CURRFACtotal.AsCurrency:=strtofloat(totalll.text);
 resultll.Text:= totalll.text;


try
if (posmodule.CURRFACCONTACT.AsInteger<>0)
    AND (posmodule.CURRFACTOTAL.AsCurrency<>0) then
begin

posmodule.contdet.ParamByName('mymid').AsInteger:=posmodule.CURRFACCONTACT.AsInteger;
posmodule.contdet.ParamByName('mycurrfac').AsInteger:=posmodule.CURRFACID.AsInteger;
if posmodule.CONFIGSPOINTAMOUNT.AsCurrency<>0 then
posmodule.contdet.ParamByName('mypointin').AsCurrency:=trunc(posmodule.CURRFACTOTAL.AsCurrency/posmodule.CONFIGSPOINTAMOUNT.AsCurrency)
else
posmodule.contdet.ParamByName('mypointin').AsCurrency:=0;
posmodule.contdet.ParamByName('mypointout').AsCurrency:=0;
posmodule.contdet.ParamByName('mytotal').AsCurrency:=posmodule.CURRFACTOTAL.AsCurrency;
posmodule.contdet.ParamByName('mydate').AsDate:=date;
posmodule.contdet.ParamByName('mytime').AsDateTime:=time;
posmodule.contdet.ExecSQL;
end;

except
end;




 //module.CURRFAC.post;
try

if posmodule.items.IsEmpty=FALSE then
begin
{
try

assignfile(f,'prn');
rewrite(f);
 writeln(f,#$1B+#$70+#$00);
writeln(f,#$07+#$50+#$00);


//p_modul.oc:=p_modul.oc+1;
except
end;
try
closefile(f);
except
end;

}
repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+'posinv.fr3') ;
if trim(posmodule.CONFIGSPINVOICE.AsString)<>'' then
repmodule.frxReport1.PrintOptions.Printer:=posmodule.CONFIGSPINVOICE.AsString;
//if s[1]='4' then
//repmodule.frxReport1.PrintOptions.Copies:=2;
repmodule.frxReport1.PrepareReport;
repmodule.frxReport1.PrintOptions.ShowDialog:=false;

if (posmodule.CONFIGSMYPRN.AsString<>'OFF') AND (PP=0) then
repmodule.frxReport1.print;
PP:=1;

{
try
if posmodule.CONFIGSMYPRN.AsString<>'OFF' then
BEGIN
s:=repmodule.frxReport1.PrintOptions.Printer;



repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+'touchorder.fr3') ;
repmodule.frxReport1.PrintOptions.ShowDialog:=false;

repmodule.frxReport1.ShowProgress:=false;

(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).filter:='myprn=''KITCHEN''';
repmodule.frxReport1.PrintOptions.Printer:=posmodule.CONFIGSKITCHEN.AsString;


repmodule.frxReport1.PrepareReport;
(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.OPEN;
IF (repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.IsEmpty=FALSE THEN

repmodule.frxReport1.print;

(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).filter:='myprn=''BAR''';
repmodule.frxReport1.PrintOptions.Printer:=posmodule.CONFIGSBAR.AsString;

repmodule.frxReport1.PrepareReport;
(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.OPEN;
IF (repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.IsEmpty=FALSE THEN
repmodule.frxReport1.print;


(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).filter:='myprn=''COCKTAIL''';
repmodule.frxReport1.PrintOptions.Printer:=posmodule.CONFIGSCOCKTAIL.AsString;
repmodule.frxReport1.PrepareReport;
(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.OPEN;
IF (repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.IsEmpty=FALSE THEN
repmodule.frxReport1.print;

(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).filter:='myprn=''FAST FOOD''';
repmodule.frxReport1.PrintOptions.Printer:=posmodule.CONFIGSFASTFOOD.AsString;
repmodule.frxReport1.PrepareReport;
(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.OPEN;
IF (repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.IsEmpty=FALSE THEN
repmodule.frxReport1.print;

(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).filter:='myprn=''OVEN''';
repmodule.frxReport1.PrintOptions.Printer:=posmodule.CONFIGSOVEN.AsString;
repmodule.frxReport1.PrepareReport;
(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.OPEN;
IF (repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.IsEmpty=FALSE THEN
repmodule.frxReport1.print;

(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).filter:='myprn=''BOUCHERY''';
repmodule.frxReport1.PrintOptions.Printer:=posmodule.CONFIGSBOUCHERY.AsString;
repmodule.frxReport1.PrepareReport;
(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.OPEN;
IF (repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.IsEmpty=FALSE THEN
repmodule.frxReport1.print;

(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).filter:='myprn=''SNACK''';
repmodule.frxReport1.PrintOptions.Printer:=posmodule.CONFIGSSNACK.AsString;
repmodule.frxReport1.PrepareReport;
(repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.OPEN;
IF (repmodule.frxReport1.GetDataset('BDEtable1') as tfrxbdeQUERY ).Query.IsEmpty=FALSE THEN
repmodule.frxReport1.print;

 repmodule.frxReport1.PrintOptions.Printer:=s;

END;
except
end;

 }

end;
except
end;

try
if creditacc.active then
begin

creditacc.edit;
creditaccCREDITLIMIT.AsCurrency:=creditaccCREDITLIMIT.AsCurrency-posmodule.CURRFACTOTAL.AsCurrency;
creditacc.ApplyUpdates;

creditacc.close;
end;
except
end;

  f_cashinv.ModalResult:=MROK;


end;

procedure Tf_cashinv.FormShow(Sender: TObject);
begin
myff:=0;
 plabel.Caption:='Ready ';
 plabel.color:=clgreen;
 plabel.Blinking:=False;
PP:=0;

c:=0;
qty:=0;


label2.Caption:='0';
E_BAR.Text:='';
totalll.Text:='0';
label2.Caption:='0';

E_BAR.SetFocus;

end;

procedure Tf_cashinv.FormCreate(Sender: TObject);
begin
try
ccc.ComNumber:=posmodule.CONFIGSMYCOM.AsInteger;
except
end;

bb:=true;
myff:=0;
end;

procedure Tf_cashinv.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
TRY
LAST:=posMODULE.CURRFACID.AsString;
EXCEPT
END;
end;

procedure Tf_cashinv.payllChange(Sender: TObject);
var c:currency;
begin
try
 c:=strtofloat(totalll.Text)-strtofloat(payll.Text);
 resultll.Text:=floattostr(c);
 edit1.Text:=formatfloat('#,0;-#,0',c);

except
end;

end;

procedure Tf_cashinv.payllKeyPress(Sender: TObject; var Key: Char);
VAR C1,C2:CURRENCY;

begin

if KEY<>#13 then exit;
payll.Enabled:=FALSE;

IF KEY=#13 THEN
BEGIN
TRY
IF (PAYLL.Text<>'0.00') then
BEGIN
C1:=STRTOFLOAT(TOTALLL.TEXT);
C2:=STRTOFLOAT(PAYLL.Text);
IF C2<C1 THEN
BEGIN
f_msgdlg:=tf_msgdlg.create(self);
try
f_msgdlg.mymsg.Caption:='Wrong Amount !!!';
f_msgdlg.ShowModal;
except
end;
f_msgdlg.Release;



payll.Enabled:=TRUE;
payll.SetFocus;
exit;
END;
END;

EXCEPT
END;
BOKClick(BOK);

END;

payll.Enabled:=TRUE;
end;

procedure Tf_cashinv.N2Click(Sender: TObject);
var f:textfile;
     i:integer;
begin

{try
assignfile(f,'prn');
rewrite(f);
writeln(f,#$1B+#$70+#$00);
writeln(f,#$07+#$50+#$00);

//p_modul.oc:=p_modul.oc+1;
except
end;
try
closefile(f);
except
end;
 }
 repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+'drawer.fr3') ;
 repmodule.frxReport1.PrepareReport;
repmodule.frxReport1.PrintOptions.ShowDialog:=false;
repmodule.frxReport1.ShowProgress:=false;
repmodule.frxReport1.print;


e_bar.SetFocus;



end;

procedure Tf_cashinv.N1Click(Sender: TObject);

var s:string;
begin

mypass.PasswordChar:='*';
mypass.ValueText:='';
mypass.PromptText:='Enter Password:';
mypass.ShowModal;
touser.open;

if touser.Locate('pass',mypass.ValueText,[]) then
begin
if touser.FieldByName('posdelete').AsString<>'True' then
begin

exit;
end;

end
else
begin

exit;
end;



tRY
//posMODULE.items.Last;
posMODULE.iTEMS.DELETE;
EXCEPT
END;

e_barExit(e_bar);

touser.close;
label2.Caption:=totalll.Text;
try
label4.Caption:=FormatFloat('$0.00',(strtofloat(label2.Caption))/posmodule.invoiceCURRVALLC.AsCurrency);
 except
 end;
try
posMODULE.items.Last;
except
end;
e_bar.SetFocus;

end;



procedure Tf_cashinv.e_barExit(Sender: TObject);
var i:integer;c,c1,tc:currency;
mycomp:string[20];
begin
try
c:=0;
c1:=0;
tc:=0;
posmodulE.items.First;
for i:=1 to posmodule.items.RecordCount do
begin

c:=c+posmodulE.itemstotal.AsCurrency;
IF posmodulE.itemsVAT.AsCurrency<>0 THEN
tc:=tc+posmodulE.itemsvatamount.AsCurrency;
posmodule.items.Next;
end;
if posmodule.CONFIGSVATTYPE.AsString='NOTTC' then
c:= c+tc;
totalll.Text:=floattostr(c);
daribe.Text:=floattostr(tc);
label2.Caption:=formatfloat('#,0;-#,0',c);
try
  label4.Caption:=FormatFloat('$0.00',(c)/posmodule.invoiceCURRVALLC.AsCurrency);
except
end;
  try
         mycomp:=posmodule.tocomp.fieldbyname('NAME1').AsString;
         mycomp:=mycomp+'....................';
         if posmodule.CONFIGSMYCOM.AsInteger<>0 then
         begin
         ccc.PutString(#$1b#$40);

  ccc.PutString(mycomp+'Your amount = '+label2.Caption);
       end;

        except
        end;
//totalus.Text:=floattostr((c)/1500);
//e_qty.Text:=floattostr(c1);
payll.Text:='0';
resultll.Text:='0';

except
E_BAR.SetFocus;
end;


end;

procedure Tf_cashinv.N5Click(Sender: TObject);
begin
if posmodule.CONFIGSEXTYESNO.AsString='YES' then
exit;

  if posmodule.stock.Active then posmodule.stock.close;
    if posmodule.locstock.Active then posmodule.locstock.close;
   if posmodule.tostock.Active then posmodule.tostock.close;

TRY
  posmodule.server.close;
  posmodule.server.Connected:=true;
  posmodule.bmstock.Execute;

 posmodule.stock.close;
posmodule.locstock.close;
posmodule.barcodes.close;
posmodule.tobar.close;

  try



  posmodule.tobar.close;
except
end;


 EXCEPT
 END;

posmodule.locstock.open;

e_bar.SetFocus;

 end;

procedure Tf_cashinv.ghzpmhghwkht1Click(Sender: TObject);


var key:word;s:string;
begin
e_bar.SetFocus;
if posMODULe.stock.Active then
posMODULe.stock.close;
s:=posMODULe.stock.sql.Strings[1];
posMODULe.stock.sql.Strings[1]:='';
//MODULe.stock.ParamByName('MYITEM').ASSTRING:='''''';
posMODULe.stock.open;

 //Application.CreateForm(Tf_stocklist,f_stocklist);
    if not assigned(f_stocklist) then
f_stocklist:=tf_stocklist.create(self);

p_stocklist.myenter:=1;
 try
if f_stocklist.showmodal=mrok then
BEGIN
e_bar.Text:=posMODULe.stockitem.AsString ;



posMODULe.stock.close;
posMODULe.stock.sql.Strings[1]:='where item='''+e_bar.Text+'''';
posMODULe.stock.open;
if posmodule.stockBARCODE1.AsString<>'' then
begin
 //Application.CreateForm(Tf_selbar,f_selbar);
   if not assigned(f_selbar) then
f_selbar:=tf_selbar.create(self);
f_selbar.DataSource1.DataSet:=posmodule.stock;
f_selbar.ShowModal  ;

if p_selbar.mysel=0 then
begin

e_bar.text:=posmodule.stockitem.AsString;


end
else
if p_selbar.mysel=1 then
begin
e_bar.text:=posmodule.stockBARCODE1.AsString;

end
else
if p_selbar.mysel=2 then
begin
e_bar.text:=posmodule.stockBARCODE2.AsString;

end
else
if p_selbar.mysel=3 then
begin
e_bar.text:=posmodule.stockBARCODE3.AsString;

end
else
if p_selbar.mysel=4 then
begin
e_bar.text:=posmodule.stockBARCODE4.AsString;
end;
if  assigned(f_selbar) then
 freeandnil(f_selbar);
end;

 posMODULe.stock.close;
posMODULe.stock.sql.Strings[1]:=s;
key:=13;

e_barKeyDown(e_bar,key,[ssShift]);

end;
except
end;
if  assigned(f_stocklist) then
freeandnil(f_stocklist);
 posMODULe.stock.close;
posMODULe.stock.sql.Strings[1]:=s;
e_bar.SetFocus;
end;

procedure Tf_cashinv.cxGrid1Enter(Sender: TObject);
begin
//e_bar.SetFocus;
end;

procedure Tf_cashinv.RzBitBtn1Click(Sender: TObject);
begin
 //Application.CreateForm(Tf_barcode,f_barcode);
     if not assigned(f_barcode) then
f_barcode:=tf_barcode.create(self);

try
if f_barcode.ShowModal=mrok then
begin
posmodule.CURRFAC.edit;
posmodule.CURRFACsid.AsString:=f_barcode.RzButtonEdit1.text;
posmodule.CURRFACSDISC.AsCurrency:=F_BARCODE.Query1.FIELDBYNAME('DISCOUNT').ASCURRENCY;
posmodule.CURRFACname.AsString:=F_BARCODE.Query1.FIELDBYNAME('sname').AsString;
posmodule.CURRFACTABLENO.AsString:=formatfloat('#,0;-#,0',F_BARCODE.Query1.FIELDBYNAME('sbalance').AsCurrency);
posmodule.CURRFAC.post;
if creditacc.active then
creditacc.close;

creditacc.ParamByName('mysid').asstring:=posmodule.CURRFACsid.AsString;
creditacc.open;

posmodule.items.first;
while not posmodule.items.Eof do
begin
posmodule.items.edit;
posmodule.itemssid.AsString:=f_barcode.RzButtonEdit1.text;
TRY
POSMODULE.itemsDISCOUNT.AsCurrency:=F_BARCODE.Query1.FIELDBYNAME('DISCOUNT').ASCURRENCY;
EXCEPT
END;

posmodule.items.post;
posmodule.items.next;
end;

end;

except
end;
f_barcode.query1.close;
if  assigned(f_barcode) then
 freeandnil(f_barcode);

 try
e_barExit(e_bar);
except
end;

e_bar.setfocus;
end;

procedure Tf_cashinv.RzBitBtn3Click(Sender: TObject);
begin




//1: b:=false;
 //Application.CreateForm(Tf_touchcash,f_touchcash);
if  assigned(f_touchcash) then
 freeandnil(f_touchcash);

f_touchcash:=tf_touchcash.create(self);
 try
//p_touchcash.myexit:=1;
//f_touchcash.btnclose1.Visible:=false;
//f_touchcash.RzBitBtn3.Visible:=false;
//f_touchcash.rzcedit.Visible:=false;
//f_touchcash.RzBitBtn6.Visible:=false;


if f_touchcash.ShowModal=mrok then
begin
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;





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

 try
e_barExit(e_bar);
except
end;

e_bar.setfocus;
end;

procedure Tf_cashinv.RzBitBtn4Click(Sender: TObject);

begin
if posmodule.items.IsEmpty=true then
exit;


if posmodule.touser.fieldbyname('posdiscount').AsBoolean=false then

exit;
mypass.PasswordChar:=#0 ;
mypass.PromptText:='Enter Discount Amount:';
mypass.ValueText:='';
try
if mypass.ShowModal=mrok then
begin
posmodule.items.locate('id',iiii,[]);
posmodule.items.edit;
if strtofloat(mypass.ValueText)<101 then
posmodule.itemsDISCOUNT.AsCurrency:=strtofloat(mypass.ValueText);
posmodule.items.post;
 try
e_barExit(e_bar);
except
end;
end;


except
end;
 e_bar.setfocus;

end;

procedure Tf_cashinv.RzBitBtn5Click(Sender: TObject);
begin
 //Application.CreateForm(Tf_barcode,f_barcode);
       if not assigned(f_barcode) then
f_barcode:=tf_barcode.create(self);

try
if f_barcode.ShowModal=mrok then
begin
posmodule.CURRFAC.edit;
posmodule.CURRFACSDISC.AsCurrency:=F_BARCODE.Query1.FIELDBYNAME('DISCOUNT').ASCURRENCY;
posmodule.CURRFACname.AsString:=F_BARCODE.Query1.FIELDBYNAME('sname').AsString;

posmodule.CURRFAC.post;

posmodule.items.first;
while not posmodule.items.Eof do
begin
posmodule.items.edit;

TRY
POSMODULE.itemsDISCOUNT.AsCurrency:=F_BARCODE.Query1.FIELDBYNAME('DISCOUNT').ASCURRENCY;
EXCEPT
END;
posmodule.items.post;
posmodule.items.next;
end;

end;

except
end;
f_barcode.query1.close;
if  assigned(f_barcode) then
 freeandnil(f_barcode);

 try
e_barExit(e_bar);
except
end;

e_bar.setfocus;
end;

procedure Tf_cashinv.DBText3Click(Sender: TObject);
begin
mypass.PromptText:='Enter Customer Name:';
mypass.ValueText:=posmodule.CURRFACNAME.AsString ;
if mypass.ShowModal=mrok then
begin
posmodule.CURRFAC.edit;
posmodule.CURRFACname.AsString:=mypass.ValueText;

end;
 e_bar.setfocus;
end;

procedure Tf_cashinv.RzBitBtn2Click(Sender: TObject);
begin
{mypass.PasswordChar:=#0 ;
mypass.PromptText:='Enter Contact Card:';
mypass.ValueText:='';
try
if mypass.ShowModal=mrok then
begin
 posmodule.CURRFAC.edit;
posmodule.CURRFACcontact.AsString:=mypass.ValueText;

posmodule.CURRFAC.post;

posmodule.items.first;
while not posmodule.items.Eof do
begin
posmodule.items.edit;

TRY
POSMODULE.itemscontact.AsString:=mypass.ValueText;
EXCEPT
END;
posmodule.items.post;
posmodule.items.next;
end;




end;
except
end;
e_bar.setfocus;
}
 //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.edit;

posmodule.CURRFACNAME.AsString:=f_telep.Query1name.AsString;
posmodule.CURRFACCONTACT.AsString:=f_telep.Query1id.AsString;



posmodule.CURrFAC.POST;

posmodule.tocontact.close;
posmodule.tocontact.open;

posmodule.items.first;
try
while not posmodule.items.Eof do
begin
posmodule.items.edit;


POSMODULE.itemscontact.AsString:=posmodule.CURRFACCONTACT.AsString;

posmodule.items.post;
posmodule.items.next;
end;

EXCEPT
END;



end;
except
end;
if  assigned(f_telep) then
freeandnil(f_telep);
 e_bar.setfocus;


end;

procedure Tf_cashinv.DeleteALL1Click(Sender: TObject);
var key:word;s:string;
begin
f_stocklist2:=tf_stocklist2.Create(self);
f_stocklist2.Query1.open;
try
if f_stocklist2.ShowModal=mrok then
begin
 key:=13;
e_bar.text:=f_stocklist2.Query1BARCODE.AsString;
e_barKeyDown(e_bar,key,[ssShift]);
end;
except
end;
f_stocklist2.Query1.close;
f_stocklist2.Release;

e_bar.SetFocus;
end;

procedure Tf_cashinv.cxGrid1DBTableView1DblClick(Sender: TObject);
begin
if posmodule.items.IsEmpty=true then
exit;

if posmodule.touser.fieldbyname('posprice').AsBoolean=false then

exit;
mypass.PasswordChar:=#0 ;
mypass.PromptText:='Enter The New Price:';
mypass.ValueText:=posmodule.itemsprice.AsString;
try
if mypass.ShowModal=mrok then
begin
if (strtofloat(mypass.ValueText)<>0)
 OR (posmodule.CONFIGSCHECKQTY.AsString='YES') then
begin

posmodule.items.edit;

posmodule.itemsprice.AsCurrency:=strtofloat(mypass.ValueText);
posmodule.items.post;
end
else
begin
f_msgdlg:=tf_msgdlg.create(self);
try
f_msgdlg.mymsg.Caption:='Price Zero Not allowed!!!';
f_msgdlg.ShowModal;
except
end;
f_msgdlg.Release;



end;

 try
e_barExit(e_bar);
except
end;
end;


except
end;
payllExit(payll);
//payll.SetFocus;
 e_bar.setfocus;


end;

procedure Tf_cashinv.RzBitBtn16Click(Sender: TObject);
begin
if myff<>1 then
begin
e_bar.Text:=trim(e_bar.Text)+(sender as tRzBitBtn).Caption;
e_bar.SetFocus;

end
else
begin

payll.Text:=trim(payll.Text)+(sender as tRzBitBtn).Caption;
end;
end;

procedure Tf_cashinv.RzBitBtn17Click(Sender: TObject);
begin
e_bar.Text:='';
e_bar.SetFocus;
end;

procedure Tf_cashinv.RzBitBtn18Click(Sender: TObject);
var key:word;
shift:tshiftstate;
begin
key:=13;
label2.Caption:=totalll.Text;
 if myff<>1 then
  e_barKeyDown(e_bar,key,shift)
  else
BOKClick(BOK);  



end;

procedure Tf_cashinv.ItemInfo1Click(Sender: TObject);
var s:string;
begin

if posMODULe.stock.Active then
posMODULe.stock.close;
s:=posMODULe.stock.sql.Strings[1];
posMODULe.stock.sql.Strings[1]:='';
//MODULe.stock.ParamByName('MYITEM').ASSTRING:='''''';
posMODULe.stock.open;
  //Application.CreateForm(Tf_stocklist,f_stocklist);
          if not assigned(f_stocklist) then
f_stocklist:=tf_stocklist.create(self);
 try
f_stocklist.showmodal;

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

posMODULe.stock.close;
posMODULe.stock.sql.Strings[1]:=s;

e_bar.SetFocus;
end;

procedure Tf_cashinv.payllExit(Sender: TObject);
begin
label2.Caption:=totalll.Text;

end;

procedure Tf_cashinv.DiscountToALl1Click(Sender: TObject);
begin
if posmodule.items.IsEmpty=true then
exit;

if posmodule.touser.fieldbyname('posdiscount').AsBoolean=false then

exit;
mypass.PasswordChar:=#0 ;
mypass.PromptText:='Enter Discount % Or Amount:';
mypass.ValueText:='';
try
if mypass.ShowModal=mrok then
begin
posmodule.items.First;
while not posmodule.items.Eof do
begin
posMODULe.stock.close;
posMODULe.stock.ParamByName('MYITEM').ASSTRING:=posmodule.itemsITEM.AsString;

posMODULe.stock.OPEN;
posmodule.items.edit;
if strtofloat(mypass.ValueText)<101 then
posmodule.itemsDISCOUNT.AsCurrency:=posMODULe.stockSALESDISC.AsCurrency+
strtofloat(mypass.ValueText)
else
posmodule.itemsDISCOUNT.AsCurrency:=posMODULe.stockSALESDISC.AsCurrency+strtofloat(mypass.ValueText)/strtofloat(label2.Caption) *100;
posmodule.items.post;
posmodule.items.Next;
end;


end;


except
end;



 try
e_barExit(e_bar);
label2.Caption:=totalll.Text;
except
end;



 e_bar.setfocus;

end;

procedure Tf_cashinv.Invoice1Click(Sender: TObject);
var b:boolean;i:integer;
begin
if posmodule.items.IsEmpty then exit;
i:=posmodule.CURRFACID.AsInteger;

p_posmodule.mycontact:=0;


posmodule.CURrFAC.Insert;
posmodule.CURRFACIACTIVE.AsString:='False';
posmodule.CURrFAC.POST;
//1: b:=false;
  //Application.CreateForm(Tf_cashinv2, f_cashinv2);
         if not assigned(f_cashinv2) then
f_cashinv2:= tf_cashinv2.create(self);
 f_cashinv2.Label2.Caption:='0';
 f_cashinv2.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



end;
//if b then goto 1;

if  assigned(f_cashinv2) then
 freeandnil(f_cashinv2);

posmodule.ITEMS.close;


posmodule.CURrFAC.close;

posmodule.CURrFAC.open;

posmodule.ITEMS.open;

posmodule.CURrFAC.locate('id',i,[]);

e_bar.SetFocus;
end;

procedure Tf_cashinv.RzBitBtn21Click(Sender: TObject);
begin

Invoice1Click(Invoice1);
end;

procedure Tf_cashinv.e_barEnter(Sender: TObject);
begin
label2.Caption:=totalll.Text;
end;

procedure Tf_cashinv.RzBitBtn22Click(Sender: TObject);
var i:integer;
begin

if posmodule.touser.fieldbyname('posprice').AsBoolean=false then

exit;
 // Application.CreateForm(Tf_selprice,f_selprice);
          if not assigned(f_selprice) then
f_selprice:=tf_selprice.Create(self);




try

if f_selprice.ShowModal=mrok then
begin

 posmodule.items.First;

for i:=1 to posmodule.items.RecordCount do
begin




posMODULe.stock.ParamByName('MYITEM').ASSTRING:=posmodule.itemsitem.AsString;

posMODULe.stock.OPEN;
if (posmodulE.stoCKpricee.AsCurrency<>0 ) or  (posmodulE.stoCKpricef.AsCurrency<>0 ) then
begin
posmodule.items.edit;
if (posmodule.itemspack.AsCurrency=1) then
BEGIN
if (posmodulE.stoCKpricee.AsCurrency<>0 ) then
posmodule.itemsprice.AsCurrency:=posmodule.stockPRICEE.AsCurrency
END
else
begin
if (posmodulE.stoCKpricef.AsCurrency<>0 ) then
posmodule.itemsprice.AsCurrency:=posmodule.stockPRICEf.AsCurrency;
end;
posmodule.items.post;

end;

posMODULe.stock.close;
posmodule.items.Next;
end;
end;
except
end;

posMODULe.stock.close;


if  assigned(f_selprice) then
 freeandnil(f_selprice);


e_barExit(e_bar);


label2.Caption:=totalll.Text;
e_bar.SetFocus;
end;




procedure Tf_cashinv.PrintOnoff1Click(Sender: TObject);
begin
posmodule.CONFIGS.edit;
if  posmodule.CONFIGSMYPRN.AsString='ON' then
posmodule.CONFIGSMYPRN.AsString:='OFF'
else
posmodule.CONFIGSMYPRN.AsString:='ON';
posmodule.CONFIGS.post;
posmodule.CONFIGS.ApplyUpdates;
posmodule.CONFIGS.close;
posmodule.CONFIGS.open;
end;

procedure Tf_cashinv.SPINvoice1Click(Sender: TObject);
begin
cbsp.Checked:=not cbsp.Checked;
end;

procedure Tf_cashinv.RzBitBtn23Click(Sender: TObject);
begin
try
repmodule.frxReport1.LoadFromFile(extractfilepath(application.exename)+ 'posinva4.fr3') ;
repmodule.frxReport1.ShowReport  ;
except
end;
e_bar.setfocus;
end;

procedure Tf_cashinv.RzBitBtn24Click(Sender: TObject);
begin
posmodule.CONFIGS.edit;
if  posmodule.CONFIGSMYPRN.AsString='ON' then
posmodule.CONFIGSMYPRN.AsString:='OFF'
else
posmodule.CONFIGSMYPRN.AsString:='ON';
posmodule.CONFIGS.post;
posmodule.CONFIGS.ApplyUpdates;
posmodule.CONFIGS.close;
posmodule.CONFIGS.open;
e_bar.setfocus;
end;

procedure Tf_cashinv.RzBitBtn25Click(Sender: TObject);
begin

       if not assigned(f_telep) then
f_telep:=tf_telep.create(self);
try

f_telep.RzBitBtn1Click(f_telep.RzBitBtn1)  ;
if f_telep.point.IsEmpty=false  then
begin





posmodule.CURRFAC.edit;

posmodule.CURRFACNAME.AsString:=f_telep.Query1name.AsString;
posmodule.CURRFACCONTACT.AsString:=f_telep.Query1id.AsString;



posmodule.CURrFAC.POST;

posmodule.tocontact.close;
posmodule.tocontact.open;

posmodule.items.first;
try
while not posmodule.items.Eof do
begin
posmodule.items.edit;


POSMODULE.itemscontact.AsString:=posmodule.CURRFACCONTACT.AsString;

posmodule.items.post;
posmodule.items.next;
end;

EXCEPT
END;

end;


except
end;
if  assigned(f_telep) then
freeandnil(f_telep);
 e_bar.setfocus;


end;

procedure Tf_cashinv.RzBitBtn26Click(Sender: TObject);
begin
mypass.PasswordChar:=#0 ;
mypass.PromptText:='Enter Tel Number';
mypass.ValueText:='';
try
if mypass.ShowModal=mrok then
begin
posmodule.tel.open;
if posmodule.tel.locate('tel',mypass.ValueText,[]) then
begin
f_msgdlg:=tf_msgdlg.create(self);
try
f_msgdlg.mymsg.Caption:='Already Exist!!!';
f_msgdlg.ShowModal;
except
end;
f_msgdlg.Release;



end
else
begin
posmodule.tel.append;
posmodule.telTel.AsString:=mypass.ValueText;

posmodule.tel.post;
end;

posmodule.tel.close;

end;
except
end;
e_bar.setfocus;
end;

procedure Tf_cashinv.RzBitBtn27Click(Sender: TObject);
begin
  //Application.CreateForm(Tf_searsh,f_searsh);
            if not assigned(f_searsh) then
f_searsh:=tf_searsh.create(self);
try
f_searsh.ShowModal;
except
end;
if  assigned(f_searsh) then
 freeandnil(f_searsh);
e_bar.setfocus;

end;

procedure Tf_cashinv.RzBitBtn28Click(Sender: TObject);
begin
  //Application.CreateForm(Tf_control,f_control);
              if not assigned(f_control) then
f_control:=tf_control.create(self);
try
f_control.currfac.Last;
f_control.currfac.prior;

f_control.MenuItem8Click(f_control.MenuItem8);
except
end;
if  assigned(f_control) then
 freeandnil(f_control);

 e_bar.setfocus;

end;

procedure Tf_cashinv.payllEnter(Sender: TObject);
begin
inherited;
try
 if strtofloat(totalll.text)=0 then exit;
posmodule.CURRFAC.edit;
 posmodule.CURRFACtotal.AsCurrency:=strtofloat(totalll.text);
posmodule.CURRFAC.post;
   //Application.CreateForm(Tf_helpdesk,f_helpdesk);
               if not assigned(f_helpdesk) then
f_helpdesk:=tf_helpdesk.create(self);
try
if f_helpdesk.ShowModal=mrok  then
begin
if  assigned(f_helpdesk) then
   freeandnil(f_helpdesk);

bokClick(bok);
end
else
begin
if  assigned(f_helpdesk) then
   freeandnil(f_helpdesk);
e_bar.SetFocus;
end;
  payll.text:=f_helpdesk.Edit1.Text;
except
if  assigned(f_helpdesk) then
   freeandnil(f_helpdesk);
end;


except
end;

 end;

procedure Tf_cashinv.im1Click(Sender: TObject);
begin
f_zoom:=tf_zoom.create(self);
try

f_zoom.ShowModal;
except
end;
f_zoom.release;
end;

procedure Tf_cashinv.AttachContact1Click(Sender: TObject);
var k:word;
begin

k:=13;
e_bar.Text:='-'+posmodule.itemsQTY.AsString;
e_barKeyDown(e_bar,k,[ssLeft]);
e_bar.Text:=posmodule.itemsitem.AsString;
e_barKeyDown(e_bar,k,[ssLeft]);
e_bar.SetFocus;



end;

procedure Tf_cashinv.cxGrid1DBTableView1CellClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
iiii:=posmodule.itemsID.AsInteger;

e_bar.SetFocus;
end;

procedure Tf_cashinv.RzBitBtn6Click(Sender: TObject);
begin
AttachContact1Click(AttachContact1);
end;

procedure Tf_cashinv.cbspClick(Sender: TObject);
begin
e_bar.SetFocus;
end;

procedure Tf_cashinv.cxDBVerticalGrid3Click(Sender: TObject);
begin
e_bar.SetFocus;
end;

end.
