Various code cleanup.

This commit is contained in:
James Cole
2017-09-16 09:24:48 +02:00
parent 3424ec1c27
commit 37250cbde3
18 changed files with 137 additions and 112 deletions

View File

@@ -47,8 +47,8 @@ class Kernel extends ConsoleKernel
* Define the application's command schedule. * Define the application's command schedule.
* *
* @param \Illuminate\Console\Scheduling\Schedule $schedule * @param \Illuminate\Console\Scheduling\Schedule $schedule
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
* @return void * @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/ */
protected function schedule(Schedule $schedule) protected function schedule(Schedule $schedule)
{ {

View File

@@ -57,11 +57,12 @@ class StoredJournalEventHandler
/** /**
* This method connects a new transfer to a piggy bank. * This method connects a new transfer to a piggy bank.
* *
*
*
* @param StoredTransactionJournal $event * @param StoredTransactionJournal $event
* *
* @return bool * @return bool
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/ */
public function connectToPiggyBank(StoredTransactionJournal $event): bool public function connectToPiggyBank(StoredTransactionJournal $event): bool
{ {

View File

@@ -169,7 +169,6 @@ class AttachmentHelper implements AttachmentHelperInterface
// store it: // store it:
$this->uploadDisk->put($attachment->fileName(), $encrypted); $this->uploadDisk->put($attachment->fileName(), $encrypted);
$attachment->uploaded = 1; // update attachment $attachment->uploaded = 1; // update attachment
$attachment->save(); $attachment->save();
$this->attachments->push($attachment); $this->attachments->push($attachment);
@@ -180,8 +179,6 @@ class AttachmentHelper implements AttachmentHelperInterface
// return it. // return it.
return $attachment; return $attachment;
} }
/** /**

View File

@@ -32,6 +32,8 @@ use Steam;
* Class MetaPieChart * Class MetaPieChart
* *
* @package FireflyIII\Helpers\Chart * @package FireflyIII\Helpers\Chart
*
*
*/ */
class MetaPieChart implements MetaPieChartInterface class MetaPieChart implements MetaPieChartInterface
{ {
@@ -83,12 +85,15 @@ class MetaPieChart implements MetaPieChartInterface
* @param string $group * @param string $group
* *
* @return array * @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/ */
public function generate(string $direction, string $group): array public function generate(string $direction, string $group): array
{ {
$transactions = $this->getTransactions($direction); $transactions = $this->getTransactions($direction);
$grouped = $this->groupByFields($transactions, $this->grouping[$group]); $grouped = $this->groupByFields($transactions, $this->grouping[$group]);
$chartData = $this->organizeByType($group, $grouped); $chartData = $this->organizeByType($group, $grouped);
$key = strval(trans('firefly.everything_else'));
// also collect all other transactions // also collect all other transactions
if ($this->collectOtherObjects && $direction === 'expense') { if ($this->collectOtherObjects && $direction === 'expense') {
@@ -96,11 +101,12 @@ class MetaPieChart implements MetaPieChartInterface
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
$collector->setUser($this->user); $collector->setUser($this->user);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]); $collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]);
$journals = $collector->getJournals();
$sum = strval($journals->sum('transaction_amount')); $journals = $collector->getJournals();
$sum = bcmul($sum, '-1'); $sum = strval($journals->sum('transaction_amount'));
$sum = bcsub($sum, $this->total); $sum = bcmul($sum, '-1');
$chartData[strval(trans('firefly.everything_else'))] = $sum; $sum = bcsub($sum, $this->total);
$chartData[$key] = $sum;
} }
if ($this->collectOtherObjects && $direction === 'income') { if ($this->collectOtherObjects && $direction === 'income') {
@@ -108,10 +114,10 @@ class MetaPieChart implements MetaPieChartInterface
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
$collector->setUser($this->user); $collector->setUser($this->user);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::DEPOSIT]); $collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::DEPOSIT]);
$journals = $collector->getJournals(); $journals = $collector->getJournals();
$sum = strval($journals->sum('transaction_amount')); $sum = strval($journals->sum('transaction_amount'));
$sum = bcsub($sum, $this->total); $sum = bcsub($sum, $this->total);
$chartData[strval(trans('firefly.everything_else'))] = $sum; $chartData[$key] = $sum;
} }
return $chartData; return $chartData;
@@ -258,12 +264,9 @@ class MetaPieChart implements MetaPieChartInterface
$collector->removeFilter(TransferFilter::class); $collector->removeFilter(TransferFilter::class);
} }
if ($this->budgets->count() > 0) { $collector->setBudgets($this->budgets);
$collector->setBudgets($this->budgets); $collector->setCategories($this->categories);
}
if ($this->categories->count() > 0) {
$collector->setCategories($this->categories);
}
if ($this->tags->count() > 0) { if ($this->tags->count() > 0) {
$collector->setTags($this->tags); $collector->setTags($this->tags);
$collector->withCategoryInformation(); $collector->withCategoryInformation();
@@ -278,6 +281,9 @@ class MetaPieChart implements MetaPieChartInterface
* @param array $fields * @param array $fields
* *
* @return array * @return array
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/ */
protected function groupByFields(Collection $set, array $fields): array protected function groupByFields(Collection $set, array $fields): array
{ {

View File

@@ -43,6 +43,9 @@ use Steam;
* Class JournalCollector * Class JournalCollector
* *
* @package FireflyIII\Helpers\Collector * @package FireflyIII\Helpers\Collector
*
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/ */
class JournalCollector implements JournalCollectorInterface class JournalCollector implements JournalCollectorInterface
{ {
@@ -413,10 +416,10 @@ class JournalCollector implements JournalCollectorInterface
$this->offset = $offset; $this->offset = $offset;
$this->query->skip($offset); $this->query->skip($offset);
Log::debug(sprintf('Changed offset to %d', $offset)); Log::debug(sprintf('Changed offset to %d', $offset));
return $this;
} }
if (is_null($this->limit)) { Log::debug('The limit is zero, cannot set the page.');
Log::debug('The limit is zero, cannot set the page.');
}
return $this; return $this;
} }

View File

@@ -42,6 +42,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
/** /**
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5. * @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // all the arrays make it long.
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* @param Collection $accounts * @param Collection $accounts

View File

@@ -39,6 +39,7 @@ use View;
* Class AccountController * Class AccountController
* *
* @package FireflyIII\Http\Controllers * @package FireflyIII\Http\Controllers
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/ */
class AccountController extends Controller class AccountController extends Controller
{ {
@@ -141,9 +142,14 @@ class AccountController extends Controller
} }
/** /**
* Edit an account.
*
* @param Request $request * @param Request $request
* @param Account $account * @param Account $account
* *
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // long and complex but not that excessively so.
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @return View * @return View
*/ */
public function edit(Request $request, Account $account) public function edit(Request $request, Account $account)
@@ -237,12 +243,16 @@ class AccountController extends Controller
/** /**
* Show an account.
* @param Request $request * @param Request $request
* @param JournalRepositoryInterface $repository * @param JournalRepositoryInterface $repository
* @param Account $account * @param Account $account
* @param string $moment * @param string $moment
* *
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // long and complex but not that excessively so.
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/ */
public function show(Request $request, JournalRepositoryInterface $repository, Account $account, string $moment = '') public function show(Request $request, JournalRepositoryInterface $repository, Account $account, string $moment = '')
{ {
@@ -389,6 +399,8 @@ class AccountController extends Controller
* @param Account $account The account involved. * @param Account $account The account involved.
* *
* @return Collection * @return Collection
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/ */
private function getPeriodOverview(Account $account): Collection private function getPeriodOverview(Account $account): Collection
{ {
@@ -419,17 +431,13 @@ class AccountController extends Controller
// try a collector for income: // try a collector for income:
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd) $collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd)->setTypes([TransactionType::DEPOSIT])->withOpposingAccount();
->setTypes([TransactionType::DEPOSIT])
->withOpposingAccount();
$earned = strval($collector->getJournals()->sum('transaction_amount')); $earned = strval($collector->getJournals()->sum('transaction_amount'));
// try a collector for expenses: // try a collector for expenses:
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd) $collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd)->setTypes([TransactionType::WITHDRAWAL])->withOpposingAccount();
->setTypes([TransactionType::WITHDRAWAL])
->withOpposingAccount();
$spent = strval($collector->getJournals()->sum('transaction_amount')); $spent = strval($collector->getJournals()->sum('transaction_amount'));
$dateStr = $end->format('Y-m-d'); $dateStr = $end->format('Y-m-d');
$dateName = Navigation::periodShow($end, $range); $dateName = Navigation::periodShow($end, $range);

View File

@@ -34,6 +34,8 @@ class TwoFactorController extends Controller
* *
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
* @throws FireflyException * @throws FireflyException
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/ */
public function index(Request $request) public function index(Request $request)
{ {

View File

@@ -40,6 +40,7 @@ use View;
* Class BudgetController * Class BudgetController
* *
* @package FireflyIII\Http\Controllers * @package FireflyIII\Http\Controllers
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/ */
class BudgetController extends Controller class BudgetController extends Controller
{ {
@@ -168,6 +169,9 @@ class BudgetController extends Controller
* @param string|null $moment * @param string|null $moment
* *
* @return View * @return View
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity) complex because of while loop
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/ */
public function index(string $moment = null) public function index(string $moment = null)
{ {
@@ -182,7 +186,6 @@ class BudgetController extends Controller
$end = Navigation::endOfPeriod($start, $range); $end = Navigation::endOfPeriod($start, $range);
} catch (Exception $e) { } catch (Exception $e) {
// start and end are already defined. // start and end are already defined.
} }
} }
$next = clone $end; $next = clone $end;
@@ -190,11 +193,7 @@ class BudgetController extends Controller
$prev = clone $start; $prev = clone $start;
$prev->subDay(); $prev->subDay();
$prev = Navigation::startOfPeriod($prev, $range); $prev = Navigation::startOfPeriod($prev, $range);
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
$budgets = $this->repository->getActiveBudgets(); $budgets = $this->repository->getActiveBudgets();
$inactive = $this->repository->getInactiveBudgets(); $inactive = $this->repository->getInactiveBudgets();
$periodStart = $start->formatLocalized($this->monthAndDayFormat); $periodStart = $start->formatLocalized($this->monthAndDayFormat);
@@ -252,6 +251,9 @@ class BudgetController extends Controller
* @param string $moment * @param string $moment
* *
* @return View * @return View
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/ */
public function noBudget(Request $request, JournalRepositoryInterface $repository, string $moment = '') public function noBudget(Request $request, JournalRepositoryInterface $repository, string $moment = '')
{ {
@@ -461,6 +463,7 @@ class BudgetController extends Controller
* @param Carbon $end * @param Carbon $end
* *
* @return array * @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/ */
private function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array private function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array
{ {

View File

@@ -129,9 +129,9 @@ class HomeController extends Controller
/** @var Carbon $start */ /** @var Carbon $start */
$start = session('start', Carbon::now()->startOfMonth()); $start = session('start', Carbon::now()->startOfMonth());
/** @var Carbon $end */ /** @var Carbon $end */
$end = session('end', Carbon::now()->endOfMonth()); $end = session('end', Carbon::now()->endOfMonth());
$accounts = $repository->getAccountsById($frontPage->data); $accounts = $repository->getAccountsById($frontPage->data);
$showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data; $showDeps = Preferences::get('showDepositsFrontpage', false)->data;
// zero bills? Hide some elements from view. // zero bills? Hide some elements from view.
/** @var BillRepositoryInterface $billRepository */ /** @var BillRepositoryInterface $billRepository */
@@ -146,7 +146,7 @@ class HomeController extends Controller
} }
return view( return view(
'index', compact('count', 'subTitle', 'transactions', 'showDepositsFrontpage', 'billCount') 'index', compact('count', 'subTitle', 'transactions', 'showDeps', 'billCount')
); );
} }

View File

@@ -85,27 +85,27 @@ class PreferencesController extends Controller
*/ */
public function index(AccountRepositoryInterface $repository) public function index(AccountRepositoryInterface $repository)
{ {
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]); $accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
$viewRangePref = Preferences::get('viewRange', '1M'); $viewRangePref = Preferences::get('viewRange', '1M');
$viewRange = $viewRangePref->data; $viewRange = $viewRangePref->data;
$frontPageAccounts = Preferences::get('frontPageAccounts', []); $frontPageAccounts = Preferences::get('frontPageAccounts', []);
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data; $language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
$transactionPageSize = Preferences::get('transactionPageSize', 50)->data; $transactionPageSize = Preferences::get('transactionPageSize', 50)->data;
$customFiscalYear = Preferences::get('customFiscalYear', 0)->data; $customFiscalYear = Preferences::get('customFiscalYear', 0)->data;
$showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data; $showDeps = Preferences::get('showDepositsFrontpage', false)->data;
$fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data; $fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
$fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr; $fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr;
$tjOptionalFields = Preferences::get('transaction_journal_optional_fields', [])->data; $tjOptionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
$is2faEnabled = Preferences::get('twoFactorAuthEnabled', 0)->data; // twoFactorAuthEnabled $is2faEnabled = Preferences::get('twoFactorAuthEnabled', 0)->data; // twoFactorAuthEnabled
$has2faSecret = !is_null(Preferences::get('twoFactorAuthSecret')); // hasTwoFactorAuthSecret $has2faSecret = !is_null(Preferences::get('twoFactorAuthSecret')); // hasTwoFactorAuthSecret
$showIncomplete = env('SHOW_INCOMPLETE_TRANSLATIONS', false) === true; $showIncomplete = env('SHOW_INCOMPLETE_TRANSLATIONS', false) === true;
return view( return view(
'preferences.index', 'preferences.index',
compact( compact(
'language', 'accounts', 'frontPageAccounts', 'tjOptionalFields', 'language', 'accounts', 'frontPageAccounts', 'tjOptionalFields',
'viewRange', 'customFiscalYear', 'transactionPageSize', 'fiscalYearStart', 'is2faEnabled', 'viewRange', 'customFiscalYear', 'transactionPageSize', 'fiscalYearStart', 'is2faEnabled',
'has2faSecret', 'showIncomplete', 'showDepositsFrontpage' 'has2faSecret', 'showIncomplete', 'showDeps'
) )
); );
} }

View File

@@ -23,13 +23,15 @@ use Watson\Validating\ValidatingTrait;
* Class Transaction * Class Transaction
* *
* @property-read int $journal_id * @property-read int $journal_id
* @property-read Carbon $date * @property Carbon $date
* @property-read string $transaction_description * @property-read string $transaction_description
* @property-read string $transaction_amount * @property string $transaction_amount
* @property-read string $transaction_foreign_amount * @property string $transaction_foreign_amount
* @property-read string $transaction_type_type * @property string $transaction_type_type
* @property string $foreign_currency_symbol
* @property int $foreign_currency_dp
* *
* @property int $account_id * @property int $account_id
* @property-read string $account_name * @property-read string $account_name
* @property string $account_iban * @property string $account_iban
* @property string $account_number * @property string $account_number

View File

@@ -55,11 +55,11 @@ class Amount
// there are five possible positions for the "+" or "-" sign (if it is even used) // there are five possible positions for the "+" or "-" sign (if it is even used)
// pos_a and pos_e could be the ( and ) symbol. // pos_a and pos_e could be the ( and ) symbol.
$pos_a = ''; // before everything $posA = ''; // before everything
$pos_b = ''; // before currency symbol $posB = ''; // before currency symbol
$pos_c = ''; // after currency symbol $posC = ''; // after currency symbol
$pos_d = ''; // before amount $posD = ''; // before amount
$pos_e = ''; // after everything $posE = ''; // after everything
// format would be (currency before amount) // format would be (currency before amount)
// AB%sC_D%vE // AB%sC_D%vE
@@ -73,32 +73,32 @@ class Amount
default: default:
case 0: case 0:
// ( and ) around the whole thing // ( and ) around the whole thing
$pos_a = '('; $posA = '(';
$pos_e = ')'; $posE = ')';
break; break;
case 1: case 1:
// The sign string precedes the quantity and currency_symbol // The sign string precedes the quantity and currency_symbol
$pos_a = $sign; $posA = $sign;
break; break;
case 2: case 2:
// The sign string succeeds the quantity and currency_symbol // The sign string succeeds the quantity and currency_symbol
$pos_e = $sign; $posE = $sign;
break; break;
case 3: case 3:
// The sign string immediately precedes the currency_symbol // The sign string immediately precedes the currency_symbol
$pos_b = $sign; $posB = $sign;
break; break;
case 4: case 4:
// The sign string immediately succeeds the currency_symbol // The sign string immediately succeeds the currency_symbol
$pos_c = $sign; $posC = $sign;
} }
// default is amount before currency // default is amount before currency
$format = $pos_a . $pos_d . '%v' . $space . $pos_b . '%s' . $pos_c . $pos_e; $format = $posA . $posD . '%v' . $space . $posB . '%s' . $posC . $posE;
if ($csPrecedes) { if ($csPrecedes) {
// alternative is currency before amount // alternative is currency before amount
$format = $pos_a . $pos_b . '%s' . $pos_c . $space . $pos_d . '%v' . $pos_e; $format = $posA . $posB . '%s' . $posC . $space . $posD . '%v' . $posE;
} }
return $format; return $format;

