feat: add domain registration form and email notifications

- Create a new Blade view for domain registration (`registrant-tochuc.blade.php`) to capture organization and manager details.
- Implement email templates for new domain orders for both admin (`domain-order-new.blade.php`) and customers (`domain-order-received.blade.php`).
- Add CSV exports for client and domain data.
- Introduce tests for customer mass assignment, password reset, login throttling, and permission gating.
- Ensure service renewals use current pricing and validate ownership for virtual machines.
- Validate mass assignment behavior in service model.
This commit is contained in:
baodev0
2026-08-22 17:30:55 +07:00
parent eec2c5906e
commit c377c7e195
58 changed files with 3063 additions and 418 deletions
@@ -1,131 +0,0 @@
<?php
namespace App\Http\Controllers\Api\Admin\Invoice;
use App\Http\Controllers\Controller;
use App\Jobs\Mail\SendInformationVirtualMachine;
use App\Jobs\VirtualMachine\Provision\SendVmCredentialsEmailJob;
use App\Models\Invoice;
use App\Models\ModuleVmware;
use App\Models\Setting;
use App\Services\InvoicePdfService;
use Barryvdh\DomPDF\Facade\Pdf;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class InvoiceTestController extends Controller
{
public function sendInvoiceEmail(Request $request, string $invoiceNumber): JsonResponse
{
$invoice = Invoice::with(['invoiceItems.product', 'customer', 'order.orderItems'])
->where('invoice_number', $invoiceNumber)
->first();
if (!$invoice) {
return response()->json([
'success' => false,
'message' => 'Không tìm thấy hóa đơn.',
], 404);
}
$customer = $invoice->customer;
if (!$customer?->email) {
return response()->json([
'success' => false,
'message' => 'Khách hàng không có email.',
], 400);
}
try {
$pdfService = app(InvoicePdfService::class);
$invoicePdf = $pdfService->generate($invoice);
$invoicePdfFileName = $pdfService->generateFileName($invoice);
} catch (\Throwable $e) {
return response()->json([
'success' => false,
'message' => 'Lỗi tạo PDF: ' . $e->getMessage(),
], 500);
}
$vm = ModuleVmware::with(['customer', 'os.osGroup', 'order.orderItems'])
->where('order_id', $invoice->order_id)
->first();
if ($vm) {
SendVmCredentialsEmailJob::dispatch($vm->id);
return response()->json([
'success' => true,
'message' => 'Đã dispatch SendVmCredentialsEmailJob (có PDF hóa đơn đính kèm).',
'data' => [
'invoice_id' => $invoice->id,
'invoice_number' => $invoice->invoice_number,
'customer_email' => $customer->email,
'vm_id' => $vm->id,
'pdf_file_name' => $invoicePdfFileName,
],
]);
}
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value) : null;
$emailData = [
'company_name' => $settingValue->company ?? 'Thế Giới Số',
'company_logo' => $settingValue->logo ?? '',
'client_name' => trim($customer->firstname . ' ' . $customer->lastname),
'product_name' => $invoice->invoiceItems->first()?->product?->name ?? 'Dịch vụ',
'product_billing' => 'N/A',
'product_price' => number_format((float) $invoice->total, 0, ',', '.'),
'service_host' => 'N/A',
'service_username' => 'N/A',
'service_port' => 'N/A',
'service_password' => 'N/A',
'os_name' => 'N/A',
'service_due_exp' => $invoice->due_date ? $invoice->due_date->format('d/m/Y') : 'N/A',
];
SendInformationVirtualMachine::dispatch($emailData, $customer, $invoicePdf, $invoicePdfFileName);
return response()->json([
'success' => true,
'message' => 'Đã gửi email hóa đơn (không có VM liên kết, sử dụng thông tin hóa đơn).',
'data' => [
'invoice_id' => $invoice->id,
'invoice_number' => $invoice->invoice_number,
'customer_email' => $customer->email,
'pdf_file_name' => $invoicePdfFileName,
],
]);
}
public function previewInvoicePdf(Request $request, string $invoiceNumber)
{
$invoice = Invoice::with(['invoiceItems.product', 'customer', 'order.orderItems'])
->where('invoice_number', $invoiceNumber)
->first();
if (!$invoice) {
return response()->json([
'success' => false,
'message' => 'Không tìm thấy hóa đơn.',
], 404);
}
$setting = Setting::where('key', 'setting')->first();
$settingValue = $setting ? json_decode((string) $setting->value) : null;
return Pdf::loadView('pdf.invoice', [
'invoice' => $invoice,
'invoiceItems' => $invoice->invoiceItems,
'customer' => $invoice->customer,
'order' => $invoice->order,
'companyName' => $settingValue->company ?? 'Thế Giới Số',
'companyAddress' => $settingValue->address ?? '',
'companyPhone' => $settingValue->phone ?? '',
'companyEmail' => $settingValue->email ?? '',
])
->setPaper('a4', 'portrait')
->stream($invoice->invoice_number . '.pdf');
}
}