diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index c3d8039546e4..51ad55d86ab7 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -27,6 +27,7 @@ use App\Http\Requests\Invoice\StoreInvoiceRequest; use App\Http\Requests\Invoice\UpdateInvoiceRequest; use App\Http\Requests\Invoice\UploadInvoiceRequest; use App\Jobs\Entity\EmailEntity; +use App\Jobs\Invoice\BulkInvoiceJob; use App\Jobs\Invoice\StoreInvoice; use App\Jobs\Invoice\ZipInvoices; use App\Jobs\Ninja\TransactionLog; @@ -747,23 +748,14 @@ class InvoiceController extends BaseController case 'email': //check query parameter for email_type and set the template else use calculateTemplate + if (request()->has('email_type') && property_exists($invoice->company->settings, request()->input('email_type'))) { $this->reminder_template = $invoice->client->getSetting(request()->input('email_type')); } else { $this->reminder_template = $invoice->calculateTemplate('invoice'); } - //touch reminder1,2,3_sent + last_sent here if the email is a reminder. - //$invoice->service()->touchReminder($this->reminder_template)->deletePdf()->save(); - $invoice->service()->touchReminder($this->reminder_template)->markSent()->save(); - - $invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($invoice) { - EmailEntity::dispatch($invitation, $invoice->company, $this->reminder_template)->delay(now()->addSeconds(30)); - }); - - if ($invoice->invitations->count() >= 1) { - $invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', $this->reminder_template); - } + BulkInvoiceJob::dispatch($invoice, $this->reminder_template); if (! $bulk) { return response()->json(['message' => 'email sent'], 200); diff --git a/app/Jobs/Invoice/BulkInvoiceJob.php b/app/Jobs/Invoice/BulkInvoiceJob.php new file mode 100644 index 000000000000..ff42dc722e61 --- /dev/null +++ b/app/Jobs/Invoice/BulkInvoiceJob.php @@ -0,0 +1,71 @@ +invoice = $invoice; + $this->reminder_template = $reminder_template; + } + + /** + * Execute the job. + * + * + * @return void + */ + public function handle() + { + + $this->invoice->service()->touchReminder($this->reminder_template)->markSent()->save(); + + $this->invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) { + EmailEntity::dispatch($invitation, $this->invoice->company, $this->reminder_template)->delay(now()->addSeconds(5)); + }); + + if ($this->invoice->invitations->count() >= 1) { + $this->invoice->entityEmailEvent($this->invoice->invitations->first(), 'invoice', $this->reminder_template); + } + + } + +} diff --git a/app/PaymentDrivers/GoCardlessPaymentDriver.php b/app/PaymentDrivers/GoCardlessPaymentDriver.php index c9cdaef99e98..95a4e1f22fab 100644 --- a/app/PaymentDrivers/GoCardlessPaymentDriver.php +++ b/app/PaymentDrivers/GoCardlessPaymentDriver.php @@ -238,6 +238,7 @@ class GoCardlessPaymentDriver extends BaseDriver if(!is_array($request->events) || !is_object($request->events)){ nlog("No GoCardless events to process in response?"); + nlog($request); return response()->json([], 200); }