<?php echo $__env->make('admin::layouts.header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php
use App\Models\AdminDetails;
use App\Models\ManagerDetails;
use App\Models\CashierDetails;;
use App\Models\User;
use App\Models\RevenuesAndExpenses;
?>
<main id="main-container">
        <!-- Hero -->
        <div class="bg-body-light">
          <div class="content content-full">
            <div class="d-flex flex-column flex-sm-row justify-content-sm-between align-items-sm-center">
              <h1 class="flex-grow-1 fs-3 fw-semibold my-2 my-sm-3">Profit & Loss Summery</h1>
              <nav class="flex-shrink-0 my-2 my-sm-0 ms-sm-3" aria-label="breadcrumb">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item">Dashboard</li>
                  <li class="breadcrumb-item">Report</li>
                  <li class="breadcrumb-item active" aria-current="page">>Profit & Loss Summery</li>
                </ol>
              </nav>
            </div>
          </div>
        </div>
        <!-- END Hero -->

        <!-- Page Content -->
        <div class="content">
          <!-- Your Block -->
          <div class="block block-rounded">
            <div class="block-header block-header-default">
              <h3 class="block-title">Profit & Loss Summery</h3>
            </div>
            <div class="block-content">
            <?php if(Session::has('success')): ?> <div class="alert alert-success mt-2 mb-2"><?php echo e(Session::get('success')); ?></div><?php endif; ?>
            <?php if(Session::has('fail')): ?> <div class="alert alert-danger mt-2 mb-2"><?php echo e(Session::get('fail')); ?></div><?php endif; ?>

            <form method="GET" action="">
              <div class="row mt-4 mb-4">
                  <div class="col-md-3">
                      <label class="form-label">Start Date</label>
                      <input type="date" class="form-control" name="start_date" value="<?php echo e(request('start_date')); ?>">
                      <?php if($errors->has('start_date')): ?> <div class="alert alert-danger mt-2"><?php echo e($errors->first('start_date')); ?></div> <?php endif; ?>
                  </div>
                  <div class="col-md-3">
                      <label class="form-label">End Date</label>
                      <input type="date" class="form-control" name="end_date" value="<?php echo e(request('end_date')); ?>">
                      <?php if($errors->has('end_date')): ?> <div class="alert alert-danger mt-2"><?php echo e($errors->first('end_date')); ?></div> <?php endif; ?>
                  </div>
                 
              </div>
              <button type="submit" class="btn btn-primary">Filter</button>
              <a href="<?php echo e(url('admin/profit-loss-summery')); ?>"><button type="button" class="btn btn-success">Clear</button></a>
          </form>
<table  id="example" class="custom-datatable display responsive nowrap" style="width:100%">
<thead>
    <tr>
    <th>Date</th>
    <th>Description</th>
    <th>Income</th>
    <th>Expense</th>
    </tr>
</thead>
          
<tbody>
<?php 
$expense_total = null;
$income_total = null;
foreach($revenues_and_expenses as $revenues_and_expense){ 
$income = null;
$expense = null;

$all_data = RevenuesAndExpenses::where('expense_category', $revenues_and_expense->expense_category)->get();
foreach($all_data as $all_da){
if($revenues_and_expense->type == 'expense'){
    $expense = $expense+$all_da->amount;
}
else{
    $income = $income+$all_da->amount;
}

}


$income_total = $income_total + $income;
$expense_total = $expense_total + $expense;


?>
<tr>
    <td><?php echo e($revenues_and_expense->date); ?></td>
    <td><?php echo e($revenues_and_expense->expense_category); ?></td>
    <td><?php echo e(number_format($income)); ?></td>
    <td><?php echo e(number_format($expense)); ?></td>
</tr>
<?php } ?>
<?php 
$sales_income = null;
if($orders){ 
foreach($orders as $order){ 
    $sales_income = $sales_income + $order->total;
} 
?>
<tr>
    <td><?php echo e($order->created_at->format('Y-m-d')); ?></td>
    <td>Sales Income</td>
    <td><?php echo e(number_format($sales_income)); ?></td>
    <td></td>
</tr>
<?php } ?>
</tbody>

<tfoot>
  <tr>
    <th colspan="2" class="text-end">Total:</th>
    <th><?php echo e(number_format($income_total+$sales_income)); ?></th>
    <th><?php echo e(number_format($expense_total)); ?></th>
  </tr>
  <tr>
    <th colspan="3" class="text-end">PnL:</th>
    <th><?php echo e(number_format(($income_total+$sales_income)-$expense_total)); ?></th>
  </tr>
</tfoot>

              </table>
            </div>
          </div>
          <!-- END Your Block -->
        </div>
        <!-- END Page Content -->
</main>
<!-- END Main Container -->
<?php echo $__env->make('admin::layouts.footer', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php /**PATH D:\Part Time Work\erp-napaskitchen\Modules/Admin\resources/views/report/profit_loss_summery.blade.php ENDPATH**/ ?>