feat(billing): renewals, coupons, VAT numbering, billing cycles and invoice payment tracking
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
ea9a53f742
commit
25f23d541e
@@ -54,6 +54,13 @@ class CustomerBillingService
|
||||
unset($data['date_paid']);
|
||||
}
|
||||
|
||||
if (array_key_exists('amount_paid', $data) && $data['amount_paid'] === null) {
|
||||
unset($data['amount_paid']);
|
||||
}
|
||||
if (isset($data['amount_paid']) && $data['amount_paid'] > (int) ($data['total'] ?? $invoice->total)) {
|
||||
abort(422, 'Số tiền đã thu không được lớn hơn tổng hóa đơn');
|
||||
}
|
||||
|
||||
// Đi qua repository (không gọi $invoice->update() trực tiếp) để cache
|
||||
// của invoiceRepository->filter() (dùng ở getInvoices) được xoá theo,
|
||||
// nếu không danh sách hóa đơn sẽ hiển thị dữ liệu cũ cho tới khi cache hết hạn.
|
||||
@@ -128,13 +135,17 @@ class CustomerBillingService
|
||||
{
|
||||
$customer = $this->resolveCustomer($uuid);
|
||||
|
||||
return $this->orderRepository->filter(['client' => $customer->id], [
|
||||
$orders = $this->orderRepository->filter(['client' => $customer->id], [
|
||||
'customer',
|
||||
'user:id,username',
|
||||
'payment',
|
||||
'invoices',
|
||||
...OrderItemServiceResource::relationsFor('orderItems'),
|
||||
]);
|
||||
|
||||
$orders->each(fn ($order) => $order->invoices->each(fn ($invoice) => $invoice->date_paid = $invoice->paid_at));
|
||||
|
||||
return $orders;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Services\Customer;
|
||||
|
||||
use App\Helpers\OrderHelper;
|
||||
use App\Mail\ServiceRenewalReminderMail;
|
||||
use App\Models\Customer;
|
||||
use App\Models\ModuleVmware;
|
||||
use App\Models\Order;
|
||||
@@ -21,7 +20,6 @@ use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CustomerServiceProvisioningService
|
||||
@@ -43,6 +41,7 @@ class CustomerServiceProvisioningService
|
||||
['customer_uuid' => $uuid],
|
||||
[
|
||||
'product',
|
||||
'product.pricings' => fn ($query) => $query->where('is_active', 1)->select('id', 'product_id', 'billing_cycle'),
|
||||
'orderItem',
|
||||
'invoice',
|
||||
'vmware.os.osGroup',
|
||||
@@ -186,22 +185,6 @@ class CustomerServiceProvisioningService
|
||||
$service->update(['vm_id' => $vmId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gửi email nhắc gia hạn dịch vụ cho khách hàng.
|
||||
*/
|
||||
public function notifyRenewal(string $uuid, int $serviceId): void
|
||||
{
|
||||
$customer = $this->resolveCustomer($uuid);
|
||||
|
||||
$service = Service::where('customer_id', $customer->id)->where('id', $serviceId)
|
||||
->with(['product', 'orderItem'])
|
||||
->first();
|
||||
abort_if(!$service, 404, 'Không tìm thấy dịch vụ');
|
||||
abort_if(!$customer->email, 422, 'Khách hàng chưa có email');
|
||||
|
||||
Mail::to($customer->email)->send(new ServiceRenewalReminderMail($customer, $service));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a service for a customer. For VPS products, accepts a
|
||||
* `virtual_machine_id` from the vCenter inventory and auto-creates the
|
||||
|
||||
Reference in New Issue
Block a user