<?php
    echo '<div>'
. '<table style="font-size:12px;"><tr><td><div style="padding:0px;margin:0px;"><b>CUSTOMER:</b>'
            . '';
    if($receipt) {
        $customer = $receipt[0]->CUSTOMER;
    }
    echo '<div style="font-weight:bold;margin:0px;">';
    if ($customer != '') {
        echo "&nbsp;&nbsp;&nbsp;&nbsp;".$receipt[0]->CUSTOMER.'<br/>';
    }
    if ($receipt[0]->ADDRESS != '') {
        echo "&nbsp;&nbsp;&nbsp;&nbsp;".$receipt[0]->ADDRESS.'<br/>';
    }   
    if ($receipt[0]->CITY != '') {
        echo "&nbsp;&nbsp;&nbsp;&nbsp;".$receipt[0]->CITY.'<br/>';
    }   
    if ($receipt[0]->REGION != '') {
        echo "&nbsp;&nbsp;&nbsp;&nbsp;".$receipt[0]->REGION.'<br/>';
    }    
    if ($receipt[0]->COUNTRY != '') {
        echo "&nbsp;&nbsp;&nbsp;&nbsp;".$receipt[0]->COUNTRY.'<br/>';
    }    
    if ($receipt[0]->EMAIL != '') {
        echo "&nbsp;&nbsp;&nbsp;&nbsp;".$receipt[0]->EMAIL.'<br/>';
    }
    if ($receipt[0]->PHONE != '') {
        echo "&nbsp;&nbsp;&nbsp;&nbsp;".$receipt[0]->PHONE;
    }
    if ($receipt[0]->TAXID != '') {
        echo "&nbsp;&nbsp;&nbsp;&nbsp;TaxID: ".$receipt[0]->TAXID.'<br/>';
    }
    echo '</div>';
    echo '</div></td><td><table style="margin:0 0 0 0; text-align:left;border-collapse:collapse;font-size:12px;">';
    echo '<tbody>';
    if(isset($receipt)){
        if($receipt) {
            if ($receipt[0]->TICKETTYPE == 0) {
                echo '<tr><td align="left" width="100">Receipt#: </td><td align="left">', $receipt[0]->TICKETID, '</td></tr>';
            } else {
                echo '<tr><td >Refund: </td><td align="left">', $receipt[0]->TICKETID, '</td></tr>';
            }
            echo '<tr><td >Date: </td><td align="left">', $receipt[0]->DATENEW, '</td></tr>';
            if(isset($receipt) && $receipt){
                if(isset($receipt[0]->CASHIER)) {
                    echo '<tr><td align="left">Cashier: </td>'
                            . '<td align="left">', $receipt[0]->CASHIER, '</td></tr>';
                }
                if(isset($station)) {
                    echo '<tr><td align="left">Station: </td><td align="left">', $station, '</td></tr>';
                }
            }
            $xml = simplexml_load_string($receipt[0]->ATTRIBUTES);
            if($xml!=null)
                                            {
            foreach ($xml as $key0 => $value) {
                foreach ($value->attributes() as $attributeskey0 => $attributesvalue1) {
                    if ($attributesvalue1 == "Place") {
                        echo '<tr>
                            <td >Table:</td><td align="left">', $value, '</td>
                            </tr>';
                    } else if ($attributesvalue1 == "TariffArea") {
                        echo '<tr>
                            <td >Tariff:</td><td align="left">', $value, '</td>
                            </tr>';
                    } else if ($attributesvalue1 == "Host") {
                        $station = $value;
                    }
                }
            }
                                            }
        }
    }
    echo "</tbody>";
    echo "</table></td></tr></table>";
    echo '<div style="width:100%;"><table id="receipt" style="text-align:left;border-collapse:collapse;padding: 5 5 5 5;font-size:12px;width:100%;">';
    echo '<thead><tr>'
    . '<th scope="col" style="text-align: left;border-bottom:1px solid #aaaa;border-right:1px solid #aaaa;border-left:1px solid #aaaa;border-top:1px solid #aaaa;background-color:#d4d4d4;width:5%;"><b>#</b></th>'
    
    . '<th scope="col" style="text-align: left;border-bottom:1px solid #aaaa;border-right:1px solid #aaaa;border-left:1px solid #aaaa;border-top:1px solid #aaaa;background-color:#d4d4d4;width:40%;"><b>Item</b></th>'
        . '<th scope="col" align="center" style="text-align: right;border-bottom:1px solid #aaaa;border-right:1px solid #aaaa;background-color:#d4d4d4;border-left:1px solid #aaaa;border-top:1px solid #aaaa;width:10%;"><b>Qty</b></th>'
        . '<th scope="col" align="center" style="border-bottom:1px solid #aaaa;border-right:1px solid #aaaa;background-color:#d4d4d4;border-left:1px solid #aaaa;border-top:1px solid #aaaa;width:10%;"><b>Rate</b></th>'
            . '<th scope="col" align="center" style="border-bottom:1px solid #aaaa;border-right:1px solid #aaaa;background-color:#d4d4d4;border-left:1px solid #aaaa;border-top:1px solid #aaaa;width:10%;"><b>Amount</b></th>'
            . '<th scope="col" align="center" style="border-bottom:1px solid #aaaa;border-right:1px solid #aaaa;background-color:#d4d4d4;border-left:1px solid #aaaa;border-top:1px solid #aaaa;width:10%;"><b>Tax</b></th>'
            . '<th scope="col" align="center" style="text-align: right;border-bottom:1px solid #aaaa;background-color:#d4d4d4;border-left:1px solid #aaaa;border-top:1px solid #aaaa;border-right:1px solid #aaaa;width:15%;"><b>Total</b></th>'
        . "</tr></thead>";
    echo "<tbody>";
    if(isset($ticketlines)) {
        $sl=0;
        $lines=0;
        foreach ($ticketlines as &$value) {
         $sl++;  
         $lines++;  
            echo '<tr>'
            . '<td height="20" align="left" style="border-left:1px solid #aaaa; border-right:1px solid #aaaa;border-bottom:1px solid #aaaa;width:5%;">', $sl, '</td>'
            . '<td height="20" style="text-align: left;border-right:1px solid #aaaa;'
            . 'border-bottom:1px solid #aaaa;width:40%;">';
//            echo $value->NAME;
            $xml = simplexml_load_string($value->ATTRIBUTES);
            if($xml) {
                foreach($xml->entry as $entryxml) {
                    if($entryxml->attributes()->key=='product.name') {
                        echo $entryxml;
                    }
                }
            }
            echo '</td>
                <td height="20" align="center" style="border-right:1px solid #aaaa;width:10%;border-bottom:1px solid #aaaa;">'. $value->UNITS.'</td>'
                    . '<td height="20" align="right" style="border-right:1px solid #aaaa;border-bottom:1px solid #aaaa;width:10%;">', $this->formatslist->formatCurrency($value->PRICE), '</td>
                <td height="20" align="right" style="border-right:1px solid #aaaa;border-bottom:1px solid #aaaa;width:10%;">', $this->formatslist->formatCurrency($value->PRICE * $value->UNITS), '</td>
                    <td height="20" align="right" style="border-right:1px solid #aaaa;border-bottom:1px solid #aaaa;width:10%;">', $this->formatslist->formatCurrency($value->PRICE * $value->UNITS * $value->RATE), '</td>
                <td height="20" align="right" style="border-right:1px solid #aaaa;width:15%;border-bottom:1px solid #aaaa;">', $this->formatslist->formatCurrencywithHash($value->UNITTOTAL), '</td>
                </tr>';
        }
        if($lines<15)
        {
            $blankLine=0;
            while($blankLine+$lines<15)
            {
                $blankLine++;
                echo '<tr>'
            . '<td height="20" align="left" style="border-left:1px solid #aaaa; border-right:1px solid #aaaa;border-bottom:1px solid #aaaa;width:5%;"></td>'
            . '<td height="20" style="text-align: left;border-right:1px solid #aaaa;'
            . 'border-bottom:1px solid #aaaa;width:40%;">';
//          
            echo '</td>
                <td height="20" align="center" style="border-right:1px solid #aaaa;width:10%;border-bottom:1px solid #aaaa;"></td>'
                    . '<td height="20" align="right" style="border-right:1px solid #aaaa;border-bottom:1px solid #aaaa;width:10%;"></td>
                <td height="20" align="right" style="border-right:1px solid #aaaa;border-bottom:1px solid #aaaa;width:10%;"></td>
                    <td height="20" align="right" style="border-right:1px solid #aaaa;border-bottom:1px solid #aaaa;width:10%;"></td>
                <td height="20" align="right" style="border-right:1px solid #aaaa;width:15%;border-bottom:1px solid #aaaa;"></td>
                </tr>';
            }
        }
        if(isset($receipt) && $receipt){
            echo '<tr>
                <td colspan="5"></td>
                <td align="right" style="border-right:1px solid #aaaa;border-left:1px solid #aaaa;border-bottom:1px solid #aaaa;">Tax </td>
                <td align="right" style="font-weight:bold;border-bottom:1px solid #aaaa;border-right:1px solid #aaaa;">', $this->formatslist->formatCurrencywithHash($receipt[0]->TAX), '</td>
                </tr>';
            echo '<tr>
                <td colspan="5"></td>
                <td align="right" style="font-weight:bold;border-right:1px solid #aaaa;border-left:1px solid #aaaa;border-bottom:1px solid #aaaa;">Total </td>
                <td align="right" style="font-weight:bold;border-bottom:1px solid #aaaa;border-right:1px solid #aaaa;">', $this->formatslist->formatCurrencywithHash($receipt[0]->TOTAL), '</td>
                </tr>';
        }
        
    }
    echo "</tbody>";
    echo "</table></div>";
    echo '<div style="width:100%;"><div style="font-size:13px;">PAYMENT DETAILS<br/></div><table '
    . 'style="font-size:12px;padding: 5 5 5 5;width:100%;">';
    if(isset($paymentlines)) {
        foreach ($paymentlines as &$value1) {
            
            if($value1->PAYMENT=="debt")
            {
              echo  '<tr><td style="text-align: left;width:50%;">'
                , 'Debt: '. $this->formatslist->formatCurrencywithHash($value1->PAYMENTTOTAL)
                , '<br/>Last Outstanding: '.$this->formatslist->formatCurrency($receipt[0]->CURDEBT-$value1->PAYMENTTOTAL) .
            '<br/>Total Outstanding: '.$this->formatslist->formatCurrency($receipt[0]->CURDEBT),
            '</td></tr>';
            }
            else
            {
            echo '<tr><td style="text-align: left;width:50%;">'
                , $value1->PAYMENT. ': '. $this->formatslist->formatCurrencywithHash($value1->PAYMENTTOTAL),
            '</td></tr>';
            }
        }
    }
    
    echo "</table></div>";
    
    echo '<div style="font-size:13px; ">BANK DETAILS</div>'
    . '<table style="padding:10px; font-size:12px;width:100%;">'
    .  '<tr><td style="text-align: left;width:100%; ">'
    . 'Bank Name:'
            . '<br/>Account Name:'
            . '<br/>Account No.:'
            . '<br/>Branch Name:'
            . '<br/>Swift Code:'
            . '</td></tr>';  
    echo "</table>";
 
    
    ?>