First invoice implementation.

This commit is contained in:
2025-01-04 14:25:13 +01:00
parent 96c7fc272a
commit 3b51ab109d
15 changed files with 942 additions and 2 deletions

View File

@@ -3,8 +3,77 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Invoice extends Model
{
//
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'user_id',
'customer_id',
'address_id',
'delivery_id',
'invoice_number',
'type',
'status',
'sum',
'tax',
];
/**
* The attributes that are appended with attribute getters.
*
* @var string[]
*/
protected $appends = [
'created',
'number'
];
/**
* Get the invoice number formatted
*/
public function getNumberAttribute(): string
{
return $this->created_at->format('Y') . '-' . str_pad($this->invoice_number, 5, '0', STR_PAD_LEFT);
}
/**
* Get the created_at attribute in local time format.
*
* @return string
*/
public function getCreatedAttribute(): string
{
return $this->created_at->format('d.m.Y');
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}
public function address(): BelongsTo
{
return $this->belongsTo(Address::class)->withTrashed();
}
public function delivery(): BelongsTo
{
return $this->belongsTo(Address::class)->withTrashed();
}
public function items(): HasMany
{
return $this->hasMany(Invoiceitem::class);
}
}

View File

@@ -7,5 +7,20 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class Invoiceitem extends Model
{
use SoftDeletes;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'invoice_id',
'amount',
'discount',
'tax',
'price',
'total',
'name',
'description',
];
}