<?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 form-group">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3><?php echo e(__('administrator.report_sales_request')); ?></h3>
                            </div>
                            <div class="pull-right">
                                    <?php echo $__env->make('report.sale-report.sub-menu', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group paddin-0">
                        <div>
                            <form class="form">
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3">
                                    <?php echo e(__('administrator.type')); ?>

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

                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="">
                                    <?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']); ?>

                                </div>
                            </div>

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

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

                                </div>
                            </div>

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

                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    <?php echo Form::text('from_date', null, array('placeholder' => __('administrator.from_date'),'class' => 'form-control date_picker','autocomplete' => 'off','required')); ?>

                                </div>
                            </div>

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

                                </div>
                                <div class="form-group col-sm-9 col-md-9">
                                    <?php echo Form::text('to_date', null, array('placeholder' => __('administrator.to_date'),'class' => 'form-control date_picker','autocomplete' => 'off','required')); ?>

                                </div>
                            </div>
                            </form>
                            <div class="col-sm-offset-6 col-sm-6">
                                <button class=" button_success pull-right print_button" data-text="<?php echo e(__('administrator.report_sales')); ?>" type="button"><i class="fa fa-print"></i> <?php echo e(__('administrator.print')); ?></button>
                                <button class=" button_primary pull-right" id="search" type="button"> <?php echo e(__('administrator.search')); ?></button>
                                <button class=" button_warning pull-right btn_clear" type="button"><i class="fa fa-times"></i> <?php echo e(__('administrator.clear')); ?></button>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
            <?php
                $role_val = DB::table('model_has_roles')->where('model_id',Auth::user()->id)->first();
                $role_val = \Spatie\Permission\Models\Role::find($role_val?$role_val->role_id:0);
                $role_val = $role_val?$role_val->name:'';
                $role_val= $role_val!=='Stock Controller';

            ?>
            <div class="wrapper-table">
                <table id="print_table" width="100%" class="table table-striped table-hover ">
                    <thead>
                    <tr>
                        <th>#</th>
                        <th><?php echo e(__('administrator.type')); ?></th>
                        <th><?php echo e(__('administrator.invoice')); ?></th>
                        <th><?php echo e(__('administrator.sale_date')); ?></th>
                        <th><?php echo e(__('administrator.seller')); ?></th>
                        <th><?php echo e(__('administrator.customer_name')); ?></th>
                        <th><?php echo e(__('administrator.customer_phone')); ?></th>
                        <?php if($role_val): ?>
                            <th><?php echo e(__('administrator.payment_status')); ?></th>
                            <th><?php echo e(__('administrator.delivery_fee')); ?></th>
                            <th><?php echo e(__('administrator.more_fee')); ?></th>
                            <th><?php echo e(__('administrator.total')); ?></th>
                        <?php endif; ?>
                    </tr>
                    </thead>
                    <tbody class="tbody"></tbody>
                    <?php if($role_val): ?>
                        <tr class="tfoot">
                            <th colspan="8" class="text-right"></th>
                            <th class="text-right"></th>
                            <th class="text-right"></th>
                            <th class="green"></th>
                        </tr>
                    <?php endif; ?>
                </table>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('script'); ?>

    <script type="text/javascript">
        $(document).ready(function () {
            dataTableFilter();
            $('.tbody').on('click', '.show_invoice', function () {
                getHtmlFormShow($(this).data('href'), '900px');
            });
            $(document).on('click', '#search', function () {
                dataTableFilter();
            });
            $(document).on('click', '.btn_clear', function () {
                $('.form').trigger('reset')
                $('select[name="customer_id"]').val('').change()
                dataTableFilter();
            });
        });


        function dataTableFilter() {
            let type = $('select[name="type"]').val();
            let customer_id = $('select[name="customer_id"]').val();
            let start_date = $('input[name="from_date"]').val();
            let end_date = $('input[name="to_date"]').val();
            let user_id = $('select[name="user_id"]').val();
            $('#print_table').DataTable().destroy();
            $('#print_table').DataTable({
                searching: false,
                ordering: false,
                serverSide: true,
                lengthMenu: tbLeng,
                ajax: {
                    url: "<?php echo e(route('get-report-sale')); ?>",
                    data: {
                        type,
                        user_id,
                        customer_id,
                        start_date,
                        end_date,
                        report_type: '<?php echo e($report_type); ?>'
                    }
                },
                columns:
                    [
                        {data: 'DT_RowIndex'},
                        {data: 'sale_type'},
                        {data: 'invoice_number'},
                        {data: 'sale_date'},
                        {data: 'user_id'},
                        {data: 'customer_id'},
                        {data: 'customer_phone'},
                        <?php if($role_val): ?>
                        {data: 'payment_status'},
                        {data: 'delivery_fee'},
                        {data: 'more_fee'},
                        {data: 'amount'},
                        <?php endif; ?>
                    ],
                "fnDrawCallback": function () {
                    let tr = $('.tbody tr');
                    let total_usd = 0;
                    let total_riel = 0;
                    let t_u = '';
                    let t_r = '';
                    $.each(tr, function (ii, vv) {
                        let amount = $(this).find('td:nth-child(11) span').data('amount');
                        let cur_id = $(this).find('td:nth-child(11) span').data('cur_id');
                        amount = amount ? parseFloat(amount) : 0;
                        if (cur_id === 2) {
                            total_usd += amount;
                        }
                        if (cur_id === 1) {
                            total_riel += amount;
                        }
                        t_u = total_usd ? ('$' + addComma(total_usd.toFixed(2))) : '';
                        t_r = total_riel ? ('៛' + addComma(total_riel.toFixed(2))) : '';

                    });
                    $('tr.tfoot:first-child ').find('.green').html((t_u ? (t_u + '<br>') : '') + t_r);
                }
            });
        }
    </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/report/sale-report/index.blade.php ENDPATH**/ ?>