From d48756ea792590f59cec1fcee97be89b04e516af Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 31 Jan 2021 16:07:45 +1100 Subject: [PATCH] Improvements to migration email --- app/Jobs/Util/Import.php | 2 +- app/Mail/MigrationCompleted.php | 13 ++- app/Models/Company.php | 5 ++ .../views/email/import/completed.blade.php | 87 ++++++++++++------- 4 files changed, 70 insertions(+), 37 deletions(-) diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index bc7efa8653..7aab42ff45 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -206,7 +206,7 @@ class Import implements ShouldQueue $this->setInitialCompanyLedgerBalances(); Mail::to($this->user) - ->send(new MigrationCompleted()); + ->send(new MigrationCompleted($this->company)); /*After a migration first some basic jobs to ensure the system is up to date*/ VersionCheck::dispatch(); diff --git a/app/Mail/MigrationCompleted.php b/app/Mail/MigrationCompleted.php index 301b91c60c..54f158ca9a 100644 --- a/app/Mail/MigrationCompleted.php +++ b/app/Mail/MigrationCompleted.php @@ -2,6 +2,7 @@ namespace App\Mail; +use App\Models\Company; use Illuminate\Bus\Queueable; use Illuminate\Mail\Mailable; use Illuminate\Queue\SerializesModels; @@ -10,14 +11,16 @@ class MigrationCompleted extends Mailable { use Queueable, SerializesModels; + public $company; + /** * Create a new message instance. * * @return void */ - public function __construct() + public function __construct(Company $company) { - // + $this->company = $company; } /** @@ -27,9 +30,11 @@ class MigrationCompleted extends Mailable */ public function build() { - $data['settings'] = auth()->user()->company()->settings; + $data['settings'] = $this->company->settings; + $data['company'] = $this->company; return $this->from(config('mail.from.address'), config('mail.from.name')) - ->view('email.migration.completed', $data); + ->view('email.import.completed', $data) + ->attach($this->company->invoices->first()->pdf_file_path()); } } diff --git a/app/Models/Company.php b/app/Models/Company.php index 90a266d18e..e02d87f0b0 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -373,6 +373,11 @@ class Company extends BaseModel return $this->hasMany(CompanyToken::class); } + public function client_gateway_tokens() + { + return $this->hasMany(ClientGatewayToken::class); + } + public function system_logs() { return $this->hasMany(SystemLog::class)->orderBy('id', 'DESC')->take(50); diff --git a/resources/views/email/import/completed.blade.php b/resources/views/email/import/completed.blade.php index 4f62a77bed..1eb858798f 100644 --- a/resources/views/email/import/completed.blade.php +++ b/resources/views/email/import/completed.blade.php @@ -6,51 +6,74 @@

Import completed

Hello, here is the output of your recent import job.

- @if(isset($clients) && count($clients) >=1) -

Clients Imported: {{ count($clients) }}

+

If your logo imported correctly it will display below. If it didn't import, you'll need to reupload your logo

+ +

+ + @if(isset($company) && count($company->clients) >=1) +

Clients Imported: {{ count($company->clients) }}

@endif - @if(isset($errors['clients']) && count($errors['clients']) >=1) -

Client Errors

- - + @if(isset($company) && count($company->products) >=1) +

Products Imported: {{ count($company->products) }}

@endif - @if(isset($invoices) && count($invoices) >=1) + @if(isset($company) && count($company->invoices) >=1) +

Invoices Imported: {{ count($company->invoices) }}

-

Invoices Imported: {{ count($invoices) }}

+

To test your PDF generation is working correctly, click here. We've also attempted to attach the PDF to this email. @endif - @if(isset($errors['invoices']) && count($errors['invoices']) >=1) -

Invoices Errors

- - + @if(isset($company) && count($company->payments) >=1) +

Payments Imported: {{ count($company->payments) }}

@endif - @if(isset($products) && count($products) >=1) -

Products Imported: {{ count($products) }}

+ @if(isset($company) && count($company->recurring_invoices) >=1) +

Recurring Invoices Imported: {{ count($company->recurring_invoices) }}

@endif - @if(isset($errors['products']) && count($errors['products']) >=1) -

Client Errors

- - + @if(isset($company) && count($company->quotes) >=1) +

Quotes Imported: {{ count($company->quotes) }}

@endif - Visit portal + @if(isset($company) && count($company->credits) >=1) +

Credits Imported: {{ count($company->credits) }}

+ @endif -

Thank you,
Invoice Ninja.

+ @if(isset($company) && count($company->projects) >=1) +

Projects Imported: {{ count($company->projects) }}

+ @endif + + @if(isset($company) && count($company->tasks) >=1) +

Tasks Imported: {{ count($company->tasks) }}

+ @endif + + @if(isset($company) && count($company->vendors) >=1) +

Vendors Imported: {{ count($company->vendors) }}

+ @endif + + @if(isset($company) && count($company->expenses) >=1) +

Expenses Imported: {{ count($company->expenses) }}

+ @endif + + @if(isset($company) && count($company->company_gateways) >=1) +

Gateways Imported: {{ count($company->company_gateways) }}

+ @endif + + @if(isset($company) && count($company->client_gateway_tokens) >=1) +

Client Gateway Tokens Imported: {{ count($company->client_gateway_tokens) }}

+ @endif + + @if(isset($company) && count($company->tax_rates) >=1) +

Tax Rates Imported: {{ count($company->tax_rates) }}

+ @endif + + @if(isset($company) && count($company->documents) >=1) +

Documents Imported: {{ count($company->documents) }}

+ @endif + + {{ ctrans('texts.account_login')}} + +

{{ ctrans('texts.email_signature')}}
{{ ctrans('texts.email_from') }}

@endcomponent