<style type="text/css">
#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: 0 !important;}
    body {
    -webkit-print-color-adjust:exact;
    background: #fff;
    }

</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");
$client_name = array_key_exists($invoice_data['client'], $clients) ? $clients[$invoice_data['client']]['name'] : NULL;
?>

<!-- ------------------------------------------------------------------------------------------------------------- -->
<table style="width: 100%; margin: 10px 0px; background: #fff;">
    <tr style="margin: 10px 0px;">
        <td style="width: 25%;"><span style="color: #bb0d0d !important; padding: 4px;"><strong style="color: #bb0d0d !important;"><?= print_lang($app_lang,'date'); ?>:</strong></span> <?= display_true_date($date); ?></td>
        <td style="width: 25%;"><span style="color: #bb0d0d !important; padding: 4px;"><strong style="color: #bb0d0d !important;"><?= print_lang($app_lang,'user'); ?>:</strong></span> <?= get_logged_user_data('name'); ?></td>
        <td style="width: 25%;"><span style="color: #bb0d0d !important; padding: 4px;"><strong style="color: #bb0d0d !important;"><?= print_lang($app_lang,'client'); ?>:</strong></span> <?= $client_name; ?></td>
        <td style="width: 16%; background: #bb0d0d !important; color: #fff!important; border-radius: 0px 15px 0px 15px !important; padding: 7px 0px; text-align: center;"><strong><span style="color: #fff !important; font-size: 15px;"><?= print_lang($app_lang,'invoice'); ?>:</span><span style="color: #fff !important;"> <?= $invoice_data['invoice']; ?></span></strong></td>
    </tr>
</table>
<!-- ------------------------------------------------------------------------------------------------------------- -->


<?php

// initialise totals vars
$total_total_amount = array();
$total_cash_paid = array();

?>


<!-- ------------------------------------------------------------------------------------------------------------- -->
<table style="width: 100%; background: #fff;">
    <!-- Table Heead with red backgorund -->
    <tr style="border: 1px solid #ccc;">
        <th style="font-size: 19px; border: 1px solid #ccc; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 5%;">#</th>
        <th style="font-size: 19px; border: 1px solid #ccc; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 20%;"><?= strtoupper(print_lang($app_lang,'fuel_type')); ?></th>
        <th style="font-size: 19px; border: 1px solid #ccc; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 15%;"><?= strtoupper(print_lang($app_lang,'driver')); ?></th>
        <th style="font-size: 19px; border: 1px solid #ccc; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'plate_num')); ?></th>
        <th style="font-size: 19px; border: 1px solid #ccc; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'cmr')); ?></th>
        <th style="font-size: 19px; border: 1px solid #ccc; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'saqlat')); ?></th>
        <th style="font-size: 19px; border: 1px solid #ccc; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'weight')); ?></th>
        <th style="font-size: 19px; border: 1px solid #ccc; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'gross_weight')); ?></th>
        <th style="font-size: 19px; border: 1px solid #ccc; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'price')); ?></th>
        <th style="font-size: 19px; border: 1px solid #ccc; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'total')); ?></th>
    </tr>
    <!-- Table Heead with red backgorund -->

    <?php
        $isn = 1;
        foreach($invoice_sales as $row)
        {

            // fetch sold lot data
            if(!array_key_exists($row['parent'], $lots)){ continue; }

            $lot_p_data = $lots[$row['parent']];

            if($lot_p_data['purchase_type'] == 'iran_to_border')
            {
                $lot_c_data = json_decode($lot_p_data['division_list'],true);
            }
            else
            {
                $lot_c_data = json_decode($lot_p_data['lot_list'],true);
            }

            $sold_lot_data = array();
            $sold_lot_data_found = false;
            foreach($lot_c_data as $c_row)
            {
                if($row['child'] == $c_row['uid'])
                {
                    $sold_lot_data = $c_row;
                    $sold_lot_data_found = true;
                }
            }

            // if data not found | skip row
            if($sold_lot_data_found === false){ continue; }

            // send in  totals
            $total_total_amount[] = $row['total'];
            $total_cash_paid[] = $row['cash'];

            if(!empty($row['saqlat']) AND $row['saqlat'] != 0)
            {
                $row['weight'] = $row['weight'] / $row['saqlat'];
                $row['gross_weight'] = $row['gross_weight'] / $row['saqlat'];
            }
    ?>
        <!-- items details body -->
        <tr>
            <td style="color: black !important; border: 1px solid #ccc; padding: 5px; text-align: center; width: 5%;"><?= $isn++; ?></td>
            <td style="color: black !important; border: 1px solid #ccc; padding: 5px; text-align: center; width: 20%;"><?= isset($sold_lot_data['fuel_type']) ? $sold_lot_data['fuel_type'] : NULL; ?></td>
            <td style="color: black !important; border: 1px solid #ccc; padding: 5px; text-align: center; width: 15%;"><?= $sold_lot_data['driver']; ?></td>
            <td style="color: black !important; border: 1px solid #ccc; padding: 5px; text-align: center; width: 10%;"><?= $sold_lot_data['plate']; ?></td>
            <td style="color: black !important; border: 1px solid #ccc; padding: 5px; text-align: center; width: 10%;"><?= $sold_lot_data['cmr']; ?></td>
            <td style="color: black !important; border: 1px solid #ccc; padding: 5px; text-align: center; width: 10%;"><?= $row['saqlat']; ?></td>
            <td style="color: black !important; border: 1px solid #ccc; padding: 5px; text-align: center; width: 10%;"><?= amount_number_format_3($row['weight']); ?></td>
            <td style="color: black !important; border: 1px solid #ccc; padding: 5px; text-align: center; width: 10%;"><?= amount_number_format_3($row['gross_weight']); ?></td>
            <td style="color: black !important; border: 1px solid #ccc; padding: 5px; text-align: center; width: 10%;"><?= array_key_exists($row['currency'], $currencies) ? $currencies[$row['currency']]['symbol'] : NULL; ?> <?= amount_number_format_3($row['sale_price']); ?></td>
            <td style="color: black !important; border: 1px solid #ccc; padding: 5px; text-align: center; width: 10%;"><?= array_key_exists($row['currency'], $currencies) ? $currencies[$row['currency']]['symbol'] : NULL; ?> <?= amount_number_format_3($row['total']); ?></td>
        </tr>
        <!-- items details body -->
    <?php } ?>