View File

@@ -258,10 +258,10 @@ class BunqPrerequisites implements PrerequisitesInterface
if ($response->status_code !== 200) { if ($response->status_code !== 200) {
throw new FireflyException(sprintf('Could not retrieve external IP: %d %s', $response->status_code, $response->body)); throw new FireflyException(sprintf('Could not retrieve external IP: %d %s', $response->status_code, $response->body));
} }
$ip = $response->body; $serverIp = $response->body;
Preferences::setForUser($this->user, 'external_ip', $ip); Preferences::setForUser($this->user, 'external_ip', $serverIp);
return $ip; return $serverIp;
} }
return $preference->data; return $preference->data;

View File

@@ -204,8 +204,8 @@ class Search implements SearchInterface
// first "modifier" is always the text of the search: // first "modifier" is always the text of the search:
// check descr of journal: // check descr of journal:
if (count($this->words) > 0 if (count($this->words) > 0
&& !$this->strpos_arr(strtolower(strval($transaction->description)), $this->words) && !$this->strposArray(strtolower(strval($transaction->description)), $this->words)
&& !$this->strpos_arr(strtolower(strval($transaction->transaction_description)), $this->words) && !$this->strposArray(strtolower(strval($transaction->transaction_description)), $this->words)
) { ) {
Log::debug('Description does not match', $this->words); Log::debug('Description does not match', $this->words);
@@ -230,7 +230,7 @@ class Search implements SearchInterface
* *
* @return bool * @return bool
*/ */
private function strpos_arr(string $haystack, array $needle) private function strposArray(string $haystack, array $needle)
{ {
if (strlen($haystack) === 0) { if (strlen($haystack) === 0) {
return false; return false;

View File

@@ -119,16 +119,15 @@ class Transaction extends Twig_Extension
return new Twig_SimpleFunction( return new Twig_SimpleFunction(
'transactionDestinationAccount', function (TransactionModel $transaction): string { 'transactionDestinationAccount', function (TransactionModel $transaction): string {
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name); $name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
$id = intval($transaction->account_id); $transactionId = intval($transaction->account_id);
$type = $transaction->account_type; $type = $transaction->account_type;
// name is present in object, use that one: // name is present in object, use that one:
if (bccomp($transaction->transaction_amount, '0') === -1 && !is_null($transaction->opposing_account_id)) { if (bccomp($transaction->transaction_amount, '0') === -1 && !is_null($transaction->opposing_account_id)) {
$name = $transaction->opposing_account_name;
$name = $transaction->opposing_account_name; $transactionId = intval($transaction->opposing_account_id);
$id = intval($transaction->opposing_account_id); $type = $transaction->opposing_account_type;
$type = $transaction->opposing_account_type;
} }
// Find the opposing account and use that one: // Find the opposing account and use that one:
@@ -136,21 +135,23 @@ class Transaction extends Twig_Extension
// if the amount is negative, find the opposing account and use that one: // if the amount is negative, find the opposing account and use that one:
$journalId = $transaction->journal_id; $journalId = $transaction->journal_id;
/** @var TransactionModel $other */ /** @var TransactionModel $other */
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id) $other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where('identifier', $transaction->identifier) ->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where(
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') 'identifier', $transaction->identifier
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') )
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']); ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
$name = Steam::decrypt(intval($other->encrypted), $other->name); ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
$id = $other->account_id; ->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
$type = $other->type; $name = Steam::decrypt(intval($other->encrypted), $other->name);
$transactionId = $other->account_id;
$type = $other->type;
} }
if ($type === AccountType::CASH) { if ($type === AccountType::CASH) {
return '<span class="text-success">(cash)</span>'; return '<span class="text-success">(cash)</span>';
} }
return sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($name), route('accounts.show', [$id])); return sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($name), route('accounts.show', [$transactionId]));
}, ['is_safe' => ['html']] }, ['is_safe' => ['html']]
); );
@@ -193,36 +194,37 @@ class Transaction extends Twig_Extension
'transactionSourceAccount', function (TransactionModel $transaction): string { 'transactionSourceAccount', function (TransactionModel $transaction): string {
// if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account. // if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account.
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name); $name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
$id = intval($transaction->account_id); $transactionId = intval($transaction->account_id);
$type = $transaction->account_type; $type = $transaction->account_type;
// name is present in object, use that one: // name is present in object, use that one:
if (bccomp($transaction->transaction_amount, '0') === 1 && !is_null($transaction->opposing_account_id)) { if (bccomp($transaction->transaction_amount, '0') === 1 && !is_null($transaction->opposing_account_id)) {
$name = $transaction->opposing_account_name;
$name = $transaction->opposing_account_name; $transactionId = intval($transaction->opposing_account_id);
$id = intval($transaction->opposing_account_id); $type = $transaction->opposing_account_type;
$type = $transaction->opposing_account_type;
} }
// Find the opposing account and use that one: // Find the opposing account and use that one:
if (bccomp($transaction->transaction_amount, '0') === 1 && is_null($transaction->opposing_account_id)) { if (bccomp($transaction->transaction_amount, '0') === 1 && is_null($transaction->opposing_account_id)) {
$journalId = $transaction->journal_id; $journalId = $transaction->journal_id;
/** @var TransactionModel $other */ /** @var TransactionModel $other */
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id) $other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where('identifier', $transaction->identifier) ->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where(
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') 'identifier', $transaction->identifier
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id') )
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']); ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
$name = Steam::decrypt(intval($other->encrypted), $other->name); ->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
$id = $other->account_id; ->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
$type = $other->type; $name = Steam::decrypt(intval($other->encrypted), $other->name);
$transactionId = $other->account_id;
$type = $other->type;
} }
if ($type === AccountType::CASH) { if ($type === AccountType::CASH) {
return '<span class="text-success">(cash)</span>'; return '<span class="text-success">(cash)</span>';
} }
return sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($name), route('accounts.show', [$id])); return sprintf('<a title="%1$s" href="%2$s">%1$s</a>', e($name), route('accounts.show', [$transactionId]));
}, ['is_safe' => ['html']] }, ['is_safe' => ['html']]
); );

View File

@@ -115,7 +115,7 @@
</div> </div>
</div> </div>
{# OPTIONAL REVENUE ACCOUNTS #} {# OPTIONAL REVENUE ACCOUNTS #}
{% if showDepositsFrontpage %} {% if showDeps %}
<div class="box"> <div class="box">
<div class="box-header with-border"> <div class="box-header with-border">
<h3 class="box-title">{{ 'revenue_accounts'|_ }}</h3> <h3 class="box-title">{{ 'revenue_accounts'|_ }}</h3>

View File

@@ -128,7 +128,7 @@
<div class="col-sm-10"> <div class="col-sm-10">
<div class="checkbox"> <div class="checkbox">
<label> <label>
<input type="checkbox" name="showDepositsFrontpage[]" value="{{ showDepositsFrontpage }}" <input type="checkbox" name="showDepositsFrontpage[]" value="{{ showDeps }}"
{% if showDepositsFrontpage %} {% if showDepositsFrontpage %}
checked checked
{% endif %} {% endif %}