<?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\GRNProducts;
?>
<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">Cost Report</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">Cost Report</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">Cost Report</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 class="table table-bordered table-striped table-vcenter js-dataTable-buttons">
                <thead>
                  <tr>
                  <th>Product Name</th>
                  <th>Product Code</th>
                  <th>Parent Category</th>
                  <th>Brand</th>
                  <th>Selling Price</th>
                   <th>Cost</th>
                   <th>QTY</th>
                   <th>Cost Total</th>
                   <th>Selling Total</th>
                   <th>Margin</th>
                   <th>Margin (%)</th>
                  </tr>
                </thead>
                <tbody>
                <?php foreach($products as $product) {
                    $grn_product = GRNProducts::where('product', $product->id)->first();

                    $cost_total = ($grn_product->wholesale_purchase_price ?? 0) * ($grn_product->quantity ?? 0);
                    $selling_total = ($grn_product->retail_selling_price ?? 0) * ($grn_product->quantity ?? 0);

                    $margin = $selling_total - $cost_total;
                    $margin_percentage = $selling_total != 0 ? ($margin / $selling_total) * 100 : 0;
                ?>
                  <tr>
                    <td class="fw-semibold">
                    <?php echo e($product->product_name); ?>

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

                    </td>
                    <td class="fw-semibold">
                    <?php echo e(Categories::where('id', $product->parent_category)->value('category_name')); ?>

                    </td>
                    <td class="fw-semibold">
                    <?php echo e(Brands::where('id', $product->brand)->value('brand_name')); ?>

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

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

                    </td>
                     <td class="fw-semibold">
                    <?php echo e($grn_product->quantity ?? 0); ?>

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

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

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

                    </td>
                    <td class="fw-semibold">
                    <?php echo e(number_format($margin_percentage, 2)); ?>%
                    </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 /var/www/erpadmin_ori_usr/data/www/erpadmin.orionux.xyz/Modules/Admin/resources/views/report/cost_report.blade.php ENDPATH**/ ?>