Various code cleanup.

This commit is contained in:
James Cole
2021-06-13 07:04:18 +02:00
parent 85204de9aa
commit c98706fac0
24 changed files with 39 additions and 65 deletions

View File

@@ -313,7 +313,7 @@ trait RecurringTransactionTrait
*/
protected function updateTags(RecurrenceTransaction $transaction, array $tags): void
{
if (count($tags) > 0) {
if (!empty($tags)) {
/** @var RecurrenceMeta|null $entry */
$entry = $transaction->recurrenceTransactionMeta()->where('name', 'tags')->first();
if (null === $entry) {

View File

@@ -32,7 +32,7 @@ use Log;
/**
* Class GroupUpdateService
* See reference nr. 91
* See reference nr. 91
*/
class GroupUpdateService
{
@@ -57,6 +57,7 @@ class GroupUpdateService
$transactionGroup->save();
}
if (empty($transactions)) {
Log::debug('No transactions submitted, do nothing.');
@@ -105,6 +106,9 @@ class GroupUpdateService
*/
private function updateTransactionJournal(TransactionGroup $transactionGroup, TransactionJournal $journal, array $data): void
{
if (empty($data)) {
return;
}
/** @var JournalUpdateService $updateService */
$updateService = app(JournalUpdateService::class);
$updateService->setTransactionGroup($transactionGroup);

View File

@@ -48,7 +48,7 @@ use Log;
* Class to centralise code that updates a journal given the input by system.
*
* Class JournalUpdateService
* See reference nr. 93
* See reference nr. 93
*/
class JournalUpdateService
{
@@ -128,6 +128,11 @@ class JournalUpdateService
public function update(): void
{
Log::debug(sprintf('Now in JournalUpdateService for journal #%d.', $this->transactionJournal->id));
if ($this->removeReconciliation()) {
$this->data['reconciled'] = false;
}
// can we update account data using the new type?
if ($this->hasValidAccounts()) {
Log::info('Account info is valid, now update.');
@@ -158,7 +163,7 @@ class JournalUpdateService
$this->updateAmount();
$this->updateForeignAmount();
// See reference nr. 94
// See reference nr. 94
app('preferences')->mark();
@@ -201,7 +206,7 @@ class JournalUpdateService
$result = $validator->validateSource($sourceId, $sourceName, null);
Log::debug(sprintf('hasValidSourceAccount(%d, "%s") will return %s', $sourceId, $sourceName, var_export($result, true)));
// See reference nr. 95
// See reference nr. 95
// validate submitted info:
return $result;
@@ -295,7 +300,7 @@ class JournalUpdateService
$result = $validator->validateDestination($destId, $destName, null);
Log::debug(sprintf('hasValidDestinationAccount(%d, "%s") will return %s', $destId, $destName, var_export($result, true)));
// See reference nr. 96
// See reference nr. 96
// validate submitted info:
return $result;
@@ -758,4 +763,19 @@ class JournalUpdateService
$this->sourceTransaction->refresh();
$this->destinationTransaction->refresh();
}
/**
* @return bool
*/
private function removeReconciliation(): bool
{
if (count($this->data) > 1) {
return true;
}
if (1 === count($this->data) && true === array_key_exists('transaction_journal_id', $this->data)) {
return true;
}
return false;
}
}