Add expenses on customer jobs

- New Expenses module: purchases (materials, other) with a description
  and cost, and mileage priced with the price list's mileage rate.
- Who paid and whether the expense is billed are separate: an employee's
  own payments are reimbursed elsewhere. A billed expense has a markup
  and a billed amount, cost plus markup unless given.
- A job's expenses page lists, adds, edits and removes them; amounts of
  others' expenses need the expenses permission, own ones always show.
  Done jobs lock their expenses.
- The Kulut menu shows the user's own expenses by month. Management
  records subcontractors' expenses, which they see but cannot change.
- The price list gets a default markup for new purchases.
- Number fields that update a calculation now use wire:model.live.blur:
  in Livewire 4 plain .blur no longer sends the value to the server,
  which also fixes the product form's VAT calculation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-24 08:11:27 +02:00
co-authored by Claude Opus 5.5
parent bdd8d446d8
commit 54d98d9d2f
64 changed files with 3092 additions and 9 deletions
@@ -7,6 +7,7 @@ use App\Modules\Catalog\Application\DTOs\ProductSummary;
use App\Modules\Catalog\Application\DTOs\VatRateSummary;
use App\Modules\Catalog\Application\UseCases\MoveProduct;
use App\Modules\Catalog\Application\UseCases\MoveVatRate;
use App\Modules\Catalog\Application\UseCases\SetDefaultExpenseMarkup;
use App\Modules\Catalog\Application\UseCases\SetHourlyRate;
use App\Modules\Catalog\Application\UseCases\SetMileageRate;
use App\Modules\Catalog\Application\UseCases\SetProductActive;
@@ -18,6 +19,7 @@ use App\Modules\Catalog\Domain\Exceptions\ProductNotFound;
use App\Modules\Catalog\Domain\Exceptions\VatRateNotFound;
use App\Modules\Catalog\Domain\ValueObjects\ProductDuration;
use App\Modules\Shared\Domain\Exceptions\InvalidMoneyAmount;
use App\Modules\Shared\Domain\Exceptions\InvalidVatPercentage;
use App\Modules\Shared\Domain\ValueObjects\Money;
use App\Modules\Shared\Domain\ValueObjects\VatPercentage;
use Livewire\Attributes\Computed;
@@ -47,6 +49,8 @@ new class extends Component
public string $mileageRate = '';
public string $expenseMarkup = '';
protected PriceListQueries $priceList;
public function boot(PriceListQueries $priceList): void
@@ -59,6 +63,8 @@ new class extends Component
$this->authorize('catalog.manage');
$this->mileageRate = $this->inputValue($this->priceList->mileageRateCents());
$markup = $this->priceList->defaultExpenseMarkupBasisPoints();
$this->expenseMarkup = $markup === 0 ? '' : (new VatPercentage($markup))->inputValue();
}
/**
@@ -177,6 +183,26 @@ new class extends Component
$this->statusMessage = __($product->isActive ? 'catalog.products.deactivated' : 'catalog.status.activated', ['name' => $product->name]);
}
public function saveExpenseMarkup(SetDefaultExpenseMarkup $setMarkup): void
{
$this->authorize('catalog.manage');
$this->resetErrorBag('expenseMarkup');
try {
$markup = $setMarkup->execute($this->expenseMarkup);
} catch (InvalidVatPercentage) {
$this->addError('expenseMarkup', __('catalog.errors.invalid_markup'));
return;
}
$this->expenseMarkup = $markup === 0 ? '' : (new VatPercentage($markup))->inputValue();
$this->statusMessage = $markup === 0
? __('catalog.expense_markup.removed')
: __('catalog.expense_markup.saved', ['markup' => (new VatPercentage($markup))->format()]);
}
public function saveMileageRate(SetMileageRate $setMileageRate): void
{
$this->authorize('catalog.manage');
@@ -473,7 +499,7 @@ new class extends Component
</section>
<section aria-labelledby="mileage-heading" class="space-y-4">
<h2 id="mileage-heading" class="text-xl font-semibold">{{ __('catalog.mileage.title') }}</h2>
<h2 id="mileage-heading" class="text-xl font-semibold">{{ __('catalog.expense_markup.section') }}</h2>
<form wire:submit="saveMileageRate" class="flex max-w-md flex-wrap items-end gap-3" novalidate>
<div class="min-w-40 flex-1">
@@ -487,5 +513,18 @@ new class extends Component
</div>
<x-button submit :text="__('catalog.save')" />
</form>
<form wire:submit="saveExpenseMarkup" class="flex max-w-md flex-wrap items-end gap-3" novalidate>
<div class="min-w-40 flex-1">
<x-input
wire:model="expenseMarkup"
:label="__('catalog.expense_markup.label')"
:hint="__('catalog.expense_markup.help')"
inputmode="decimal"
autocomplete="off"
/>
</div>
<x-button submit :text="__('catalog.save')" />
</form>
</section>
</div>