Apply changes when creating invoices for projects.
All checks were successful
Build project image / Build-and-release-image (push) Successful in 3m9s
All checks were successful
Build project image / Build-and-release-image (push) Successful in 3m9s
This commit is contained in:
@@ -43,9 +43,9 @@ class InvoiceController extends Controller
|
||||
'address_id' => 'required|integer|exists:addresses,id',
|
||||
'delivery_id' => 'nullable|integer|exists:addresses,id',
|
||||
'project_id' => 'nullable|integer|exists:projects,id',
|
||||
'project_count' => 'nullable|integer',
|
||||
'currency_code' => 'required|string',
|
||||
'type' => [Rule::enum(InvoiceTypeCode::class)],
|
||||
'project_count' => 'nullable|integer',
|
||||
'tax' => 'required|numeric',
|
||||
'sum' => 'required|numeric',
|
||||
'due_date' => 'required|date',
|
||||
@@ -73,6 +73,7 @@ class InvoiceController extends Controller
|
||||
'address_id' => 'required|integer|exists:addresses,id',
|
||||
'delivery_id' => 'nullable|integer|exists:addresses,id',
|
||||
'project_id' => 'nullable|integer|exists:projects,id',
|
||||
'project_count' => 'nullable|integer',
|
||||
'currency_code' => 'required|string',
|
||||
'type' => [Rule::enum(InvoiceTypeCode::class)],
|
||||
'tax' => 'required|numeric',
|
||||
|
||||
@@ -43,25 +43,6 @@ class Invoice extends Model
|
||||
'localized_state'
|
||||
];
|
||||
|
||||
/**
|
||||
* Set the project_count variable automatically, if a project is related to this invoice.
|
||||
*/
|
||||
public static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
self::creating(function (Invoice $invoice) {
|
||||
if (is_null($invoice->project_id)) {
|
||||
return true;
|
||||
}
|
||||
if ($invoice->type != '326') {
|
||||
return true;
|
||||
}
|
||||
$projectMax = Invoice::where('project_id', '=', $invoice->project_id)->max('project_count') + 1;
|
||||
$invoice->project_count = $projectMax;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the invoice state as translated string.
|
||||
*/
|
||||
|
||||
@@ -36,6 +36,7 @@ class Project extends Model
|
||||
'end',
|
||||
'customer_email',
|
||||
'customer_name',
|
||||
'next_invoice_count',
|
||||
];
|
||||
|
||||
|
||||
@@ -56,6 +57,14 @@ class Project extends Model
|
||||
return (is_null($this->start_date)) ? '' : Carbon::createFromFormat('Y-m-d', $this->start_date)->format('d.m.Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next invoice number for this project.
|
||||
*/
|
||||
public function getNextInvoiceCountAttribute(): int
|
||||
{
|
||||
return $this->invoices()->max('project_count') + 1 ?? 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the end_date attribute in local format.
|
||||
*/
|
||||
@@ -72,6 +81,9 @@ class Project extends Model
|
||||
return $this->belongsTo(Customer::class)->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the invoices for this project.
|
||||
*/
|
||||
public function invoices(): HasMany
|
||||
{
|
||||
return $this->hasMany(Invoice::class);
|
||||
|
||||
Reference in New Issue
Block a user