<style type="text/css">
::-webkit-scrollbar {
    display: none;
}
#dynamic-content-container{background: #fff;}
    .navbar-default.navbar-static-side{display: none !important;}
    #page-wrapper{margin: 0px !important; padding: 0 !important;}
    .row.border-bottom{display: none !important;}
    .footer.fixed{display: none;}
    .ibox-content{padding: 4px !important;}
    body {
    -webkit-print-color-adjust:exact;
    background: #fff;
    padding: 4px;
    }
    .table > thead > tr > th, .table > tbody > tr > th, .table > tfoot > tr > th, .table > thead > tr > td, .table > tbody > tr > td, .table > tfoot > tr > td {
        border-top: 1px dashed black !important;
    }
    td,th{padding: 5px !important; font-weight: 700 !important; color: black !important;}
    @media print {
        .cancel-btn{display: none !important;}    
    }
    

</style>



<table style="width: 100%; background: #fff;">
    <tr>
        <td><img style="width: 100%; height: 200px;" src="<?= get_branch_image('bookings'); ?>"></td>
    </tr>
</table>

<table style="width: 100%; background: #fff; border-bottom: 3px solid black !important;">
    <tr>
        <td><strong><?= strtoupper(print_lang($app_lang,'mod_bookings_inv_date')); ?>:&nbsp;&nbsp;<?= date("y-m-d h:i:s a");?> / <?= get_persian_date(date('Y-m-d')).' '.date('h:i:s a'); ?></strong></td>
        <td <?php if($app_direction == 'rtl'){echo 'style="text-align: right;"';}else{echo 'style="text-align: right;"';}?>><strong><?= strtoupper(print_lang($app_lang,'mod_bookings_inv_exp_date')); ?>:&nbsp;&nbsp;<?= $invoice_data['expected_date'];?> / <?= get_persian_date($invoice_data['expected_date']); ?></strong></td>
    </tr>
</table>

<?php
$date = date_create($invoice_data['created_at']);
$date = date_format($date,"Y-m-d h:i:s");
$currency_symbol = array_key_exists($invoice_data['currency'], $currencies) ? $currencies[$invoice_data['currency']]['symbol'] : NULL;
$currency_name = array_key_exists($invoice_data['currency'], $currencies) ? $currencies[$invoice_data['currency']]['name'] : NULL;

$client_data = fetch_table_where('accounts','uid',$invoice_data['customer'],true);
$client_name = $client_data['name'];
$client_mobile = $client_data['mobile'];

?>





<table style="width: 100%; margin: 5px 0px; background: #fff; border-bottom: 3px solid black !important;">
    <tr style="height: 20px;">
        <td>
            <strong><?= strtoupper(print_lang($app_lang,'mod_bookings_inv_customer')); ?>:</strong>&nbsp;&nbsp;<strong><?= $client_name; ?></strong>
        </td>
        <td <?php if($app_direction == 'rtl'){echo 'style="text-align: right; width: 150px;"';}else{echo 'style="text-align: right;"';}?>>
            <strong style="font-size: 13px;"><span><?= strtoupper(print_lang($app_lang,'mod_bookings_inv_bill_num')); ?>:</span> &nbsp;&nbsp;</strong><span><strong><?= $invoice_data['invoice']; ?></strong></span>
        </td>
    </tr>
    <tr style="height: 20px;">
        <td>
            <strong><?= strtoupper(print_lang($app_lang,'mod_bookings_inv_phone')); ?>:</strong>&nbsp;&nbsp;<strong><?= $client_mobile; ?></strong>
        </td>
        <td <?php if($app_direction == 'rtl'){echo 'style="text-align: right; width: 150px;"';}else{echo 'style="text-align: right;"';}?>>
            <strong style="font-size: 13px;"><span><?= strtoupper(print_lang($app_lang,'mod_bookings_inv_currency')); ?>:</span> &nbsp;&nbsp;</strong><span><strong><?= $currency_name; ?></strong></span>
        </td>
    </tr>
    <tr style="height: 20px;">
        <td colspan="2">
            <strong><?= strtoupper(print_lang($app_lang,'mod_bookings_inv_memo')); ?>:</strong>&nbsp;&nbsp;<strong><?= ucfirst($invoice_data['memo']); ?></strong>
        </td>
    </tr>
