Improvements to the check data script

This commit is contained in:
Hillel Coren 2016-08-29 18:03:08 +03:00
parent fd5fa8f557
commit 1463bbbfae

View File

@ -57,15 +57,28 @@ class CheckData extends Command {
if (!$this->option('client_id')) { if (!$this->option('client_id')) {
$this->checkPaidToDate(); $this->checkPaidToDate();
$this->checkBlankInvoiceHistory();
} }
$this->checkBalances(); $this->checkBalances();
if (!$this->option('client_id')) {
$this->checkAccountData(); $this->checkAccountData();
}
$this->info('Done'); $this->info('Done');
} }
private function checkBlankInvoiceHistory()
{
$count = DB::table('activities')
->where('activity_type_id', '=', 5)
->where('json_backup', '=', '')
->count();
$this->info($count . ' activities with blank invoice backup');
}
private function checkAccountData() private function checkAccountData()
{ {
$tables = [ $tables = [
@ -97,6 +110,12 @@ class CheckData extends Command {
ENTITY_CLIENT, ENTITY_CLIENT,
ENTITY_USER ENTITY_USER
], ],
'expenses' => [
ENTITY_CLIENT,
ENTITY_VENDOR,
ENTITY_INVOICE,
ENTITY_USER
]
]; ];
foreach ($tables as $table => $entityTypes) { foreach ($tables as $table => $entityTypes) {
@ -158,15 +177,15 @@ class CheckData extends Command {
// find all clients where the balance doesn't equal the sum of the outstanding invoices // find all clients where the balance doesn't equal the sum of the outstanding invoices
$clients = DB::table('clients') $clients = DB::table('clients')
->join('invoices', 'invoices.client_id', '=', 'clients.id') ->join('invoices', 'invoices.client_id', '=', 'clients.id')
->join('accounts', 'accounts.id', '=', 'clients.account_id'); ->join('accounts', 'accounts.id', '=', 'clients.account_id')
->where('clients.is_deleted', '=', 0)
if ($this->option('client_id')) { ->where('invoices.is_deleted', '=', 0)
$clients->where('clients.id', '=', $this->option('client_id'));
} else {
$clients->where('invoices.is_deleted', '=', 0)
->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD) ->where('invoices.invoice_type_id', '=', INVOICE_TYPE_STANDARD)
->where('invoices.is_recurring', '=', 0) ->where('invoices.is_recurring', '=', 0)
->havingRaw('abs(clients.balance - sum(invoices.balance)) > .01 and clients.balance != 999999999.9999'); ->havingRaw('abs(clients.balance - sum(invoices.balance)) > .01 and clients.balance != 999999999.9999');
if ($this->option('client_id')) {
$clients->where('clients.id', '=', $this->option('client_id'));
} }
$clients = $clients->groupBy('clients.id', 'clients.balance', 'clients.created_at') $clients = $clients->groupBy('clients.id', 'clients.balance', 'clients.created_at')
@ -230,8 +249,14 @@ class CheckData extends Command {
&& $activity->adjustment == 0 && $activity->adjustment == 0
&& $invoice->amount > 0; && $invoice->amount > 0;
// **Fix for ninja invoices which didn't have the invoice_type_id value set
if ($noAdjustment && $client->account_id == 20432) {
$this->info("No adjustment for ninja invoice");
$foundProblem = true;
$clientFix += $invoice->amount;
$activityFix = $invoice->amount;
// **Fix for allowing converting a recurring invoice to a normal one without updating the balance** // **Fix for allowing converting a recurring invoice to a normal one without updating the balance**
if ($noAdjustment && $invoice->invoice_type_id == INVOICE_TYPE_STANDARD && !$invoice->is_recurring) { } elseif ($noAdjustment && $invoice->invoice_type_id == INVOICE_TYPE_STANDARD && !$invoice->is_recurring) {
$this->info("No adjustment for new invoice:{$activity->invoice_id} amount:{$invoice->amount} invoiceTypeId:{$invoice->invoice_type_id} isRecurring:{$invoice->is_recurring}"); $this->info("No adjustment for new invoice:{$activity->invoice_id} amount:{$invoice->amount} invoiceTypeId:{$invoice->invoice_type_id} isRecurring:{$invoice->is_recurring}");
$foundProblem = true; $foundProblem = true;
$clientFix += $invoice->amount; $clientFix += $invoice->amount;