<?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;

?>
<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">Sales Reports</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">Sales Reports</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">Sales Reports</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="<?php echo e(url('admin/sales-report')); ?>">
              <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 class="col-md-3">
                      <label class="form-label">Cashier</label>
                      <select class="js-select2 form-select" name="cashier" style="width: 100%;" data-placeholder="Select a cashier..">
                          <option hidden>Select</option>
                          <?php $__currentLoopData = $cashiers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cashier): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                              <option value="<?php echo e($cashier->user_id); ?>" <?php echo e(request('cashier') == $cashier->user_id ? 'selected' : ''); ?>>
                                  <?php echo e($cashier->name); ?>

                              </option>
                          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                      </select>
                      <?php if($errors->has('cashier')): ?> <div class="alert alert-danger mt-2"><?php echo e($errors->first('cashier')); ?></div> <?php endif; ?>
                  </div>
              </div>
              <button type="submit" class="btn btn-primary">Filter</button>
          </form>
            <table  id="example" class="custom-datatable display responsive nowrap" style="width:100%">
                <thead>
                  <tr>
                    <th>Date</th>
                    <th>Invoice No</th>
                    <th>Cashier</th>
                    <th>Gross Total</th>
                    <th>Total</th>
                    <th>Cash</th>
                    <th>Card</th>
                    <th>Card Ref</th>
                  </tr>
                </thead>
                <?php
$total_sub_total = 0;
$total_total = 0;
$total_cash_paid = 0;
$total_card_paid = 0;
?>
<tbody>
<?php foreach($orders as $order) {

  $cashier_role=User::withTrashed()->where('id', $order->sales_person)->value('user_role');
  $cashier_name = '-';
  if($cashier_role == 1){
      $cashier_name=AdminDetails::withTrashed()->where('user_id', $order->sales_person)->value('name');
  }
  if($cashier_role == 3){
      $cashier_name=ManagerDetails::withTrashed()->where('user_id', $order->sales_person)->value('name');
  }
  if($cashier_role == 4){
      $cashier_name=CashierDetails::withTrashed()->where('user_id', $order->sales_person)->value('name');
  }

  // Add to totals
  $total_sub_total += $order->sub_total;
  $total_total += $order->total;
  $total_cash_paid += $order->cash_paid_amount;
  $total_card_paid += $order->card_paid_amount;
?>
<tr>
    <td class="fw-semibold"><?php echo e($order->created_at->format('Y-m-d')); ?></td>
    <td class="fw-semibold"><?php echo e($order->sales_order_number); ?></td>
     <td class="fw-semibold"><?php echo e($cashier_name); ?></td>
    <td class="fw-semibold">LKR <?php echo e(number_format($order->sub_total)); ?></td>
    <td class="fw-semibold">LKR <?php echo e(number_format($order->total)); ?></td>
    <td class="fw-semibold">LKR <?php echo e(number_format($order->cash_paid_amount)); ?></td>
    <td class="fw-semibold">LKR <?php echo e(number_format($order->card_paid_amount)); ?></td>
    <td class="fw-semibold"><?php echo e($order->card_ref_no); ?></td>
  </tr>
<?php } ?>
</tbody>

<tfoot>
  <tr>
    <th colspan="3" class="text-end">Total:</th>
    <th>LKR <?php echo e(number_format($total_sub_total)); ?></th>
    <th>LKR <?php echo e(number_format($total_total)); ?></th>
    <th>LKR <?php echo e(number_format($total_cash_paid)); ?></th>
    <th>LKR <?php echo e(number_format($total_card_paid)); ?></th>
    <th></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-demo-site\Modules/Admin\resources/views/report/sales_reports.blade.php ENDPATH**/ ?>