The expenses employees paid themselves in a period, by person with kilometres and amounts, printable and as CSV for payroll. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
65 lines
2.8 KiB
PHP
65 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Expenses\Infrastructure\Providers;
|
|
|
|
use App\Models\User;
|
|
use App\Modules\Expenses\Application\Contracts\ExpenseJobs;
|
|
use App\Modules\Expenses\Application\Contracts\ExpensePricing;
|
|
use App\Modules\Expenses\Application\Contracts\ExpenseQueries;
|
|
use App\Modules\Expenses\Application\Contracts\ExpenseReportQueries;
|
|
use App\Modules\Expenses\Domain\Contracts\ExpenseRepository;
|
|
use App\Modules\Expenses\Infrastructure\JobsForExpenses;
|
|
use App\Modules\Expenses\Infrastructure\Persistence\Repositories\EloquentExpenseQueries;
|
|
use App\Modules\Expenses\Infrastructure\Persistence\Repositories\EloquentExpenseReportQueries;
|
|
use App\Modules\Expenses\Infrastructure\Persistence\Repositories\EloquentExpenseRepository;
|
|
use App\Modules\Expenses\Infrastructure\PriceListForExpenses;
|
|
use App\Modules\Users\Domain\Enums\Role;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Livewire\Livewire;
|
|
|
|
/**
|
|
* Wires the Expenses module (expenses on customer jobs) into Laravel:
|
|
* bindings, routes, the `expenses::` Livewire namespace and the
|
|
* `expenses.*` abilities.
|
|
*/
|
|
class ExpensesServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* @var array<class-string, class-string>
|
|
*/
|
|
public array $bindings = [
|
|
ExpenseRepository::class => EloquentExpenseRepository::class,
|
|
ExpenseQueries::class => EloquentExpenseQueries::class,
|
|
ExpenseReportQueries::class => EloquentExpenseReportQueries::class,
|
|
ExpenseJobs::class => JobsForExpenses::class,
|
|
ExpensePricing::class => PriceListForExpenses::class,
|
|
];
|
|
|
|
public function boot(): void
|
|
{
|
|
$presentationPath = dirname(__DIR__, 2).'/Presentation';
|
|
|
|
Livewire::addNamespace('expenses', viewPath: $presentationPath.'/Livewire');
|
|
|
|
if (! $this->app->routesAreCached()) {
|
|
$this->loadRoutesFrom($presentationPath.'/Routes/web.php');
|
|
}
|
|
|
|
// Everyone may list their own expenses; subcontractors' are recorded by management (spec 10).
|
|
Gate::define('expenses.use', fn (User $user): bool => true);
|
|
|
|
Gate::define('expenses.record', fn (User $user): bool => $user->role !== Role::Subcontractor);
|
|
|
|
// Admins and management record expenses for others, e.g. subcontractors.
|
|
Gate::define('expenses.record-for-others', fn (User $user): bool => $user->role->seesAllMoney());
|
|
|
|
Gate::define('expenses.change', fn (User $user, int $ownerId, int $recordedBy): bool => $user->role->seesAllMoney()
|
|
|| ($user->role !== Role::Subcontractor && in_array($user->id, [$ownerId, $recordedBy], true)));
|
|
|
|
// Everyone sees the amounts of their own expenses; others' need the expenses permission.
|
|
Gate::define('expenses.see-amount', fn (User $user, int $ownerId, int $recordedBy): bool => in_array($user->id, [$ownerId, $recordedBy], true)
|
|
|| $user->can('money.expenses'));
|
|
}
|
|
}
|