@@ -57,3 +57,22 @@ test('explicit zero-value receipt differs from unknown cost', function () {
|
||||
$r = StockCosting::project('fifo', costingOpening(), [costingReceipt(1, 1000, 0), costingIssue(2, 1000)]);
|
||||
expect($r['movements'][1]['value']['amount_minor'])->toBe('0')->and($r['journals_written'])->toBeFalse();
|
||||
});
|
||||
|
||||
test('configured half up preserves the final balance without changing the exact default', function (string $method, array $expected) {
|
||||
$facts = [costingReceipt(1, 3000, 100), costingIssue(2, 1000), costingIssue(3, 1000), costingIssue(4, 1000)];
|
||||
$result = StockCosting::project($method, costingOpening(), $facts, 'half_up_final_balance');
|
||||
expect(array_column(array_column(array_slice($result['movements'], 1), 'value'), 'amount_minor'))->toBe($expected)
|
||||
->and($result['closing']['value']['amount_minor'])->toBe('0')
|
||||
->and($result['closing']['quantity_milli'])->toBe(0)
|
||||
->and(StockCosting::project($method, costingOpening(), $facts)['movements'][1]['value']['rounding_required'])->toBeTrue();
|
||||
})->with(['fifo' => ['fifo', ['33', '33', '34']], 'average' => ['weighted_average', ['33', '34', '33']]]);
|
||||
|
||||
test('half cent rounds upwards and the last issue receives the residual', function (string $method) {
|
||||
$result = StockCosting::project($method, costingOpening(), [costingReceipt(1, 2000, 101), costingIssue(2, 1000), costingIssue(3, 1000)], 'half_up_final_balance');
|
||||
expect($result['movements'][1]['value']['amount_minor'])->toBe('51')
|
||||
->and($result['movements'][2]['value']['amount_minor'])->toBe('50');
|
||||
})->with(['fifo', 'weighted_average']);
|
||||
|
||||
test('an unrecognised rounding policy cannot silently change costs', function () {
|
||||
expect(fn () => StockCosting::project('fifo', costingOpening(), [], 'automatic'))->toThrow(InvalidArgumentException::class);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user