<?php

$getBal = new App\Models\AccountBalancesTrio();
$getOpenBal = new App\Models\OpenningAccountBalancesTrio();

?>
<?php $__env->startSection('content'); ?>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <br><br>
      <?php echo $__env->make('inc.contentheader', ['title' => 'Trial Balance' ], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
        <!-- Main content -->
        <section class="content">
            <div class="container-fluid">
                <!-- Small boxes (Stat box) -->
                <!-- /.row -->
                <!-- Main row -->
                <br>
                <br>
                <br>
                <div class="row">
                    <!-- Left col -->

                    <section class="col-lg-12 connectedSortable">
                        <div class="card card-primary">
                            <div class="card-header">
                              <b>Start:</b> <?php echo e(date('jS F Y',strtotime($start_date))); ?> <b>End:</b>  <?php echo e(date('jS F Y',strtotime($end_date))); ?>

                            </div>
                            <!-- /.card-header -->
                            <div class="card-body">


                                <div class="row">
                                    <div class="col-md-12">
                                        <br>
                                        <div class="panel-heading ">

                                        </div>

                                        <div class="card-body">
                                            <div class="row">
                                                <div class="col-12 col-sm-12 ">
                                                    <table class="table table-bordered table-striped">
                                                        <thead>
                                                            <tr>
                                                                <th scope="col">Account Number</th>
                                                                <th scope="col">Account Name</th>
                                                                <th scope="col">Debit</th>
                                                                <th scope="col">Credit</th>

                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php
                                                            $debit1 = 0;
                                                            $debit2 = 0;
                                                            $credit1 = 0;
                                                            $credit2 = 0;
                                                            $credit3 = 0;
                                                            $assets_total = 0;
                                                            ?>
                                                             <tr>
                                                                <td>

                                                                </td>

                                                                <td>
                                                                    <b>ClASS 1: REVENUE</b>
                                                                </td>
                                                                <td>
                                                                </td>
                                                                <td>
                                                                </td>
                                                            </tr>
                                                            <?php $revenue_total = 0; ?>
                                                            <?php $__currentLoopData = $account_group_revenue; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset_group_infor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <?php $__currentLoopData = $asset_group_infor->ledger_categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ledger_category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if(count($ledger_category->bank_accounts) != 0): ?>
                                                                        <?php $__currentLoopData = $ledger_category->bank_accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bank_account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                                                            <tr>
                                                                                <td>

                                                                                    <b><?php echo e($bank_account->account_number); ?></b>
                                                                                </td>
                                                                                <td>



                                                                                        <?php echo e($bank_account->name); ?>

                                                                                </td>


                                                                                <td>

                                                                                </td>
                                                                                <td>
                                                                                    <b><?php echo e(number_format($getBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date, $end_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date))); ?>

                                                                                        </b>

                                                                                    <b>

                                                                                    </b>

                                                                                    <?php $revenue_total =
                                                                                    $revenue_total +
                                                                                    $getBal->calculate_amount_on_accounts($bank_account->account_number,
                                                                                    $bank_account->id, 1, $start_date, $end_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date); ?>
                                                                                </td>
                                                                            </tr>

                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                        <?php $credit2 = $revenue_total; ?>
                                                                    <?php endif; ?>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            <tr>
                                                                <td>

                                                                </td>

                                                                <td>
                                                                    <b>ClASS 2: EXPENSES</b>
                                                                </td>
                                                                <td>
                                                                </td>
                                                                <td>
                                                                </td>
                                                            </tr>
                                                            <?php $expense_total = 0; ?>
                                                            <?php $__currentLoopData = $account_group_expenses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset_group_infor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <?php $__currentLoopData = $asset_group_infor->ledger_categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ledger_category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if(count($ledger_category->bank_accounts) != 0): ?>
                                                                        <?php $__currentLoopData = $ledger_category->bank_accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bank_account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                                                            <tr>
                                                                                <td>
                                                                                    <b><?php echo e($bank_account->account_number); ?></b>
                                                                                </td>
                                                                                <td>



                                                                                        <?php echo e($bank_account->name); ?>

                                                                                </td>


                                                                                <td>
                                                                                    <b><?php echo e(number_format($getBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date, $end_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date))); ?>

                                                                                        </b>

                                                                                    <?php $expense_total =
                                                                                    $expense_total +
                                                                                    $getBal->calculate_amount_on_accounts($bank_account->account_number,
                                                                                    $bank_account->id, 1, $start_date, $end_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date); ?>


                                                                                </td>
                                                                                <td>

                                                                                </td>
                                                                            </tr>

                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                        <?php $debit2 = $expense_total; ?>
                                                                    <?php endif; ?>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            <tr>
                                                                <td>

                                                                </td>

                                                                <td>
                                                                    <b>ClASS 3: ASSETS</b>
                                                                </td>
                                                                <td>
                                                                </td>
                                                                <td>
                                                                </td>
                                                            </tr>
                                                            <?php $__currentLoopData = $account_group_assets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset_group_infor3): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <?php $__currentLoopData = $asset_group_infor3->ledger_categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ledger_category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if(count($ledger_category->bank_accounts) != 0): ?>
                                                                        <?php $__currentLoopData = $ledger_category->bank_accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bank_account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                                                            <tr>
                                                                                <td>
                                                                                    <b><?php echo e($bank_account->account_number); ?></b>
                                                                                </td>
                                                                                <td>



                                                                                        <?php echo e($bank_account->name); ?>

                                                                                </td>


                                                                                <td>
                                                                                    <b><?php echo e(number_format($getBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date, $end_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date))); ?>

                                                                                        </b>

                                                                                    <?php $assets_total =
                                                                                    $assets_total +
                                                                                    $getBal->calculate_amount_on_accounts($bank_account->account_number,
                                                                                    $bank_account->id, 1, $start_date, $end_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date); ?>
                                                                                </td>
                                                                                <td>

                                                                                </td>
                                                                            </tr>
                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                        <?php $debit1 = $assets_total; ?>
                                                                    <?php endif; ?>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            <tr>
                                                                <td>

                                                                </td>

                                                                <td>
                                                                    <b>ClASS 4: LIABILITIES</b>
                                                                </td>
                                                                <td>
                                                                </td>
                                                                <td>
                                                                </td>
                                                            </tr>
                                                            <?php $liabilities_total = 0; ?>
                                                            <?php $__currentLoopData = $account_group_liabilities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset_group_infor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <?php $__currentLoopData = $asset_group_infor->ledger_categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ledger_category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if(count($ledger_category->bank_accounts) != 0): ?>
                                                                        <?php $__currentLoopData = $ledger_category->bank_accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bank_account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                                                            <tr>

                                                                                <td>
                                                                                    <b><?php echo e($bank_account->account_number); ?></b>
                                                                                </td>
                                                                                <td>



                                                                                        <?php echo e($bank_account->name); ?>

                                                                                </td>


                                                                                <td>

                                                                                </td>
                                                                                <td>
                                                                                    <?php $liabilities_total
                                                                                    = $liabilities_total +
                                                                                    $getBal->calculate_amount_on_accounts($bank_account->account_number,
                                                                                    $bank_account->id, 1, $start_date, $end_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date);

                                                                                    ?>

                                                                                    <b><?php echo e(number_format($getBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date, $end_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date))); ?>

                                                                                        </b>




                                                                                </td>
                                                                            </tr>

                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                        <?php $credit1 = $liabilities_total;
                                                                        ?>
                                                                    <?php endif; ?>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>


                                                            <tr>
                                                                <td>

                                                                </td>

                                                                <td>
                                                                    <b>ClASS 5: RESERVES</b>
                                                                </td>
                                                                <td>
                                                                </td>
                                                                <td>
                                                                </td>
                                                            </tr>
                                                            <?php $equity_total = 0; ?>
                                                            <?php $__currentLoopData = $account_group_equity; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset_group_infor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                <?php $__currentLoopData = $asset_group_infor->ledger_categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ledger_category): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                                    <?php if(count($ledger_category->bank_accounts) != 0): ?>
                                                                        <?php $__currentLoopData = $ledger_category->bank_accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $bank_account): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>


                                                                            <tr>
                                                                                <td>
                                                                                    <b><?php echo e($bank_account->account_number); ?></b>
                                                                                </td>
                                                                                <td>



                                                                                        <?php echo e($bank_account->name); ?>

                                                                                </td>


                                                                                <td>

                                                                                </td>
                                                                                <td>
                                                                                    <b><?php echo e(number_format($getBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date, $end_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date))); ?>

                                                                                        </b>

                                                                                    <?php $equity_total =
                                                                                    $equity_total +
                                                                                    $getBal->calculate_amount_on_accounts($bank_account->account_number,
                                                                                    $bank_account->id, 1, $start_date, $end_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date) + $getOpenBal->calculate_amount_on_accounts($bank_account->account_number, $bank_account->id, 1, $start_date); ?>
                                                                                </td>
                                                                            </tr>
                                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                                        <?php $credit3 = $equity_total; ?>
                                                                    <?php endif; ?>
                                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                                                            <tr>
                                                                <td>
                                                                    <h5><b> Total </b></h5>
                                                                </td>
                                                                <td>

                                                                </td>


                                                                <td>
                                                                    <?php echo e(number_format($debit1 + $debit2)); ?>

                                                                </td>
                                                                <td>
                                                                    <?php echo e(number_format($credit1 + $credit2 + $credit3)); ?>

                                                                </td>
                                                            </tr>
                                                        </tbody>
                                                    </table>

                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>
                            <!-- /.card-body -->
                        </div>
                    </section>
                    <!-- /.Left col -->
                </div>
                <!-- /.row (main row) -->
            </div><!-- /.container-fluid -->
        </section>
        <!-- /.content -->
    </div>
    <br><br><br><br><br><br><br>
    <?php echo $__env->make('inc.copyright', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.dashboard', ['title' => 'Trial Balance'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xamp\htdocs\esp_manager\resources\views/chartofaccounts/trialbalancev.blade.php ENDPATH**/ ?>