diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index f0ac9d77857f..82b3e2b6989f 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -11,8 +11,9 @@ namespace App\Console; -use App\Jobs\Cron\SubscriptionCron; +use App\Jobs\Cron\AutoBillCron; use App\Jobs\Cron\RecurringInvoicesCron; +use App\Jobs\Cron\SubscriptionCron; use App\Jobs\Ninja\AdjustEmailQuota; use App\Jobs\Ninja\CompanySizeCheck; use App\Jobs\Util\ReminderJob; @@ -58,6 +59,8 @@ class Kernel extends ConsoleKernel $schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping(); + $schedule->job(new AutoBillCron)->daily()->withoutOverlapping(); + $schedule->job(new SchedulerCheck)->everyFiveMinutes(); /* Run hosted specific jobs */ diff --git a/app/Jobs/Cron/AutoBillCron.php b/app/Jobs/Cron/AutoBillCron.php index 6f9bf09c303e..8a56bb86e218 100644 --- a/app/Jobs/Cron/AutoBillCron.php +++ b/app/Jobs/Cron/AutoBillCron.php @@ -52,22 +52,18 @@ class AutoBillCron ->where('auto_bill_enabled', true) ->where('balance', '>', 0) ->with('company') - ->cursor(); - - $auto_bill_partial_invoices->each(function ($invoice){ - $this->runAutoBiller($invoice); - }); + ->cursor()->each(function ($invoice){ + $this->runAutoBiller($invoice); + }); $auto_bill_invoices = Invoice::whereDate('due_date', '<=', now()) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->where('auto_bill_enabled', true) ->where('balance', '>', 0) ->with('company') - ->cursor(); - - $auto_bill_invoices->each(function ($invoice){ - $this->runAutoBiller($invoice); - }); + ->cursor()->each(function ($invoice){ + $this->runAutoBiller($invoice); + }); } else { @@ -80,22 +76,18 @@ class AutoBillCron ->where('auto_bill_enabled', true) ->where('balance', '>', 0) ->with('company') - ->cursor(); - - $auto_bill_partial_invoices->each(function ($invoice){ - $this->runAutoBiller($invoice); - }); + ->cursor()->each(function ($invoice){ + $this->runAutoBiller($invoice); + }); $auto_bill_invoices = Invoice::whereDate('due_date', '<=', now()) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->where('auto_bill_enabled', true) ->where('balance', '>', 0) ->with('company') - ->cursor(); - - $auto_bill_invoices->each(function ($invoice){ - $this->runAutoBiller($invoice); - }); + ->cursor()->each(function ($invoice){ + $this->runAutoBiller($invoice); + }); } } diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 04f5eee78233..299127213da1 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -1655,17 +1655,16 @@ class Import implements ShouldQueue $current_db = config('database.default'); $local_company = Company::where('company_key', $this->company->company_key)->first(); - $owner = $local_company->owner(); MultiDB::setDb('db-ninja-01'); $ninja_company = Company::find(config('ninja.ninja_default_company_id')); /* If we already have a record of this user - move along. */ - if($client_contact = ClientContact::where(['email' => $owner->email, 'company_id' => $ninja_company->id])->first()) + if($client_contact = ClientContact::where(['email' => $this->user->email, 'company_id' => $ninja_company->id])->first()) return $client_contact->client; $ninja_client = ClientFactory::create($ninja_company->id, $ninja_company->owner()->id); - $ninja_client->name = $owner->present()->name(); + $ninja_client->name = $this->user->present()->name(); $ninja_client->address1 = $local_company->settings->address1; $ninja_client->address2 = $local_company->settings->address2; $ninja_client->city = $local_company->settings->city; @@ -1677,11 +1676,11 @@ class Import implements ShouldQueue $ninja_client->save(); $ninja_client_contact = ClientContactFactory::create($ninja_company->id, $ninja_company->owner()->id); - $ninja_client_contact->first_name = $owner->first_name; - $ninja_client_contact->last_name = $owner->last_name; + $ninja_client_contact->first_name = $this->user->first_name; + $ninja_client_contact->last_name = $this->user->last_name; $ninja_client_contact->client_id = $ninja_client->id; - $ninja_client_contact->email = $owner->email; - $ninja_client_contact->phone = $owner->phone; + $ninja_client_contact->email = $this->user->email; + $ninja_client_contact->phone = $this->user->phone; $ninja_client_contact->save();