feat: Reimplement order and invoice management with new service and repository layers, introduce compression middleware, and update database schema.

This commit is contained in:
pbao9
2026-03-12 09:30:29 +07:00
parent 7f6264c87f
commit 1e09ccf17b
87 changed files with 2348 additions and 2612 deletions
+15 -15
View File
@@ -2,32 +2,32 @@
namespace App\Helpers;
use Illuminate\Support\Str;
use App\Models\Invoice;
use App\Models\Order;
use Illuminate\Support\Str;
class OrderHelper
{
/**
* Generate a unique order number with prefix.
* Generate a unique prefixed number.
*
* @param string $prefix
* @return string
* Examples:
* generateOrderNumber() → ORD-A1B2C3D4
* generateOrderNumber('INV') → INV-A1B2C3D4
*
* Uniqueness is guaranteed by checking the correct column on each model.
*/
public static function generateOrderNumber(string $prefix = 'ORD'): string
{
do {
// Generate a random string of 8 uppercase characters/numbers
$random = strtoupper(Str::random(8));
$orderNum = $prefix . '-' . $random;
if ($prefix === 'INV') {
$exists = \App\Models\Invoice::where('order_num', $orderNum)->exists();
} else {
$exists = Order::where('order_num', $orderNum)->exists();
}
$number = $prefix . '-' . strtoupper(Str::random(8));
$exists = match ($prefix) {
'INV' => Invoice::where('invoice_num', $number)->exists(),
default => Order::where('order_num', $number)->exists(),
};
} while ($exists);
return $orderNum;
return $number;
}
}