This commit is contained in:
baodev0
2026-09-23 15:17:18 +07:00
parent cd38c5d6d0
commit 82a71244ca
107 changed files with 3332 additions and 3306 deletions
@@ -22,9 +22,14 @@ class InvoiceResource extends JsonResource
'discount_amount' => $this->discount_amount,
'tax' => $this->tax,
'total' => $this->total,
// Công nợ: đã thu bao nhiêu / còn thiếu bao nhiêu. Kế toán cần thấy ngay trên
// danh sách thay vì phải suy từ số dư ví của khách.
'amount_paid' => (int) $this->amount_paid,
'outstanding' => \App\Services\InvoicePaymentService::outstanding($this->resource),
'status' => $this->status,
'due_date' => $this->due_date,
'paid_at' => $this->paid_at,
'reminder_step' => (int) $this->reminder_step,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
@@ -56,10 +56,13 @@ class OrderResource extends JsonResource
'discount_amount' => $invoice->discount_amount,
'tax' => $invoice->tax,
'total' => $invoice->total,
'amount_paid' => (int) $invoice->amount_paid,
'outstanding' => \App\Services\InvoicePaymentService::outstanding($invoice),
'status' => $invoice->status,
'date' => $invoice->created_at,
'due_date' => $invoice->due_date,
'date_paid' => $invoice->paid_at,
'reminder_step' => (int) $invoice->reminder_step,
'billing_period_start' => $invoice->billing_period_start,
'billing_period_end' => $invoice->billing_period_end,
// Which service(s)/product(s) this invoice actually bills for — without this,
@@ -4,6 +4,8 @@ namespace App\Http\Resources\Api\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
class ClientResource extends JsonResource
{
@@ -31,9 +33,9 @@ class ClientResource extends JsonResource
'date' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : null,
'company' => $this->company ?? '',
'avatar' => $this->avatar,
'cmnd_before' => $this->front_identity_number,
'cmnd_after' => $this->back_identity_number,
'cmnd' => $this->identity_number,
'cmnd_before' => $this->cccdUrl('front', $this->front_identity_number),
'cmnd_after' => $this->cccdUrl('back', $this->back_identity_number),
'cmnd' => $this->identity_number ? Str::mask($this->identity_number, '*', 0, -4) : null,
'fb_link' => null,
'active_2fa' => 0,
'off_mail_marketing' => $this->off_mail_marketing,
@@ -57,4 +59,18 @@ class ClientResource extends JsonResource
]
];
}
/**
* Ảnh CCCD trên disk private → URL ký tương đối (/v1/client/cccd/...), hết hạn 60 phút.
*/
private function cccdUrl(string $side, ?string $path): string
{
if (!$path) {
return '';
}
// Giá trị import từ portal cũ (/uploads/... trên host cũ) cũng chỉ trả URL ký — không lộ đường dẫn gốc;
// route trả 404 cho chúng vì file không có trên disk private. Vẫn khác rỗng để hasCccd giữ nguyên hành vi.
return URL::temporarySignedRoute('api.client.cccd', now()->addHour(), ['customer' => $this->id, 'side' => $side], false);
}
}
@@ -21,6 +21,9 @@ class InvoiceDetailResource extends JsonResource
'discount_amount' => (float) ($this->discount_amount ?? 0),
'tax' => (float) $this->tax,
'total' => (float) $this->total,
// Công nợ: đã thu / còn thiếu. Dịch vụ chỉ kích hoạt khi outstanding = 0.
'amount_paid' => (float) $this->amount_paid,
'outstanding' => (float) \App\Services\InvoicePaymentService::outstanding($this->resource),
'payment_method' => $this->resolvePaymentMethod($this->resource),
'auto_renew' => (bool) $this->auto_renew,
'created_at' => $this->created_at?->toISOString(),
@@ -15,6 +15,9 @@ class InvoiceSummaryResource extends JsonResource
'invoice_number' => $this->invoice_number,
'service_name' => $this->order?->orderItems->first()?->product?->name ?? ('Đơn hàng ' . $this->order?->order_num),
'total' => (float) $this->total,
// Khách trả một phần thì hoá đơn vẫn chưa thanh toán — phải thấy được còn thiếu bao nhiêu.
'amount_paid' => (float) $this->amount_paid,
'outstanding' => (float) \App\Services\InvoicePaymentService::outstanding($this->resource),
'status' => $this->status,
'status_text' => InvoiceStatus::tryFrom((int) $this->status)?->label() ?? '-',
'created_at' => $this->created_at?->toISOString(),