mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Determine partial or full payment template
This commit is contained in:
parent
725e4092ce
commit
353fe14b1e
@ -70,7 +70,6 @@ class EmailPayment implements ShouldQueue
|
|||||||
if ($this->company->is_disabled)
|
if ($this->company->is_disabled)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
if ($this->contact->email) {
|
if ($this->contact->email) {
|
||||||
|
|
||||||
MultiDB::setDb($this->company->db);
|
MultiDB::setDb($this->company->db);
|
||||||
|
@ -37,6 +37,10 @@ class PaymentEmailEngine extends BaseEmailEngine
|
|||||||
|
|
||||||
private $helpers;
|
private $helpers;
|
||||||
|
|
||||||
|
private $payment_template_body;
|
||||||
|
|
||||||
|
private $payment_template_subject;
|
||||||
|
|
||||||
public function __construct($payment, $contact, $template_data = null)
|
public function __construct($payment, $contact, $template_data = null)
|
||||||
{
|
{
|
||||||
$this->payment = $payment;
|
$this->payment = $payment;
|
||||||
@ -55,20 +59,22 @@ class PaymentEmailEngine extends BaseEmailEngine
|
|||||||
App::setLocale($this->contact->preferredLocale());
|
App::setLocale($this->contact->preferredLocale());
|
||||||
$t->replace(Ninja::transformTranslations($this->client->getMergedSettings()));
|
$t->replace(Ninja::transformTranslations($this->client->getMergedSettings()));
|
||||||
|
|
||||||
|
$this->resolvePaymentTemplate();
|
||||||
|
|
||||||
if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) {
|
if (is_array($this->template_data) && array_key_exists('body', $this->template_data) && strlen($this->template_data['body']) > 0) {
|
||||||
$body_template = $this->template_data['body'];
|
$body_template = $this->template_data['body'];
|
||||||
} elseif (strlen($this->client->getSetting('email_template_payment')) > 0) {
|
} elseif (strlen($this->client->getSetting($this->payment_template_body)) > 0) {
|
||||||
$body_template = $this->client->getSetting('email_template_payment');
|
$body_template = $this->client->getSetting($this->payment_template_body);
|
||||||
} else {
|
} else {
|
||||||
$body_template = EmailTemplateDefaults::getDefaultTemplate('email_template_payment', $this->client->locale());
|
$body_template = EmailTemplateDefaults::getDefaultTemplate($this->payment_template_body, $this->client->locale());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0) {
|
if (is_array($this->template_data) && array_key_exists('subject', $this->template_data) && strlen($this->template_data['subject']) > 0) {
|
||||||
$subject_template = $this->template_data['subject'];
|
$subject_template = $this->template_data['subject'];
|
||||||
} elseif (strlen($this->client->getSetting('email_subject_payment')) > 0) {
|
} elseif (strlen($this->client->getSetting($this->payment_template_subject)) > 0) {
|
||||||
$subject_template = $this->client->getSetting('email_subject_payment');
|
$subject_template = $this->client->getSetting($this->payment_template_subject);
|
||||||
} else {
|
} else {
|
||||||
$subject_template = EmailTemplateDefaults::getDefaultTemplate('email_subject_payment', $this->client->locale());
|
$subject_template = EmailTemplateDefaults::getDefaultTemplate($this->payment_template_subject, $this->client->locale());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setTemplate($this->client->getSetting('email_style'))
|
$this->setTemplate($this->client->getSetting('email_style'))
|
||||||
@ -96,6 +102,34 @@ class PaymentEmailEngine extends BaseEmailEngine
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to resolve which payment template
|
||||||
|
* to use. We need to check the invoice balances to
|
||||||
|
* determine if this is a partial payment, or full payment.
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
private function resolvePaymentTemplate()
|
||||||
|
{
|
||||||
|
|
||||||
|
$partial = $this->payment->invoices->contains(function ($invoice){
|
||||||
|
|
||||||
|
return $invoice->balance > 0;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
if($partial){
|
||||||
|
$this->payment_template_body = "email_template_payment_partial";
|
||||||
|
$this->payment_template_subject = "email_subject_payment_partial";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->payment_template_body = "email_template_payment";
|
||||||
|
$this->payment_template_subject = "email_subject_payment";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function makePaymentVariables()
|
public function makePaymentVariables()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user