<?php $__env->startSection('content'); ?>
    <?php Fun::lang() ?>
    <?php
        $tailor = findTailor($master->tailor_id);
    ?>
    <div class="print_form" style="overflow-y: scroll">
        <div class=" col-sm-12 col-xs-12 form-group text-center">
            <h3><?php echo e(__('administrator.return_item')); ?></h3>
        </div>
        <div class=" col-sm-12 col-xs-12 form-group">
            <table class="inv-header">
                <tr>
                    <td><?php echo e(__('administrator.start_date')); ?></td>
                    <td width="2%">:</td>
                    <td><?php echo e(date('d-m-Y',strtotime($master->date))); ?></td>
                </tr>
                <tr>
                    <td><?php echo e(__('administrator.invoice_number')); ?></td>
                    <td>:</td>
                    <td><?php echo e($master->invoice_number); ?></td>
                </tr>
                <tr>
                    <td><?php echo e(__('administrator.tailor')); ?></td>
                    <td>:</td>
                    <td><?php echo e(findTailor($master->tailor_id)->name??''); ?></td>
                </tr>
                <tr>
                    <td><?php echo $master->done===1?'<span class="label label-success">'.__('administrator.done').'</span>':''; ?></td>
                </tr>
            </table>
        </div>
        <hr>
        <?php echo Form::open(['route' => ['production-request-get-return-item-form',$master->id], 'method' => 'post','class'=>'jform']); ?>

        <div class=" col-sm-12 col-xs-12 form-group text-left">
            <table class="table" width="100%">
                <thead>
                <tr>
                    <th>#</th>
                    <th><?php echo e(__('administrator.items')); ?></th>
                    <th><?php echo e(__('administrator.barcode')); ?></th>
                    <th><?php echo e(__('administrator.qty')); ?></th>
                    <th><?php echo e(__('administrator.template')); ?></th>
                    <th><?php echo e(__('administrator.total_qty')); ?></th>
                    <th><?php echo e(__('administrator.total_return_item')); ?></th>
                    <th><?php echo e(__('administrator.left_qty')); ?></th>
                    <th><?php echo e(__('administrator.return_item')); ?></th>
                </tr>
                </thead>
                <tbody>
                <?php $__currentLoopData = $detail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key=> $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php
                        $total = $row->qty*$row->template_qty;
                        $product_unit = findProductUnitByCode($row->barcode);
                        if($product_unit){
                                 $product = getProductById($product_unit->product_id);
                                 $product = $product->product_name??'';
                                 $size = findSize($product_unit->size_code)->size??'';
                                 $color = findColor($product_unit->color_code)->name??'';
                        }else{
                            $product = '';
                            $size = '';
                            $color = '';
                        }
                        $done = \App\Model\production\ProductionDoneModel::where('production_id',$master->id)->pluck('id');
                        $qty = \App\Model\production\ProductionDoneDetailModel::whereIn('production_done_id',$done)->where('barcode',$row->barcode)->sum('qty');
                        $left_qty = $total-$qty;
                    ?>
                    <tr>
                        <td><?php echo e($key+1); ?></td>
                        <td>
                            <?php echo e($product.' ( '.$size.','.$color.' )'); ?>

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

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

                        </td>
                        <td><?php echo e($row->barcode); ?></td>
                        <td><?php echo e($row->qty); ?></td>
                        <td><?php echo e($row->template_qty); ?></td>
                        <td><?php echo e($total); ?></td>
                        <td><?php echo e($qty); ?></td>
                        <td><?php echo e($left_qty); ?></td>
                        <td>
                            <?php echo Form::text('return_item_qty[]', 0, ['class' => 'form-control return_item_qty number-only','data-left_qty'=>$left_qty]); ?>

                            <?php echo Form::hidden('total_qty[]', $total, ['class' => 'form-control total_qty']); ?>

                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                <tr>
                    <td colspan="7" rowspan="7"
                        class="no-border" style="vertical-align: top!important;"><?php echo e(__('administrator.note')); ?><?php echo Form::textarea('note', null, ['class' => 'form-control','rows'=>2]); ?></td>
                    <td></td>
                    <td></td>


                </tr>
                </tbody>
            </table>
            <br>
        </div>
        <input type="submit" class="display-none">
        <?php echo Form::close(); ?>

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

    </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-request/return-item-form.blade.php ENDPATH**/ ?>