mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-14 17:33:43 -06:00
Various code cleanup.
This commit is contained in:
parent
3424ec1c27
commit
37250cbde3
@ -47,8 +47,8 @@ class Kernel extends ConsoleKernel
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
|
@ -57,11 +57,12 @@ class StoredJournalEventHandler
|
||||
/**
|
||||
* This method connects a new transfer to a piggy bank.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param StoredTransactionJournal $event
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function connectToPiggyBank(StoredTransactionJournal $event): bool
|
||||
{
|
||||
|
@ -169,7 +169,6 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
|
||||
// store it:
|
||||
$this->uploadDisk->put($attachment->fileName(), $encrypted);
|
||||
|
||||
$attachment->uploaded = 1; // update attachment
|
||||
$attachment->save();
|
||||
$this->attachments->push($attachment);
|
||||
@ -180,8 +179,6 @@ class AttachmentHelper implements AttachmentHelperInterface
|
||||
|
||||
// return it.
|
||||
return $attachment;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -32,6 +32,8 @@ use Steam;
|
||||
* Class MetaPieChart
|
||||
*
|
||||
* @package FireflyIII\Helpers\Chart
|
||||
*
|
||||
*
|
||||
*/
|
||||
class MetaPieChart implements MetaPieChartInterface
|
||||
{
|
||||
@ -83,12 +85,15 @@ class MetaPieChart implements MetaPieChartInterface
|
||||
* @param string $group
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function generate(string $direction, string $group): array
|
||||
{
|
||||
$transactions = $this->getTransactions($direction);
|
||||
$grouped = $this->groupByFields($transactions, $this->grouping[$group]);
|
||||
$chartData = $this->organizeByType($group, $grouped);
|
||||
$key = strval(trans('firefly.everything_else'));
|
||||
|
||||
// also collect all other transactions
|
||||
if ($this->collectOtherObjects && $direction === 'expense') {
|
||||
@ -96,11 +101,12 @@ class MetaPieChart implements MetaPieChartInterface
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::WITHDRAWAL]);
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcmul($sum, '-1');
|
||||
$sum = bcsub($sum, $this->total);
|
||||
$chartData[strval(trans('firefly.everything_else'))] = $sum;
|
||||
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcmul($sum, '-1');
|
||||
$sum = bcsub($sum, $this->total);
|
||||
$chartData[$key] = $sum;
|
||||
}
|
||||
|
||||
if ($this->collectOtherObjects && $direction === 'income') {
|
||||
@ -108,10 +114,10 @@ class MetaPieChart implements MetaPieChartInterface
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser($this->user);
|
||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)->setTypes([TransactionType::DEPOSIT]);
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcsub($sum, $this->total);
|
||||
$chartData[strval(trans('firefly.everything_else'))] = $sum;
|
||||
$journals = $collector->getJournals();
|
||||
$sum = strval($journals->sum('transaction_amount'));
|
||||
$sum = bcsub($sum, $this->total);
|
||||
$chartData[$key] = $sum;
|
||||
}
|
||||
|
||||
return $chartData;
|
||||
@ -258,12 +264,9 @@ class MetaPieChart implements MetaPieChartInterface
|
||||
$collector->removeFilter(TransferFilter::class);
|
||||
}
|
||||
|
||||
if ($this->budgets->count() > 0) {
|
||||
$collector->setBudgets($this->budgets);
|
||||
}
|
||||
if ($this->categories->count() > 0) {
|
||||
$collector->setCategories($this->categories);
|
||||
}
|
||||
$collector->setBudgets($this->budgets);
|
||||
$collector->setCategories($this->categories);
|
||||
|
||||
if ($this->tags->count() > 0) {
|
||||
$collector->setTags($this->tags);
|
||||
$collector->withCategoryInformation();
|
||||
@ -278,6 +281,9 @@ class MetaPieChart implements MetaPieChartInterface
|
||||
* @param array $fields
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*
|
||||
*/
|
||||
protected function groupByFields(Collection $set, array $fields): array
|
||||
{
|
||||
|
@ -43,6 +43,9 @@ use Steam;
|
||||
* Class JournalCollector
|
||||
*
|
||||
* @package FireflyIII\Helpers\Collector
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class JournalCollector implements JournalCollectorInterface
|
||||
{
|
||||
@ -413,10 +416,10 @@ class JournalCollector implements JournalCollectorInterface
|
||||
$this->offset = $offset;
|
||||
$this->query->skip($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;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ class BudgetReportHelper implements BudgetReportHelperInterface
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly 5.
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // all the arrays make it long.
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
|
@ -39,6 +39,7 @@ use View;
|
||||
* Class AccountController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class AccountController extends Controller
|
||||
{
|
||||
@ -141,9 +142,14 @@ class AccountController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit an account.
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Account $account
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // long and complex but not that excessively so.
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function edit(Request $request, Account $account)
|
||||
@ -237,12 +243,16 @@ class AccountController extends Controller
|
||||
|
||||
|
||||
/**
|
||||
* Show an account.
|
||||
* @param Request $request
|
||||
* @param JournalRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
* @param string $moment
|
||||
*
|
||||
* @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 = '')
|
||||
{
|
||||
@ -389,6 +399,8 @@ class AccountController extends Controller
|
||||
* @param Account $account The account involved.
|
||||
*
|
||||
* @return Collection
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
private function getPeriodOverview(Account $account): Collection
|
||||
{
|
||||
@ -419,17 +431,13 @@ class AccountController extends Controller
|
||||
// try a collector for income:
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd)
|
||||
->setTypes([TransactionType::DEPOSIT])
|
||||
->withOpposingAccount();
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd)->setTypes([TransactionType::DEPOSIT])->withOpposingAccount();
|
||||
$earned = strval($collector->getJournals()->sum('transaction_amount'));
|
||||
|
||||
// try a collector for expenses:
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd)
|
||||
->setTypes([TransactionType::WITHDRAWAL])
|
||||
->withOpposingAccount();
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($end, $currentEnd)->setTypes([TransactionType::WITHDRAWAL])->withOpposingAccount();
|
||||
$spent = strval($collector->getJournals()->sum('transaction_amount'));
|
||||
$dateStr = $end->format('Y-m-d');
|
||||
$dateName = Navigation::periodShow($end, $range);
|
||||
|
@ -34,6 +34,8 @@ class TwoFactorController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
@ -40,6 +40,7 @@ use View;
|
||||
* Class BudgetController
|
||||
*
|
||||
* @package FireflyIII\Http\Controllers
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class BudgetController extends Controller
|
||||
{
|
||||
@ -168,6 +169,9 @@ class BudgetController extends Controller
|
||||
* @param string|null $moment
|
||||
*
|
||||
* @return View
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) complex because of while loop
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function index(string $moment = null)
|
||||
{
|
||||
@ -182,7 +186,6 @@ class BudgetController extends Controller
|
||||
$end = Navigation::endOfPeriod($start, $range);
|
||||
} catch (Exception $e) {
|
||||
// start and end are already defined.
|
||||
|
||||
}
|
||||
}
|
||||
$next = clone $end;
|
||||
@ -190,11 +193,7 @@ class BudgetController extends Controller
|
||||
$prev = clone $start;
|
||||
$prev->subDay();
|
||||
$prev = Navigation::startOfPeriod($prev, $range);
|
||||
|
||||
|
||||
$this->repository->cleanupBudgets();
|
||||
|
||||
|
||||
$budgets = $this->repository->getActiveBudgets();
|
||||
$inactive = $this->repository->getInactiveBudgets();
|
||||
$periodStart = $start->formatLocalized($this->monthAndDayFormat);
|
||||
@ -252,6 +251,9 @@ class BudgetController extends Controller
|
||||
* @param string $moment
|
||||
*
|
||||
* @return View
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function noBudget(Request $request, JournalRepositoryInterface $repository, string $moment = '')
|
||||
{
|
||||
@ -461,6 +463,7 @@ class BudgetController extends Controller
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return array
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
private function collectBudgetInformation(Collection $budgets, Carbon $start, Carbon $end): array
|
||||
{
|
||||
|
@ -129,9 +129,9 @@ class HomeController extends Controller
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$accounts = $repository->getAccountsById($frontPage->data);
|
||||
$showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data;
|
||||
$end = session('end', Carbon::now()->endOfMonth());
|
||||
$accounts = $repository->getAccountsById($frontPage->data);
|
||||
$showDeps = Preferences::get('showDepositsFrontpage', false)->data;
|
||||
|
||||
// zero bills? Hide some elements from view.
|
||||
/** @var BillRepositoryInterface $billRepository */
|
||||
@ -146,7 +146,7 @@ class HomeController extends Controller
|
||||
}
|
||||
|
||||
return view(
|
||||
'index', compact('count', 'subTitle', 'transactions', 'showDepositsFrontpage', 'billCount')
|
||||
'index', compact('count', 'subTitle', 'transactions', 'showDeps', 'billCount')
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -85,27 +85,27 @@ class PreferencesController extends Controller
|
||||
*/
|
||||
public function index(AccountRepositoryInterface $repository)
|
||||
{
|
||||
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$viewRangePref = Preferences::get('viewRange', '1M');
|
||||
$viewRange = $viewRangePref->data;
|
||||
$frontPageAccounts = Preferences::get('frontPageAccounts', []);
|
||||
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$transactionPageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||
$customFiscalYear = Preferences::get('customFiscalYear', 0)->data;
|
||||
$showDepositsFrontpage = Preferences::get('showDepositsFrontpage', false)->data;
|
||||
$fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
|
||||
$fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr;
|
||||
$tjOptionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$is2faEnabled = Preferences::get('twoFactorAuthEnabled', 0)->data; // twoFactorAuthEnabled
|
||||
$has2faSecret = !is_null(Preferences::get('twoFactorAuthSecret')); // hasTwoFactorAuthSecret
|
||||
$showIncomplete = env('SHOW_INCOMPLETE_TRANSLATIONS', false) === true;
|
||||
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
|
||||
$viewRangePref = Preferences::get('viewRange', '1M');
|
||||
$viewRange = $viewRangePref->data;
|
||||
$frontPageAccounts = Preferences::get('frontPageAccounts', []);
|
||||
$language = Preferences::get('language', config('firefly.default_language', 'en_US'))->data;
|
||||
$transactionPageSize = Preferences::get('transactionPageSize', 50)->data;
|
||||
$customFiscalYear = Preferences::get('customFiscalYear', 0)->data;
|
||||
$showDeps = Preferences::get('showDepositsFrontpage', false)->data;
|
||||
$fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
|
||||
$fiscalYearStart = date('Y') . '-' . $fiscalYearStartStr;
|
||||
$tjOptionalFields = Preferences::get('transaction_journal_optional_fields', [])->data;
|
||||
$is2faEnabled = Preferences::get('twoFactorAuthEnabled', 0)->data; // twoFactorAuthEnabled
|
||||
$has2faSecret = !is_null(Preferences::get('twoFactorAuthSecret')); // hasTwoFactorAuthSecret
|
||||
$showIncomplete = env('SHOW_INCOMPLETE_TRANSLATIONS', false) === true;
|
||||
|
||||
return view(
|
||||
'preferences.index',
|
||||
compact(
|
||||
'language', 'accounts', 'frontPageAccounts', 'tjOptionalFields',
|
||||
'viewRange', 'customFiscalYear', 'transactionPageSize', 'fiscalYearStart', 'is2faEnabled',
|
||||
'has2faSecret', 'showIncomplete', 'showDepositsFrontpage'
|
||||
'has2faSecret', 'showIncomplete', 'showDeps'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -23,13 +23,15 @@ use Watson\Validating\ValidatingTrait;
|
||||
* Class Transaction
|
||||
*
|
||||
* @property-read int $journal_id
|
||||
* @property-read Carbon $date
|
||||
* @property Carbon $date
|
||||
* @property-read string $transaction_description
|
||||
* @property-read string $transaction_amount
|
||||
* @property-read string $transaction_foreign_amount
|
||||
* @property-read string $transaction_type_type
|
||||
* @property string $transaction_amount
|
||||
* @property string $transaction_foreign_amount
|
||||
* @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 string $account_iban
|
||||
* @property string $account_number
|
||||
|
@ -55,11 +55,11 @@ class Amount
|
||||
|
||||
// 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 = ''; // before everything
|
||||
$pos_b = ''; // before currency symbol
|
||||
$pos_c = ''; // after currency symbol
|
||||
$pos_d = ''; // before amount
|
||||
$pos_e = ''; // after everything
|
||||
$posA = ''; // before everything
|
||||
$posB = ''; // before currency symbol
|
||||
$posC = ''; // after currency symbol
|
||||
$posD = ''; // before amount
|
||||
$posE = ''; // after everything
|
||||
|
||||
// format would be (currency before amount)
|
||||
// AB%sC_D%vE
|
||||
@ -73,32 +73,32 @@ class Amount
|
||||
default:
|
||||
case 0:
|
||||
// ( and ) around the whole thing
|
||||
$pos_a = '(';
|
||||
$pos_e = ')';
|
||||
$posA = '(';
|
||||
$posE = ')';
|
||||
break;
|
||||
case 1:
|
||||
// The sign string precedes the quantity and currency_symbol
|
||||
$pos_a = $sign;
|
||||
$posA = $sign;
|
||||
break;
|
||||
case 2:
|
||||
// The sign string succeeds the quantity and currency_symbol
|
||||
$pos_e = $sign;
|
||||
$posE = $sign;
|
||||
break;
|
||||
case 3:
|
||||
// The sign string immediately precedes the currency_symbol
|
||||
$pos_b = $sign;
|
||||
$posB = $sign;
|
||||
break;
|
||||
case 4:
|
||||
// The sign string immediately succeeds the currency_symbol
|
||||
$pos_c = $sign;
|
||||
$posC = $sign;
|
||||
}
|
||||
|
||||
// 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) {
|
||||
// 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;
|
||||
|
@ -258,10 +258,10 @@ class BunqPrerequisites implements PrerequisitesInterface
|
||||
if ($response->status_code !== 200) {
|
||||
throw new FireflyException(sprintf('Could not retrieve external IP: %d %s', $response->status_code, $response->body));
|
||||
}
|
||||
$ip = $response->body;
|
||||
Preferences::setForUser($this->user, 'external_ip', $ip);
|
||||
$serverIp = $response->body;
|
||||
Preferences::setForUser($this->user, 'external_ip', $serverIp);
|
||||
|
||||
return $ip;
|
||||
return $serverIp;
|
||||
}
|
||||
|
||||
return $preference->data;
|
||||
|
@ -204,8 +204,8 @@ class Search implements SearchInterface
|
||||
// first "modifier" is always the text of the search:
|
||||
// check descr of journal:
|
||||
if (count($this->words) > 0
|
||||
&& !$this->strpos_arr(strtolower(strval($transaction->description)), $this->words)
|
||||
&& !$this->strpos_arr(strtolower(strval($transaction->transaction_description)), $this->words)
|
||||
&& !$this->strposArray(strtolower(strval($transaction->description)), $this->words)
|
||||
&& !$this->strposArray(strtolower(strval($transaction->transaction_description)), $this->words)
|
||||
) {
|
||||
Log::debug('Description does not match', $this->words);
|
||||
|
||||
@ -230,7 +230,7 @@ class Search implements SearchInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function strpos_arr(string $haystack, array $needle)
|
||||
private function strposArray(string $haystack, array $needle)
|
||||
{
|
||||
if (strlen($haystack) === 0) {
|
||||
return false;
|
||||
|
@ -119,16 +119,15 @@ class Transaction extends Twig_Extension
|
||||
return new Twig_SimpleFunction(
|
||||
'transactionDestinationAccount', function (TransactionModel $transaction): string {
|
||||
|
||||
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
|
||||
$id = intval($transaction->account_id);
|
||||
$type = $transaction->account_type;
|
||||
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
|
||||
$transactionId = intval($transaction->account_id);
|
||||
$type = $transaction->account_type;
|
||||
|
||||
// name is present in object, use that one:
|
||||
if (bccomp($transaction->transaction_amount, '0') === -1 && !is_null($transaction->opposing_account_id)) {
|
||||
|
||||
$name = $transaction->opposing_account_name;
|
||||
$id = intval($transaction->opposing_account_id);
|
||||
$type = $transaction->opposing_account_type;
|
||||
$name = $transaction->opposing_account_name;
|
||||
$transactionId = intval($transaction->opposing_account_id);
|
||||
$type = $transaction->opposing_account_type;
|
||||
}
|
||||
|
||||
// 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:
|
||||
$journalId = $transaction->journal_id;
|
||||
/** @var TransactionModel $other */
|
||||
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
|
||||
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where('identifier', $transaction->identifier)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||
$name = Steam::decrypt(intval($other->encrypted), $other->name);
|
||||
$id = $other->account_id;
|
||||
$type = $other->type;
|
||||
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
|
||||
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where(
|
||||
'identifier', $transaction->identifier
|
||||
)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||
$name = Steam::decrypt(intval($other->encrypted), $other->name);
|
||||
$transactionId = $other->account_id;
|
||||
$type = $other->type;
|
||||
}
|
||||
|
||||
if ($type === AccountType::CASH) {
|
||||
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']]
|
||||
);
|
||||
@ -193,36 +194,37 @@ class Transaction extends Twig_Extension
|
||||
'transactionSourceAccount', function (TransactionModel $transaction): string {
|
||||
|
||||
// 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);
|
||||
$id = intval($transaction->account_id);
|
||||
$type = $transaction->account_type;
|
||||
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
|
||||
$transactionId = intval($transaction->account_id);
|
||||
$type = $transaction->account_type;
|
||||
|
||||
// name is present in object, use that one:
|
||||
if (bccomp($transaction->transaction_amount, '0') === 1 && !is_null($transaction->opposing_account_id)) {
|
||||
|
||||
$name = $transaction->opposing_account_name;
|
||||
$id = intval($transaction->opposing_account_id);
|
||||
$type = $transaction->opposing_account_type;
|
||||
$name = $transaction->opposing_account_name;
|
||||
$transactionId = intval($transaction->opposing_account_id);
|
||||
$type = $transaction->opposing_account_type;
|
||||
}
|
||||
// Find the opposing account and use that one:
|
||||
if (bccomp($transaction->transaction_amount, '0') === 1 && is_null($transaction->opposing_account_id)) {
|
||||
$journalId = $transaction->journal_id;
|
||||
/** @var TransactionModel $other */
|
||||
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
|
||||
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where('identifier', $transaction->identifier)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||
$name = Steam::decrypt(intval($other->encrypted), $other->name);
|
||||
$id = $other->account_id;
|
||||
$type = $other->type;
|
||||
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
|
||||
->where('amount', '=', bcmul($transaction->transaction_amount, '-1'))->where(
|
||||
'identifier', $transaction->identifier
|
||||
)
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
|
||||
$name = Steam::decrypt(intval($other->encrypted), $other->name);
|
||||
$transactionId = $other->account_id;
|
||||
$type = $other->type;
|
||||
}
|
||||
|
||||
if ($type === AccountType::CASH) {
|
||||
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']]
|
||||
);
|
||||
|
@ -115,7 +115,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{# OPTIONAL REVENUE ACCOUNTS #}
|
||||
{% if showDepositsFrontpage %}
|
||||
{% if showDeps %}
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'revenue_accounts'|_ }}</h3>
|
||||
|
@ -128,7 +128,7 @@
|
||||
<div class="col-sm-10">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="showDepositsFrontpage[]" value="{{ showDepositsFrontpage }}"
|
||||
<input type="checkbox" name="showDepositsFrontpage[]" value="{{ showDeps }}"
|
||||
{% if showDepositsFrontpage %}
|
||||
checked
|
||||
{% endif %}
|
||||
|
Loading…
Reference in New Issue
Block a user