<%
crlf=CHR(13)+CHR(10)
SET CENTURY ON 
m_transid=orequest.form('thetransid')
if isnull(m_transid)
    m_transid=orequest.querystring('t') 
endif
theuser=orequest.querystring('user')

if isnull(m_transid)
    tsql=[select top 1 *,IIF(VAL(transid)=0,VAL(SUBSTR(transid,2)),VAL(transid)) AS VTR, ]
    tsql=tsql+[ padl(allt(transid),9) as ptransid ]
    tsql=tsql+[ from ("]+dbclocation+'cashsale.dbf'+[") order by vtr desc, ptransid desc ]
    else
    tsql=[select top 1 *,IIF(VAL(transid)=0,VAL(SUBSTR(transid,2)),VAL(transid)) AS VTR, ]
    tsql=tsql+[ padl(allt(transid),9) as ptransid ]
    tsql=tsql+[ from ("]+dbclocation+'cashsale.dbf'+[") order by vtr desc, ptransid desc where allt(transid)==']+allt(m_transid)+[']
endif
&tsql
SCATTER NAME SearchResults
if TYPE('SearchResults.fbrinv')='C' and not ALLTRIM(SearchResults.fbrinv)=='0' and not EMPTY(SearchResults.fbrinv)
  fbrnumberreceived=allt(searchresults.fbrinv)
else
  fbrnumberreceived=[]
endif
if empty(date)
  thedatestring=date() &&transform(date())
else
  thedatestring=date &&transform(dtoc(date))
endif
openingbalance=[]
if BETWEEN(val(left(SearchResults.depositid,2)),1,8) and left(SearchResults.depositid,3)<>'019' 
    select sum(debit-credit) as dayopening from (dbclocation+[acctran]) where accountid=SearchResults.depositid and date<SearchResults.date INTO CURSOR opening
		select sum(debit) as debits, SUM(credit) as credits from (dbclocation+[acctran]) where accountid=SearchResults.depositid and date=SearchResults.date INTO CURSOR closing
		openingbalance=[Opening: ]+allt(transform(opening.dayopening))+[ add debits: ]+allt(transform(closing.debits))+[ less credits: ]+;
		ALLTRIM(transform(closing.credits))+[ closing: ]+ALLTRIM(TRANSFORM(opening.dayopening+closing.debits-closing.credits))+[ as on ]+transform(DAY(SearchResults.date))+[ ]+LEFT(CMONTH(SearchResults.date),3)+[ ]+ALLTRIM(TRANSFORM(YEAR(SearchResults.date)))
ENDIF
*****
if not empty(fbrnumberreceived)
    tfile=addbs(oprop.appstartpath)+'temp\'+fbrnumberreceived+'.bmp'
    if not file(tfile)
      SET PROCEDURE TO (addbs(oprop.appstartpath)+"FoxBarcodeQR.fxp") ADDITIVE
      set path to (addbs(oprop.appstartpath)) additive
      *--- Create FoxBarcodeQR object and QR Code barcode image
      LOCAL loFbc, lcQRImage
      m.loFbc = CREATEOBJECT("FoxBarcodeQR")
      *m.loFbc = NEWOBJECT("FoxBarcodeQR")
      m.lcString = fbrnumberreceived
      ERASE (tfile)
      m.lcQRImage = loFbc.FullQRCodeImage(lcString, tfile , 32*4)
      m.loFbc=.null.
    endif
