mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Code cleanup.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ class Form
|
||||
$html .= \Form::input('text', $name, $value, $options);
|
||||
break;
|
||||
case 'amount':
|
||||
$html .= '<div class="input-group"><div class="input-group-addon">' . getCurrencySymbol() . '</div>';
|
||||
$html .= '<div class="input-group"><div class="input-group-addon">' . \Amount::getCurrencySymbol() . '</div>';
|
||||
$html .= \Form::input('number', $name, $value, $options);
|
||||
$html .= '</div>';
|
||||
break;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) . '%');
|
||||
}
|
||||
|
||||
24
app/lib/FireflyIII/Shared/Facade/Amount.php
Normal file
24
app/lib/FireflyIII/Shared/Facade/Amount.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Shared\Facade;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
/**
|
||||
* Class Amount
|
||||
*
|
||||
* @package FireflyIII\Shared\Facade
|
||||
*/
|
||||
class Amount extends Facade
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'amount';
|
||||
}
|
||||
|
||||
}
|
||||
148
app/lib/FireflyIII/Shared/Toolkit/Amount.php
Normal file
148
app/lib/FireflyIII/Shared/Toolkit/Amount.php
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Shared\Toolkit;
|
||||
|
||||
/**
|
||||
* Class Amount
|
||||
*
|
||||
* @package FireflyIII\Shared\Toolkit
|
||||
*/
|
||||
class Amount
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $amount
|
||||
* @param bool $coloured
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format($amount, $coloured = true)
|
||||
{
|
||||
$currencySymbol = $this->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 '<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>';
|
||||
}
|
||||
|
||||
// €
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user