feat: standardize invoice number field, refine invoice creation logic, and update module foreign key constraints

This commit is contained in:
pbao9
2026-03-12 10:10:20 +07:00
parent 1e09ccf17b
commit 1934be9a19
10 changed files with 24 additions and 30 deletions
+12 -7
View File
@@ -42,14 +42,14 @@ class OrderService
[$productItems, $relIdData, $total] = $this->buildProductItems($data);
$invoiceData = [
'date' => Carbon::today()->toDateString(),
'invoice_number' => Helper::generateUniqueCode(),
'due_date' => Carbon::today()->toDateString(),
'date_paid' => (int) $data['status'] === 1 ? Carbon::today()->toDateString() : null,
'paid_at' => (int) $data['status'] === 1 ? Carbon::today()->toDateString() : null,
'sub_total' => $total,
'tax' => $total * (10 / 100),
'total' => $total + ($total * (10 / 100)),
'payment_method' => $paymentRecord?->id,
'customer_id' => ($data['create_invoice'] ?? false) ? $data['customer_id'] : 0,
'customer_id' => $data['customer_id'],
'status' => $data['status'],
];
@@ -84,10 +84,15 @@ class OrderService
$this->createModules($relIdData);
$invoiceItemData = array_map(
fn ($item) => \Illuminate\Support\Arr::except($item, ['billing_cycle', 'code']),
$productItems
);
$invoiceItemData = array_map(fn ($item) => [
'invoice_id' => $item['invoice_id'],
'product_id' => $item['product_id'],
'type' => 'service',
'months' => $item['months'],
'quantity' => $item['quantity'],
'unit_price' => $item['price'],
'total_price' => $item['price'] * $item['quantity'],
], $productItems);
$this->invoiceItemRepository->insert($invoiceItemData);
$now = now();