</table>
<!-- ------------------------------------------------------------------------------------------------------------- -->


<!-- ------------------------------------------------------------------------------------------------------------- -->
<!-- <table style="width: 100%; margin: 0 auto; background: #fff;">
    <tr>
        <td style="padding-bottom: 10px;">
            <span style="border: 2px dotted; padding: 6px; width: 95%; display: block; margin: 20px auto 0; background: #f3f3f3 !important; border-radius: 0px 12px 0px 12px; display: block; height: 60px;" ></span><br>
        </td>
    </tr>
</table> -->
<!-- ------------------------------------------------------------------------------------------------------------- -->


<!-- ------------------------------------------------------------------------------------------------------------- -->
<table style="width: 90%; margin: 30px auto 0; background: #fff;">
    <tr>
        <td style="text-align: center; padding: 5px;"><strong style="color: #bb0d0d;"><?= print_lang($app_lang,'total_amount'); ?>:</strong> &nbsp;&nbsp;&nbsp; <?= amount_number_format_3(array_sum($total_total_amount)); ?></td>
        <td style="text-align: center; padding: 5px;"><strong style="color: #bb0d0d;"><?= print_lang($app_lang,'cash_paid'); ?>:</strong> &nbsp;&nbsp;&nbsp; <?= amount_number_format_3(array_sum($total_cash_paid)); ?></td>
        <td style="text-align: center; padding: 5px;"><strong style="color: #bb0d0d;"><?= print_lang($app_lang,'balance'); ?>:</strong> &nbsp;&nbsp;&nbsp; <?= amount_number_format_3(array_sum($total_total_amount) - array_sum($total_cash_paid)); ?></td>
        <?php if(1 == 2){ ?><td style="text-align: center; padding: 5px;"><strong style="color: #bb0d0d;"><?= print_lang($app_lang,'old_balance'); ?>:</strong> &nbsp;&nbsp;&nbsp; <?= amount_number_format_3(0); ?></td><?php } ?>
        <?php if(1 == 2){ ?><td style="text-align: center; padding: 5px;"><strong style="color: #bb0d0d;"><?= print_lang($app_lang,'total_balance'); ?>:</strong> &nbsp;&nbsp;&nbsp; <?= amount_number_format_3(array_sum($total_total_amount) - array_sum($total_cash_paid)); ?></td><?php } ?>
    </tr>
</table>
<!-- ------------------------------------------------------------------------------------------------------------- -->


<!-- ------------------------------------------------------------------------------------------------------------- -->
<table style="width: 100%; margin: 0 auto 0; background: #fff;">
    <tr style="line-height: 70px;">
        <td>
            <span style="<?php if($app_direction == 'rtl'){echo 'margin-right: 10px;';}else{echo 'margin-left: 10px;';} ?>"><?= print_lang($app_lang,'signature_stamp'); ?>_______________________________</span>
        </td>
        <td colspan="11" style="<?php if($app_direction == 'rtl'){echo 'text-align: left;';}else{echo 'text-align: right;';}?> font-size: 10px; color: #555;">
            <span style="<?php if($app_direction == 'rtl'){echo 'margin-left: 10px;';}else{echo 'margin-right: 10px;';} ?>">FASTBOOKS SOFTWARE | 0707009795 | www.fastbooks.com</span>
        </td>
    </tr>
</table>
<!-- ------------------------------------------------------------------------------------------------------------- -->