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]>
60 lines
2.5 KiB
PHP
60 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\TimeTracking\Infrastructure\Providers;
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
|
use App\Modules\Jobs\Application\Contracts\TaskUsage;
|
|
use App\Modules\TimeTracking\Application\Contracts\TimeEntryQueries;
|
|
use App\Modules\TimeTracking\Application\Contracts\TimeReportQueries;
|
|
use App\Modules\TimeTracking\Domain\Contracts\TimeEntryRepository;
|
|
use App\Modules\TimeTracking\Infrastructure\Persistence\Repositories\EloquentTimeEntryQueries;
|
|
use App\Modules\TimeTracking\Infrastructure\Persistence\Repositories\EloquentTimeEntryRepository;
|
|
use App\Modules\TimeTracking\Infrastructure\Persistence\Repositories\EloquentTimeReportQueries;
|
|
use App\Modules\TimeTracking\Infrastructure\TaskUsageFromTimeEntries;
|
|
use App\Modules\Users\Domain\Enums\Role;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Livewire\Livewire;
|
|
|
|
/**
|
|
* Wires the TimeTracking module (hours on tasks) into Laravel.
|
|
*/
|
|
class TimeTrackingServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* @var array<class-string, class-string>
|
|
*/
|
|
public array $bindings = [
|
|
TimeEntryRepository::class => EloquentTimeEntryRepository::class,
|
|
TimeEntryQueries::class => EloquentTimeEntryQueries::class,
|
|
TimeReportQueries::class => EloquentTimeReportQueries::class,
|
|
TaskUsage::class => TaskUsageFromTimeEntries::class,
|
|
];
|
|
|
|
public function boot(): void
|
|
{
|
|
$presentationPath = dirname(__DIR__, 2).'/Presentation';
|
|
|
|
Livewire::addNamespace('time', viewPath: $presentationPath.'/Livewire');
|
|
|
|
if (! $this->app->routesAreCached()) {
|
|
$this->loadRoutesFrom($presentationPath.'/Routes/web.php');
|
|
}
|
|
|
|
Gate::define('time.use', fn (User $user): bool => true);
|
|
|
|
// Users approve their own hours; management anyone's, including subcontractors' (spec 9).
|
|
Gate::define('time.approve', fn (User $user, int $ownerId): bool => $user->role->seesAllMoney()
|
|
|| ($user->role !== Role::Subcontractor && $user->id === $ownerId));
|
|
|
|
Gate::define('time.approve-others', fn (User $user): bool => $user->role->seesAllMoney());
|
|
|
|
Gate::define('time.cancel-approval', fn (User $user): bool => $user->role->seesAllMoney());
|
|
|
|
// Hours go on any task of an unlocked job; subcontractors only on jobs they are attached to (K12).
|
|
Gate::define('time.book', fn (User $user, int $jobId): bool => $user->role !== Role::Subcontractor
|
|
|| app(CustomerJobQueries::class)->isMember($jobId, $user->id));
|
|
}
|
|
}
|