Fixes for import

This commit is contained in:
David Bomba 2021-05-26 19:51:04 +10:00
parent d5c4b85434
commit 65ccf75375
3 changed files with 22 additions and 28 deletions

View File

@ -11,8 +11,9 @@
namespace App\Console; namespace App\Console;
use App\Jobs\Cron\SubscriptionCron; use App\Jobs\Cron\AutoBillCron;
use App\Jobs\Cron\RecurringInvoicesCron; use App\Jobs\Cron\RecurringInvoicesCron;
use App\Jobs\Cron\SubscriptionCron;
use App\Jobs\Ninja\AdjustEmailQuota; use App\Jobs\Ninja\AdjustEmailQuota;
use App\Jobs\Ninja\CompanySizeCheck; use App\Jobs\Ninja\CompanySizeCheck;
use App\Jobs\Util\ReminderJob; use App\Jobs\Util\ReminderJob;
@ -58,6 +59,8 @@ class Kernel extends ConsoleKernel
$schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping(); $schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping();
$schedule->job(new AutoBillCron)->daily()->withoutOverlapping();
$schedule->job(new SchedulerCheck)->everyFiveMinutes(); $schedule->job(new SchedulerCheck)->everyFiveMinutes();
/* Run hosted specific jobs */ /* Run hosted specific jobs */

View File

@ -52,9 +52,7 @@ class AutoBillCron
->where('auto_bill_enabled', true) ->where('auto_bill_enabled', true)
->where('balance', '>', 0) ->where('balance', '>', 0)
->with('company') ->with('company')
->cursor(); ->cursor()->each(function ($invoice){
$auto_bill_partial_invoices->each(function ($invoice){
$this->runAutoBiller($invoice); $this->runAutoBiller($invoice);
}); });
@ -63,9 +61,7 @@ class AutoBillCron
->where('auto_bill_enabled', true) ->where('auto_bill_enabled', true)
->where('balance', '>', 0) ->where('balance', '>', 0)
->with('company') ->with('company')
->cursor(); ->cursor()->each(function ($invoice){
$auto_bill_invoices->each(function ($invoice){
$this->runAutoBiller($invoice); $this->runAutoBiller($invoice);
}); });
@ -80,9 +76,7 @@ class AutoBillCron
->where('auto_bill_enabled', true) ->where('auto_bill_enabled', true)
->where('balance', '>', 0) ->where('balance', '>', 0)
->with('company') ->with('company')
->cursor(); ->cursor()->each(function ($invoice){
$auto_bill_partial_invoices->each(function ($invoice){
$this->runAutoBiller($invoice); $this->runAutoBiller($invoice);
}); });
@ -91,9 +85,7 @@ class AutoBillCron
->where('auto_bill_enabled', true) ->where('auto_bill_enabled', true)
->where('balance', '>', 0) ->where('balance', '>', 0)
->with('company') ->with('company')
->cursor(); ->cursor()->each(function ($invoice){
$auto_bill_invoices->each(function ($invoice){
$this->runAutoBiller($invoice); $this->runAutoBiller($invoice);
}); });

View File

@ -1655,17 +1655,16 @@ class Import implements ShouldQueue
$current_db = config('database.default'); $current_db = config('database.default');
$local_company = Company::where('company_key', $this->company->company_key)->first(); $local_company = Company::where('company_key', $this->company->company_key)->first();
$owner = $local_company->owner();
MultiDB::setDb('db-ninja-01'); MultiDB::setDb('db-ninja-01');
$ninja_company = Company::find(config('ninja.ninja_default_company_id')); $ninja_company = Company::find(config('ninja.ninja_default_company_id'));
/* If we already have a record of this user - move along. */ /* 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; return $client_contact->client;
$ninja_client = ClientFactory::create($ninja_company->id, $ninja_company->owner()->id); $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->address1 = $local_company->settings->address1;
$ninja_client->address2 = $local_company->settings->address2; $ninja_client->address2 = $local_company->settings->address2;
$ninja_client->city = $local_company->settings->city; $ninja_client->city = $local_company->settings->city;
@ -1677,11 +1676,11 @@ class Import implements ShouldQueue
$ninja_client->save(); $ninja_client->save();
$ninja_client_contact = ClientContactFactory::create($ninja_company->id, $ninja_company->owner()->id); $ninja_client_contact = ClientContactFactory::create($ninja_company->id, $ninja_company->owner()->id);
$ninja_client_contact->first_name = $owner->first_name; $ninja_client_contact->first_name = $this->user->first_name;
$ninja_client_contact->last_name = $owner->last_name; $ninja_client_contact->last_name = $this->user->last_name;
$ninja_client_contact->client_id = $ninja_client->id; $ninja_client_contact->client_id = $ninja_client->id;
$ninja_client_contact->email = $owner->email; $ninja_client_contact->email = $this->user->email;
$ninja_client_contact->phone = $owner->phone; $ninja_client_contact->phone = $this->user->phone;
$ninja_client_contact->save(); $ninja_client_contact->save();