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:
baodev0
2026-10-19 16:37:56 +07:00
co-authored by Claude Sonnet 5.5
parent ea9a53f742
commit 25f23d541e
134 changed files with 4926 additions and 185 deletions
@@ -8,6 +8,7 @@ use App\Models\Invoice;
use App\Models\InvoiceItem;
use App\Models\Order;
use App\Repositories\Api\BaseApiRepository;
use App\Support\VatNumbering;
class InvoiceRepository extends BaseApiRepository implements InvoiceRepositoryInterface
{
@@ -37,6 +38,7 @@ class InvoiceRepository extends BaseApiRepository implements InvoiceRepositoryIn
// sub_total là tổng TRƯỚC giảm giá, để sub_total - discount_amount = total.
'sub_total' => (int) $order->total + $discount,
'discount_amount' => $discount,
'coupon_code' => $order->coupon_code,
'tax' => 0,
'total' => $order->total,
'status' => InvoiceStatus::UNPAID->value,
@@ -78,7 +80,7 @@ class InvoiceRepository extends BaseApiRepository implements InvoiceRepositoryIn
}
}
return $invoice;
return VatNumbering::settle($invoice);
}
// -------------------------------------------------------------------------
@@ -2,6 +2,7 @@
namespace App\Repositories\Api\Service;
use App\Support\ProductBillingCycles;
use App\Models\Product;
use App\Repositories\Api\BaseApiRepository;
@@ -35,8 +36,13 @@ class ServiceRepository extends BaseApiRepository implements ServiceRepositoryIn
public function getPricing(int $productId, string $billingCycle)
{
$pricing = $this->model->find($productId)
->pricings()
$product = $this->model->find($productId);
if (!ProductBillingCycles::allows($product->product_type, $billingCycle)) {
return null;
}
$pricing = $product->pricings()
->where('billing_cycle', $billingCycle)
->where('is_active', 1)
->first();
@@ -2,6 +2,7 @@
namespace App\Repositories\Api\ServiceClient;
use App\Support\ProductBillingCycles;
use App\Models\Service;
use App\Repositories\Api\BaseApiRepository;
@@ -46,8 +47,13 @@ class ServiceClientRepository extends BaseApiRepository implements ServiceClient
public function getPricing(int $productId, string $billingCycle)
{
$pricing = $this->model->find($productId)
->pricings()
$product = $this->model->find($productId);
if (!ProductBillingCycles::allows($product->product_type, $billingCycle)) {
return null;
}
$pricing = $product->pricings()
->where('billing_cycle', $billingCycle)
->where('is_active', 1)
->first();