<?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.expense')); ?></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.item_cost')); ?></th>
                        <th><?php echo e(__('administrator.delivery_fee')); ?></th>
                        <th><?php echo e(__('administrator.discount')); ?></th>
                        <th><?php echo e(__('administrator.total')); ?></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_cost"></th>
                        <th class="green f_total_delivery"></th>
                        <th class="green f_total_discount"></th>
                        <th class="green f_total_amount"></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: 'item_cost', 'searchable': false},
                        {data: 'delivery_fee', 'searchable': false},
                        {data: 'discount', 'searchable': false},
                        {data: 'total', 'searchable': false},
                    ],
                "fnDrawCallback": function () {
                    let tr = $('.tbody .row_data');
                    let total_amount = [];
                    let total_cost = [];
                    let total_delivery = [];
                    let total_discount = [];
                    $.each(tr,function (i,v) {
                        let delivery_fee = toFloat($(this).data('delivery_fee'))
                        let cost = toFloat($(this).data('cost'))
                        let discount = toFloat($(this).data('discount'))
                        let total = toFloat($(this).data('total'))
                        let cur = $(this).data('cur')
                        total_amount[cur] = typeof total_amount[cur] === 'undefined'?total:(total_amount[cur]+total);
                        total_cost[cur] = typeof total_cost[cur] === 'undefined'?cost:(total_cost[cur]+cost);
                        total_delivery[cur] = typeof total_delivery[cur] === 'undefined'?delivery_fee:(total_delivery[cur]+delivery_fee);
                        total_discount[cur] = typeof total_discount[cur] === 'undefined'?discount:(total_discount[cur]+discount);
                    })

                    let total_amount_text = ''
                    let total_cost_text = ''
                    let total_delivery_text = ''
                    let total_discount_text = ''

                    let obj = Object.keys(total_amount);
                    $.each(obj,function (i,cur) {
                        total_amount_text+= `${total_amount[cur].toFixed(2)+cur}<br>`
                        total_cost_text+= `${total_cost[cur].toFixed(2)+cur}<br>`
                        total_delivery_text+= `${total_delivery[cur].toFixed(2)+cur}<br>`
                        total_discount_text+= `${total_discount[cur].toFixed(2)+cur}<br>`
                    })
                    $('.f_total_amount').html(total_amount_text)
                    $('.f_total_cost').html(total_cost_text)
                    $('.f_total_delivery').html(total_delivery_text)
                    $('.f_total_discount').html(total_discount_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/operation-expense.blade.php ENDPATH**/ ?>