mirror of
https://github.com/archtechx/money.git
synced 2025-12-12 03:14:03 +00:00
commit
4474c2b115
2 changed files with 6 additions and 6 deletions
|
|
@ -115,7 +115,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
|
||||||
public function addFee(float $rate): self
|
public function addFee(float $rate): self
|
||||||
{
|
{
|
||||||
return $this->multiplyBy(
|
return $this->multiplyBy(
|
||||||
round(1 + $rate, $this->currency->mathDecimals())
|
round(1 + ($rate / 100), $this->currency->mathDecimals())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,7 +129,7 @@ final class Money implements JsonSerializable, Arrayable, Wireable
|
||||||
public function subtractFee(float $rate): self
|
public function subtractFee(float $rate): self
|
||||||
{
|
{
|
||||||
return $this->divideBy(
|
return $this->divideBy(
|
||||||
round(1 + $rate, $this->currency->mathDecimals())
|
round(1 + ($rate / 100), $this->currency->mathDecimals())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -104,19 +104,19 @@ test('money can be divided', function () {
|
||||||
test('fees can be added to and subtracted from money', function () {
|
test('fees can be added to and subtracted from money', function () {
|
||||||
$money = Money::fromDecimal(10.0);
|
$money = Money::fromDecimal(10.0);
|
||||||
|
|
||||||
expect($money->addFee(0.1)->decimal())->toBe(11.0);
|
expect($money->addFee(10)->decimal())->toBe(11.0);
|
||||||
expect($money->subtractFee(0.1)->decimal())->toBe(9.09); // 10/1.1
|
expect($money->subtractFee(10)->decimal())->toBe(9.09); // 10/1.1
|
||||||
});
|
});
|
||||||
|
|
||||||
test('taxes can be added and subtracted from money', function () {
|
test('taxes can be added and subtracted from money', function () {
|
||||||
currencies()->add([CZK::class]);
|
currencies()->add([CZK::class]);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
Money::fromDecimal(100.0, 'CZK')->addTax(0.21)->decimal()
|
Money::fromDecimal(100.0, 'CZK')->addTax(21.0)->decimal()
|
||||||
)->toBe(121.0);
|
)->toBe(121.0);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
Money::fromDecimal(121.0, 'CZK')->subtractTax(0.21)->decimal()
|
Money::fromDecimal(121.0, 'CZK')->subtractTax(21.0)->decimal()
|
||||||
)->toBe(100.0);
|
)->toBe(100.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue