Add the profitability report and the internal hourly cost

Profitability by job and service unit from a period's hours, expenses
and the created billing materials of its months. Hours are costed at one
internal hourly cost, set on the price list maintenance page; a job of
several service units is shared evenly between them.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 08:50:30 +02:00
co-authored by Claude Sonnet 5.5
parent 8079c272d2
commit 8aa62c8e02
31 changed files with 1110 additions and 1 deletions
@@ -44,6 +44,11 @@ interface PriceListQueries
*/
public function mileageRateCents(): ?int;
/**
* The internal cost of an hour of work in cents (VAT 0), null when not set.
*/
public function internalHourlyCostCents(): ?int;
/**
* Markup suggested for new purchase expenses, in hundredths of a percent (0 when not set).
*/
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Modules\Catalog\Application\UseCases;
use App\Modules\Shared\Application\Contracts\Settings;
use App\Modules\Shared\Domain\Exceptions\InvalidMoneyAmount;
use App\Modules\Shared\Domain\ValueObjects\Money;
/**
* Sets the company's internal cost of an hour of work (wages and
* overheads, VAT 0), one rate for everyone, which the profitability report
* charges for the hours worked. An empty value removes it.
*/
final class SetInternalHourlyCost
{
public const string SETTING_KEY = 'catalog.internal_hourly_cost_cents';
public function __construct(private Settings $settings) {}
/**
* @return Money|null The stored cost.
*
* @throws InvalidMoneyAmount
*/
public function execute(string $hourlyCost): ?Money
{
$cost = Money::parse($hourlyCost);
$this->settings->put(self::SETTING_KEY, $cost === null ? null : (string) $cost->cents);
return $cost;
}
}
@@ -11,6 +11,7 @@ use App\Modules\Catalog\Application\DTOs\ServiceUnitNode;
use App\Modules\Catalog\Application\DTOs\VatRateSummary;
use App\Modules\Catalog\Application\DTOs\WorkTypeSummary;
use App\Modules\Catalog\Application\UseCases\SetDefaultExpenseMarkup;
use App\Modules\Catalog\Application\UseCases\SetInternalHourlyCost;
use App\Modules\Catalog\Application\UseCases\SetMileageRate;
use App\Modules\Catalog\Domain\Enums\ProductUnit;
use App\Modules\Catalog\Domain\ValueObjects\ProductDuration;
@@ -125,6 +126,13 @@ class EloquentPriceListQueries implements PriceListQueries
return $value === null ? null : (int) $value;
}
public function internalHourlyCostCents(): ?int
{
$value = $this->settings->get(SetInternalHourlyCost::SETTING_KEY);
return $value === null ? null : (int) $value;
}
public function defaultExpenseMarkupBasisPoints(): int
{
return (int) ($this->settings->get(SetDefaultExpenseMarkup::SETTING_KEY) ?? 0);
@@ -9,6 +9,7 @@ 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\SetInternalHourlyCost;
use App\Modules\Catalog\Application\UseCases\SetMileageRate;
use App\Modules\Catalog\Application\UseCases\SetProductActive;
use App\Modules\Catalog\Application\UseCases\SetVatRateActive;
@@ -51,6 +52,8 @@ new class extends Component
public string $expenseMarkup = '';
public string $internalHourlyCost = '';
protected PriceListQueries $priceList;
public function boot(PriceListQueries $priceList): void
@@ -63,6 +66,7 @@ new class extends Component
$this->authorize('catalog.manage');
$this->mileageRate = $this->inputValue($this->priceList->mileageRateCents());
$this->internalHourlyCost = $this->inputValue($this->priceList->internalHourlyCostCents());
$markup = $this->priceList->defaultExpenseMarkupBasisPoints();
$this->expenseMarkup = $markup === 0 ? '' : (new VatPercentage($markup))->inputValue();
}
@@ -223,6 +227,26 @@ new class extends Component
: __('catalog.mileage.saved', ['rate' => $rate->format()]);
}
public function saveInternalHourlyCost(SetInternalHourlyCost $setInternalHourlyCost): void
{
$this->authorize('catalog.manage');
$this->resetErrorBag('internalHourlyCost');
try {
$cost = $setInternalHourlyCost->execute($this->internalHourlyCost);
} catch (InvalidMoneyAmount) {
$this->addError('internalHourlyCost', __('catalog.errors.invalid_price'));
return;
}
$this->internalHourlyCost = $cost?->inputValue() ?? '';
$this->statusMessage = $cost === null
? __('catalog.internal_cost.removed')
: __('catalog.internal_cost.saved', ['cost' => $cost->format()]);
}
/**
* @return list<array{index: string, label: string, sortable: bool, align?: string}>
*/
@@ -527,4 +551,21 @@ new class extends Component
<x-button submit :text="__('catalog.save')" />
</form>
</section>
<section aria-labelledby="internal-cost-heading" class="space-y-4">
<h2 id="internal-cost-heading" class="text-xl font-semibold">{{ __('catalog.internal_cost.section') }}</h2>
<form wire:submit="saveInternalHourlyCost" class="flex max-w-md flex-wrap items-end gap-3" novalidate>
<div class="min-w-40 flex-1">
<x-input
wire:model="internalHourlyCost"
:label="__('catalog.internal_cost.label')"
:hint="__('catalog.internal_cost.help')"
inputmode="decimal"
autocomplete="off"
/>
</div>
<x-button submit :text="__('catalog.save')" />
</form>
</section>
</div>