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);
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
<template x-for="(project, index) in getFilteredProject()">
|
||||
<div class="cursor-pointer grid grid-cols-4 even:bg-gray-100 odd:bg-white"
|
||||
:class="project.id == invoice.project_id ? 'font-bold' : ''"
|
||||
@click="invoice.project_id = project.id; selected_project = project; invoice.customer_id = project.customer.id; selected_customer = project.customer; getCustomerAddresses();">
|
||||
@click="invoice.project_id = project.id; selected_project = project; invoice.customer_id = project.customer.id; selected_customer = project.customer; invoice.project_count = project.next_invoice_count; getCustomerAddresses();">
|
||||
<div x-text="project.name"></div>
|
||||
<div x-text="project.project_number"></div>
|
||||
<div x-text="project.customer_name"></div>
|
||||
@@ -231,7 +231,7 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex flex-row items-center"
|
||||
x-show="!from_project && (invoice.type === '326' || invoice.type === '875')">
|
||||
x-show="invoice.type === '326' || invoice.type === '875'">
|
||||
<x-input-label class="w-1/3" for="project_count"
|
||||
:value="__('invoice.Partial invoice number')"/>
|
||||
<x-text-input id="project_count" name="project_count" type="text"
|
||||
@@ -401,7 +401,6 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<x-primary-button x-on:click="submit();" class="">{{ __('form.Save') }}</x-primary-button>
|
||||
|
||||
</div>
|
||||
@@ -443,6 +442,7 @@
|
||||
tax: 0,
|
||||
sum: 0,
|
||||
project_id: null,
|
||||
project_count: null,
|
||||
due_date: '{!! \Illuminate\Support\Carbon::today()->addDays(intval($options->payment_terms))->format('Y-m-d') !!}',
|
||||
cash_discount: 0,
|
||||
cash_discount_date: '{!! \Illuminate\Support\Carbon::today()->addDays(intval($options->cash_discount_date))->format('Y-m-d') !!}',
|
||||
|
||||
@@ -232,7 +232,7 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="flex flex-row items-center"
|
||||
x-show="!from_project && (invoice.type === '326' || invoice.type === '875')">
|
||||
x-show="invoice.type === '326' || invoice.type === '875'">
|
||||
<x-input-label class="w-1/3" for="project_count"
|
||||
:value="__('invoice.Partial invoice number')"/>
|
||||
<x-text-input id="project_count" name="project_count" type="text"
|
||||
|
||||
@@ -81,9 +81,9 @@
|
||||
|
||||
@if($invoice->project)
|
||||
<div class="flex flex-row items-center">
|
||||
<x-input-label class="w-1/3" for="project_count"
|
||||
<x-input-label class="w-1/3" for="project_name"
|
||||
:value="__('project.Project')"/>
|
||||
<x-text-input id="project_count" name="project_count" type="text"
|
||||
<x-text-input id="project_name" name="project_name" type="text"
|
||||
value="{{ $invoice->project->name }}"
|
||||
class="mt-1 w-2/3"
|
||||
autofocus disabled
|
||||
@@ -91,9 +91,9 @@
|
||||
|
||||
</div>
|
||||
<div class="flex flex-row items-center">
|
||||
<x-input-label class="w-1/3" for="project_count"
|
||||
<x-input-label class="w-1/3" for="project_number"
|
||||
:value="__('project.Project Number')"/>
|
||||
<x-text-input id="project_count" name="project_count" type="text"
|
||||
<x-text-input id="project_number" name="project_number" type="text"
|
||||
value="{{ $invoice->project->project_number }}"
|
||||
class="mt-1 w-2/3"
|
||||
autofocus disabled
|
||||
|
||||
Reference in New Issue
Block a user