Add money permissions, a read-only price list and VAT rates

- Admins give employees and interns personal money permissions (prices,
  expenses, quotes, billing) on the user form. Other modules check them
  through the money.* abilities; admins and management see all amounts,
  subcontractors none.
- Employees and interns get a read-only price list: consumer products
  with VAT always, hourly rates, other products and the mileage rate only
  with the price permission. Subcontractors cannot open it.
- VAT rates are maintained on the price list page, with one default rate
  that always stays in use. Products get a VAT rate; changing a rate's
  percentage applies to every product using it.
- Consumer product prices are entered and stored with VAT, so cash prices
  stay round; the price without VAT is calculated. The product form shows
  the other price as you type.
- Shared VatPercentage value object and Money::addVat()/removeVat(),
  rounding half up to the cent in integer arithmetic.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 07:51:19 +02:00
co-authored by Claude Opus 5.5
parent dc2612cf46
commit bdd8d446d8
68 changed files with 2222 additions and 64 deletions
@@ -6,6 +6,7 @@ use App\Modules\Shared\Domain\Exceptions\DomainException;
use App\Modules\Shared\Domain\Exceptions\InvalidEmailAddress;
use App\Modules\Users\Application\DTOs\UserAccountData;
use App\Modules\Users\Application\DTOs\UserSummary;
use App\Modules\Users\Domain\Enums\MoneyPermission;
use App\Modules\Users\Domain\Enums\Role;
use App\Modules\Users\Domain\Exceptions\EmailAlreadyInUse;
use App\Modules\Users\Domain\Exceptions\InternRequiresEndDateAndSupervisor;
@@ -13,6 +14,7 @@ use App\Modules\Users\Domain\Exceptions\InvalidPersonName;
use App\Modules\Users\Domain\Exceptions\InvalidSupervisor;
use App\Modules\Users\Domain\Exceptions\LastAdminCannotBeRemoved;
use App\Modules\Users\Domain\Exceptions\SupervisorHasInterns;
use Closure;
use Illuminate\Validation\Rule;
use Livewire\Form;
@@ -35,6 +37,13 @@ class UserForm extends Form
public string $supervisor_id = '';
/**
* Values of MoneyPermission; only for employees and interns.
*
* @var list<string>
*/
public array $money_permissions = [];
public function fillFromSummary(UserSummary $user): void
{
$this->name = $user->name;
@@ -43,6 +52,7 @@ class UserForm extends Form
$this->active = $user->active;
$this->employment_ends_on = $user->employmentEndsOn ?? '';
$this->supervisor_id = $user->supervisorId === null ? '' : (string) $user->supervisorId;
$this->money_permissions = array_map(fn (MoneyPermission $permission): string => $permission->value, $user->moneyPermissions);
}
public function isIntern(): bool
@@ -50,6 +60,14 @@ class UserForm extends Form
return $this->role === Role::Intern->value;
}
/**
* Whether the chosen role gets personal money permissions.
*/
public function hasMoneyPermissions(): bool
{
return Role::tryFrom($this->role)?->hasPersonalMoneyPermissions() ?? false;
}
public function toData(): UserAccountData
{
$this->validate();
@@ -61,6 +79,7 @@ class UserForm extends Form
'active' => $this->active,
'employment_ends_on' => $this->isIntern() ? $this->employment_ends_on : null,
'supervisor_id' => $this->isIntern() ? $this->supervisor_id : null,
'money_permissions' => $this->hasMoneyPermissions() ? $this->money_permissions : [],
]);
}
@@ -95,6 +114,15 @@ class UserForm extends Form
'active' => ['boolean'],
'employment_ends_on' => [Rule::requiredIf($this->isIntern()), 'nullable', 'date_format:Y-m-d'],
'supervisor_id' => [Rule::requiredIf($this->isIntern()), 'nullable', 'integer'],
'money_permissions' => ['array', function (string $attribute, mixed $value, Closure $fail): void {
foreach ((array) $value as $permission) {
if (! is_string($permission) || MoneyPermission::tryFrom($permission) === null) {
$fail(__('users.errors.invalid_money_permission'));
return;
}
}
}],
];
}
@@ -6,6 +6,7 @@ use App\Modules\Users\Application\DTOs\UserOption;
use App\Modules\Users\Application\UseCases\CreateUserAccount;
use App\Modules\Users\Application\UseCases\SendPasswordSetupLink;
use App\Modules\Users\Application\UseCases\UpdateUserAccount;
use App\Modules\Users\Domain\Enums\MoneyPermission;
use App\Modules\Users\Domain\Enums\Role;
use App\Modules\Users\Domain\Exceptions\UserAccountNotFound;
use App\Modules\Users\Presentation\Livewire\Forms\UserForm;
@@ -161,6 +162,20 @@ new class extends Component
</x-select.native>
@endif
@if ($form->hasMoneyPermissions())
<x-checkbox-group
:legend="__('users.money_permissions.legend')"
model="form.money_permissions"
:hint="__('users.money_permissions.hint')"
:columns="false"
:options="collect(MoneyPermission::cases())->map(fn (MoneyPermission $permission) => [
'value' => $permission->value,
'label' => __('users.money_permissions.'.$permission->value),
'note' => __('users.money_permissions.'.$permission->value.'_note'),
])->all()"
/>
@endif
<div>
<x-checkbox wire:model="form.active" :label="__('users.fields.active')" aria-describedby="active-description" />
<p id="active-description" class="mt-1 text-sm text-zinc-600 dark:text-zinc-300">{{ __('users.fields.active_description') }}</p>