Invoice model
This commit is contained in:
parent
6c4deaa298
commit
67de82a525
|
|
@ -0,0 +1,29 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Casts;
|
||||||
|
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class MoneyCast implements CastsAttributes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Cast the given value.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $attributes
|
||||||
|
*/
|
||||||
|
public function get(Model $model, string $key, mixed $value, array $attributes): float
|
||||||
|
{
|
||||||
|
return $value / 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the given value for storage.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $attributes
|
||||||
|
*/
|
||||||
|
public function set(Model $model, string $key, mixed $value, array $attributes): int
|
||||||
|
{
|
||||||
|
return (int) round($value * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum InvoiceStatus: string
|
||||||
|
{
|
||||||
|
case DRAFT = 'draft';
|
||||||
|
case POSTED = 'posted';
|
||||||
|
case VOID = 'void';
|
||||||
|
case PAID = 'paid';
|
||||||
|
}
|
||||||
|
|
@ -2,9 +2,22 @@
|
||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Casts\MoneyCast;
|
||||||
|
use App\Enums\InvoiceStatus;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class Invoice extends Model
|
class Invoice extends Model
|
||||||
{
|
{
|
||||||
//
|
protected $casts = [
|
||||||
|
'total' => MoneyCast::class,
|
||||||
|
'status' => InvoiceStatus::class,
|
||||||
|
'invoice_date' => 'date',
|
||||||
|
'due_date' => 'date',
|
||||||
|
'date_sent' => 'date',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function formattedTotal(): string
|
||||||
|
{
|
||||||
|
return '$'.number_format($this->total, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,13 @@ return new class extends Migration
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->string('invoice_number')->unique();
|
$table->string('invoice_number')->unique();
|
||||||
$table->foreignIdFor(Client::class);
|
$table->foreignIdFor(Client::class);
|
||||||
$table->json('lines');
|
$table->string('status')->default('draft');
|
||||||
|
$table->date('invoice_date')->nullable();
|
||||||
|
$table->date('date_sent')->nullable();
|
||||||
|
$table->date('due_date')->nullable();
|
||||||
|
$table->integer('total');
|
||||||
|
$table->text('notes')->nullable();
|
||||||
|
$table->text('internal_notes')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue