diff --git a/app/DataMapper/EmailTemplateDefaults.php b/app/DataMapper/EmailTemplateDefaults.php index bd281b4d87bf..e4f8c0c6ebc2 100644 --- a/app/DataMapper/EmailTemplateDefaults.php +++ b/app/DataMapper/EmailTemplateDefaults.php @@ -123,7 +123,7 @@ class EmailTemplateDefaults public static function emailInvoiceTemplate() { - $invoice_message = '

'.self::transformText('invoice_message').'

$view_link
'; + $invoice_message = '

'.self::transformText('invoice_message').'

$view_button
'; return $invoice_message; } @@ -135,7 +135,7 @@ class EmailTemplateDefaults public static function emailQuoteTemplate() { - $quote_message = '

'.self::transformText('quote_message').'

$view_link
'; + $quote_message = '

'.self::transformText('quote_message').'

$view_button
'; return $quote_message; } @@ -147,21 +147,21 @@ class EmailTemplateDefaults public static function emailPaymentTemplate() { - $payment_message = '

'.self::transformText('payment_message').'

$view_link
'; + $payment_message = '

'.self::transformText('payment_message').'

$view_button
'; return $payment_message; } public static function emailCreditTemplate() { - $credit_message = '

'.self::transformText('credit_message').'

$view_link
'; + $credit_message = '

'.self::transformText('credit_message').'

$view_button
'; return $credit_message; } public static function emailPaymentPartialTemplate() { - $payment_message = '

'.self::transformText('payment_message').'

$view_link
'; + $payment_message = '

'.self::transformText('payment_message').'

$view_button
'; return $payment_message; } diff --git a/app/Http/Controllers/CreditController.php b/app/Http/Controllers/CreditController.php index 6478dd1ebfbc..871034337f9f 100644 --- a/app/Http/Controllers/CreditController.php +++ b/app/Http/Controllers/CreditController.php @@ -589,14 +589,20 @@ class CreditController extends BaseController public function downloadPdf($invitation_key) { $invitation = $this->credit_repository->getInvitationByKey($invitation_key); - // $contact = $invitation->contact; + $credit = $invitation->credit; $file = $credit->service()->getCreditPdf($invitation); + $headers = ['Content-Type' => 'application/pdf']; + + if(request()->input('inline') == 'true') + $headers = array_merge($headers, ['Content-Disposition' => 'inline']); + return response()->streamDownload(function () use($file) { echo Storage::get($file); - }, basename($file), ['Content-Type' => 'application/pdf']); + }, basename($file), $headers); + } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 1e831d4bae8c..dbbddde36c60 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -804,9 +804,15 @@ class InvoiceController extends BaseController $file = $invoice->service()->getInvoicePdf($contact); + $headers = ['Content-Type' => 'application/pdf']; + + if(request()->input('inline') == 'true') + $headers = array_merge($headers, ['Content-Disposition' => 'inline']); + return response()->streamDownload(function () use($file) { echo Storage::get($file); - }, basename($file), ['Content-Type' => 'application/pdf']); + }, basename($file), $headers); + } /** diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index c47fa3f2178a..843818fabc23 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -740,11 +740,16 @@ class QuoteController extends BaseController $file = $quote->service()->getQuotePdf($contact); + $headers = ['Content-Type' => 'application/pdf']; + + if(request()->input('inline') == 'true') + $headers = array_merge($headers, ['Content-Disposition' => 'inline']); + return response()->streamDownload(function () use($file) { echo Storage::get($file); - }, basename($file), ['Content-Type' => 'application/pdf']); + }, basename($file), $headers); + - // return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true); } /** diff --git a/app/Jobs/Company/CompanyExport.php b/app/Jobs/Company/CompanyExport.php index 77f92407693a..571913ee0438 100644 --- a/app/Jobs/Company/CompanyExport.php +++ b/app/Jobs/Company/CompanyExport.php @@ -514,7 +514,7 @@ class CompanyExport implements ShouldQueue $nmo->company = $company_reference; $nmo->settings = $this->company->settings; - NinjaMailerJob::dispatch($nmo); + NinjaMailerJob::dispatch($nmo, true); if(Ninja::isHosted()){ sleep(3); diff --git a/app/Jobs/Company/CompanyImport.php b/app/Jobs/Company/CompanyImport.php index 9ae53dcf011e..fc7aa0b4aece 100644 --- a/app/Jobs/Company/CompanyImport.php +++ b/app/Jobs/Company/CompanyImport.php @@ -13,6 +13,7 @@ namespace App\Jobs\Company; use App\Exceptions\ImportCompanyFailed; use App\Exceptions\NonExistingMigrationFile; +use App\Factory\ClientContactFactory; use App\Jobs\Mail\NinjaMailerJob; use App\Jobs\Mail\NinjaMailerObject; use App\Jobs\Util\UnlinkFile; @@ -65,14 +66,15 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; +use JsonMachine\JsonDecoder\ExtJsonDecoder; +use JsonMachine\JsonMachine; use ZipArchive; use ZipStream\Option\Archive; use ZipStream\ZipStream; -use JsonMachine\JsonMachine; -use JsonMachine\JsonDecoder\ExtJsonDecoder; class CompanyImport implements ShouldQueue { @@ -208,7 +210,8 @@ class CompanyImport implements ShouldQueue $this->preFlightChecks() ->purgeCompanyData() - ->importData(); + ->importData() + ->postImportCleanup(); $data = [ 'errors' => [] @@ -234,11 +237,31 @@ class CompanyImport implements ShouldQueue } + // + private function postImportCleanup() + { + //ensure all clients have a contact + + $this->company + ->clients() + ->whereDoesntHave('contacts') + ->cursor() + ->each(function ($client){ + + $new_contact = ClientContactFactory::create($client->company_id, $client->user_id); + $new_contact->client_id = $client->id; + $new_contact->contact_key = Str::random(40); + $new_contact->is_primary = true; + $new_contact->confirmed = true; + $new_contact->email = ' '; + $new_contact->save(); + + }); + + } + private function unzipFile() { - - // if(mime_content_type(Storage::path($this->file_location)) == 'text/plain') - // return Storage::path($this->file_location); $path = TempFile::filePath(Storage::disk(config('filesystems.default'))->get($this->file_location), basename($this->file_location)); @@ -1391,13 +1414,16 @@ class CompanyImport implements ShouldQueue private function sendImportMail($message){ + App::forgetInstance('translator'); + $t = app('translator'); + $t->replace(Ninja::transformTranslations($this->company->settings)); - $nmo = new NinjaMailerObject; - $nmo->mailable = new CompanyImportFailure($this->company, $message); - $nmo->company = $this->company; - $nmo->settings = $this->company->settings; - $nmo->to_user = $this->company->owner(); - NinjaMailerJob::dispatchNow($nmo); + $nmo = new NinjaMailerObject; + $nmo->mailable = new CompanyImportFailure($this->company, $message); + $nmo->company = $this->company; + $nmo->settings = $this->company->settings; + $nmo->to_user = $this->company->owner(); + NinjaMailerJob::dispatchNow($nmo); } } \ No newline at end of file diff --git a/app/Jobs/Util/WebhookHandler.php b/app/Jobs/Util/WebhookHandler.php index da2419ea3306..aad1fb2d537a 100644 --- a/app/Jobs/Util/WebhookHandler.php +++ b/app/Jobs/Util/WebhookHandler.php @@ -120,7 +120,7 @@ class WebhookHandler implements ShouldQueue SystemLog::CATEGORY_WEBHOOK, SystemLog::EVENT_WEBHOOK_SUCCESS, SystemLog::TYPE_WEBHOOK_RESPONSE, - $this->company->clients->first(), + $this->resolveClient(), $this->company ); @@ -137,7 +137,7 @@ class WebhookHandler implements ShouldQueue SystemLog::CATEGORY_WEBHOOK, SystemLog::EVENT_WEBHOOK_RESPONSE, SystemLog::TYPE_WEBHOOK_RESPONSE, - $this->company->clients->first(), + $this->resolveClient(), $this->company, ); @@ -145,6 +145,15 @@ class WebhookHandler implements ShouldQueue } + private function resolveClient() + { + if($this->entity->client()->exists()){ + return $this->entity->client; + } + + return $this->company->clients->first(); + } + public function failed($exception) { nlog(print_r($exception->getMessage(), 1)); diff --git a/app/Mail/Engine/PaymentEmailEngine.php b/app/Mail/Engine/PaymentEmailEngine.php index 85caa5de8ff2..ed36c8ae321f 100644 --- a/app/Mail/Engine/PaymentEmailEngine.php +++ b/app/Mail/Engine/PaymentEmailEngine.php @@ -135,6 +135,7 @@ class PaymentEmailEngine extends BaseEmailEngine { $data = []; + $data['$from'] = ['value' => '', 'label' => ctrans('texts.from')]; $data['$to'] = ['value' => '', 'label' => ctrans('texts.to')]; $data['$number'] = ['value' => $this->payment->number ?: ' ', 'label' => ctrans('texts.payment_number')]; @@ -227,6 +228,7 @@ class PaymentEmailEngine extends BaseEmailEngine $data['$company4'] = ['value' => $this->helpers->formatCustomFieldValue($this->company->custom_fields, 'company4', $this->settings->custom_value4, $this->client) ?: ' ', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'company4')]; $data['$view_link'] = ['value' => ''.ctrans('texts.view_payment').'', 'label' => ctrans('texts.view_payment')]; + $data['$view_button'] = &$data['$view_link']; $data['$paymentLink'] = &$data['$view_link']; $data['$portalButton'] = ['value' => "".ctrans('texts.login')."", 'label' =>'']; $data['$portal_url'] = &$data['$portalButton']; diff --git a/app/Observers/InvoiceObserver.php b/app/Observers/InvoiceObserver.php index 606d37c50a80..609d1e912291 100644 --- a/app/Observers/InvoiceObserver.php +++ b/app/Observers/InvoiceObserver.php @@ -30,7 +30,7 @@ class InvoiceObserver public function created(Invoice $invoice) { - $subscriptions = Webhook::where('company_id', $invoice->company->id) + $subscriptions = Webhook::where('company_id', $invoice->company_id) ->where('event_id', Webhook::EVENT_CREATE_INVOICE) ->exists(); @@ -47,7 +47,7 @@ class InvoiceObserver */ public function updated(Invoice $invoice) { - $subscriptions = Webhook::where('company_id', $invoice->company->id) + $subscriptions = Webhook::where('company_id', $invoice->company_id) ->where('event_id', Webhook::EVENT_UPDATE_INVOICE) ->exists(); @@ -65,7 +65,7 @@ class InvoiceObserver */ public function deleted(Invoice $invoice) { - $subscriptions = Webhook::where('company_id', $invoice->company->id) + $subscriptions = Webhook::where('company_id', $invoice->company_id) ->where('event_id', Webhook::EVENT_DELETE_INVOICE) ->exists(); diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 991a0895e8e2..0401c14a3868 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -132,6 +132,7 @@ class HtmlEngine $data['$view_link'] = ['value' => ''.ctrans('texts.view_invoice').'', 'label' => ctrans('texts.view_invoice')]; $data['$viewLink'] = &$data['$view_link']; $data['$viewButton'] = &$data['$view_link']; + $data['$view_button'] = &$data['$view_link']; $data['$paymentButton'] = &$data['$view_link']; $data['$view_url'] = ['value' => $this->invitation->getLink(), 'label' => ctrans('texts.view_invoice')]; $data['$date'] = ['value' => $this->translateDate($this->entity->date, $this->entity->client->date_format(), $this->entity->client->locale()) ?: ' ', 'label' => ctrans('texts.invoice_date')]; diff --git a/resources/views/index/index.blade.php b/resources/views/index/index.blade.php index 03f70989f814..bf4de0c63056 100644 --- a/resources/views/index/index.blade.php +++ b/resources/views/index/index.blade.php @@ -1,5 +1,5 @@ - +