<?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.income')); ?></h3>
                            </div>
                            <div class="pull-right">
                                <?php echo $__env->make('report.income.sub-menu-income', \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_data">
                                <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('01-m-Y'), 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('t-m-Y'), array('placeholder' => __('administrator.to_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.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']); ?>

                                    </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']); ?>

                                    </div>
                                </div>
                            </form>
                            <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_sale_detail')); ?>"><i class="fa fa-print "></i> <?php echo e(__('administrator.print')); ?></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.sale_date')); ?></th>
                        <th><?php echo e(__('administrator.seller')); ?></th>
                        <th><?php echo e(__('administrator.branch')); ?></th>
                        <th><?php echo e(__('administrator.invoice_number')); ?></th>
                        <th><?php echo e(__('administrator.amount')); ?></th>
                        <th><?php echo e(__('administrator.remain')); ?></th>
                        <th><?php echo e(__('administrator.change_amount')); ?></th>
                        <th><?php echo e(__('administrator.balance')); ?></th>
                    </tr>
                    </thead>
                    <tbody class="tbody"></tbody>
                    <tfoot class="tfoot">
                    <tr>
                        <th class="text-right" colspan="5"><?php echo e(__('administrator.total')); ?></th>
                        <th class="green f_total_amount"></th>
                        <th class="green f_total_remain"></th>
                        <th class="green"></th>
                        <th class="green f_total_balance"></th>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

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

    <script type="text/javascript">
        $(document).ready(function () {
            dataTableFilter();
            $('.form_data input,.form_data select').on('change', function () {
                dataTableFilter();
            });
        });

        function dataTableFilter() {
            $('#print_table').DataTable().destroy();
            $('#print_table').DataTable({
                ordering: false,
                serverSide: true,
                lengthMenu: tbLeng,
                ajax: {
                    url: "?" + $('.form_data').serialize(),
                },
                columns:
                    [
                        {data: 'DT_RowIndex', 'searchable': false},
                        {data: 'sale_date', 'searchable': false},
                        {data: 'user_id', 'searchable': false},
                        {data: 'branch_id', 'searchable': false},
                        {data: 'invoice_number', 'searchable': false},
                        {data: 'grand_total', 'searchable': false},
                        {data: 'remain', 'searchable': false},
                        {data: 'change', 'searchable': false},
                        {data: 'balance', 'searchable': false},
                    ],
                "fnDrawCallback": function () {
                    let tr = $('.tbody .row_data');
                    let total_amount = [];
                    let total_remain = [];
                    let total_balance = [];
                    $.each(tr,function (i,v) {
                        let amount = toFloat($(this).data('grand_total'))
                        let remain = toFloat($(this).data('remain'))
                        let balance = toFloat($(this).data('balance'))
                        let cur = $(this).data('cur')
                        total_amount[cur] = typeof total_amount[cur] === 'undefined'?amount:(total_amount[cur]+amount);
                        total_remain[cur] = typeof total_remain[cur] === 'undefined'?remain:(total_remain[cur]+remain);
                        total_balance[cur] = typeof total_balance[cur] === 'undefined'?balance:(total_balance[cur]+balance);

                    })
                    let total_amount_text = ''
                    let total_remain_text = ''
                    let total_balance_text = ''

                    let obj = Object.keys(total_amount);
                    $.each(obj,function (i,cur) {
                        total_amount_text+= `${total_amount[cur].toFixed(2)+cur}<br>`
                        total_remain_text+= `${total_remain[cur].toFixed(2)+cur}<br>`
                        total_balance_text+= `${total_balance[cur].toFixed(2)+cur}<br>`
                    })
                    $('.f_total_amount').html(total_amount_text)
                    $('.f_total_remain').html(total_remain_text)
                    $('.f_total_balance').html(total_balance_text)

                },
            });
        }

        $(document).on('click', '#search', function () {
            dataTableFilter();
        });
    </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/income/income.blade.php ENDPATH**/ ?>