Show a monthly fee job's billed periods on a page of its own

The new billing::job-months page lists the months that created billing
materials have billed for a monthly fee job, with links to the materials
and the total, and the months still to bill up to the current month,
counted the same way as a new material counts them. The job page links
to it next to the payment basis for those who manage billing.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 15:56:15 +02:00
co-authored by Claude Sonnet 5.5
parent e817cca329
commit bc3dbf16a4
16 changed files with 470 additions and 3 deletions
@@ -3,13 +3,16 @@
namespace App\Modules\Billing\Infrastructure\Persistence\Repositories;
use App\Modules\Billing\Application\Contracts\BillingQueries;
use App\Modules\Billing\Application\DTOs\BilledMonth;
use App\Modules\Billing\Application\DTOs\ExportSummary;
use App\Modules\Billing\Domain\Enums\ExportStatus;
use App\Modules\Billing\Domain\Enums\LineKind;
use App\Modules\Billing\Infrastructure\Persistence\Eloquent\BillingExportModel;
use App\Modules\Billing\Infrastructure\Persistence\Eloquent\BillingInvoiceJobModel;
use App\Modules\Billing\Infrastructure\Persistence\Eloquent\BillingLineModel;
use App\Modules\Users\Application\Contracts\UserAccountQueries;
use DateTimeImmutable;
use DateTimeZone;
class EloquentBillingQueries implements BillingQueries
{
@@ -54,4 +57,32 @@ class EloquentBillingQueries implements BillingQueries
$model->status === ExportStatus::Created ? (int) ($netSums[$model->id] ?? 0) : null,
))->values()->all();
}
public function billedMonthsOf(int $jobId): array
{
return BillingLineModel::query()
->join('billing_invoices', 'billing_invoices.id', '=', 'billing_lines.billing_invoice_id')
->join('billing_exports', 'billing_exports.id', '=', 'billing_invoices.billing_export_id')
->where('billing_lines.customer_job_id', $jobId)
->where('billing_lines.kind', LineKind::MonthlyFee)
->whereNotNull('billing_lines.period')
->where('billing_exports.status', ExportStatus::Created)
->orderBy('billing_lines.period')
->get([
'billing_lines.period',
'billing_lines.net_cents',
'billing_exports.id as export_id',
'billing_exports.number as export_number',
'billing_exports.finalized_at',
])
->map(fn (BillingLineModel $line): BilledMonth => new BilledMonth(
(string) $line->getAttribute('period'),
(int) $line->getAttribute('export_id'),
(int) $line->getAttribute('export_number'),
$line->getAttribute('finalized_at') === null ? null : new DateTimeImmutable((string) $line->getAttribute('finalized_at'), new DateTimeZone('UTC')),
$line->net_cents,
))
->values()
->all();
}
}