<?php $__env->startSection('content'); ?>
    <?php Fun::lang()?>
<?php
    $from_date = @$_GET['from_date']?$_GET['from_date']:\Carbon\Carbon::now()->startOfMonth()->toDateString();
    $to_date = @$_GET['to_date']?$_GET['to_date']:\Carbon\Carbon::now()->EndOfMonth()->toDateString();
    $user_id = @$_GET['user_id'];
    $iloveucustomer = @$_GET['iloveucustomer'];
    $product_id = @$_GET['product_id'];
    $sale_type = @$_GET['sale_type'];
?>
    <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_sold_product_by_seller')); ?></h3>
                            </div>
                            <div class="pull-right">
                                <?php if(myBranch()->main): ?>
                                    <?php echo $__env->make('report.sale-report.sub-menu', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                                <?php endif; ?>
                            </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>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    <?php echo e(__('administrator.branch')); ?>

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

                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    <?php echo e(__('administrator.seller')); ?>

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

                                </div>
                            </div>
                            <div class="col-sm-3 col-md-3">
                                <div class="col-sm-3 col-md-3" style="margin-top: 5px">
                                    <?php echo e(__('administrator.product')); ?>

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

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

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

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

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

                                </div>
                            </div>

                            <div class=" col-sm-offset-6 col-sm-6">
                                <button class=" button_success pull-right print_button" type="button" data-text="<?php echo e(__('administrator.report_sold_product_by_seller')); ?>"><i class="fa fa-print "></i> <?php echo e(__('administrator.print')); ?></button>
                                <button class=" button_primary pull-right"  id="search" type="submit"> <?php echo e(__('administrator.search')); ?></button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <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.branch')); ?></th>
                        <th><?php echo e(__('administrator.sale_date')); ?></th>
                        <th><?php echo e(__('administrator.seller')); ?></th>
                        <th><?php echo e(__('administrator.products')); ?></th>
                        <th><?php echo e(__('administrator.sale_qty')); ?></th>
                        <th><?php echo e(__('administrator.total')); ?></th>
                    </tr>
                    </thead>
                    <tbody class="tbody">

                    </tbody>
                    <tr class="tfoot">
                        <th colspan="4" class="text-right"></th>
                        <th class="text-right"><?php echo e(__('administrator.total')); ?></th>
                        <th class="green f_total_item">0</th>
                        <th class="green f_total">0</th>
                    </tr>
                </table>
            </div>
        </div>
    </div>
        <?php $__env->stopSection(); ?>

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

            <script type="text/javascript">

                $(document).ready(function () {
                    dataTableFilter()
                });
                function dataTableFilter(type ='',user_id = '',customer_id ='',product_id='', start_date = '', end_date = '') {
                    let branch_id = $('select[name="branch_id"]').val();
                    $('#print_table').DataTable({
                        "oLanguage": {
                            "sSearch": "<?php echo e(__('administrator.search')); ?>:",
                            "sLengthMenu": "<?php echo e(__('administrator.display')); ?> _MENU_ <?php echo e(__('administrator.record_per_page')); ?>",
                            "sZeroRecords": "<?php echo e(__('administrator.Nothing_foundsorry')); ?>",
                            "sInfo": "<?php echo e(__('administrator.showing')); ?> _START_ <?php echo e(__('administrator.to')); ?> _END_ <?php echo e(__('administrator.of')); ?> _TOTAL_ <?php echo e(__('administrator.record')); ?>",
                            "sInfoEmpty": "<?php echo e(__('administrator.showing')); ?> 0 <?php echo e(__('administrator.to')); ?> 0 <?php echo e(__('administrator.of')); ?> 0 <?php echo e(__('administrator.record')); ?>",
                            "sInfoFiltered": "(<?php echo e(__('administrator.filter_form')); ?> _MAX_ <?php echo e(__('administrator.total_records')); ?>)",
                            "oPaginate": {
                                "sFirst": "<?php echo e(__('administrator.first')); ?>",
                                "sLast": "<?php echo e(__('administrator.last')); ?>",
                                "sNext": "<?php echo e(__('administrator.next')); ?>",
                                "sPrevious": "<?php echo e(__('administrator.previous')); ?>"
                            },
                        },

                        ordering: false,
                        serverSide: true,
                        lengthMenu: tbLeng,
                        ajax:{
                            url:"<?php echo e(route('sold-product-by-seller-report')); ?>",
                            data:{
                                type,
                                user_id,
                                customer_id,
                                product_id,
                                start_date,
                                end_date,
                                branch_id,
                            }
                       },
                        columns:
                            [
                                {data: 'DT_RowIndex', 'searchable': false},
                                {data: 'branch_id','searchable': false},
                                {data: 'sale_date', 'name': 'nso007_sales.sale_date'},
                                {data: 'user_id', 'searchable': false},
                                {data: 'product_id', 'searchable': false},
                                {data: 'sale_qty', 'searchable': false},
                                {data: 'total_amount', 'searchable': false},

                            ],
                        "fnDrawCallback":function () {
                            let tr = $('.tbody tr');
                            let total_usd = 0;
                            let total_riel = 0;
                            let t_r='';
                            let t_b='';
                            let total_qty=0;
                            $.each(tr,function (ii,vv) {
                                let amount = $(this).find('td:nth-child(7) span').data('amount');
                                let cur_id = $(this).find('td:nth-child(7) span').data('cur_id');
                                let qty = $(this).find('td:nth-child(6)').text();
                                qty = qty?parseFloat(qty):0;
                                total_qty+=qty;

                                amount = amount?parseFloat(amount):0;
                                if(cur_id===1){
                                    total_riel+=amount;
                                }
                                if(cur_id===2){
                                    total_usd+=amount;
                                }

                                t_r = total_usd?('$'+addComma(total_usd.toFixed(2))):'';
                                t_b = total_riel?('៛'+addComma(total_riel.toFixed(2))):'';

                            });
                            $('tr.tfoot:first-child ').find('.f_total_item').html(total_qty);
                            $('tr.tfoot:first-child ').find('.f_total').html((t_r?(t_r+'<br>'):'')+t_b);
                        },
                    });
                }
                $(document).on('click', '#search', function () {
                    let type = $('select[name="type"]').val();
                    let user_id = $('select[name="user_id"]').val();
                    let customer_id = $('select[name="customer_id"]').val();
                    let product_id = $('select[name="product_id"]').val();
                    let start_date = $('input[name="from_date"]').val();
                    let end_date = $('input[name="to_date"]').val();
                    $('#print_table').DataTable().destroy();
                    dataTableFilter(type,user_id,customer_id,product_id, start_date, end_date);
                });
            </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/sold-product-by-seller.blade.php ENDPATH**/ ?>