diff --git a/app/Listeners/AnalyticsListener.php b/app/Listeners/AnalyticsListener.php index f9c21221a938..2596293793c0 100644 --- a/app/Listeners/AnalyticsListener.php +++ b/app/Listeners/AnalyticsListener.php @@ -23,7 +23,7 @@ class AnalyticsListener $invoice = $payment->invoice; $account = $payment->account; - if (! in_array($account->account_key, [NINJA_ACCOUNT_KEY, NINJA_LICENSE_ACCOUNT_KEY])) { + if ($account->isNinjaAccount() || $account->account_key == NINJA_LICENSE_ACCOUNT_KEY) { return; } diff --git a/app/Models/Account.php b/app/Models/Account.php index 8ef47d45b74f..0b5f882223fa 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -938,7 +938,7 @@ class Account extends Eloquent */ public function isNinjaAccount() { - return $this->account_key === NINJA_ACCOUNT_KEY; + return strpos($this->account_key, 'zg4ylmzDkdkPOT8yoKQw9LTWaoZJx7') === 0; } /** diff --git a/app/Ninja/PaymentDrivers/BasePaymentDriver.php b/app/Ninja/PaymentDrivers/BasePaymentDriver.php index be6f22002736..78e0d39b3b53 100644 --- a/app/Ninja/PaymentDrivers/BasePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BasePaymentDriver.php @@ -314,7 +314,7 @@ class BasePaymentDriver $payment = $this->createPayment($ref, $paymentMethod); // TODO move this to stripe driver - if ($this->invitation->invoice->account->account_key == NINJA_ACCOUNT_KEY) { + if ($this->invitation->invoice->account->isNinjaAccount()) { Session::flash('trackEventCategory', '/account'); Session::flash('trackEventAction', '/buy_pro_plan'); Session::flash('trackEventAmount', $payment->amount); @@ -642,7 +642,7 @@ class BasePaymentDriver $this->createLicense($payment); // TODO move this code // enable pro plan for hosted users - } elseif ($accountKey == NINJA_ACCOUNT_KEY) { + } elseif ($invoice->account->isNinjaAccount()) { foreach ($invoice->invoice_items as $invoice_item) { // Hacky, but invoices don't have meta fields to allow us to store this easily if (1 == preg_match('/^Plan - (.+) \((.+)\)$/', $invoice_item->product_key, $matches)) { diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php index e6e4ff8c8063..fc2dafd26c6a 100644 --- a/app/Ninja/Repositories/AccountRepository.php +++ b/app/Ninja/Repositories/AccountRepository.php @@ -335,7 +335,7 @@ class AccountRepository public function getNinjaAccount() { - $account = Account::whereAccountKey(NINJA_ACCOUNT_KEY)->first(); + $account = Account::where('account_key', 'LIKE', substr(NINJA_ACCOUNT_KEY, 0, 30) . '%')->orderBy('id')->first(); if ($account) { return $account; diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index cf7ffb09bf91..71ad93246d4b 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -279,7 +279,7 @@ class InvoiceRepository extends BaseRepository ->where('invoices.is_recurring', '=', false) ->where('invoices.is_public', '=', true) // Only show paid invoices for ninja accounts - ->whereRaw(sprintf("((accounts.account_key != '%s' and accounts.account_key != '%s') or invoices.invoice_status_id = %d)", env('NINJA_LICENSE_ACCOUNT_KEY'), NINJA_ACCOUNT_KEY, INVOICE_STATUS_PAID)) + ->whereRaw(sprintf("((accounts.account_key != '%s' and accounts.account_key not like '%s') or invoices.invoice_status_id = %d)", env('NINJA_LICENSE_ACCOUNT_KEY'), substr(NINJA_ACCOUNT_KEY, 0, 30), INVOICE_STATUS_PAID)) ->select( DB::raw('COALESCE(clients.currency_id, accounts.currency_id) currency_id'), DB::raw('COALESCE(clients.country_id, accounts.country_id) country_id'), diff --git a/resources/views/invoices/pdf.blade.php b/resources/views/invoices/pdf.blade.php index fb3332047efe..87bea8cab634 100644 --- a/resources/views/invoices/pdf.blade.php +++ b/resources/views/invoices/pdf.blade.php @@ -117,8 +117,9 @@ try { return getPDFString(refreshPDFCB, force); } catch (exception) { + console.warn('Failed to generate PDF'); var href = location.href; - if (href.indexOf('/view/') && href.indexOf('phantomjs') == -1) { + if (href.indexOf('/view/') > 0 && href.indexOf('phantomjs') == -1) { var url = href.replace('/view/', '/download/') + '?base64=true'; $.get(url, function(result) { refreshPDFCB(result); diff --git a/resources/views/invoices/view.blade.php b/resources/views/invoices/view.blade.php index c6e529a49508..f5fedaf28218 100644 --- a/resources/views/invoices/view.blade.php +++ b/resources/views/invoices/view.blade.php @@ -242,7 +242,7 @@ var fileName = invoice.is_quote ? invoiceLabels.quote : invoiceLabels.invoice; doc.save(fileName + '-' + invoice.invoice_number + '.pdf'); } catch (exception) { - if (location.href.indexOf('/view/')) { + if (location.href.indexOf('/view/') > 0) { location.href = location.href.replace('/view/', '/download/'); } }