mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Working on refactor for emailables
This commit is contained in:
parent
a19a48ac92
commit
6a687c2aef
@ -235,12 +235,17 @@ class EmailTemplateDefaults
|
||||
|
||||
public static function emailStatementSubject()
|
||||
{
|
||||
return '';
|
||||
return ctrans('texts.your_statement');
|
||||
}
|
||||
|
||||
public static function emailStatementTemplate()
|
||||
{
|
||||
return '';
|
||||
|
||||
$statement_message = '<p>$client<br><br>'.self::transformText('client_statement_body').'<br><br>$invoices</p>';
|
||||
|
||||
return $statement_message;
|
||||
|
||||
// return ctrans('texts.client_statement_body', ['start_date' => '$start_date', 'end_date' => '$end_date']);
|
||||
}
|
||||
|
||||
private static function transformText($string)
|
||||
|
@ -455,16 +455,6 @@ class NinjaMailerJob implements ShouldQueue
|
||||
|
||||
$this->checkValidSendingUser($user);
|
||||
|
||||
/* Always ensure the user is set on the correct account */
|
||||
// if($user->account_id != $this->company->account_id){
|
||||
|
||||
// $this->nmo->settings->email_sending_method = 'default';
|
||||
// return $this->setMailDriver();
|
||||
|
||||
// }
|
||||
|
||||
$this->checkValidSendingUser($user);
|
||||
|
||||
nlog("Sending via {$user->name()}");
|
||||
|
||||
$google = (new Google())->init();
|
||||
|
@ -21,18 +21,6 @@ use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ClientStatement extends Mailable
|
||||
{
|
||||
|
||||
// 'to' => [],
|
||||
// 'from_email' => '',
|
||||
// 'from_name' => '',
|
||||
// 'reply_to' => '',
|
||||
// 'cc' => [],
|
||||
// 'bcc' => [],
|
||||
// 'subject' => ctrans('texts.your_statement'),
|
||||
// 'body' => ctrans('texts.client_statement_body', ['start_date' => $this->client_start_date, 'end_date' => $this->client_end_date]),
|
||||
// 'attachments' => [
|
||||
// ['name' => ctrans('texts.statement') . ".pdf", 'file' => base64_encode($pdf)],
|
||||
// ]
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
|
@ -11,15 +11,17 @@
|
||||
|
||||
namespace App\Services\Scheduler;
|
||||
|
||||
use App\DataMapper\EmailTemplateDefaults;
|
||||
use App\Mail\Client\ClientStatement;
|
||||
use App\Models\Client;
|
||||
use App\Models\Scheduler;
|
||||
use App\Services\Email\EmailMailable;
|
||||
use App\Services\Email\EmailObject;
|
||||
use App\Services\Email\EmailService;
|
||||
use App\Utils\Ninja;
|
||||
use App\Utils\Traits\MakesDates;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Mail\Mailables\Address;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class SchedulerService
|
||||
@ -62,11 +64,10 @@ class SchedulerService
|
||||
//work out the date range
|
||||
$pdf = $_client->service()->statement($statement_properties);
|
||||
|
||||
$mail_able_envelope = $this->buildMailableData($pdf);
|
||||
$email_service = new EmailService($this->buildMailableData($pdf), $_client->company);
|
||||
$email_service->send();
|
||||
|
||||
Mail::send($mail_able_envelope);
|
||||
|
||||
//calculate next run dates;
|
||||
//calculate next run dates;
|
||||
|
||||
});
|
||||
|
||||
@ -99,86 +100,19 @@ class SchedulerService
|
||||
'previous_quarter' => [now()->subQuarter()->firstOfQuarter()->format('Y-m-d'), now()->subQuarter()->lastOfQuarter()->format('Y-m-d')],
|
||||
'previous_year' => [now()->subYear()->firstOfYear()->format('Y-m-d'), now()->subYear()->lastOfYear()->format('Y-m-d')],
|
||||
'custom_range' => [$this->scheduler->parameters['start_date'], $this->scheduler->parameters['end_date']],
|
||||
'default' => [now()->firstOfMonth()->format('Y-m-d'), now()->lastOfMonth()->format('Y-m-d')],
|
||||
default => [now()->firstOfMonth()->format('Y-m-d'), now()->lastOfMonth()->format('Y-m-d')],
|
||||
};
|
||||
}
|
||||
|
||||
private function buildMailableData($pdf)
|
||||
{
|
||||
App::setLocale($this->client->locale());
|
||||
$primary_contact = $this->client->primary_contact()->first();
|
||||
$settings = $this->client->getMergedSettings();
|
||||
|
||||
App::forgetInstance('translator');
|
||||
$t = app('translator');
|
||||
$t->replace(Ninja::transformTranslations($settings));
|
||||
$email_object = new EmailObject;
|
||||
$email_object->to = [new Address($this->client->present()->email(), $this->client->present()->name())];
|
||||
$email_object->attachments = ['name' => ctrans('texts.statement') . ".pdf", 'file' => base64_encode($pdf)];
|
||||
|
||||
$data = [
|
||||
'to' => [new Address($this->client->present()->email(), $this->client->present()->name())],
|
||||
'from' => new Address($this->client->company->owner()->email, $this->client->company->owner()->name()),
|
||||
'reply_to' => [$this->buildReplyTo($settings)],
|
||||
'cc' => $this->buildCc($settings),
|
||||
'bcc' => $this->buildBcc($settings),
|
||||
'subject' => ctrans('texts.your_statement'),
|
||||
'body' => ctrans('texts.client_statement_body', ['start_date' => $this->client_start_date, 'end_date' => $this->client_end_date]),
|
||||
'attachments' => [
|
||||
['name' => ctrans('texts.statement') . ".pdf", 'file' => base64_encode($pdf)],
|
||||
],
|
||||
'company_key' => $this->client->company->company_key,
|
||||
'settings' => $settings,
|
||||
'whitelabel' => $this->client->user->account->isPaid() ? true : false,
|
||||
'logo' => $this->client->company->present()->logo($settings),
|
||||
'signature' => $settings->email_signature,
|
||||
'company' => $this->client->company,
|
||||
'greeting' => ctrans('texts.email_salutation', ['name' => $primary_contact->present()->name()]),
|
||||
];
|
||||
return $email_object;
|
||||
|
||||
return new ClientStatement($data);
|
||||
|
||||
}
|
||||
|
||||
private function buildReplyTo($settings)
|
||||
{
|
||||
|
||||
$reply_to_email = str_contains($settings->reply_to_email, "@") ? $settings->reply_to_email : $this->client->company->owner()->email;
|
||||
|
||||
$reply_to_name = strlen($settings->reply_to_name) > 3 ? $settings->reply_to_name : $this->client->company->owner()->present()->name();
|
||||
|
||||
return new Address($reply_to_email, $reply_to_name);
|
||||
|
||||
}
|
||||
|
||||
private function buildBcc($settings): array
|
||||
{
|
||||
$bccs = false;
|
||||
$bcc_array = [];
|
||||
|
||||
if (strlen($settings->bcc_email) > 1) {
|
||||
|
||||
if (Ninja::isHosted() && $this->client->company->account->isPaid()) {
|
||||
$bccs = array_slice(explode(',', str_replace(' ', '', $settings->bcc_email)), 0, 2);
|
||||
} else {
|
||||
$bccs(explode(',', str_replace(' ', '', $settings->bcc_email)));
|
||||
}
|
||||
}
|
||||
|
||||
if(!$bccs)
|
||||
return $bcc_array;
|
||||
|
||||
foreach($bccs as $bcc)
|
||||
{
|
||||
$bcc_array[] = new Address($bcc);
|
||||
}
|
||||
|
||||
return $bcc_array;
|
||||
|
||||
}
|
||||
|
||||
private function buildCc($settings)
|
||||
{
|
||||
return [
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user