Branchwise Stock Report

Branch Stock Report

@php $material = \App\Models\Material::latest(); if ($search != '') { $material->where(function ($query2) use ($search) { $query2->where('name', 'like', '%' . $search . '%'); }); } $materials = $material->get(); @endphp @if($search != '') Search Term : {{ $search }}
@endif @if ($branch_id != '') @php $branchUser = \App\Models\User::where('id', $branch_id)->first(); @endphp

[{{ $branchUser->name }}]

@else

[{{ 'All Branches' }}]

@endif @php $total_count = 0; $i = 1; @endphp

@foreach ($materials as $row) @php /* sales */ if ($branch_id != '') { $invoices = \App\Models\Invoice::where('branch_id', $branch_id)->get(); } else { $invoices = \App\Models\Invoice::get(); } $sales_count = 0; foreach ($invoices as $base_invoice_row) { $invoice_details = \App\Models\InvoiceDetail::where('invoice_id', $base_invoice_row->id) ->where('type', 2) ->get(); foreach ($invoice_details as $invoice_row) { if ($invoice_row->item_id == $row->id) { $sales_count = $sales_count + $invoice_row->quantity; } } } /* transfers */ if ($branch_id != '') { $transfers = \App\Models\StockTransfer::where('warehouse_to', $branch_id)->get(); } else { $transfers = \App\Models\StockTransfer::get(); } $transfer_count = 0; foreach ($transfers as $base_transfer_row) { $transfer_details = \App\Models\StockTransferDetail::where('stock_transfer_id', $base_transfer_row->id)->get(); foreach ($transfer_details as $transfer_row) { if ($transfer_row->material_id == $row->id) { $transfer_count = $transfer_count + $transfer_row->quantity; } } } /* transfers */ if ($branch_id != '') { $returns = \App\Models\SalesReturn::where('branch_id', $branch_id)->get(); } else { $returns = \App\Models\SalesReturn::get(); } $return_count = 0; foreach ($returns as $sales_return_row) { $return_details = \App\Models\SalesReturnDetail::where('sales_return_id', $sales_return_row->id)->get(); foreach ($return_details as $return_row) { if ($return_row->item_id == $row->id) { if ($return_row->type == 2) { $return_count = $return_count + $return_row->quantity; } } } } @endphp @if ($transfer_count != 0 || $sales_count != 0) @php $total_count = $total_count + 1; @endphp @endif @endforeach
Date Material Name Received Sales Sales Return In Stock<< /th>
{{ $i++ }} {{ $row->name }} {{ $transfer_count }} {{ getUnitType($row->unit) }} {{ $sales_count }} {{ getUnitType($row->unit) }} {{ $return_count }} {{ getUnitType($row->unit) }} {{ $transfer_count - $sales_count + $return_count }} {{ getUnitType($row->unit) }}


Total Items: {{ $total_count }}