Improvements to check-data

This commit is contained in:
Hillel Coren 2017-05-28 17:12:29 +03:00
parent 631bc9ffe2
commit d5d17d52b9

View File

@ -10,6 +10,7 @@ use Mail;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Utils; use Utils;
use App\Models\Contact; use App\Models\Contact;
use App\Models\Invoice;
use App\Models\Invitation; use App\Models\Invitation;
/* /*
@ -71,6 +72,7 @@ class CheckData extends Command
if (! $this->option('client_id')) { if (! $this->option('client_id')) {
$this->checkBlankInvoiceHistory(); $this->checkBlankInvoiceHistory();
$this->checkPaidToDate(); $this->checkPaidToDate();
$this->checkDraftSentInvoices();
} }
$this->checkBalances(); $this->checkBalances();
@ -88,8 +90,6 @@ class CheckData extends Command
$this->logMessage('Done: ' . strtoupper($this->isValid ? RESULT_SUCCESS : RESULT_FAILURE)); $this->logMessage('Done: ' . strtoupper($this->isValid ? RESULT_SUCCESS : RESULT_FAILURE));
$errorEmail = env('ERROR_EMAIL'); $errorEmail = env('ERROR_EMAIL');
$this->info($this->log);
if ($errorEmail) { if ($errorEmail) {
Mail::raw($this->log, function ($message) use ($errorEmail, $database) { Mail::raw($this->log, function ($message) use ($errorEmail, $database) {
$message->to($errorEmail) $message->to($errorEmail)
@ -103,9 +103,29 @@ class CheckData extends Command
private function logMessage($str) private function logMessage($str)
{ {
$this->info($str);
$this->log .= $str . "\n"; $this->log .= $str . "\n";
} }
private function checkDraftSentInvoices()
{
$invoices = Invoice::whereInvoiceStatusId(INVOICE_STATUS_SENT)
->whereIsPublic(false)
->withTrashed()
->get();
$this->logMessage(count($invoices) . ' draft sent invoices');
if ($this->option('fix') == 'true') {
foreach ($invoices as $invoice) {
if ($invoice->is_deleted) {
$invoice->unsetEventDispatcher();
}
$invoice->markSent();
}
}
}
private function checkOAuth() private function checkOAuth()
{ {
// check for duplicate oauth ids // check for duplicate oauth ids