<?php $__env->startSection('content'); ?>
    <?php Fun::lang()?>
    <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.transfers_stock')); ?></h3>
                            </div>
                            <div class="pull-right">
                                <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Request Stock Create')): ?>
                                    <a href="<?php echo e(route('transfer-stock.create')); ?>" class=" button_info"><span
                                            class="fa fa-plus"></span> <?php echo e(__('administrator.add_new')); ?></a>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <br>&nbsp;
            <br>
            <div class="wrapper-table">
                <table id="print_table" class="table table-striped table-hover">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th><?php echo e(__('administrator.invoice_number')); ?></th>
                        <th><?php echo e(__('administrator.branch')); ?></th>
                        <th><?php echo e(__('administrator.from_warehouse')); ?></th>
                        <th><?php echo e(__('administrator.to_warehouse')); ?></th>
                        <th><?php echo e(__('administrator.date')); ?></th>
                        <th><?php echo e(__('administrator.confirm_received')); ?></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">
        function getTable() {
            $('#print_table').DataTable().destroy();
            $('#print_table').DataTable({
                ordering: false,
                serverSide: true,
                lengthMenu: [20, 30, 50, 100, 200, 500, 1000],
                ajax: {
                    url: "<?php echo e(route('transfer-stock.index')); ?>",
                },
                columns:
                    [
                        {data: 'DT_RowIndex', 'searchable': false},
                        {data: 'invoice_number', 'name': 'nso007_transfer_stock.invoice_number'},
                        {data: 'branch_id', 'searchable': false},
                        {data: 'from_warehouse_id', 'searchable': false},
                        {data: 'to_warehouse_id', 'searchable': false},
                        {data: 'date', 'searchable': false},
                        {data: 'confirm_status', 'searchable': false},
                        {data: 'action', 'searchable': false},

                    ],

                "initComplete": function (settings, json) {
                }
            });
        }

        $(document).ready(function () {
            getTable();
            $('.select2').on('change', function () {
                let supplier = $('select[name=supplier]').val();
                let type = $('select[name=type]').val();
                getTable(supplier, type);
            });

            $(document).on('click', ' .show_request', function () {
                let id = $(this).data('id');
                let confirm_status = $(this).data('confirm_status');
                $.ajax({
                    url: $(this).data('href'),
                    method: 'get',
                    dataType: 'json',
                    success: function (data) {
                        $.confirm({
                            title: '',
                            theme: 'modern',
                            useBootstrap: false,
                            boxWidth: '50%',
                            content: data.view,
                            buttons: {
                                close: {
                                    text: '<?php echo e(__('administrator.close')); ?>',
                                    btnClass: 'button_warning',
                                },
                                print: {
                                    text: '<?php echo e(__('administrator.print')); ?>',
                                    btnClass: 'button_info',
                                    keys: ['enter'],
                                    action: function () {
                                        $('.page-purchases').printThis({
                                            loadCSS: "<?php echo e(asset('assets/css/pos-invoice.css')); ?>",
                                            afterPrint: function () {
                                                window.location.reload();
                                            }
                                        });
                                        return false;
                                    },
                                },

                                confirm_received: {
                                    text: '<?php echo e(__('administrator.confirm_received')); ?>',
                                    btnClass: 'button_success confirm_status',
                                    keys: ['enter'],
                                    action: function () {
                                        show_alert({status:1,id:id,text:'<?php echo e(__('administrator.confirm_received')); ?>',btnClass:'button_primary'})
                                        return false
                                    }
                                },
                                seller_reject: {
                                    text: '<?php echo e(__('administrator.reject')); ?>',
                                    btnClass: 'button_danger confirm_status',
                                    keys: ['enter'],
                                    action: function () {
                                        show_alert({status:2,id:id,text:'<?php echo e(__('administrator.reject')); ?>',btnClass:'button_danger'})
                                        return false
                                    }
                                }
                            },
                        });
                        setTimeout(function () {
                            if (confirm_status === 0) {
                                $('.confirm_status').remove();
                            }
                        }, 100);

                    }
                });
            });
        });

        function show_alert(obj = {status: '', id: '', text: '', btnClass: ''}) {
            if (!obj.status || !obj.id) return false

            $.confirm({
                title: obj.text,
                theme: 'modern',
                content: '<?php echo e(__('administrator.are_you_sure')); ?>',
                buttons: {
                    cancel: {
                        btnClass: 'button_warning',
                        text: '<?php echo e(__('administrator.cancel')); ?>',
                    },
                    confirm_received: {
                        btnClass: obj.btnClass+' btn_alert',
                        text: obj.text,
                        action: function () {
                            $(document).find('.btn_alert').prop('disabled',true)
                            $.ajax({
                                url: `<?php echo route("transfer-stock-confirm"); ?>`,
                                method: 'POST',
                                data: {
                                    id: obj.id,
                                    status: obj.status
                                },
                                success: function (data) {
                                    if(data.status){
                                        getTable();
                                        $(document).find('.button_warning').trigger('click');
                                        new jBox('Notice', {
                                            content: '<span style="font-size: 20px">👍‍‍</span> បានជោគជ័យ',
                                            color: 'green'
                                        });
                                    }

                                }
                            });

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