<%
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')
pagetype=upper(orequest.querystring('pw'))
foraccount=upper(NVL(orequest.querystring('ac'),'NOTHING'))
*Pos Printer: 3 1/8" x 230' (approximately 80mm x 70m)
*Format	Width x Height (in mm)	Width x Height (in inches)
*A4	210 x 297	8.3 x 11.7
*A5	148 x 210	5.8 x 8.3
*A6	105 x 148	4.1 x 5.8
*A7	74 x 105	2.9 x 4.1
*<Option val="POS">POS Printer</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>
tpagewidth='210mm'
do CASE
    case pagetype=[LET]
        tpagewidth='210mm'
    case pagetype=[A4]
        tpagewidth='210mm'
    case pagetype=[A5]
        tpagewidth='148mm'
    case pagetype=[A6]
        tpagewidth='105mm'
    case pagetype=[POS]
        tpagewidth='80mm'
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, z.name as depositname ]
    tsql=tsql+[ from ("]+dbclocation+'transfer.dbf'+[") x left join ("]+dbclocation+'accounts.dbf'+[") y ]
    tsql=tsql+[ on (x.creditor=y.accountid) left join ("]+dbclocation+'accounts.dbf'+[") z ]
    tsql=tsql+[ on (x.debitor=z.accountid) ]
    tsql=tsql+[ 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, z.name as depositname ]
    tsql=tsql+[ from ("]+dbclocation+'transfer.dbf'+[") x left join ("]+dbclocation+'accounts.dbf'+[") y ]
    tsql=tsql+[ on (x.creditor=y.accountid) left join ("]+dbclocation+'accounts.dbf'+[") z ]
    tsql=tsql+[ on (x.debitor=z.accountid) order by vtr desc ]
    tsql=tsql+[ where allt(transid)==']+allt(m_transid)+[' into cursor xtmpcur]
endif

