<?php
    global $gAr;
    foreach($gAr as $k=>$v){${$k}=$v;}
?>
<div id="details_top">
    <table class="table table-borderd">
        <tr><td>Invoice No</td><td><?=$sale['invoice_no']?></td></tr>
        <tr><td>Date</td><td><?=$sale['date']?></td></tr>
        <tr><td>Csustomer</td><td><?=$sale['customer']?></td></tr>
        <tr><td>Due Date</td><td><?=$sale['collection_date']?></td></tr>
        <tr><td>Remarks</td><td><?=$sale['note']?></td></tr>

    </table>
</div>   
<table class="table table-borderd">
    <thead>
        <tr>
            <td>#</td>
            <td>Product</td>
            <td>Unit</td>
            <td class="amount_td">Unit Price</td>
            <td class="amount_td">Quantity</td>
            <td class="amount_td">Sub Total</td>
        </tr>
    </thead>
    <tbody class="details_products">
        <?php
            $serial=1;
            foreach($product_details as $po){ 
            ?>
            <tr>
                <td><?=$serial++?></td>
                <td><?=$po['product']?></td>
                <td><?=$po['unit']?></td>
                <td class="amount_td"><?=$po['unit_price']?></td>
                <td class="amount_td"><?=$po['sale_qty']?></td>
                <td class="amount_td"><?=$po['total']?></td>
            </tr>

            <?php 
            }
        ?>
    </tbody>
    <tfoot>
        <tr><td colspan="5">Subtotal</td><td class="amount_td"><b><?=$sale['sub_total']?></b></td></tr>
        <tr><td colspan="5">Discount</td><td class="amount_td"><?=$sale['discount']?></td></tr>
        <tr><td colspan="5">Total</td><td class="amount_td"><b><?=$sale['total']?></td></b></tr>
    </tfoot>
</table>

<h4>Truk</h4>
<table class="table table-borderd">
    <thead>
        <tr>
            <td>#</td>
            <td>Pay by</td>
            <td>Truk</td>
            <td class="amount_td">Rent</td>
        </tr>
    </thead>
    <tbody>
        <?php
        $serial=1;
            foreach($truk as $t){
                ?>
                <tr>
                <td><?=$serial++?></td>
                    <td><?=$t['pay_by']?></td>
                    <td><?=$t['truk']?></td>
                    <td class="amount_td"><?=$t['rent']?></td>
                </tr>
                <?php
            }
        ?>
    </tbody>
</table>
<h4>Additional expense</h4>
<table class="table table-borderd">
    <thead>
        <tr>
            <td>#</td>
            <td>Title</td>
            <td>Pay by</td>
            <td>Truk</td>
            <td class="amount_td">Amount</td>
        </tr>
    </thead>
    <tbody>
        <?php
        $serial=1;
            foreach($ade as $t){
                ?>
                <tr>
                    <td><?=$serial++?></td>
                    <td><?=$t['title']?></td>
                    <td><?=$t['pay_by']?></td>
                    <td><?=$t['truk']?></td>
                    <td class="amount_td"><?=$t['amount']?></td>
                </tr>
                <?php
            }
        ?>
    </tbody>
</table>

<?php
$due_data=[];

if(isset($sale_data['customer_due_invoice'])){
    $due_data=$sale_data['customer_due_invoice'];
}
if(!empty($due_data)){
    
?>
<h4>Due list</h4>
<table class="table table-borderd">
    <thead>
        <tr>
            <td>SN</td>
            <td>Invoice Date</td>
            <td>Invoice No</td>
            <td>Sales Terms</td>
            <td class="amount_td">Dues</td>
            <td class="amount_td">Aging (Days)</td>
        </tr>
    </thead>
    <tbody class="details_products">
<?php
$serial=1;
foreach($due_data as $d){
?>
<tr>
    <td><?=$serial?></td>
    <td><?=date('d-m-y',$d['date'])?></td>
    <td><?=$d['invoice_no']?></td>
    <td><?=$d['pay_type']?></td>
    <td class="amount_td"><?=(float)$d['due']?></td>
    <td class="amount_td"><?=$d['aging']?></td>
</tr>
<?php
}
?>
    </tbody>
    </table>
<?php
}