<?php $__env->startSection('content'); ?>
    <section class="content-header">
        <h1>
            <?php echo Trans('reports.menu'); ?>

            <small><?php echo Trans('reports.sub_title'); ?></small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="/"><i class="fa fa-dashboard"></i> Home</a></li>
            <li class="active"><a href="#"><i class="fa fa-usd"></i> <?php echo Trans('reports.menu'); ?></a></li>
            <li class="active"><a href="#"><?php echo Trans('reports.sub_title'); ?></a></li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <?php if(Session::has('message')): ?>
            <p class="alert alert-warning">
                <?php echo Trans(Session::get('message')); ?>

            </p>
        <?php endif; ?>
        <div class="box box-body">
            <?php echo Form::open(['method' => 'get']); ?>

            <div class="row">
                <div class="col-md-3">
                    <div class="form-group">
                        <label for="start_date"><?php echo trans('invoices.start_date'); ?></label>
                        <div class="input-group date">
                            <?php
                            $value = Request::get('start_date') ? Request::get('start_date') : null;

                            ?>
                            <?php echo Form::text('start_date', $value, [
                              'class' => "form-control",
                              'placeholder' => Trans('invoices.start_date'),
                              'autocomplete' => "off",
                              'id' => 'start_date'
                            ]); ?>

                            <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <label for="start_date"><?php echo trans('invoices.end_date'); ?></label>
                    <div class="form-group">
                        <div class="input-group date">
                            <?php
                            $value = Request::get('end_date') ? Request::get('end_date') : null;

                            ?>
                            <?php echo Form::text('end_date', $value, [
                              'class' => "form-control",
                              'placeholder' => Trans('invoices.end_date'),
                              'id' => 'end_date',
                              'autocomplete' => "off"
                            ]); ?>

                            <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="form-group">
                        <label for=""><?php echo trans("reports.show"); ?></label>
                        <?php
                        $selected = Input::get('paginate') ? Input::get('paginate') : 10;
                        ?>
                        <?php echo Form::select("paginate", [
                            'all'   =>  "All",
                            10      =>  10,
                            15      =>  15,
                            20      =>  20,
                            25      =>  25,
                            30      =>  30,
                            50      =>  50,
                            100     => 100
                        ], $selected, [
                            'class' => 'form-control select2',
                          ]); ?>

                    </div>
                </div>
                <div class="col-md-3">
                    <div class="pull-right">
                        <br>
                        <button type="submit" class="btn btn-info" name="search" value="true"><i
                                    class="fa fa-search"></i> <?php echo Trans('invoices.search'); ?></button>
                    </div>
                </div>
            </div>
            <?php echo Form::close(); ?>

            <div class="row">
                <br>
                <div class="col-md-12">
                    <table class="table table-striped table-bordered">
                        <thead>
                        <tr>
                            <th style="width: 10%;"><?php echo trans('products.id'); ?></th>
                            <th><?php echo trans('reports.created_at'); ?></th>
                            <th><?php echo trans('reports.profit_types.expense'); ?> </th>
                            <th><?php echo trans('reports.profit_types.income'); ?> </th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php
                        $totalIncome = 0;
                        $totalExpense = 0;
                        $i = 1;
                        ?>
                        <?php if(count($profits) > 0): ?>
                            <?php foreach($profits as $profit): ?>
                                <?php
                                $totalIncome += $profit->totalIncome;
                                $totalExpense += $profit->totalExpense;
                                ?>
                                <tr>
                                    <td><?php echo $i; ?></td>
                                    <td><a href="<?php echo route('reports.profits.show', $profit->byDay); ?>"><?php echo d_format($profit->byDay); ?></a></td>
                                    <td><?php echo $profit->totalExpense > 0 ? money($profit->totalExpense) : 0; ?></td>
                                    <td><?php echo $profit->totalIncome > 0 ? money($profit->totalIncome) : 0; ?></td>
                                </tr>
                                <?php $i++; ?>
                            <?php endforeach; ?>
                            <tr>
                                <td class="text-right" colspan="2"><?php echo trans('reports.total'); ?></td>
                                <td><strong><?php echo money($totalExpense); ?></strong></td>
                                <td><strong><?php echo money($totalIncome); ?></strong></td>
                            </tr>
                        <?php else: ?>
                            <tr>
                                <td colspan="5" class="text-center"><?php echo trans('reports.no_row'); ?></td>
                            </tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            <?php if(!empty(Input::get("paginate")) && Input::get("paginate") != "all"): ?>
                <div class="row">
                    <div class="col-md-4">
                        <p style="margin-top: 10px;">Total Records : <?php echo $profits->getTotal(); ?> Page <?php echo $profits->getCurrentPage(); ?> of <?php echo $profits->getLastPage(); ?></p>
                    </div>
                    <div class="col-md-8 text-right">
                        <?php echo $profits->appends(Request::except('page'))->links(); ?>

                    </div>
                </div>
            <?php else: ?>
                <?php if(count($profits) > 0): ?>
                    Total Records : <?php echo count($profits); ?>

                <?php endif; ?>
            <?php endif; ?>
            </div>
        </div>
    </section>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('addJs'); ?>
    <?php echo HTML::script('plugins/datepicker/bootstrap-datepicker.js'); ?>

    <?php echo HTML::script('plugins/datepicker/locales/bootstrap-datepicker.kh.js'); ?>

    <script>
        $("#start_date, #end_date").datepicker({
            format: 'dd/mm/yyyy',
            language: 'kh',
            autoclose: true,
            todayHighlight: true
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.production', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>