InvoiceStatus::class, 'issue_date' => 'date', 'due_date' => 'date', 'paid_date' => 'date', 'subtotal' => 'decimal:2', 'tax_rate' => 'decimal:2', 'tax_amount' => 'decimal:2', 'total' => 'decimal:2', ]; public function client(): BelongsTo { return $this->belongsTo(Client::class); } public function items(): HasMany { return $this->hasMany(InvoiceItem::class); } public function recalculate(): void { $this->subtotal = $this->items->sum('total'); $this->tax_amount = round($this->subtotal * ($this->tax_rate / 100), 2); $this->total = $this->subtotal + $this->tax_amount; $this->save(); } public function getFormattedTotalAttribute(): string { return 'Rp ' . number_format((float) $this->total, 0, ',', '.'); } public static function generateNumber(): string { $prefix = 'INV-' . now()->format('Ym'); $last = static::where('invoice_number', 'like', $prefix . '%')->count(); return $prefix . '-' . str_pad((string) ($last + 1), 3, '0', STR_PAD_LEFT); } }