@extends('layouts.main') @section('content')

Cement Stock Movement Report

Filter Report
{{-- FILTER FIELDS ROW --}}
{{-- ✅ WORKSTATION DROPDOWN --}}
{{-- ACTIONS ROW (perfect alignment) --}}
Reset
{{-- EXPORT --}} Export
@if(($purchases ?? collect())->isEmpty() && ($production ?? collect())->isEmpty() && ($sales ?? collect())->isEmpty())
No data found for the selected filters.
@else {{-- ======================= 1) Cement Purchases ======================= --}}
1. Cement Purchases (Bought In)
@foreach(($purchases ?? collect()) as $purchase) @php $supplierName = $purchase->supplier_name ?? (isset($purchase->supplier) && $purchase->supplier ? $purchase->supplier->name : ''); $qty = (float) ($purchase->total ?? 0); $unit = $purchase->bought_price ?? $purchase->purchase_cost_per_unit ?? 0; $unit = (float) str_replace(',', '', (string)$unit); $amount = $unit * $qty; @endphp @endforeach @php $totalPurchaseQty = (float) ($purchases ?? collect())->sum('total'); $totalPurchaseAmount = (float) ($purchases ?? collect())->sum(function($p){ $qty = (float)($p->total ?? 0); $unit = $p->bought_price ?? $p->purchase_cost_per_unit ?? 0; $unit = (float) str_replace(',', '', (string)$unit); return $qty * $unit; }); @endphp
Date Supplier Quantity (Bags) Price per Bag Total Amount
{{ optional($purchase->created_at)->format('d M Y') }} {{ $supplierName }} {{ number_format($qty) }} {{ number_format($unit, 2) }} {{ number_format($amount, 2) }}
Total Purchases {{ number_format($totalPurchaseQty) }} - {{ number_format($totalPurchaseAmount, 2) }}
@php $productionIds = ($production ?? collect())->pluck('id')->toArray(); $stockBricksMap = \App\Models\StockBrick::whereIn('stock_id', $productionIds) ->get() ->keyBy('stock_id'); $totalCementUsed = 0; $totalGoodBricks = 0; @endphp {{-- ======================= 2) Cement Used in Production ======================= --}}
2. Cement Used in Production
@foreach(($production ?? collect()) as $prod) @php $sb = $stockBricksMap[$prod->id] ?? null; $good = $sb ? (int)($sb->total_bricks_without_fault ?? 0) : 0; $expected = $sb ? (int)($sb->expected_output ?? 0) : 0; $actual = $sb ? (int)($sb->actual_output ?? 0) : 0; $status = ($sb && $expected > 0 && $actual <= 0) ? 'Actual Output Not Given' : ''; $cement = (int)($prod->total ?? 0); $totalCementUsed += $cement; $totalGoodBricks += $good; @endphp @endforeach
Date Cement (Bags) Good Bricks Status
{{ optional($prod->created_at)->format('d M Y') }} {{ number_format($cement) }} {{ number_format($good) }} {{ $status }}
Total Cement Used: {{ number_format($totalCementUsed) }} bags
Total Good Bricks: {{ number_format($totalGoodBricks) }}
{{-- ======================= 3) Cement Sales ======================= --}}
3. Cement Sales ({{ \Carbon\Carbon::parse($startDate)->format('d M Y') }} - {{ \Carbon\Carbon::parse($endDate)->format('d M Y') }})
@php $totalQuantity = 0; $totalAmount = 0; $totalBuying = 0; $totalSelling = 0; $totalProfitGained = 0; @endphp @foreach(($sales ?? collect()) as $sale) @php $qty = (int)($sale->quantity ?? 0); $buy = (float) str_replace(',', '', (string)($sale->buying_price ?? 0)); $sell = (float) str_replace(',', '', (string)($sale->selling_price ?? 0)); $amount = $qty * $sell; $cost = $qty * $buy; $profitGained = $amount - $cost; $totalQuantity += $qty; $totalAmount += $amount; $totalBuying += $buy; $totalSelling += $sell; $totalProfitGained += $profitGained; @endphp @endforeach
Date Quantity (Bags) Buying Price Selling Price Total Amount Profit Gained
{{ \Carbon\Carbon::parse($sale->created_at)->format('d M Y') }} {{ number_format($qty) }} {{ number_format($buy, 2) }} {{ number_format($sell, 2) }} {{ number_format($amount, 2) }} {{ number_format($profitGained, 2) }}
Total Sales {{ number_format($totalQuantity) }} {{ number_format($totalBuying, 2) }} {{ number_format($totalSelling, 2) }} {{ number_format($totalAmount, 2) }} {{ number_format($totalProfitGained, 2) }}
{{-- ======================= 4) Current Stock Summary ======================= --}}
4. Current Stock Summary
Stock Movement
Opening Stock (as of {{ $startDate->format('d M Y') }}) {{ number_format($openingStock ?? 0) }} bags
Total Purchased {{ number_format(($purchases ?? collect())->sum('total')) }} bags
Total Used in Production {{ number_format(($production ?? collect())->sum('total')) }} bags
Total Sold {{ number_format(($sales ?? collect())->sum('quantity')) }} bags
Closing Stock (as of {{ $endDate->format('d M Y') }}) {{ number_format($closingStock ?? 0) }} bags
Stock Value
Average Purchase Rate {{ number_format($averageRate ?? 0, 2) }} per bag
Average Sale Rate {{ number_format($averageSaleRate ?? 0, 2) }} per bag
Current Stock Value {{ number_format(($closingStock ?? 0) * ($averageRate ?? 0), 2) }}
@endif
@endsection @section('scripts') @endsection