@@ -59,6 +59,50 @@ test('unknown rates and missing bases never become zero while explicit non-appli
|
||||
expect(fn () => $amounts->calculate([legalCharge(['rate_percent' => '10000'])], ['synthetic-duty' => ['value_minor' => 100000000000000, 'quantity' => null, 'quantity_unit' => null, 'source' => 'Synthetic overflow boundary']]))->toThrow(ValidationException::class);
|
||||
});
|
||||
|
||||
test('specific coefficients preserve fractional cents and round only the final exact charge', function () {
|
||||
$amounts = app(ImportLegalAmounts::class);
|
||||
$charge = legalCharge(['method' => 'specific', 'rate_percent' => null, 'specific_minor' => '1.33', 'quantity_unit' => 'g']);
|
||||
// Synthetic quantity: 600 L * 10.6 g/100 ml * 10 = 63600 g.
|
||||
// Coefficient0.0133 MZN/g corresponds exactly to1.33 cents/g.
|
||||
$base = ['value_minor' => null, 'quantity' => '63600.000000', 'quantity_unit' => 'g', 'source' => 'Synthetic documented quantity and concentration; no implicit conversion'];
|
||||
expect($amounts->definitions([$charge])[0]['specific_minor'])->toBe('1.33')
|
||||
->and($amounts->calculate([$charge], ['synthetic-duty' => $base])['total_minor'])->toBe(84588)
|
||||
->and($amounts->calculate([[...$charge, 'specific_minor' => '0.99']], ['synthetic-duty' => $base])['total_minor'])->toBe(62964);
|
||||
foreach (['0.499999' => 0, '0.500000' => 1] as $coefficient => $expected) {
|
||||
expect($amounts->calculate([[...$charge, 'specific_minor' => $coefficient]], ['synthetic-duty' => [...$base, 'quantity' => '1']])['total_minor'])->toBe($expected);
|
||||
}
|
||||
expect($amounts->definitions([[...$charge, 'specific_minor' => '125.000000']])[0]['specific_minor'])->toBe(125);
|
||||
foreach (['0.0000001', '1e2', '-0.1', '100000000000000.000001', 0.99] as $invalid) {
|
||||
expect(fn () => $amounts->definitions([[...$charge, 'specific_minor' => $invalid]]))->toThrow(ValidationException::class);
|
||||
}
|
||||
$maximum = [...$charge, 'method' => 'maximum', 'rate_percent' => '7.5', 'specific_minor' => '0.99'];
|
||||
expect($amounts->calculate([$maximum], ['synthetic-duty' => [...$base, 'value_minor' => 10001, 'quantity' => '1000']])['total_minor'])->toBe(990);
|
||||
});
|
||||
|
||||
test('native fractional specific estimates preserve the coefficient source and replay without financial effects', function () {
|
||||
$rules = app(ImportLegalRules::class);
|
||||
$charge = legalCharge(['method' => 'specific', 'rate_percent' => null, 'specific_minor' => '0.99', 'quantity_unit' => 'g']);
|
||||
$draft = $rules->save($this->f['issuer'], importLegalQaInput(['charges' => [$charge]]), importLegalQaFile());
|
||||
$rule = $rules->save($this->f['issuer'], ['operation_key' => (string) Str::uuid(), 'record_key' => $draft->record_key, 'version' => 1,
|
||||
'action' => 'publish', 'reason' => 'Synthetic fractional coefficient verification, no real tax activation']);
|
||||
$before = [];
|
||||
foreach (['budget_entries', 'invoices', 'stock_movements'] as $table) {
|
||||
$before[$table] = DB::table($table)->orderBy('id')->get()->toJson();
|
||||
}
|
||||
$input = ['operation_key' => (string) Str::uuid(), 'version' => 0, 'requisition_item_id' => $this->f['r']->items()->sole()->id,
|
||||
'rule_id' => $rule->id, 'match_code' => '1234', 'origin' => 'Synthetic A', 'sector' => 'Synthetic sector', 'date' => '2026-11-27',
|
||||
'bases' => ['synthetic-duty' => ['value_minor' => null, 'quantity' => '63600', 'quantity_unit' => 'g', 'source' => 'Synthetic explicit sugar mass']],
|
||||
'reason' => 'Synthetic exact coefficient estimate without a budget or stock effect'];
|
||||
$service = app(ImportLegalEstimates::class);
|
||||
$record = $service->save($this->f['issuer'], $this->f['r'], $input);
|
||||
expect($rule->data['charges'][0]['specific_minor'])->toBe('0.99')
|
||||
->and($record->snapshot['result']['total_minor'])->toBe(62964)
|
||||
->and($service->save($this->f['issuer'], $this->f['r'], $input)->id)->toBe($record->id);
|
||||
foreach ($before as $table => $rows) {
|
||||
expect(DB::table($table)->orderBy('id')->get()->toJson())->toBe($rows);
|
||||
}
|
||||
});
|
||||
|
||||
test('native estimates freeze source bases and calculated results without reserving funds and reject stale versions', function () {
|
||||
$rules = app(ImportLegalRules::class);
|
||||
$draft = $rules->save($this->f['issuer'], importLegalQaInput(['charges' => [legalCharge()]]), importLegalQaFile());
|
||||
|
||||
Reference in New Issue
Block a user