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:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Reports\Domain\ValueObjects\Profit;
|
||||
|
||||
it('charges the hours at the internal hourly cost and subtracts the costs from what was billed', function () {
|
||||
// 10,25 h at 45 €/h, 1 000 € billed for work and 120 € for expenses that cost 100 €.
|
||||
$profit = Profit::of(41, 40, 100000, 12000, 10000, 4500);
|
||||
|
||||
expect($profit->hourCostCents)->toBe(46125)
|
||||
->and($profit->revenueCents())->toBe(112000)
|
||||
->and($profit->marginCents())->toBe(55875)
|
||||
->and($profit->marginRatio())->toEqualWithDelta(0.4989, 0.0001)
|
||||
->and($profit->effectiveHourlyCents())->toBe(9756);
|
||||
});
|
||||
|
||||
it('leaves the cost of the hours and the margin out without an hourly cost', function () {
|
||||
$profit = Profit::of(8, 0, 50000, 0, 0, null);
|
||||
|
||||
expect($profit->hourCostCents)->toBeNull()
|
||||
->and($profit->marginCents())->toBeNull()
|
||||
->and($profit->marginRatio())->toBeNull()
|
||||
->and($profit->effectiveHourlyCents())->toBe(25000)
|
||||
->and($profit->plus(Profit::of(4, 0, 0, 0, 0, 4500))->hourCostCents)->toBeNull();
|
||||
});
|
||||
|
||||
it('has no margin ratio or hourly yield when nothing was billed or worked', function () {
|
||||
$profit = Profit::of(0, 0, 0, 0, 5000, 4500);
|
||||
|
||||
expect($profit->marginCents())->toBe(-5000)
|
||||
->and($profit->marginRatio())->toBeNull()
|
||||
->and($profit->effectiveHourlyCents())->toBeNull();
|
||||
});
|
||||
|
||||
it('splits the figures evenly so that the parts add up to the whole', function () {
|
||||
$profit = Profit::of(5, 4, 1001, 0, -7, 4500);
|
||||
$parts = $profit->split(3);
|
||||
|
||||
expect(array_map(fn (Profit $part): int => $part->quarters, $parts))->toBe([2, 2, 1])
|
||||
->and(array_map(fn (Profit $part): int => $part->workCents, $parts))->toBe([334, 334, 333])
|
||||
->and(array_map(fn (Profit $part): int => $part->expenseCostCents, $parts))->toBe([-3, -2, -2])
|
||||
->and(array_sum(array_map(fn (Profit $part): int => (int) $part->hourCostCents, $parts)))->toBe($profit->hourCostCents)
|
||||
->and($parts[0]->plus($parts[1])->plus($parts[2]))->toEqual($profit);
|
||||
});
|
||||
Reference in New Issue
Block a user