endif
*****
USE (dbclocation+[accounts]) IN SELECT([accounts])
=SEEK(SearchResults.customer,[accounts],[accountid])
ccreditor=[<option value=']+accounts.accountid+[' selected>]+ALLTRIM(accounts.name)+[</option>]
=SEEK(SearchResults.depositid,[accounts],[accountid])
cdebitor=[<option value=']+accounts.accountid+[' selected>]+ALLTRIM(accounts.name)+[</option>]
invnum=searchresults.transid
CLOSE TABLES 
CLOSE DATABASES 
*************
USE IN SELECT('printinvoice')
	IF NOT EMPTY(xcompany.fbrposid)
		Select d.name as deposited,x.depositid, x.Total As PrdTotal, x.fbrinv, x.fbrPOST, x.daysrno, x.discount As prdDisc, x.memdisc,;
			A.TAXPRATE, A.TAXRATE,  x.Payment,;
			x.EXPAMT, x.transid, x.name As Memo,Space(9) As bill,;
			x.Date,x.ddate,x.address1,x.address2,x.SaleMan,x.customer,z.SaleMan As ySaleMan,Y.ac,Y.Name,Y.phone, Y.fax,y.accountid, ;
			z.ItemID, z.Batch, z.Desc, z.sr_no, z.packing, z.qty,z.bonus,z.rate,a.cost, a.trade ,x.dtime,x.srvchgs, z.discount, z.Total, z.expiry;
			FROM (dbclocation+[CashSale]) x LEFT join (dbclocation+[ACCOUNTS]) Y ON (x.customer=y.accountid) ;
			LEFT JOIN (dbclocation+[Cashdata]) z ON (x.transid=z.transid) LEFT join (dbclocation+[itemmast]) a ON (z.itemid=a.itemid) ;
			LEFT JOIN (dbclocation+[accounts]) d ON (x.depositid=d.accountid);
			WHERE x.transid=invnum ;
			Order By z.transid, x.Date,z.sr_no ;
			INTO cursor ([printinvoice]) readwrite
	ELSE
		Select d.name as deposited,x.depositid, x.Total As PrdTotal, '' as fbrinv, '' as fbrPOST, x.daysrno, x.discount As prdDisc, x.memdisc,;
			0 as TAXPRATE, 0 as TAXRATE, x.Payment,;
			x.EXPAMT, x.transid, x.name As Memo,Space(9) As bill,;
			x.Date,x.ddate,x.address1,x.address2,x.SaleMan,x.customer,z.SaleMan As ySaleMan,Y.ac,Y.Name,Y.phone, Y.fax,y.accountid, ;
			z.ItemID, z.Batch, z.Desc, z.sr_no, z.packing, z.qty,z.bonus,z.rate,a.cost, a.trade ,x.dtime,x.srvchgs, z.discount, z.Total, z.expiry;
			FROM (dbclocation+[CashSale]) x LEFT join (dbclocation+[ACCOUNTS]) Y ON (x.customer=y.accountid) ;
			LEFT JOIN (dbclocation+[Cashdata]) z ON (x.transid=z.transid) LEFT join (dbclocation+[itemmast]) a ON (z.itemid=a.itemid) ;
			LEFT JOIN (dbclocation+[accounts]) d ON (x.depositid=d.accountid);
			WHERE x.transid=invnum ;
			Order By z.transid, x.Date,z.sr_no ;
			INTO cursor ([printinvoice]) readwrite
	endif
    thedeposited=deposited
    =changeFieldStruc()
	IF EMPTY(memo) AND depositid<>[019]
		replace ALL memo WITH thedeposited
	ENDIF
	XDISCLABEL=[]
	rept_saleman=[]
	SCAN
		replace cost WITH NVL(cost,0), trade WITH NVL(trade,0), sr_no WITH RECNO()
		IF discount<>0
			XDISCLABEL=[DISC]
		ENDIF
		IF NOT EMPTY(saleman)
			rept_saleman=IIF(SEEK(saleman,[accounts],[accountid]),accounts.name,[])
		endif
	endscan
	If xcompany.haspart
		PartsValue=0
		partsQty=0
		Select 'printinvoice'
		Go Top
		Scan
			If Seek(ItemID,'itemmast','itemid') And itemmast.ispart
				PartsValue=PartsValue+(rate*qty-discount)
				partsQty=partsQty+qty
				Scatter Name saveit
				Delete
			ENDIF
			IF discount<>0
				XDISCLABEL=[DISC]
			endif
		Endscan
		If PartsValue<>0
			Append Blank
			Gather Name saveit
			Replace Desc With 'REPAIR CHARGES',;
				qty With partsQty,;
				rate With  (PartsValue)/partsQty,;
				total With PartsValue
		Endif
	Endif
    go top
    STORE 0 TO TOTALTAX, fbrservice, SERVICECHARGES, TOTALAMOUNT, PRODUCTDISCOUNT,;
     MEMBERDISCOUNT, NETAMOUNT, RECEIVEDAMOUNT, BALANCEAMOUNT
    IF type([searchresults.fbrinv])=[C] and not empty(searchresults.fbrinv)
        fbrservice=1
    endif
    SERVICECHARGES=srvchgs
    TOTALAMOUNT=ROUND(Printinvoice.prdtotal+printinvoice.srvchgs,0)
    PRODUCTDISCOUNT=prdDisc
    MEMBERDISCOUNT=memdisc
    netamount=ROUND(Printinvoice.prdtotal+fbrservice-Printinvoice.prdDISC-PRINTINVOICE.MEMDISC+printinvoice.srvchgs,0)
    RECEIVEDAMOUNT=iif(empty(payment),netamount,payment) 
    BALANCEAMOUNT=RECEIVEDAMOUNT-netamount 
*************
%>
<!DocType HTML>
<html>
<html lang="ar" lang="ar" translate="no">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="google" content="notranslate">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <link rel="icon" href="images/logo.bmp" type="image/x-icon">
    <style>
      body {
            font-family: 'Calibri', 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
            width:302px;
       }
        @media print {
            .printnoshow {
                display: none;
            }
        }

        @media screen {
            .screennoshow {
                display: none;
            }
        }

        @media screen,
        print {
            .noshowall {
                display: none;
            }
        }

        #wrapper {
                     width: 8cm;
            text-align: center;
            margin: auto;
        }
    h1, p, table {
        margin:auto;
    }
    TD{
        font-size: 10PT;
    }
    </style>
