@if(($purchases ?? collect())->isEmpty() && ($production ?? collect())->isEmpty() && ($sales ?? collect())->isEmpty())
No data found for the selected filters.
@else
{{-- =======================
1) Cement Purchases
======================= --}}
| Date |
Supplier |
Quantity (Bags) |
Price per Bag |
Total Amount |
@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
| {{ optional($purchase->created_at)->format('d M Y') }} |
{{ $supplierName }} |
{{ number_format($qty) }} |
{{ number_format($unit, 2) }} |
{{ number_format($amount, 2) }} |
@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
| 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
======================= --}}
| Date |
Cement (Bags) |
Good Bricks |
Status |
@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
| {{ optional($prod->created_at)->format('d M Y') }} |
{{ number_format($cement) }} |
{{ number_format($good) }} |
{{ $status }} |
@endforeach
| Total Cement Used: |
{{ number_format($totalCementUsed) }} bags |
| Total Good Bricks: |
{{ number_format($totalGoodBricks) }} |
{{-- =======================
3) Cement Sales
======================= --}}
| Date |
Quantity (Bags) |
Buying Price |
Selling Price |
Total Amount |
Profit Gained |
@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
| {{ \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) }}
|
@endforeach
| 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
======================= --}}
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