{{-- resources/views/admin/sales_invoices/edit.blade.php --}} @extends('admin.layouts.master') @section('title', 'تعديل فاتورة مبيعات') @section('css') @endsection @section('content') @php // ====== Safe defaults (لو الكنترولر مش باعتهم) ====== $today = now()->timezone('Africa/Cairo')->toDateString(); $warehouses = $warehouses ?? collect(); $treasuries = $treasuries ?? collect(); $terminals = $terminals ?? collect(); $openShiftTreasuryId = $openShiftTreasuryId ?? null; $openShiftTreasuryName = $openShiftTreasuryName ?? null; // ====== Pre-fill payments from invoice (لو invoice->payments موجودة) ====== $invoice->loadMissing(['customer','items.item','payments']); $invPayCash = (float) ($invoice->payments?->where('method','cash')->sum('amount') ?? 0); $invPayCard = (float) ($invoice->payments?->where('method','card')->sum('amount') ?? 0); $invPayWallet = (float) ($invoice->payments?->where('method','wallet')->sum('amount') ?? 0); $defaultPayCash = (float) old('payment.cash', $invPayCash); $defaultPayCard = (float) old('payment.card', $invPayCard); $defaultPayWallet = (float) old('payment.wallet', $invPayWallet); // ====== Global UI defaults ====== $defaultGlobalDiscType = old('global_discount_type', 'amount'); $defaultGlobalDiscValue = (float) old('global_discount_value', 0); // VAT default for new lines $defaultVatRate = (float) old('global_vat_rate', 14); // ====== IMPORTANT: Prepare items array in PHP to avoid Blade ParseError ====== $itemsData = $invoice->items->map(function ($it) { $qty = (float) ($it->quantity ?? 0); $price = (float) ($it->price ?? 0); $gross = $qty * $price; // لو اسم الخصم عندك مختلف غيّره هنا $discAmount = (float) ($it->discount ?? 0); $base = max(0, $gross - $discAmount); // لو اسم vat عندك مختلف غيّره هنا $vatAmount = (float) ($it->vat ?? 0); $vatRate = 0.0; if ($base > 0.0001 && $vatAmount > 0) { $vatRate = round(($vatAmount / $base) * 100, 4); } return [ 'item_id' => (int) $it->item_id, 'item_text' => $it->item->name ?? ('Item#' . $it->item_id), 'qty' => round($qty, 4), 'price' => round($price, 4), 'discount_value' => round($discAmount, 4), 'discount_type' => 'amount', 'vat_rate' => round($vatRate, 4), 'cost_price' => round((float) ($it->cost_price ?? 0), 4), ]; })->values()->toArray(); @endphp {{-- Top Bar --}}

تعديل فاتورة مبيعات #{{ $invoice->invoice_code }}

{{ ucfirst($invoice->status) }} F4: عميل F6: باركود F9: دفع Del: تصفير
الأسعار/الخصم/الضريبة داخل مودال السطر فقط (ثابتة ومش بتتزحلق).
رجوع
@include('admin.Alerts') @if ($errors->any())
فيه أخطاء لازم تتصلح:
@endif
@csrf @method('PUT') {{-- Totals --}} {{-- Global Discount --}} {{-- Payment (split) --}} {{-- Pricing context --}}
{{-- بيانات الفاتورة --}}
بيانات الفاتورة
POS Ready Hold/Park Split Payment
المخزن يؤثر على المخزون المتاح ومنع السالب.
F4 لفتح اختيار العميل بسرعة.
عروض: Buy X Get Y (Auto)
منع السالب: مفعل
@if($openShiftTreasuryId)
الخزنة مرتبطة بالشِفت المفتوح
سيتم استخدام خزنة: {{ $openShiftTreasuryName ?? ('#'.$openShiftTreasuryId) }} تلقائيًا في شاشة الدفع.
@else
لا يوجد شِفت مفتوح
لن تستطيع تطبيق الدفع حتى تفتح شِفت على خزنة (أو فعل صلاحية استثنائية).
@endif
{{-- CART --}}
السلة
Edit داخل مودال السطر
{{-- Barcode --}}
Scan Barcode (F6 للتركيز)
سيتم دمج الصنف لو موجود مسبقًا.
✅ الأسعار/الخصومات/VAT مش هتظهر كمدخلات في السطر… كله داخل مودال “Edit”.
{{-- TOTALS / PAYMENT --}}
الإجماليات والدفع
Auto
Subtotal (قبل الخصومات والضريبة)
0.00
قيمة أو نسبة على إجمالي الفاتورة.
لو نسبة: اكتب 10 = 10%.
يُستخدم كافتراضي للسطور الجديدة/لو السطر VAT=0.
إجمالي الخصومات
0.00
إجمالي الضريبة
0.00
الإجمالي النهائي
0.00
إلغاء
@if(!$openShiftTreasuryId)
ممنوع الدفع بدون شِفت
افتح شِفت على خزنة أولاً.
@endif
{{-- Template Row (JS will clone) --}} @php // بنكتب template كسطر واحد في HTML (JS بيحطه في cartBody) @endphp {{-- مودال تعديل السطر (سعر + خصم + VAT) --}} {{-- Pay Modal (Split Payment) --}} {{-- Park Modal --}} @endsection @section('js') @php $invoiceDataArray = [ 'id' => $invoice->id, 'invoice_date' => old('invoice_date', $invoice->invoice_date ?? ''), 'due_date' => old('due_date', $invoice->due_date ?? ''), 'payment_type' => old('payment_type', $invoice->payment_type ?? 'cash'), 'subtotal' => (float) old('subtotal', (float) $invoice->subtotal), 'discount' => (float) old('discount_amount', (float) $invoice->discount_amount), 'vat' => (float) old('vat_amount', (float) $invoice->vat_amount), 'total' => (float) old('total', (float) $invoice->total), ]; @endphp @endsection