{{-- resources/views/purchase/bills/edit.blade.php --}} @extends('master.app') @section('title', 'Edit Supplier Invoice') @section('body') Edit Purchase Invoice One-page invoice (Add to List + Update) Back to Bills @include('general.valert') @csrf @method('PUT') {{-- Invoice Header --}} Invoice Info Header Invoice Type Choose Invoice Type type_id === 1 || is_null($bill->type_id) ? 'selected' : '' }}>Raw Materials type_id === 2 ? 'selected' : '' }}>Finished Goods Supplier Choose Supplier @foreach ($suppliers as $row) id === (int)$bill->supplier_id ? 'selected' : '' }}> {{ $row->name }} @endforeach Invoice Number Title @if(isset($bdate) && $bdate == 1) Date @else Date @endif Currency Choose Currency @foreach ($currencies as $row) id === (int)$bill->currency_id ? 'selected' : '' }}> {{ $row->title_ps ?? $row->title_en ?? $row->title_dr }} @endforeach Exchange Rate Invoice File Upload only if you want to replace old file {{-- Add Items --}} Add Items Select type then add items Items {{-- RAW --}} Raw Materials Clear Category Choose Category @foreach ($pCategories ?? [] as $c) {{ $c->title_en }} @endforeach Sub Category SCAT Unit Choose Unit @foreach ($pUnits ?? [] as $u) {{ $u->title_ps ?? $u->title_en }} @endforeach CPI SPI Qty Add to List {{-- FIN --}} Finished Goods Clear Category Choose Category @foreach ($sCategories ?? [] as $c) {{ $c->title_en ?? $c->name }} @endforeach Sub Category Choose Sub Category @foreach ($sSubcategories ?? [] as $sc) {{ $sc->title_en ?? $sc->name }} @endforeach Unit Choose Unit @foreach ($sUnits ?? [] as $u) {{ $u->title_ps ?? $u->title_en }} @endforeach Weight Choose Weight @foreach ($sWeights ?? [] as $w) {{ $w->title_ps ?? $w->title_en }} @endforeach Location Choose Location @foreach ($locations ?? [] as $l) {{ $l->title ?? $l->name ?? ('Location #'.$l->id) }} @endforeach Price Qty SPI Add to List {{-- Items List --}} Items List List # Item Unit Qty Price Total Action No items added yet. {{-- Hidden inputs for items --}} {{-- Checkout --}} Checkout Update Grand Total Payment Balance Transaction Type Define Transaction Type transaction_id === 1 ? 'selected' : '' }}>Cash transaction_id === 2 ? 'selected' : '' }}>Bank transaction_id === 3 ? 'selected' : '' }}>Sarafi Target Cash Define Target Type c_target === 1 ? 'selected' : '' }}>Target Cash Yes c_target !== 1 ? 'selected' : '' }}>Target Cash No Payment By Back Update Invoice @endsection @section('pageJs') @php // ✅ FIX: build PHP array first, then json it (prevents "Unclosed '[' ... does not match ')'") $preloadItems = (((int)$bill->type_id === 1) || is_null($bill->type_id)) ? $bill_items->map(function($it){ return [ 'label' => 'Cat #'.$it->cat_id, 'subLabel' => $it->scat_id ? ('SCAT #'.$it->scat_id) : '', 'unitLabel' => 'Unit #'.$it->unit_id, 'qty' => (float) $it->qty, 'price' => (float) $it->cpi, 'total' => (float) $it->total, 'payload' => [ 'mode' => 'raw', 'cat_id' => $it->cat_id, 'scat_id' => $it->scat_id ?? '', 'unit_id' => $it->unit_id, 'cpi' => (float) $it->cpi, 'spi' => (float) $it->spi, 'qty' => (float) $it->qty, ], ]; })->values() : $bill_items->map(function($it){ return [ 'label' => 'Cat #'.$it->cat_id.' - Sub #'.$it->sub_cat_id, 'subLabel' => 'Weight #'.$it->weight_id.' | Location #'.$it->location_id, 'unitLabel' => 'Unit #'.$it->unit_id, 'qty' => (float) $it->qty, 'price' => (float) $it->price, 'total' => (float) $it->total, 'payload' => [ 'mode' => 'fin', 'cat_id' => $it->cat_id, 'sub_cat_id' => $it->sub_cat_id, 'unit_id' => $it->unit_id, 'weight_id' => $it->weight_id, 'location_id' => $it->location_id, 'price' => (float) $it->price, 'qty' => (float) $it->qty, 'spi' => (float) ($it->spi ?? 0), ], ]; })->values(); @endphp @endsection