<?php $__env->startSection('content'); ?>
    <?php echo Form::open(['method' => 'POST','url' => $master->route,'enctype'=>'multipart/form-data','class'=>'jform',]); ?>

    <?php Fun::lang() ?>
    <div class="production-request1">
        <div class="container-fluid">
            <h2><?php echo e($master->return?__('administrator.return_item'):__('administrator.import_stock')); ?></h2>
            <hr>
            <?php
                $user = findUser($master->user_id);
            ?>
            <table width="100%">
                <tr>
                    <td>
                        <table class="text-left">
                            <tr>
                                <td><?php echo e(__('administrator.invoice_number')); ?></td>
                                <td> : <?php echo e($master->invoice_number); ?> </td>
                            </tr>
                            <tr>
                                <td><?php echo e(__('administrator.user')); ?></td>
                                <td> : <?php echo e($user?$user->name:''); ?> </td>
                            </tr>
                            <tr>
                                <td><?php echo e(__('administrator.date')); ?></td>
                                <td> : <?php echo e(date('d-m-Y',strtotime($master['date']))); ?> </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
            <br>
            <br>
            <table class="table table-striped table-hover " width="100%">
                <thead>
                <tr>
                    <th>#</th>
                    <th><?php echo e(__('administrator.barcode')); ?></th>
                    <th><?php echo e(__('administrator.items')); ?></th>
                    <th><?php echo e(__('administrator.size')); ?></th>
                    <th><?php echo e(__('administrator.color')); ?></th>
                    <th><?php echo e(__('administrator.packing_qty')); ?></th>
                    <th><?php echo e(__('administrator.import_qty')); ?></th>
                    <th><?php echo e(__('administrator.return_qty')); ?></th>
                    <th><?php echo e(__('administrator.left_qty')); ?></th>
                    <th><?php echo e($master->return?__('administrator.return_qty'):__('administrator.import_qty')); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php
                    $total_done = 0;
                    $total_import = 0;
                    $total_return = 0;
                    $total_left = 0;
                    $packing_done = \App\Model\production\packing\ProductionPackingDoneModel::where('packing_id',$master->id)->pluck('id');
                    $production = \App\Model\production\ProductionRequestModel::where('packing_id',$master->id)->pluck('id');
                ?>
                <?php $__currentLoopData = $master->detail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $product_unit = findProductUnitByCode($row->barcode,'product');
                        $product = getProductById($product_unit->product_id);
                        $size = findSize($product_unit->size_code);
                        $color = findColor($product_unit->color_code);
                        $unit = findUnit($product_unit->unit_id);

                        $packing_done_qty = \App\Model\production\packing\ProductionPackingDoneDetailModel::whereIn('packing_done_id',$packing_done)
                        ->where('barcode',$row->barcode)
                        ->sum('qty');
                        $return_qty = \App\Model\production\ProductionRequestDetailModel::whereIn('production_id',$production)
                        ->where(['barcode'=> $row->barcode,'type'=>'item'])
                        ->sum('qty');
                        $left_qty = $row->qty-$packing_done_qty-$return_qty;

                        $total_import +=$packing_done_qty;
                        $total_return +=$return_qty;
                        $total_left +=$left_qty;
                        $total_done+=$row->qty;
                    ?>
                    <tr>
                        <td><?php echo e($key+1); ?></td>
                        <td><?php echo e($row->barcode); ?></td>
                        <td><?php echo e($product->product_name??''); ?></td>
                        <td><?php echo e($size->size??''); ?></td>
                        <td><?php echo e($color->name??''); ?></td>
                        <td><?php echo e($row->qty); ?></td>
                        <td><?php echo e($packing_done_qty); ?></td>
                        <td><?php echo e($return_qty); ?></td>
                        <td><?php echo e($left_qty); ?></td>
                        <td>
                            <?php echo Form::text('qty[]',0, ['placeholder'=>__('administrator.import_qty'),'class' => 'form-control qty number-only','data-left'=>$left_qty]); ?>

                            <?php echo Form::hidden('barcode[]',$row->barcode); ?>

                            <?php echo Form::hidden('packing_detail_id[]',$row->id); ?>

                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
                <tfoot>
                <tr>
                    <td colspan="5" class="text-right no-border"><?php echo e(__('administrator.total_item')); ?></td>
                    <td><?php echo e($total_done); ?></td>
                    <td><?php echo e($total_import); ?></td>
                    <td><?php echo e($total_return); ?></td>
                    <td><?php echo e($total_left); ?></td>
                    <td></td>
                </tr>
                <tr>
                <?php if(!$master->return): ?>
                    <tr>
                        <td colspan="5" class="text-right no-border"><?php echo e(__('administrator.to_warehouse')); ?></td>
                        <td colspan="4"><?php echo Form::select('warehouse_id',getWarehouse('item')->pluck('warehouse_name','id'),null, ['placeholder'=>__('administrator.please_select'),'class' => 'form-control select2']); ?></td>
                        <td><?php echo Form::text('total_qty',0, ['class' => 'form-control','readonly']); ?></td>
                    </tr>
                <?php endif; ?>
                </tfoot>
            </table>

            <?php if($master->return): ?>
                <table>
                    <tr>
                        <td><?php echo e(__('administrator.note')); ?>&nbsp;&nbsp;</td>
                        <td>
                            <?php echo Form::textarea('note', null,['class' => 'form-control','rows'=>3]); ?>

                        </td>
                    </tr>
                </table>

            <?php endif; ?>
        </div>
    </div>
    <?php echo Form::submit('Submit', ['class' => 'hidden']); ?>

    <?php echo Form::close(); ?>

<?php $__env->stopSection(); ?>
<?php $__env->startSection('jq'); ?>
    <script>
        $(document).ready(function () {
            $('table').on('keyup', '.qty', function () {
                let _qty = $(this).val();
                let left = $(this).data('left');
                left = left ? parseFloat(left) : 0;
                _qty = _qty ? parseFloat(_qty) : 0;
                if (_qty > left) {
                    $(this).val(left);
                }
            });
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.jform', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/nsowos/public_html/shr-brand/resources/views/administrator/production-packing/import-return-form.blade.php ENDPATH**/ ?>