Add contract management and invoice settings pages

- Created a new Blade view for managing brand contracts with forms for adding and editing contracts, including client and category selection.
- Implemented success message notifications for contract actions.
- Added a new Blade view for invoice settings, allowing customization of invoice number format, header branding, and default values for new invoices.
- Introduced a new PDF view for generating rate cards with customizable styles based on user profile settings.
- Developed a profile management page for rate cards, enabling users to update their identity, appearance, and visibility settings.
This commit is contained in:
I-Fun
2026-04-01 21:47:34 +07:00
parent d3c35ad730
commit 22f03ccca7
48 changed files with 2415 additions and 296 deletions

View File

@@ -6,6 +6,7 @@ namespace App\Models;
use App\Enums\InvoiceStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
// InvoiceSettings used for number generation
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -19,7 +20,7 @@ class Invoice extends Model
'client_id', 'invoice_number', 'title', 'description',
'subtotal', 'tax_rate', 'tax_amount', 'total', 'currency',
'status', 'issue_date', 'due_date', 'paid_date', 'notes',
'bank_name', 'bank_account', 'bank_holder',
'bank_name', 'bank_account', 'bank_holder', 'branch_name',
];
protected $casts = [
@@ -45,9 +46,15 @@ class Invoice extends Model
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;
// Total of all items (what the creator receives)
$this->subtotal = $this->items->sum('total');
// Tax is calculated only on taxable items, but paid by the client on top
$taxableSubtotal = $this->items->where('is_taxable', true)->sum('total');
$this->tax_amount = round((float) $taxableSubtotal * ($this->tax_rate / 100), 2);
// Grand total = subtotal (creator's fee, pre-tax — tax is borne by client separately)
$this->total = $this->subtotal;
$this->save();
}
@@ -58,8 +65,6 @@ class Invoice extends Model
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);
return InvoiceSettings::generateNumber();
}
}