diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 24b869e48374..05b3db324400 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -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'); diff --git a/app/Http/Requests/Project/UpdateProjectRequest.php b/app/Http/Requests/Project/UpdateProjectRequest.php index 66e3c72f5887..20a951f06c44 100644 --- a/app/Http/Requests/Project/UpdateProjectRequest.php +++ b/app/Http/Requests/Project/UpdateProjectRequest.php @@ -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 { diff --git a/app/Jobs/Mail/BaseMailerJob.php b/app/Jobs/Mail/BaseMailerJob.php index cddb89bbb72c..d0649ba73fc7 100644 --- a/app/Jobs/Mail/BaseMailerJob.php +++ b/app/Jobs/Mail/BaseMailerJob.php @@ -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(); } diff --git a/app/Jobs/Mail/EntityPaidMailer.php b/app/Jobs/Mail/EntityPaidMailer.php index a2ad45ed1494..01d8eb635f37 100644 --- a/app/Jobs/Mail/EntityPaidMailer.php +++ b/app/Jobs/Mail/EntityPaidMailer.php @@ -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) diff --git a/app/Jobs/Mail/EntitySentMailer.php b/app/Jobs/Mail/EntitySentMailer.php index 175159b7669b..4ee370f43cf7 100644 --- a/app/Jobs/Mail/EntitySentMailer.php +++ b/app/Jobs/Mail/EntitySentMailer.php @@ -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) diff --git a/app/Jobs/Mail/EntityViewedMailer.php b/app/Jobs/Mail/EntityViewedMailer.php index 1bd22f5e1ddd..416250264034 100644 --- a/app/Jobs/Mail/EntityViewedMailer.php +++ b/app/Jobs/Mail/EntityViewedMailer.php @@ -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 { diff --git a/app/Jobs/Mail/PaymentFailureMailer.php b/app/Jobs/Mail/PaymentFailureMailer.php index 2f59c93f3384..73f570729cfd 100644 --- a/app/Jobs/Mail/PaymentFailureMailer.php +++ b/app/Jobs/Mail/PaymentFailureMailer.php @@ -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 { diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 54c5378c5efb..b3b30d3c724c 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -199,8 +199,9 @@ 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(); diff --git a/app/Mail/Admin/EntityNotificationMailer.php b/app/Mail/Admin/EntityNotificationMailer.php index 9f91d113672e..344e161d78e8 100644 --- a/app/Mail/Admin/EntityNotificationMailer.php +++ b/app/Mail/Admin/EntityNotificationMailer.php @@ -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) { diff --git a/app/Mail/BouncedEmail.php b/app/Mail/BouncedEmail.php index ef7c59827eb9..7aaedccff532 100644 --- a/app/Mail/BouncedEmail.php +++ b/app/Mail/BouncedEmail.php @@ -43,9 +43,9 @@ class BouncedEmail extends Mailable implements ShouldQueue $entity_type = class_basename(lcfirst($this->invitation->getEntityType())); $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); diff --git a/app/Mail/DownloadInvoices.php b/app/Mail/DownloadInvoices.php index 9d6720c89162..2c65d34ee125 100644 --- a/app/Mail/DownloadInvoices.php +++ b/app/Mail/DownloadInvoices.php @@ -30,13 +30,15 @@ class DownloadInvoices extends Mailable */ public function build() { - return $this->subject(ctrans('texts.download_files')) - ->markdown( - 'email.admin.download_files', - [ - 'url' => $this->file_path, - 'logo' => $this->company->present()->logo, - ] - ); + + return $this->from(config('mail.from.name'), config('mail.from.address')) + ->subject(ctrans('texts.download_files')) + ->markdown( + 'email.admin.download_files', + [ + 'url' => $this->file_path, + 'logo' => $this->company->present()->logo, + ] + ); } } diff --git a/app/Mail/Engine/BaseEmailEngine.php b/app/Mail/Engine/BaseEmailEngine.php index 37c13c1f263b..f1b8a7b6cc53 100644 --- a/app/Mail/Engine/BaseEmailEngine.php +++ b/app/Mail/Engine/BaseEmailEngine.php @@ -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; } diff --git a/app/Mail/Engine/CreditEmailEngine.php b/app/Mail/Engine/CreditEmailEngine.php index 7cbcbc0ec44b..71a2e01e15e3 100644 --- a/app/Mail/Engine/CreditEmailEngine.php +++ b/app/Mail/Engine/CreditEmailEngine.php @@ -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; diff --git a/app/Mail/Engine/InvoiceEmailEngine.php b/app/Mail/Engine/InvoiceEmailEngine.php index af72ac485fe9..711b4bdc6dc7 100644 --- a/app/Mail/Engine/InvoiceEmailEngine.php +++ b/app/Mail/Engine/InvoiceEmailEngine.php @@ -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; diff --git a/app/Mail/Engine/QuoteEmailEngine.php b/app/Mail/Engine/QuoteEmailEngine.php index eeea79ccc26a..02ca6150beb4 100644 --- a/app/Mail/Engine/QuoteEmailEngine.php +++ b/app/Mail/Engine/QuoteEmailEngine.php @@ -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; diff --git a/app/Mail/ExistingMigration.php b/app/Mail/ExistingMigration.php index b9b657daa2f1..596947b7fcab 100644 --- a/app/Mail/ExistingMigration.php +++ b/app/Mail/ExistingMigration.php @@ -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'); } } diff --git a/app/Mail/Invoices/InvoiceWasPaid.php b/app/Mail/Invoices/InvoiceWasPaid.php index 72979b88a829..3dc64bf16f0f 100644 --- a/app/Mail/Invoices/InvoiceWasPaid.php +++ b/app/Mail/Invoices/InvoiceWasPaid.php @@ -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'); } } diff --git a/app/Mail/MigrationCompleted.php b/app/Mail/MigrationCompleted.php index 988b36c0f819..358a15a6c3bc 100644 --- a/app/Mail/MigrationCompleted.php +++ b/app/Mail/MigrationCompleted.php @@ -28,7 +28,8 @@ class MigrationCompleted extends Mailable public function build() { $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); } } diff --git a/app/Mail/MigrationFailed.php b/app/Mail/MigrationFailed.php index 71bb53cfac9e..545736fd0bf3 100644 --- a/app/Mail/MigrationFailed.php +++ b/app/Mail/MigrationFailed.php @@ -31,7 +31,8 @@ class MigrationFailed extends Mailable */ public function build() { - return $this->from('noreply@invoiceninja.com') - ->view('email.migration.failed'); + + return $this->from(config('mail.from.name'), config('mail.from.address')) + ->view('email.migration.failed'); } } diff --git a/app/Mail/Quote/QuoteWasApproved.php b/app/Mail/Quote/QuoteWasApproved.php index dbe095b577af..a5b9a7348776 100644 --- a/app/Mail/Quote/QuoteWasApproved.php +++ b/app/Mail/Quote/QuoteWasApproved.php @@ -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'); } } diff --git a/app/Mail/SupportMessageSent.php b/app/Mail/SupportMessageSent.php index cfecff8ce2c5..8c71d9fed9c4 100644 --- a/app/Mail/SupportMessageSent.php +++ b/app/Mail/SupportMessageSent.php @@ -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, diff --git a/app/Mail/TemplateEmail.php b/app/Mail/TemplateEmail.php index 464eac9ea25f..0154a12752ef 100644 --- a/app/Mail/TemplateEmail.php +++ b/app/Mail/TemplateEmail.php @@ -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); diff --git a/app/Mail/TestMailServer.php b/app/Mail/TestMailServer.php index e392e121b334..ee1ebde3dd9d 100644 --- a/app/Mail/TestMailServer.php +++ b/app/Mail/TestMailServer.php @@ -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, diff --git a/app/Mail/User/UserNotificationMailer.php b/app/Mail/User/UserNotificationMailer.php index 97a56513871b..4a55a368042f 100644 --- a/app/Mail/User/UserNotificationMailer.php +++ b/app/Mail/User/UserNotificationMailer.php @@ -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) { diff --git a/config/ninja.php b/config/ninja.php index 53e91347349e..7276e438f2ea 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -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', ''),