<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;}

</style>



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

    $date = date_create($invoice_data['created_at']);
    $date = date_format($date,"Y-m-d H:i:s");
    
?>

<?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;
if(strpos($invoice_data['client'],"CASHSALE") === FALSE)
{
    $client_name = array_key_exists($invoice_data['client'], $accounts) ? $accounts[$invoice_data['client']]['name'] : NULL;
    $client_mobile = array_key_exists($invoice_data['client'], $accounts) ? $accounts[$invoice_data['client']]['mobile'] : NULL;
}
else
{
    $client_name = $invoice_data['cash_client_name'];
    $client_mobile = $invoice_data['cash_client_mobile'];
}

?>

<table style="width: 100%;">
    <tr>
        <td style="color: #000 !important; width: 50%; padding-top: 0px !important; padding-bottom: 0px !important;"><?= print_lang($app_lang,'sales_invoice_4_thead_client'); ?>: <span><?= $client_name; ?></span> </td>
        <td style="color: #000 !important; width: 50%; padding-top: 0px !important; padding-bottom: 0px !important; <?php if($app_direction == 'rtl'){echo 'text-align: left;';}else{echo 'text-align: right;';}?>"><?= print_lang($app_lang,'sales_invoice_4_thead_invoice'); ?>: <span><?= $invoice_data['invoice']; ?></span></td>
    </tr>
    <tr>
        <td style="color: #000 !important; width: 50%; padding-top: 0px !important; padding-bottom: 0px !important;"><?= print_lang($app_lang,'sales_invoice_4_thead_date'); ?>: <span><?= $date; ?></span> </td>
        <td style="color: #000 !important; width: 50%; padding-top: 0px !important; padding-bottom: 0px !important; <?php if($app_direction == 'rtl'){echo 'text-align: left;';}else{echo 'text-align: right;';}?>"><?= print_lang($app_lang,'sales_invoice_4_thead_user'); ?>: <span><?= get_logged_user_data('name'); ?></span></td>
    </tr>
</table>
<table class="table table-bordered" style="width: 100%; margin: 0; background: #fff;">
    <thead>
        <tr>
            <th style="width: 5%; border: 3px solid #000 !important; font-size: 14px !important; background: #e0e8f7 !important;"><?= ucfirst(print_lang($app_lang,'sales_invoice_4_thead_sr')); ?></th>
            <th style="width: 65%; border: 3px solid #000 !important; font-size: 14px !important; background: #e0e8f7 !important;"><?= ucfirst(print_lang($app_lang,'sales_invoice_4_thead_details')); ?></th>
            <th style="width: 10%; border: 3px solid #000 !important; font-size: 14px !important; background: #e0e8f7 !important;"><?= ucfirst(print_lang($app_lang,'sales_invoice_4_thead_qty')); ?></th>
            <th style="width: 10%; border: 3px solid #000 !important; font-size: 14px !important; background: #e0e8f7 !important;"><?= ucfirst(print_lang($app_lang,'sales_invoice_4_thead_rate')); ?></th>
            <th style="width: 10%; border: 3px solid #000 !important; font-size: 14px !important; background: #e0e8f7 !important;"><?= ucfirst(print_lang($app_lang,'sales_invoice_4_thead_total')); ?></th>
        </tr>
    </thead>
    <tbody>
        <?php
        $sr = 1;
        $details = json_decode($invoice_data['items_details'],true);
        $total_qty = array();
        $total_rate = array();
        $grand_total = array();
        foreach($details as $row){
            $item_data = fetch_table_where('items','uid',$row['item'],true);
            if(strpos($row['item'],"MITNAME_") === FALSE)
            {
                $item_name = isset($item_data['name']) ? $item_data['name'] : NULL;
            }
            else
            {
                $item_name = ucfirst(str_replace('MITNAME_', '', $row['item']));
            }

            if($row['unit'] == 'production')
            {
                $item_unit_name = $item_data['production_unit_name'];
            }
            else if($row['unit'] == 'sale')
            {
                $item_unit_name = $item_data['sale_unit_name'];
            }
            else
            {
                $item_unit_name = $item_data['purchase_unit_name'];
            }
        ?>
            <tr>
                <td style="border: 3px solid #000 !important; background: #e0e8f7 !important;"><?= $sr++; ?></td>
                <td style="border: 3px solid #000 !important;"><?= ucfirst($item_name); ?></td>
                <td style="border: 3px solid #000 !important;"><?= amount_number_format_0($row['qty']).' '.$item_unit_name; $total_qty[] = $row['qty']; ?></td>
                <td style="border: 3px solid #000 !important;"><?= $currency_symbol.' '.amount_number_format_0($row['sale_price']); $total_rate[] = $row['sale_price']; ?></td>
                <td style="border: 3px solid #000 !important;"><?= $currency_symbol.' '.amount_number_format_0($row['item_total']); $grand_total[] = $row['item_total']; ?></td>
            </tr>
        <?php } ?>
            <tr>
                <td colspan="2" rowspan="3" style="font-size: 14px !important; border: 3px solid #000 !important;"><?= $invoice_data['memo']; ?></td>
                <td colspan="2" style="font-size: 14px !important; border: 3px solid #000 !important; background: #e0e8f7 !important;"><?= ucfirst(print_lang($app_lang,'sales_invoice_4_thead_grand_total')); ?></td>
                <td style="font-size: 14px !important; border: 3px solid #000 !important; background: #cbddff !important;"><?= $currency_symbol.' '.amount_number_format_0($invoice_data['sales_total']); ?></td>
            </tr>
            <tr>
                <td colspan="2" style="font-size: 14px !important; border: 3px solid #000 !important; background: #e0e8f7 !important;"><?= ucfirst(print_lang($app_lang,'sales_invoice_4_thead_paid')); ?></td>
                <td style="font-size: 14px !important; border: 3px solid #000 !important; background: #cbddff !important;"><?= $currency_symbol.' '.amount_number_format_0($invoice_data['cash_received']); ?></td>
            </tr>
            <tr>
                <td colspan="2" style="font-size: 14px !important; border: 3px solid #000 !important; background: #e0e8f7 !important;"><?= ucfirst(print_lang($app_lang,'sales_invoice_4_thead_pending')); ?></td>
                <td style="font-size: 14px !important; border: 3px solid #000 !important; background: #cbddff !important;"><?= $currency_symbol.' '.amount_number_format_0($invoice_data['remaining_amount']); ?></td>
            </tr>
            <tr>
                <td colspan="5" <?php if($app_direction == 'rtl'){echo 'style="text-align: right; font-size: 9px; color: #928e8e;"';}else{echo 'style="text-align: left; font-size: 9px; color: #928e8e;"';}?>><strong>ALPHA SOFTWARE | 0700573290 | Development By En Sudais Noori</strong></td>
            </tr>
    </tbody>
</table>