Replace the demo home page with a dashboard
Everyone sees their open tasks on an agenda, their open jobs, this week's hours and quick links. Admin and management also get a lazily loaded management panel: things to do, the month so far against the previous month, jobs and late work, and everyone's workload. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Dashboard\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Billing\Application\Contracts\BillingQueries;
|
||||
use App\Modules\Billing\Domain\Enums\ExportStatus;
|
||||
use App\Modules\Dashboard\Application\Contracts\DashboardAdmin;
|
||||
use App\Modules\Sales\Application\Contracts\QuickSaleQueries;
|
||||
use App\Modules\Shared\Application\UseCases\HolidayCalendar;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use App\Modules\Users\Domain\Enums\Role;
|
||||
|
||||
/**
|
||||
* Billing drafts, cash days, people and holidays for the management panel
|
||||
* through the Billing, Sales, Users and Shared modules.
|
||||
*/
|
||||
class AdminForDashboard implements DashboardAdmin
|
||||
{
|
||||
public function __construct(
|
||||
private BillingQueries $billing,
|
||||
private QuickSaleQueries $sales,
|
||||
private UserAccountQueries $users,
|
||||
private HolidayCalendar $holidays,
|
||||
) {}
|
||||
|
||||
public function openDraftId(): ?int
|
||||
{
|
||||
foreach ($this->billing->exports() as $export) {
|
||||
if ($export->status === ExportStatus::Draft) {
|
||||
return $export->id;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function unclosedCashDaysBefore(string $day): array
|
||||
{
|
||||
return $this->sales->unclosedDaysBefore($day);
|
||||
}
|
||||
|
||||
public function staff(): array
|
||||
{
|
||||
$staff = [];
|
||||
|
||||
foreach ($this->users->activeUserOptions() as $user) {
|
||||
if ($user->role !== Role::Subcontractor) {
|
||||
$staff[$user->id] = $user->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $staff;
|
||||
}
|
||||
|
||||
public function holidaysBetween(string $from, string $to): array
|
||||
{
|
||||
return $this->holidays->activeDatesBetween($from, $to);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Dashboard\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Dashboard\Application\Contracts\DashboardFigures;
|
||||
use App\Modules\Dashboard\Application\DTOs\PeriodFigures;
|
||||
use App\Modules\Reports\Application\UseCases\HoursByPerson;
|
||||
use App\Modules\Reports\Application\UseCases\ProfitabilityByJob;
|
||||
use App\Modules\Reports\Application\UseCases\QuickSalesReport;
|
||||
use App\Modules\Reports\Application\UseCases\UnbilledHoursReport;
|
||||
use App\Modules\Reports\Domain\ValueObjects\ReportPeriod;
|
||||
|
||||
/**
|
||||
* Key figures through the Reports module's reports, so the panel shows the
|
||||
* same numbers as the reports.
|
||||
*/
|
||||
class FiguresForDashboard implements DashboardFigures
|
||||
{
|
||||
public function __construct(
|
||||
private HoursByPerson $hours,
|
||||
private ProfitabilityByJob $profitability,
|
||||
private QuickSalesReport $sales,
|
||||
private UnbilledHoursReport $unbilled,
|
||||
) {}
|
||||
|
||||
public function between(string $from, string $to): PeriodFigures
|
||||
{
|
||||
$period = new ReportPeriod($from, $to);
|
||||
$hours = $this->hours->execute($period)->total;
|
||||
$profit = $this->profitability->execute($period)->total;
|
||||
|
||||
return new PeriodFigures(
|
||||
$hours->customerQuarters,
|
||||
$hours->internalQuarters,
|
||||
$profit->revenueCents(),
|
||||
$profit->marginCents(),
|
||||
$this->sales->execute($period)->totalCents(),
|
||||
);
|
||||
}
|
||||
|
||||
public function unbilledValueCents(string $day): int
|
||||
{
|
||||
return $this->unbilled->execute($day)->valueCents;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Dashboard\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Dashboard\Application\Contracts\DashboardTime;
|
||||
use App\Modules\Dashboard\Application\DTOs\PendingApproval;
|
||||
use App\Modules\Dashboard\Application\DTOs\WeekHours;
|
||||
use App\Modules\TimeTracking\Application\Contracts\TimeEntryQueries;
|
||||
|
||||
/**
|
||||
* Hours for the home page through the TimeTracking module.
|
||||
*/
|
||||
class TimeForDashboard implements DashboardTime
|
||||
{
|
||||
public function __construct(private TimeEntryQueries $entries) {}
|
||||
|
||||
public function week(int $userId, string $monday): WeekHours
|
||||
{
|
||||
$sheet = $this->entries->week($userId, $monday);
|
||||
|
||||
return new WeekHours($monday, $sheet->dayTotals, $sheet->totalQuarters, $sheet->unapprovedQuarters);
|
||||
}
|
||||
|
||||
public function pendingApprovals(): array
|
||||
{
|
||||
$people = [];
|
||||
|
||||
foreach ($this->entries->pendingWeeks() as $week) {
|
||||
$current = $people[$week->userId] ?? new PendingApproval($week->userId, $week->userName, 0, 0);
|
||||
$people[$week->userId] = new PendingApproval($week->userId, $week->userName, $current->quarters + $week->quarters, $current->weekCount + 1);
|
||||
}
|
||||
|
||||
$people = array_values($people);
|
||||
usort($people, fn (PendingApproval $a, PendingApproval $b): int => strnatcasecmp($a->name, $b->name));
|
||||
|
||||
return $people;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Dashboard\Infrastructure\Adapters;
|
||||
|
||||
use App\Modules\Dashboard\Application\Contracts\DashboardWork;
|
||||
use App\Modules\Dashboard\Application\DTOs\WorkJob;
|
||||
use App\Modules\Dashboard\Application\DTOs\WorkTask;
|
||||
use App\Modules\Jobs\Application\Contracts\JobOverviewQueries;
|
||||
use App\Modules\Jobs\Application\Contracts\TaskCalendarQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobSummary;
|
||||
use App\Modules\Jobs\Application\DTOs\OpenTask;
|
||||
use App\Modules\Jobs\Application\Services\TaskPlanner;
|
||||
|
||||
/**
|
||||
* Jobs, tasks and bookings for the home page through the Jobs module.
|
||||
*/
|
||||
class WorkForDashboard implements DashboardWork
|
||||
{
|
||||
public function __construct(
|
||||
private JobOverviewQueries $overview,
|
||||
private TaskCalendarQueries $calendar,
|
||||
private TaskPlanner $planner,
|
||||
) {}
|
||||
|
||||
public function openTasksOf(int $userId): array
|
||||
{
|
||||
return array_map(self::task(...), $this->overview->openTasksOf($userId));
|
||||
}
|
||||
|
||||
public function openJobsOf(int $userId): array
|
||||
{
|
||||
return array_map(fn (CustomerJobSummary $job): WorkJob => new WorkJob(
|
||||
$job->id,
|
||||
$job->number,
|
||||
$job->name,
|
||||
$job->customerName,
|
||||
$job->status->value,
|
||||
$job->priority->value,
|
||||
$job->dueOn,
|
||||
), $this->overview->openJobsOf($userId));
|
||||
}
|
||||
|
||||
public function jobCountsByStatus(): array
|
||||
{
|
||||
return $this->overview->jobCountsByStatus();
|
||||
}
|
||||
|
||||
public function overdueJobCount(string $today): int
|
||||
{
|
||||
return $this->overview->overdueJobCount($today);
|
||||
}
|
||||
|
||||
public function overdueTaskCount(string $today): int
|
||||
{
|
||||
return $this->overview->overdueTaskCount($today);
|
||||
}
|
||||
|
||||
public function oldestOverdueTasks(string $today, int $limit): array
|
||||
{
|
||||
return array_map(self::task(...), $this->overview->oldestOverdueTasks($today, $limit));
|
||||
}
|
||||
|
||||
public function dailyCapacityMinutes(): int
|
||||
{
|
||||
return $this->planner->capacityMinutes();
|
||||
}
|
||||
|
||||
public function bookedMinutes(array $userIds, string $from, string $to): array
|
||||
{
|
||||
return array_map(fn (array $days): int => array_sum($days), $this->calendar->openMinutesByUser($userIds, $from, $to));
|
||||
}
|
||||
|
||||
private static function task(OpenTask $task): WorkTask
|
||||
{
|
||||
return new WorkTask(
|
||||
$task->taskId,
|
||||
$task->jobId,
|
||||
$task->jobNumber,
|
||||
$task->jobName,
|
||||
$task->title,
|
||||
$task->status->value,
|
||||
$task->dueOn,
|
||||
$task->plannedFrom,
|
||||
$task->plannedTo,
|
||||
$task->assigneeName,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user