1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00

Merge pull request #4421 from turbo124/v5-develop

Fixes for email attachments and sending names
This commit is contained in:
David Bomba 2020-12-03 09:27:26 +11:00 committed by GitHub
commit 65f1ae024c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 49 additions and 37 deletions

View File

@ -294,7 +294,7 @@ class CheckData extends Command
$wrong_balances = 0;
$wrong_paid_to_dates = 0;
foreach (Client::cursor() as $client) {
foreach (Client::where('is_deleted', 0)->cursor() as $client) {
$invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance');
$credit_balance = $client->credits->where('is_deleted', false)->sum('balance');
@ -318,7 +318,7 @@ class CheckData extends Command
$wrong_paid_to_dates = 0;
$credit_total_applied = 0;
Client::withTrashed()->cursor()->each(function ($client) use ($wrong_paid_to_dates, $credit_total_applied) {
Client::withTrashed()->where('is_deleted', 0)->cursor()->each(function ($client) use ($wrong_paid_to_dates, $credit_total_applied) {
$total_invoice_payments = 0;
foreach ($client->invoices->where('is_deleted', false)->where('status_id', '>', 1) as $invoice) {
@ -358,7 +358,7 @@ class CheckData extends Command
$wrong_balances = 0;
$wrong_paid_to_dates = 0;
Client::cursor()->each(function ($client) use ($wrong_balances) {
Client::cursor()->where('is_deleted', 0)->each(function ($client) use ($wrong_balances) {
$client->invoices->where('is_deleted', false)->whereIn('status_id', '!=', Invoice::STATUS_DRAFT)->each(function ($invoice) use ($wrong_balances, $client) {
$total_amount = $invoice->payments->whereIn('status_id', [Payment::STATUS_PAID, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.amount');
$total_refund = $invoice->payments->whereIn('status_id', [Payment::STATUS_PAID, Payment:: STATUS_PENDING, Payment::STATUS_PARTIALLY_REFUNDED])->sum('pivot.refunded');
@ -385,7 +385,7 @@ class CheckData extends Command
$wrong_balances = 0;
$wrong_paid_to_dates = 0;
foreach (Client::cursor() as $client) {
foreach (Client::cursor()->where('is_deleted', 0) as $client) {
//$invoice_balance = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance');
$invoice_balance = Invoice::where('client_id', $client->id)->where('is_deleted', false)->where('status_id', '>', 1)->withTrashed()->sum('balance');
$client_balance = Credit::where('client_id', $client->id)->where('is_deleted', false)->withTrashed()->sum('balance');

View File

@ -13,6 +13,7 @@ namespace App\Http\Requests\Project;
use App\Http\Requests\Request;
use App\Utils\Traits\ChecksEntityStatus;
use Illuminate\Validation\Rule;
class UpdateProjectRequest extends Request
{

View File

@ -77,6 +77,8 @@ class BaseMailerJob implements ShouldQueue
Config::set('mail.driver', 'gmail');
Config::set('services.gmail.token', $user->oauth_user_token->access_token);
Config::set('mail.from.address', $user->email);
Config::set('mail.from.name', $user->present()->name());
(new MailServiceProvider(app()))->register();
}

View File

@ -77,7 +77,7 @@ class EntityPaidMailer extends BaseMailerJob implements ShouldQueue
try {
$mail_obj = (new EntityPaidObject($this->payment))->build();
$mail_obj->from = [$this->user->email, $this->user->present()->name()];
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
//send email
Mail::to($this->user->email)

View File

@ -81,7 +81,7 @@ class EntitySentMailer extends BaseMailerJob implements ShouldQueue
$this->setMailDriver();
$mail_obj = (new EntitySentObject($this->invitation, $this->entity_type))->build();
$mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()];
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
try {
Mail::to($this->user->email)

View File

@ -81,7 +81,7 @@ class EntityViewedMailer extends BaseMailerJob implements ShouldQueue
$this->setMailDriver();
$mail_obj = (new EntityViewedObject($this->invitation, $this->entity_type))->build();
$mail_obj->from = [$this->entity->user->email, $this->entity->user->present()->name()];
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
//send email
try {

View File

@ -91,7 +91,7 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
unset($methods[$key]);
$mail_obj = (new PaymentFailureObject($this->client, $this->message, $this->amount, $this->company))->build();
$mail_obj->from = [$this->company->owner()->email, $this->company->owner()->present()->name()];
$mail_obj->from = [config('mail.from.address'), config('mail.from.name')];
//send email
try {

View File

@ -200,7 +200,8 @@ class Import implements ShouldQueue
$this->setInitialCompanyLedgerBalances();
Mail::to($this->user)->send(new MigrationCompleted());
Mail::to($this->user)
->send(new MigrationCompleted());
/*After a migration first some basic jobs to ensure the system is up to date*/
VersionCheck::dispatch();

View File

@ -34,7 +34,7 @@ class EntityNotificationMailer extends Mailable
*/
public function build()
{
return $this->from($this->mail_obj->from[0], $this->mail_obj->from[1])
return $this->from(config('mail.from.address'), config('mail.from.name'))
->subject($this->mail_obj->subject)
->markdown($this->mail_obj->markdown, $this->mail_obj->data)
->withSwiftMessage(function ($message) {

View File

@ -45,7 +45,7 @@ class BouncedEmail extends Mailable implements ShouldQueue
$subject = ctrans("texts.notification_{$entity_type}_bounced_subject", ['invoice' => $invoice->number]);
return
$this->from($invitation->user->email)
$this->from(config('mail.from.name'), config('mail.from.address'))
->text()
->subject($subject);

View File

@ -30,7 +30,9 @@ class DownloadInvoices extends Mailable
*/
public function build()
{
return $this->subject(ctrans('texts.download_files'))
return $this->from(config('mail.from.name'), config('mail.from.address'))
->subject(ctrans('texts.download_files'))
->markdown(
'email.admin.download_files',
[

View File

@ -25,7 +25,7 @@ class BaseEmailEngine implements EngineInterface
public $template_style;
public $attachments;
public $attachments = [];
public $link;
@ -83,7 +83,8 @@ class BaseEmailEngine implements EngineInterface
public function setAttachments($attachments)
{
$this->attachments = $attachments;
$this->attachments = array_merge($this->getAttachments(), $attachments);
return $this;
}

View File

@ -88,7 +88,7 @@ class CreditEmailEngine extends BaseEmailEngine
->setViewText(ctrans('texts.view_credit'));
if ($this->client->getSetting('pdf_email_attachment') !== false) {
$this->setAttachments($invitation->pdf_file_path());
$this->setAttachments([$this->credit->pdf_file_path()]);
}
return $this;

View File

@ -97,7 +97,7 @@ class InvoiceEmailEngine extends BaseEmailEngine
->setViewText(ctrans('texts.view_invoice'));
if ($this->client->getSetting('pdf_email_attachment') !== false) {
$this->setAttachments($this->invoice->pdf_file_path());
$this->setAttachments([$this->invoice->pdf_file_path()]);
}
return $this;

View File

@ -88,7 +88,7 @@ class QuoteEmailEngine extends BaseEmailEngine
->setViewText(ctrans('texts.view_quote'));
if ($this->client->getSetting('pdf_email_attachment') !== false) {
$this->setAttachments($this->invitation->pdf_file_path());
$this->setAttachments([$this->invitation->pdf_file_path()]);
}
return $this;

View File

@ -27,6 +27,8 @@ class ExistingMigration extends Mailable
*/
public function build()
{
return $this->view('email.migration.existing');
return $this->from(config('mail.from.name'), config('mail.from.address'))
->view('email.migration.existing');
}
}

View File

@ -27,6 +27,6 @@ class InvoiceWasPaid extends Mailable
*/
public function build()
{
return $this->view('email.invoices.paid');
return $this->from(config('mail.from.address'), config('mail.from.name'))->view('email.invoices.paid');
}
}

View File

@ -29,6 +29,7 @@ class MigrationCompleted extends Mailable
{
$data['settings'] = auth()->user()->company()->settings;
return $this->view('email.migration.completed', $data);
return $this->from(config('mail.from.name'), config('mail.from.address'))
->view('email.migration.completed', $data);
}
}

View File

@ -31,7 +31,8 @@ class MigrationFailed extends Mailable
*/
public function build()
{
return $this->from('noreply@invoiceninja.com')
return $this->from(config('mail.from.name'), config('mail.from.address'))
->view('email.migration.failed');
}
}

View File

@ -27,6 +27,6 @@ class QuoteWasApproved extends Mailable
*/
public function build()
{
return $this->view('email.quotes.approved');
return $this->from(config('mail.from.address'), config('mail.from.name'))->view('email.quotes.approved');
}
}

View File

@ -59,7 +59,7 @@ class SupportMessageSent extends Mailable
$subject = "Customer MSG {$user->present()->name} - [{$plan} - DB:{$company->db}]";
return $this->from(config('mail.from.address')) //todo this needs to be fixed to handle the hosted version
return $this->from(config('mail.from.address'), config('mail.from.name')) //todo this needs to be fixed to handle the hosted version
->subject($subject)
->markdown('email.support.message', [
'message' => $this->message,

View File

@ -52,7 +52,7 @@ class TemplateEmail extends Mailable
$company = $this->client->company;
$this->from($this->user->email, $this->user->present()->name());
$this->from(config('mail.from.address'), config('mail.from.name'));
if (strlen($settings->reply_to_email) > 1) {
$this->replyTo($settings->reply_to_email, $settings->reply_to_email);

View File

@ -36,7 +36,7 @@ class TestMailServer extends Mailable
*/
public function build()
{
return $this->from($this->from_email) //todo this needs to be fixed to handle the hosted version
return $this->from(config('mail.from.address'), config('mail.from.name'))
->subject(ctrans('texts.email'))
->markdown('email.support.message', [
'message' => $this->message,

View File

@ -34,7 +34,7 @@ class UserNotificationMailer extends Mailable
*/
public function build()
{
return $this->from($this->mail_obj->from[0], $this->mail_obj->from[1]) //todo
return $this->from(config('mail.from.address'), config('mail.from.name'))
->subject($this->mail_obj->subject)
->markdown($this->mail_obj->markdown, $this->mail_obj->data)
->withSwiftMessage(function ($message) {

View File

@ -23,6 +23,7 @@ return [
'date_time_format' => 'Y-m-d H:i',
'daily_email_limit' => 300,
'error_email' => env('ERROR_EMAIL', ''),
'mailer' => env('MAIL_MAILER',''),
'company_id' => 0,
'hash_salt' => env('HASH_SALT', ''),
'currency_converter_api_key' => env('OPENEXCHANGE_APP_ID', ''),