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:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Users\Domain\Enums\MoneyPermission;
|
||||
use App\Modules\Users\Infrastructure\Persistence\Eloquent\UserMoneyPermissionsModel;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('lets admins and management see all money, employees and interns only by permission, subcontractors none', function (Closure $makeUser, array $abilities) {
|
||||
$user = $makeUser();
|
||||
|
||||
foreach (['prices', 'expenses', 'quotes', 'billing'] as $ability) {
|
||||
expect(Gate::forUser($user)->allows('money.'.$ability))->toBe(in_array($ability, $abilities, true), $ability);
|
||||
}
|
||||
})->with([
|
||||
'admin' => [fn () => User::factory()->admin()->create(), ['prices', 'expenses', 'quotes', 'billing']],
|
||||
'management' => [fn () => User::factory()->management()->create(), ['prices', 'expenses', 'quotes', 'billing']],
|
||||
'employee without permissions' => [fn () => User::factory()->employee()->create(), []],
|
||||
'employee with prices and quotes' => [fn () => User::factory()->employee()->withMoneyPermissions(MoneyPermission::Prices, MoneyPermission::Quotes)->create(), ['prices', 'quotes']],
|
||||
'intern with billing' => [fn () => User::factory()->intern()->withMoneyPermissions(MoneyPermission::Billing)->create(), ['billing']],
|
||||
'subcontractor with a stray permission' => [fn () => User::factory()->subcontractor()->withMoneyPermissions(MoneyPermission::Prices)->create(), []],
|
||||
]);
|
||||
|
||||
it('saves money permissions on the user form for an employee', function () {
|
||||
Notification::fake();
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
$employee = User::factory()->employee()->create();
|
||||
|
||||
Livewire::test('users::form', ['user' => $employee->id])
|
||||
->assertSee('Rahamäärien näkyvyys')
|
||||
->set('form.money_permissions', ['prices', 'expenses'])
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($employee->refresh()->moneyPermissions?->permissions())->toBe([MoneyPermission::Prices, MoneyPermission::Expenses]);
|
||||
|
||||
Livewire::test('users::form', ['user' => $employee->id])
|
||||
->assertSet('form.money_permissions', ['prices', 'expenses'])
|
||||
->set('form.role', 'management')
|
||||
->assertDontSee('Rahamäärien näkyvyys')
|
||||
->call('save')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect(UserMoneyPermissionsModel::query()->where('user_id', $employee->id)->sole()->permissions())->toBe([]);
|
||||
});
|
||||
|
||||
it('rejects an unknown money permission', function () {
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
$employee = User::factory()->employee()->create();
|
||||
|
||||
Livewire::test('users::form', ['user' => $employee->id])
|
||||
->set('form.money_permissions', ['salaries'])
|
||||
->call('save')
|
||||
->assertHasErrors(['form.money_permissions']);
|
||||
});
|
||||
Reference in New Issue
Block a user