<?php $__env->startSection('content'); ?>
    <?php Fun::lang();
    $sym = user_currency();
    $sym = $sym->symbol ?? '';
    ?>
    <style>
        table tfoot tr td:first-child {
            text-align: right;
        }

        .padding-5 td {
            padding-top: 10px;
            padding-bottom: 20px;
        }
    </style>
    <div class="page ">
        <div class="container-fluid ">
            <div class="row">
                <?php echo Form::open(array('route' => 'production-request.store','method'=>'POST','enctype'=>'multipart/form-data','id'=>'submit_post','class'=>'jform')); ?>

                <div class="col-sm-12 col-xs-12 padding-top-bottom-10 bg-white">
                    <div class="master-form">
                        <h3 class="margin-ud-10"><?php echo e(__('administrator.production_request')); ?></h3>
                        <div class="title-note">
                            <h3><span class="fa fa-exclamation-triangle"></span> <?php echo e(__('administrator.create')); ?>

                                <i>(<?php echo e(__('administrator.fields_in_red_are_required')); ?>)</i></h3>
                        </div>
                        <div class="col-md-8 col-md-offset-2">
                            <fieldset>
                                <legend><?php echo e(__('administrator.cut_piece')); ?></legend>
                            </fieldset>
                            <div class="row">
                                <div class="col-sm-4 col-md-4 col-lg-4 form-group">
                                    <div class="col-sm-6 col-md-6 col-lg-6">
                                        <label class="required"><?php echo e(__('administrator.invoice_number')); ?></label>
                                    </div>
                                    <div class="col-sm-6 col-md-6 col-lg-6">
                                        <?php echo Form::text('invoice_number',$cutting->invoice_number, ['placeholder'=>__('administrator.invoice_number'),'class' => 'form-control']); ?>

                                        <?php echo Form::hidden('cutting_id',request()->cutting_id); ?>

                                    </div>
                                </div>
                                <div class="col-sm-4 col-md-4 col-lg-4 form-group">
                                    <div class="col-sm-5 col-md-5 col-lg-5">
                                        <label class="required"><?php echo e(__('administrator.tailor_shop')); ?></label>
                                    </div>
                                    <div class="col-sm-7 col-md-7 col-lg-7">
                                        <?php echo Form::select('tailor_type',getTailorType(),null,array('placeholder'=>__('administrator.please_select'),'class'=>' form-control tailor_type')); ?>

                                    </div>
                                </div>
                                <div class="col-sm-4 col-md-4 col-lg-4 form-group">
                                    <div class="col-sm-5 col-md-5 col-lg-5">
                                        <label class="required"><?php echo e(__('administrator.tailor')); ?></label>
                                    </div>
                                    <div class="col-sm-7 col-md-7 col-lg-7">
                                        <?php echo Form::select('tailor_id',[],null,array('placeholder'=>__('administrator.please_select'),'class'=>' form-control')); ?>

                                    </div>
                                </div>
                            </div>

                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th>#</th>
                                    <th><?php echo e(__('administrator.code')); ?></th>
                                    <th><?php echo e(__('administrator.size')); ?></th>
                                    <th><?php echo e(__('administrator.color')); ?></th>
                                    <th><?php echo e(__('administrator.total_qty')); ?></th>
                                    <th><?php echo e(__('administrator.remain')); ?></th>
                                    <th><?php echo e(__('administrator.qty')); ?></th>
                                    <th width="150px"><?php echo e(__('administrator.sewing_price')); ?></th>
                                    <th><?php echo e(__('administrator.check')); ?></th>
                                </tr>
                                </thead>
                                <tbody class="table_cut_piece">
                                <?php $sum_cutpiece = 0; ?>
                                <?php $__currentLoopData = $detail; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $production_cutting): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <?php
                                        $total_qty= $production_cutting->qty * $production_cutting->size_qty;
                                        $sum_cutpiece +=$total_qty;
                                        $check = checkProductExist($production_cutting->barcode);
                                        $template = \App\Model\production\ProductionTemplateModel::where([
                                            'product_id' => $production_cutting->code_of_pant,
                                            'barcode' => $production_cutting->barcode,
                                            'size_code' => $production_cutting->size_code,
                                            'color_code' => $production_cutting->color_code,
                                            ])->selectRaw('sewing_price,id,currency_id')->first();
                                        $currency = findCurrency($template->currency_id??user_currency()->id);
                                    ?>
                                    <tr class="<?php echo e($check?:'bg-danger'); ?>">
                                        <td><?php echo e($key+=1); ?>

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

                                        </td>
                                        <td>
                                            <?php echo e($production_cutting->barcode); ?>

                                        </td>
                                        <td>
                                            <?php echo e(findSize($production_cutting->size_code)->size??''); ?>

                                        </td>
                                        <td>
                                            <?php echo e(findColor($production_cutting->color_code)->name??''); ?>

                                        </td>
                                        <td>
                                            <?php echo e($production_cutting->total_qty); ?> ឯកតា
                                        </td>
                                        <td>
                                            <?php echo e($production_cutting->remain_qty); ?> ឯកតា
                                        </td>
                                        <td width="150px">
                                            <?php echo Form::number('c_qty[]', 0,['class'=>'form-control piece_qty','data-stock'=>$production_cutting->remain_qty]); ?>

                                        </td>
                                        <td>
                                            <div class="input-group">
                                                <?php echo Form::hidden('cutting_price[]', $production_cutting->cutting_price??0); ?>

                                                <?php echo Form::number('sewing_price[]', $template->sewing_price??0,['class'=>'form-control sewing_price','step'=>'0.001']); ?>

                                                <span class="input-group-addon cursor"><?php echo e($currency->symbol); ?> </span>
                                            </div>
                                            <?php echo Form::hidden('symbol[]',($currency->symbol??''),['class'=>'symbol']); ?>

                                            <?php echo Form::hidden('template_id[]',($template->id??0)); ?>

                                        </td>
                                        <td><span class="fa <?php echo e($check?' fa-check text-success':' fa-times text-danger'); ?> "></span></td>
                                    </tr>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </tbody>
                            </table>
                        </div>
                        <div class="col-md-10">
                            <div class="form-group footer-save">
                                <?php echo Form::hidden('checked_item'); ?>

                                <button type="submit" class=" button_primary pull-right"><span class="fa fa-save"></span> <?php echo e(__('administrator.save')); ?></button>
                                <button type="button" onClick="history.go(-1)" class=" button_warning pull-right">
                                    <span class=" fa fa-arrow-circle-left"></span> <?php echo e(__('administrator.back')); ?>

                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <?php echo Form::close(); ?>

            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script type="text/javascript">
        $(document).ready(function () {
            check_submit();
            $(document).on('keyup', '.piece_qty', function () {
                let stock = toFloat($(this).data('stock'));
                let qty = toFloat($(this).val());
                if (stock < qty) {
                    $(this).val(stock)
                }
            });
            $(document).on('change', 'select[name=tailor_type]', function () {
                let type = $(this).val();
                $.ajax({
                    url: "<?php echo e(route('find-warehouse-by-type')); ?>",
                    method: "post",
                    dataType: 'json',
                    data: {
                        type,
                    },
                    success: function (response) {
                        let row = '<option value=""><?php echo e(__('administrator.please_select')); ?></option>';
                        $.each(response, function (ii, vv) {
                            row += '<option value="' + ii + '">' + vv + '</option>';
                        });
                        $('select[name=tailor_id]').html(row);
                    }
                });
            });
        });

        function check_submit() {
            let check = $('.table_cut_piece').find('span').hasClass('text-danger');
            if (check) {
                $('button[type=submit]').prop('disabled', true);
            } else {
                $('button[type=submit]').prop('disabled', false);
            }
        }
    </script>
<?php $__env->stopSection(); ?>

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