Skip to content

Firefly III: a personal finances manager

Most views now show the transaction the current journal/transaction is set in, even if it's not the current default currency. See issue #37

James Colec0c37eec7b26
diff --git a/app/database/seeds/TestContentSeeder.php b/app/database/seeds/TestContentSeeder.php
index bc68264062..525d6fd4b6 100644
--- a/app/database/seeds/TestContentSeeder.php
+++ b/app/database/seeds/TestContentSeeder.php
@@ -22,6 +22,9 @@ class TestContentSeeder extends Seeder
$transfer = TransactionType::whereType('Transfer')->first();
$deposit = TransactionType::whereType('Deposit')->first();
+ $euro = TransactionCurrency::whereCode('EUR')->first();
+ $dollar = TransactionCurrency::whereCode('USD')->first();
+
$user = User::whereEmail('[email protected]')->first();
if ($user) {
@@ -245,8 +248,8 @@ class TestContentSeeder extends Seeder
['user_id' => $user->id, 'account_type_id' => $ibType->id, 'name' => 'Savings account initial balance', 'active' => 0]
);
- $this->createTransaction($ibChecking, $checking, 4000, $obType, 'Initial Balance for Checking account', '2014-01-01');
- $this->createTransaction($ibSavings, $savings, 10000, $obType, 'Initial Balance for Savings account', '2014-01-01');
+ $this->createTransaction($ibChecking, $checking, 4000, $obType, 'Initial Balance for Checking account', '2014-01-01', $euro);
+ $this->createTransaction($ibSavings, $savings, 10000, $obType, 'Initial Balance for Savings account', '2014-01-01', $euro);
// create some expenses and incomes and what-not (for every month):
@@ -254,14 +257,16 @@ class TestContentSeeder extends Seeder
$end = Carbon::now()->endOfMonth()->addDay();
while ($start <= $end) {
$this->createTransaction(
- $checking, $portaal, 500, $withdrawal, 'Huur Portaal for ' . $start->format('F Y'), $start->format('Y-m-') . '01', $billsBudget, $house,
+ $checking, $portaal, 500, $withdrawal, 'Huur Portaal for ' . $start->format('F Y'), $start->format('Y-m-') . '01', $euro, $billsBudget,
+ $house,
$firstBill
);
$this->createTransaction(
- $checking, $vitens, 12, $withdrawal, 'Water for ' . $start->format('F Y'), $start->format('Y-m-') . '02', $billsBudget, $house
+ $checking, $vitens, 12, $withdrawal, 'Water for ' . $start->format('F Y'), $start->format('Y-m-') . '02', $euro, $billsBudget, $house
);
$this->createTransaction(
- $checking, $greenchoice, 110, $withdrawal, 'Power for ' . $start->format('F Y'), $start->format('Y-m-') . '02', $billsBudget, $house
+ $checking, $greenchoice, 110, $withdrawal, 'Power for ' . $start->format('F Y'), $start->format('Y-m-') . '02', $euro, $billsBudget,
+ $house
);
// spend on groceries
@@ -270,22 +275,24 @@ class TestContentSeeder extends Seeder
$amt = rand(100, 300) / 10;
$lunchAmount = rand(30, 60) / 10;
$this->createTransaction(
- $checking, $plus, $lunchAmount, $withdrawal, 'Lunch', $groceriesStart->format('Y-m-d'), $groceriesBudget, $lunch
+ $checking, $plus, $lunchAmount, $withdrawal, 'Lunch', $groceriesStart->format('Y-m-d'), $dollar, $groceriesBudget, $lunch
);
$groceriesStart->addDay();
if (intval($groceriesStart->format('d')) % 2 == 0) {
$this->createTransaction(
- $checking, $albert, $amt, $withdrawal, 'Groceries', $groceriesStart->format('Y-m-d'), $groceriesBudget, $dailyGroceries
+ $checking, $albert, $amt, $withdrawal, 'Groceries', $groceriesStart->format('Y-m-d'), $euro, $groceriesBudget, $dailyGroceries
);
}
$groceriesStart->addDay();
}
// get income:
- $this->createTransaction($employer, $checking, rand(1400, 1600), $deposit, 'Salary', $start->format('Y-m-') . '23');
+ $this->createTransaction($employer, $checking, rand(1400, 1600), $deposit, 'Salary', $start->format('Y-m-') . '23', $dollar);
// pay taxes:
- $this->createTransaction($checking, $taxes, rand(50, 70), $withdrawal, 'Taxes in ' . $start->format('F Y'), $start->format('Y-m-') . '27');
+ $this->createTransaction(
+ $checking, $taxes, rand(50, 70), $withdrawal, 'Taxes in ' . $start->format('F Y'), $start->format('Y-m-') . '27', $euro
+ );
// some other stuff.
@@ -295,8 +302,8 @@ class TestContentSeeder extends Seeder
}
// create some big expenses, move some money around.
- $this->createTransaction($savings, $checking, 1259, $transfer, 'Money for new PC', $end->format('Y-m') . '-11');
- $this->createTransaction($checking, $store, 1259, $withdrawal, 'New PC', $end->format('Y-m') . '-12');
+ $this->createTransaction($savings, $checking, 1259, $transfer, 'Money for new PC', $end->format('Y-m') . '-11', $dollar);
+ $this->createTransaction($checking, $store, 1259, $withdrawal, 'New PC', $end->format('Y-m') . '-12', $euro);
// create two budgets
@@ -315,6 +322,7 @@ class TestContentSeeder extends Seeder
* @param TransactionType $type
* @param $description
* @param $date
+ * @param TransactionCurrency $currency
*
* @param Budget $budget
* @param Category $category
@@ -323,18 +331,20 @@ class TestContentSeeder extends Seeder
* @return TransactionJournal
*/
public function createTransaction(
- Account $from, Account $to, $amount, TransactionType $type, $description, $date, Budget $budget = null, Category $category = null, Bill $bill = null
+ Account $from, Account $to, $amount, TransactionType $type, $description, $date, TransactionCurrency $currency, Budget $budget = null,
+ Category $category = null, Bill $bill = null
) {
- $user = User::whereEmail('[email protected]')->first();
- $euro = TransactionCurrency::whereCode('EUR')->first();
+ $user = User::whereEmail('[email protected]')->first();
+
$billID = is_null($bill) ? null : $bill->id;
+
/** @var TransactionJournal $journal */
$journal = TransactionJournal::create(
[
'user_id' => $user->id,
'transaction_type_id' => $type->id,
- 'transaction_currency_id' => $euro->id,
+ 'transaction_currency_id' => $currency->id,
'bill_id' => $billID,
'description' => $description,
'completed' => 1,
diff --git a/app/database/seeds/TransactionCurrencySeeder.php b/app/database/seeds/TransactionCurrencySeeder.php
index 20f50e9f60..67ae8faba3 100644
--- a/app/database/seeds/TransactionCurrencySeeder.php
+++ b/app/database/seeds/TransactionCurrencySeeder.php
@@ -12,6 +12,7 @@ class TransactionCurrencySeeder extends Seeder
TransactionCurrency::create(['code' => 'EUR','name' => 'Euro','symbol' => '&#8364;']);
TransactionCurrency::create(['code' => 'USD','name' => 'US Dollar','symbol' => '$']);
+ TransactionCurrency::create(['code' => 'HUF','name' => 'Hungarian forint','symbol' => 'Ft']);
}
}
\ No newline at end of file
diff --git a/app/views/list/journals-full.blade.php b/app/views/list/journals-full.blade.php
index ffbaa2427f..c97a4ca210 100644
--- a/app/views/list/journals-full.blade.php
+++ b/app/views/list/journals-full.blade.php
@@ -58,13 +58,13 @@
</td>
<td>
@if($journal->transactiontype->type == 'Withdrawal')
- <span class="text-danger">{{mf($journal->transactions[1]->amount,false)}}</span>
+ <span class="text-danger">{{mft($journal->transactions[1],false)}}</span>
@endif
@if($journal->transactiontype->type == 'Deposit')
- <span class="text-success">{{mf($journal->transactions[1]->amount,false)}}</span>
+ <span class="text-success">{{mft($journal->transactions[1],false)}}</span>
@endif
@if($journal->transactiontype->type == 'Transfer')
- <span class="text-info">{{mf($journal->transactions[1]->amount,false)}}</span>
+ <span class="text-info">{{mft($journal->transactions[1],false)}}</span>
@endif
</td>
<td>
diff --git a/app/views/list/journals-small.blade.php b/app/views/list/journals-small.blade.php
index 02ea6c7939..5643db3ad0 100644
--- a/app/views/list/journals-small.blade.php
+++ b/app/views/list/journals-small.blade.php
@@ -9,13 +9,13 @@
<td>
<?php $tableSum += floatval($journal->transactions[1]->amount);?>
@if($journal->transactiontype->type == 'Withdrawal')
- <span class="text-danger">{{mf($journal->transactions[1]->amount,false)}}</span>
+ <span class="text-danger">{{mft($journal->transactions[1],false)}}</span>
@endif
@if($journal->transactiontype->type == 'Deposit')
- <span class="text-success">{{mf($journal->transactions[1]->amount,false)}}</span>
+ <span class="text-success">{{mft($journal->transactions[1],false)}}</span>
@endif
@if($journal->transactiontype->type == 'Transfer')
- <span class="text-info">{{mf($journal->transactions[1]->amount,false)}}</span>
+ <span class="text-info">{{mft($journal->transactions[1],false)}}</span>
@endif
</td>
<td>
diff --git a/app/views/list/journals-tiny.blade.php b/app/views/list/journals-tiny.blade.php
index 91c2b6f2d3..ff369db70c 100644
--- a/app/views/list/journals-tiny.blade.php
+++ b/app/views/list/journals-tiny.blade.php
@@ -18,13 +18,13 @@
@if(isset($account))
@foreach($journal->transactions as $index => $t)
@if($t->account_id == $account->id)
- {{mf($t->amount)}}
+ {{mft($t)}}
@endif
@endforeach
@else
@foreach($journal->transactions as $index => $t)
@if($index == 0)
- {{mf($t->amount)}}
+ {{mft($t)}}
@endif
@endforeach
@endif
diff --git a/app/views/transactions/show.blade.php b/app/views/transactions/show.blade.php
index 5b86bd130a..8443184239 100644
--- a/app/views/transactions/show.blade.php
+++ b/app/views/transactions/show.blade.php
@@ -74,7 +74,7 @@
<tr>
<td><input type="checkbox" checked="checked" data-relatedto="{{$journal->id}}" data-id="{{$jrnl->id}}" class="unrelate-checkbox" /></td>
<td><a href="#">{{{$jrnl->description}}}</a></td>
- <td>{{mf($jrnl->getAmount())}}</td>
+ <td>{{mfj($jrnl, $jrnl->getAmount())}}</td>
</tr>
@endforeach
</table>
@@ -97,7 +97,7 @@
<table class="table table-striped table-bordered">
<tr>
<td>Amount</td>
- <td>{{mf($t->amount)}}</td>
+ <td>{{mft($t)}}</td>
</tr>
<tr>
<td>New balance</td>
diff --git a/bootstrap/functions.php b/bootstrap/functions.php
new file mode 100644
index 0000000000..2424d07741
--- /dev/null
+++ b/bootstrap/functions.php
@@ -0,0 +1,166 @@
+<?php
+if (!function_exists('mf')) {
+ /**
+ * @param $amount
+ * @param bool $coloured
+ *
+ * @return string
+ */
+ function mf($amount, $coloured = true)
+ {
+ $currencySymbol = getCurrencySymbol();
+
+ return mfc($currencySymbol, $amount, $coloured);
+
+
+ }
+}
+
+if (!function_exists('mft')) {
+ /**
+ * @param \Transaction $transaction
+ * @param bool $coloured
+ *
+ * @return string
+ */
+ function mft(\Transaction $transaction, $coloured = true)
+ {
+ $symbol = $transaction->transactionJournal->transactionCurrency->symbol;
+ $amount = floatval($transaction->amount);
+
+ return mfc($symbol, $amount, $coloured);
+
+
+ }
+}
+
+if (!function_exists('mfj')) {
+ /**
+ * @param \TransactionJournal $journal
+ * @param float $amount
+ * @param bool $coloured
+ *
+ * @return string
+ */
+ function mfj(\TransactionJournal $journal, $amount, $coloured = true)
+ {
+ $symbol = $journal->transactionCurrency->symbol;
+
+ return mfc($symbol, $amount, $coloured);
+
+
+ }
+}
+
+if (!function_exists('mfc')) {
+ /**
+ * @param string $symbol
+ * @param float $amount
+ * @param bool $coloured
+ *
+ * @return string
+ */
+ function mfc($symbol, $amount, $coloured = true)
+ {
+ $amount = floatval($amount);
+ $amount = round($amount, 2);
+ $string = number_format($amount, 2, ',', '.');
+
+ if ($coloured === true) {
+ if ($amount === 0.0) {
+ return '<span style="color:#999">' . $symbol . ' ' . $string . '</span>';
+ }
+ if ($amount > 0) {
+ return '<span class="text-success">' . $symbol . ' ' . $string . '</span>';
+ }
+
+ return '<span class="text-danger">' . $symbol . ' ' . $string . '</span>';
+ }
+
+ // &#8364;
+ return $symbol . ' ' . $string;
+ }
+}
+
+if (!function_exists('getCurrencySymbol')) {
+ /**
+ * @return string
+ */
+ function getCurrencySymbol()
+ {
+ if (defined('FFCURRENCYSYMBOL')) {
+ return FFCURRENCYSYMBOL;
+ }
+ if (Cache::has('FFCURRENCYSYMBOL')) {
+ define('FFCURRENCYSYMBOL', Cache::get('FFCURRENCYSYMBOL'));
+
+ return FFCURRENCYSYMBOL;
+ }
+
+ /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencies */
+ $currencies = App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
+
+ /** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
+ $preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
+
+ $currencyPreference = $preferences->get('currencyPreference', 'EUR');
+ $currency = $currencies->findByCode($currencyPreference->data);
+
+ Cache::forever('FFCURRENCYSYMBOL', $currency->symbol);
+
+ define('FFCURRENCYSYMBOL', $currency->symbol);
+
+ return $currency->symbol;
+ }
+}
+
+if (!function_exists('getCurrencyCode')) {
+ /**
+ * @return string
+ */
+ function getCurrencyCode()
+ {
+ if (defined('FFCURRENCYCODE')) {
+ return FFCURRENCYCODE;
+ }
+ if (Cache::has('FFCURRENCYCODE')) {
+ define('FFCURRENCYCODE', Cache::get('FFCURRENCYCODE'));
+
+ return FFCURRENCYCODE;
+ }
+
+ /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencies */
+ $currencies = App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
+
+ /** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
+ $preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
+
+ $currencyPreference = $preferences->get('currencyPreference', 'EUR');
+ $currency = $currencies->findByCode($currencyPreference->data);
+
+ Cache::forever('FFCURRENCYCODE', $currency->code);
+
+ define('FFCURRENCYCODE', $currency->code);
+
+ return $currency->code;
+ }
+}
+
+if (!function_exists('boolstr')) {
+ /**
+ * @param $boolean
+ *
+ * @return string
+ */
+ function boolstr($boolean)
+ {
+ if (is_bool($boolean) && $boolean === true) {
+ return 'BOOLEAN TRUE';
+ }
+ if (is_bool($boolean) && $boolean === false) {
+ return 'BOOLEAN FALSE';
+ }
+
+ return 'NO BOOLEAN: ' . $boolean;
+ }
+}
\ No newline at end of file
diff --git a/bootstrap/start.php b/bootstrap/start.php
index 7395dfd718..a45a61456c 100644
--- a/bootstrap/start.php
+++ b/bootstrap/start.php
@@ -1,118 +1,6 @@
<?php
-if (!function_exists('mf')) {
- /**
- * @param $amount
- * @param bool $coloured
- *
- * @return string
- */
- function mf($amount, $coloured = true)
- {
- $currencySymbol = getCurrencySymbol();
-
- $amount = floatval($amount);
- $amount = round($amount, 2);
- $string = number_format($amount, 2, ',', '.');
-
- if ($coloured === true) {
- if ($amount === 0.0) {
- return '<span style="color:#999">' . $currencySymbol . ' ' . $string . '</span>';
- }
- if ($amount > 0) {
- return '<span class="text-success">' . $currencySymbol . ' ' . $string . '</span>';
- }
-
- return '<span class="text-danger">' . $currencySymbol . ' ' . $string . '</span>';
- }
-
- // &#8364;
- return $currencySymbol . ' ' . $string;
- }
-}
-
-if (!function_exists('getCurrencySymbol')) {
- /**
- * @return string
- */
- function getCurrencySymbol()
- {
- if (defined('FFCURRENCYSYMBOL')) {
- return FFCURRENCYSYMBOL;
- }
- if (Cache::has('FFCURRENCYSYMBOL')) {
- define('FFCURRENCYSYMBOL', Cache::get('FFCURRENCYSYMBOL'));
-
- return FFCURRENCYSYMBOL;
- }
-
- /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencies */
- $currencies = App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
-
- /** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
- $preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
-
- $currencyPreference = $preferences->get('currencyPreference', 'EUR');
- $currency = $currencies->findByCode($currencyPreference->data);
-
- Cache::forever('FFCURRENCYSYMBOL', $currency->symbol);
-
- define('FFCURRENCYSYMBOL', $currency->symbol);
-
- return $currency->symbol;
- }
-}
-
-if (!function_exists('getCurrencyCode')) {
- /**
- * @return string
- */
- function getCurrencyCode()
- {
- if (defined('FFCURRENCYCODE')) {
- return FFCURRENCYCODE;
- }
- if (Cache::has('FFCURRENCYCODE')) {
- define('FFCURRENCYCODE', Cache::get('FFCURRENCYCODE'));
-
- return FFCURRENCYCODE;
- }
-
- /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencies */
- $currencies = App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency');
-
- /** @var \FireflyIII\Shared\Preferences\Preferences $preferences */
- $preferences = App::make('FireflyIII\Shared\Preferences\Preferences');
-
- $currencyPreference = $preferences->get('currencyPreference', 'EUR');
- $currency = $currencies->findByCode($currencyPreference->data);
-
- Cache::forever('FFCURRENCYCODE', $currency->code);
-
- define('FFCURRENCYCODE', $currency->code);
-
- return $currency->code;
- }
-}
-
-if (!function_exists('boolstr')) {
- /**
- * @param $boolean
- *
- * @return string
- */
- function boolstr($boolean)
- {
- if (is_bool($boolean) && $boolean === true) {
- return 'BOOLEAN TRUE';
- }
- if (is_bool($boolean) && $boolean === false) {
- return 'BOOLEAN FALSE';
- }
-
- return 'NO BOOLEAN: ' . $boolean;
- }
-}
+include('functions.php');
$app = new Illuminate\Foundation\Application;
diff --git a/tests/functional/CurrencyControllerCest.php b/tests/functional/CurrencyControllerCest.php
index 0f59b4136f..47f4bf2ec2 100644
--- a/tests/functional/CurrencyControllerCest.php
+++ b/tests/functional/CurrencyControllerCest.php
@@ -41,8 +41,8 @@ class CurrencyControllerCest
public function delete(FunctionalTester $I)
{
$I->wantTo('delete a currency');
- $I->amOnPage('/currency/delete/2');
- $I->see('Delete currency "US Dollar"');
+ $I->amOnPage('/currency/delete/3');
+ $I->see('Delete currency "Hungarian forint"');
}
/**
@@ -51,10 +51,10 @@ class CurrencyControllerCest
public function destroy(FunctionalTester $I)
{
$I->wantTo('destroy a currency');
- $I->amOnPage('/currency/delete/2');
- $I->see('Delete currency "US Dollar"');
+ $I->amOnPage('/currency/delete/3');
+ $I->see('Delete currency "Hungarian forint"');
$I->submitForm('#destroy', []);
- $I->see('Currency &quot;US Dollar&quot; deleted');
+ $I->see('Currency &quot;Hungarian forint&quot; deleted');
}
/**