<?php $__env->startSection('content'); ?>
    <?php Fun::lang()?>
    <style>
        .jconfirm .jconfirm-box {
            overflow-x: scroll;
            overflow-y: hidden;
        }

        .table {
            white-space: nowrap;
        }
    </style>
    <div class="page">
        <div class=container-fluid>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3><?php echo e(__('administrator.production_request')); ?></h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <br>&nbsp;
            <br>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group ">
                        <div>
                            <div class="col-sm-4 form-group">
                                <div class="col-sm-3 form-group">
                                    <label><?php echo e(__('administrator.user')); ?></label>
                                </div>
                                <div class="col-sm-9 form-group">
                                    <?php echo Form::select('user_id', $user, null, array('class' => 'form-control select2', 'placeholder' =>__('administrator.please_select'))); ?>

                                </div>
                            </div>
                            <div class="col-sm-4 form-group">
                                <div class="col-sm-2 form-group">
                                    <label><?php echo e(__('administrator.tailor')); ?></label>
                                </div>
                                <div class="col-sm-10 form-group">
                                    <?php echo Form::select('tailor_id', $tailor_id,null, array('class' => 'form-control select2', 'placeholder' =>__('administrator.please_select'))); ?>

                                </div>
                            </div>
                            <div class="col-sm-4">
                                <button type="button" class="btn btn-primary getHtmlForm" data-href="<?php echo e(route('production-request-add-more')); ?>" data-width="1000px" data-full_name="<?php echo e(__('administrator.production')); ?>"><i class="fa fa-plus"></i></button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="wrapper-table">
                <table id="print_table" class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th><?php echo e(__('administrator.type')); ?></th>
                        <th><?php echo e(__('administrator.date')); ?></th>
                        <th><?php echo e(__('administrator.reference_number')); ?></th>
                        <th><?php echo e(__('administrator.invoice_number')); ?></th>
                        <th><?php echo e(__('administrator.user')); ?></th>
                        <th><?php echo e(__('administrator.tailor')); ?></th>
                        <th><?php echo e(__('administrator.number_of_item')); ?></th>
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Show Cost')): ?>
                            <th><?php echo e(__('administrator.cost_per_item')); ?></th>
                            <th><?php echo e(__('administrator.total_amount')); ?></th>
                        <?php endif; ?>
                        <th><?php echo e(__('administrator.return_qty')); ?></th>
                        <th><?php echo e(__('administrator.status')); ?></th>
                        <th><?php echo e(__('administrator.action')); ?></th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script type="text/javascript">
        let table_ = $('#print_table');
        $(document).ready(function () {
            getTable();
            $('.select2').on('change', function () {
                getTable();
            });
            $(document).on('click', ' .to_packing', function () {
               getHtmlForm($(this).data('href'),'<?php echo e(__('administrator.add')); ?> <?php echo e(__('administrator.packing')); ?>','900px');
            });
            $(document).on('click', ' .show_request', function () {
                let id = $(this).data('id');
                $.ajax({
                    url: $(this).data('href'),
                    method: 'get',
                    dataType: 'json',
                    success: function (data) {
                        $.confirm({
                            title: '',
                            theme: 'modern',
                            useBootstrap: false,
                            escapeKey: 'close',
                            boxWidth: '50%',
                            content: data.html,
                            buttons: {
                                print: {
                                    text: '<?php echo e(__('administrator.print')); ?>',
                                    btnClass: 'button_info print_btn',
                                    action: function () {
                                        $('.production-request').printThis({
                                            loadCSS: "<?php echo e(asset('assets/css/bootstrap.min.css')); ?>",
                                            afterPrint: function () {
                                                window.location.reload();
                                            }
                                        });
                                    }
                                },
                                close: {
                                    text: '<?php echo e(__('administrator.close')); ?>',
                                    btnClass: 'button_warning',
                                },
                            },
                        });
                        if (data.status !== 0) {
                            setTimeout(function () {
                                $(document).find('.status_btn').remove();
                            }, 1);
                        }
                    }
                });
            });
            $(document).on('click', ' .return_item', function () {
                let this_ = $(this);
                let return_href = this_.data('return_href');
                let done_href = this_.data('done_href');
                let status = this_.data('status');
                $.ajax({
                    url: $(this).data('href'),
                    method: 'get',
                    dataType: 'html',
                    success: function (data) {
                        $.confirm({
                            title: '',
                            theme: 'modern',
                            useBootstrap: false,
                            escapeKey: 'close',
                            boxWidth: '60%',
                            content: data,
                            buttons: {
                                print: {
                                    text: '<?php echo e(__('administrator.print')); ?>',
                                    btnClass: 'button_info print_jquery_confirm',
                                },
                                return_item: {
                                    text: '<?php echo e(__('administrator.return_item')); ?>',
                                    btnClass: 'button_success status_btn',
                                    action: function () {
                                        $.ajax({
                                            url: return_href,
                                            method: 'get',
                                            dataType: 'html',
                                            success: function (data) {
                                                $.confirm({
                                                    title: '',
                                                    theme: 'modern',
                                                    useBootstrap: false,
                                                    escapeKey: 'close',
                                                    boxWidth: '50%',
                                                    content: data,
                                                    buttons: {
                                                        close: {
                                                            btnClass: 'button_warning click_close_form',
                                                            text: '<?php echo e(__('administrator.close')); ?>',
                                                            keys: ['esc'],
                                                        },
                                                        submit: {
                                                            text: '<?php echo e(__('administrator.submit')); ?>',
                                                            btnClass: 'button_primary',
                                                            action: function () {
                                                                let this_ = this;
                                                                this_.buttons.submit.disable();
                                                                setTimeout(function () {
                                                                    this_.buttons.submit.enable();
                                                                },3000);
                                                                this_.$content.find('form input[type=submit]').trigger('click');
                                                                return false;
                                                            }
                                                        }
                                                    }
                                                });
                                            }
                                        });
                                        return false;
                                    }
                                },
                                done: {
                                    text: '<?php echo e(__('administrator.done')); ?>',
                                    btnClass: 'button_primary status_btn',
                                    action: function () {
                                        let closest_ = this_.closest('tr');
                                        let date = closest_.find('td:nth-child(2)').text();
                                        let inv = closest_.find('td:nth-child(3)').text();
                                        let user = closest_.find('td:nth-child(4)').text();
                                        let tailor = closest_.find('td:nth-child(5)').text();
                                        let qty = closest_.find('td:nth-child(6)').text();
                                        let return_qty = closest_.find('td:nth-child(8)').text();
                                        let html = `
                                        <ul class="text-left">
                                            <li><?php echo e(__('administrator.date')); ?> : ${date}</li>
                                            <li><?php echo e(__('administrator.invoice_number')); ?> : ${inv}</li>
                                            <li><?php echo e(__('administrator.user')); ?> : ${user}</li>
                                            <li><?php echo e(__('administrator.tailor')); ?> : ${tailor}</li>
                                            <li><?php echo e(__('administrator.total_qty')); ?> : ${qty}</li>
                                            <li><?php echo e(__('administrator.return_qty')); ?> : ${return_qty}</li>
                                        </ul>
                                        `;
                                        confirmForm(done_href, '<?php echo e(__('administrator.are_you_sure')); ?>', html);
                                        return false;
                                    }
                                },
                                close: {
                                    text: '<?php echo e(__('administrator.close')); ?>',
                                    btnClass: 'button_warning click_close_form',
                                },
                            },
                        });
                        if (status) {
                            setTimeout(function () {
                                $(document).find('.status_btn').remove();
                            }, 1);
                        }
                    }
                });
            });
            table_.on('click','.btn_delete',function () {
                let this_ = $(this);
                let text = function (index) {return this_.closest('tr').find(`td:nth-child(${index})`).text();};
                let date = text(3);
                let inv = text(4);
                let tailor = text(5);
                let return_qty = text(10);
                confirmForm($(this).data('href'), '<?php echo e(__('administrator.are_you_sure')); ?>', `
                <div class="text-left">
                <p><?php echo e(__('administrator.date')); ?> : ${date}</p>
                <p><?php echo e(__('administrator.invoice_number')); ?> : ${inv}</p>
                <p><?php echo e(__('administrator.tailor')); ?> : ${tailor}</p>
                <p><?php echo e(__('administrator.return_qty')); ?> : ${return_qty} ឯកតា</p>
                </div>
                `, 'danger');
            })
        });

        function getTable() {
            let tailor_id = $('select[name=tailor_id]').val();
            let request_by = $('select[name=request_by]').val();
            table_.DataTable().destroy();
            table_.DataTable({
                ordering: false,
                serverSide: true,
                lengthMenu: [20, 30, 50, 100, 200, 500, 1000],
                ajax: {
                    url: "<?php echo e(route('production-request.index')); ?>",
                    data: {
                        request_by: request_by,
                        tailor_id: tailor_id
                    }
                },
                columns:
                    [
                        {data: 'DT_RowIndex','searchable':false},
                        {data: 'type'},
                        {data: 'date'},
                        {data: 'reference_invoice'},
                        {data: 'invoice_number'},
                        {data: 'user_id','searchable':false},
                        {data: 'tailor_id','searchable':false},
                        {data: 'total_item','searchable':false},
                            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Show Cost')): ?>
                        { data: 'cost_per_item','searchable':false},
                        {data: 'total','searchable':false},
                            <?php endif; ?>
                        { data: 'return_qty','searchable':false},
                        {data: 'done','searchable':false},
                        {data: 'action','searchable':false},
                    ],
                "initComplete": function (settings, json) {
                }
            });
        }

    </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/index.blade.php ENDPATH**/ ?>