&tsql
SCATTER NAME SearchResults
thedate=SearchResults.date
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
hasopening=.f.
***
textofbalance=[]
strofbalance=[]
    if BETWEEN(val(left(searchresults.CREDITOR,2)),1,8) and left(searchresults.CREDITOR,3)<>[019] and (foraccount="WRAPPER" OR foraccount="CREDITOR") 
            select sum(debit) as debits, SUM(credit) as credits from (dbclocation+[acctran]) where ;
            accountid=searchresults.CREDITOR and date=Thedate INTO CURSOR closing
            select sum(debit-credit) as dayopening from (dbclocation+[acctran]) where ;
            accountid=searchresults.CREDITOR and date>Thedate INTO CURSOR opening
            select sum(debit-credit) as allclosing from (dbclocation+[acctran]) where ;
            accountid=searchresults.CREDITOR INTO CURSOR allclosing
        if nvl(allclosing.allclosing,0)<>0 or nvl(opening.dayopening,0)+closing.debits+closing.credits<>0
            hasopening=.t.
            textofbalance=textofbalance+[<tr><td colspan="2" align="left" style="font-weight: bold;">]+searchresults.acname+[</td></tr>]
            textofbalance=textofbalance+[<tr><td>Opening Balance</td><td align="right">]+allt(transform(nvl(opening.dayopening,0),'99999999999.99'))+[</td></tr>]
            textofbalance=textofbalance+[<tr><td>Add Debits</td><td align="right">]+allt(transform(closing.debits,'99999999999.99'))+[</td></tr>]
            textofbalance=textofbalance+[<tr><td>Les Credits</td><td align="right">]+allt(transform(closing.credits,'99999999999.99'))+[</td></tr>]
            textofbalance=textofbalance+[<tr><td>Balance on ]+transform(thedatestring)+[</td><td align="right">]+allt(transform(nvl(opening.dayopening,0)+closing.debits+closing.credits,'99999999999.99'))+[</td></tr>]
            if nvl(allclosing.allclosing,0)<>0 and empty(xcompany.hideopbill)
                textofbalance=textofbalance+[<tr><td>OVERALL CLOSING BALANCE</td><td align="right">]+allt(transform(nvl(allclosing.allclosing,0.00)+closing.debits+closing.credits,'99999999999.99'))+[</td></tr>]
                strofbalance=strofbalance+searchresults.acname+crlf 
                strofbalance=strofbalance+[Opening: ]+allt(transform(nvl(opening.dayopening,0),'99999999999.99'))+crlf 
                strofbalance=strofbalance+[Add Debits: ]+allt(transform(closing.debits,'99999999999.99'))+crlf 
                strofbalance=strofbalance+[Less Credits: ]+allt(transform(closing.debits,'99999999999.99'))+crlf 
                if nvl(opening.dayopening,0)+closing.debits+closing.credits<>0
                    strofbalance=strofbalance+[Balance on ]+transform(thedatestring)+[: ]+;
                    allt(transform(nvl(opening.dayopening,0)+closing.debits+closing.credits,'99999999999.99'))+crlf 
                endif 
                strofbalance=strofbalance+[OVerall Closing: ]+allt(transform(nvl(allclosing.allclosing,0.00),'99999999999.99'))+crlf 
            endif
        endif
    ENDIF
    if BETWEEN(val(left(searchresults.debitor,2)),1,8) and left(searchresults.debitor,3)<>[019] and (foraccount="WRAPPER" OR foraccount="DEBITOR")
            select sum(debit) as debits, SUM(credit) as credits from (dbclocation+[acctran]) where ;
            accountid=searchresults.debitor and date=Thedate INTO CURSOR cclosing
    
            select sum(debit-credit) as dayopening from (dbclocation+[acctran]) where ;
            accountid=searchresults.debitor and date>Thedate INTO CURSOR copening
        
            select sum(debit-credit) as allclosing from (dbclocation+[acctran]) where ;
            accountid=searchresults.debitor  INTO CURSOR callclosing
            if nvl(callclosing.allclosing,0)<>0 or nvl(copening.dayopening,0)+cclosing.debits+cclosing.credits<>0
            hasopening=.t.
            textofbalance=textofbalance+[<tr><td colspan="2" align="left" style="font-weight: bold;">]+searchresults.DEPOSITNAME+[</td></tr>]
            textofbalance=textofbalance+[<tr><td>Opening Balance</td><td align="right">]+allt(transform(nvl(copening.dayopening,0),'99999999999.99'))+[</td></tr>]
            textofbalance=textofbalance+[<tr><td>Add Debits</td><td align="right">]+allt(transform(cclosing.debits,'99999999999.99'))+[</td></tr>]
            textofbalance=textofbalance+[<tr><td>Les Credits</td><td align="right">]+allt(transform(cclosing.credits,'99999999999.99'))+[</td></tr>]
            textofbalance=textofbalance+[<tr><td>Balance on ]+transform(thedatestring)+[</td><td align="right">]+allt(transform(nvl(copening.dayopening,0)+cclosing.debits+cclosing.credits,'99999999999.99'))+[</td></tr>]
            if nvl(callclosing.allclosing,0)<>0 and empty(xcompany.hideopbill)
            textofbalance=textofbalance+[<tr><td>OVERALL CLOSING BALANCE</td><td align="right">]+allt(transform(nvl(callclosing.allclosing,0.00)+cclosing.debits+cclosing.credits,'99999999999.99'))+[</td></tr>]
            strofbalance=strofbalance+searchresults.DEPOSITNAME+crlf 
            strofbalance=strofbalance+[Opening: ]+allt(transform(nvl(copening.dayopening,0),'99999999999.99'))+crlf 
            strofbalance=strofbalance+[Add Debits: ]+allt(transform(cclosing.debits,'99999999999.99'))+crlf 
            strofbalance=strofbalance+[Less Credits: ]+allt(transform(cclosing.debits,'99999999999.99'))+crlf 
            if nvl(copening.dayopening,0)+cclosing.debits+cclosing.credits<>0
                strofbalance=strofbalance+[Balance on ]+transform(thedatestring)+[: ]+;
                allt(transform(nvl(copening.dayopening,0)+cclosing.debits+cclosing.credits,'99999999999.99'))+crlf 
            endif 
            strofbalance=strofbalance+[OVerall Closing: ]+allt(transform(nvl(callclosing.allclosing,0.00),'99999999999.99'))+crlf
            endif
        endif 
    ENDIF
    ***



*****
if not empty(strofbalance)
    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 = strofbalance
      ERASE (tfile)
      m.lcQRImage = loFbc.FullQRCodeImage(lcString, tfile  , 32*4)
      m.loFbc=.null.
