Files

64 lines
2.6 KiB
PHP

<?php
namespace App\Modules\Reports\Infrastructure\Providers;
use App\Models\User;
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
use App\Modules\Reports\Application\Contracts\ReportCatalog;
use App\Modules\Reports\Application\Contracts\ReportExpenses;
use App\Modules\Reports\Application\Contracts\ReportHours;
use App\Modules\Reports\Application\Contracts\ReportJobs;
use App\Modules\Reports\Application\Contracts\ReportPeople;
use App\Modules\Reports\Application\Contracts\ReportRevenue;
use App\Modules\Reports\Application\Contracts\ReportSales;
use App\Modules\Reports\Application\Contracts\ReportStock;
use App\Modules\Reports\Infrastructure\Adapters\CatalogForReports;
use App\Modules\Reports\Infrastructure\Adapters\ExpensesForReports;
use App\Modules\Reports\Infrastructure\Adapters\HoursForReports;
use App\Modules\Reports\Infrastructure\Adapters\JobsForReports;
use App\Modules\Reports\Infrastructure\Adapters\PeopleForReports;
use App\Modules\Reports\Infrastructure\Adapters\RevenueForReports;
use App\Modules\Reports\Infrastructure\Adapters\SalesForReports;
use App\Modules\Reports\Infrastructure\Adapters\StockForReports;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;
/**
* Wires the Reports module (management's reports, spec 13) into Laravel:
* the ports to the other modules, routes, the `reports::` Livewire
* namespace and the `reports.view` ability.
*/
class ReportsServiceProvider extends ServiceProvider
{
/**
* @var array<class-string, class-string>
*/
public array $bindings = [
ReportHours::class => HoursForReports::class,
ReportJobs::class => JobsForReports::class,
ReportCatalog::class => CatalogForReports::class,
ReportPeople::class => PeopleForReports::class,
ReportSales::class => SalesForReports::class,
ReportStock::class => StockForReports::class,
ReportExpenses::class => ExpensesForReports::class,
ReportRevenue::class => RevenueForReports::class,
];
public function boot(): void
{
$presentationPath = dirname(__DIR__, 2).'/Presentation';
Livewire::addNamespace('reports', viewPath: $presentationPath.'/Livewire');
if (! $this->app->routesAreCached()) {
$this->loadRoutesFrom($presentationPath.'/Routes/web.php');
}
// Reports are for admin and management (spec 2.4).
Gate::define('reports.stock', fn (User $user): bool => $user->role->seesAllMoney() && app(CatalogQueries::class)->stockServiceUnitIds() !== []);
Gate::define('reports.view', fn (User $user): bool => $user->role->seesAllMoney());
}
}