refactor: remove global RateCardProfile singleton usage from controllers and delete unused welcome view

This commit is contained in:
I-Fun
2026-04-06 09:33:43 +07:00
parent a72eec3ead
commit 737ba24293
9 changed files with 155 additions and 268 deletions

View File

@@ -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;
}
}