</table>


<table class="table table-striped" style="width: 100%; margin: 0; background: #fff;">
    <thead>
        <tr style="border-top: 2px solid black !important; border-bottom: 2px solid black !important;">
            <th style="width: 5%;"><?= ucfirst(print_lang($app_lang,'mod_bookings_inv_thead_num')); ?></th>
            <th style="width: 20%;"><?= ucfirst(print_lang($app_lang,'mod_bookings_inv_thead_item')); ?></th>
            <th style="width: 8%;"><?= ucfirst(print_lang($app_lang,'mod_bookings_inv_thead_qty')); ?></th>
            <th style="width: 15%;"><?= ucfirst(print_lang($app_lang,'mod_bookings_inv_thead_qty_p')); ?></th>
            <th style="width: 8%;"><?= ucfirst(print_lang($app_lang,'mod_bookings_inv_thead_tp')); ?></th>
            <th style="width: 10%;"><?= ucfirst(print_lang($app_lang,'mod_bookings_inv_thead_total')); ?></th>
            <th style="width: 18%;"><?= ucfirst(print_lang($app_lang,'mod_bookings_inv_thead_total_process')); ?></th>
            <th style="width: 18%;"><?= ucfirst(print_lang($app_lang,'mod_bookings_inv_thead_memo')); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php
        $i = 1;
        $branch_id = active_branch_id();
        $details = json_decode($invoice_data['items_processed'],true);
        $total_qty = array();
        $total_qty_p = array();
        $total_tp = array();
        $grand_total = array();
        $grand_total_p = array();
        foreach($details as $row){
            $item_data = fetch_table_where('items','uid',$row['item'],true);
            $item_name = $item_data['name'];            
        ?>
            <tr>
                <td><?= $i++; ?></td>
                <td><?= ucfirst($item_name); ?></td>
                <td><?= (float)$row['qty']; $total_qty[] = (float)$row['qty']; ?></td>
                <td><?= (float)$row['qty_p']; $total_qty_p[] = (float)$row['qty_p']; ?></td>
                <td><?= (float)$row['tp']; $total_tp[] = (float)$row['tp']; ?></td>
                <td><?= (float)$row['total']; $grand_total[] = (float)$row['total']; ?></td>
                <td><?= (float)$row['total_p']; $grand_total_p[] = (float)$row['total_p']; ?></td>
                <td><?= $row['memo']; ?></td>
            </tr>
        <?php } ?>
            <tr>
                <td></td>
                <td><strong style="font-size: 15px !important;"><?= ucfirst(print_lang($app_lang,'mod_bookings_inv_grand_total')); ?></td>
                <td><strong style="font-size: 15px !important;"><?= amount_number_format(array_sum($total_qty)); ?></strong></td>
                <td><strong style="font-size: 15px !important;"><?= amount_number_format(array_sum($total_qty_p)); ?></strong></td>
                <td><strong style="font-size: 15px !important;"><?= amount_number_format(array_sum($total_tp)); ?></strong></td>
                <td><strong style="font-size: 15px !important;"><?= amount_number_format(array_sum($grand_total)); ?></strong></td>
                <td><strong style="font-size: 15px !important;"><?= amount_number_format(array_sum($grand_total_p)); ?></strong></td>
                <td><strong style="font-size: 15px !important;"></td>
            </tr>
    </tbody>
</table>
<?php if(is_customer_user() === FALSE){?>
<a href="<?= url('/orders'); ?>?status=processed" style="margin-top: 30px;" class="btn btn-danger cancel-btn">Cancel</a>
<?php } ?>