<?php $__env->startSection('content'); ?>
    <?php Fun::lang()?>
    <div class="container-fluid">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12 form-group">
                    <div class="title-add">
                        <div class="pull-left">
                            <h3 class="set_menu_name"></h3>
                        </div>
                    </div>
                </div>
            </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-12 col-sm-12 col-md-12 col-lg-12">
                        <form class="serialize_form">
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" >
                                    <?php echo e(__('administrator.seller')); ?>

                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    <?php echo Form::select('user_id', $user , null , ['placeholder'=>__('administrator.please_select'),'class' => 'form-control user_id']); ?>

                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" >
                                    <?php echo e(__('administrator.customer')); ?>

                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    <?php echo Form::select('customer', [] , null , ['placeholder'=>__('administrator.please_select'),'class' => 'search_customer form-control customer']); ?>

                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" >
                                    <?php echo e(__('administrator.from_date')); ?>

                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    <input type="text" class="form-control date_picker from_date" name="form_date" value="">
                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" >
                                    <?php echo e(__('administrator.to_date')); ?>

                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    <input type="text" class="form-control date_picker to_date" name="to_date" value="">
                                </div>
                            </div>
                        </form>
                        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 form-group">
                            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 ">
                                <button  class="button_info submit_data pull-right"><?php echo e(__('administrator.search')); ?></button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="container-fluid" style="background: white; padding:10px">
                    <div class="table-responsive">
                        <table id="data_table" class="table table-hover">
                            <thead>
                                <tr>
                                    <th width="2%">#</th>
                                    <th><?php echo e(__('administrator.type')); ?></th>
                                    <th><?php echo e(__('administrator.date')); ?></th>
                                    <th><?php echo e(__('administrator.seller')); ?></th>
                                    <th><?php echo e(__('administrator.invoice_number')); ?></th>
                                    <th><?php echo e(__('administrator.customer')); ?></th>
                                    <th><?php echo e(__('administrator.phone')); ?></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.owed_amount')); ?></th>
                                    <th><?php echo e(__('administrator.change_amount')); ?></th>
                                    <th><?php echo e(__('administrator.delivery_fee')); ?></th>
                                    <th><?php echo e(__('administrator.payment_status')); ?></th>
                                    <th width="15%"><?php echo e(__('administrator.action')); ?></th>
                                </tr>
                            </thead>
                            <tbody>

                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script type="text/javascript">
        $(document).ready(function () {
            getTable();
            $(document).on('click','.submit_data',function () {
                getTable();
            });
            $(document).on('click','.delete_sale',function () {
                let href = $(this).data('href')
                let text = $(this).data('text')
                if(href){
                    if (confirm(`delete ${text} ?`) == true) {
                        $.ajax({
                            url:href,
                            dataType:'json',
                            method:'DELETE',
                            success:function (data) {
                                new jBox('Notice', {
                                    content: `<span style="font-size: 20px">👍‍‍</span> បានលុប ${text}`,
                                    color: 'green',
                                    autoClose: 5000
                                });
                                getTable()
                            },
                            error(xhr){
                                alertErrorFormController(xhr);
                            }
                        });
                    }
                }
            });
            $(document).on('click','.show_edit',function () {
                let href= $(this).data('href');
                let edit_url= $(this).data('edit');
                $.ajax({
                    url:href,
                    dataType: 'html',
                    method: 'get',
                    success: function (data) {
                        $.confirm({
                            title: '',
                            theme: 'modern',
                            useBootstrap:false,
                            boxWidth:'70%',
                            closeAnimation: 'zoom',
                            content: data,
                            buttons: {
                                hidden: {
                                    btnClass: 'button_warning',
                                    text:'<?php echo e(__('administrator.close')); ?>',
                                    keys: ['esc'],
                                    action:function () {

                                    }
                                },
                                enter: {
                                    btnClass: 'button_info',
                                    text:'<?php echo e(__('administrator.print')); ?>',
                                    keys: ['enter'],
                                    action:function () {
                                        $('.print_this_form').printThis({
                                            //loadCSS: "<?php echo e(asset('assets/css/pos-invoice.css')); ?>",
                                            beforePrint: function () {
                                                $(document).find('button').hide();
                                            },
                                            afterPrint: function () {
                                                $(document).find('button').show();
                                            },
                                        });
                                        return false;
                                    }
                                },
                                edit: {
                                    btnClass: 'button_danger',
                                    text:'<?php echo e(__('administrator.edit')); ?>',
                                    action:function () {
                                        window.location.replace(edit_url);
                                        return false;
                                    }
                                },
                            },
                        });
                    },
                    error(xhr) {
                        alertErrorFormController(xhr);
                    }
                });
            });
        });
        function getTable(){
            let customer = $('.customer').val();
            let user_id = $('.user_id').val();
            let from_date = $('.from_date').val();
            let to_date = $('.to_date').val();
            $('#data_table').DataTable().destroy();
            $('#data_table').DataTable({
                ordering: false,
                processing: false,
                serverSide: true,
                lengthMenu: tbLeng,
                ajax: {
                    url: "",
                    data:{
                        customer,
                        from_date,
                        to_date,
                        user_id
                    },
                },
                columns:
                    [
                        {data: 'DT_RowIndex', 'searchable': false},
                        {data: 'sale_type'},
                        {data: 'sale_date'},
                        {data: 'user_id', 'searchable': false},
                        {data: 'invoice_number'},
                        {data: 'customer_id', 'searchable': false},
                        {data: 'customer_phone', 'searchable': false},
                        {data: 'discount', 'searchable': false},
                        {data: 'paid_amount', 'searchable': false},
                        {data: 'total', 'searchable': false},
                        {data: 'owed', 'searchable': false},
                        {data: 'change_amount', 'searchable': false},
                        {data: 'delivery_fee_amt', 'searchable': false},
                        {data: 'payment_status', '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/pos/all-sale-list/sale-history.blade.php ENDPATH**/ ?>