feat: add GeneratesUniqueSlug class for unique slug generation

feat: create PostCategoryFactory for generating post category data

feat: create PostFactory for generating post data

feat: add retry_requested_at column to services table

feat: add vcenter provisioning fields to products table

feat: add module_host_id to os table

feat: create email_notification_templates table for email templates

feat: add scenario and format fields to template table

feat: add admin fields to transactions table

fix: update ticket table columns and types

feat: add uuid to ticket table and backfill existing records

fix: make ticket_reply user_id nullable

feat: create notifications table for user notifications

fix: make ticket uuid nullable

feat: create post_categories table for blog categories

feat: create posts table for blog posts

feat: add invoice email template for PDF generation
This commit is contained in:
baodev0
2026-05-25 15:39:42 +07:00
parent a31d238135
commit 520f21cb11
73 changed files with 4682 additions and 440 deletions
@@ -10,6 +10,7 @@ use App\Models\Customer;
use App\Models\Invoice;
use App\Models\Order;
use App\Models\Transaction;
use App\Models\Log;
use App\Repositories\Customer\CustomerRepositoryInterface;
use App\Repositories\Invoice\InvoiceRepositoryInterface;
use App\Repositories\InvoiceItem\InvoiceItemRepositoryInterface;
@@ -23,6 +24,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Str;
class CustomerController extends Controller
@@ -370,6 +372,87 @@ class CustomerController extends Controller
}
}
public function addTotal(Request $request, string $uuid): JsonResponse
{
$request->validate([
'amount' => 'required|numeric|min:1',
'note' => 'required|string|max:1000',
]);
$customer = $this->customerRepository->findBy('uuid', $uuid);
if (!$customer) {
return response()->json([
'error' => true,
'message' => "Can't find customer by UUID #" . $uuid,
], 404);
}
$admin = Auth::guard('admin')->user();
if (!$admin) {
return response()->json([
'error' => true,
'message' => 'Unauthorized',
], 401);
}
try {
DB::beginTransaction();
$amount = (int) $request->amount;
$transaction = Transaction::create([
'uuid' => (string) Str::uuid(),
'trans' => 'ADMIN' . now()->format('YmdHis'),
'amount' => $amount,
'customer_id' => $customer->id,
'user_id' => $admin->id,
'status' => 1,
'type' => 'admin_add_total',
'note' => $request->string('note')->trim()->toString(),
]);
$customer->update([
'total' => (int) $customer->total + $amount,
]);
Log::create([
'agent' => 'admin',
'client_ip' => $request->ip(),
'description' => sprintf(
'%s cộng tiền trực tiếp cho customer %s: %s VNĐ - %s',
$admin->username ?? $admin->email,
$customer->email,
number_format($amount),
$transaction->note,
),
'customer_id' => $customer->id,
]);
DB::commit();
return response()->json([
'error' => false,
'message' => 'Total updated successfully',
'data' => [
'transaction' => [
'uuid' => $transaction->uuid,
'amount' => $transaction->amount,
'note' => $transaction->note,
'admin' => $admin->username ?? $admin->email,
],
],
]);
} catch (\Exception $e) {
DB::rollBack();
return response()->json([
'error' => true,
'message' => $e->getMessage(),
], 500);
}
}
public function getProducts(string $uuid): JsonResponse
{
$customer = $this->customerRepository->findBy('uuid', $uuid);
@@ -446,7 +529,10 @@ class CustomerController extends Controller
], 404);
}
$transactions = $this->transactionRepository->filter(['customer_id' => $customer->id]);
$transactions = $this->transactionRepository->filter(
['customer_id' => $customer->id],
['user']
);
return response()->json([
'error' => false,