Some small code optimisations.

This commit is contained in:
James Cole
2015-07-09 06:13:39 +02:00
parent 0372c1aaf1
commit 84a7f825d7
7 changed files with 59 additions and 33 deletions

View File

@@ -43,6 +43,8 @@ class AuthController extends Controller
*/ */
public function __construct() public function __construct()
{ {
parent::__construct();
$this->middleware('guest', ['except' => 'getLogout']); $this->middleware('guest', ['except' => 'getLogout']);
} }

View File

@@ -36,6 +36,7 @@ class PasswordController extends Controller
*/ */
public function __construct() public function __construct()
{ {
parent::__construct();
$this->middleware('guest'); $this->middleware('guest');
} }

View File

@@ -150,14 +150,9 @@ class TransactionJournal extends Model
return $cache->get(); // @codeCoverageIgnore return $cache->get(); // @codeCoverageIgnore
} }
$amount = '0';
bcscale(2); bcscale(2);
/** @var Transaction $t */ $set = $this->transactions->sortByDesc('amount');
foreach ($this->transactions as $t) { $amount = $set->first()->amount;
if ($t->amount > 0) {
$amount = $t->amount;
}
}
if (intval($this->tag_count) === 1) { if (intval($this->tag_count) === 1) {
// get amount for single tag: // 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. * Assuming the journal has only one tag. Parameter amount is used as fallback.
* *
@@ -186,28 +224,12 @@ class TransactionJournal extends Model
protected function amountByTag(Tag $tag, $amount) protected function amountByTag(Tag $tag, $amount)
{ {
if ($tag->tagMode == 'advancePayment') { if ($tag->tagMode == 'advancePayment') {
if ($this->transactionType->type == 'Withdrawal') { return $this->amountByTagAdvancePayment($tag, $amount);
$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';
}
} }
if ($tag->tagMode == 'balancingAct') { if ($tag->tagMode == 'balancingAct') {
if ($this->transactionType->type == 'Withdrawal') { return $this->amountByTagBalancingAct($tag, $amount);
$transfer = $tag->transactionJournals()->transactionTypes(['Transfer'])->first();
if ($transfer) {
$amount = bcsub($amount, $transfer->actual_amount);
return $amount;
}
}
} }
return $amount; return $amount;

View File

@@ -94,15 +94,15 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
* *
* set id of piggy bank. * set id of piggy bank.
* *
* @param int $id * @param int $piggyBankId
* @param int $order * @param int $order
* *
* @return void * @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) $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) { if ($piggyBank) {
$piggyBank->order = $order; $piggyBank->order = $order;
$piggyBank->save(); $piggyBank->save();

View File

@@ -58,12 +58,12 @@ interface PiggyBankRepositoryInterface
* *
* set id of piggy bank. * set id of piggy bank.
* *
* @param int $id * @param int $piggyBankId
* @param int $order * @param int $order
* *
* @return void * @return void
*/ */
public function setOrder($id, $order); public function setOrder($piggyBankId, $order);
/** /**

View File

@@ -36,7 +36,8 @@ return [
' je jouw tekstbestand bij "CSV-bestand". ' ' je jouw tekstbestand bij "CSV-bestand". '
. 'Als je hulp nodig hebt, klik dan op het <i class="fa fa-question-circle"></i>-icoontje rechtsboven.', . '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_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.' . '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' . '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'), ' 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_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' . '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 ' . ' 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.', ' die al in Firefly staan, gebruik dan het vinkje. Tijdens de volgende stap komt Firefly hier dan op terug.',
'csv_column' => 'CSV-kolom', 'csv_column' => 'CSV-kolom',

View File

@@ -165,7 +165,6 @@
padding: 6px; padding: 6px;
float: left; float: left;
margin-right: 10px; margin-right: 10px;
float: left;
display: block; display: block;
} }