Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some small code optimisations.
James Cole84a7f825d7a3
diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.phpindex af4fa3e0ba..fadb4029dc 100644--- a/app/Http/Controllers/Auth/AuthController.php+++ b/app/Http/Controllers/Auth/AuthController.php@@ -43,6 +43,8 @@ class AuthController extends Controller*/public function __construct(){+ parent::__construct();+$this->middleware('guest', ['except' => 'getLogout']);}diff --git a/app/Http/Controllers/Auth/PasswordController.php b/app/Http/Controllers/Auth/PasswordController.phpindex 2fa89f2c20..8f618f136d 100644--- a/app/Http/Controllers/Auth/PasswordController.php+++ b/app/Http/Controllers/Auth/PasswordController.php@@ -36,6 +36,7 @@ class PasswordController extends Controller*/public function __construct(){+ parent::__construct();$this->middleware('guest');}diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.phpindex f0018f7025..4b06c5d666 100644--- a/app/Models/TransactionJournal.php+++ b/app/Models/TransactionJournal.php@@ -150,14 +150,9 @@ class TransactionJournal extends Modelreturn $cache->get(); // @codeCoverageIgnore}- $amount = '0';bcscale(2);- /** @var Transaction $t */- foreach ($this->transactions as $t) {- if ($t->amount > 0) {- $amount = $t->amount;- }- }+ $set = $this->transactions->sortByDesc('amount');+ $amount = $set->first()->amount;if (intval($this->tag_count) === 1) {// get amount for single tag:@@ -175,6 +170,49 @@ class TransactionJournal extends Model}+ /**+ * @param Tag $tag+ * @param $amount+ *+ * @return string+ */+ protected function amountByTagAdvancePayment(Tag $tag, $amount)+ {+ if ($this->transactionType->type == 'Withdrawal') {+ $others = $tag->transactionJournals()->transactionTypes(['Deposit'])->get();+ foreach ($others as $other) {+ $amount = bcsub($amount, $other->actual_amount);+ }++ return $amount;+ }+ if ($this->transactionType->type == 'Deposit') {+ return '0';+ }++ return $amount;+ }++ /**+ * @param $tag+ * @param $amount+ *+ * @return string+ */+ protected function amountByTagBalancingAct($tag, $amount)+ {+ if ($this->transactionType->type == 'Withdrawal') {+ $transfer = $tag->transactionJournals()->transactionTypes(['Transfer'])->first();+ if ($transfer) {+ $amount = bcsub($amount, $transfer->actual_amount);++ return $amount;+ }+ }++ return $amount;+ }+/*** Assuming the journal has only one tag. Parameter amount is used as fallback.*@@ -186,28 +224,12 @@ class TransactionJournal extends Modelprotected function amountByTag(Tag $tag, $amount){if ($tag->tagMode == 'advancePayment') {- if ($this->transactionType->type == 'Withdrawal') {- $others = $tag->transactionJournals()->transactionTypes(['Deposit'])->get();- foreach ($others as $other) {- $amount = bcsub($amount, $other->actual_amount);- }-- return $amount;- }- if ($this->transactionType->type == 'Deposit') {- return '0';- }+ return $this->amountByTagAdvancePayment($tag, $amount);}if ($tag->tagMode == 'balancingAct') {- if ($this->transactionType->type == 'Withdrawal') {- $transfer = $tag->transactionJournals()->transactionTypes(['Transfer'])->first();- if ($transfer) {- $amount = bcsub($amount, $transfer->actual_amount);+ return $this->amountByTagBalancingAct($tag, $amount);- return $amount;- }- }}return $amount;diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.phpindex 903f1f586a..77b63a35eb 100644--- a/app/Repositories/PiggyBank/PiggyBankRepository.php+++ b/app/Repositories/PiggyBank/PiggyBankRepository.php@@ -94,15 +94,15 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface** set id of piggy bank.*- * @param int $id+ * @param int $piggyBankId* @param int $order** @return void*/- public function setOrder($id, $order)+ public function setOrder($piggyBankId, $order){$piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id)- ->where('piggy_banks.id', $id)->first(['piggy_banks.*']);+ ->where('piggy_banks.id', $piggyBankId)->first(['piggy_banks.*']);if ($piggyBank) {$piggyBank->order = $order;$piggyBank->save();diff --git a/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php b/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.phpindex faa50a7694..3bf29f36d6 100644--- a/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php+++ b/app/Repositories/PiggyBank/PiggyBankRepositoryInterface.php@@ -58,12 +58,12 @@ interface PiggyBankRepositoryInterface** set id of piggy bank.*- * @param int $id+ * @param int $piggyBankId* @param int $order** @return void*/- public function setOrder($id, $order);+ public function setOrder($piggyBankId, $order);/**diff --git a/resources/lang/nl/firefly.php b/resources/lang/nl/firefly.phpindex c60a0aa951..713414cc3a 100644--- a/resources/lang/nl/firefly.php+++ b/resources/lang/nl/firefly.php@@ -36,7 +36,8 @@ return [' je jouw tekstbestand bij "CSV-bestand". '. 'Als je hulp nodig hebt, klik dan op het <i class="fa fa-question-circle"></i>-icoontje rechtsboven.','csv_index_beta_warning' => 'Deze tool is nog erg experimenteel. Wees dus voorzichtig.',- 'csv_header_help' => 'Zet hier een vinkje als de eerste rij van je tekstbestand bestaat uit kolomnamen, en niet uit daadwerkelijke gegevens.',+ 'csv_header_help' => 'Zet hier een vinkje als de eerste rij van je tekstbestand bestaat uit kolomnamen,'.+ 'en niet uit daadwerkelijke gegevens.','csv_date_help' => 'Het gebruikte datumformaat in jouw bestand. Gebruik het formaat zoals <a href="https://secure.' .'php.net/manual/en/datetime.createfromformat.php#refsect1-datetime.createfromformat-parameters">deze' .' pagina</a> het uitlegt (Engels). Het standaardformaat kan omgaan met data zoals deze: ' . date('Ymd'),@@ -47,7 +48,8 @@ return ['csv_column_roles_title' => 'Bepaal de inhoud van elke kolom','csv_column_roles_text' => 'Firefly kan niet automatisch ontdekken wat elke kolom betekent. Je moet het zelf aangeven. Gebruik de' .' voorbeeldgegevens als je het ook niet zeker weet. Klik op het <i class="fa fa-question-circle"></i>-icoontje ' .- 'rechtsboven om te ontdekken wat elke kolomsoort precies is. Als de kolominhoud een directe relatie heeft met gegevens'+ 'rechtsboven om te ontdekken wat elke kolomsoort precies is. Als de kolominhoud een directe'.+ ' relatie heeft met gegevens'.' die al in Firefly staan, gebruik dan het vinkje. Tijdens de volgende stap komt Firefly hier dan op terug.','csv_column' => 'CSV-kolom',diff --git a/resources/twig/errors/404.twig b/resources/twig/errors/404.twigindex c80eb8402f..41481b8501 100644--- a/resources/twig/errors/404.twig+++ b/resources/twig/errors/404.twig@@ -165,7 +165,6 @@padding: 6px;float: left;margin-right: 10px;- float: left;display: block;}