Add the billing material with drafts, combined invoices and billed marks
Management builds the monthly billing material (laskuaineisto) as a draft: done jobs are added as invoices of their own, combined when the customer, billing unit and reference allow it, and their billable hours are set per work type. Creating the material checks the jobs again, marks the approved hours and billable expenses billed, forms invoice lines with price and VAT snapshots and moves the jobs to "Lasku luotu". Fixed price jobs bill their quoted amount once. Billed hours keep their approval and billed expenses can no longer change. The Fennoa export and monthly fee lines come later. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+47
@@ -7,6 +7,7 @@ use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobDetails;
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobSummary;
|
||||
use App\Modules\Jobs\Application\DTOs\JobBillingInfo;
|
||||
use App\Modules\Jobs\Application\DTOs\JobChangeEntry;
|
||||
use App\Modules\Jobs\Application\DTOs\JobListFilter;
|
||||
use App\Modules\Jobs\Application\DTOs\NamedId;
|
||||
@@ -184,6 +185,52 @@ class EloquentCustomerJobQueries implements CustomerJobQueries
|
||||
);
|
||||
}
|
||||
|
||||
public function billingInfoWithStatus(JobStatus $status): array
|
||||
{
|
||||
return array_values($this->billingInfo(CustomerJobModel::query()->where('status', $status)->orderBy('number')->get()));
|
||||
}
|
||||
|
||||
public function billingInfoOf(array $ids): array
|
||||
{
|
||||
return $ids === [] ? [] : $this->billingInfo(CustomerJobModel::query()->whereIn('id', $ids)->orderBy('number')->get());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, CustomerJobModel> $models
|
||||
* @return array<int, JobBillingInfo>
|
||||
*/
|
||||
private function billingInfo(Collection $models): array
|
||||
{
|
||||
$customerNames = $this->customers->namesByIds($models->pluck('customer_id')->unique()->values()->all());
|
||||
$billingUnitNames = [];
|
||||
$result = [];
|
||||
|
||||
foreach ($models as $model) {
|
||||
if ($model->billing_unit_id !== null && ! isset($billingUnitNames[$model->customer_id])) {
|
||||
$billingUnitNames[$model->customer_id] = [];
|
||||
foreach ($this->customers->billingUnitsOf($model->customer_id) as $unit) {
|
||||
$billingUnitNames[$model->customer_id][$unit->id] = $unit->name;
|
||||
}
|
||||
}
|
||||
|
||||
$result[$model->id] = new JobBillingInfo(
|
||||
$model->id,
|
||||
$model->number,
|
||||
$model->name,
|
||||
$model->customer_id,
|
||||
$customerNames[$model->customer_id] ?? '',
|
||||
$model->status,
|
||||
$model->payment_basis,
|
||||
$model->quoted_amount_cents,
|
||||
$model->customer_reference,
|
||||
$model->billing_unit_id,
|
||||
$model->billing_unit_id === null ? null : ($billingUnitNames[$model->customer_id][$model->billing_unit_id] ?? null),
|
||||
);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function changes(int $jobId): array
|
||||
{
|
||||
$rows = DB::table('customer_job_changes')->where('customer_job_id', $jobId)->orderByDesc('id')->get();
|
||||
|
||||
Reference in New Issue
Block a user