<?php $__env->startSection('content'); ?>
    <?php Fun::lang() ?>
    <form action="<?php echo e(route('production-request-add-more')); ?>" method="POST" class="jform">
        <?php echo csrf_field(); ?>
        <div class="row">
            <div class="col-md-4 col-lg-4 form-group">
                <label class="required"><?php echo e(__('administrator.invoice_number')); ?></label>
                <?php echo Form::text('invoice_number',null, ['placeholder'=>__('administrator.invoice_number'),'class' => 'form-control']); ?>

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

            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <table class="table table-bordered table-hover">
                    <thead>
                    <th><?php echo e(__('administrator.item_name')); ?></th>
                    <th><?php echo e(__('administrator.size')); ?></th>
                    <th><?php echo e(__('administrator.color')); ?></th>
                    <th><?php echo e(__('administrator.qty')); ?></th>
                    <th><?php echo e(__('administrator.sewing_price')); ?></th>
                    <th>
                        <button type="button" onclick="add_row()" class="button_success fa fa-plus"></button>
                    </th>
                    </thead>
                    <tbody class="tbody">

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

    </form>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('jq'); ?>
    <script>
        var tb = $('.tbody');

        $(document).ready(function () {
            add_row()
            tb.on('change','.color_code,.size_code',function () {
                let row = $(this).closest('tr');
                let size_code = row.find('.size_code').val();
                let color_code = row.find('.color_code').val();
                let product_id = row.find('.search_product').val();

                $.ajax({
                    url:'<?php echo e(route('production-request-add-more')); ?>',
                    dataType:'json',
                    method:'get',
                    data:{
                        product_id,size_code,color_code,getSewingPrice:1
                    },
                    success:function (data) {
                        let p =  row.find('.sewing_price')
                        let c =  row.find('.input-group-addon')
                        let t =  row.find('.template_id')
                        let cur =  row.find('.currency_id')

                        p.val(0)
                        c.text('')
                        t.val(0)
                        cur.val(0)

                        if(data.id){
                            p.val(data.sewing_price)
                            c.text(data.cur)
                            t.val(data.id)
                            cur.val(data.currency_id)
                        }
                    }
                })
            })
            tb.on('change','.search_product',function () {
                let row = $(this).closest('tr');
                let size = row.find('.size_code');
                let color = row.find('.color_code');
                size.html('')
                color.html('')
                let product_id = row.find('.search_product').val();
                $.ajax({
                    url:'<?php echo e(route('product-return.create')); ?>',
                    dataType:'json',
                    method:'get',
                    data:{
                        product_id
                    },
                    success:function (data) {
                        let option_color = `<option value=""><?php echo e(__('administrator.please_select')); ?></option>`;
                        let option_size = option_color
                        $.each(data.size,function (i,v) {
                            option_size+=`<option value="${i}">${v}</option>`
                        })
                        size.html(option_size)

                        $.each(data.color,function (i,v) {
                            option_color+=`<option value="${i}">${v}</option>`
                        })
                        color.html(option_color)
                    },
                    error(xhr){
                        alertErrorFormController(xhr);
                    }
                });
            })
        });
        function add_row() {
            tb.append(`
                <tr>
                    <td><?php echo Form::select('product_id[]',[],null,['placeholder'=>__('administrator.please_select'),'class'=>'form-control search_product']);; ?></td>
                    <td><?php echo Form::select('size_code[]',[],null,['placeholder'=>__('administrator.please_select'),'class'=>'form-control size_code']);; ?></td>
                    <td><?php echo Form::select('color_code[]',[],null,['placeholder'=>__('administrator.please_select'),'class'=>'form-control color_code']);; ?></td>
                    <td><?php echo Form::text('qty[]',1,['placeholder'=>__('administrator.qty'),'class'=>'form-control number-only qty']);; ?></td>
                    <td>
                        <div class="input-group">
                            <input name="cutting_price[]" type="hidden" value="1100" autocomplete="off">
                            <?php echo Form::number('sewing_price[]',0, ['placeholder'=>__('administrator.sewing_price'),'class' => 'form-control sewing_price','step'=>'0.001']); ?>

                            <?php echo Form::hidden('template_id[]',null,['class'=>'template_id']); ?>

                            <?php echo Form::hidden('currency_id[]',null,['class'=>'currency_id']); ?>

                            <span class="input-group-addon"></span>
                        </div>
                    </td>
                    <td><button class="button_danger fa fa-times" onclick="$(this).closest('tr').remove()"></button></td>
                <tr>
            `);
                search_something('product','.search_product:last');
        }
    </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/add-more-production.blade.php ENDPATH**/ ?>