feat: Implement comprehensive product management, including categories, pricing, and integration into the order system.

This commit is contained in:
pbao9
2026-02-12 14:29:29 +07:00
parent 3b1beef66e
commit f3a679d7f3
25 changed files with 577 additions and 692 deletions
@@ -24,9 +24,12 @@ class InvoiceRepository extends BaseApiRepository implements InvoiceRepositoryIn
{
$invoice = $this->model->create([
'customer_id' => $order->customer_id,
'order_num' => \App\Helpers\OrderHelper::generateOrderNumber('INV'),
'date' => now(),
'due_date' => now()->addDays(3),
'amount' => $order->amount,
'total' => $order->amount,
'sub_total' => $order->amount,
'tax' => 0,
'status' => 1, // Unpaid
]);
@@ -38,15 +41,36 @@ class InvoiceRepository extends BaseApiRepository implements InvoiceRepositoryIn
}
foreach ($orderItems as $item) {
\App\Models\InvoiceItem::create([
$invoiceItem = \App\Models\InvoiceItem::create([
'invoice_id' => $invoice->id,
'customer_id' => $invoice->customer_id,
// 'customer_id' removed as not in migration
'product_id' => $item->product_id,
'description' => optional($item->product)->name ?? 'Order Item',
'amount' => $item->price ?? $order->amount,
'type_id' => 1,
'billing' => $item->billing_cycle ?? 'monthly',
// 'description' removed as not in migration
'price' => $item->price ?? $order->amount,
// 'type_id' removed, use 'product_type'
'product_type' => $item->product->product_type instanceof \App\Enums\Product\ProductTypeEnums
? $item->product->product_type->value
: (\App\Enums\Product\ProductTypeEnums::tryFrom($item->product->product_type)?->value ?? 1),
// 'billing' removed, map to 'months' if possible? default 0 in migration
'months' => match ($item->billing_cycle) {
'quarterly' => 3,
'semi_annually' => 6,
'annually' => 12,
default => 1,
},
'server_name' => $item->server_name,
'os_id' => $item->os_id,
]);
// Copy addons from OrderItem to InvoiceItem
foreach ($item->addons as $addon) {
\App\Models\InvoiceAddons::create([
'invoice_item_id' => $invoiceItem->id,
'addon_id' => $addon->addon_id,
'qty' => $addon->qty,
'price' => $addon->price // Unit price preserved from order
]);
}
}
return $invoice;