<?php echo $__env->make('admin::layouts.header', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php
use App\Models\Categories;
use App\Models\Supliers;
use App\Models\Brands;
use App\Models\Stock;
use App\Models\Products;
use App\Models\Batches;
?>
<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">Inventory 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">Inventory 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">Inventory 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; ?>
            <table  id="example" class="custom-datatable display responsive nowrap" style="width:100%">
                <thead>
                  <tr>
                    <th>Item</th>
                    <th>IN Quantity</th>
                    <th>OUT Quantity</th>
                    <th>Stock In-Hand</th>
                  </tr>
                </thead>
                <tbody>
                <?php foreach($products as $product) {
                    $stocks = Stock::where('product', $product->id)->where('is_free', 0)->get();
                    $in_quantity = 0;
                    $out_quantity = 0;
                    $avilable_quantity = 0;
                    foreach($stocks as $stock){
                      $in_quantity = $in_quantity+$stock->initial_stock;
                      $avilable_quantity = $avilable_quantity+$stock->avilable_stock;

                      $free_in_quantity = 0;
                      $free_avilable_quantity = 0;

                      $free_stock = Stock::where('grn_id', $stock->grn_id)->where('batch', $stock->batch)->where('product', $stock->product)->where('is_free', 1)->first();
                      if($free_stock){
                        $free_in_quantity = $free_in_quantity+$free_stock->initial_stock;
                        $free_avilable_quantity = $free_avilable_quantity+$free_stock->avilable_stock;
                      }

                      $in_quantity = $in_quantity+$free_in_quantity;
                      $avilable_quantity = $avilable_quantity+$free_avilable_quantity;
                    }
                    $out_quantity = $in_quantity - $avilable_quantity;

                ?>
                  <tr>
                    <td class="fw-semibold">
                    <?php echo e($product->product_name); ?>

                    </td>
                     <td class="fw-semibold">
                    <?php echo e(number_format($in_quantity)); ?>

                    </td>
                     <td class="fw-semibold">
                    <?php echo e(number_format($out_quantity)); ?>

                    </td>
                    <td class="fw-semibold">
                    <?php echo e(number_format($avilable_quantity)); ?>

                    </td>
                  </tr>
                <?php } ?>
                </tbody>
              </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 /home/u446954234/domains/orionerp.xyz/public_html/indianheavenrestaurant/Modules/Admin/resources/views/report/inventory_reports.blade.php ENDPATH**/ ?>