feat: Implement comprehensive product management, including categories, pricing, and integration into the order system.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Order;
|
||||
|
||||
class OrderHelper
|
||||
{
|
||||
/**
|
||||
* Generate a unique order number with prefix.
|
||||
*
|
||||
* @param string $prefix
|
||||
* @return string
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
} while ($exists);
|
||||
|
||||
return $orderNum;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user