<?php Fun::lang()?>
<?php $total = 0 ?>
<?php $total_discount = 0 ?>
<?php $g_total = 0 ?>
<div class="print_this_form">
    <style>
        .tb_info td{
            padding-top: 7px;
        }
    </style>
    <table width="100%">
        <tr>
            <td style="text-align: left">
                <?php
                    $br = myBranch();
                ?>
                <?php if($br->logo): ?>
                    <img src="<?php echo e(asset($br->logo??LogoImage())); ?> " style="height: 100px;margin: 5px">
                <?php else: ?>
                    <h4><?php echo e($br->name); ?></h4>
                <?php endif; ?>
            </td>
            <td style="text-align: right;width: 30%">
                <h2 class="text-green pull-right"><?php echo e(__('administrator.stock_in')); ?></h2><br>
                <table class="table table-striped pull-right">
                    <tr>
                        <td class=""><b><?php echo e(__('administrator.invoice')); ?>:</b></td>
                        <td><?php echo e($purchases->invoice_number); ?></td>
                    </tr>
                    <tr>
                        <td class=""><b><?php echo e(__('administrator.stock_in_date')); ?>:</b></td>
                        <td><?php echo e(date('d-m-Y',strtotime($purchases->purchase_date))); ?></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <hr>
    <table width="100%" class="tb_info">
        <tr>
            <td>
                <table class="text-left">
                    <tr>
                        <td colspan="2"><h4><u><?php echo e(__('administrator.suppliers')); ?></u></h4></td>
                    </tr>
                    <tr>
                        <td><?php echo e(__('administrator.from')); ?></td>
                        <td> : <?php echo e(findSupplier($purchases->supplier_id)->supplier_name); ?></td>
                    </tr>
                    <tr>
                        <td><?php echo e(__('administrator.supplier_phone')); ?></td>
                        <td> : <?php echo e(findSupplier($purchases->supplier_id)->supplier_phone); ?></td>
                    </tr>
                    <?php if(findSupplierType($purchases->supplier_id)): ?>
                        <td><?php echo e(__('administrator.supplier_type')); ?></td>
                        <td> : <?php echo e(findSupplierType($purchases->supplier_id)->type_name); ?></td>
                    <?php endif; ?>
                </table>
            </td>
            <td>
                <table class="text-left pull-right">
                    <tr>
                        <td colspan="2"><h4><u><?php echo e(__('administrator.ship_to')); ?></u></h4></td>
                    </tr>
                    <tr>
                        <td><?php echo e(__('administrator.warehouse')); ?></td>
                        <td> : <?php echo e(findWarehouse($purchases->warehouse_id)->warehouse_name); ?></td>
                    </tr>
                    <tr>
                        <td><?php echo e(__('administrator.address')); ?></td>
                        <td> : <?php echo e(findWarehouse($purchases->warehouse_id)->location_name); ?></td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <hr>
    <table class="table table-striped table-hover ">
        <thead>
        <tr>
            <th>#</th>
            <th><?php echo e(__('administrator.product_code')); ?></th>
            <th><?php echo e(__('administrator.item_name')); ?></th>
            <th><?php echo e(__('administrator.qty')); ?></th>
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Show Purchase Item Price')): ?>
                <th><?php echo e(__('administrator.cost')); ?></th>
                <th><?php echo e(__('administrator.discount')); ?> (%)</th>
                <th><?php echo e(__('administrator.total')); ?></th>
            <?php endif; ?>
        </tr>
        </thead>
        <tbody>
        <?php

            $g_total= 0;
            $total = 0;
            $currency = findCurrency($purchases->currency_id);
            $currency = $currency?$currency->symbol:'';
        ?>
        <?php $__currentLoopData = $purchase_details; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $value): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

            <?php
            $check_pro = false;
            if ($purchases->type == 'material') {
                $unit = findUnit($value->unit_id);
                $barcode = getProductById($value->product_id)->barcode;
                if($barcode){
                    $check_pro = true;
                }
            } else {
                if ($value->type == 'fabric') {

                    $product = getProductById($value->product_id);
                    $unit = findUnit($product->unit_id??'');
                    $sub_unit = findUnit($product->child_unit??0);
                    if($unit){
                        $check_pro = true;
                    }
                } else {
                    $unit = findProductUnitByCode($value->barcode, $value->type);
                    if($unit){
                        $check_pro = true;
                    }
                    $unit = findUnit($unit->unit_id??'');
                }
                $barcode = $value->barcode;
            }
            $amount = $value->qty * $value->cost;
            $total = $amount - ($value->dis * $amount / 100);
            $g_total += $total;
            // $total_discount += ($currency == '$' ? ($amount * $value->dis / 100) : ($amount * $value->dis / 100));
            $color = findColor($value->color_code);
            $size = findSize($value->size_code);

            ?>
                <tr>
                    <td><?php echo e($key+1); ?></td>
                    <td><?php echo e($barcode); ?></td>
                    <td><?php echo e(getProductById($value->product_id)->product_name??''); ?>

                        <?php if($purchases->type !== 'material'): ?>
                            <?php if($purchases->type=='product'): ?>
                                (<?php echo e(($size->size??'').','.($color->name??'')); ?>)
                            <?php else: ?>
                                (<?php echo e($value->qty_per_unit.' '.($sub_unit->unit??'')); ?>)
                            <?php endif; ?>
                        <?php endif; ?>
                    </td>
                    <td><?php echo e($value->qty.' '.($unit?$unit->unit:'')); ?></td>
                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Show Purchase Item Price')): ?>
                        <td><?php echo e($currency.$value->cost); ?></td>
                        <td><?php echo e(number_format($value->dis)); ?>%</td>
                        <td><?php echo e($currency.$total); ?></td>
                    <?php endif; ?>
                </tr>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        <?php
            $paid = $purchases->paid;
        ?>
        </tbody>
        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Show Purchase Item Price')): ?>
            <tfoot class="label-right">
            <tr>
                <td colspan="6" class="text-right"><?php echo e(__('administrator.discount')); ?> :</td>
                <td class=""><?php echo e(number_format($purchases->discount)); ?>%</td>
            </tr>
            <tr>
                <td colspan="6" class="text-right"><b><?php echo e(__('administrator.grand_total')); ?> :</b></td>
                <td class=""> <?php echo e($currency.number_format(($g_total),2)); ?></td>
            </tr>
            <?php if($purchases->paid): ?>
                <tr>
                    <td colspan="6" class="text-right"><b><?php echo e(__('administrator.paid')); ?>:</b></td>
                    <td> <?php echo e($currency.number_format($purchases->paid,2)); ?></td>
                </tr>
            <?php endif; ?>
            <?php if($paid-$g_total>0): ?>
                <tr>
                    <td colspan="6" class="text-right"><b><?php echo e(__('administrator.change_amount')); ?> :</b></td>
                    <td><?php echo e($currency.number_format(($paid-$g_total),2)); ?></td>
                </tr>
            <?php elseif($paid-$g_total): ?>
                <tr>
                    <td colspan="6" class="text-right"><b><?php echo e(__('administrator.owed_amount')); ?> :</b></td>
                    <td><?php echo e($currency.number_format(($g_total-$paid),2)); ?></td>
                </tr>
            <?php endif; ?>
            </tfoot>
        <?php endif; ?>
    </table>
</div>









<?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/stock-inventory/purchases/show.blade.php ENDPATH**/ ?>