@php // เนื่องจาก Controller ส่งมาเป็น Collection (จาก ->get()) เราต้องดึงตัวแรกออกมาใช้งาน if ($invoice instanceof \Illuminate\Support\Collection) { $invoice = $invoice->first(); } if (empty($invoice)) { // กรณีสร้างใหม่ (Insert) - กำหนดค่าว่างเริ่มต้น $invoice_id = ''; $invoice_no = ''; $invoice_date = ''; $invoice_exp_date = ''; $invoice_attention = ''; $invoice_attention_detail = ''; $invoice_project_name = ''; $invoice_project_duration = ''; $invoice_main_description = ''; $invoice_amount = ''; $invoice_discount_type = ''; $invoice_discount_value = ''; $invoice_sub_services = []; $invoice_sub_amounts = []; // เพิ่มตัวแปรสำหรับระบบ Quantity และ Remark $invoice_main_qty = 1; $invoice_sub_qtys = []; $invoice_use_qty = 0; // 0 = ปิด, 1 = เปิด $invoice_bank = ''; $invoice_remark = ''; } else { // กรณีแก้ไข (Update) - ดึงค่าจาก Object $invoice $invoice_id = $invoice->invoice_id; $invoice_no = $invoice->invoice_no; $invoice_date = $invoice->invoice_date; $invoice_exp_date = $invoice->invoice_exp_date; $invoice_attention = $invoice->invoice_attention; $invoice_attention_detail = $invoice->invoice_attention_detail; $invoice_project_name = $invoice->invoice_project_name; $invoice_project_duration = $invoice->invoice_project_duration; $invoice_main_description = $invoice->invoice_main_description; $invoice_amount = $invoice->invoice_amount; $invoice_discount_type = $invoice->invoice_discount_type; $invoice_discount_value = $invoice->invoice_discount_value; // แปลง JSON string เป็น Array $invoice_sub_services = json_decode($invoice->invoice_sub_services, true) ?? []; $invoice_sub_amounts = json_decode($invoice->invoice_sub_amounts, true) ?? []; // ดึงค่าระบบ Quantity และ Remark จาก Database $invoice_main_qty = $invoice->invoice_main_qty ?? 1; $invoice_sub_qtys = json_decode($invoice->invoice_sub_qtys, true) ?? []; $invoice_use_qty = $invoice->invoice_use_qty ?? 0; $invoice_bank = $invoice->invoice_bank ?? ''; $invoice_remark = $invoice->invoice_remark ?? ''; } // รายชื่อธนาคารสำหรับ dropdown เลือก (ถ้า Controller ยังไม่ได้ส่ง $banks มาให้ จะ fallback ไปดึงจากตาราง bank เอง) $banks = $banks ?? \Illuminate\Support\Facades\DB::table('bank')->orderBy('bank_name')->get(); $breadcrumbs = [ 'Invoice List' => url('/invoice_list'), 'Invoice Editor' => '' ]; @endphp @extends('layouts.master') @section('title') Invoice Duplicate @endsection @section('style') @endsection @section('content') Invoice Editor {{ csrf_field() }} Invoice Date: Expiration Date: Invoice No.: Attention: Attention Details: {{ $invoice_attention_detail }} Project Name: Sync to Title {{ $invoice_project_name }} Project Duration: {{ $invoice_project_duration }} Description Quantity Amount (THB) + Add Quantity Mode Main Service Description (Title): Quantity: Amount (THB): @if(count($invoice_sub_services) > 0) @foreach($invoice_sub_services as $index => $item) - Sub-service {{ $index + 1 }}: {{ $item }} @endforeach @else - Sub-service 1: @endif Add Sub-service Item Bank Account: Switch to Remark -- Select Bank Account -- @foreach($banks as $bank) bank_id ? 'selected' : '' }} title="{{ $bank->bank_name }} ({{ $bank->bank_branch }}) - {{ $bank->bank_account_no }}" style="line-height: 1.8; padding: 6px;"> {{ $bank->bank_name }} ({{ $bank->bank_branch }}) - {{ $bank->bank_account_no }} @endforeach แทรกข้อความมาตรฐาน {{ $invoice_remark }} Special Discount % THB (0.00) NET TOTAL: 0.00 Save Invoice @endsection @section('script') @endsection