
<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;}
    ::-webkit-scrollbar {
        display: none;
    }

    body {
    -webkit-print-color-adjust:exact;
    background: #fff;
    }

</style>

<table style="width: 100%; background: #fff;">
    <tr>
        <td><img style="width: 100%; height: 200px; padding: 0;" 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 A");
$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;
?>

<table style="width: 100%; margin: 10px 0px; background: #fff;">
    <tr style="margin: 10px 0px;">
        <td style="width: 35%;"><span style="color: #bb0d0d !important; padding: 4px;"><strong style="color: #bb0d0d !important;"><?= strtoupper(print_lang($app_lang,'production_date')); ?>:</strong></span> <?= display_true_date($date); ?></td>
        <td style="width: 25%;"><span style="color: #bb0d0d !important; padding: 4px;"><strong style="color: #bb0d0d !important;"><?= strtoupper(print_lang($app_lang,'user')); ?>:</strong></span> <?= get_logged_user_data('name'); ?></td>
        <td style="width: 15%;"><span style="color: #bb0d0d !important; padding: 4px;"><strong style="color: #bb0d0d !important;"><?= strtoupper(print_lang($app_lang,'currency')); ?>:</strong></span> <?= $currency_name; ?></td>
        <td style="width: 25%; background: #bb0d0d !important; color: #fff!important; border-radius: 0px 10px 0px 10px !important; padding: 4px; text-align: center;"><strong><span style="color: #fff !important;"><?= strtoupper(print_lang($app_lang,'slip_#')); ?>:</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 sales table-->
    <tr style="border: 1px solid black;">
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 4%;">#</th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 13%;"><?= strtoupper(print_lang($app_lang,'production_items')); ?></th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'warehouse')); ?></th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 7%;"><?= strtoupper(print_lang($app_lang,'batch')); ?></th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 7%;"><?= strtoupper(print_lang($app_lang,'unit')); ?></th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 7%;"><?= strtoupper(print_lang($app_lang,'qty')); ?></th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 7%;"><?= strtoupper(print_lang($app_lang,'mode_production_invoice_ready_qty')); ?></th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 7%;"><?= strtoupper(print_lang($app_lang,'mode_production_invoice_pending_qty')); ?></th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 7%;"><?= strtoupper(print_lang($app_lang,'ava_quantity')); ?></th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'cost')); ?></th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'profit')); ?></th>
        <th style="border: 1px solid black; background: #5e91d0 !important; color: #fff !important; padding: 5px; text-align: center; width: 12%;"><?= strtoupper(print_lang($app_lang,'sale_price')); ?></th>
    </tr>
    <!-- Table Heead with red backgorund -->
    <?php $ptic = 1; foreach($produced_details as $pitem){
        $production_item_data = fetch_table_where('items','uid',$pitem['item'],true);
        $production_item_unit_name = NULL;
        if($pitem['unit'] == 'purchase')
        {
            $production_item_unit_name = array_key_exists($production_item_data['purchase_unit'],$units) ? $units[$production_item_data['purchase_unit']]['name'] : NULL;
        }
        if($pitem['unit'] == 'sale')
        {
            $production_item_unit_name = array_key_exists($production_item_data['sale_unit'],$units) ? $units[$production_item_data['sale_unit']]['name'] : NULL;
        }
        if($pitem['unit'] == 'production')
        {
            $production_item_unit_name = array_key_exists($production_item_data['production_unit'],$units) ? $units[$production_item_data['production_unit']]['name'] : NULL;
        }
    ?>
        <tr>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $ptic++; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= array_key_exists($pitem['item'], $items) ? $items[$pitem['item']]['name'] : NULL; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= array_key_exists($pitem['warehouse'], $warehouse) ? $warehouse[$pitem['warehouse']]['name'] : NULL; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $pitem['batch']; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $production_item_unit_name; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $pitem['qty']; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $pitem['ready_qty']; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= (float)$pitem['qty'] - (float)$pitem['ready_qty']; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= (float)$pitem['ava_qty'] + $pitem['qty']; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= amount_number_format($pitem['cost']); ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= amount_number_format($pitem['profit']); ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= amount_number_format($pitem['sale_price']); ?></td>
        </tr>
    <?php }?>

    <!-- Raw Material Used -->
    <tr style="border: 1px solid black;">
        <th style="border: 1px solid black; background: #1db136c7 !important; color: #fff !important; padding: 5px; text-align: center;">#</th>
        <th style="border: 1px solid black; background: #1db136c7 !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'raw_material_used')); ?></th>
        <th colspan="2" style="border: 1px solid black; background: #1db136c7 !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'warehouse')); ?></th>
        <th style="border: 1px solid black; background: #1db136c7 !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'cost')); ?></th>
        <th style="border: 1px solid black; background: #1db136c7 !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'qty')); ?></th>
        <th style="border: 1px solid black; background: #1db136c7 !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'batch')); ?></th>
        <th style="border: 1px solid black; background: #1db136c7 !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'unit')); ?></th>
        <th style="border: 1px solid black; background: #1db136c7 !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'used_quantity')); ?></th>
        <th style="border: 1px solid black; background: #1db136c7 !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'damage')); ?></th>
        <th colspan="2" style="border: 1px solid black; background: #1db136c7 !important; color: #fff !important; padding: 5px; text-align: center;"><?= strtoupper(print_lang($app_lang,'ava_quantity')); ?></th>
    </tr>

    <?php
        $pic = 1;
        foreach($raw_details as $row)
        {
            // $production_item_data = array_key_exists($row['item'], $items) ? $items[$row['item']] : array('purchase_unit' => NULL, 'sale_unit' => NULL, 'production_unit' => NULL);
            $production_item_data = fetch_table_where('items','uid',$row['item'],true);
            // print_rr($production_item_data);
            $production_item_unit_name = NULL;
            if($row['unit'] == 'purchase')
            {
                $production_item_unit_name = array_key_exists($production_item_data['purchase_unit'],$units) ? $units[$production_item_data['purchase_unit']]['name'] : NULL;
            }
            if($row['unit'] == 'sale')
            {
                $production_item_unit_name = array_key_exists($production_item_data['sale_unit'],$units) ? $units[$production_item_data['sale_unit']]['name'] : NULL;
            }
            if($row['unit'] == 'production')
            {
                $production_item_unit_name = array_key_exists($production_item_data['production_unit'],$units) ? $units[$production_item_data['production_unit']]['name'] : NULL;
            }
    ?>

        <tr>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $pic++; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= array_key_exists($row['item'], $items) ? $items[$row['item']]['name'] : NULL; ?></td>
            <td colspan="2" style="border: 1px solid black; padding: 5px; text-align: center;"><?= array_key_exists($row['warehouse'], $warehouse) ? $warehouse[$row['warehouse']]['name'] : NULL; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= amount_number_format($row['cost']); ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $row['ava_qty']; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $row['batch']; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $production_item_unit_name; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $row['qty']; ?></td>
            <td style="border: 1px solid black; padding: 5px; text-align: center;"><?= $row['damage']; ?></td>
            <td colspan="2" style="border: 1px solid black; padding: 5px; text-align: center;"><?= (float)$row['ava_qty'] - (float)$row['qty']; ?></td>
        </tr>

    <?php } ?>

    <!-- Expenses table -->
    <tr style="border: 1px solid black;">
        <th style="border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 5%;">#</th>
        <th colspan="5" style="border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'extra_expense_description')); ?></th>
        <th style="border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 8%;"><?= strtoupper(print_lang($app_lang,'total')); ?></th>
        <th colspan="5" style="border: 1px solid black; background: #bb0d0d !important; color: #fff !important; padding: 5px; text-align: center; width: 10%;"><?= strtoupper(print_lang($app_lang,'expense_account')); ?></th>
    </tr>

    <?php
        $eec = 1;
        foreach($raw_details as $row){
        if(empty($row['expense'])){ continue; }
    ?>
    <tr>
        <td style="border: 1px solid black; padding: 5px; text-align: center; width: 5%;"><?= $eec++; ?></td>
        <td colspan="5" style="border: 1px solid black; padding: 5px; text-align: center; width: 10%;"><?php echo print_lang($app_lang,'mode_production_invoice_extra_expense_details'); ?></td>
        <td style="border: 1px solid black; padding: 5px; text-align: center; width: 8%;"><?= amount_number_format($row['expense']); ?></td>
        <td colspan="5" style="border: 1px solid black; padding: 5px; text-align: center; width: 8%;"><?= array_key_exists($row['expense_account'], $expenses) ? $expenses[$row['expense_account']]['name'] : NULL; ?></td>
    </tr>
    <?php } ?>


    <!-- Total -->
    <tr>
        <td colspan="5" style=" border: 1px solid black;padding-bottom: 10px; border-bottom: none; border-left: none; padding-top: 50px;">
            <span style="margin-left: 6px; margin-top: 70px;"><?= strtoupper(print_lang($app_lang,'signature_stamp')); ?>_______________________________</span>
        </td>
        <td colspan="7" style=" border: 1px solid black;padding: 4px; background: #f3f3f3 !important">
            <strong><?= strtoupper(print_lang($app_lang,'mode_production_invoice_total_qty')); ?>: <span style="float: right;"><?= amount_number_format((float)$invoice_data['total_qty']); ?></span></strong><br>
            <strong><?= strtoupper(print_lang($app_lang,'mode_production_invoice_total_ready')); ?>: <span style="float: right;"><?= amount_number_format((float)$invoice_data['ready_qty']); ?></span></strong><br>
            <strong><?= strtoupper(print_lang($app_lang,'mode_production_invoice_total_pending')); ?>: <span style="float: right;"><?= amount_number_format((float)$invoice_data['pending_qty']); ?></span></strong><br>
            <strong><?= strtoupper(print_lang($app_lang,'total_used_raw_material_cost')); ?>: <span style="float: right;"><?= amount_number_format((float)$invoice_data['total_raw_cost'] - (float)$invoice_data['total_expenses']); ?></span></strong><br>
            <strong><?= strtoupper(print_lang($app_lang,'total_extra_expenses')); ?>: <span style="float: right;"><?= amount_number_format($invoice_data['total_expenses']); ?></span></strong><br>
            <hr style="border-top: 1px solid #131212; margin-top: 0px; margin-bottom: 9px;">
            <strong style="color: #bb0d0d !important; font-size: 16px;"><?= strtoupper(print_lang($app_lang,'total_production_cost')); ?>: <span style="float: right; color: #bb0d0d !important;"><?= amount_number_format($invoice_data['total_raw_cost']); ?></span></strong>
        </td>
    </tr>

    <tr>
        <td colspan="12" style="text-align: right; text-align: right; font-size: 10px; color: #928e8e; padding-top: 10px;">FASTBOOKS SOFTWARE | 0707009795 | www.fastbooks.com</td>
    </tr>