unit p_cashinv2;

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, RzEdit, RzDBEdit, IvDictio, IvAMulti, IvBinDic,
  IvMulti, dxGDIPlusClasses, Abcwav;

type
  Tf_cashinv2 = 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;
    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;
    RzDBEdit1: TRzDBEdit;
    RzDBEdit2: TRzDBEdit;
    RzBitBtn3: TRzBitBtn;
    RzBitBtn4: TRzBitBtn;
    RzBitBtn5: TRzBitBtn;
    creditacc: TQuery;
    dcreditacc: TDataSource;
    creditaccSID: TStringField;
    creditaccSNAME: TStringField;
    creditaccCREDITLIMIT: TFloatField;
    DBText3: TDBText;
    IvTranslator1: TIvTranslator;
    RzBitBtn2: TRzBitBtn;
    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;
    www: TabcWaveList;
    cbsp: TCheckBox;
    BarcodeList1: TMenuItem;
    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 e_barEnter(Sender: TObject);
    procedure BarcodeList1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_cashinv2: Tf_cashinv2; qty:currency;bb:boolean;c:currency;LAST:STRING;
  myff:integer;

implementation

uses p_posmodule,p_touchcash, p_repmodule, p_barcode,  p_cbarcode,
  p_stocklist, p_companye, p_selbar, p_stocklist2, p_telep, p_msgdlg;

{$R *.DFM}

procedure Tf_cashinv2.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('price').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
posmodule.itemsprice.AsCurrency:=posmodule.stockposprice1.AsCurrency*cp;





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;

        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:='';


end;



END;



procedure Tf_cashinv2.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);
//module.CURRFAC.post;




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;





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') then
repmodule.frxReport1.print;
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_cashinv2.ModalResult:=MROK;


end;

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


c:=0;
qty:=0;


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

E_BAR.SetFocus;

end;

procedure Tf_cashinv2.FormCreate(Sender: TObject);
begin
bb:=true;
myff:=0;
end;

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

procedure Tf_cashinv2.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_cashinv2.payllKeyPress(Sender: TObject; var Key: Char);
VAR C1,C2:CURRENCY;

begin
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;




exit;
END;
END;

EXCEPT
END;
BOKClick(BOK);

END;
end;

procedure Tf_cashinv2.N2Click(Sender: TObject);
var f:textfile;
     i:integer;
begin
 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_cashinv2.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('udelete').AsString<>'True' then
begin

exit;
end;

end
else
begin

exit;
end;



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

e_barExit(e_bar);
try
posMODULE.items.Last;
except
end;
touser.close;
label2.Caption:=totalll.Text;
e_bar.SetFocus;
end;



procedure Tf_cashinv2.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;

totalll.Text:=floattostr(c);
daribe.Text:=floattostr(tc);
label2.Caption:=formatfloat('#,0;-#,0',c);
  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_cashinv2.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;


 EXCEPT
 END;

posmodule.locstock.open;

e_bar.SetFocus;

 end;

procedure Tf_cashinv2.ghzpmhghwkht1Click(Sender: TObject);


var key:word;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);
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;

end;

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

procedure Tf_cashinv2.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.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_cashinv2.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);
//p_touchcash.myexit:=1;
f_touchcash.btnclose1.Visible:=false;
f_touchcash.RzBitBtn3.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;
 if  assigned(f_touchcash) then
freeandnil(f_touchcash);




end;
 try
e_barExit(e_bar);
except
end;

e_bar.setfocus;
end;

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

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

exit;
mypass.PasswordChar:=#0 ;
mypass.PromptText:='Enter Discount Amount:';
mypass.ValueText:='';
try
if mypass.ShowModal=mrok then
begin
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_cashinv2.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_cashinv2.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_cashinv2.RzBitBtn2Click(Sender: TObject);
begin
       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_cashinv2.DeleteALL1Click(Sender: TObject);
var s:string;
begin

end;

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

if posmodule.touser.fieldbyname('CHANGEPRICE').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
posmodule.items.edit;

posmodule.itemsprice.AsCurrency:=strtofloat(mypass.ValueText);
posmodule.items.post;
 try
e_barExit(e_bar);
except
end;
end;


except
end;
 e_bar.setfocus;


end;

procedure Tf_cashinv2.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_cashinv2.RzBitBtn17Click(Sender: TObject);
begin
e_bar.Text:='';
e_bar.SetFocus;
end;

procedure Tf_cashinv2.RzBitBtn18Click(Sender: TObject);
var key:word;
shift:tshiftstate;
begin
key:=13;

 if myff<>1 then
  e_barKeyDown(e_bar,key,shift)
  else
BOKClick(BOK);  



end;

procedure Tf_cashinv2.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_cashinv2.payllExit(Sender: TObject);
begin
label2.Caption:=totalll.Text;
end;

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

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

exit;
mypass.PasswordChar:=#0 ;
mypass.PromptText:='Enter Discount Amount:';
mypass.ValueText:='';
try
if mypass.ShowModal=mrok then
begin
posmodule.items.First;
while not posmodule.items.Eof do
begin
posmodule.items.edit;
if strtofloat(mypass.ValueText)<101 then
posmodule.itemsDISCOUNT.AsCurrency:=strtofloat(mypass.ValueText);
posmodule.items.post;
posmodule.items.Next;
end;

 try
e_barExit(e_bar);
except
end;
end;


except
end;
 e_bar.setfocus;

end;

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

procedure Tf_cashinv2.BarcodeList1Click(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;


end.
