diff --git a/README.md b/README.md index e61b574ee0..06fc100514 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Firefly III [![Build Status](https://travis-ci.org/JC5/firefly-iii.svg?branch=develop)](https://travis-ci.org/JC5/firefly-iii) [![Project Status](http://stillmaintained.com/JC5/firefly-iii.png?a=b)](http://stillmaintained.com/JC5/firefly-iii) [![Coverage Status](https://coveralls.io/repos/JC5/firefly-iii/badge.png?branch=master)](https://coveralls.io/r/JC5/firefly-iii?branch=master) +[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102/mini.png)](https://insight.sensiolabs.com/projects/d44c7012-5f50-41ad-add8-8445330e4102) [![Latest Stable Version](https://poser.pugx.org/grumpydictator/firefly-iii/v/stable.svg)](https://packagist.org/packages/grumpydictator/firefly-iii) [![Total Downloads](https://poser.pugx.org/grumpydictator/firefly-iii/downloads.svg)](https://packagist.org/packages/grumpydictator/firefly-iii) diff --git a/app/controllers/PiggybankController.php b/app/controllers/PiggybankController.php index 8bf024d9ef..58924755ae 100644 --- a/app/controllers/PiggybankController.php +++ b/app/controllers/PiggybankController.php @@ -199,9 +199,9 @@ class PiggyBankController extends BaseController */ Event::fire('piggy_bank.addMoney', [$piggyBank, $amount]); // new and used. - Session::flash('success', 'Added ' . mf($amount, false) . ' to "' . e($piggyBank->name) . '".'); + Session::flash('success', 'Added ' . Amount::format($amount, false) . ' to "' . e($piggyBank->name) . '".'); } else { - Session::flash('error', 'Could not add ' . mf($amount, false) . ' to "' . e($piggyBank->name) . '".'); + Session::flash('error', 'Could not add ' . Amount::format($amount, false) . ' to "' . e($piggyBank->name) . '".'); } return Redirect::route('piggy_banks.index'); @@ -228,9 +228,9 @@ class PiggyBankController extends BaseController */ Event::fire('piggy_bank.removeMoney', [$piggyBank, $amount]); // new and used. - Session::flash('success', 'Removed ' . mf($amount, false) . ' from "' . e($piggyBank->name) . '".'); + Session::flash('success', 'Removed ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".'); } else { - Session::flash('error', 'Could not remove ' . mf($amount, false) . ' from "' . e($piggyBank->name) . '".'); + Session::flash('error', 'Could not remove ' . Amount::format($amount, false) . ' from "' . e($piggyBank->name) . '".'); } return Redirect::route('piggy_banks.index'); diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index da176b827d..167da8a6c0 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -69,7 +69,7 @@ class TransactionController extends BaseController $set = $this->_repository->getByIds($unique); $set->each( function (TransactionJournal $journal) { - $journal->amount = mf($journal->getAmount()); + $journal->amount = Amount::format($journal->getAmount()); } ); @@ -308,7 +308,7 @@ class TransactionController extends BaseController $result = $this->_repository->searchRelated($search, $journal); $result->each( function (TransactionJournal $j) { - $j->amount = mf($j->getAmount()); + $j->amount = Amount::format($j->getAmount()); } ); diff --git a/app/lib/FireflyIII/Database/Account/Account.php b/app/lib/FireflyIII/Database/Account/Account.php index e1ba05daa0..0cfa42dd03 100644 --- a/app/lib/FireflyIII/Database/Account/Account.php +++ b/app/lib/FireflyIII/Database/Account/Account.php @@ -7,11 +7,11 @@ use FireflyIII\Database\CommonDatabaseCallsInterface; use FireflyIII\Database\CUDInterface; use FireflyIII\Database\SwitchUser; use FireflyIII\Exception\NotImplementedException; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; - +use Illuminate\Database\Query\Builder as QueryBuilder; +use Illuminate\Database\Eloquent\Builder as EloquentBuilder; /** * Class Account * @@ -223,20 +223,21 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte public function destroy(Eloquent $model) { + // delete piggy banks // delete journals: $journals = \TransactionJournal::whereIn( - 'id', function (Builder $query) use ($model) { + 'id', function (QueryBuilder $query) use ($model) { $query->select('transaction_journal_id') ->from('transactions')->whereIn( - 'account_id', function (Builder $query) use ($model) { + 'account_id', function (QueryBuilder $query) use ($model) { $query ->select('id') ->from('accounts') ->where( - function (Builder $q) use ($model) { + function (QueryBuilder $q) use ($model) { $q->where('id', $model->id); $q->orWhere( - function (Builder $q) use ($model) { + function (QueryBuilder $q) use ($model) { $q->where('accounts.name', 'LIKE', '%' . $model->name . '%'); // TODO magic number! $q->where('accounts.account_type_id', 3); @@ -274,10 +275,10 @@ class Account implements CUDInterface, CommonDatabaseCallsInterface, AccountInte // delete accounts: \Account::where( - function (Builder $q) use ($model) { + function (EloquentBuilder $q) use ($model) { $q->where('id', $model->id); $q->orWhere( - function (Builder $q) use ($model) { + function (EloquentBuilder $q) use ($model) { $q->where('accounts.name', 'LIKE', '%' . $model->name . '%'); // TODO magic number! $q->where('accounts.account_type_id', 3); diff --git a/app/lib/FireflyIII/Database/Budget/Budget.php b/app/lib/FireflyIII/Database/Budget/Budget.php index f47f745b8f..770e703c1d 100644 --- a/app/lib/FireflyIII/Database/Budget/Budget.php +++ b/app/lib/FireflyIII/Database/Budget/Budget.php @@ -10,7 +10,7 @@ use FireflyIII\Exception\NotImplementedException; use Illuminate\Database\Eloquent\Model as Eloquent; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; -use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Query\Builder; /** * Class Budget @@ -336,7 +336,6 @@ class Budget implements CUDInterface, CommonDatabaseCallsInterface, BudgetInterf $limit->repeat_freq = 'monthly'; $limit->repeats = 0; $result = $limit->save(); - \Log::info('Created new limit? ' . boolstr($result)); \Log::info('ID: ' . $limit->id); /* * A newly stored limit also created a limit repetition. diff --git a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php index ff6cf9d12c..d85daa266c 100644 --- a/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php +++ b/app/lib/FireflyIII/Database/TransactionCurrency/TransactionCurrency.php @@ -35,7 +35,6 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas public function store(array $data) { $currency = new \TransactionCurrency($data); - \Log::debug('Is valid? ' . boolstr($currency->isValid())); $currency->save(); return $currency; @@ -52,7 +51,6 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas $model->symbol = $data['symbol']; $model->code = $data['code']; $model->name = $data['name']; - \Log::debug('Is valid? ' . boolstr($model->isValid())); $model->save(); return true; diff --git a/app/lib/FireflyIII/FF3ServiceProvider.php b/app/lib/FireflyIII/FF3ServiceProvider.php index 18ad6a4612..6495f65f51 100644 --- a/app/lib/FireflyIII/FF3ServiceProvider.php +++ b/app/lib/FireflyIII/FF3ServiceProvider.php @@ -7,6 +7,7 @@ use FireflyIII\Shared\Toolkit\Form; use FireflyIII\Shared\Toolkit\Navigation; use FireflyIII\Shared\Toolkit\Reminders; use FireflyIII\Shared\Toolkit\Steam; +use FireflyIII\Shared\Toolkit\Amount; use FireflyIII\Shared\Validation\FireflyValidator; use Illuminate\Foundation\AliasLoader; use Illuminate\Support\ServiceProvider; @@ -82,6 +83,11 @@ class FF3ServiceProvider extends ServiceProvider return new Steam; } ); + $this->app->bind( + 'amount', function () { + return new Amount; + } + ); } public function registerInterfaces() @@ -114,6 +120,7 @@ class FF3ServiceProvider extends ServiceProvider $loader->alias('Navigation', 'FireflyIII\Shared\Facade\Navigation'); $loader->alias('FFForm', 'FireflyIII\Shared\Facade\FFForm'); $loader->alias('Steam', 'FireflyIII\Shared\Facade\Steam'); + $loader->alias('Amount', 'FireflyIII\Shared\Facade\Amount'); } ); } diff --git a/app/lib/FireflyIII/Form/Form.php b/app/lib/FireflyIII/Form/Form.php index c44683a674..68409ab2df 100644 --- a/app/lib/FireflyIII/Form/Form.php +++ b/app/lib/FireflyIII/Form/Form.php @@ -123,7 +123,7 @@ class Form $html .= \Form::input('text', $name, $value, $options); break; case 'amount': - $html .= '
' . getCurrencySymbol() . '
'; + $html .= '
' . \Amount::getCurrencySymbol() . '
'; $html .= \Form::input('number', $name, $value, $options); $html .= '
'; break; diff --git a/app/lib/FireflyIII/Report/Report.php b/app/lib/FireflyIII/Report/Report.php index 3b012bcc1c..340179db5e 100644 --- a/app/lib/FireflyIII/Report/Report.php +++ b/app/lib/FireflyIII/Report/Report.php @@ -6,7 +6,7 @@ use Carbon\Carbon; use FireflyIII\Database\Account\Account as AccountRepository; use FireflyIII\Database\SwitchUser; use FireflyIII\Database\TransactionJournal\TransactionJournal as JournalRepository; -use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; diff --git a/app/lib/FireflyIII/Report/ReportQuery.php b/app/lib/FireflyIII/Report/ReportQuery.php index c224c80ea0..23d8113363 100644 --- a/app/lib/FireflyIII/Report/ReportQuery.php +++ b/app/lib/FireflyIII/Report/ReportQuery.php @@ -3,9 +3,9 @@ namespace FireflyIII\Report; use Carbon\Carbon; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\JoinClause; use Illuminate\Support\Collection; +use Illuminate\Database\Eloquent\Builder; /** * Class ReportQuery diff --git a/app/lib/FireflyIII/Search/Search.php b/app/lib/FireflyIII/Search/Search.php index 4324223d14..859d83b7b4 100644 --- a/app/lib/FireflyIII/Search/Search.php +++ b/app/lib/FireflyIII/Search/Search.php @@ -4,7 +4,7 @@ namespace FireflyIII\Search; use Illuminate\Support\Collection; -use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Builder as EloquentBuilder; /** * Class Search @@ -21,7 +21,7 @@ class Search public function searchAccounts(array $words) { return \Auth::user()->accounts()->with('accounttype')->where( - function (Builder $q) use ($words) { + function (EloquentBuilder $q) use ($words) { foreach ($words as $word) { $q->orWhere('name', 'LIKE', '%' . e($word) . '%'); } @@ -97,7 +97,7 @@ class Search public function searchTransactions(array $words) { return \Auth::user()->transactionjournals()->withRelevantData()->where( - function (Builder $q) use ($words) { + function (EloquentBuilder $q) use ($words) { foreach ($words as $word) { $q->orWhere('description', 'LIKE', '%' . e($word) . '%'); } diff --git a/app/lib/FireflyIII/Shared/Facade/Amount.php b/app/lib/FireflyIII/Shared/Facade/Amount.php new file mode 100644 index 0000000000..4a3eb4dba4 --- /dev/null +++ b/app/lib/FireflyIII/Shared/Facade/Amount.php @@ -0,0 +1,24 @@ +getCurrencySymbol(); + + return $this->formatWithSymbol($currencySymbol, $amount, $coloured); + + + } + + /** + * @return string + */ + public 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; + } + + /** + * @param string $symbol + * @param float $amount + * @param bool $coloured + * + * @return string + */ + protected function formatWithSymbol($symbol, $amount, $coloured = true) + { + $amount = floatval($amount); + $amount = round($amount, 2); + $string = number_format($amount, 2, ',', '.'); + + if ($coloured === true) { + if ($amount === 0.0) { + return '' . $symbol . ' ' . $string . ''; + } + if ($amount > 0) { + return '' . $symbol . ' ' . $string . ''; + } + + return '' . $symbol . ' ' . $string . ''; + } + + // € + return $symbol . ' ' . $string; + } + + /** + * @param \TransactionJournal $journal + * @param float $amount + * @param bool $coloured + * + * @return string + */ + public function formatJournal(\TransactionJournal $journal, $amount, $coloured = true) + { + $symbol = $journal->transactionCurrency->symbol; + + return $this->formatWithSymbol($symbol, $amount, $coloured); + + + } + + /** + * @param \Transaction $transaction + * @param bool $coloured + * + * @return string + */ + public function formatTransaction(\Transaction $transaction, $coloured = true) + { + $symbol = $transaction->transactionJournal->transactionCurrency->symbol; + $amount = floatval($transaction->amount); + + return $this->formatWithSymbol($symbol, $amount, $coloured); + + + } + + /** + * @return string + */ + public 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; + } + +} \ No newline at end of file diff --git a/app/lib/FireflyIII/Shared/Toolkit/Steam.php b/app/lib/FireflyIII/Shared/Toolkit/Steam.php index 4348456b4d..03f644bafc 100644 --- a/app/lib/FireflyIII/Shared/Toolkit/Steam.php +++ b/app/lib/FireflyIII/Shared/Toolkit/Steam.php @@ -25,7 +25,7 @@ class Steam */ public function balance(\Account $account, Carbon $date = null) { - $date = is_null($date) ? Carbon::now() : $date; + $date = is_null($date) ? Carbon::now() : $date; $balance = floatval( $account->transactions()->leftJoin( 'transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id' @@ -35,6 +35,23 @@ class Steam return $balance; } + /** + * @param $boolean + * + * @return string + */ + public function boolString($boolean) + { + if ($boolean === true) { + return 'BOOLEAN TRUE'; + } + if ($boolean === false) { + return 'BOOLEAN FALSE'; + } + + return 'NO BOOLEAN: ' . $boolean; + } + /** * @param \PiggyBank $piggyBank * @param \PiggyBankRepetition $repetition diff --git a/app/models/Reminder.php b/app/models/Reminder.php index 8ea1b8dddb..b9c7b326b8 100644 --- a/app/models/Reminder.php +++ b/app/models/Reminder.php @@ -1,8 +1,10 @@ where('startdate', $start->format('Y-m-d 00:00:00'))->where('enddate', $end->format('Y-m-d 00:00:00')); } diff --git a/app/models/Transaction.php b/app/models/Transaction.php index c4a77ee917..bb5c423bec 100644 --- a/app/models/Transaction.php +++ b/app/models/Transaction.php @@ -1,7 +1,7 @@ where('transactions.account_id', $account->id); } /** - * @param Builder $query + * @param EloquentBuilder $query * @param Carbon $date */ - public function scopeAfter(Builder $query, Carbon $date) + public function scopeAfter(EloquentBuilder $query, Carbon $date) { if (is_null($this->joinedJournals)) { $query->leftJoin( @@ -51,10 +51,10 @@ class Transaction extends Eloquent } /** - * @param Builder $query + * @param EloquentBuilder $query * @param Carbon $date */ - public function scopeBefore(Builder $query, Carbon $date) + public function scopeBefore(EloquentBuilder $query, Carbon $date) { if (is_null($this->joinedJournals)) { $query->leftJoin( @@ -66,28 +66,28 @@ class Transaction extends Eloquent } /** - * @param Builder $query + * @param EloquentBuilder $query * @param $amount */ - public function scopeLessThan(Builder $query, $amount) + public function scopeLessThan(EloquentBuilder $query, $amount) { $query->where('amount', '<', $amount); } /** - * @param Builder $query + * @param EloquentBuilder $query * @param $amount */ - public function scopeMoreThan(Builder $query, $amount) + public function scopeMoreThan(EloquentBuilder $query, $amount) { $query->where('amount', '>', $amount); } /** - * @param Builder $query + * @param EloquentBuilder $query * @param array $types */ - public function scopeTransactionTypes(Builder $query, array $types) + public function scopeTransactionTypes(EloquentBuilder $query, array $types) { if (is_null($this->joinedJournals)) { $query->leftJoin( diff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.php index 66aa050a00..e39a8a4c81 100644 --- a/app/models/TransactionJournal.php +++ b/app/models/TransactionJournal.php @@ -1,10 +1,11 @@ 'required|exists:transaction_types,id', 'transaction_currency_id' => 'required|exists:transaction_currencies,id', 'description' => 'required|between:1,255', 'date' => 'required|date', 'completed' => 'required|between:0,1']; - protected $fillable - = ['transaction_type_id', 'transaction_currency_id', 'user_id', - 'description', 'date', 'completed']; + + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + */ + public function bill() + { + return $this->belongsTo('Bill'); + } /** * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany @@ -43,7 +52,6 @@ class TransactionJournal extends Eloquent ); } - /** * TODO remove this method in favour of something in the FireflyIII libraries. * @@ -83,18 +91,10 @@ class TransactionJournal extends Eloquent } /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @param EloquentBuilder $query + * @param Account $account */ - public function bill() - { - return $this->belongsTo('Bill'); - } - - /** - * @param Builder $query - * @param Account $account - */ - public function scopeAccountIs($query, \Account $account) + public function scopeAccountIs(EloquentBuilder $query, \Account $account) { if (!isset($this->joinedTransactions)) { $query->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id'); @@ -104,32 +104,32 @@ class TransactionJournal extends Eloquent } /** - * @param $query - * @param Carbon $date + * @param EloquentBuilder $query + * @param Carbon $date * * @return mixed */ - public function scopeAfter($query, Carbon $date) + public function scopeAfter(EloquentBuilder $query, Carbon $date) { return $query->where('transaction_journals.date', '>=', $date->format('Y-m-d 00:00:00')); } /** - * @param $query - * @param Carbon $date + * @param EloquentBuilder $query + * @param Carbon $date * * @return mixed */ - public function scopeBefore($query, Carbon $date) + public function scopeBefore(EloquentBuilder $query, Carbon $date) { return $query->where('transaction_journals.date', '<=', $date->format('Y-m-d 00:00:00')); } /** - * @param Builder $query - * @param $amount + * @param EloquentBuilder $query + * @param $amount */ - public function scopeLessThan($query, $amount) + public function scopeLessThan(EloquentBuilder $query, $amount) { if (is_null($this->joinedTransactions)) { $query->leftJoin( @@ -142,10 +142,10 @@ class TransactionJournal extends Eloquent } /** - * @param Builder $query - * @param $amount + * @param EloquentBuilder $query + * @param $amount */ - public function scopeMoreThan($query, $amount) + public function scopeMoreThan(EloquentBuilder $query, $amount) { if (is_null($this->joinedTransactions)) { $query->leftJoin( @@ -158,21 +158,21 @@ class TransactionJournal extends Eloquent } /** - * @param $query - * @param Carbon $date + * @param EloquentBuilder $query + * @param Carbon $date * * @return mixed */ - public function scopeOnDate($query, Carbon $date) + public function scopeOnDate(EloquentBuilder $query, Carbon $date) { return $query->where('date', '=', $date->format('Y-m-d')); } /** - * @param Builder $query - * @param array $types + * @param EloquentBuilder $query + * @param array $types */ - public function scopeTransactionTypes($query, array $types) + public function scopeTransactionTypes(EloquentBuilder $query, array $types) { if (is_null($this->joinedTransactionTypes)) { $query->leftJoin( @@ -187,14 +187,14 @@ class TransactionJournal extends Eloquent * Automatically includes the 'with' parameters to get relevant related * objects. * - * @param $query + * @param EloquentBuilder $query */ - public function scopeWithRelevantData($query) + public function scopeWithRelevantData(EloquentBuilder $query) { $query->with( - ['transactions' => function (HasMany $q) { + ['transactions' => function (HasMany $q) { $q->orderBy('amount', 'ASC'); - }, 'transactiontype', 'budgets','categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories'] + }, 'transactiontype', 'budgets', 'categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories'] ); } diff --git a/app/views/accounts/index.blade.php b/app/views/accounts/index.blade.php index 69fb63340e..e837940541 100644 --- a/app/views/accounts/index.blade.php +++ b/app/views/accounts/index.blade.php @@ -30,7 +30,7 @@ @section('scripts') diff --git a/app/views/accounts/show.blade.php b/app/views/accounts/show.blade.php index 87297603f8..e5b4fc9e04 100644 --- a/app/views/accounts/show.blade.php +++ b/app/views/accounts/show.blade.php @@ -52,7 +52,7 @@ diff --git a/app/views/bills/show.blade.php b/app/views/bills/show.blade.php index 023b3dd515..b4ad8d9e1e 100644 --- a/app/views/bills/show.blade.php +++ b/app/views/bills/show.blade.php @@ -42,7 +42,7 @@ @foreach(explode(',',$bill->match) as $word) {{{$word}}} @endforeach - between {{mf($bill->amount_min)}} and {{mf($bill->amount_max)}}. + between {{Amount::format($bill->amount_min)}} and {{Amount::format($bill->amount_max)}}. Repeats {{$bill->repeat_freq}}. @@ -106,7 +106,7 @@ @section('scripts') diff --git a/app/views/budgets/index.blade.php b/app/views/budgets/index.blade.php index 556a6fc6f1..2b5f62be48 100644 --- a/app/views/budgets/index.blade.php +++ b/app/views/budgets/index.blade.php @@ -10,11 +10,11 @@
- Budgeted: {{mf(300)}} + Budgeted: {{Amount::format(300)}}
Income {{\Session::get('start', \Carbon\Carbon::now()->startOfMonth())->format('F Y')}}: - {{mf($amount)}} + {{Amount::format($amount)}}
@@ -29,7 +29,7 @@
- Spent: {{mf($spent)}} + Spent: {{Amount::format($spent)}}
@@ -100,21 +100,21 @@ @if($budget->currentRep->amount > $budget->spent) - {{getCurrencySymbol()}} + {{Amount::getCurrencySymbol()}} @else - {{getCurrencySymbol()}} + {{Amount::getCurrencySymbol()}} @endif @else No budget - + @endif

- Spent: {{mf($budget->spent)}} + Spent: {{Amount::format($budget->spent)}}

diff --git a/app/views/budgets/show.blade.php b/app/views/budgets/show.blade.php index 4b4d983082..b6c35c646d 100644 --- a/app/views/budgets/show.blade.php +++ b/app/views/budgets/show.blade.php @@ -29,10 +29,10 @@
- Amount: {{mf($rep->amount)}} + Amount: {{Amount::format($rep->amount)}}
- Spent: {{mf($rep->spentInRepetition())}} + Spent: {{Amount::format($rep->spentInRepetition())}}
diff --git a/app/views/categories/index.blade.php b/app/views/categories/index.blade.php index e9ed09213e..3c176f36b6 100644 --- a/app/views/categories/index.blade.php +++ b/app/views/categories/index.blade.php @@ -29,7 +29,7 @@ @stop @section('scripts') diff --git a/app/views/categories/show.blade.php b/app/views/categories/show.blade.php index 66e091427d..37fa8d0e2d 100644 --- a/app/views/categories/show.blade.php +++ b/app/views/categories/show.blade.php @@ -32,7 +32,7 @@ diff --git a/app/views/index.blade.php b/app/views/index.blade.php index 68bf2afa13..22520f85b5 100644 --- a/app/views/index.blade.php +++ b/app/views/index.blade.php @@ -114,7 +114,7 @@ @stop @section('scripts') diff --git a/app/views/list/accounts.blade.php b/app/views/list/accounts.blade.php index 4ccf4f36eb..84f88bdfcc 100644 --- a/app/views/list/accounts.blade.php +++ b/app/views/list/accounts.blade.php @@ -17,7 +17,7 @@ {{{$account->name}}} {{{$account->accountRole}}} - {{mf(Steam::balance($account))}} + {{Amount::format(Steam::balance($account))}} @if($account->active) diff --git a/app/views/list/bills.blade.php b/app/views/list/bills.blade.php index 70c7989d84..a603bd9617 100644 --- a/app/views/list/bills.blade.php +++ b/app/views/list/bills.blade.php @@ -27,9 +27,9 @@ @endforeach - {{mf($entry->amount_min)}} + {{Amount::format($entry->amount_min)}} — - {{mf($entry->amount_max)}} + {{Amount::format($entry->amount_max)}} lastFoundMatch();?> diff --git a/app/views/list/journals-full.blade.php b/app/views/list/journals-full.blade.php index e5982e24ae..4979b6a428 100644 --- a/app/views/list/journals-full.blade.php +++ b/app/views/list/journals-full.blade.php @@ -58,13 +58,13 @@ @if($journal->transactiontype->type == 'Withdrawal') - {{mft($journal->transactions[1],false)}} + {{Amount::formatTransaction($journal->transactions[1],false)}} @endif @if($journal->transactiontype->type == 'Deposit') - {{mft($journal->transactions[1],false)}} + {{Amount::formatTransaction($journal->transactions[1],false)}} @endif @if($journal->transactiontype->type == 'Transfer') - {{mft($journal->transactions[1],false)}} + {{Amount::formatTransaction($journal->transactions[1],false)}} @endif diff --git a/app/views/list/journals-small.blade.php b/app/views/list/journals-small.blade.php index 113b4224a7..9bf33f4b0b 100644 --- a/app/views/list/journals-small.blade.php +++ b/app/views/list/journals-small.blade.php @@ -9,13 +9,13 @@ transactions[1]->amount);?> @if($journal->transactiontype->type == 'Withdrawal') - {{mft($journal->transactions[1],false)}} + {{Amount::formatTransaction($journal->transactions[1],false)}} @endif @if($journal->transactiontype->type == 'Deposit') - {{mft($journal->transactions[1],false)}} + {{Amount::formatTransaction($journal->transactions[1],false)}} @endif @if($journal->transactiontype->type == 'Transfer') - {{mft($journal->transactions[1],false)}} + {{Amount::formatTransaction($journal->transactions[1],false)}} @endif @@ -33,7 +33,7 @@ @if(isset($displaySum) && $displaySum === true) Sum - {{mf($tableSum)}} + {{Amount::format($tableSum)}} @endif diff --git a/app/views/list/journals-tiny.blade.php b/app/views/list/journals-tiny.blade.php index c4380ca00c..9987e28ae4 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) - {{mft($t)}} + {{Amount::formatTransaction($t)}} @endif @endforeach @else @foreach($journal->transactions as $index => $t) @if($index == 0) - {{mft($t)}} + {{Amount::formatTransaction($t)}} @endif @endforeach @endif diff --git a/app/views/list/piggy-bank-events.blade.php b/app/views/list/piggy-bank-events.blade.php index bbd39d9798..e7527ed54e 100644 --- a/app/views/list/piggy-bank-events.blade.php +++ b/app/views/list/piggy-bank-events.blade.php @@ -23,9 +23,9 @@ @if($event->amount < 0) - Removed {{mf($event->amount*-1,false)}} + Removed {{Amount::format($event->amount*-1,false)}} @else - Added {{mf($event->amount,false)}} + Added {{Amount::format($event->amount,false)}} @endif diff --git a/app/views/piggy_banks/add.blade.php b/app/views/piggy_banks/add.blade.php index f9680880e7..b9ee7be0d0 100644 --- a/app/views/piggy_banks/add.blade.php +++ b/app/views/piggy_banks/add.blade.php @@ -8,7 +8,7 @@
@@ -109,11 +109,11 @@ @foreach($accounts as $id => $info) {{{$info['name']}}} - {{mf($info['balance'])}} - {{mf($info['leftForPiggyBanks'])}} - {{mf($info['sumOfTargets'])}} - {{mf($info['sumOfSaved'])}} - {{mf($info['leftToSave'])}} + {{Amount::format($info['balance'])}} + {{Amount::format($info['leftForPiggyBanks'])}} + {{Amount::format($info['sumOfTargets'])}} + {{Amount::format($info['sumOfSaved'])}} + {{Amount::format($info['leftToSave'])}} @endforeach diff --git a/app/views/piggy_banks/remove.blade.php b/app/views/piggy_banks/remove.blade.php index 4d157a8287..90129fecc6 100644 --- a/app/views/piggy_banks/remove.blade.php +++ b/app/views/piggy_banks/remove.blade.php @@ -8,7 +8,7 @@
@@ -149,16 +149,16 @@ ?> {{{$account['name']}}} - {{mf($account['startBalance'])}} - {{mf($account['endBalance'])}} - {{mf($account['difference'])}} + {{Amount::format($account['startBalance'])}} + {{Amount::format($account['endBalance'])}} + {{Amount::format($account['difference'])}} @endforeach Sum - {{mf($sumStart)}} - {{mf($sumEnd)}} - {{mf($sumDiff)}} + {{Amount::format($sumStart)}} + {{Amount::format($sumEnd)}} + {{Amount::format($sumDiff)}} diff --git a/app/views/reports/year.blade.php b/app/views/reports/year.blade.php index 10a332bf67..2911af39fa 100644 --- a/app/views/reports/year.blade.php +++ b/app/views/reports/year.blade.php @@ -49,16 +49,16 @@ shared @endif - {{mf($balance['start'])}} - {{mf($balance['end'])}} - {{mf($balance['end']-$balance['start'])}} + {{Amount::format($balance['start'])}} + {{Amount::format($balance['end'])}} + {{Amount::format($balance['end']-$balance['start'])}} @endforeach Sum of sums - {{mf($start)}} - {{mf($end)}} - {{mf($diff)}} + {{Amount::format($start)}} + {{Amount::format($end)}} + {{Amount::format($diff)}} @@ -83,15 +83,15 @@ - + - + - +
In{{mf($incomeSum)}}{{Amount::format($incomeSum)}}
Out{{mf($expenseSum*-1)}}{{Amount::format($expenseSum*-1)}}
Difference{{mf($incomeSum - $expenseSum)}}{{Amount::format($incomeSum - $expenseSum)}}
@@ -107,12 +107,12 @@ sum)*-1;?> {{{$income->name}}} - {{mf(floatval($income->sum)*-1)}} + {{Amount::format(floatval($income->sum)*-1)}} @endforeach Sum - {{mf($sum)}} + {{Amount::format($sum)}} @@ -126,7 +126,7 @@ @foreach($groupedExpenses as $id => $expense) {{{$expense['name']}}} - {{mf(floatval($expense['amount'])*-1)}} + {{Amount::format(floatval($expense['amount'])*-1)}} @endforeach @@ -156,7 +156,7 @@ {{HTML::script('assets/javascript/firefly/reports.js')}} diff --git a/app/views/transactions/show.blade.php b/app/views/transactions/show.blade.php index a6b7446b21..2bdc086cf1 100644 --- a/app/views/transactions/show.blade.php +++ b/app/views/transactions/show.blade.php @@ -74,7 +74,7 @@ {{{$jrnl->description}}} - {{mfj($jrnl, $jrnl->getAmount())}} + {{Amount::formatJournal($jrnl, $jrnl->getAmount())}} @endforeach @@ -97,11 +97,11 @@ - + - + @if(!is_null($t->description)) diff --git a/bootstrap/functions.php b/bootstrap/functions.php index 69c13d834b..b3d9bbc7f3 100644 --- a/bootstrap/functions.php +++ b/bootstrap/functions.php @@ -1,166 +1 @@ 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 '' . $symbol . ' ' . $string . ''; - } - if ($amount > 0) { - return '' . $symbol . ' ' . $string . ''; - } - - return '' . $symbol . ' ' . $string . ''; - } - - // € - 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; - } -} diff --git a/tests/functional/ReminderControllerCest.php b/tests/functional/ReminderControllerCest.php index 01901b2cb5..139e4e279b 100644 --- a/tests/functional/ReminderControllerCest.php +++ b/tests/functional/ReminderControllerCest.php @@ -33,7 +33,7 @@ class ReminderControllerCest ['reminders.*'] ); - $I->wantTo('act on reminder ' . boolstr(is_null($reminder))); + $I->wantTo('act on a reminder'); $I->amOnPage('/reminders/' . $reminder->id . '/act'); $I->see('Money for Nieuwe spullen'); }
Amount{{mft($t)}}{{Amount::formatTransaction($t)}}
New balance{{mf($t->before)}} → {{mf($t->after)}}{{Amount::format($t->before)}} → {{Amount::format($t->after)}}