@extends('layouts.master') @section('page_title', 'Stock Report') @section('title', 'Stock Report') @section('main_item', 'Reports') @section('sub_item', 'Stock Report') @section('content')

Filter

business_location != '1') style="display: none" @endif>
Reset
Download Excel

@csrf
@php $total_current_stock = 0; $total_purchase_value = 0; $total_sale_value = 0; $total_potential_profit = 0; $total_units_sold = 0; @endphp @foreach($products as $product) @php $current_stock = 0; $purchase_value = 0; $sale_value = 0; // Calculate current stock $current_stock += $product->stocks->sum('qty'); $parent_products = App\Product::where('parent_product_id', $product->id)->get(); foreach ($parent_products as $parent_product) { $current_stock += $parent_product->stocks->sum('qty'); } // Calculate costs and selling prices foreach ($product->stocks as $stock) { $purchase_value += $stock->qty * $stock->unit_cost; $sale_value += $stock->qty * $stock->unit_price; } $potential_profit = $sale_value - $purchase_value; $min_price = $product->stocks->min('unit_price'); $max_price = $product->stocks->max('unit_price'); $selling_price = $min_price == $max_price ? number_format($min_price, 2) : number_format($min_price, 2) . ' - ' . number_format($max_price, 2); $min_cost = $product->stocks->min('unit_cost'); $max_cost = $product->stocks->max('unit_cost'); $purchase_price = $min_cost == $max_cost ? number_format($min_cost, 2) : number_format($min_cost, 2) . ' - ' . number_format($max_cost, 2); // Query attributes and quantities $stocks = DB::table('stocks') ->leftJoin('products', 'stocks.product_id', '=', 'products.id') ->where('products.id', '=', $product->id) ->orWhere('products.parent_product_id', $product->id) ->select('stocks.qty', 'products.attribute_value') ->get(); // Update total values $total_current_stock += $current_stock; $total_purchase_value += $purchase_value; $total_sale_value += $sale_value; $total_potential_profit += $potential_profit; $total_units_sold += $product->saleItems->sum('qty'); @endphp @endforeach
SKU Business Location Product Name Product Image Attribute
value And Qty
Current Stock Purchase Price Selling Price Current Stock Value
(by purchase price)
Current Stock Value
(by sale price)
Potential Profit Total Unit Sold
{{ $product->sku ?? 'N/A' }} {{ $product->productHasBusinessLocations->map(function ($location) { return $location->locationDeatils->name; })->implode(', ') }} {{ $product->product_name }}
@foreach ($stocks as $stock) @endforeach
{{ $stock->attribute_value }} {{ $stock->qty }}
{{ $current_stock }} {{ $purchase_price }} {{ $selling_price }} {{ number_format($purchase_value, 2) }} {{ number_format($sale_value, 2) }} {{ number_format($potential_profit, 2) }} {{ $product->saleItems->sum('qty') }}
Total {{ $total_current_stock }} {{ number_format($total_purchase_value, 2) }} {{ number_format($total_sale_value, 2) }} {{ number_format($total_potential_profit, 2) }} {{ $total_units_sold }}
{!! $products->links() !!}
@endsection @section('scripts') @endsection