Count billing materials without a billing month in reports

Materials created before billing months existed have no period, so the
profitability report left out what they billed. Their month is now the
month they were created in, as in the export repository.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 09:04:43 +02:00
co-authored by Claude Sonnet 5.5
parent 2de3733a3f
commit b13310b815
2 changed files with 18 additions and 1 deletions
@@ -16,7 +16,8 @@ class EloquentBilledRevenueQueries implements BilledRevenueQueries
->join('billing_invoices', 'billing_invoices.id', '=', 'billing_lines.billing_invoice_id')
->join('billing_exports', 'billing_exports.id', '=', 'billing_invoices.billing_export_id')
->where('billing_exports.status', ExportStatus::Created->value)
->whereBetween('billing_exports.period', [$fromMonth, $toMonth])
// Materials created before billing months existed have none: their month is the month they were created in, as in the export repository.
->whereRaw('COALESCE(billing_exports.period, SUBSTR(billing_exports.created_at, 1, 7)) BETWEEN ? AND ?', [$fromMonth, $toMonth])
->groupBy('billing_lines.customer_job_id')
->select('billing_lines.customer_job_id')
->selectRaw(self::sumOf(LineKind::Hours, 'net_cents').' as hours_cents')