refactor: remove global RateCardProfile singleton usage from controllers and delete unused welcome view
This commit is contained in:
@@ -35,25 +35,39 @@ class InvoiceSettings extends Model
|
||||
'default_tax_rate' => 'decimal:2',
|
||||
];
|
||||
|
||||
protected static ?self $instance = null;
|
||||
|
||||
/** Always return the single settings row, creating it if absent. */
|
||||
public static function instance(): self
|
||||
{
|
||||
return static::firstOrCreate([], [
|
||||
if (self::$instance) {
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
self::$instance = static::firstOrCreate([], [
|
||||
'invoice_prefix' => 'INV',
|
||||
'invoice_next_number' => 1,
|
||||
'accent_color' => '#FFB7C5',
|
||||
'default_tax_rate' => 2.5,
|
||||
'default_currency' => 'IDR',
|
||||
]);
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::saved(fn ($model) => self::$instance = $model);
|
||||
static::deleted(fn () => self::$instance = null);
|
||||
}
|
||||
|
||||
/** Generate the next invoice number and increment the counter. */
|
||||
public static function generateNumber(): string
|
||||
{
|
||||
$settings = static::instance();
|
||||
$prefix = rtrim($settings->invoice_prefix, '-');
|
||||
$number = str_pad((string) $settings->invoice_next_number, 3, '0', STR_PAD_LEFT);
|
||||
$settings->increment('invoice_next_number');
|
||||
\Illuminate\Support\Facades\Cache::forget('invoice_settings');
|
||||
return $prefix . '-' . $number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,16 +26,30 @@ class RateCardProfile extends Model
|
||||
'content_showcase' => 'array',
|
||||
];
|
||||
|
||||
protected static ?self $instance = null;
|
||||
|
||||
/** Get the singleton profile, creating defaults if needed */
|
||||
public static function getSingleton(): self
|
||||
{
|
||||
return static::firstOrCreate([], [
|
||||
if (self::$instance) {
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
self::$instance = static::firstOrCreate([], [
|
||||
'owner_name' => config('app.name', 'Cathy Page'),
|
||||
'bg_color' => '#FFF8F0',
|
||||
'accent_color' => '#FFB7C5',
|
||||
'text_color' => '#374151',
|
||||
'show_prices' => true,
|
||||
]);
|
||||
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
protected static function booted()
|
||||
{
|
||||
static::saved(fn ($model) => self::$instance = $model);
|
||||
static::deleted(fn () => self::$instance = null);
|
||||
}
|
||||
|
||||
public function getWhatsappUrlAttribute(): ?string
|
||||
|
||||
Reference in New Issue
Block a user