</head>
<body >
<div id='wrapper'>
    <h1 style="margin:auto;font-stretch: ultra-expanded	"><<xcompany.name>></h1>
        <p><<allt(allt(xcompany.address1)+[ ]+allt(xcompany.address2))>>
            <%if not empty(xcompany.fbrposid)%>
            <img src="bootstrap/images/fbr.png" style="height:1in;width:1.5in"/>
            <%endif%>
            <%if not empty(fbrnumberreceived)%>
            <img src="temp/<<fbrnumberreceived>>.bmp" style="height:0.75in"/> 
            <%endif%>
            </p>
            <%if type([searchresults.fbrinv])=[C] and not empty(searchresults.fbrinv)%>
            <p><<[POSID# ]+ALLT(xcompany.fbrposid)>> <<[FBR# ]+ALLT(fbrinv)>></p>
            <%endif%>
            <%if not empty(memo)%>
            <p><<allt(memo)>></p>
            <%endif%>
            <p><<[INV# ]+ALLT(TRANSID)+[ ]+ttoc(dtime)>></p>
            <table width="100%" BORDER="1PX" STYLE="border-collapse:collapse">
                <tr>
                    <td>#</td>
                    <td>DETAILS</td>
                    <TD >PRICE</TD>
                    <TD >QTY</TD>
                    <TD >TAX</TD>
                    <TD >AMOUNT</TD>
                </tr>
               
                <%SCAN%>
                <%
                ITEMTX=round(iif(empty(taxprate),taxrate*qty,(qty*rate)-(qty*rate)/(1+taxprate/100)),2)
                SALEINCLUDINGTAX=qty*rate
                saleexcludingtax=saleincludingtax-itemtx
                totaltax=totaltax+itemtx
                %>
                   <TR>
                    <td STYLE="VERTICAL-ALIGN:TOP"><<RECNO()>></td>
                    <td><<DESC>></td>
                    <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><<round(saleexcludingtax/qty,2)>></TD>
                    <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><<QTY>></TD>
                    <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><<itemtx>></TD>
                    <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><<ROUND(Printinvoice.qty*printinvoice.rate,0)>></TD>
                    </TR>
                <%ENDSCAN%>
                <!--*SERVICECHARGES=srvchgs
                *TOTALAMOUNT=ROUND(Printinvoice.prdtotal+printinvoice.srvchgs,0)
                *PRODUCTDISCOUNT=prdDisc
                *MEMBERDISCOUNT=memdisc
                *netamount=ROUND(Printinvoice.prdtotal+fbrservice-Printinvoice.prdDISC-PRINTINVOICE.MEMDISC+printinvoice.srvchgs,0)
                *RECEIVEDAMOUNT=iif(empty(payment),netamount,payment) 
                *BALANCEAMOUNT=RECEIVEDAMOUNT-netamount
                --> 
                <%if totaltax<>0 %>
                    <tr><td colspan="3" align='right' STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC">TOTAL TAX</td><TD colspan="3" ALIGN='RIGHT' STYLE="FONT-WEIGHT:BOLD;"><<TOTALTAX>></TD></tr>
                <%endif%>
                <%if fbrservice<>0 %>
                <tr><td colspan="3" align='right' STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC">POS SERVICE CHARGES</td><TD colspan="3" ALIGN='RIGHT' STYLE="FONT-WEIGHT:BOLD;"><<fbrservice>></TD></tr>
                <%endif%>
                <%if SERVICECHARGES<>0 %>
                <tr><td colspan="3" align='right' STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC">SERVICE CHARGES</td><TD colspan="3" ALIGN='RIGHT' STYLE="FONT-WEIGHT:BOLD;"><<SERVICECHARGES>></TD></tr>
                <%endif%>
                <tr><td colspan="3" align='right' STYLE="FONT-WEIGHT:BOLD;">TOTAL AMOUNT</td><TD colspan="3" ALIGN='RIGHT' STYLE="FONT-WEIGHT:BOLD;"><<TOTALAMOUNT>></TD></tr>
                <%if round(PRODUCTDISCOUNT+MEMBERDISCOUNT,2)<>0 %>
                    <tr><td colspan="6" align='right' STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC">YOU SAVED <<round(PRODUCTDISCOUNT+MEMBERDISCOUNT,2)<>0>></td></tr>
                <%endif%>
                </table>
           
            <DIV>
            <P STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC"><<'OPERATOR '+ALLT(theuser)+' '+IIF(EMPTY(REPT_SALEMAN),'','SOLD BY: '+REPT_SALEMAN)>></P>
            <%if NOT EMPTY(XCOMPANY.CUSTMSG1) %>
                <P STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC"><<XCOMPANY.CUSTMSG1>></P>
            <%endif%>
            <%if NOT EMPTY(XCOMPANY.CUSTMSG2) %>
                <P STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC"><<XCOMPANY.CUSTMSG2>></P>
            <%endif%>
            <%if NOT EMPTY(XCOMPANY.CUSTMSG3) %>
                <P STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC"><<XCOMPANY.CUSTMSG3>></P>
            <%endif%>
            <%if NOT EMPTY(XCOMPANY.CUSTMSG4) %>
                <P STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC"><<XCOMPANY.CUSTMSG4>></P>
            <%endif%>

        </DIV>
</div>

</body>
</html>