Add Reports module with the hours by person report
Management's reports (spec 13) get their own module that reads the other modules through ports. The first report sums hours by person in a period, narrowed by service unit or customer, with breakdowns, a chart and CSV. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
+38
@@ -10,6 +10,7 @@ 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\JobReportInfo;
|
||||
use App\Modules\Jobs\Application\DTOs\NamedId;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\PaymentBasis;
|
||||
@@ -206,6 +207,43 @@ class EloquentCustomerJobQueries implements CustomerJobQueries
|
||||
return $ids === [] ? [] : $this->billingInfo(CustomerJobModel::query()->whereIn('id', $ids)->orderBy('number')->get());
|
||||
}
|
||||
|
||||
public function reportInfoOf(array $ids): array
|
||||
{
|
||||
if ($ids === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach (array_chunk(array_values(array_unique($ids)), 500) as $chunk) {
|
||||
$models = CustomerJobModel::query()->whereIn('id', $chunk)->get();
|
||||
$customerNames = $this->customers->namesByIds($models->pluck('customer_id')->unique()->values()->all());
|
||||
$internalCustomerId = $this->customers->internalCustomerId();
|
||||
$serviceUnitIds = [];
|
||||
|
||||
foreach (DB::table('customer_job_service_unit')->whereIn('customer_job_id', $chunk)->orderBy('service_unit_id')->get() as $row) {
|
||||
$serviceUnitIds[(int) $row->customer_job_id][] = (int) $row->service_unit_id;
|
||||
}
|
||||
|
||||
foreach ($models as $model) {
|
||||
$result[$model->id] = new JobReportInfo(
|
||||
$model->id,
|
||||
$model->number,
|
||||
$model->name,
|
||||
$model->customer_id,
|
||||
$customerNames[$model->customer_id] ?? '',
|
||||
$model->customer_id === $internalCustomerId,
|
||||
$model->status,
|
||||
$model->payment_basis,
|
||||
$model->quoted_amount_cents,
|
||||
$serviceUnitIds[$model->id] ?? [],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection<int, CustomerJobModel> $models
|
||||
* @return array<int, JobBillingInfo>
|
||||
|
||||
Reference in New Issue
Block a user