<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; background: #fff;}
    .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;
$warehouse_name = array_key_exists($invoice_data['warehouse'], $warehouse) ? $warehouse[$invoice_data['warehouse']]['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,'stock_in_clinet'); ?>:</strong></span> <?= $client_name; ?></td>
        <td style="width: 25%;"><span style="color: #bb0d0d !important; padding: 4px;"><strong style="color: #bb0d0d !important;"><?= print_lang($app_lang,'stock_in_agent_invoice'); ?>:</strong></span> <?= $invoice_data['agent']; ?></td>
        <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: 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,'receipt_#'); ?>:</span><span style="color: #fff !important;"> <?= $invoice_data['invoice']; ?></span></strong></td>
    </tr>
</table>


<table style="width: 100%; background: #fff;">
    <!-- Table Heead with red backgorund -->
    <tr style="border: 1px solid black;">
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center;">#</th>
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px;"><?= strtoupper(print_lang($app_lang,'stock_out_invoice_item')); ?></th>
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'unit')); ?></th>
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'qty_out')); ?></th>
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'mark')); ?></th>
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'warehouse')); ?></th>
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'total_in_date')); ?></th>
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'stock_out_date')); ?></th>
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'stay_in_warehouse')); ?></th>
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'qty_remain')); ?></th>
        <th style="font-size: 15px; border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'remarks')); ?></th>
    </tr>
    <!-- Table Heead with red backgorund -->
    <?php

        $isn = 1;
        $items = json_decode($invoice_data['items_details'],true);
        // print_rr($items);
        $total_out = array();
        $total_remain = array();
        foreach($items as $item){
            $item_ava_qty = item_available_qty($item['item_id']);
            $total_out[] = $item['qty'];
            $total_remain[] = $item_ava_qty;
        ?>
    <tr>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= $isn++; ?></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px;"><?= $item['item']; ?></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= $item['unit']; ?></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= $item['qty']; ?></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= $item['mark']; ?></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= $warehouse_name; ?></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= display_true_date($stock_in_data['invoice_data']['stock_date']); ?></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= display_true_date($invoice_data['stock_date_out']); ?></td>
        <?php
            $days = get_days_in_dates($stock_in_data['invoice_data']['stock_date'],$invoice_data['stock_date_out']);
            $days = $days." ".print_lang($app_lang,'days');
        ?>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= $days; ?></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= $item_ava_qty; ?></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= $item['remark']; ?></td>
    </tr>
    <?php } ?>
    <tr>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><?= $isn++; ?></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px;"><strong><?= strtoupper(print_lang($app_lang,'total')); ?></strong></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><strong><?= array_sum($total_out); ?></strong></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"><strong><?= array_sum($total_remain); ?></strong></td>
        <td style="color: black !important; border: 1px solid black; padding: 5px; text-align: center;"></td>
    </tr>
</table>

<table style="width: 60%; background: #fff; float: left;">
    <tr>
        <td style="padding-bottom: 10px; border-bottom: none; border-left: none;">
            <span style="border: 2px dotted; padding: 6px; width: 98%; margin-left: 4px; margin-top: 20px; background: #f3f3f3 !important; border-radius: 0px 12px 0px 12px; display: block; height: 100px;" ></span><br>
        </td>
    </tr>
    <tr>
        <td>
            <span style="margin-left: 4px; margin-top: 50px;"><?= print_lang($app_lang,'signature_stamp'); ?>_______________________________</span>
        </td>
    </tr>
</table>
<table style="width: 40%; margin-top: 20px; background: #fff; float: right;">
    <tr>
        <td style="padding: 4px; background: #f3f3f3 !important; margin-top: 40px;">
            <strong><?= strtoupper(print_lang($app_lang,'warehouse_rent')); ?>: <span style="<?php if($app_direction == 'rtl'){echo 'float: left;';}else{echo 'float: right;';}?>"><?php echo $invoice_data['rent']; ?></span></strong>
        </td>
    </tr>
    <tr>
        <td style="padding: 4px; background: #f3f3f3 !important; margin-top: 40px;">
            <strong><?= strtoupper(print_lang($app_lang,'discount')); ?>: <span style="<?php if($app_direction == 'rtl'){echo 'float: left;';}else{echo 'float: right;';}?>"><?php echo $invoice_data['discount']; ?></span></strong>
        </td>
    </tr>
    <tr>
        <td style="padding: 4px; background: #f3f3f3 !important; margin-top: 40px;">
            <strong><?= strtoupper(print_lang($app_lang,'gross_stock_amount')); ?>: <span style="<?php if($app_direction == 'rtl'){echo 'float: left;';}else{echo 'float: right;';}?>"><?php echo $invoice_data['gross_total']; ?></span></strong>
        </td>
    </tr>
    <tr>
        <td style="padding: 4px; background: #f3f3f3 !important; margin-top: 40px;">
            <strong><?= strtoupper(print_lang($app_lang,'cash_paid_stock')); ?>: <span style="<?php if($app_direction == 'rtl'){echo 'float: left;';}else{echo 'float: right;';}?>"><?php echo $invoice_data['cash_paid']; ?></span></strong>
        </td>
    </tr>
    <?php
        $total_rent = $invoice_data['gross_total'] - $invoice_data['cash_paid'];
        $total_invoice_balance = $total_rent + $invoice_data['client_old_balance'];
    ?>
    <tr>
        <td style="padding: 4px; background: #f3f3f3 !important; margin-top: 40px;">
            <strong><?= strtoupper(print_lang($app_lang,'balance')); ?>: <span style="<?php if($app_direction == 'rtl'){echo 'float: left;';}else{echo 'float: right;';}?>"><?php echo $total_rent; ?></span></strong>
        </td>
    </tr>
    <tr>
        <td style="padding: 4px; background: #f3f3f3 !important; margin-top: 40px;">
            <strong><?= strtoupper(print_lang($app_lang,'stock_old_balance')); ?>: <span style="<?php if($app_direction == 'rtl'){echo 'float: left;';}else{echo 'float: right;';}?>"><?php echo $invoice_data['client_old_balance']; ?></span></strong>
        </td>
    </tr>
    <?php

    $total_balance = $total_rent - $invoice_data['client_old_balance'];

    ?>
    <tr style="border-top: 1px solid #dddddd;">
        <td style="padding: 4px; background: #f3f3f3 !important; margin-top: 40px;">
            <strong style="color: #bb0d0d !important; font-size: 16px;"><?= strtoupper(print_lang($app_lang,'stock_total_balance')); ?>: <span style="<?php if($app_direction == 'rtl'){echo 'float: left;';}else{echo 'float: right;';}?> color: #bb0d0d !important;"><?php echo $total_balance; ?></span></strong>
        </td>
    </tr>
</table>