Report stock usage and value, add material cost to profitability, document phase 5

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 17:24:07 +02:00
co-authored by Claude Sonnet 5.5
parent 38b8075a9c
commit 3207d0064a
34 changed files with 1145 additions and 24 deletions
@@ -11,6 +11,8 @@ namespace App\Modules\Reports\Domain\ValueObjects;
* - billed for the work (hours, fixed price, monthly fees) and for expenses;
* - the purchase cost of the expenses and the cost of the hours worked at
* the company's one internal hourly cost (null when it is not set);
* - the cost of the stock used on the job (material, spec 19.8), which is
* not billed separately;
* - the margin: everything billed less those costs (null without the hourly cost).
*/
final readonly class Profit
@@ -22,12 +24,13 @@ final readonly class Profit
public int $expenseRevenueCents = 0,
public int $expenseCostCents = 0,
public ?int $hourCostCents = 0,
public int $materialCostCents = 0,
) {}
/**
* @param int|null $hourlyCostCents The internal cost of an hour, null when not set.
*/
public static function of(int $quarters, int $billedQuarters, int $workCents, int $expenseRevenueCents, int $expenseCostCents, ?int $hourlyCostCents): self
public static function of(int $quarters, int $billedQuarters, int $workCents, int $expenseRevenueCents, int $expenseCostCents, ?int $hourlyCostCents, int $materialCostCents = 0): self
{
return new self(
$quarters,
@@ -37,6 +40,7 @@ final readonly class Profit
$expenseCostCents,
// Rounded half up to a cent.
$hourlyCostCents === null ? null : intdiv($quarters * $hourlyCostCents * 2 + 4, 8),
$materialCostCents,
);
}
@@ -47,7 +51,7 @@ final readonly class Profit
public function marginCents(): ?int
{
return $this->hourCostCents === null ? null : $this->revenueCents() - $this->expenseCostCents - $this->hourCostCents;
return $this->hourCostCents === null ? null : $this->revenueCents() - $this->expenseCostCents - $this->materialCostCents - $this->hourCostCents;
}
/**
@@ -77,6 +81,7 @@ final readonly class Profit
$this->expenseRevenueCents + $other->expenseRevenueCents,
$this->expenseCostCents + $other->expenseCostCents,
$this->hourCostCents === null || $other->hourCostCents === null ? null : $this->hourCostCents + $other->hourCostCents,
$this->materialCostCents + $other->materialCostCents,
);
}
@@ -100,6 +105,7 @@ final readonly class Profit
self::share($this->expenseRevenueCents, $parts, $index),
self::share($this->expenseCostCents, $parts, $index),
$this->hourCostCents === null ? null : self::share($this->hourCostCents, $parts, $index),
self::share($this->materialCostCents, $parts, $index),
);
}