Files
petriandClaude Opus 5.5 bdd8d446d8 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]>
2026-11-24 07:51:19 +02:00

56 lines
2.4 KiB
PHP

<?php
use App\Models\User;
use App\Modules\Catalog\Application\UseCases\SetMileageRate;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ProductModel;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
use App\Modules\Shared\Application\Contracts\Settings;
use App\Modules\Users\Domain\Enums\MoneyPermission;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
ProductModel::factory()->consumer()->create(['name' => 'Passikuvat', 'price_cents' => 1800]);
ProductModel::factory()->consumer()->inactive()->create(['name' => 'Vanha passikuva']);
ProductModel::factory()->create(['name' => 'Roll-up', 'price_cents' => 12000]);
WorkTypeModel::query()->where('name', 'painotyö')->update(['hourly_rate_cents' => 7500]);
app(Settings::class)->put(SetMileageRate::SETTING_KEY, '59');
});
it('shows consumer prices with VAT but no other prices to an employee without the price permission', function () {
$this->actingAs(User::factory()->employee()->create())
->get(route('catalog.price-list'))
->assertOk()
->assertSee('Passikuvat')
->assertSee("18,00\u{00A0}€", false)
->assertSee("25,5\u{00A0}%", false)
->assertDontSee('Vanha passikuva')
->assertDontSee('Roll-up')
->assertDontSee('painotyö')
->assertDontSee("75,00\u{00A0}€", false)
->assertDontSee("0,59\u{00A0}€", false)
->assertSee(__('catalog.price_list.no_permission'));
});
it('shows every price to an employee with the price permission and to management', function (Closure $makeUser) {
$this->actingAs($makeUser())
->get(route('catalog.price-list'))
->assertOk()
->assertSee('Roll-up')
->assertSee("120,00\u{00A0}€", false)
->assertSee("150,60\u{00A0}€", false)
->assertSee('painotyö')
->assertSee("75,00\u{00A0}€", false)
->assertSee("0,59\u{00A0}€", false);
})->with([
'employee with prices' => [fn () => User::factory()->employee()->withMoneyPermissions(MoneyPermission::Prices)->create()],
'management' => [fn () => User::factory()->management()->create()],
]);
it('keeps subcontractors out of the price list', function () {
$this->actingAs(User::factory()->subcontractor()->create())
->get(route('catalog.price-list'))
->assertForbidden();
});