Purchase Reports

@php $total_estimate = 0; $total_profit = 0; $total_loss = 0; $total_inv = 0; $total_hp = 0; @endphp @if($purchases->isNotEmpty()) @foreach($purchases as $purchase) @php $trc = 0; $total_pg = 0; $pQuery = $project->purchases()->where('sub_activity_id', $purchase->sub_activity_id); if(isset($dates['from']) && isset($dates['to'])){ $pQuery->whereBetween('delivery_date', [$dates['from'], $dates['to']]); } $pPurchases = $pQuery->get(); @endphp @if($pPurchases->isNotEmpty()) @foreach($pPurchases as $pPurchase) @php $trc = $trc + 1; $estimate = 0; $purchases = 0; $profit1 = 0; $profit = 0; $loss1 = 0; $loss = 0; $total_p = 0; $g_total = 0; $p_total = 0; $a = 0; $p = 0; $l = 0; $p1 = 0; $l1 = 0; $pcode = ""; $description = ""; $total_pg = ($total_pg + $pPurchase->orders->sum('total')); $total_pg = ($total_pg + $pPurchase->carriage_costs + $pPurchase->c_of_c + $pPurchase->other_costs); @endphp @foreach($pPurchase->orders as $order) @php $total_p = ($total_p + $order->total); $description = strstr($order->activityOfOrder->activity, '-', true); $a = $a + 1; if ($a > 1) { $description = "-"; } $estimate = $estimate + ((($order->activityOfOrder->rate * $order->activityOfOrder->quantity) * $pPurchase->subActivity->quantity) * $pPurchase->mainActivity->quantity); $pcode = $order->activityOfOrder->item_code; @endphp @endforeach @php $total_p = ($total_p + $pPurchase->carriage_costs + $pPurchase->c_of_c + $pPurchase->other_costs); $purchases = $total_p; $profit1 = ($estimate - $purchases); if($profit1 > 0){ $profit = $profit1; } $loss1 = ($purchases - $estimate); if($loss1 > 0){ $loss = $loss1; } $total_hp = ($total_hp+$total_p); @endphp @endforeach @endif @endforeach @endif
Purchase No. Project Description Delivery Date Supplier Name Invoice No Invoice Date Inv Amount Price Estimate Profit Loss Action
{{ $pPurchase->project->unique_reference_no }}-{{ str_pad($pPurchase->purchase_no, 3, '0', STR_PAD_LEFT) }} {{ $pcode }} {{ $description }} {{ date("d/m/Y", strtotime($pPurchase->delivery_date)) }} {{ $pPurchase->supplier->supplier_name }} @if($pPurchase->invoices->isNotEmpty()) @foreach($pPurchase->invoices as $invoice) {{ $invoice->invoice_no }}
@endforeach @endif
@if($pPurchase->invoices->isNotEmpty()) @foreach($pPurchase->invoices as $invoice) {{ date("d-m-Y", strtotime($invoice->invoice_date)) }}
@endforeach @endif
@if($pPurchase->invoices->isNotEmpty()) @foreach($pPurchase->invoices as $invoice) £{{ number_format($invoice->invoice_amount, 2) }}
@php $total_inv = $total_inv + $invoice->invoice_amount; @endphp @endforeach @endif
£{{ number_format($total_p, 2) }} @if ($trc == 1) @php $total_estimate = $total_estimate + $estimate; @endphp £{{ number_format($estimate, 2) }} @else - @endif @if ($trc == 1) @php $p1 = $estimate - $total_pg; @endphp @if ($p1 > 0) @php $p = $p1; @endphp @endif @php $total_profit = $total_profit + $p; @endphp @if ($p >= 0) £ {{ number_format((float)$p, 2) }} @endif @else - @endif @if ($trc == 1) @php $l1 = $total_pg - $estimate; @endphp @if ($l1 > 0) @php $l = $l1; @endphp @endif @php $total_loss = $total_loss + $l; @endphp @if ($l >= 0) £ {{ number_format((float)$l, 2) }} @endif @else - @endif
Totals : £{{ number_format($total_inv, 2) }} £{{ number_format($total_hp, 2) }} £{{ number_format($total_estimate, 2) }} @if ($total_profit >= 0) £{{ number_format((float)$total_profit, 2) }} @endif @if ($total_loss >= 0) £{{ number_format((float)$total_loss, 2) }} @endif