<?php

$getBal = new App\Models\AccountBalances();
$getOpenBal = new App\Models\OpenningAccountBalances();

?>
<?php $__env->startSection('content'); ?>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <br><br><br>
        <?php echo $__env->make('inc.contentheader', ['title' => 'Current Month: '.date('F',strtotime($start_date)) ], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<br><br>
      <!-- Main content -->
      <section class="content">
            <div class="container-fluid">
              <!-- Small boxes (Stat box) -->
              <!-- /.row -->
              <!-- Main row -->
              <div class="row">
                <!-- Left col -->
                <section class="col-lg-12 connectedSortable">
                    <div class="card card-primary">
                        <div class="card-header">
                            Current Month Stats:<b></b>
                        </div>
                        <!-- /.card-header -->
                        <div class="card-body">


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

                                  <div class="card-body">
                                      <div class="row">
                                          <div class="col-12 col-sm-12 assets_container">
                                            <table width="100%" border="0" class="table table-bordered table-striped">
                                                <tr>
                                                    <td>
                                                        <b>No. of Beneficiaries: <?php echo number_format($stt); ?></b>
                                                    </td>
                                                    <td>
                                                        <b>No. of DLG(s): <?php echo number_format($dlg); ?></b>
                                                    </td>
                                                </tr>
                                                <tr>
                                                  <td>

                                                    <?php $total_rev = 0; $overall_rev = 0; $total_op_rev = 0; $total_op_non = 0; $total_op_non1 = 0;  ?>

                                                    <?php $__currentLoopData = $account_group_revenue; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset_group_infor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                  <table width="100%" border="0">
                                                    <?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(); ?>
                                                    <?php if
                                                                            (number_format($getBal->calculate_amount_on_accounts($bank_account->account_number,
                                                                            $bank_account->id, 1, $start_date, $end_date)) != 0) { ?>
                                                    <?php $rev_exp = substr($bank_account->account_number, 0, 3);

                                                    //var_dump($lia_exp);

                                                    $revlevel = $rev_exp

                                                     ?>
                                                     <?php if('133' == $revlevel): ?>
                                                     <?php

                                                     $total_rev = 0;


                                                      $total_op_rev = $total_op_rev + $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);

                                                      $total_rev = $total_op_rev;


                                                     ?>

                                                     <?php elseif('142' == $revlevel): ?>
                                                     <?php

                                                     $total_rev = 0;

                                                     $total_op_non = $total_op_non + $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);

                                                     $total_rev = $total_op_non;


                                                     ?>
                                                     <?php elseif('145' == $revlevel): ?>
                                                     <?php

                                                     $total_rev = 0;

                                                     $total_op_non1 = $total_op_non1 + $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);

                                                     $total_rev = $total_op_non1;


                                                     ?>
                                                     <?php endif; ?>

                                                    <?php } ?>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

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





                                                </td>
                                                  <td>
                                                    <?php $overall = 0; $totalexp1 = $totalexp2 = $totalexp3 = $totalexp4 = 0; $exp1 = 0; $exp2 = 0; $exp3 = 0; $exp4 = 0; ?>
                                                    <?php $__currentLoopData = $account_group_expenses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset_group_infor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <table width="100%" border="0">
                                                      <?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(); ?>
                                                      <?php $expl = substr($bank_account->account_number, 0, 2);

                                                      //var_dump($exp);

                                                      $explevel = $expl;

                                                       ?>
                                                       <?php if('21' == $explevel): ?>
                                                       <?php

                                                       $totalexp1 = 0;


                                                        $exp1 = $exp1 + $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);

                                                        $totalexp1 = $exp1;


                                                       ?>

                                                       <?php elseif('22' == $explevel): ?>
                                                       <?php

                                                       $totalexp2 = 0;

                                                       $exp2 = $exp2 + $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);

                                                       $totalexp2 = $exp2;


                                                       ?>

                                                        <?php elseif('26' == $explevel): ?>
                                                        <?php

                                                        $totalexp3 = 0;

                                                        $exp3 = $exp3 + $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);

                                                        $totalexp3 = $exp3;


                                                        ?>

                                                        <?php elseif('28' == $explevel): ?>
                                                            <?php

                                                            $totalexp4 = 0;

                                                            $exp4 = $exp4 + $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);

                                                            $totalexp4 = $exp4;


                                                            ?>

                                                       <?php endif; ?>

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

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


                                                   </td>
                                                </tr>
                                                <tr>
                                                  <td><b>CLASS 1: REVENUE: <?php echo e(number_format($total_rev)); ?></b></td>
                                                  <td><b>CLASS 2 : EXPENSES: <?php echo e(number_format($totalexp1 + $totalexp2 + $totalexp3 + $totalexp4)); ?></b></td>
                                                </tr>
                                                <tr>
                                                  <td></td>
                                                  <td>&nbsp;</td>
                                                </tr>

                                                <tr>
                                                  <td>
                                                    <?php $overall = 0; $totalass1 = $totalass2 = 0; $total_non = $total_current = 0; $total_op_non1 = 0; $total_other = 0; ?>
                                                    <?php $__currentLoopData = $account_group_assets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset_group_infor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <table width="100%" border="0">
                                                      <?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(); ?>
                                                      <?php $exp = substr($bank_account->account_number, 0, 2);

                                                      //var_dump($exp);

                                                      $assetlevel = $exp;

                                                       ?>
                                                       <?php if('31' == $assetlevel): ?>
                                                       <?php

                                                       $totalass1 = 0;


                                                        $total_current = $total_current + $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);

                                                        $totalass1 = $total_current;


                                                       ?>

                                                       <?php elseif('32' == $assetlevel): ?>
                                                       <?php

                                                       $totalass2 = 0;

                                                       $total_non = $total_non + $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);

                                                       $totalass2 = $total_non;


                                                       ?>

                                                       <?php endif; ?>

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

                                                      <?php endif; ?>
                                                      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </table>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                  </td>
                                                  <td>
                                                    <?php $overall_lia = 0; $total_lia_current = 0; $total_lia_non = 0;  ?>
                                                    <?php $__currentLoopData = $account_group_liabilities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset_group_infor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <table width="100%" border="0">
                                                      <?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(); ?>
                                                      <?php $lia_exp = substr($bank_account->account_number, 0, 2);

                                                      //var_dump($lia_exp);

                                                      $lialevel = $lia_exp;

                                                       ?>
                                                       <?php if('41' == $lialevel): ?>
                                                       <?php

                                                       $total_lia = 0;


                                                        $total_lia_current = $total_lia_current + $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);

                                                        $total_lia = $total_lia_current;


                                                       ?>


                                                       <?php endif; ?>


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

                                                      <?php endif; ?>
                                                      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </table>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                  </td>
                                                </tr>
                                                <tr>
                                                  <td><b>CLASS 3: ASSETS: <?php echo e(number_format($totalass2 + $totalass1)); ?></b></td>
                                                  <td><b>CLASS 4: LIABILITIES: <?php echo e(number_format($total_lia)); ?></b></td>
                                                </tr>
                                                <tr>
                                                  <td></td>
                                                  <td></td>
                                                </tr>

                                                <tr>
                                                  <td>
                                                    <?php $overall_equity = 0; $total_owners = 0; $total_ownerwquity = 0;?>
                                                    <?php $__currentLoopData = $account_group_equity; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $asset_group_infor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <table width="100%" border="0">
                                                      <?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(); ?>
                                                      <?php $equi_exp = substr($bank_account->account_number, 0, 2);

                                                      //var_dump($lia_exp);

                                                      $equilevel = $equi_exp;

                                                       ?>
                                                       <?php if('51' == $equilevel): ?>
                                                       <?php

                                                       $total_ownerwquity = 0;


                                                        $total_owners = $total_owners + $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);

                                                        $total_ownerwquity = $total_owners;


                                                       ?>

                                                       <?php endif; ?>


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

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

                                                  </td>
                                                  <td></td>
                                                </tr>
                                                <tr>
                                                  <td><b>CLASS 5 : RESERVES: <?php echo e(number_format($total_ownerwquity)); ?></b></td>
                                                  <td>&nbsp;</td>
                                                </tr>
                                              </table>
                                            <br><br>


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

                            </div>
                        </div>
                        <!-- /.card-body -->
                      </div>
                </section>
                <!-- /.Left col -->
              </div>
              <!-- /.row (main row) -->
            </div><!-- /.container-fluid -->
          </section>
          <!-- /.content -->
    </div>
    <?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' => 'Balance Sheet'], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xamp\htdocs\esp_manager\resources\views/chartofaccounts/balancesheethome.blade.php ENDPATH**/ ?>