mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Change number of emails sent when auto billing recurring invoices
This commit is contained in:
parent
6329484771
commit
50eceaf9d1
@ -11,13 +11,14 @@
|
||||
|
||||
namespace App\Jobs\Cron;
|
||||
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Models\Invoice;
|
||||
use App\Libraries\MultiDB;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use App\Jobs\Entity\EmailEntity;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class AutoBill implements ShouldQueue
|
||||
{
|
||||
@ -25,19 +26,13 @@ class AutoBill implements ShouldQueue
|
||||
|
||||
public $tries = 1;
|
||||
|
||||
public int $invoice_id;
|
||||
|
||||
public string $db;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(int $invoice_id, ?string $db)
|
||||
public function __construct(public int $invoice_id, public ?string $db, public bool $send_email_on_failure = false)
|
||||
{
|
||||
$this->invoice_id = $invoice_id;
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,6 +56,24 @@ class AutoBill implements ShouldQueue
|
||||
$invoice->service()->autoBill();
|
||||
} catch (\Exception $e) {
|
||||
nlog("Failed to capture payment for {$this->invoice_id} ->".$e->getMessage());
|
||||
|
||||
if($this->send_email_on_failure)
|
||||
{
|
||||
|
||||
$invoice->invitations->each(function ($invitation) use ($invoice) {
|
||||
if ($invitation->contact && ! $invitation->contact->trashed() && strlen($invitation->contact->email) >= 1 && $invoice->client->getSetting('auto_email_invoice')) {
|
||||
try {
|
||||
EmailEntity::dispatch($invitation, $invoice->company)->delay(rand(1, 2));
|
||||
} catch (\Exception $e) {
|
||||
nlog($e->getMessage());
|
||||
}
|
||||
|
||||
nlog("Firing email for invoice {$invoice->number}");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -116,11 +116,11 @@ class SendRecurring implements ShouldQueue
|
||||
//auto bill, BUT NOT DRAFTS!!
|
||||
if ($invoice->auto_bill_enabled && $invoice->client->getSetting('auto_bill_date') == 'on_send_date' && $invoice->client->getSetting('auto_email_invoice')) {
|
||||
nlog("attempting to autobill {$invoice->number}");
|
||||
AutoBill::dispatch($invoice->id, $this->db)->delay(rand(1, 2));
|
||||
AutoBill::dispatch($invoice->id, $this->db, true)->delay(rand(1, 2));
|
||||
}
|
||||
elseif ($invoice->auto_bill_enabled && $invoice->client->getSetting('auto_bill_date') == 'on_due_date' && $invoice->client->getSetting('auto_email_invoice') && ($invoice->due_date && Carbon::parse($invoice->due_date)->startOfDay()->lte(now()->startOfDay()))) {
|
||||
nlog("attempting to autobill {$invoice->number}");
|
||||
AutoBill::dispatch($invoice->id, $this->db)->delay(rand(1, 2));
|
||||
AutoBill::dispatch($invoice->id, $this->db, true)->delay(rand(1, 2));
|
||||
}
|
||||
elseif ($invoice->client->getSetting('auto_email_invoice')) {
|
||||
//Admin notification for recurring invoice sent.
|
||||
|
Loading…
x
Reference in New Issue
Block a user