- 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]>
61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Users\Application\UseCases;
|
|
|
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
|
use App\Modules\Shared\Domain\ValueObjects\EmailAddress;
|
|
use App\Modules\Users\Application\Contracts\PasswordLinkSender;
|
|
use App\Modules\Users\Application\DTOs\CreatedUserAccount;
|
|
use App\Modules\Users\Application\DTOs\UserAccountData;
|
|
use App\Modules\Users\Domain\Contracts\UserAccountRepository;
|
|
use App\Modules\Users\Domain\Entities\UserAccount;
|
|
use App\Modules\Users\Domain\Exceptions\EmailAlreadyInUse;
|
|
use App\Modules\Users\Domain\Exceptions\InvalidSupervisor;
|
|
use App\Modules\Users\Domain\Services\SupervisorRule;
|
|
use App\Modules\Users\Domain\ValueObjects\PersonName;
|
|
|
|
/**
|
|
* Creates a user and makes a link for setting the first password, which is
|
|
* emailed and returned for the admin to copy, so nobody handles the
|
|
* password in plain text.
|
|
*/
|
|
final class CreateUserAccount
|
|
{
|
|
public function __construct(
|
|
private UserAccountRepository $users,
|
|
private SupervisorRule $supervisorRule,
|
|
private TransactionManager $transactions,
|
|
private PasswordLinkSender $passwordLinks,
|
|
) {}
|
|
|
|
/**
|
|
* @throws EmailAlreadyInUse
|
|
* @throws InvalidSupervisor
|
|
*/
|
|
public function execute(UserAccountData $data): CreatedUserAccount
|
|
{
|
|
$user = UserAccount::register(
|
|
new PersonName($data->name),
|
|
new EmailAddress($data->email),
|
|
$data->role,
|
|
EmploymentEndDate::parse($data->employmentEndsOn),
|
|
$data->supervisorId,
|
|
$data->moneyPermissions,
|
|
);
|
|
|
|
$userId = $this->transactions->run(function () use ($user): int {
|
|
if ($this->users->isEmailTaken($user->email())) {
|
|
throw new EmailAlreadyInUse;
|
|
}
|
|
|
|
$this->supervisorRule->ensureValidFor($user);
|
|
|
|
return (int) $this->users->save($user)->id();
|
|
});
|
|
|
|
return new CreatedUserAccount($userId, $this->passwordLinks->issueSetupLink($user->email()));
|
|
}
|
|
}
|