diff --git a/app/Console/Commands/VerifyDatabase.php b/app/Console/Commands/VerifyDatabase.php index 3238c2c0dd..3b21b24cb3 100644 --- a/app/Console/Commands/VerifyDatabase.php +++ b/app/Console/Commands/VerifyDatabase.php @@ -72,6 +72,9 @@ class VerifyDatabase extends Command $this->reportTransactions(); // deleted accounts that still have not deleted transactions or journals attached to them. $this->reportDeletedAccounts(); + + // report on journals with no transactions at all. + $this->reportNoTransactions(); } /** @@ -210,6 +213,28 @@ class VerifyDatabase extends Command } } + private function reportNoTransactions() + { + /* + * select transaction_journals.id, count(transactions.id) as transaction_count from transaction_journals +left join transactions ON transaction_journals.id = transactions.transaction_journal_id +group by transaction_journals.id +having transaction_count = 0 + */ + $set = TransactionJournal + ::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') + ->groupBy('transaction_journals.id') + ->having('transaction_count', '=', 0) + ->get(['transaction_journals.id', DB::raw('COUNT(`transactions`.`id`) as `transaction_count`')]); + + foreach ($set as $entry) { + $this->error( + 'Error: Journal #' . $entry->id . ' has zero transactions. Open table `transaction_journals` and delete the entry with id #' . $entry->id + ); + } + + } + /** * Reports for each user when the sum of their transactions is not zero. */