<?php $__env->startSection('content'); ?>
    <?php
        $date       = @$_GET['date'];
        $customer   = @$_GET['customer'] ;
        $status     = @$_GET['status'] ;
        $sale_type  = @$_GET['sale_type'] ;
    ?>
    <?php Fun::lang()?>
    <style>
        .delivery-form td{
            padding: 3px;
            text-align: left;
        }
    </style>
    <div class="container-fluid">
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <?php echo Form::open(['route' => 'saller-request.index', 'method' => 'get']); ?>

                <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 form-group">
                    <label class="col-sm-3 col-form-label text-right"><?php echo e(__('administrator.type')); ?></label>
                    <div class="col-sm-9">
                        <?php echo Form::select('sale_type', ['retail'=>__('administrator.retail'),'wholesale'=>__('administrator.wholesale')] , $sale_type , ['placeholder'=>__('administrator.please_select'),'class' => 'form-control select2']); ?>

                    </div>
                </div>
                <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 form-group">
                    <label class="col-sm-3 col-form-label text-right"><?php echo e(__('administrator.customer')); ?></label>
                    <div class="col-sm-9">
                        <?php echo Form::select('customer', getCustomerByAgent(Auth::user()->id) , $customer , ['placeholder'=>__('administrator.please_select'),'class' => 'form-control select2']); ?>

                    </div>
                </div>
                <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 form-group">
                    <label class="col-sm-3 col-form-label text-right"><?php echo e(__('administrator.status')); ?></label>
                    <div class="col-sm-9">
                        <?php echo Form::select('status', getRequestStatus() , $status , ['placeholder'=>__('administrator.please_select'),'class' => 'form-control select2']); ?>

                    </div>
                </div>
                <div class="col-xs-3 col-sm-3 col-md-3 col-lg-3 form-group">
                    <label class="col-sm-3 col-form-label text-right "><?php echo e(__('administrator.date')); ?></label>
                    <div class="col-sm-9">
                        <input type="text" class="form-control date_picker" name="date"
                               value="<?php echo e($date?$date:''); ?>">
                    </div>
                </div>
                <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 form-group">
                    <div class="col-sm-12">
                        <button type="submit" class="button_info pull-right"><?php echo e(__('administrator.search')); ?></button>
                    </div>
                </div>
                <?php echo Form::close(); ?>


            </div>
        </div>
        <div class="row">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="row">
                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                        <h3><?php echo e(__('administrator.sale_request')); ?></h3>
                    </div>
                </div>
                <div class="container-fluid" style="background: white; padding:10px">
                    <div class="table-responsive">
                        <table id="customer" class="table">
                            <thead>
                                <tr>
                                    <th width="5%">#</th>
                                    <th><?php echo e(__('administrator.date')); ?></th>
                                    <th><?php echo e(__('administrator.invoice_number')); ?></th>
                                    <th><?php echo e(__('administrator.request_by')); ?></th>
                                    <th><?php echo e(__('administrator.customer')); ?></th>
                                    <th><?php echo e(__('administrator.discount')); ?> (%)</th>
                                    <th><?php echo e(__('administrator.paid')); ?> ($)</th>
                                    <th><?php echo e(__('administrator.total')); ?> ($)</th>
                                    <th><?php echo e(__('administrator.payment_status')); ?></th>
                                    <th><?php echo e(__('administrator.status')); ?></th>
                                    <th><?php echo e(__('administrator.delivery_number')); ?></th>
                                    <th><?php echo e(__('administrator.delivery_fee')); ?></th>
                                    <th><?php echo e(__('administrator.delivery_status')); ?></th>
                                    <th><?php echo e(__('administrator.action')); ?></th>
                                </tr>
                            </thead>

                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script type="text/javascript">
        $(document).ready(function () {
            setTimeout(function () {
                $.ajax({
                    url: '<?php echo e(route('update-seen-sale-request')); ?>',
                    success: function (data) {
                            console.log(data);
                    }
                });
            },5000);

            $(document).on('click', '.show_invoice', function () {
                var id = $(this).data('id');
                var status = $(this).data('status');
                var type = $(this).data('type');
                if(type=='retail'){
                    type = '';
                    var bwidth = '20%';
                    var print_this = '.invoice-box';

                }else{
                    type = '-wholesale';
                    var bwidth = '50%';
                    var print_this = '.print_invoice_wholesale';
                }
                if (id) {
                    $.ajax({
                        url: '<?php echo url("get'+type+'-invoice/'+id+'"); ?>',
                        success: function (data) {
                            let content_ = (data);
                            $.confirm({
                                title: '',
                                content: content_,
                                boxWidth: bwidth,
                                useBootstrap: false,
                                closeIcon: true,
                                buttons: {
                                    close: {
                                        text: '<?php echo e(__('administrator.close')); ?>',
                                        btnClass: 'button_warning ',
                                        keys: ['esc'],
                                        action: function () {

                                        }
                                    },
                                    print: {
                                        text: '<?php echo e(__('administrator.print')); ?>',
                                        btnClass: 'button_info',
                                        keys: ['enter'],
                                        action: function () {
                                            $(print_this).printThis({
                                                loadCSS: "<?php echo e(asset('assets/css/pos-invoice.css')); ?>",
                                                afterPrint: function () {
                                                    window.location.reload();
                                                }
                                            });
                                            return false
                                        }
                                    },
                                    <?php if(Auth::user()->user_type == 1): ?>
                                    approve: {
                                        text: '<?php echo e(__('administrator.approve')); ?>',
                                        btnClass: 'button_success ifstatus',
                                        action: function () {
                                            $.confirm({
                                                title: '<?php echo e(__('administrator.please_complete_information_below')); ?>',
                                                boxWidth: '30%',
                                                theme: 'modern',
                                                useBootstrap: false,
                                                content: `
                                                <form class="" action="<?php echo url("update-status-sale-request/1"); ?>" method="get">
                                                <table width="100%" class="delivery-form">
                                                <tr><td colspan="2" ><h4 class="text-center" style="margin-bottom:15px"><?php echo e(__('administrator.delivery_info')); ?></h4></td></tr>
                                                    <tr>
                                                        <td width="25%"><?php echo e(__('administrator.phone')); ?><span class="text-danger">*</span></td>
                                                        <td><input type="text" class="form-control" name="phone" value="" required  maxlength="30"></td>
                                                        <td><input type="hidden" name="id" value="`+id+`" required></td>
                                                    </tr>
                                                    <tr>
                                                        <td><?php echo e(__('administrator.delivery_fee')); ?> ($)<span class="text-danger">*</span></td>
                                                        <td><input type="text" class="form-control number-only" name="delivery_fee" value="" required maxlength="4"></td>
                                                    </tr>
                                                    <tr>
                                                        <td><span class="required"><?php echo e(__('administrator.note')); ?></td>
                                                        <td><textarea name="note" id="" class="no-resize form-control" maxlength="200"></textarea></td>
                                                    </tr>
                                                </table>
                                                <button type="submit" class="submit_delivery display-none"></button>
                                                </form>
                                    `,
                                                buttons: {
                                                    submit: {
                                                        text: '<?php echo e(__('administrator.approve')); ?>',
                                                        btnClass: 'button_primary',
                                                        action: function () {
                                                            $('.submit_delivery').trigger('click');
                                                            return false;
                                                        }
                                                    },
                                                    close: {
                                                        text: '<?php echo e(__('administrator.close')); ?>',
                                                        btnClass: 'button_warning',
                                                        action: function () {

                                                        }
                                                    },
                                                }
                                            });
                                            return false;
                                        }
                                    },
                                    reject: {
                                        text: '<?php echo e(__('administrator.reject')); ?>',
                                        btnClass: 'button_danger ifstatus',
                                        action: function () {
                                            $.confirm({
                                                title: '<?php echo e(__('administrator.are_you_sure')); ?>',
                                                content: '',
                                                buttons: {
                                                    submit: {
                                                        text: '<?php echo e(__('administrator.reject')); ?>',
                                                        btnClass: 'button_danger',
                                                        action: function () {
                                                            $.ajax({
                                                                url: '<?php echo url("update-status-sale-request/2?id='+id+'"); ?>',
                                                                async:false,
                                                                success: function (data) {
                                                                    if(data.status=='fail'){
                                                                        if(data.count>0){
                                                                            $.alert({
                                                                                theme:'modern',
                                                                                title:'<?php echo e(__('administrator.warning')); ?>',
                                                                                content:data.message,
                                                                            });
                                                                        }
                                                                    }else{
                                                                        window.location.reload();
                                                                    }
                                                                }
                                                            });
                                                        }
                                                    },
                                                    close: {
                                                        text: '<?php echo e(__('administrator.close')); ?>',
                                                        btnClass: 'button_warning',
                                                        action: function () {

                                                        }
                                                    },
                                                }
                                            });
                                            return false;
                                        }
                                    },
                                    <?php endif; ?>
                                }
                            });
                            setTimeout(function () {
                                if(status!=0){
                                    $('.ifstatus').remove();
                                }
                            },1);

                        }
                    });
                }
            });
        });
        $('#customer').DataTable({
            ordering: false,
            processing: false,
            serverSide: true,
            lengthMenu: [[20, 30, 50, 100, 200, 500, 1000], [20, 30, 50, 100, 200, 500, 1000]],
            ajax: {
                url: "<?php echo e(route('sale-request.index')); ?>",
                data:{
                    customer:'<?php echo e($customer); ?>',
                    date:'<?php echo e($date); ?>',
                    status:'<?php echo e($status); ?>',
                    sale_type:'<?php echo e($sale_type); ?>',
                }
            },
            columns:
                [
                    {data: 'DT_RowIndex', 'searchable': false},
                    {data: 'sale_date'},
                    {data: 'invoice_number'},
                    {data: 'user_id'},
                    {data: 'customer_id'},
                    {data: 'discount'},
                    {data: 'paid_amount_kh'},
                    {data: 'total'},
                    {data: 'payment_status'},
                    {data: 'status'},
                    {data: 'delivery_phone'},
                    {data: 'delivery_fee'},
                    {data: 'delivery_status'},
                    {data: 'action'},
                ],
            "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/branch/pos/sale-request/index.blade.php ENDPATH**/ ?>