From d4bfca46bccbc626665873b1512a895ef79ac613 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Jan 2021 21:59:24 +1100 Subject: [PATCH 1/6] Fixes for reminder job --- app/DataMapper/FeesAndLimits.php | 3 +++ app/Jobs/Util/ReminderJob.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/DataMapper/FeesAndLimits.php b/app/DataMapper/FeesAndLimits.php index ecb51cc0130f..922a6cb486c1 100644 --- a/app/DataMapper/FeesAndLimits.php +++ b/app/DataMapper/FeesAndLimits.php @@ -37,9 +37,12 @@ class FeesAndLimits public $adjust_fee_percent = false; + public $is_enabled = true; + //public $gateway_type_id = 1; public static $casts = [ + 'is_enabled' => 'bool', 'gateway_type_id' => 'int', 'min_limit' => 'float', 'max_limit' => 'float', diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index ea72979d617d..f6f53f176229 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -58,7 +58,7 @@ class ReminderJob implements ShouldQueue Invoice::where('next_send_date', Carbon::today()->format('Y-m-d'))->with('invitations')->cursor()->each(function ($invoice) { if ($invoice->isPayable()) { $reminder_template = $invoice->calculateTemplate('invoice'); - $invoice->service()->touchReminder($this->reminder_template)->save(); + $invoice->service()->touchReminder($reminder_template)->save(); $invoice->invitations->each(function ($invitation) use ($invoice, $reminder_template) { EmailEntity::dispatch($invitation, $invitation->company, $reminder_template); From 81da8e169d4229a50689eb288742a54105a51225 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Jan 2021 22:06:26 +1100 Subject: [PATCH 2/6] Add documents to groups --- app/Http/Controllers/GroupSettingController.php | 5 +++++ app/Models/GroupSetting.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/app/Http/Controllers/GroupSettingController.php b/app/Http/Controllers/GroupSettingController.php index 1f79f7838dc8..8f7f828270e0 100644 --- a/app/Http/Controllers/GroupSettingController.php +++ b/app/Http/Controllers/GroupSettingController.php @@ -22,6 +22,7 @@ use App\Models\GroupSetting; use App\Repositories\GroupSettingRepository; use App\Transformers\GroupSettingTransformer; use App\Utils\Traits\MakesHash; +use App\Utils\Traits\SavesDocuments; use App\Utils\Traits\Uploadable; use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Http\Request; @@ -32,6 +33,7 @@ class GroupSettingController extends BaseController use DispatchesJobs; use Uploadable; use MakesHash; + use SavesDocuments; protected $entity_type = GroupSetting::class; @@ -357,6 +359,9 @@ class GroupSettingController extends BaseController $this->uploadLogo($request->file('company_logo'), $group_setting->company, $group_setting); + if ($request->has('documents')) + $this->saveDocuments($request->input('documents'), $group_setting, false); + return $this->itemResponse($group_setting); } diff --git a/app/Models/GroupSetting.php b/app/Models/GroupSetting.php index 14d4178a37fe..b94fffbbfd3b 100644 --- a/app/Models/GroupSetting.php +++ b/app/Models/GroupSetting.php @@ -51,6 +51,11 @@ class GroupSetting extends StaticModel return $this->hasMany(Client::class, 'id', 'group_settings_id'); } + public function documents() + { + return $this->morphMany(Document::class, 'documentable'); + } + /** * Retrieve the model for a bound value. * From 1a4b5ed51d29ac814c58df622e039ded2273dc46 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 18 Jan 2021 22:08:18 +1100 Subject: [PATCH 3/6] Add public notes to invoices --- app/Services/Credit/CreditService.php | 3 +++ app/Services/Invoice/InvoiceService.php | 4 ++++ app/Services/Quote/QuoteService.php | 3 +++ 3 files changed, 10 insertions(+) diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index b7cc91d13888..3abdfc3ef583 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -114,6 +114,9 @@ class CreditService $this->credit->terms = $settings->credit_terms; } + if (!isset($this->credit->public_notes)) { + $this->credit->public_notes = $this->credit->client->public_notes; + } return $this; } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 7b9fc1a13b3c..2c0128b79d4f 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -375,6 +375,10 @@ class InvoiceService if (!isset($this->invoice->terms)) { $this->invoice->terms = $settings->invoice_terms; } + + if (!isset($this->invoice->public_notes)) { + $this->invoice->public_notes = $this->invoice->client->public_notes; + } return $this; } diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 92ac2731175a..c561f10dee69 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -171,6 +171,9 @@ class QuoteService $this->quote->terms = $settings->quote_terms; } + if (!isset($this->quote->public_notes)) { + $this->quote->public_notes = $this->quote->client->public_notes; + } return $this; } From 40f336c469f564fd79635620a3c3c685802e06cc Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 19 Jan 2021 07:02:32 +1100 Subject: [PATCH 4/6] Fixes for defaults --- .../ClientPortal/InvitationController.php | 3 +++ app/Repositories/BaseRepository.php | 4 ---- app/Services/Credit/CreditService.php | 14 ++++++------- app/Services/Invoice/InvoiceService.php | 21 ++++++++++--------- app/Services/Quote/QuoteService.php | 16 +++++++------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index 460020db838b..5e89320062f6 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -55,10 +55,13 @@ class InvitationController extends Controller /* Return early if we have the correct client_hash embedded */ if (request()->has('client_hash') && request()->input('client_hash') == $invitation->contact->client->client_hash) { + nlog("scenario 1"); auth()->guard('contact')->login($invitation->contact, true); } elseif ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) { + nlog("scenario 2"); $this->middleware('auth:contact'); } else { + nlog("scenario 3"); auth()->guard('contact')->login($invitation->contact, true); } diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 6fce805e8390..b6fa2b9e66cb 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -202,10 +202,6 @@ class BaseRepository /* Model now persisted, now lets do some child tasks */ - /* If client currency differs from the company default currency, then insert the client exchange rate on the model.*/ - if($client->currency()->id != (int) $model->company->settings->currency_id) - $model->exchange_rate = $client->currency()->exchange_rate; - /* Save any documents */ if (array_key_exists('documents', $data)) $this->saveDocuments($data['documents'], $model); diff --git a/app/Services/Credit/CreditService.php b/app/Services/Credit/CreditService.php index b7cc91d13888..e2a4b2229525 100644 --- a/app/Services/Credit/CreditService.php +++ b/app/Services/Credit/CreditService.php @@ -102,18 +102,18 @@ class CreditService { $settings = $this->credit->client->getMergedSettings(); - if (! $this->credit->design_id) { + if (! $this->credit->design_id) $this->credit->design_id = $this->decodePrimaryKey($settings->credit_design_id); - } - - if (!isset($this->credit->footer)) { + + if (!isset($this->credit->footer)) $this->credit->footer = $settings->credit_footer; - } - if (!isset($this->credit->terms)) { + if (!isset($this->credit->terms)) $this->credit->terms = $settings->credit_terms; - } + /* If client currency differs from the company default currency, then insert the client exchange rate on the model.*/ + if(!isset($this->credit->exchange_rate) && $this->credit->client->currency()->id != (int) $this->credit->company->settings->currency_id) + $this->credit->exchange_rate = $this->credit->client->currency()->exchange_rate; return $this; } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 7b9fc1a13b3c..295d15e84f70 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -364,18 +364,19 @@ class InvoiceService { $settings = $this->invoice->client->getMergedSettings(); - if (! $this->invoice->design_id) { + if (! $this->invoice->design_id) $this->invoice->design_id = $this->decodePrimaryKey($settings->invoice_design_id); - } - - if (!isset($this->invoice->footer)) { - $this->invoice->footer = $settings->invoice_footer; - } - - if (!isset($this->invoice->terms)) { - $this->invoice->terms = $settings->invoice_terms; - } + if (!isset($this->invoice->footer)) + $this->invoice->footer = $settings->invoice_footer; + + if (!isset($this->invoice->terms)) + $this->invoice->terms = $settings->invoice_terms; + + /* If client currency differs from the company default currency, then insert the client exchange rate on the model.*/ + if(!isset($this->invoice->exchange_rate) && $this->invoice->client->currency()->id != (int) $this->invoice->company->settings->currency_id) + $this->invoice->exchange_rate = $this->invoice->client->currency()->exchange_rate; + return $this; } diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index 92ac2731175a..b8c2195f91fc 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -159,18 +159,18 @@ class QuoteService { $settings = $this->quote->client->getMergedSettings(); - if (! $this->quote->design_id) { + if (! $this->quote->design_id) $this->quote->design_id = $this->decodePrimaryKey($settings->quote_design_id); - } - if (!isset($this->quote->footer)) { + if (!isset($this->quote->footer)) $this->quote->footer = $settings->quote_footer; - } - - if (!isset($this->quote->terms)) { + + if (!isset($this->quote->terms)) $this->quote->terms = $settings->quote_terms; - } - + + /* If client currency differs from the company default currency, then insert the client exchange rate on the model.*/ + if(!isset($this->quote->exchange_rate) && $this->quote->client->currency()->id != (int) $this->quote->company->settings->currency_id) + $this->quote->exchange_rate = $this->quote->client->currency()->exchange_rate; return $this; } From f20db94b62dd8d6efdc6f1e42ca6f8b6c05c8f34 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 19 Jan 2021 07:29:36 +1100 Subject: [PATCH 5/6] Fixes for how we auth a client contact --- app/Http/Controllers/ClientPortal/InvitationController.php | 3 --- app/Models/ClientContact.php | 6 ++++++ app/Repositories/ClientContactRepository.php | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index 5e89320062f6..460020db838b 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -55,13 +55,10 @@ class InvitationController extends Controller /* Return early if we have the correct client_hash embedded */ if (request()->has('client_hash') && request()->input('client_hash') == $invitation->contact->client->client_hash) { - nlog("scenario 1"); auth()->guard('contact')->login($invitation->contact, true); } elseif ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) { - nlog("scenario 2"); $this->middleware('auth:contact'); } else { - nlog("scenario 3"); auth()->guard('contact')->login($invitation->contact, true); } diff --git a/app/Models/ClientContact.php b/app/Models/ClientContact.php index bb759a8738a1..83907c39532c 100644 --- a/app/Models/ClientContact.php +++ b/app/Models/ClientContact.php @@ -87,6 +87,12 @@ class ClientContact extends Authenticatable implements HasLocalePreference 'client_id', ]; + /* Changing the username to id allows us to login() a contact that doesn't have an email address set*/ + public function username() + { + return 'id'; + } + public function getEntityType() { return self::class; diff --git a/app/Repositories/ClientContactRepository.php b/app/Repositories/ClientContactRepository.php index b53de62ed3fa..ea574f52061c 100644 --- a/app/Repositories/ClientContactRepository.php +++ b/app/Repositories/ClientContactRepository.php @@ -76,6 +76,7 @@ class ClientContactRepository extends BaseRepository $new_contact->client_id = $client->id; $new_contact->contact_key = Str::random(40); $new_contact->is_primary = true; + $new_contact->confirmed = true; $new_contact->save(); } } From 4a34c6b90306ad21e05e58338a7dedbe0e43ed0f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 19 Jan 2021 07:40:54 +1100 Subject: [PATCH 6/6] Add is_docker variable to account transformeR --- app/Transformers/AccountTransformer.php | 1 + config/ninja.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index 10fd3a54df18..6475834ddc85 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -75,6 +75,7 @@ class AccountTransformer extends EntityTransformer 'archived_at' => (int) $account->deleted_at, 'report_errors' => (bool) $account->report_errors, 'debug_enabled' => (bool) config('ninja.debug_enabled'), + 'is_docker' => (bool) config('ninja.is_docker'), ]; } diff --git a/config/ninja.php b/config/ninja.php index f569136aec69..36b6ad857d41 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -33,7 +33,7 @@ return [ 'phantomjs_secret' => env('PHANTOMJS_SECRET', false), 'phantomjs_pdf_generation' => env('PHANTOMJS_PDF_GENERATION', true), 'trusted_proxies' => env('TRUSTED_PROXIES', false), - + 'is_docker' => env('IS_DOCKER', false), 'sentry_dsn' => env('SENTRY_LARAVEL_DSN', 'https://9b4e15e575214354a7d666489783904a@sentry.invoicing.co/6'), 'environment' => env('NINJA_ENVIRONMENT', 'selfhost'), // 'hosted', 'development', 'selfhost', 'reseller'