2022-04-21 01:25:19 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2022-04-21 01:25:19 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Jobs\Invoice;
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
2023-12-12 08:43:55 +01:00
|
|
|
use App\Models\Webhook;
|
2022-04-21 01:25:19 +02:00
|
|
|
use Illuminate\Bus\Queueable;
|
2023-12-12 08:43:55 +01:00
|
|
|
use App\Jobs\Entity\EmailEntity;
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
use Illuminate\Queue\InteractsWithQueue;
|
2022-04-21 01:25:19 +02:00
|
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
|
|
|
|
|
|
class BulkInvoiceJob implements ShouldQueue
|
|
|
|
{
|
2024-01-14 05:05:00 +01:00
|
|
|
use Dispatchable;
|
|
|
|
use InteractsWithQueue;
|
|
|
|
use Queueable;
|
|
|
|
use SerializesModels;
|
2022-04-21 01:25:19 +02:00
|
|
|
|
|
|
|
public $invoice;
|
|
|
|
|
|
|
|
public $reminder_template;
|
|
|
|
|
|
|
|
public function __construct(Invoice $invoice, string $reminder_template)
|
|
|
|
{
|
|
|
|
$this->invoice = $invoice;
|
|
|
|
$this->reminder_template = $reminder_template;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
2023-01-13 12:26:12 +01:00
|
|
|
{ //only the reminder should mark the reminder sent field
|
2023-07-10 10:29:24 +02:00
|
|
|
|
2023-01-13 12:26:12 +01:00
|
|
|
$this->invoice->service()->markSent()->save();
|
2022-04-21 01:25:19 +02:00
|
|
|
|
|
|
|
$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);
|
2023-12-12 08:43:55 +01:00
|
|
|
$this->invoice->sendEvent(Webhook::EVENT_SENT_INVOICE, "client");
|
|
|
|
|
2022-04-21 01:25:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|