چوہدری محمد دین محمد شریف اینڈ کو
الو پوہ — امپورٹر، ایکسپورٹر، کمیشن ایجنٹس
نو اسٹریٹ مارکیٹ سپر ہائی وے کراچی
منڈی: 35950017-021
0333-2174848
mdskarachi@hotmail.com

تاریخ:   {{ $b_cheque->date->format('d/m/Y') }}

محترمی جناب:  {{ $b_cheque->supplier->supplier_name_urdu }}

حوالہ نمبر:  {{ $b_cheque->bilty_no }}

گاڑی نمبر:   {{ $b_cheque->goodReceiptTruck->truck_no }}
@php $details = $b_cheque->details; $maal = $b_cheque->items; $totalBori = $maal->sum('bori'); $rows = collect([ (object) ['item' => 'کرایہ محصول', 'value' => number_format($details->rent_recieve_amount, 0) ?? '-'], (object) [ 'item' => 'مزوری بوری', 'value' => number_format($details->labour_amount * $totalBori, 0) ?? '-', ], (object) [ 'item' => 'مزوری کَٹا', 'value' => number_format($details->total_katta * $details->labour_katta_amount, 0) ?? '-', ], (object) ['item' => 'مارکیٹ فیس', 'value' => number_format($details->market_fees_amount, 0) ?? '-'], (object) ['item' => 'ڈاک خرج', 'value' => number_format($details->post_expense_amount, 0) ?? '-'], (object) [ 'item' => 'خرجہ متفرقات', 'value' => number_format($details->miscellaneous_expense_amount, 0) ?? '-', ], (object) ['item' => 'نقد', 'value' => number_format($details->cash_amount, 0) ?? '-'], (object) ['item' => 'کمیشن', 'value' => number_format($details->commission_amount, 0) ?? '-'], ]); $prevChild = ['id' => null, 'name' => null]; $prevRate = null; $prevMarka = null; $sumBori = 0; $sumWeight = 0; $sumAmount = 0; $bori = 0; $weight = 0; $total_amount = 0; $printedItems = []; $countIndex = 0; $groupedData = []; // NEW: Store grouped data with correct marka @endphp @foreach ($maal as $m) @php // 1. Robust Child Category resolution $childObj = $m->productChildCate; if (!$childObj && !empty($m->child_cate)) { $childObj = \App\ProductsSubCategoryChild::where('id_pro_sub_cat_child', $m->child_cate) ->orWhere('name', $m->child_cate) ->orWhere('name_urdu', $m->child_cate) ->first(); } $childName = $childObj ? ($childObj->name_urdu ?: $childObj->name) : (!is_numeric($m->child_cate) ? $m->child_cate : ''); // 2. Robust Parent Category resolution (with fallback to Child's parent relation) $parentObj = $m->productParentCate; if (!$parentObj && !empty($m->parent_cate)) { $parentObj = \App\ProductsSubCategoryParent::where('id_pro_sub_cat_parent', $m->parent_cate) ->orWhere('name', $m->parent_cate) ->orWhere('name_urdu', $m->parent_cate) ->first(); } if (!$parentObj && $childObj && !empty($childObj->pro_sub_cat_parent_id)) { $parentObj = \App\ProductsSubCategoryParent::find($childObj->pro_sub_cat_parent_id); } $parentName = $parentObj ? ($parentObj->name_urdu ?: $parentObj->name) : (!is_numeric($m->parent_cate) ? $m->parent_cate : ''); // 3. Robust Main Category resolution (with fallback to Parent's main relation) $mainObj = $m->productMainCate; if (!$mainObj && !empty($m->main_cate)) { $mainObj = \App\ProductsCategoryMain::where('id_pro_cate_main', $m->main_cate) ->orWhere('products_category_name', $m->main_cate) ->orWhere('products_category_name_urdu', $m->main_cate) ->first(); } if (!$mainObj && $parentObj && !empty($parentObj->pro_cate_main_id)) { $mainObj = \App\ProductsCategoryMain::find($parentObj->pro_cate_main_id); } $mainName = $mainObj ? ($mainObj->products_category_name_urdu ?: $mainObj->products_category_name) : (!is_numeric($m->main_cate) ? $m->main_cate : ''); // 4. Compose complete hierarchy in مال column (Main Category - Parent Category - Child Category) $categoryHierarchy = array_unique(array_filter([$mainName, $parentName, $childName])); $itemFullName = !empty($categoryHierarchy) ? implode(' - ', $categoryHierarchy) : ($m->item ?? '-'); $itemKey = ($m->main_cate ?? '') . '_' . ($m->parent_cate ?? '') . '_' . ($m->child_cate ?? '') . '_' . $itemFullName; $currentChild = [ 'id' => $itemKey, 'name' => $itemFullName, ]; $currentRate = $m->rate; $currentMarka = $m->marka; $bori += $m->bori; $weight += $m->weight; $total_amount += $m->amount; @endphp @if ($prevChild['id'] === $currentChild['id'] && $prevRate === $currentRate && $prevMarka === $currentMarka) @php $sumBori += $m->bori; $sumWeight += $m->weight; $sumAmount += $m->amount; @endphp @else @if ($prevChild['id'] !== null) @php // Store the grouped data with correct marka $groupedData[] = [ 'name' => $prevChild['name'], 'marka' => $prevMarka, // Correct marka stored here 'bori' => $sumBori, 'weight' => $sumWeight, 'rate' => $prevRate, 'amount' => $sumAmount, 'expense_item' => $rows[$countIndex]->item ?? '', 'expense_value' => $rows[$countIndex]->value ?? '', ]; $printedItems[] = $rows[$countIndex]->item ?? ''; $countIndex++; @endphp @endif @php $prevChild = $currentChild; $prevRate = $currentRate; $prevMarka = $currentMarka; $sumBori = $m->bori; $sumWeight = $m->weight; $sumAmount = $m->amount; @endphp @endif @endforeach {{-- Last group --}} @php $groupedData[] = [ 'name' => $prevChild['name'], 'marka' => $prevMarka, // Correct marka for last group 'bori' => $sumBori, 'weight' => $sumWeight, 'rate' => $prevRate, 'amount' => $sumAmount, 'expense_item' => $rows[$countIndex]->item ?? '', 'expense_value' => $rows[$countIndex]->value ?? '', ]; $printedItems[] = $rows[$countIndex]->item ?? ''; @endphp {{-- Print all grouped data with correct marka --}} @foreach ($groupedData as $group) @endforeach {{-- Print remaining rows without duplicates --}} @foreach ($rows as $item) @if (!in_array($item->item, $printedItems)) @endif @endforeach {{-- Totals --}}
تفصیل خرج رقم مال بورے وزن بهاؤدر قیمت
{{ $group['expense_item'] }} {{ $group['expense_value'] }} {{ $group['name'] }}{{ !empty($group['marka']) ? ' (' . $group['marka'] . ')' : '' }} {{ $group['bori'] }} {{ $group['weight'] }} {{ number_format($group['rate'], 0) }} {{ number_format($group['amount'], 0) }}
{{ $item->item }} {{ $item->value }}
کل خرجہ {{ number_format($details->total_expanse_amount, 0) }}
{{ $bori }} {{ $weight }}
خام بکری {{ number_format($total_amount, 0) }}
کل خرجہ {{ number_format($details->total_expanse_amount, 0) }}
پختہ بکری {{ number_format($total_amount - $details->total_expanse_amount, 0) }}
دستخط