<?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_payment')); ?></h3>
                            </div>
                            <div class="pull-right">
                                <?php echo $__env->make('administrator.reportpayment.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>

                            <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('seller',$seller,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="margin-top: 5px">
                                    <?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="margin-top: 5px">
                                    <?php echo e(__('administrator.status')); ?>

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

                                </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', 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="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', null, array('placeholder' => __('administrator.to_date'),'class' => 'form-control date_picker','autocomplete' => 'off','required')); ?>

                                </div>
                            </div>


                            <div class="col-sm-offset-6 col-sm-6">
                                <button type="submit" class=" button_success pull-right print_button" data-text="<?php echo e(__('administrator.report_sales_request_payment')); ?>"
                                        type="button"><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.invoice')); ?></th>
                        <th><?php echo e(__('administrator.date')); ?></th>
                        <th><?php echo e(__('administrator.seller')); ?></th>
                        <th><?php echo e(__('administrator.customer_name')); ?></th>
                        <th><?php echo e(__('administrator.contact')); ?></th>
                        <th><?php echo e(__('administrator.amount')); ?></th>
                        <th><?php echo e(__('administrator.paid')); ?></th>
                        <th><?php echo e(__('administrator.remain_amount')); ?></th>
                        <th><?php echo e(__('administrator.status')); ?></th>
                    </tr>
                    </thead>
                    <tbody class="tbody"></tbody>
                    <tr class="tfoot">
                        <th colspan="6" class="text-right"><?php echo e(__('administrator.total_amount')); ?></th>
                        <th class="total_amt green">0</th>
                        <th class="total_paid green">0</th>
                        <th class="total_remain green">0</th>
                        <th></th>
                    </tr>
                </table>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script type="text/javascript">
        $(document).ready(function () {
            dataTableFilter()
        });
        function dataTableFilter( seller='', customer_id='',status = '', start_date = '', end_date = '' ) {
            let path = window.location.pathname.replace('/','');
            $('#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(url('report-sale-request-payment')); ?>",
                    data: {
                        path,
                        seller,
                        customer_id,
                        status,
                        start_date,
                        end_date,
                    },
                },
                columns:
                    [
                        {data: 'DT_RowIndex', 'searchable': false},
                        {data: 'invoice_number','name':'nso007_sales.invoice_number'},
                        {data: 'payment_date','searchable': false},
                        {data: 'user_id','searchable': false},
                        {data: 'name','name': 'nso007_customers.name'},
                        {data: 'phone','name': 'nso007_customers.phone'},
                        {data: 'payment_amount','searchable': false},
                        {data: 'paid_amount','searchable': false},
                        {data: 'remain','searchable': false},
                        {data: 'payment_status','searchable': false},
                    ],
                "fnDrawCallback":function () {
                    let tr = $('.tbody tr');
                    let total_amt_usd = 0,total_amt_riel = 0,total_paid_riel = 0,total_paid_usd = 0,total_remain_riel = 0,total_remain_usd = 0,ta_r='',ta_u='',tp_r='',tp_u='',tr_r='',tr_u='';
                    $.each(tr,function (ii,vv) {
                        let amt_row = $(this).find('.payment_amount')
                        let paid_row = $(this).find('.paid_amount')
                        let remain_row = $(this).find('.remain_amount')
                        let cur_id = amt_row.data('currency_id');

                        let amount = amt_row.data('amount')
                        amount = amount?parseFloat(amount):0;

                        let paid = paid_row.data('amount')
                        paid = paid?parseFloat(paid):0;

                        let remain = remain_row.data('amount')
                        remain = remain?parseFloat(remain):0;

                        if(cur_id===1){
                            total_amt_riel+=amount;
                            total_paid_riel+=paid;
                            total_remain_riel+=remain;
                        }
                        if(cur_id===2){
                            total_amt_usd+=amount;
                            total_paid_usd+=paid;
                            total_remain_usd+=remain;
                        }
                    });
                    ta_r = total_amt_riel?('៛'+addComma(total_amt_riel.toFixed(2))):'';
                    ta_u = total_amt_usd?('$'+addComma(total_amt_usd.toFixed(2))):'';

                    tp_r = total_paid_riel?('៛'+addComma(total_paid_riel.toFixed(2))):'';
                    tp_u = total_paid_usd?('$'+addComma(total_paid_usd.toFixed(2))):'';

                    tr_r = total_remain_riel?('៛'+addComma(total_remain_riel.toFixed(2))):'';
                    tr_u = total_remain_usd?('$'+addComma(total_remain_usd.toFixed(2))):'';


                    $('.tfoot .total_amt').html((ta_r?(ta_r+'<br>'):'0')+ta_u);
                    $('.tfoot .total_paid').html((tp_r?(tp_r+'<br>'):'0')+tp_u);
                    $('.tfoot .total_remain').html((tr_r?(tr_r+'<br>'):'0')+tr_u);
                },
            });
        }
        $(document).on('click', '#search', function () {
            let seller = $('select[name="seller"]').val();
            let customer_id = $('select[name="customer_id"]').val();
            let status = $('select[name="status"]').val();
            let start_date = $('input[name="from_date"]').val();
            let end_date = $('input[name="to_date"]').val();
            $('#print_table').DataTable().destroy();
            dataTableFilter( seller,customer_id,status,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/administrator/reportpayment/index.blade.php ENDPATH**/ ?>