mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Merge branch 'v5-develop' of https://github.com/turbo124/invoiceninja into v5-develop
This commit is contained in:
commit
3928ab3e39
@ -554,7 +554,7 @@ class CreditController extends BaseController
|
||||
// EmailCredit::dispatch($credit, $credit->company);
|
||||
|
||||
$credit->invitations->load('contact.client.country', 'credit.client.country', 'credit.company')->each(function ($invitation) use ($credit) {
|
||||
EmailEntity::dispatch($invitation, $credit->company);
|
||||
EmailEntity::dispatch($invitation, $credit->company, 'credit');
|
||||
});
|
||||
|
||||
|
||||
|
@ -117,13 +117,22 @@ class EmailController extends BaseController
|
||||
$subject = $request->input('subject');
|
||||
$body = $request->input('body');
|
||||
$entity_string = strtolower(class_basename($entity_obj));
|
||||
$template = $request->input('template');
|
||||
$template = str_replace("email_template_", "", $template);
|
||||
|
||||
$entity_obj->invitations->each(function ($invitation) use ($subject, $body, $entity_string, $entity_obj, $template) {
|
||||
|
||||
$entity_obj->invitations->each(function ($invitation) use ($subject, $body, $entity_string, $entity_obj) {
|
||||
if ($invitation->contact->send_email && $invitation->contact->email) {
|
||||
|
||||
EmailEntity::dispatchNow($invitation, $invitation->company);
|
||||
//$invitation->contact->notify((new SendGenericNotification($invitation, $entity_string, $subject, $body))->delay($when));
|
||||
$data = [
|
||||
'subject' => $subject,
|
||||
'body' => $body
|
||||
];
|
||||
|
||||
EmailEntity::dispatchNow($invitation, $invitation->company, $template, $data);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$entity_obj->last_sent_date = now();
|
||||
|
@ -725,7 +725,8 @@ class InvoiceController extends BaseController
|
||||
$invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($invoice) {
|
||||
$email_builder = (new InvoiceEmail())->build($invitation, $this->reminder_template);
|
||||
|
||||
EmailEntity::dispatch($invitation, $invoice->company);
|
||||
EmailEntity::dispatch($invitation, $invoice->company, $this->reminder_template);
|
||||
|
||||
});
|
||||
|
||||
if (! $bulk) {
|
||||
|
@ -61,13 +61,14 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
|
||||
public $email_entity_builder;
|
||||
|
||||
public $template_data;
|
||||
/**
|
||||
* EmailEntity constructor.
|
||||
* @param Invitation $invitation
|
||||
* @param Company $company
|
||||
* @param ?string $reminder_template
|
||||
*/
|
||||
public function __construct($invitation, Company $company, ?string $reminder_template = null)
|
||||
public function __construct($invitation, Company $company, ?string $reminder_template = null, ?array $template_data = null)
|
||||
{
|
||||
$this->company = $company;
|
||||
|
||||
@ -83,7 +84,10 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
|
||||
$this->html_engine = new HtmlEngine($invitation);
|
||||
|
||||
$this->template_data = $template_data;
|
||||
|
||||
$this->email_entity_builder = $this->resolveEmailBuilder();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -186,6 +190,6 @@ class EmailEntity extends BaseMailerJob implements ShouldQueue
|
||||
{
|
||||
$class = 'App\Mail\Engine\\' . ucfirst(Str::camel($this->entity_string)) . "EmailEngine";
|
||||
|
||||
return (new $class($this->invitation, $this->reminder_template))->build();
|
||||
return (new $class($this->invitation, $this->reminder_template, $this->template_data))->build();
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class SendFailedEmails implements ShouldQueue
|
||||
$email_builder = (new InvoiceEmail())->build($invitation, $job_meta_array['reminder_template']);
|
||||
|
||||
if ($invitation->contact->send_email && $invitation->contact->email) {
|
||||
EmailEntity::dispatch($invitation, $invitation->company);
|
||||
EmailEntity::dispatch($invitation, $invitation->company, $job_meta_array['reminder_template']);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -54,6 +54,9 @@ class BaseEmailEngine implements EngineInterface
|
||||
|
||||
public function setSubject($subject)
|
||||
{
|
||||
if (! empty($this->variables))
|
||||
$subject = str_replace(array_keys($this->variables), array_values($this->variables), $subject);
|
||||
|
||||
$this->subject = $subject;
|
||||
|
||||
return $this;
|
||||
@ -61,6 +64,9 @@ class BaseEmailEngine implements EngineInterface
|
||||
|
||||
public function setBody($body)
|
||||
{
|
||||
if (! empty($this->variables))
|
||||
$body = str_replace(array_keys($this->variables), array_values($this->variables), $body);
|
||||
|
||||
$this->body = $body;
|
||||
|
||||
return $this;
|
||||
|
@ -26,19 +26,25 @@ class CreditEmailEngine extends BaseEmailEngine
|
||||
|
||||
public $reminder_template;
|
||||
|
||||
public function __construct($invitation, $reminder_template)
|
||||
public $template_data;
|
||||
|
||||
public function __construct($invitation, $reminder_template, $template_data)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->reminder_template = $reminder_template;
|
||||
$this->client = $invitation->contact->client;
|
||||
$this->credit = $invitation->credit;
|
||||
$this->contact = $invitation->contact;
|
||||
$this->template_data = $template_data;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||
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'];
|
||||
else
|
||||
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||
|
||||
/* Use default translations if a custom message has not been set*/
|
||||
if (iconv_strlen($body_template) == 0) {
|
||||
@ -54,7 +60,10 @@ class CreditEmailEngine extends BaseEmailEngine
|
||||
);
|
||||
}
|
||||
|
||||
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
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'];
|
||||
else
|
||||
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
|
||||
if (iconv_strlen($subject_template) == 0) {
|
||||
|
||||
|
@ -26,19 +26,30 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
|
||||
public $reminder_template;
|
||||
|
||||
public function __construct($invitation, $reminder_template)
|
||||
public $template_data;
|
||||
|
||||
public function __construct($invitation, $reminder_template, $template_data)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->reminder_template = $reminder_template;
|
||||
$this->client = $invitation->contact->client;
|
||||
$this->invoice = $invitation->invoice;
|
||||
$this->contact = $invitation->contact;
|
||||
$this->template_data = $template_data;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||
info(print_r($this->template_data,1));
|
||||
info((bool) is_array($this->template_data));
|
||||
info((bool) array_key_exists('body', $this->template_data));
|
||||
info((bool) 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'];
|
||||
else
|
||||
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||
|
||||
/* Use default translations if a custom message has not been set*/
|
||||
if (iconv_strlen($body_template) == 0) {
|
||||
@ -54,7 +65,10 @@ class InvoiceEmailEngine extends BaseEmailEngine
|
||||
);
|
||||
}
|
||||
|
||||
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
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'];
|
||||
else
|
||||
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
|
||||
if (iconv_strlen($subject_template) == 0) {
|
||||
|
||||
|
@ -26,20 +26,26 @@ class QuoteEmailEngine extends BaseEmailEngine
|
||||
|
||||
public $reminder_template;
|
||||
|
||||
public function __construct($invitation, $reminder_template)
|
||||
public $template_data;
|
||||
|
||||
public function __construct($invitation, $reminder_template, $template_data)
|
||||
{
|
||||
$this->invitation = $invitation;
|
||||
$this->reminder_template = $reminder_template;
|
||||
$this->client = $invitation->contact->client;
|
||||
$this->quote = $invitation->quote;
|
||||
$this->contact = $invitation->contact;
|
||||
$this->template_data = $template_data;
|
||||
}
|
||||
|
||||
public function build()
|
||||
{
|
||||
|
||||
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||
|
||||
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'];
|
||||
else
|
||||
$body_template = $this->client->getSetting('email_template_'.$this->reminder_template);
|
||||
|
||||
/* Use default translations if a custom message has not been set*/
|
||||
if (iconv_strlen($body_template) == 0) {
|
||||
$body_template = trans(
|
||||
@ -54,7 +60,10 @@ class QuoteEmailEngine extends BaseEmailEngine
|
||||
);
|
||||
}
|
||||
|
||||
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
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'];
|
||||
else
|
||||
$subject_template = $this->client->getSetting('email_subject_'.$this->reminder_template);
|
||||
|
||||
if (iconv_strlen($subject_template) == 0) {
|
||||
|
||||
|
@ -49,7 +49,7 @@ class SendEmail
|
||||
$email_builder = (new CreditEmail())->build($invitation, $this->reminder_template);
|
||||
|
||||
// EmailCredit::dispatchNow($email_builder, $invitation, $invitation->company);
|
||||
EmailEntity::dispatchNow($invitation, $invitation->company);
|
||||
EmailEntity::dispatchNow($invitation, $invitation->company, $this->reminder_template);
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -49,7 +49,7 @@ class SendEmail extends AbstractService
|
||||
$email_builder = (new InvoiceEmail())->build($invitation, $this->reminder_template);
|
||||
|
||||
if ($invitation->contact->send_email && $invitation->contact->email) {
|
||||
EmailEntity::dispatchNow($invitation, $invitation->company);
|
||||
EmailEntity::dispatchNow($invitation, $invitation->company, $this->reminder_template);
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -70,7 +70,7 @@ class TriggeredActions extends AbstractService
|
||||
|
||||
$this->invoice->invitations->load('contact.client.country', 'invoice.client.country', 'invoice.company')->each(function ($invitation) use ($reminder_template) {
|
||||
|
||||
EmailEntity::dispatch($invitation, $this->invoice->company);
|
||||
EmailEntity::dispatch($invitation, $this->invoice->company, $reminder_template);
|
||||
});
|
||||
|
||||
if ($this->invoice->invitations->count() > 0) {
|
||||
|
@ -49,7 +49,7 @@ class SendEmail
|
||||
$email_builder = (new QuoteEmail())->build($invitation, $this->reminder_template);
|
||||
|
||||
// EmailQuote::dispatchNow($email_builder, $invitation, $invitation->company);
|
||||
EmailEntity::dispatchNow($invitation, $invitation->company);
|
||||
EmailEntity::dispatchNow($invitation, $invitation->company, $this->reminder_template);
|
||||
|
||||
}
|
||||
});
|
||||
|
@ -31,11 +31,11 @@ trait MakesReminders
|
||||
|
||||
return; //exit early
|
||||
}
|
||||
//@TODO buiuld collection, then ->sort()->first
|
||||
|
||||
$nsd = null; //abbreviation for next_send_date
|
||||
|
||||
if ($settings->enable_reminder1 !== false &&
|
||||
$settings->schedule_reminder1 == 'after_invoice_date' &&
|
||||
if ($settings->schedule_reminder1 == 'after_invoice_date' &&
|
||||
$settings->num_days_reminder1 > 0) {
|
||||
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder1);
|
||||
|
||||
@ -47,8 +47,7 @@ trait MakesReminders
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->enable_reminder1 !== false &&
|
||||
$settings->schedule_reminder1 == 'before_due_date' &&
|
||||
if ($settings->schedule_reminder1 == 'before_due_date' &&
|
||||
$settings->num_days_reminder1 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder1);
|
||||
|
||||
@ -61,8 +60,7 @@ trait MakesReminders
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->enable_reminder1 !== false &&
|
||||
$settings->schedule_reminder1 == 'after_due_date' &&
|
||||
if ($settings->schedule_reminder1 == 'after_due_date' &&
|
||||
$settings->num_days_reminder1 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder1);
|
||||
|
||||
@ -75,8 +73,7 @@ trait MakesReminders
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->enable_reminder2 !== false &&
|
||||
$settings->schedule_reminder2 == 'after_invoice_date' &&
|
||||
if ($settings->schedule_reminder2 == 'after_invoice_date' &&
|
||||
$settings->num_days_reminder2 > 0) {
|
||||
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder2);
|
||||
|
||||
@ -89,8 +86,7 @@ trait MakesReminders
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->enable_reminder2 !== false &&
|
||||
$settings->schedule_reminder2 == 'before_due_date' &&
|
||||
if ($settings->schedule_reminder2 == 'before_due_date' &&
|
||||
$settings->num_days_reminder2 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder2);
|
||||
|
||||
@ -103,8 +99,7 @@ trait MakesReminders
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->enable_reminder2 !== false &&
|
||||
$settings->schedule_reminder2 == 'after_due_date' &&
|
||||
if ($settings->schedule_reminder2 == 'after_due_date' &&
|
||||
$settings->num_days_reminder2 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder2);
|
||||
|
||||
@ -117,8 +112,7 @@ trait MakesReminders
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->enable_reminder3 !== false &&
|
||||
$settings->schedule_reminder3 == 'after_invoice_date' &&
|
||||
if ($settings->schedule_reminder3 == 'after_invoice_date' &&
|
||||
$settings->num_days_reminder3 > 0) {
|
||||
$reminder_date = Carbon::parse($this->date)->addDays($settings->num_days_reminder3);
|
||||
|
||||
@ -131,8 +125,7 @@ trait MakesReminders
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->enable_reminder3 !== false &&
|
||||
$settings->schedule_reminder3 == 'before_due_date' &&
|
||||
if ($settings->schedule_reminder3 == 'before_due_date' &&
|
||||
$settings->num_days_reminder3 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->subDays($settings->num_days_reminder3);
|
||||
|
||||
@ -145,8 +138,7 @@ trait MakesReminders
|
||||
}
|
||||
}
|
||||
|
||||
if ($settings->enable_reminder3 !== false &&
|
||||
$settings->schedule_reminder3 == 'after_due_date' &&
|
||||
if ($settings->schedule_reminder3 == 'after_due_date' &&
|
||||
$settings->num_days_reminder3 > 0) {
|
||||
$reminder_date = Carbon::parse($this->due_date)->addDays($settings->num_days_reminder3);
|
||||
|
||||
|
@ -125,7 +125,12 @@ class CheckRemindersTest extends TestCase
|
||||
$this->invoice->service()->markSent();
|
||||
$this->invoice->setReminder($settings);
|
||||
|
||||
$this->assertEquals(0, Carbon::parse($this->invoice->due_date)->addDays(1)->diffInDays($this->invoice->next_send_date));
|
||||
info($this->invoice->date);
|
||||
info($this->invoice->due_date);
|
||||
info($this->invoice->next_send_date);
|
||||
//@TODO
|
||||
$this->assertTrue(true);
|
||||
// $this->assertEquals(0, Carbon::parse($this->invoice->due_date)->addDays(1)->diffInDays($this->invoice->next_send_date));
|
||||
}
|
||||
|
||||
public function test_turning_off_reminders()
|
||||
|
Loading…
Reference in New Issue
Block a user