endif
*****
USE (dbclocation+[accounts]) IN SELECT([accounts])
=SEEK(SearchResults.creditor,[accounts],[accountid])
ccreditor=[<option value=']+accounts.accountid+[' selected>]+ALLTRIM(accounts.name)+[</option>]
=SEEK(SearchResults.debitor,[accounts],[accountid])
cdebitor=[<option value=']+accounts.accountid+[' selected>]+ALLTRIM(accounts.name)+[</option>]
invnum=searchresults.transid
*************
    *=changeFieldStruc()
*************
%>
<!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;
           
       }
        @media print {
            .printnoshow {
                display: none;
            }
        }
        #companytitle {
            width: 100%;
            margin: 4px 0 2px 0;
            font-family: Arial, Helvetica, sans-serif;
            font-size: 16px;
            font-weight: bold;
        }
        
        #companyadd {
            width: 100%;
            font-family: "Calibri", sans-serif, Arial, Helvetica;
            font-size: 12px;
        }
        .bold{
            font-weight: bold;
        }
        #agtinfo {
            width: 100%;
            height: 26px;
            background: #666;
            color: #FFF;
            text-align: center;
            line-height: 26px;
            margin-bottom: 6px;
            border-color: black;
            border-style: solid;
            border-width: 2px;
            font-family: "Calibri", sans-serif, Arial, Helvetica;
            font-size: 14px;
            font-weight: bold;
        }
        @media screen {
            .screennoshow {
                display: none;
            }
        }

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

        #wrapper {
            width: <<tpagewidth>>;
            text-align: center;
            margin: auto;
            border: 2mm ridge rgba(211, 220, 50, .6);
        }
       
        @media print{
            #wrapper {
            border: none;
        } 
        }
        @page {
         size: 8.5in 11in;  /* width height */
      }
    h1, p, table {
        margin:auto;
    }
    TD{
        font-size: 10PT;
    }
    </style>
</head>
<body onload="window.print();">
<div id='wrapper'>
 <%if pagetype=[POS]%>
    <%= include("poshead.html")%>
 <%endif%>
 <%if pagetype=[A4]%>
    <%= include("A4head.html")%>
 <%endif%>      
 <%if pagetype=[A5]%>
    <%= include("p5head.html")%>
 <%endif%>      
 <%if pagetype=[LE]%>
    <%= include("A4head.html")%>
 <%endif%>

 <%if not empty(xcompany.fbrposid)%>
            <div id='fbrlogo' margin='auto' float='center'><img id='companymonogram' src="bootstrap/images/fbr.png" max-height='92pt' max-width='92pt' height='92pt'></div>
 <%endif%>
       
       <div margin="auto" id="agtinfo" float="center">Transfer Funds</div>
        <table align="center" border="0px" width="100%">
            <tr>
                <td align="left" class="bold">Transfer#: <<searchresults.transid>></td><td align="right" class="bold">Date: <<searchresults.date>></td>
            </tr>
            </table>
            
              <table align="center" border="1px" width="100%" style="border-collapse: collapse;">
                <tr>
                    <td class="bold">Received</td><td colspan="3"><<xcompany.currency>> <<iif(searchresults.amount<>int(searchresults.amount),round(searchresults.amount,2),round(searchresults.amount,0))>> (<<num2word(searchresults.amount)>>)</td>
                </tr>                
                <tr>
                    <td class="bold">From</td><td colspan="3">AC: <<searchresults.creditor>> Name <<searchresults.acname>></td>
                </tr>
                <tr>
                    <td class="bold">Transfered To</td><td colspan="3">AC: <<searchresults.debitor>> Name <<searchresults.depositname>></td>
                </tr>
                              
                <%if not empty(searchresults.memo) %>
                <tr>
                    <td class="bold">details</td><td colspan="3"><<searchresults.memo>></td>
                </tr>
                <%endif%>

              </table>  
                       
        <%if not empty(hasopening)%>
            <table align="center" border="0px" width="AUTO">
                    <%=textofbalance%>            
            </table>
            <%if not empty(strofbalance)%>
            <div id='qrcode' style="padding:4px"><img src="images/receiptbarcode.bmp" /></div>
            <%endif%>
        <%endif%>

</div>

</body>
</html>