<%
crlf=CHR(13)+CHR(10)
SET CENTURY ON 
m_transid=orequest.form('thetransid')
if isnull(m_transid)
    m_transid=orequest.querystring('t') 
endif
calledon=nvl(orequest.querystring('calledon'),ttoc(dtot({//})))
theuser=[] &&orequest.querystring('user')
pagetype=orequest.querystring('pw')
**
pagetype=lower(transform(orequest.querystring('pw')))
*<Option val="POS">POS English</Option> 80mm
*<Option val="posmix">POS MIX</Option>
*<Option val="poslocal">POS Local Language</Option>
*<Option val="A4">A4 (8.3 x 11.7 inches)</Option>
*<Option val="A5">A5 (5.8 x 8.3 inches)</Option>
*<Option val="A6">A6 (4.1 x 5.8 inches)</Option>
*@page {size: <length> | auto | [ <page-size> || [ landscape | portrait ] ]}
do case 
    case [mix] $ pagetype
        isurdu=2
    case [local] $ pagetype
        isurdu=1
    OTHER
        isurdu=0
endcase
    
do case
    case pagetype='pos'
        pagewidth='80mm'
        pageheight='3276mm'
    case pagetype='a4'
        pagewidth='8.3inch'
        pageheight='11.7inch'
    case pagetype='a5'
        pagewidth='5.8inch'
        pageheight='8.3inch'
    case pagetype='a6'
        pagewidth='4.1inch'
        pageheight='5.8inch'
    OTHER
        pagewidth='8.3inch'
        pageheight='11.7inch'
endcase
**
if isnull(m_transid)
    tsql=[select top 1 x.*,IIF(VAL(x.transid)=0,VAL(SUBSTR(x.transid,2)),VAL(x.transid)) AS VTR, ]
    tsql=tsql+[ padl(allt(x.transid),9) as ptransid, y.name as acname ]
    tsql=tsql+[ from ("]+dbclocation+'invoice.dbf'+[") x left join ("]+dbclocation+'accounts.dbf'+[") y ]
    tsql=tsql+[ on (x.customer=y.accountid) order by vtr desc, ptransid desc into cursor xtmpcur]
    else
    tsql=[select top 1 x.*,IIF(VAL(x.transid)=0,VAL(SUBSTR(x.transid,2)),VAL(x.transid)) AS VTR, ]
    tsql=tsql+[ padl(allt(x.transid),9) as ptransid, y.name as acname]
    tsql=tsql+[ from ("]+dbclocation+'invoice.dbf'+[") x left join ("]+dbclocation+'accounts.dbf'+[") y ]
    tsql=tsql+[ on (x.customer=y.accountid) order by vtr desc, ptransid desc ]
    tsql=tsql+[ where allt(transid)==']+allt(m_transid)+[' into cursor xtmpcur]
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.customer,2)),1,8) and left(SearchResults.customer,3)<>'019' 
    select sum(debit-credit) as dayopening from (dbclocation+[acctran]) where accountid=SearchResults.customer and date<SearchResults.date INTO CURSOR opening
	
    select sum(debit) as debits, SUM(credit) as credits from (dbclocation+[acctran]) where accountid=SearchResults.customer and date=SearchResults.date INTO CURSOR closing

	openingbalance=[Opening: ]+allt(transform(nvl(opening.dayopening,0)))+[ add debits: ]+allt(transform(nvl(closing.debits,0.00)))+[ less credits: ]+;
		ALLTRIM(transform(nvl(closing.credits,0.00)))+[ closing: ]+ALLTRIM(TRANSFORM(nvl(opening.dayopening,0)+nvl(closing.debits,0.00)-nvl(closing.credits,0.00)))+;
        [ as on ]+transform(DAY(SearchResults.date))+[ ]+LEFT(CMONTH(SearchResults.date),3)+[ ]+ALLTRIM(TRANSFORM(YEAR(SearchResults.date)))
ENDIF
*****

if not empty(openingbalance)
    tfile=addbs(oprop.appstartpath)+'images\receiptbarcode.bmp'
      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 = allt(searchresults.acname)+[ balance: ]+ openingbalance
      ERASE (tfile)
      m.lcQRImage = loFbc.FullQRCodeImage(lcString, tfile  , 32*4)
      m.loFbc=.null.
endif
if not empty(fbrnumberreceived)
    tfile=addbs(oprop.appstartpath)+'images\'+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.customer,[accounts],[accountid])
cdebitor=[<option value=']+accounts.accountid+[' selected>]+ALLTRIM(accounts.name)+[</option>]
*invnum=allt(searchresults.transid)
if empty(m_transid)
    invnum=allt(searchresults.transid)
    else
    invnum=allt(m_transid)
endif
*CLOSE TABLES 
*CLOSE DATABASES 
lgetunit=iif(xcompany.zunit or xcompany.usekglibs,.t.,.f.) 
*************
haskglibs=xcompany.usekglibs
uniquealias=SYS(2015)
*uniquefilename=addbs(oprop.appstartpath)+[temp\]+uniquealias+[.dbf] 
	IF NOT EMPTY(xcompany.fbrposid) 
        tsql=[Select d.name as deposited,x.customer as depositid, d.phone as custphone, x.opt, x.Total As PrdTotal, x.fbrinv, x.fbrPOST, 0 as daysrno, x.discount As prdDisc, 0 as memdisc, ]
        tsql=tsql+[0 as TAXPRATE, 0 as TAXRATE,a.extra, x.Payment, x.EXPAMT, x.transid, x.name As Memo,Space(9) As bill, ]
        tsql=tsql+[x.Date,x.ddate,x.address1,x.address2,x.SaleMan,x.customer, ]+iif(lgetunit=.t.,'z.unit','0')+[ as zunit, ] + iif(xcompany.zctn=.t.,'z.ctn','space(2)')+[ as zctn, ]
        tsql=tsql+[space(6) as ySaleman, Y.ac,Y.Name,Y.phone, Y.fax,y.accountid, ]+ iif(xcompany.ismedical=.t.,'z.pdisc1','0')+[ as pdisc1, ]
        tsql=tsql+iif(xcompany.ismedical=.t.,'z.pdisc2','0')+[ as pdisc2, ]
        tsql=tsql+[z.ItemID, z.Batch, z.Desc, z.sr_no, z.packing, z.qty,]+iif(haskglibs,'a.kgs','0')+[ as kgs,]+iif(haskglibs,'a.libs','0')+[ as libs,z.bonus,z.rate,a.cost, a.trade ,x.dtime,0 as srvchgs, z.discount, z.Total, z.expiry ] 
        tsql=tsql+[FROM (']+dbclocation+[invoice') x LEFT join (']+dbclocation+[ACCOUNTS') Y ON (x.customer=y.accountid) ]   
        tsql=tsql+[LEFT JOIN (']+dbclocation+[invdata') z ON (x.transid=z.transid) LEFT join (']+dbclocation+[itemmast') a ON (z.itemid=a.itemid) ]
        tsql=tsql+[LEFT JOIN (']+dbclocation+[accounts') d ON (x.customer=d.accountid) ]
        tsql=tsql+[WHERE x.transid==']+invnum+[' Order By z.transid, x.Date, z.sr_no INTO cursor (']+uniquealias+[') readwrite]
        &tsql
    ELSE
        tsql=[Select d.name as deposited,x.customer as depositid, d.phone as custphone, x.opt, x.Total As PrdTotal, '' as fbrinv, '' as fbrPOST, 0 as daysrno, x.discount As prdDisc, 0 as memdisc, ]
        tsql=tsql+[0 as TAXPRATE, 0 as TAXRATE,a.extra, x.Payment, x.EXPAMT, x.transid, x.name As Memo,Space(9) As bill, ]
        tsql=tsql+[x.Date,x.ddate,x.address1,x.address2,x.SaleMan,x.customer, ]+iif(lgetunit=.t.,'z.unit','0')+[ as zunit, ] + iif(xcompany.zctn=.t.,'z.ctn','space(2)')+[ as zctn, ]
        tsql=tsql+[space(6) as ySaleman, Y.ac,Y.Name,Y.phone, Y.fax,y.accountid, ]+ iif(xcompany.ismedical=.t.,'z.pdisc1','0')+[ as pdisc1, ]
        tsql=tsql+iif(xcompany.ismedical=.t.,'z.pdisc2','0')+[ as pdisc2, ]
        tsql=tsql+[z.ItemID, z.Batch, z.Desc, z.sr_no, z.packing, z.qty,]+iif(haskglibs,'a.kgs','0')+[ as kgs,]+iif(haskglibs,'a.libs','0')+[ as libs,z.bonus,z.rate,a.cost, a.trade ,x.dtime,0 as srvchgs, z.discount, z.Total, z.expiry ] 
        tsql=tsql+[FROM (']+dbclocation+[invoice') x LEFT join (']+dbclocation+[ACCOUNTS') Y ON (x.customer=y.accountid) ]   
        tsql=tsql+[LEFT JOIN (']+dbclocation+[invdata') z ON (x.transid=z.transid) LEFT join (']+dbclocation+[itemmast') a ON (z.itemid=a.itemid) ]
        tsql=tsql+[LEFT JOIN (']+dbclocation+[accounts') d ON (x.customer=d.accountid) ]
        tsql=tsql+[WHERE x.transid==']+invnum+[' Order By z.transid, x.Date, z.sr_no INTO cursor (']+uniquealias+[') readwrite]
        &tsql
    endif
   
    select (uniquealias)
    
    thedeposited=nvl(deposited,'')
    =changeFieldStruc()
	IF EMPTY(memo) AND depositid<>[019]
		*replace ALL memo WITH thedeposited
	ENDIF
    go top 
    thevendordetails=allt(depositid)+[: ]+allt(thedeposited)+[ ]+allt(custphone)
	XDISCLABEL=[]
	rept_saleman=[]
    hastax=.f.
    hasdiscount=.f. 
    haszunit = .f. 
    haszctn = .f.
	haskglibs=xcompany.usekglibs
    Go Top
    haspdisc1=.f.
    haspdisc2=.f.
    hasbonus=.f.
    hasexpiry=.f. 
    hasbatch=.f.
    select (uniquealias)
    SCAN
        if not empty(kgs) or not empty(libs)
            haskglibs=xcompany.usekglibs 
        endif
        if not empty(expiry)
            hasexpiry=.t. 
        endif
        if not empty(batch)
            hasbatch=.t. 
        endif
        if not empty(pdisc1)
            haspdisc1=.t.
        endif
        if not empty(pdisc2)
            haspdisc2=.t.
        endif
        if not empty(bonus)
            hasbonus=.t.
        endif
        
        if not empty(zunit)
            haszunit= .t.
        endif
        if not empty(zctn)
            haszctn= .t.
        endif
        if not empty(taxprate) or not empty(taxrate)
            hastax=.t. 
        endif
		replace cost WITH NVL(cost,0), trade WITH NVL(trade,0), sr_no WITH RECNO()
		IF discount<>0
			XDISCLABEL=[DISC]
            hasdiscount=.t. 
		ENDIF
		IF NOT EMPTY(saleman)
			rept_saleman=IIF(SEEK(saleman,[accounts],[accountid]),accounts.name,[])
		endif
        theuser=allt(opt)
	endscan
 
    If xcompany.haspart
		PartsValue=0
		partsQty=0
		Select (uniquealias)
		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(prdtotal+srvchgs,0)
    PRODUCTDISCOUNT=prdDisc
    MEMBERDISCOUNT=memdisc
    netamount=ROUND(prdtotal+fbrservice-prdDISC-MEMDISC+srvchgs,0)
    RECEIVEDAMOUNT=iif(empty(payment),netamount,payment) 
    BALANCEAMOUNT=RECEIVEDAMOUNT-netamount 
    select (uniquealias)
*************
%>
<!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="stylesheet" href="bootstrap/bills.css">
    
    <link rel="icon" href="images/logo.bmp" type="image/x-icon">
    <link href="bootstrap/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="bootstrap/web-fonts-with-css/css/all.min.css">
  
</head>
<body ">
<div id='wrapper'>
    <div class="centered-on-top  printnoshow">
    <button type="button" class="btn btn-primary" style='display:inline-block' id="search" href="#" onclick="window.print();">Print
            <i class="fas fa-print"></i></button>
    <button type="button" class="btn btn-primary" style='display:inline-block' onclick="window.close()">
        <i class="fas fa-stop-circle"></i> Close
        </button>
    </div>
    <p align="center">
        <img src='images/logo.bmp' >
    </p>
    
     <div class='companytitlediv'>
        <span class='thetittle' style="font-family: 'Arial', 'Verdana', 'Tahoma';font-size:16px !important;line-height: 1 !important;font-weight:bold !important;"><%=xcompany.name%><%=iif(empty(xcompany.ntn),'',[NTN: ]+allt(xcompany.ntn))%></span>
        <p style="font-family: 'Arial', 'Verdana', 'Tahoma';font-size:10px !important;line-height:1 !important;font-weight:bold !important;padding:0px"><%=allt(allt(xcompany.address1)+[ ]+allt(xcompany.address2))%>
        <%=allt(allt(xcompany.phone)+[ ]+allt(xcompany.email))%></p>
    </div>
       
    <div class='clientdiv'>
        <span class='thetittle' class='thetittle' style="font-family: 'Arial', 'Verdana', 'Tahoma';font-size:16px !important;line-height: 1 !important;font-weight:bold !important;">CLIENT:</span>
        <p calss='thetittle' style="font-family: 'Arial', 'Verdana', 'Tahoma';font-size:12px !important;line-height: 1 !important;font-weight:bold !important;"><%=thevendordetails%></p>
    </div>
   
    
        <table BORDER="1PX" STYLE="border-collapse:collapse;width:98%">
            <tr><td align='center' colspan="14" style="border-left-style:hidden;border-top-style:hidden;border-right-style:hidden;">
                <p align='center' style="font-weight: bold;text-align: center;line-height:1 !important;">DEBIT SALES</p>
        <%if not empty(fbrnumberreceived)%>
            <p style="text-align: center;">
            <img src="bootstrap/images/fbr.png" style="height:1in;width:1.5in"/>
            <img src="images/<%=fbrnumberreceived%>.bmp" style="height:0.75in"/> 
            </p>
           <%endif%>
            <%if type([searchresults.fbrinv])=[C] and not empty(searchresults.fbrinv)%>
            <p style="text-align: center;font-weight: bold;line-height:1 !important;"><%=[POSID# ]+ALLT(xcompany.fbrposid)%> <%=[FBR# ]+ALLT(fbrinv)%></p>
            <%endif%>
            <%if not empty(memo)%>
                <p style="text-align: center;font-weight: bold;line-height:1 !important;"><%=allt(memo)%></p>
            <%endif%>
            <p style="text-align: center;font-weight: bold;line-height:1 !important;"><%=[PUR# ]+ALLT(TRANSID)+[ DATE: ]+dtoc(date)+iif(empty(bill),[],[ BILL: ]+allt(bill))%></p>
            </td></tr>
            <tr STYLE="font-weight: bold;">
                    <tr STYLE="font-weight: bold;">
                    <td>#</td>
                    <td>DETAILS</td>
                    <%if hasbatch%>
                        <td class="hiddenonpos">Batch</td>
                    <%endif%>
                    <%if hasexpiry%>
                        <td class="hiddenonpos">expiry</td>
                    <%endif%>
                    
                    <%if haskglibs%>
                        <TD >KGs</TD>
                        <TD >LIBs</TD>
                        <TD >CTNs</TD>
                        <TD >RATE/LIB</TD>
                        <TD >RATE/KG</TD>
                    <%else%>
                        <%if haszctn%>
                            <td>UNIT</td>    
                        <%endif%>
                        <%if haszunit%>
                            <td>PCS</td>    
                        <%endif%>
                        <TD >QTY</TD>
                         <%if hasbonus%>
                            <td class="hiddenonpos"><i>BONUS</i></td>    
                        <%endif%>
                        <TD >RATE</TD>
                    <%endif haskglibs%>
                    <%if hastax=.t.%>
                    <TD class="hiddenonpos">TAX</TD>
                    <TD class="hiddenonpos">VAT</TD>
                    <%endif%>
                    <TD >TOTAL</TD>
                    <%if haspdisc1%>
                        <td class="hiddenonpos">Disc<br/>ON Sale</td>
                    <%endif%>
                    <%if haspdisc2%>
                        <td class="hiddenonpos">Disc<br/>NET</td>
                    <%endif%>
                    <%if hasdiscount%>
                        <td class="hiddenonpos">DISC</td>    
                        <TD class="hiddenonpos">NET AMOUNT</TD>
                    <%endif%>
                </tr>

                <%SCAN%>
                <%
                select (uniquealias)
                ITEMTX=round(iif(empty(taxprate),taxrate*qty,(qty*rate)-(qty*rate)/(1+taxprate/100)),2)
                    if empty(taxprate)
                        thetaxprate=round((taxrate/(rate-taxrate))*100,2)
                        else
                        thetaxprate=taxprate
                    endif
                    SALEINCLUDINGTAX=qty*rate
                    saleexcludingtax=saleincludingtax-itemtx
                    totaltax=totaltax+itemtx
                    thechars=[]
           
                    textra=allt(nvl(extra,''))
                    if not empty(textra)
                        for i=1 to len(textra)
                            thechars=thechars+[ | ]+subst(textra,i,1)+[ : ]+transform(asc(subst(textra,i,1)))
                        endfor
                    endif
                    testunits=nvl(zunit,0)
                    kgqty=QTY*iif(KGS=0,1,kgs)
                    libsqty=QTY*iif(libs=0,2.20462,libs)
                    kgqty=icase(kgqty=round(kgqty,0),round(kgqty,0),kgqty=round(kgqty,2),round(kgqty,2),kgqty=round(kgqty,3),round(kgqty,3),round(kgqty,4))
                    libsqty=icase(libsqty=round(libsqty,0),round(libsqty,0),libsqty=round(libsqty,2),round(libsqty,2),libsqty=round(libsqty,3),round(libsqty,3),round(libsqty,4))
                    rateperlib=saleexcludingtax/libsqty
                    if haskglibs
                        if empty(kgs) 
                            thectnqty=iif(empty(testunits),qty,testunits)
                        else
                            thectnqty=qty
                        endif
                        rateperkg=saleexcludingtax/kgqty
                        else
                        thectnqty=qty
                        *rateperkg=saleexcludingtax/qty
                        rateperkg=saleincludingtax/qty
                    endif
                    rateperkg=icase(rateperkg=round(rateperkg,0),round(rateperkg,0),round(rateperkg,2))
                    rateperlib=icase(rateperlib=round(rateperlib,0),round(rateperlib,0),round(rateperlib,2))
        
                    %>
                     <td STYLE="VERTICAL-ALIGN:TOP"><%=RECNO()%></td>
                    <td title="<%=thechars%>"><%=icase(isurdu=2,allt(DESC)+iif(empty(textra),[],[<br/>]+allt(textra)),isurdu=1,iif(empty(textra),allt(desc),allt(textra)),allt(desc))%></td>
                    <%if hasbatch%>
                        <TD class="hiddenonpos" ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><i><%=iif(empty(batch),'&nbsp;',transform(batch))%></i></TD>    
                    <%endif%>
                    <%if hasexpiry%>
                        <TD class="hiddenonpos" ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><i><%=iif(empty(expiry),'&nbsp;',transform(expiry))%></i></TD>    
                    <%endif%>
                    <%if haskglibs%>
                        <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(KGQTY),'&nbsp;',KGQTY)%></TD>
                        <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(libsQTY),'&nbsp;',libsQTY)%></TD>
                        <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(thectnqty),'&nbsp;',thectnqty)%></TD>
                        <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(rateperlib),'&nbsp;',rateperlib)%></TD>
                        <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(rateperkg),'&nbsp;',rateperkg)%></TD>
                    <%else%>
                        <%if haszctn%>
                            <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=zctn%></TD>    
                        <%endif%>
                        <%if haszunit%>
                            <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(thectnqty),'&nbsp;',thectnqty)%></TD>    
                        <%endif%>
                        <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=thectnqty%></TD>
                        <%if hasbonus%>
                            <TD class="hiddenonpos" ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><i><%=iif(empty(bonus),'&nbsp;',transform(bonus))%></i></TD>    
                        <%endif%>
                       <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=rateperkg%></TD>
                    <%endif haskglibs%>
                    <%if hastax=.t.%>
                    <TD class="hiddenonpos" ALIGN="center" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(thetaxprate),'&nbsp;',transform(thetaxprate)+[%])%></TD>
                    <TD class="hiddenonpos" ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(itemtx),'&nbsp;',transform(itemtx,'999999999.99'))%></TD>
                    <%endif%>
                     <TD ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=ROUND(qty*rate,0)%></TD>
                    <%
                        roundeddisc=icase(discount=round(discount,0),round(discount,0),round(discount,2))
                    %>
                    <%if haspdisc1%>
                        <td class="hiddenonpos" ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(pdisc1),'&nbsp;',transform(pdisc1)+'%')%></td>
                    <%endif%>
                    <%if haspdisc2%>
                            <td class="hiddenonpos" ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(pdisc2),'&nbsp;',transform(pdisc2)+'%')%></td>
                    <%endif%>
                    
                    <%if hasdiscount%>
                        <td class="hiddenonpos" ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=iif(empty(roundeddisc),'&nbsp;',transform(roundeddisc))%></td>
                         <TD class="hiddenonpos" ALIGN="RIGHT" STYLE="VERTICAL-ALIGN:TOP"><%=ROUND(qty*rate-roundeddisc,0)%></TD>    
                    <%endif%>
                   </tr>
                <%ENDSCAN%>
               <%
                   cspan=1
                  
                %>
                 
                <tr>
                <td colspan='14' style="text-align:right;border-left-style:hidden;border-bottom-style:hidden;border-right-style:hidden;">
                <table align="right" style="width:auto"> 
                    <%if hastax=.t.%> 
                    <%if totaltax<>0 %>
                        <tr><td colspan="<%=cspan%>" align='right' STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC;border-bottom-style: hidden;border-left-style: hidden;">TOTAL TAX</td><TD ALIGN='RIGHT' STYLE="FONT-WEIGHT:BOLD;padding-left: 20px;"><%=transform(TOTALTAX,'99999999999999.99')%></TD></tr>
                    <%endif%>
                    <%endif%>
                    <%if fbrservice<>0 %>
                    <tr><td colspan="<%=cspan%>" align='right' STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC;border-bottom-style: hidden;border-left-style: hidden;">POS SERVICE CHARGES</td><TD  ALIGN='RIGHT' STYLE="FONT-WEIGHT:BOLD;padding-left: 20px;"><%=transform(fbrservice,'99999999999999.99')%></TD></tr>
                    <%endif%>
                    <%if SERVICECHARGES<>0 %>
                    <tr><td colspan="<%=cspan%>" align='right' STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC;border-bottom-style: hidden;border-left-style: hidden;">SERVICE CHARGES</td><TD  ALIGN='RIGHT' STYLE="FONT-WEIGHT:BOLD;padding-left: 20px;"><%=transform(SERVICECHARGES,'99999999999999.99')%></TD></tr>
                    <%endif%>
                    <tr ><td colspan="<%=cspan%>" align='right' STYLE="FONT-WEIGHT:BOLD;border-bottom-style: hidden;border-left-style: hidden;">TOTAL AMOUNT</td><TD  ALIGN='RIGHT' STYLE="FONT-WEIGHT:BOLD;padding-left: 20px;"><%=transform(TOTALAMOUNT+fbrservice+SERVICECHARGES,'99999999999999.99')%></TD></tr>
                    <%if round(PRODUCTDISCOUNT+MEMBERDISCOUNT,2)<>0 %>
                    <tr ><td colspan="<%=cspan%>" align='right' STYLE="FONT-WEIGHT:BOLD;border-bottom-style: hidden;border-left-style: hidden;">DISCOUNT</td><TD  ALIGN='RIGHT' STYLE="FONT-WEIGHT:BOLD;padding-left: 20px;"><%=transform(PRODUCTDISCOUNT+MEMBERDISCOUNT,'99999999999999.99')%></TD></tr>
                    <tr ><td colspan="<%=cspan%>" align='right' STYLE="FONT-WEIGHT:BOLD;border-bottom-style: hidden;border-left-style: hidden;">NET AMOUNT</td><TD  ALIGN='RIGHT' STYLE="FONT-WEIGHT:BOLD;padding-left: 20px;"><%=transform(TOTALAMOUNT+fbrservice+SERVICECHARGES-PRODUCTDISCOUNT-MEMBERDISCOUNT,'99999999999999.99')%></TD></tr>
                   <%endif%>
                </table>
                </td>
                </tr>


                <tr>
        <%if not empty(openingbalance)%>
        
            <table align="center" STYLE="FONT-WEIGHT:BOLD;FONT-STYLE" border="0px" width="AUTO">
                <tr>
                    <td align="left" STYLE="FONT-WEIGHT:BOLD;FONT-STYLE">Opening</td><td align="right"><<nvl(opening.dayopening,0.00)>></td>
                </tr>
                <%if not empty(nvl(closing.debits,0))%>
                <tr>
                    <td align="left" STYLE="FONT-WEIGHT:BOLD;FONT-STYLE">Add Debits</td><td align="right"><<closing.debits>></td>
                    
                </tr>
                <%endif%>
                <%if not empty(nvl(closing.Credits,0))%>
                <tr>
                    <td align="left" STYLE="FONT-WEIGHT:BOLD;FONT-STYLE">Less Credits</td><td align="right"><<closing.Credits>></td>
                </tr>
                <%endif%>
                <tr>
                    <td align="left" STYLE="FONT-WEIGHT:BOLD;FONT-STYLE">Closing Balance</td><td align="right"><<nvl(opening.dayopening,0)+nvl(closing.debits,0)-nvl(closing.credits,0)>></td>
                </tr>
                <tr><td colspan='2' style="text-align:center;"><img src="images/receiptbarcode.bmp" width="96px"/></td></tr>
            </table>
        <%endif%>
                </tr>
                
            </table>
           
            <DIV>
            <%
            LASTMESSAGE=[]
                IF NOT EMPTY(XCOMPANY.CUSTMSG1)
                    LASTMESSAGE=LASTMESSAGE+ALLT(XCOMPANY.CUSTMSG1)+[ ]
                ENDIF
                IF NOT EMPTY(XCOMPANY.CUSTMSG2)
                    LASTMESSAGE=LASTMESSAGE+ALLT(XCOMPANY.CUSTMSG2)+[ ]
                ENDIF
                IF NOT EMPTY(XCOMPANY.CUSTMSG3)
                    LASTMESSAGE=LASTMESSAGE+ALLT(XCOMPANY.CUSTMSG3)+[ ]
                ENDIF
                IF NOT EMPTY(XCOMPANY.CUSTMSG4)
                    LASTMESSAGE=LASTMESSAGE+ALLT(XCOMPANY.CUSTMSG4)+[ ]
                ENDIF
            %>
            <P STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC"><%='OPERATOR '+ALLT(theuser)+' '+IIF(EMPTY(REPT_SALEMAN),'','SOLD BY: '+REPT_SALEMAN)%></P>
            <%if NOT EMPTY(LASTMESSAGE) %>
                <P STYLE="FONT-WEIGHT:BOLD;FONT-STYLE:ITALIC"><%=LASTMESSAGE%></P>
            <%endif%>
            
        </DIV>
</div>

</body>
</html>
<%
CLOSE TABLES 
CLOSE DATABASES
USE IN SELECT(uniquealias)
clear resources 
%>