Skip to content

Commit

Permalink
currency changed to parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
kablanfatih committed Mar 3, 2020
1 parent fc01f51 commit a17f175
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
34 changes: 14 additions & 20 deletions src/Models/Ledger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* Class Journal
* @package Scottlaurent\Accounting
* @property Money $balance
* @property string $currency
* @property Carbon $updated_at
* @property Carbon $post_date
* @property Carbon $created_at
Expand All @@ -24,13 +23,6 @@ class Ledger extends Model
*/
protected $table = 'accounting_ledgers';

/**
* Currency.
*
* @var string $currency
*/
public $currency;

/**
*
*/
Expand All @@ -46,27 +38,29 @@ public function journal_transactions()
{
return $this->hasManyThrough(JournalTransaction::class, Journal::class);
}

/**
*
*/
public function getCurrentBalance()

/**
* @param $currency
* @return Money
*/
public function getCurrentBalance($currency)
{
if ($this->type == 'asset' || $this->type == 'expense') {
$balance = $this->journal_transactions->sum('debit') - $this->journal_transactions->sum('credit');
} else {
$balance = $this->journal_transactions->sum('credit') - $this->journal_transactions->sum('debit');
}

return new Money($balance, new Currency($this->currency));
return new Money($balance, new Currency($currency));
}

/**
*
*/
public function getCurrentBalanceInDollars()

/**
* @param $currency
* @return float|int
*/
public function getCurrentBalanceInDollars($currency)
{
return $this->getCurrentBalance()->getAmount() / 100;
return $this->getCurrentBalance($currency)->getAmount() / 100;
}


Expand Down
12 changes: 6 additions & 6 deletions tests/DoubleEntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ public function testMakingSurePostTransactionLedgersMatch() {
$transaction_group->addDollarTransaction($this->company_income_journal,'credit',$dollar_value);
$transaction_group->commit();

$this->assertEquals($this->company_assets_ledger->getCurrentBalanceInDollars(),((int) ($dollar_value*100))/100);
$this->assertEquals($this->company_income_ledger->getCurrentBalanceInDollars(),((int) ($dollar_value*100))/100);
$this->assertEquals($this->company_assets_ledger->getCurrentBalanceInDollars('USD'),((int) ($dollar_value*100))/100);
$this->assertEquals($this->company_income_ledger->getCurrentBalanceInDollars('USD'),((int) ($dollar_value*100))/100);

$this->assertEquals(
$this->company_assets_ledger->getCurrentBalanceInDollars(),
$this->company_income_ledger->getCurrentBalanceInDollars()
$this->company_assets_ledger->getCurrentBalanceInDollars('USD'),
$this->company_income_ledger->getCurrentBalanceInDollars('USD')
);
}

Expand All @@ -117,8 +117,8 @@ public function testMakingSurePostTransactionLedgersMatchAfterComplexActivity()
}

$this->assertEquals(
$this->company_assets_ledger->getCurrentBalanceInDollars(),
$this->company_income_ledger->getCurrentBalanceInDollars()
$this->company_assets_ledger->getCurrentBalanceInDollars('USD'),
$this->company_income_ledger->getCurrentBalanceInDollars('USD')
);
}
}
8 changes: 4 additions & 4 deletions tests/LedgerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function testLedgers() {
$this->assertEquals($number_of_users * 100, (-1) * $this->company_ar_journal->getCurrentBalanceInDollars());

// This is testing that the value on the LEFT side of the books (ASSETS) is the same as the RIGHT side (L + OE + nominals)
$this->assertEquals($number_of_users * 100, $this->company_assets_ledger->getCurrentBalanceInDollars());
$this->assertEquals($number_of_users * 100, $this->company_income_ledger->getCurrentBalanceInDollars());
$this->assertEquals($this->company_assets_ledger->getCurrentBalanceInDollars(),$this->company_income_ledger->getCurrentBalanceInDollars());
$this->assertEquals($number_of_users * 100, $this->company_assets_ledger->getCurrentBalanceInDollars('USD'));
$this->assertEquals($number_of_users * 100, $this->company_income_ledger->getCurrentBalanceInDollars('USD'));
$this->assertEquals($this->company_assets_ledger->getCurrentBalanceInDollars('USD'),$this->company_income_ledger->getCurrentBalanceInDollars('USD'));

// At this point we have no cash on hand
$this->assertEquals($this->company_cash_journal->getCurrentBalanceInDollars(),0);
Expand Down Expand Up @@ -81,7 +81,7 @@ public function testLedgers() {
);

// still make sure our ledger balances match
$this->assertEquals($this->company_assets_ledger->getCurrentBalanceInDollars(),$this->company_income_ledger->getCurrentBalanceInDollars());
$this->assertEquals($this->company_assets_ledger->getCurrentBalanceInDollars('USD'),$this->company_income_ledger->getCurrentBalanceInDollars('USD'));

}

Expand Down

0 comments on commit a17f175

Please sign in to comment.