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

@@ -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;
}
}