mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for recurring invoice email logic
This commit is contained in:
parent
c164ab1970
commit
a0fab8d22d
@ -110,33 +110,50 @@ class SendRecurring implements ShouldQueue
|
||||
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, true)->delay(rand(1, 2));
|
||||
|
||||
//edge case to support where online payment notifications are not enabled
|
||||
if(!$invoice->client->getSetting('client_online_payment_notification')){
|
||||
$this->sendRecurringEmails($invoice);
|
||||
}
|
||||
}
|
||||
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, true)->delay(rand(1, 2));
|
||||
}
|
||||
elseif ($invoice->client->getSetting('auto_email_invoice')) {
|
||||
//Admin notification for recurring invoice sent.
|
||||
if ($invoice->invitations->count() >= 1) {
|
||||
$invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', 'email_template_invoice');
|
||||
|
||||
//edge case to support where online payment notifications are not enabled
|
||||
if(!$invoice->client->getSetting('client_online_payment_notification')) {
|
||||
$this->sendRecurringEmails($invoice);
|
||||
}
|
||||
|
||||
$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}");
|
||||
}
|
||||
});
|
||||
}
|
||||
elseif ($invoice->client->getSetting('auto_email_invoice')) {
|
||||
$this->sendRecurringEmails($invoice);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function sendRecurringEmails(Invoice $invoice)
|
||||
{
|
||||
//Admin notification for recurring invoice sent.
|
||||
if ($invoice->invitations->count() >= 1) {
|
||||
$invoice->entityEmailEvent($invoice->invitations->first(), 'invoice', 'email_template_invoice');
|
||||
}
|
||||
|
||||
$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}");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Only create the invitations that are defined on the recurring invoice.
|
||||
* @param Invoice $invoice
|
||||
|
@ -310,25 +310,6 @@ class AutoBillInvoice extends AbstractService
|
||||
return $this;
|
||||
}
|
||||
|
||||
// private function applyPaymentToCredit($credit, $amount) :Credit
|
||||
// {
|
||||
// $credit_item = new InvoiceItem;
|
||||
// $credit_item->type_id = '1';
|
||||
// $credit_item->product_key = ctrans('texts.credit');
|
||||
// $credit_item->notes = ctrans('texts.credit_payment', ['invoice_number' => $this->invoice->number]);
|
||||
// $credit_item->quantity = 1;
|
||||
// $credit_item->cost = $amount * -1;
|
||||
|
||||
// $credit_items = $credit->line_items;
|
||||
// $credit_items[] = $credit_item;
|
||||
|
||||
// $credit->line_items = $credit_items;
|
||||
|
||||
// $credit = $credit->calc()->getCredit();
|
||||
// $credit->save();
|
||||
|
||||
// return $credit;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Harvests a client gateway token which passes the
|
||||
@ -371,37 +352,4 @@ class AutoBillInvoice extends AbstractService
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a gateway fee to the invoice.
|
||||
*
|
||||
* @param float $fee The fee amount.
|
||||
* @return AutoBillInvoice
|
||||
* @deprecated / unused
|
||||
*/
|
||||
// private function addFeeToInvoice(float $fee)
|
||||
// {
|
||||
// //todo if we increase the invoice balance here, we will also need to adjust UP the client balance and ledger?
|
||||
// $starting_amount = $this->invoice->amount;
|
||||
|
||||
// $item = new InvoiceItem;
|
||||
// $item->quantity = 1;
|
||||
// $item->cost = $fee;
|
||||
// $item->notes = ctrans('texts.online_payment_surcharge');
|
||||
// $item->type_id = 3;
|
||||
|
||||
// $items = (array) $this->invoice->line_items;
|
||||
// $items[] = $item;
|
||||
|
||||
// $this->invoice->line_items = $items;
|
||||
// $this->invoice->saveQuietly();
|
||||
|
||||
// $this->invoice = $this->invoice->calc()->getInvoice()->saveQuietly();
|
||||
|
||||
// if ($starting_amount != $this->invoice->amount && $this->invoice->status_id != Invoice::STATUS_DRAFT) {
|
||||
// $this->invoice->client->service()->updateBalance($this->invoice->amount - $starting_amount)->save();
|
||||
// $this->invoice->ledger()->updateInvoiceBalance($this->invoice->amount - $starting_amount, "Invoice {$this->invoice->number} balance updated after stale gateway fee removed")->save();
|
||||
// }
|
||||
|
||||
// return $this;
|
||||
// }
|
||||
}
|
||||
|
@ -39,7 +39,6 @@ class PdfBuilder
|
||||
/**
|
||||
* The DOM Document;
|
||||
*
|
||||
* @var $document
|
||||
*/
|
||||
public DomDocument $document;
|
||||
|
||||
@ -619,7 +618,6 @@ class PdfBuilder
|
||||
*
|
||||
* @param mixed $items
|
||||
* @param string $table_type
|
||||
* @param mixed|null $custom_fields
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@ -1313,7 +1311,7 @@ class PdfBuilder
|
||||
* Generates the custom values for the
|
||||
* entity.
|
||||
*
|
||||
* @param array
|
||||
* @param array $variables
|
||||
* @return array
|
||||
*/
|
||||
public function genericDetailsBuilder(array $variables): array
|
||||
@ -1470,7 +1468,7 @@ class PdfBuilder
|
||||
* Passes an array of items by reference
|
||||
* and performs a nl2br
|
||||
*
|
||||
* @param array
|
||||
* @param array $variables
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
|
@ -183,7 +183,6 @@ class PdfMock
|
||||
/**
|
||||
* getStubVariables
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getStubVariables()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user