diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 3c5fd83d61ff..573bc0b5b3d7 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -22,6 +22,7 @@ use App\Jobs\Ninja\CompanySizeCheck; use App\Jobs\Ninja\QueueSize; use App\Jobs\Ninja\SystemMaintenance; use App\Jobs\Ninja\TaskScheduler; +use App\Jobs\Quote\InvoiceCheckLateWebhook; use App\Jobs\Quote\QuoteCheckExpired; use App\Jobs\Subscription\CleanStaleInvoiceOrder; use App\Jobs\Util\DiskCleanup; @@ -78,6 +79,9 @@ class Kernel extends ConsoleKernel /* Fires notifications for expired Quotes */ $schedule->job(new QuoteCheckExpired)->dailyAt('05:10')->withoutOverlapping()->name('quote-expired-job')->onOneServer(); + /* Fires webhooks for overdue Invoice */ + $schedule->job(new InvoiceCheckLateWebhook)->dailyAt('07:00')->withoutOverlapping()->name('invoice-overdue-job')->onOneServer(); + /* Performs auto billing */ $schedule->job(new AutoBillCron)->dailyAt('06:20')->withoutOverlapping()->name('auto-bill-job')->onOneServer(); diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 913c63ad077b..e376043b5f99 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -1155,6 +1155,10 @@ class CompanyImport implements ShouldQueue { try{ Storage::disk(config('filesystems.default'))->put($new_document->url, $file); + + $new_document->disk = config('filesystems.default'); + $new_document->save(); + } catch(\Exception $e) { diff --git a/app/Jobs/Invoice/InvoiceCheckLateWebhook.php b/app/Jobs/Invoice/InvoiceCheckLateWebhook.php new file mode 100644 index 000000000000..824f34e499ef --- /dev/null +++ b/app/Jobs/Invoice/InvoiceCheckLateWebhook.php @@ -0,0 +1,111 @@ +where('is_deleted', 0) + ->pluck('company_id'); + + Invoice::query() + ->where('is_deleted', false) + ->whereNull('deleted_at') + ->whereNotNull('due_date') + ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) + ->where('balance', '>', 0) + ->whereIn('company_id', $company_ids) + ->whereHas('client', function ($query) { + $query->where('is_deleted', 0) + ->where('deleted_at', null); + }) + ->whereHas('company', function ($query){ + $query->where('is_disabled', 0); + }) + ->whereBetween('due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()]) + ->cursor() + ->each(function ($invoice){ + + WebhookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(2)); + + }); + + } + else { + + foreach (MultiDB::$dbs as $db) + { + + MultiDB::setDB($db); + + $company_ids = Webhook::where('event_id', Webhook::EVENT_LATE_INVOICE) + ->where('is_deleted', 0) + ->pluck('company_id'); + + Invoice::query() + ->where('is_deleted', false) + ->whereNull('deleted_at') + ->whereNotNull('due_date') + ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) + ->where('balance', '>', 0) + ->whereIn('company_id', $company_ids) + ->whereHas('client', function ($query) { + $query->where('is_deleted', 0) + ->where('deleted_at', null); + }) + ->whereHas('company', function ($query){ + $query->where('is_disabled', 0); + }) + ->whereBetween('due_date', [now()->subDay()->startOfDay(), now()->startOfDay()->subSecond()]) + ->cursor() + ->each(function ($invoice){ + + WebhookHandler::dispatch(Webhook::EVENT_LATE_INVOICE, $invoice, $invoice->company, 'client')->delay(now()->addSeconds(2)); + + }); + + + } + } + + } + +}