<?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; ?>
        <?php echo $__env->make('installments.inc.montly_payment', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title"><?php echo trans("profits.detail"); ?> - <?php echo d_format($start); ?></h3>
            </div>
            <div class="box-body">
                <table class="table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th><?php echo trans("dashboard.id"); ?></th>
                        <th style="width: 20%;"><?php echo trans('reports.user'); ?></th>
                        <th><?php echo trans("invoices.menu"); ?></th>
                        <th><?php echo trans("profits.description"); ?></th>
                        <th><?php echo trans('reports.profit_types.income'); ?> </th>
                        <th><?php echo trans('reports.profit_types.expense'); ?> </th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php if(count($profits) > 0): ?>
                        <?php
                        $i = 1;
                        $totalIncome = 0;
                        $totalExpense = 0;
                        ?>
                        <?php foreach($profits as $profit): ?>
                            <?php
                            $totalIncome += $profit->type == "income" ? $profit->amount : 0;
                            $totalExpense += $profit->type == "expense" ? $profit->amount : 0;
                            ?>
                            <tr>
                                <td><?php echo $i; ?></td>
                                <td><?php echo $profit->first_name; ?> <?php echo $profit->last_name; ?></td>
                                <td>
                                    <?php if($profit->installment_id): ?>
                                        <a href="<?php echo route('installments.show', $profit->installment_id); ?>"><?php echo convertInvoiceNumber($profit->installment_id); ?></a>
                                    <?php elseif($profit->mortgage_id): ?>
                                        <a href="<?php echo route("mortgages.show", $profit->mortgage_id); ?>"><?php echo convertInvoiceNumber($profit->mortgage_id); ?></a>
                                    <?php else: ?>
                                        <?php if($profit->receipt_id): ?>
                                            <?php
                                            $payment = DB::table("payments")->where("receipt_id", $profit->receipt_id)->first();
                                            ?>
                                            <?php if(!empty($payment)): ?>
                                                <a href="<?php echo route('installments.paymentHistory', $payment->id); ?>" class="btn btn-sm btn-success btn-payment-history"><i class="fa fa-history"></i></a>
                                            <?php endif; ?>
                                            <?php
                                            $mortgagePayment = DB::table("mortgage_payments")->where("receipt_id", $profit->receipt_id)->first();
                                            ?>
                                                <?php if(!empty($mortgagePayment)): ?>
                                                    <a href="<?php echo route('mortgage_payments.history', $mortgagePayment->id); ?>" class="btn btn-sm btn-success btn-payment-history"><i class="fa fa-history"></i></a>
                                                <?php endif; ?>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                </td>
                                <td><?php echo $profit->description; ?></td>
                                <td><?php echo $profit->type == "income" ? money($profit->amount) : 0; ?></td>
                                <td><?php echo $profit->type == "expense" ? money($profit->amount) : 0; ?></td>
                            </tr>
                            <?php $i++; ?>
                        <?php endforeach; ?>
                        <tr>
                            <td colspan="4" class="text-right"><?php echo trans("reports.total"); ?></td>
                            <td><strong><?php echo money($totalIncome); ?></strong></td>
                            <td><strong><?php echo money($totalExpense); ?></strong></td>
                        </tr>
                    <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </section>
<?php $__env->stopSection(); ?>
<?php $__env->startSection("addJs"); ?>
    <?php echo HTML::script("js/loan.js"); ?>

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