@include('pos.supplier._purchasing_nav') @php $isEdit = isset($bill); $systemIdVal = $bill->supplier_bill_details_system_id ?? ($defaultBill['supplier_bill_details_system_id'] ?? (string) $systemId); $status = $bill->supplier_bill_details_status ?? ($defaultBill['supplier_bill_details_status'] ?? 'draft'); $hasStockRowsVal = (bool) ($hasStockRows ?? false); $isLocked = ($status === 'cancelled') || ($status === 'received' && $hasStockRowsVal); @endphp

{{ isset($bill) ? 'Edit Purchase' : 'Add Purchase' }}

{{ strtoupper($status) }}
System ID: {{ $systemIdVal }}
Back to Purchases @if(isset($bill)) Create Return @endif
@if(!$isEdit)
@csrf @endif

Purchase Details

Reference: {{ old('supplier_bill_details_billnumber', $bill->supplier_bill_details_billnumber ?? ($defaultBill['supplier_bill_details_billnumber'] ?? '')) }}
@if($isEdit) @csrf @method('PUT') @else
@endif
@if($isEdit) @endif
@if($isEdit) @endif
@if($isLocked) @endif
Optional (JPG, max 5MB)
@if($isEdit)
@else
@endif

Items

@if($isLocked)
This purchase is {{ strtoupper($status) }}. Items are locked. To edit, use Reopen to Draft (undo stock) first.
@endif @if($isEdit && $status === 'received' && !$isLocked)
This purchase is marked RECEIVED but has no stock movements. You can edit items and click Receive (Post Stock) to post stock.
@endif
Product
Batch Name MFD EXP Qty Cost A. Rate MRP Total Pricing Group Actions
Grand Total 0.00
@if(!$isEdit)

Actions

@php $createStatus = old('supplier_bill_details_status', $status); $paymentEnabled = ($createStatus === 'received'); // Group accounts by type for JS filtering $accountsByType = []; foreach(($paymentAccounts ?? []) as $acc) { $type = strtolower($acc->type); if (!isset($accountsByType[$type])) { $accountsByType[$type] = []; } $accountsByType[$type][] = ['id' => $acc->id, 'name' => $acc->name, 'type' => $acc->type]; } @endphp
Payment (optional)
Only applies when Status = Received
@php $oldPayments = old('sp_payments'); if (!is_array($oldPayments) || count($oldPayments) === 0) { $oldPayments = [[ 'method' => 'cash', 'account_id' => $defaultPaymentAccountId ?? null, 'amount' => '', 'reference' => '', 'info' => '', ]]; } @endphp @foreach($oldPayments as $idx => $p) @php $rowMethod = $p['method'] ?? 'cash'; @endphp {{-- Cheque Type (only for cheque method) --}} {{-- Cheque Number --}} {{-- Clear Date --}} {{-- Reference (only for non-cheque methods) --}} {{-- Remark/Note (for all methods) --}} @endforeach
Method Account Amount Cheque Type Cheque No Clear Date Reference Remark Actions
@php $aid = (int) ($p['account_id'] ?? ($defaultPaymentAccountId ?? 0)); @endphp @php $chequeType = $p['cheque_type'] ?? 'crossed'; @endphp
Note: Cheque payments are tracked separately (not due, not paid until cleared).
Tip: Create as Draft, then Receive to post stock.
@endif
@php $isPosPopup = request()->boolean('pos_popup'); @endphp @if($isEdit && !$isPosPopup)

Actions

@if($isEdit && ($status === 'draft' || ($status === 'received' && !$isLocked)))
@csrf
@endif @if($isEdit && $status === 'received' && $isLocked && \Illuminate\Support\Facades\Route::has('pos.supplier.bill.reopen'))
@csrf
@endif @if($isEdit && $status !== 'cancelled')
@csrf
@endif
@if($isEdit) @php $total = (float) ($bill->supplier_bill_details_total ?? 0); $paid = (float) ($bill->supplier_bill_details_paid ?? 0); $chequeIssued = (float) ($bill->supplier_bill_details_cheque_issued ?? 0); $returnedTotal = (float) ($bill->supplier_bill_details_returned_total ?? 0); $due = max(0, $total - $paid - $chequeIssued - $returnedTotal); @endphp

Payment

Total
{{ number_format($total, 2) }}
Due
{{ number_format($due, 2) }}
Paid
{{ number_format($paid, 2) }}
@if($chequeIssued > 0)
Cheque Issued
{{ number_format($chequeIssued, 2) }}
Not cleared yet
@else
Returned
{{ number_format($returnedTotal, 2) }}
@endif
@if($chequeIssued > 0 && $returnedTotal > 0)
Returned: {{ number_format($returnedTotal, 2) }}
@endif
@if($status === 'cancelled')
Cannot add payments to a cancelled purchase.
@endif

Payments

@forelse(($billPayments ?? []) as $p) @empty @endforelse
Date User Method Reference Account Document Amount
{{ \Carbon\Carbon::parse(($p->sp_add_date ?? now()->toDateString()).' '.($p->sp_add_time ?? '00:00:00'))->format('Y-m-d h:i A') }} {{ $p->user_name ?? '' }} {{ $p->sp_method ?? '' }} {{ $p->sp_reference ?? '' }} {{ $p->account_name ?? '' }} @if(!empty($p->sp_document)) View @else -- @endif {{ number_format((float) ($p->sp_amount ?? 0), 2) }}
No payments yet
@endif
@endif