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:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Reports\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Catalog\Application\Contracts\PriceListQueries;
|
||||
use App\Modules\Reports\Application\Contracts\ReportCatalog;
|
||||
use App\Modules\Reports\Application\DTOs\ReportWorkType;
|
||||
|
||||
/**
|
||||
* Service units, work types and prices for reports through the Catalog
|
||||
* module's price list.
|
||||
*/
|
||||
class CatalogForReports implements ReportCatalog
|
||||
{
|
||||
public function __construct(private PriceListQueries $prices) {}
|
||||
|
||||
public function workTypes(): array
|
||||
{
|
||||
$workTypes = [];
|
||||
|
||||
foreach ($this->prices->hourlyRates() as $group) {
|
||||
foreach ($group->rows as $row) {
|
||||
$workTypes[$row->workTypeId] = new ReportWorkType($row->workTypeId, $row->name, $group->serviceUnitId, $group->serviceUnitName, $row->hourlyRateCents);
|
||||
}
|
||||
}
|
||||
|
||||
return $workTypes;
|
||||
}
|
||||
|
||||
public function serviceUnits(): array
|
||||
{
|
||||
$units = [];
|
||||
|
||||
foreach ($this->prices->hourlyRates() as $group) {
|
||||
$units[$group->serviceUnitId] = $group->serviceUnitName;
|
||||
}
|
||||
|
||||
return $units;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Reports\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Reports\Application\Contracts\ReportHours;
|
||||
use App\Modules\Reports\Application\DTOs\HoursEntry;
|
||||
use App\Modules\Reports\Application\DTOs\UnbilledEntry;
|
||||
use App\Modules\Reports\Domain\ValueObjects\ReportPeriod;
|
||||
use App\Modules\TimeTracking\Application\Contracts\TimeReportQueries;
|
||||
use App\Modules\TimeTracking\Application\DTOs\ReportedHours;
|
||||
use App\Modules\TimeTracking\Application\DTOs\UnbilledHours;
|
||||
|
||||
/**
|
||||
* Hours for reports through the TimeTracking module.
|
||||
*/
|
||||
class HoursForReports implements ReportHours
|
||||
{
|
||||
public function __construct(private TimeReportQueries $queries) {}
|
||||
|
||||
public function between(ReportPeriod $period): array
|
||||
{
|
||||
return array_map(
|
||||
fn (ReportedHours $hours): HoursEntry => new HoursEntry($hours->userId, $hours->jobId, $hours->workTypeId, $hours->quarters, $hours->unapprovedQuarters, $hours->billedQuarters),
|
||||
$this->queries->hoursBetween($period->from, $period->to),
|
||||
);
|
||||
}
|
||||
|
||||
public function unbilledUntil(string $day): array
|
||||
{
|
||||
return array_map(
|
||||
fn (UnbilledHours $hours): UnbilledEntry => new UnbilledEntry($hours->jobId, $hours->workTypeId, $hours->approvedQuarters, $hours->unapprovedQuarters, $hours->oldestDay),
|
||||
$this->queries->unbilledUntil($day),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Reports\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\JobReportInfo;
|
||||
use App\Modules\Jobs\Domain\Enums\PaymentBasis;
|
||||
use App\Modules\Reports\Application\Contracts\ReportJobs;
|
||||
use App\Modules\Reports\Application\DTOs\ReportJob;
|
||||
|
||||
/**
|
||||
* Customer jobs for reports through the Jobs module. As in billing, a job
|
||||
* without a payment basis is billed by its hours.
|
||||
*/
|
||||
class JobsForReports implements ReportJobs
|
||||
{
|
||||
public function __construct(private CustomerJobQueries $jobs) {}
|
||||
|
||||
public function infoOf(array $ids): array
|
||||
{
|
||||
return array_map(fn (JobReportInfo $job): ReportJob => new ReportJob(
|
||||
$job->id,
|
||||
$job->number,
|
||||
$job->name,
|
||||
$job->customerId,
|
||||
$job->customerName,
|
||||
$job->isInternal,
|
||||
$job->status->value,
|
||||
$job->paymentBasis?->value,
|
||||
! $job->isInternal && $job->paymentBasis !== PaymentBasis::NotBillable,
|
||||
! $job->isInternal && in_array($job->paymentBasis, [null, PaymentBasis::Hourly, PaymentBasis::PriceList], true),
|
||||
$job->quotedAmountCents,
|
||||
$job->serviceUnitIds,
|
||||
), $this->jobs->reportInfoOf($ids));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Reports\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Reports\Application\Contracts\ReportPeople;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
|
||||
/**
|
||||
* Users' names for reports through the Users module.
|
||||
*/
|
||||
class PeopleForReports implements ReportPeople
|
||||
{
|
||||
public function __construct(private UserAccountQueries $users) {}
|
||||
|
||||
public function namesByIds(array $ids): array
|
||||
{
|
||||
return $ids === [] ? [] : $this->users->namesByIds($ids);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user