update email template
This commit is contained in:
@@ -6,7 +6,6 @@ namespace App\Services\Api\Order;
|
||||
|
||||
use App\DTOs\Order\ClientOrderFilters;
|
||||
use App\Enums\Invoice\InvoiceStatus;
|
||||
use App\Enums\Order\OrderStatus;
|
||||
use App\Helpers\OrderHelper;
|
||||
use App\Jobs\VirtualMachine\Action\VMJobs;
|
||||
use App\Jobs\VirtualMachine\Provision\RetryProvisioningOrchestrator;
|
||||
@@ -234,33 +233,16 @@ class OrderQueryService
|
||||
];
|
||||
}
|
||||
|
||||
$invoice = DB::transaction(function () use ($service, $orderItem, $price, $months) {
|
||||
$order = Order::create([
|
||||
'order_num' => OrderHelper::generateOrderNumber(),
|
||||
'customer_id' => $service->customer_id,
|
||||
'sub_total' => $price,
|
||||
'discount_amount' => 0,
|
||||
'total' => $price,
|
||||
'status' => OrderStatus::PENDING->value,
|
||||
'client_ip' => request()?->ip(),
|
||||
'note' => 'Đơn hàng gia hạn dịch vụ #' . $service->id,
|
||||
]);
|
||||
|
||||
OrderItem::create([
|
||||
'order_id' => $order->id,
|
||||
'product_id' => $service->product_id,
|
||||
'billing_cycle' => $orderItem->billing_cycle,
|
||||
'months' => $months,
|
||||
'os_id' => $orderItem->os_id,
|
||||
'quantity' => 1,
|
||||
'server_name' => $service->server_name,
|
||||
'price' => $price,
|
||||
]);
|
||||
// Gia hạn là một billing cycle mới của CÙNG một Order/Service — không tạo Order mới.
|
||||
// Order gốc chính là order đã tạo ra service này (qua order_item -> order_id).
|
||||
$periodStart = $service->expires_at && $service->expires_at->isFuture() ? $service->expires_at->copy() : now();
|
||||
$periodEnd = $periodStart->copy()->addMonths($months);
|
||||
|
||||
$invoice = DB::transaction(function () use ($service, $orderItem, $price, $months, $periodStart, $periodEnd) {
|
||||
$invoice = Invoice::create([
|
||||
'invoice_number' => OrderHelper::generateOrderNumber('INV'),
|
||||
'customer_id' => $service->customer_id,
|
||||
'order_id' => $order->id,
|
||||
'order_id' => $orderItem->order_id,
|
||||
'invoice_type' => 2,
|
||||
'sub_total' => $price,
|
||||
'discount_amount' => 0,
|
||||
@@ -268,6 +250,8 @@ class OrderQueryService
|
||||
'total' => $price,
|
||||
'status' => InvoiceStatus::UNPAID->value,
|
||||
'due_date' => now()->addDays(7)->toDateString(),
|
||||
'billing_period_start' => $periodStart->toDateString(),
|
||||
'billing_period_end' => $periodEnd->toDateString(),
|
||||
]);
|
||||
|
||||
\App\Models\InvoiceItem::create([
|
||||
|
||||
@@ -83,7 +83,7 @@ class OrderService
|
||||
$this->orderRepo->createItem($order->id, [
|
||||
'product_id' => $product->id,
|
||||
'billing_cycle' => $data['billing_cycle'],
|
||||
'months' => $this->cycleToMonths($data['billing_cycle']),
|
||||
'months' => OrderHelper::cycleToMonths($data['billing_cycle']),
|
||||
'server_name' => $data['server_name'] ?? null,
|
||||
'os_id' => $data['os_id'] ?? null,
|
||||
'quantity' => 1,
|
||||
@@ -151,7 +151,7 @@ class OrderService
|
||||
private function provisionService(Order $order, OrderItem $item, $customer): void
|
||||
{
|
||||
$invoice = $order->invoice;
|
||||
$months = $item->months ?: $this->cycleToMonths($item->billing_cycle);
|
||||
$months = $item->months ?: OrderHelper::cycleToMonths($item->billing_cycle);
|
||||
$expiresAt = now()->addMonths($months);
|
||||
|
||||
$service = Service::create([
|
||||
@@ -253,18 +253,6 @@ class OrderService
|
||||
// Helpers
|
||||
// =========================================================================
|
||||
|
||||
private function cycleToMonths(?string $cycle): int
|
||||
{
|
||||
return match ($cycle) {
|
||||
'monthly' => 1,
|
||||
'quarterly' => 3,
|
||||
'semi_annually' => 6,
|
||||
'annually' => 12,
|
||||
'biennially' => 24,
|
||||
'triennially' => 36,
|
||||
default => 1,
|
||||
};
|
||||
}
|
||||
|
||||
private function dispatchAdminNotification(Order $order, $customer): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user