Patch currency subunit conversion (#1484)
* added parentheses around the conversion * updated finance test updated the following test: - journal operations fixed the following tests: - pirep finances - pirep finances specific expense - pirep finances expenses multi airline
This commit is contained in:
parent
f30a3bc1ef
commit
2155979eb9
@ -33,7 +33,7 @@ class Money
|
|||||||
/**
|
/**
|
||||||
* Create from a dollar amount
|
* Create from a dollar amount
|
||||||
*
|
*
|
||||||
* @param mixed $amount The amount in pennies
|
* @param mixed $amount The amount in dollar
|
||||||
*
|
*
|
||||||
* @throws \UnexpectedValueException
|
* @throws \UnexpectedValueException
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
@ -52,12 +52,12 @@ class Money
|
|||||||
*
|
*
|
||||||
* @param mixed $amount
|
* @param mixed $amount
|
||||||
*
|
*
|
||||||
* @return float|int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function convertToSubunit($amount)
|
public static function convertToSubunit($amount)
|
||||||
{
|
{
|
||||||
$currency = setting('units.currency', 'USD');
|
$currency = setting('units.currency', 'USD');
|
||||||
return (int) $amount * config('money.'.$currency.'.subunit');
|
return (int) ($amount * config('money.'.$currency.'.subunit'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -712,20 +712,20 @@ class FinanceTest extends TestCase
|
|||||||
|
|
||||||
$journalRepo->post(
|
$journalRepo->post(
|
||||||
$journal,
|
$journal,
|
||||||
Money::createFromAmount(100),
|
Money::createFromAmount(100.5),
|
||||||
null,
|
null,
|
||||||
$user
|
$user
|
||||||
);
|
);
|
||||||
|
|
||||||
$balance = $journalRepo->getBalance($journal);
|
$balance = $journalRepo->getBalance($journal);
|
||||||
$this->assertEquals(100, $balance->getValue());
|
$this->assertEquals(100.5, $balance->getValue());
|
||||||
$this->assertEquals(100, $journal->balance->getValue());
|
$this->assertEquals(100.5, $journal->balance->getValue());
|
||||||
|
|
||||||
// add another transaction
|
// add another transaction
|
||||||
|
|
||||||
$journalRepo->post(
|
$journalRepo->post(
|
||||||
$journal,
|
$journal,
|
||||||
Money::createFromAmount(25),
|
Money::createFromAmount(24.5),
|
||||||
null,
|
null,
|
||||||
$user
|
$user
|
||||||
);
|
);
|
||||||
@ -912,7 +912,7 @@ class FinanceTest extends TestCase
|
|||||||
|
|
||||||
// $this->assertCount(9, $transactions['transactions']);
|
// $this->assertCount(9, $transactions['transactions']);
|
||||||
$this->assertEquals(3020, $transactions['credits']->getValue());
|
$this->assertEquals(3020, $transactions['credits']->getValue());
|
||||||
$this->assertEquals(2050.0, $transactions['debits']->getValue());
|
$this->assertEquals(2050.4, $transactions['debits']->getValue());
|
||||||
|
|
||||||
// Check that all the different transaction types are there
|
// Check that all the different transaction types are there
|
||||||
// test by the different groups that exist
|
// test by the different groups that exist
|
||||||
@ -967,7 +967,7 @@ class FinanceTest extends TestCase
|
|||||||
|
|
||||||
// $this->assertCount(9, $transactions['transactions']);
|
// $this->assertCount(9, $transactions['transactions']);
|
||||||
$this->assertEquals(3020, $transactions['credits']->getValue());
|
$this->assertEquals(3020, $transactions['credits']->getValue());
|
||||||
$this->assertEquals(2050.0, $transactions['debits']->getValue());
|
$this->assertEquals(2050.4, $transactions['debits']->getValue());
|
||||||
|
|
||||||
// Check that all the different transaction types are there
|
// Check that all the different transaction types are there
|
||||||
// test by the different groups that exist
|
// test by the different groups that exist
|
||||||
@ -1006,7 +1006,7 @@ class FinanceTest extends TestCase
|
|||||||
|
|
||||||
$transactions = $journalRepo->getAllForObject($pirep2);
|
$transactions = $journalRepo->getAllForObject($pirep2);
|
||||||
$this->assertEquals(3020, $transactions['credits']->getValue());
|
$this->assertEquals(3020, $transactions['credits']->getValue());
|
||||||
$this->assertEquals(2150.0, $transactions['debits']->getValue());
|
$this->assertEquals(2150.4, $transactions['debits']->getValue());
|
||||||
|
|
||||||
// Check that all the different transaction types are there
|
// Check that all the different transaction types are there
|
||||||
// test by the different groups that exist
|
// test by the different groups that exist
|
||||||
@ -1115,6 +1115,6 @@ class FinanceTest extends TestCase
|
|||||||
|
|
||||||
// $this->assertCount(9, $transactions['transactions']);
|
// $this->assertCount(9, $transactions['transactions']);
|
||||||
$this->assertEquals(3020, $transactions['credits']->getValue());
|
$this->assertEquals(3020, $transactions['credits']->getValue());
|
||||||
$this->assertEquals(2050.0, $transactions['debits']->getValue());
|
$this->assertEquals(2050.4, $transactions['debits']->getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user