From 4091538161f9e8faf79dbe4ea0bb0c4ea530fc9e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Dec 2021 10:16:13 +1100 Subject: [PATCH 01/18] Fixes for memory consumption with client statements --- app/Services/Client/Statement.php | 13 ++++++------- app/Services/PdfMaker/Design.php | 4 ++-- .../PdfMaker/Designs/Utilities/DesignHelpers.php | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/Services/Client/Statement.php b/app/Services/Client/Statement.php index 1c26d19324d4..daafb5bb4973 100644 --- a/app/Services/Client/Statement.php +++ b/app/Services/Client/Statement.php @@ -28,6 +28,7 @@ use App\Utils\Ninja; use App\Utils\Number; use App\Utils\PhantomJS\Phantom; use App\Utils\Traits\Pdf\PdfMaker as PdfMakerTrait; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Facades\DB; use Illuminate\Support\LazyCollection; @@ -123,7 +124,7 @@ class Statement */ protected function setupEntity(): self { - if (count($this->getInvoices()) >= 1) { + if ($this->getInvoices()->count() >= 1) { $this->entity = $this->getInvoices()->first(); } @@ -218,7 +219,7 @@ class Statement * * @return Invoice[]|\Illuminate\Database\Eloquent\Collection */ - protected function getInvoices(): LazyCollection + protected function getInvoices(): Builder { return Invoice::withTrashed() ->where('is_deleted', false) @@ -226,8 +227,7 @@ class Statement ->where('client_id', $this->client->id) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL, Invoice::STATUS_PAID]) ->whereBetween('date', [$this->options['start_date'], $this->options['end_date']]) - ->orderBy('number', 'ASC') - ->cursor(); + ->orderBy('number', 'ASC'); } /** @@ -235,7 +235,7 @@ class Statement * * @return Payment[]|\Illuminate\Database\Eloquent\Collection */ - protected function getPayments(): LazyCollection + protected function getPayments(): Builder { return Payment::withTrashed() ->with('client.country','invoices') @@ -244,8 +244,7 @@ class Statement ->where('client_id', $this->client->id) ->whereIn('status_id', [Payment::STATUS_COMPLETED, Payment::STATUS_PARTIALLY_REFUNDED, Payment::STATUS_REFUNDED]) ->whereBetween('date', [$this->options['start_date'], $this->options['end_date']]) - ->orderBy('number', 'ASC') - ->cursor(); + ->orderBy('number', 'ASC'); } /** diff --git a/app/Services/PdfMaker/Design.php b/app/Services/PdfMaker/Design.php index eb858b225248..8416ae729f47 100644 --- a/app/Services/PdfMaker/Design.php +++ b/app/Services/PdfMaker/Design.php @@ -359,7 +359,7 @@ class Design extends BaseDesign $tbody = []; - foreach ($this->invoices as $invoice) { + foreach ($this->invoices->cursor() as $invoice) { $element = ['element' => 'tr', 'elements' => []]; $element['elements'][] = ['element' => 'td', 'content' => $invoice->number]; @@ -407,7 +407,7 @@ class Design extends BaseDesign $tbody = []; - foreach ($this->payments as $payment) { + foreach ($this->payments->cursor() as $payment) { foreach ($payment->invoices as $invoice) { $element = ['element' => 'tr', 'elements' => []]; diff --git a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php index dd04ead2ed3a..82bbc3db684f 100644 --- a/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php +++ b/app/Services/PdfMaker/Designs/Utilities/DesignHelpers.php @@ -41,7 +41,7 @@ trait DesignHelpers if (isset($this->context['invoices'])) { $this->invoices = $this->context['invoices']; - if (\count($this->invoices) >= 1) { + if ($this->invoices->count() >= 1) { $this->entity = $this->invoices->first(); } } From f3d91c44142dde6650f7fbbf795adb8dc3f173dd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Dec 2021 12:54:19 +1100 Subject: [PATCH 02/18] Allow custom client numbering for projects --- app/Jobs/Util/Import.php | 4 ++-- app/PaymentDrivers/GoCardless/ACH.php | 1 + app/Utils/Traits/GeneratesCounter.php | 19 +++++++++++++------ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index c2e999ec62ff..467ac973da5d 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -1105,7 +1105,7 @@ class Import implements ShouldQueue throw new MigrationValidatorFailed(json_encode($validator->errors())); } - $quote_repository = new QuoteRepository(); + $quote_repository = new InvoiceMigrationRepository(); foreach ($data as $resource) { $modified = $resource; @@ -1144,7 +1144,7 @@ class Import implements ShouldQueue $resource['invitations'][$key]['user_id'] = $modified['user_id']; $resource['invitations'][$key]['company_id'] = $this->company->id; $resource['invitations'][$key]['email_status'] = ''; - unset($resource['invitations'][$key]['invoice_id']); + unset($resource['invitations'][$key]['quote_id']); unset($resource['invitations'][$key]['id']); } diff --git a/app/PaymentDrivers/GoCardless/ACH.php b/app/PaymentDrivers/GoCardless/ACH.php index 7aafa628d86d..41bd1fe892cf 100644 --- a/app/PaymentDrivers/GoCardless/ACH.php +++ b/app/PaymentDrivers/GoCardless/ACH.php @@ -148,6 +148,7 @@ class ACH implements MethodInterface $data['gateway'] = $this->go_cardless; $data['amount'] = $this->go_cardless->convertToGoCardlessAmount($data['total']['amount_with_fee'], $this->go_cardless->client->currency()->precision); $data['currency'] = $this->go_cardless->client->getCurrencyCode(); + $data['description'] = ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number'); return render('gateways.gocardless.ach.pay', $data); } diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index 1a7039c27a58..c9494ca3b2b1 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -295,19 +295,26 @@ trait GeneratesCounter */ public function getNextProjectNumber(Project $project) :string { - $this->resetCompanyCounters($project->company); + // 08/12/2021 - allows projects to have client counters. + + // $this->resetCompanyCounters($project->company); - $counter = $project->company->settings->project_number_counter; - $setting_entity = $project->company->settings->project_number_counter; + // $counter = $project->company->settings->project_number_counter; + // $setting_entity = $project->company->settings->project_number_counter; - $project_number = $this->checkEntityNumber(Project::class, $project, $counter, $project->company->settings->counter_padding, $project->company->settings->project_number_pattern); + // $project_number = $this->checkEntityNumber(Project::class, $project, $counter, $project->company->settings->counter_padding, $project->company->settings->project_number_pattern); - $this->incrementCounter($project->company, 'project_number_counter'); + // $this->incrementCounter($project->company, 'project_number_counter'); - $entity_number = $project_number; + // $entity_number = $project_number; + + // return $this->replaceUserVars($project, $entity_number); + + $entity_number = $this->getNextEntityNumber(Project::class, $project->client, false); return $this->replaceUserVars($project, $entity_number); + } From 64e0da29588031f38b22f05d35d6b8a91e6aef84 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Dec 2021 14:11:13 +1100 Subject: [PATCH 03/18] Fixes for project tests --- tests/MockAccountData.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/MockAccountData.php b/tests/MockAccountData.php index bbd8b44adb62..4056e6a828a5 100644 --- a/tests/MockAccountData.php +++ b/tests/MockAccountData.php @@ -297,6 +297,7 @@ trait MockAccountData $this->project = Project::factory()->create([ 'user_id' => $user_id, 'company_id' => $this->company->id, + 'client_id' => $this->client->id, ]); $this->expense = Expense::factory()->create([ From 5b7be30612254e12e50521412f0f9df7ab380877 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Dec 2021 20:46:15 +1100 Subject: [PATCH 04/18] Add descriptions to GoCardless --- app/PaymentDrivers/GoCardless/ACH.php | 19 +++++++++++++------ app/PaymentDrivers/GoCardless/DirectDebit.php | 13 ++++++++++++- app/PaymentDrivers/GoCardless/SEPA.php | 13 ++++++++++++- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/app/PaymentDrivers/GoCardless/ACH.php b/app/PaymentDrivers/GoCardless/ACH.php index 41bd1fe892cf..c466754f58fa 100644 --- a/app/PaymentDrivers/GoCardless/ACH.php +++ b/app/PaymentDrivers/GoCardless/ACH.php @@ -14,10 +14,10 @@ namespace App\PaymentDrivers\GoCardless; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use Illuminate\Http\Request; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; +use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; @@ -27,6 +27,7 @@ use App\Utils\Traits\MakesHash; use Exception; use GoCardlessPro\Resources\Payment as ResourcesPayment; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\View\View; @@ -148,7 +149,6 @@ class ACH implements MethodInterface $data['gateway'] = $this->go_cardless; $data['amount'] = $this->go_cardless->convertToGoCardlessAmount($data['total']['amount_with_fee'], $this->go_cardless->client->currency()->precision); $data['currency'] = $this->go_cardless->client->getCurrencyCode(); - $data['description'] = ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number'); return render('gateways.gocardless.ach.pay', $data); } @@ -161,17 +161,24 @@ class ACH implements MethodInterface */ public function paymentResponse(PaymentResponseRequest $request) { - // $token = ClientGatewayToken::find( - // $this->decodePrimaryKey($request->source) - // )->firstOrFail(); $this->go_cardless->ensureMandateIsReady($request->source); - + + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) + ->withTrashed() + ->first(); + + if($invoice) + $description = "Invoice {$invoice->number} for {$request->amount} for client {$this->go_cardless->client->present()->name()}"; + else + $description = "Amount {$request->amount} from client {$this->go_cardless->client->present()->name()}"; + try { $payment = $this->go_cardless->gateway->payments()->create([ 'params' => [ 'amount' => $request->amount, 'currency' => $request->currency, + 'description' => $description, 'metadata' => [ 'payment_hash' => $this->go_cardless->payment_hash->hash, ], diff --git a/app/PaymentDrivers/GoCardless/DirectDebit.php b/app/PaymentDrivers/GoCardless/DirectDebit.php index 7e915f5f8f9d..51ae2fb1de91 100644 --- a/app/PaymentDrivers/GoCardless/DirectDebit.php +++ b/app/PaymentDrivers/GoCardless/DirectDebit.php @@ -14,11 +14,11 @@ namespace App\PaymentDrivers\GoCardless; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use Illuminate\Http\Request; use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; +use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; @@ -26,6 +26,7 @@ use App\PaymentDrivers\Common\MethodInterface; use App\PaymentDrivers\GoCardlessPaymentDriver; use App\Utils\Traits\MakesHash; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\View\View; @@ -155,11 +156,21 @@ class DirectDebit implements MethodInterface $this->go_cardless->ensureMandateIsReady($request->source); + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) + ->withTrashed() + ->first(); + + if($invoice) + $description = "Invoice {$invoice->number} for {$request->amount} for client {$this->go_cardless->client->present()->name()}"; + else + $description = "Amount {$request->amount} from client {$this->go_cardless->client->present()->name()}"; + try { $payment = $this->go_cardless->gateway->payments()->create([ 'params' => [ 'amount' => $request->amount, 'currency' => $request->currency, + 'description' => $description, 'metadata' => [ 'payment_hash' => $this->go_cardless->payment_hash->hash, ], diff --git a/app/PaymentDrivers/GoCardless/SEPA.php b/app/PaymentDrivers/GoCardless/SEPA.php index 6a9bfb342664..d14d84a69d34 100644 --- a/app/PaymentDrivers/GoCardless/SEPA.php +++ b/app/PaymentDrivers/GoCardless/SEPA.php @@ -14,10 +14,10 @@ namespace App\PaymentDrivers\GoCardless; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use Illuminate\Http\Request; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; +use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; @@ -26,6 +26,7 @@ use App\PaymentDrivers\GoCardlessPaymentDriver; use App\Utils\Traits\MakesHash; use Exception; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\View\View; @@ -162,11 +163,21 @@ class SEPA implements MethodInterface { $this->go_cardless->ensureMandateIsReady($request->source); + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) + ->withTrashed() + ->first(); + + if($invoice) + $description = "Invoice {$invoice->number} for {$request->amount} for client {$this->go_cardless->client->present()->name()}"; + else + $description = "Amount {$request->amount} from client {$this->go_cardless->client->present()->name()}"; + try { $payment = $this->go_cardless->gateway->payments()->create([ 'params' => [ 'amount' => $request->amount, 'currency' => $request->currency, + 'description' => $description, 'metadata' => [ 'payment_hash' => $this->go_cardless->payment_hash->hash, ], From de0bebcd2cb8f6a69a39bdc315249b3c2f3d4f89 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 9 Dec 2021 16:34:23 +1100 Subject: [PATCH 05/18] refactor --- .../Auth/ContactForgotPasswordController.php | 22 ++++++++++--------- .../Auth/ContactResetPasswordController.php | 20 +++++++++++++---- .../Auth/ForgotPasswordController.php | 11 ++++++++-- .../Auth/ResetPasswordController.php | 7 ++++-- .../ClientPortal/InvoiceController.php | 9 +++++--- app/Http/Middleware/ApiSecretCheck.php | 6 ++--- app/Http/Middleware/ContactAccount.php | 4 ++-- app/Http/Middleware/Locale.php | 9 ++++++++ app/Http/Middleware/SetDomainNameDb.php | 7 +++--- app/Models/Client.php | 3 +++ 10 files changed, 69 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/Auth/ContactForgotPasswordController.php b/app/Http/Controllers/Auth/ContactForgotPasswordController.php index 9481a7d9d277..ef6ca6c2b2d9 100644 --- a/app/Http/Controllers/Auth/ContactForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ContactForgotPasswordController.php @@ -58,16 +58,21 @@ class ContactForgotPasswordController extends Controller */ public function showLinkRequestForm(Request $request) { - $account_id = $request->has('account_id') ? $request->get('account_id') : 1; - $account = Account::find($account_id); - - if($request->has('company_key')) + // $account_id = $request->has('account_id') ? $request->get('account_id') : 1; + // $account = Account::find($account_id); + $account = false; + + if(Ninja::isHosted() && $request->has('company_key')) + { + MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); $company = Company::where('company_key', $request->input('company_key'))->first(); - else - $company = $account->companies->first(); + $account = $company->first(); + } - if(!$account) + if(!$account){ $account = Account::first(); + $company = $account->companies->first(); + } return $this->render('auth.passwords.request', [ 'title' => 'Client Password Reset', @@ -95,10 +100,7 @@ class ContactForgotPasswordController extends Controller $this->validateEmail($request); - // $user = MultiDB::hasContact($request->input('email')); $company = Company::where('company_key', $request->input('company_key'))->first(); - //$contact = MultiDB::findContact(['company_id' => $company->id, 'email' => $request->input('email')]); - nlog(['company_id' => $company->id, 'email' => $request->input('email')]); $contact = ClientContact::where(['company_id' => $company->id, 'email' => $request->input('email')])->first(); $response = false; diff --git a/app/Http/Controllers/Auth/ContactResetPasswordController.php b/app/Http/Controllers/Auth/ContactResetPasswordController.php index f5a981ae1859..0d245026a590 100644 --- a/app/Http/Controllers/Auth/ContactResetPasswordController.php +++ b/app/Http/Controllers/Auth/ContactResetPasswordController.php @@ -68,10 +68,22 @@ class ContactResetPasswordController extends Controller */ public function showResetForm(Request $request, $token = null) { - $account_id = $request->has('account_id') ? $request->get('account_id') : 1; - $account = Account::find($account_id); - $db = $account->companies->first()->db; - $company = $account->companies->first(); + + if($request->has('company_key')){ + MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); + $company = Company::where('company_key', $request->input('company_key'))->first(); + $db = $company->db; + $account = $company->account; + } + else { + + $account_id = $request->has('account_id') ? $request->get('account_id') : 1; + $account = Account::find($account_id); + $db = $account->companies->first()->db; + $company = $account->companies->first(); + + } + return $this->render('auth.passwords.reset')->with( ['token' => $token, 'email' => $request->email, 'account' => $account, 'db' => $db, 'company' => $company] diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php index 4d29e66e1518..ecffd294af7f 100644 --- a/app/Http/Controllers/Auth/ForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -79,8 +79,15 @@ class ForgotPasswordController extends Controller public function showLinkRequestForm(Request $request) { - $account_id = $request->get('account_id'); - $account = Account::find($account_id); + if($request->has('company_key')){ + MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); + $company = Company::where('company_key', $request->input('company_key'))->first(); + $account = $company->account; + } + else{ + $account_id = $request->get('account_id'); + $account = Account::find($account_id); + } return $this->render('auth.passwords.request', ['root' => 'themes', 'account' => $account]); } diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 7c6cae9eafaf..5a4f9476286a 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -53,8 +53,11 @@ class ResetPasswordController extends Controller public function showResetForm(Request $request, $token = null) { - $account_id = $request->get('account_id'); - $account = Account::find($account_id); + // $account_id = $request->get('account_id'); + // $account = Account::find($account_id); + MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); + $company = Company::where('company_key', $request->input('company_key'))->first(); + $account = $company->account; return $this->render('auth.passwords.reset', ['root' => 'themes', 'token' => $token, 'account' => $account]); } diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index cd66cfcbd541..25471f73ea26 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -42,6 +42,9 @@ class InvoiceController extends Controller */ public function index(ShowInvoicesRequest $request) { + // $request->request->remove('account_id'); + // $request->request->remove('company_key'); + return $this->render('invoices.index'); } @@ -77,7 +80,7 @@ class InvoiceController extends Controller if ($request->query('mode') === 'fullscreen') { return render('invoices.show-fullscreen', $data); } - + // $request->fullUrlWithQuery(['q' => null]); return $this->render('invoices.show', $data); } @@ -189,9 +192,9 @@ class InvoiceController extends Controller if ($invoices->count() == 1) { $invoice = $invoices->first(); $invitation = $invoice->invitations->first(); - //$file = $invoice->pdf_file_path($invitation); + $file = $invoice->service()->getInvoicePdf(auth()->user()); - // return response()->download($file, basename($file), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);; + return response()->streamDownload(function () use($file) { echo Storage::get($file); }, basename($file), ['Content-Type' => 'application/pdf']); diff --git a/app/Http/Middleware/ApiSecretCheck.php b/app/Http/Middleware/ApiSecretCheck.php index 972f37f5c7b9..2dea07d6395d 100644 --- a/app/Http/Middleware/ApiSecretCheck.php +++ b/app/Http/Middleware/ApiSecretCheck.php @@ -40,9 +40,9 @@ class ApiSecretCheck ]; return response() - ->json($error, 403) - ->header('X-App-Version', config('ninja.app_version')) - ->header('X-Minimum-Client-Version', config('ninja.minimum_client_version')); + ->json($error, 403) + ->header('X-App-Version', config('ninja.app_version')) + ->header('X-Minimum-Client-Version', config('ninja.minimum_client_version')); } } } diff --git a/app/Http/Middleware/ContactAccount.php b/app/Http/Middleware/ContactAccount.php index 79faf0a9c740..7ab922edfdfd 100644 --- a/app/Http/Middleware/ContactAccount.php +++ b/app/Http/Middleware/ContactAccount.php @@ -31,8 +31,8 @@ class ContactAccount if(!Ninja::isHosted()) { - $account_id = Account::first()->id; - $request->request->add(['account_id' => $account_id]); + $account = Account::first(); + $request->merge(['account_id' => $account->id, 'account_key' => $account->key]); } diff --git a/app/Http/Middleware/Locale.php b/app/Http/Middleware/Locale.php index 7ccf7988a8ce..e8c9e4e14835 100644 --- a/app/Http/Middleware/Locale.php +++ b/app/Http/Middleware/Locale.php @@ -1,4 +1,13 @@ request->add(['account_id' => $company->account_id, 'company_key' => $company->company_key]); + $request->merge(['company_key' => $company->company_key]); + // $request->merge(['account_id' => $company->account_id, 'company_key' => $company->company_key]); } else { @@ -72,7 +73,8 @@ class SetDomainNameDb ]; if($company = MultiDB::findAndSetDbByDomain($query)){ - $request->request->add(['account_id' => $company->account_id, 'company_key' => $company->company_key]); + $request->merge(['company_key' => $company->company_key]); + //$request->merge(['account_id' => $company->account_id, 'company_key' => $company->company_key]); } else { @@ -81,7 +83,6 @@ class SetDomainNameDb } else { MultiDB::setDb('db-ninja-01'); nlog("I could not set the DB - defaulting to DB1"); - //abort(400, 'Domain not found'); } } diff --git a/app/Models/Client.php b/app/Models/Client.php index 55ac5fe02471..a002d18828d9 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -283,6 +283,9 @@ class Client extends BaseModel implements HasLocalePreference { $date_formats = Cache::get('date_formats'); + if(!$date_formats) + $this->buildCache(true); + return $date_formats->filter(function ($item) { return $item->id == $this->getSetting('date_format_id'); })->first()->format; From d2a929b975897fd04429a0843fb331f6c26c301f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 9 Dec 2021 21:50:29 +1100 Subject: [PATCH 06/18] Refactor client portal authentication --- .../Auth/ContactForgotPasswordController.php | 19 ++++++------ .../Auth/ContactLoginController.php | 8 ++--- .../Auth/ContactRegisterController.php | 2 +- .../Auth/ContactResetPasswordController.php | 31 +++++++++++++------ .../Auth/ResetPasswordController.php | 9 +++--- .../ClientPortal/InvoiceController.php | 2 -- app/Http/Middleware/ContactAccount.php | 2 +- app/Http/Middleware/ContactRegister.php | 12 ++++--- app/Http/Middleware/SetDomainNameDb.php | 8 ++--- 9 files changed, 54 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/Auth/ContactForgotPasswordController.php b/app/Http/Controllers/Auth/ContactForgotPasswordController.php index ef6ca6c2b2d9..bdfe94431c73 100644 --- a/app/Http/Controllers/Auth/ContactForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ContactForgotPasswordController.php @@ -58,15 +58,14 @@ class ContactForgotPasswordController extends Controller */ public function showLinkRequestForm(Request $request) { - // $account_id = $request->has('account_id') ? $request->get('account_id') : 1; - // $account = Account::find($account_id); + $account = false; - if(Ninja::isHosted() && $request->has('company_key')) + if(Ninja::isHosted() && $request->session()->has('company_key')) { - MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); - $company = Company::where('company_key', $request->input('company_key'))->first(); - $account = $company->first(); + MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key')); + $company = Company::where('company_key', $request->session()->get('company_key'))->first(); + $account = $company->account; } if(!$account){ @@ -94,13 +93,13 @@ class ContactForgotPasswordController extends Controller public function sendResetLinkEmail(ContactPasswordResetRequest $request) { - - if(Ninja::isHosted() && $request->has('company_key')) - MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); + + if(Ninja::isHosted() && $request->session()->has('company_key')) + MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key')); $this->validateEmail($request); - $company = Company::where('company_key', $request->input('company_key'))->first(); + $company = Company::where('company_key', $request->session()->get('company_key'))->first(); $contact = ClientContact::where(['company_id' => $company->id, 'email' => $request->input('email')])->first(); $response = false; diff --git a/app/Http/Controllers/Auth/ContactLoginController.php b/app/Http/Controllers/Auth/ContactLoginController.php index 16a2fc746e01..876364bb4fb3 100644 --- a/app/Http/Controllers/Auth/ContactLoginController.php +++ b/app/Http/Controllers/Auth/ContactLoginController.php @@ -40,8 +40,8 @@ class ContactLoginController extends Controller $company = false; $account = false; - if($request->has('company_key')){ - MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); + if($request->session()->has('company_key')){ + MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key')); $company = Company::where('company_key', $request->input('company_key'))->first(); } @@ -80,8 +80,8 @@ class ContactLoginController extends Controller { Auth::shouldUse('contact'); - if(Ninja::isHosted() && $request->has('company_key')) - MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); + if(Ninja::isHosted() && $request->session()->has('company_key')) + MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key')); $this->validateLogin($request); // If the class is using the ThrottlesLogins trait, we can automatically throttle diff --git a/app/Http/Controllers/Auth/ContactRegisterController.php b/app/Http/Controllers/Auth/ContactRegisterController.php index 0ee232eadc53..ef4fe9502c89 100644 --- a/app/Http/Controllers/Auth/ContactRegisterController.php +++ b/app/Http/Controllers/Auth/ContactRegisterController.php @@ -29,7 +29,7 @@ class ContactRegisterController extends Controller public function showRegisterForm(string $company_key = '') { - $key = request()->has('key') ? request('key') : $company_key; + $key = request()->session()->has('key') ? request()->session()->get('key') : $company_key; $company = Company::where('company_key', $key)->firstOrFail(); diff --git a/app/Http/Controllers/Auth/ContactResetPasswordController.php b/app/Http/Controllers/Auth/ContactResetPasswordController.php index 0d245026a590..4ea188166cf3 100644 --- a/app/Http/Controllers/Auth/ContactResetPasswordController.php +++ b/app/Http/Controllers/Auth/ContactResetPasswordController.php @@ -15,6 +15,7 @@ use App\Http\Controllers\Controller; use App\Libraries\MultiDB; use App\Models\Account; use App\Models\ClientContact; +use App\Models\Company; use Illuminate\Auth\Events\PasswordReset; use Illuminate\Contracts\View\Factory; use Illuminate\Foundation\Auth\ResetsPasswords; @@ -69,18 +70,29 @@ class ContactResetPasswordController extends Controller public function showResetForm(Request $request, $token = null) { - if($request->has('company_key')){ - MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); - $company = Company::where('company_key', $request->input('company_key'))->first(); + if($request->session()->has('company_key')){ + MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key')); + $company = Company::where('company_key', $request->session()->get('company_key'))->first(); $db = $company->db; $account = $company->account; } else { - $account_id = $request->has('account_id') ? $request->get('account_id') : 1; - $account = Account::find($account_id); - $db = $account->companies->first()->db; - $company = $account->companies->first(); + $account_key = $request->session()->has('account_key') ? $request->session()->get('account_key') : false; + + if($account_key){ + + MultiDB::findAndSetDbByAccountKey($account_key); + $account = Account::where('key', $account_key)->first(); + $db = $account->companies->first()->db; + $company = $account->companies->first(); + } + else{ + + $account = Account::first(); + $db = $account->companies->first()->db; + $company = $account->companies->first(); + } } @@ -88,12 +100,13 @@ class ContactResetPasswordController extends Controller return $this->render('auth.passwords.reset')->with( ['token' => $token, 'email' => $request->email, 'account' => $account, 'db' => $db, 'company' => $company] ); + } public function reset(Request $request) { - if($request->has('company_key')) - MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); + if($request->session()->has('company_key')) + MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key')); $request->validate($this->rules(), $this->validationErrorMessages()); diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index 5a4f9476286a..c46ca92d7427 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -12,7 +12,9 @@ namespace App\Http\Controllers\Auth; use App\Http\Controllers\Controller; +use App\Libraries\MultiDB; use App\Models\Account; +use App\Models\Company; use Illuminate\Foundation\Auth\ResetsPasswords; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; @@ -53,10 +55,9 @@ class ResetPasswordController extends Controller public function showResetForm(Request $request, $token = null) { - // $account_id = $request->get('account_id'); - // $account = Account::find($account_id); - MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); - $company = Company::where('company_key', $request->input('company_key'))->first(); + + MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key')); + $company = Company::where('company_key', $request->session()->get('company_key'))->first(); $account = $company->account; return $this->render('auth.passwords.reset', ['root' => 'themes', 'token' => $token, 'account' => $account]); diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index 25471f73ea26..fe9809860eab 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -42,8 +42,6 @@ class InvoiceController extends Controller */ public function index(ShowInvoicesRequest $request) { - // $request->request->remove('account_id'); - // $request->request->remove('company_key'); return $this->render('invoices.index'); } diff --git a/app/Http/Middleware/ContactAccount.php b/app/Http/Middleware/ContactAccount.php index 7ab922edfdfd..cfeabbcdc1b0 100644 --- a/app/Http/Middleware/ContactAccount.php +++ b/app/Http/Middleware/ContactAccount.php @@ -32,8 +32,8 @@ class ContactAccount if(!Ninja::isHosted()) { $account = Account::first(); - $request->merge(['account_id' => $account->id, 'account_key' => $account->key]); + session()->put('account_key', $account->key); } return $next($request); diff --git a/app/Http/Middleware/ContactRegister.php b/app/Http/Middleware/ContactRegister.php index c76df09a582b..2b3a72e1653b 100644 --- a/app/Http/Middleware/ContactRegister.php +++ b/app/Http/Middleware/ContactRegister.php @@ -37,7 +37,8 @@ class ContactRegister if(! $company->client_can_register) abort(400, 'Registration disabled'); - $request->merge(['key' => $company->company_key]); + // $request->merge(['key' => $company->company_key]); + session()->put('key', $company->company_key); return $next($request); } @@ -55,7 +56,8 @@ class ContactRegister if(! $company->client_can_register) abort(400, 'Registration disabled'); - $request->merge(['key' => $company->company_key]); + // $request->merge(['key' => $company->company_key]); + session()->put('key', $company->company_key); return $next($request); } @@ -69,7 +71,8 @@ class ContactRegister if(! (bool)$company->client_can_register); abort(400, 'Registration disabled'); - $request->merge(['key' => $company->company_key]); + //$request->merge(['key' => $company->company_key]); + session()->put('key', $company->company_key); return $next($request); } @@ -82,7 +85,8 @@ class ContactRegister if(! $company->client_can_register) abort(400, 'Registration disabled'); - $request->merge(['key' => $company->company_key]); + //$request->merge(['key' => $company->company_key]); + session()->put('key', $company->company_key); return $next($request); } diff --git a/app/Http/Middleware/SetDomainNameDb.php b/app/Http/Middleware/SetDomainNameDb.php index 8a5f3425408d..ca8b016325c3 100644 --- a/app/Http/Middleware/SetDomainNameDb.php +++ b/app/Http/Middleware/SetDomainNameDb.php @@ -50,8 +50,8 @@ class SetDomainNameDb ]; if($company = MultiDB::findAndSetDbByDomain($query)){ - $request->merge(['company_key' => $company->company_key]); - // $request->merge(['account_id' => $company->account_id, 'company_key' => $company->company_key]); + //$request->merge(['company_key' => $company->company_key]); + session()->put('company_key', $company->company_key); } else { @@ -73,8 +73,8 @@ class SetDomainNameDb ]; if($company = MultiDB::findAndSetDbByDomain($query)){ - $request->merge(['company_key' => $company->company_key]); - //$request->merge(['account_id' => $company->account_id, 'company_key' => $company->company_key]); + //$request->merge(['company_key' => $company->company_key]); + session()->put('company_key', $company->company_key); } else { From 0ec5eb51682937fceb3103e0e3f7749734781f2f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 10 Dec 2021 08:02:28 +1100 Subject: [PATCH 07/18] Increase timeout for Redis --- config/database.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/database.php b/config/database.php index dc9f80481864..8c0d15cdf936 100644 --- a/config/database.php +++ b/config/database.php @@ -207,7 +207,7 @@ return [ ['options' => [ 'replication' => 'sentinel', 'service' => env('REDIS_SENTINEL_SERVICE', 'mymaster'), - 'sentinel_timeout' => 2.0, + 'sentinel_timeout' => 3.0, 'parameters' => [ 'password' => env('REDIS_PASSWORD', null), 'database' => env('REDIS_DB', 0), @@ -226,7 +226,7 @@ return [ ['options' => [ 'replication' => 'sentinel', 'service' => env('REDIS_SENTINEL_SERVICE', 'mymaster'), - 'sentinel_timeout' => 2.0, + 'sentinel_timeout' => 3.0, 'parameters' => [ 'password' => env('REDIS_PASSWORD', null), 'database' => env('REDIS_CACHE_DB', 1), From ac194665de6728e4091f273ef2e01b4c48369fcd Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 10 Dec 2021 13:10:02 +1100 Subject: [PATCH 08/18] fixes for password reset for admin --- app/Http/Controllers/Auth/ResetPasswordController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php index c46ca92d7427..4d05cb2f31f2 100644 --- a/app/Http/Controllers/Auth/ResetPasswordController.php +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -58,7 +58,11 @@ class ResetPasswordController extends Controller MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key')); $company = Company::where('company_key', $request->session()->get('company_key'))->first(); - $account = $company->account; + + if($company) + $account = $company->account; + else + $account = Account::first(); return $this->render('auth.passwords.reset', ['root' => 'themes', 'token' => $token, 'account' => $account]); } From 1186eaa82375692d01d5ef3369c5b7bc7315b55f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 10 Dec 2021 14:00:22 +1100 Subject: [PATCH 09/18] Fixes for client password reset --- .../Auth/ContactForgotPasswordController.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/Auth/ContactForgotPasswordController.php b/app/Http/Controllers/Auth/ContactForgotPasswordController.php index bdfe94431c73..f88e99a43e9e 100644 --- a/app/Http/Controllers/Auth/ContactForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ContactForgotPasswordController.php @@ -93,14 +93,15 @@ class ContactForgotPasswordController extends Controller public function sendResetLinkEmail(ContactPasswordResetRequest $request) { - - if(Ninja::isHosted() && $request->session()->has('company_key')) - MultiDB::findAndSetDbByCompanyKey($request->session()->get('company_key')); + if(Ninja::isHosted() && $request->has('company_key')) + MultiDB::findAndSetDbByCompanyKey($request->input('company_key')); $this->validateEmail($request); - $company = Company::where('company_key', $request->session()->get('company_key'))->first(); - $contact = ClientContact::where(['company_id' => $company->id, 'email' => $request->input('email')])->first(); + // $company = Company::where('company_key', $request->input('company_key'))->first(); + // $contact = ClientContact::where(['company_id' => $company->id, 'email' => $request->input('email')])->first(); + + $contact = ClientContact::where(['email' => $request->input('email')])->first(); $response = false; @@ -117,7 +118,7 @@ class ContactForgotPasswordController extends Controller return $this->sendResetLinkFailedResponse($request, Password::INVALID_USER); // We will send the password reset link to this user. Once we have attempted - // to send the link, we will examine the response then see the message we + // to send the link, we will examine thuser@example.ce response then see the message we // need to show to the user. Finally, we'll send out a proper response. // $response = $this->broker()->sendResetLink( // $this->credentials($request) From 307e32e54d630fd509b7cadf7785198cc89022a4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 10 Dec 2021 15:39:07 +1100 Subject: [PATCH 10/18] Clean up --- .../Controllers/Auth/ContactForgotPasswordController.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/Http/Controllers/Auth/ContactForgotPasswordController.php b/app/Http/Controllers/Auth/ContactForgotPasswordController.php index f88e99a43e9e..0ef1c0090abd 100644 --- a/app/Http/Controllers/Auth/ContactForgotPasswordController.php +++ b/app/Http/Controllers/Auth/ContactForgotPasswordController.php @@ -110,20 +110,13 @@ class ContactForgotPasswordController extends Controller /* Update all instances of the client */ $token = Str::random(60); ClientContact::where('email', $contact->email)->update(['token' => $token]); - $contact->sendPasswordResetNotification($token); $response = Password::RESET_LINK_SENT; + } else return $this->sendResetLinkFailedResponse($request, Password::INVALID_USER); - // We will send the password reset link to this user. Once we have attempted - // to send the link, we will examine thuser@example.ce response then see the message we - // need to show to the user. Finally, we'll send out a proper response. - // $response = $this->broker()->sendResetLink( - // $this->credentials($request) - // ); - if ($request->ajax()) { if($response == Password::RESET_THROTTLED) From b1a2403e35ad2011cc957fd7e360593325b6d205 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 10 Dec 2021 21:50:46 +1100 Subject: [PATCH 11/18] Fixes for duplicate payment numbers" --- .../Requests/Payment/StorePaymentRequest.php | 4 +- app/Services/Invoice/AddGatewayFee.php | 10 +++++ tests/Feature/PaymentTest.php | 44 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index 9f0ba912bd5f..2deffed782ec 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -20,6 +20,7 @@ use App\Http\ValidationRules\ValidCreditsPresentRule; use App\Http\ValidationRules\ValidPayableInvoicesRule; use App\Models\Payment; use App\Utils\Traits\MakesHash; +use Illuminate\Validation\Rule; class StorePaymentRequest extends Request { @@ -100,7 +101,8 @@ class StorePaymentRequest extends Request 'credits.*.credit_id' => new ValidCreditsRules($this->all()), 'credits.*.amount' => ['required', new CreditsSumRule($this->all())], 'invoices' => new ValidPayableInvoicesRule(), - 'number' => 'bail|nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->company_id, + 'number' => ['nullable', Rule::unique('payments')->where('company_id', auth()->user()->company()->id)], + ]; if ($this->input('documents') && is_array($this->input('documents'))) { diff --git a/app/Services/Invoice/AddGatewayFee.php b/app/Services/Invoice/AddGatewayFee.php index 438fb6f85e03..b63f7a43e4d9 100644 --- a/app/Services/Invoice/AddGatewayFee.php +++ b/app/Services/Invoice/AddGatewayFee.php @@ -17,6 +17,8 @@ use App\Models\CompanyGateway; use App\Models\Invoice; use App\Models\Payment; use App\Services\AbstractService; +use App\Utils\Ninja; +use Illuminate\Support\Facades\App; class AddGatewayFee extends AbstractService { @@ -72,6 +74,10 @@ class AddGatewayFee extends AbstractService private function processGatewayFee($gateway_fee) { + App::forgetInstance('translator'); + $t = app('translator'); + $t->replace(Ninja::transformTranslations($this->invoice->company->settings)); + $invoice_item = new InvoiceItem; $invoice_item->type_id = '3'; $invoice_item->product_key = ctrans('texts.surcharge'); @@ -98,6 +104,10 @@ class AddGatewayFee extends AbstractService private function processGatewayDiscount($gateway_fee) { + App::forgetInstance('translator'); + $t = app('translator'); + $t->replace(Ninja::transformTranslations($this->invoice->company->settings)); + $invoice_item = new InvoiceItem; $invoice_item->type_id = '3'; $invoice_item->product_key = ctrans('texts.discount'); diff --git a/tests/Feature/PaymentTest.php b/tests/Feature/PaymentTest.php index 1fe76bf7bfe8..dd926406300f 100644 --- a/tests/Feature/PaymentTest.php +++ b/tests/Feature/PaymentTest.php @@ -1480,5 +1480,49 @@ class PaymentTest extends TestCase $this->assertEquals(10, $this->invoice->fresh()->balance); $this->assertEquals(10, $this->invoice->fresh()->balance); } + + + public function testUniquePaymentNumbers() + { + $data = [ + 'amount' => $this->invoice->amount, + 'client_id' => $this->client->hashed_id, + 'date' => '2020/12/12', + 'number' => 'duplicate', + ]; + + try { + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/payments', $data); + } catch (ValidationException $e) { + $message = json_decode($e->validator->getMessageBag(), 1); + nlog($message); + } + + $arr = $response->json(); + + $response->assertStatus(200); + + $response = false; + + try { + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->post('/api/v1/payments', $data); + } catch (ValidationException $e) { + $message = json_decode($e->validator->getMessageBag(), 1); + nlog($message); + } + + if($response) + $response->assertStatus(302); + + + + + } } From 56a59a5cdf877ed62cf8d4a4fe5aa8f2df3ae065 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 10 Dec 2021 22:39:53 +1100 Subject: [PATCH 12/18] Payment filters --- app/Filters/PaymentFilters.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Filters/PaymentFilters.php b/app/Filters/PaymentFilters.php index 774c8bc9ed77..c7000febaa97 100644 --- a/app/Filters/PaymentFilters.php +++ b/app/Filters/PaymentFilters.php @@ -94,6 +94,12 @@ class PaymentFilters extends QueryFilters return $this->builder->orderBy($sort_col[0], $sort_col[1]); } + + public function number(string $number) : Builder + { + return $this->builder->where('number', $number); + } + /** * Returns the base query. * From 5a98fe392525dfc56ca1751968e9761defa5c561 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 11 Dec 2021 08:15:53 +1100 Subject: [PATCH 13/18] Fixes for Freshbooks transformers --- app/Import/Transformers/Freshbooks/InvoiceTransformer.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Import/Transformers/Freshbooks/InvoiceTransformer.php b/app/Import/Transformers/Freshbooks/InvoiceTransformer.php index feb28d131aac..623b59fe7d63 100644 --- a/app/Import/Transformers/Freshbooks/InvoiceTransformer.php +++ b/app/Import/Transformers/Freshbooks/InvoiceTransformer.php @@ -14,6 +14,7 @@ namespace App\Import\Transformers\Freshbooks; use App\Import\ImportException; use App\Import\Transformers\BaseTransformer; use App\Models\Invoice; +use App\Utils\Number; /** * Class InvoiceTransformer. @@ -75,4 +76,11 @@ class InvoiceTransformer extends BaseTransformer { return $transformed; } + + /** @return float */ + public function getFloat($data, $field) + { + return Number::parseFloat($data[$field]); + } + } From 0cebfd1f56e097a4d572e7e856ea8087664578ae Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 11 Dec 2021 08:32:24 +1100 Subject: [PATCH 14/18] Fixes for freshbooks import --- app/Http/Kernel.php | 5 ++- .../Freshbooks/InvoiceTransformer.php | 18 +++++----- app/Jobs/Import/CSVImport.php | 34 ++++++++----------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index e788bd0fb71d..87b9f32c92ae 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -72,7 +72,7 @@ class Kernel extends HttpKernel ConvertEmptyStringsToNull::class, TrustProxies::class, // \Fruitcake\Cors\HandleCors::class, - Cors::class, + // Cors::class, ]; @@ -95,6 +95,7 @@ class Kernel extends HttpKernel 'api' => [ 'throttle:300,1', 'bindings', + 'cors', 'query_logging', ], 'contact' => [ @@ -116,6 +117,7 @@ class Kernel extends HttpKernel 'throttle:120,1', 'bindings', 'query_logging', + 'cors', ], ]; @@ -132,6 +134,7 @@ class Kernel extends HttpKernel 'bindings' => SubstituteBindings::class, 'cache.headers' => SetCacheHeaders::class, 'can' => Authorize::class, + 'cors' => Cors::class, 'guest' => RedirectIfAuthenticated::class, 'signed' => ValidateSignature::class, 'throttle' => ThrottleRequests::class, diff --git a/app/Import/Transformers/Freshbooks/InvoiceTransformer.php b/app/Import/Transformers/Freshbooks/InvoiceTransformer.php index 623b59fe7d63..48ab07a1eef4 100644 --- a/app/Import/Transformers/Freshbooks/InvoiceTransformer.php +++ b/app/Import/Transformers/Freshbooks/InvoiceTransformer.php @@ -54,16 +54,16 @@ class InvoiceTransformer extends BaseTransformer { $line_items[] = [ 'product_key' => $this->getString( $record, 'Item Name' ), 'notes' => $this->getString( $record, 'Item Description' ), - 'cost' => $this->getFloat( $record, 'Rate' ), - 'quantity' => $this->getFloat( $record, 'Quantity' ), - 'discount' => $this->getFloat( $record, 'Discount Percentage' ), + 'cost' => $this->getFreshbookQuantityFloat( $record, 'Rate' ), + 'quantity' => $this->getFreshbookQuantityFloat( $record, 'Quantity' ), + 'discount' => $this->getFreshbookQuantityFloat( $record, 'Discount Percentage' ), 'is_amount_discount' => false, 'tax_name1' => $this->getString( $record, 'Tax 1 Type' ), - 'tax_rate1' => $this->getFloat( $record, 'Tax 1 Amount' ), + 'tax_rate1' => $this->getFreshbookQuantityFloat( $record, 'Tax 1 Amount' ), 'tax_name2' => $this->getString( $record, 'Tax 2 Type' ), - 'tax_rate2' => $this->getFloat( $record, 'Tax 2 Amount' ), + 'tax_rate2' => $this->getFreshbookQuantityFloat( $record, 'Tax 2 Amount' ), ]; - $transformed['amount'] += $this->getFloat( $record, 'Line Total' ); + $transformed['amount'] += $this->getFreshbookQuantityFloat( $record, 'Line Total' ); } $transformed['line_items'] = $line_items; @@ -78,9 +78,9 @@ class InvoiceTransformer extends BaseTransformer { } /** @return float */ - public function getFloat($data, $field) + public function getFreshbookQuantityFloat($data, $field) { - return Number::parseFloat($data[$field]); + return $data[$field]; } - + } diff --git a/app/Jobs/Import/CSVImport.php b/app/Jobs/Import/CSVImport.php index 27626ad9f484..3a9a44f65969 100644 --- a/app/Jobs/Import/CSVImport.php +++ b/app/Jobs/Import/CSVImport.php @@ -440,30 +440,25 @@ class CSVImport implements ShouldQueue { 'tax_names' => [], ]; - $clients = Client::scope()->get(); - foreach ( $clients as $client ) { + $clients = Client::where('company_id', $this->company->id)->cursor()->each(function ($client){ $this->addClientToMaps( $client ); - } + }); - $contacts = ClientContact::scope()->get(); - foreach ( $contacts as $contact ) { + $contacts = ClientContact::where('company_id', $this->company->id)->cursor()->each(function ($contact){ $this->addContactToMaps( $contact ); - } + }); - $invoices = Invoice::scope()->get(); - foreach ( $invoices as $invoice ) { + $invoices = Invoice::where('company_id', $this->company->id)->cursor()->each(function ($invoice){ $this->addInvoiceToMaps( $invoice ); - } + }); - $products = Product::scope()->get(); - foreach ( $products as $product ) { + $products = Product::where('company_id', $this->company->id)->cursor()->each(function ($product){ $this->addProductToMaps( $product ); - } + }); - $projects = Project::scope()->get(); - foreach ( $projects as $project ) { + $projects = Project::where('company_id', $this->company->id)->cursor()->each(function ($project){ $this->addProjectToMaps( $project ); - } + }); $countries = Country::all(); foreach ( $countries as $country ) { @@ -481,17 +476,16 @@ class CSVImport implements ShouldQueue { $this->maps['payment_types'][ strtolower( $payment_type->name ) ] = $payment_type->id; } - $vendors = Vendor::scope()->get(); - foreach ( $vendors as $vendor ) { + $vendors = Vendor::where('company_id', $this->company->id)->cursor()->each(function ($vendor){ $this->addVendorToMaps( $vendor ); - } + }); - $expenseCaegories = ExpenseCategory::scope()->get(); + $expenseCaegories = ExpenseCategory::where('company_id', $this->company->id)->get(); foreach ( $expenseCaegories as $category ) { $this->addExpenseCategoryToMaps( $category ); } - $taxRates = TaxRate::scope()->get(); + $taxRates = TaxRate::where('company_id', $this->company->id)->get(); foreach ( $taxRates as $taxRate ) { $name = trim( strtolower( $taxRate->name ) ); $this->maps['tax_rates'][ $name ] = $taxRate->rate; From d80d440ca3c0dab7601df6d63f868571fa5bbe73 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 11 Dec 2021 08:43:14 +1100 Subject: [PATCH 15/18] Fixes for freshbooks imports --- app/Jobs/Import/CSVImport.php | 37 +++++++++++++++-------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/app/Jobs/Import/CSVImport.php b/app/Jobs/Import/CSVImport.php index 3a9a44f65969..1933d10ecbbe 100644 --- a/app/Jobs/Import/CSVImport.php +++ b/app/Jobs/Import/CSVImport.php @@ -440,57 +440,52 @@ class CSVImport implements ShouldQueue { 'tax_names' => [], ]; - $clients = Client::where('company_id', $this->company->id)->cursor()->each(function ($client){ + Client::where('company_id', $this->company->id)->cursor()->each(function ($client){ $this->addClientToMaps( $client ); }); - $contacts = ClientContact::where('company_id', $this->company->id)->cursor()->each(function ($contact){ + ClientContact::where('company_id', $this->company->id)->cursor()->each(function ($contact){ $this->addContactToMaps( $contact ); }); - $invoices = Invoice::where('company_id', $this->company->id)->cursor()->each(function ($invoice){ + Invoice::where('company_id', $this->company->id)->cursor()->each(function ($invoice){ $this->addInvoiceToMaps( $invoice ); }); - $products = Product::where('company_id', $this->company->id)->cursor()->each(function ($product){ + Product::where('company_id', $this->company->id)->cursor()->each(function ($product){ $this->addProductToMaps( $product ); }); - $projects = Project::where('company_id', $this->company->id)->cursor()->each(function ($project){ + Project::where('company_id', $this->company->id)->cursor()->each(function ($project){ $this->addProjectToMaps( $project ); }); - $countries = Country::all(); - foreach ( $countries as $country ) { + Country::all()->each(function ($country){ $this->maps['countries'][ strtolower( $country->name ) ] = $country->id; $this->maps['countries2'][ strtolower( $country->iso_3166_2 ) ] = $country->id; - } + }); - $currencies = Currency::all(); - foreach ( $currencies as $currency ) { + Currency::all()->each(function ($currency){ $this->maps['currencies'][ strtolower( $currency->code ) ] = $currency->id; - } + }); - $payment_types = PaymentType::all(); - foreach ( $payment_types as $payment_type ) { + PaymentType::all()->each(function ($payment_type){ $this->maps['payment_types'][ strtolower( $payment_type->name ) ] = $payment_type->id; - } + }); - $vendors = Vendor::where('company_id', $this->company->id)->cursor()->each(function ($vendor){ + Vendor::where('company_id', $this->company->id)->cursor()->each(function ($vendor){ $this->addVendorToMaps( $vendor ); }); - $expenseCaegories = ExpenseCategory::where('company_id', $this->company->id)->get(); - foreach ( $expenseCaegories as $category ) { + ExpenseCategory::where('company_id', $this->company->id)->cursor()->each(function ($category){ $this->addExpenseCategoryToMaps( $category ); - } + }); - $taxRates = TaxRate::where('company_id', $this->company->id)->get(); - foreach ( $taxRates as $taxRate ) { + TaxRate::where('company_id', $this->company->id)->cursor()->each(function ($taxRate){ $name = trim( strtolower( $taxRate->name ) ); $this->maps['tax_rates'][ $name ] = $taxRate->rate; $this->maps['tax_names'][ $name ] = $taxRate->name; - } + }); } /** From 107ec59ebe53cfa3e8029bff8b27679194cb54c7 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 11 Dec 2021 20:29:03 +1100 Subject: [PATCH 16/18] Login Controller cleanup --- app/Http/Controllers/Auth/LoginController.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 000cfdf98a31..20186943c2e5 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -236,15 +236,6 @@ class LoginController extends BaseController } - //method above override this - // $user->company_users->each(function ($company_user) use($request){ - - // if($company_user->tokens->count() == 0){ - // CreateCompanyToken::dispatchNow($company_user->company, $company_user->user, $request->server('HTTP_USER_AGENT')); - // } - - // }); - /*On the hosted platform, only owners can login for free/pro accounts*/ if(Ninja::isHosted() && !$cu->first()->is_owner && !$user->account->isEnterpriseClient()) return response()->json(['message' => 'Pro / Free accounts only the owner can log in. Please upgrade'], 403); From 65493c47a5e56a43ce788bce3a6e3cac1d7cacaa Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 11 Dec 2021 20:49:29 +1100 Subject: [PATCH 17/18] Change batch() to ->queue() --- app/Http/Controllers/Auth/LoginController.php | 4 ++-- app/Http/Controllers/CompanyController.php | 2 +- app/Http/Controllers/PostMarkController.php | 4 ++-- app/Http/Controllers/PreviewController.php | 2 +- app/Http/Middleware/QueryLogging.php | 2 +- app/Jobs/Account/CreateAccount.php | 2 +- app/Jobs/Mail/NinjaMailerJob.php | 4 ++-- app/Jobs/RecurringInvoice/SendRecurring.php | 2 +- app/Jobs/Util/Import.php | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 20186943c2e5..2d8ea8fef702 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -176,7 +176,7 @@ class LoginController extends BaseController LightLogs::create(new LoginSuccess()) ->increment() - ->batch(); + ->queue(); $user = $this->guard()->user(); @@ -249,7 +249,7 @@ class LoginController extends BaseController LightLogs::create(new LoginFailure()) ->increment() - ->batch(); + ->queue(); // SystemLogger::dispatch( // json_encode(['ip' => request()->getClientIp()]), diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index b83d472977f0..7d6e0814df3c 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -504,7 +504,7 @@ class CompanyController extends BaseController LightLogs::create(new AccountDeleted()) ->increment() - ->batch(); + ->queue(); } else { $company_id = $company->id; diff --git a/app/Http/Controllers/PostMarkController.php b/app/Http/Controllers/PostMarkController.php index e6e1d2797fad..60bb918e688a 100644 --- a/app/Http/Controllers/PostMarkController.php +++ b/app/Http/Controllers/PostMarkController.php @@ -170,7 +170,7 @@ class PostMarkController extends BaseController $request->input('MessageID') ); - LightLogs::create($bounce)->batch(); + LightLogs::create($bounce)->queue(); SystemLogger::dispatch($request->all(), SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_BOUNCED, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company); } @@ -212,7 +212,7 @@ class PostMarkController extends BaseController $request->input('MessageID') ); - LightLogs::create($spam)->batch(); + LightLogs::create($spam)->queue(); SystemLogger::dispatch($request->all(), SystemLog::CATEGORY_MAIL, SystemLog::EVENT_MAIL_SPAM_COMPLAINT, SystemLog::TYPE_WEBHOOK_RESPONSE, $this->invitation->contact->client, $this->invitation->company); } diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 052a1a3c9dcb..9978033a4430 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -294,7 +294,7 @@ class PreviewController extends BaseController { LightLogs::create(new LivePreview()) ->increment() - ->batch(); + ->queue(); } diff --git a/app/Http/Middleware/QueryLogging.php b/app/Http/Middleware/QueryLogging.php index 4b08ad38ca44..1eac23e7f310 100644 --- a/app/Http/Middleware/QueryLogging.php +++ b/app/Http/Middleware/QueryLogging.php @@ -68,7 +68,7 @@ class QueryLogging } LightLogs::create(new DbQuery($request->method(), urldecode($request->url()), $count, $time, $ip)) - ->batch(); + ->queue(); } diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index a34f266c764d..75b230298e06 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -136,7 +136,7 @@ class CreateAccount LightLogs::create(new AnalyticsAccountCreated()) ->increment() - ->batch(); + ->queue(); diff --git a/app/Jobs/Mail/NinjaMailerJob.php b/app/Jobs/Mail/NinjaMailerJob.php index 72cc5fcef935..83a5b62bff7e 100644 --- a/app/Jobs/Mail/NinjaMailerJob.php +++ b/app/Jobs/Mail/NinjaMailerJob.php @@ -110,7 +110,7 @@ class NinjaMailerJob implements ShouldQueue ->send($this->nmo->mailable); LightLogs::create(new EmailSuccess($this->nmo->company->company_key)) - ->batch(); + ->queue(); /* Count the amount of emails sent across all the users accounts */ Cache::increment($this->company->account->key); @@ -279,7 +279,7 @@ class NinjaMailerJob implements ShouldQueue $job_failure->string_metric6 = substr($errors, 0, 150); LightLogs::create($job_failure) - ->batch(); + ->queue(); } public function failed($exception = null) diff --git a/app/Jobs/RecurringInvoice/SendRecurring.php b/app/Jobs/RecurringInvoice/SendRecurring.php index 46ba3400fc3e..0f722256a3c1 100644 --- a/app/Jobs/RecurringInvoice/SendRecurring.php +++ b/app/Jobs/RecurringInvoice/SendRecurring.php @@ -192,7 +192,7 @@ class SendRecurring implements ShouldQueue $job_failure->string_metric6 = $exception->getMessage(); LightLogs::create($job_failure) - ->batch(); + ->queue(); nlog(print_r($exception->getMessage(), 1)); } diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index 467ac973da5d..347ed8998dd7 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -1832,7 +1832,7 @@ class Import implements ShouldQueue $job_failure->string_metric6 = $exception->getMessage(); LightLogs::create($job_failure) - ->batch(); + ->queue(); info(print_r($exception->getMessage(), 1)); From b56167da3946eb60d48bcddec523a4b159c11f89 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 11 Dec 2021 21:12:48 +1100 Subject: [PATCH 18/18] Fixes for duplicate quote approved notification --- app/Http/Controllers/Auth/LoginController.php | 106 ++++++++++++++---- .../Quote/QuoteApprovedNotification.php | 9 -- app/Services/Quote/QuoteService.php | 8 +- 3 files changed, 88 insertions(+), 35 deletions(-) diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 2d8ea8fef702..c0c53faa0bd3 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -102,7 +102,6 @@ class LoginController extends BaseController * * @return Response|User Process user login. * - * * @throws \Illuminate\Validation\ValidationException * @OA\Post( * path="/api/v1/login", @@ -386,13 +385,31 @@ class LoginController extends BaseController $cu = CompanyUser::query() ->where('user_id', auth()->user()->id); - $cu->first()->account->companies->each(function ($company) use($cu){ + // $cu->first()->account->companies->each(function ($company) use($cu){ - if($company->tokens()->where('is_system', true)->count() == 0) + // if($company->tokens()->where('is_system', true)->count() == 0) + // { + // CreateCompanyToken::dispatchNow($company, $cu->first()->user, request()->server('HTTP_USER_AGENT')); + // } + // }); + + + if($existing_user->company_users()->count() != $existing_user->tokens()->count()) { - CreateCompanyToken::dispatchNow($company, $cu->first()->user, request()->server('HTTP_USER_AGENT')); + + $existing_user->companies->each(function($company) use($existing_user){ + + if(!CompanyToken::where('user_id', $existing_user->id)->where('company_id', $company->id)->exists()){ + + CreateCompanyToken::dispatchNow($company, $existing_user, "Google_O_Auth"); + + } + + }); + } - }); + + if(Ninja::isHosted() && !$cu->first()->is_owner && !$existing_user->account->isEnterpriseClient()) return response()->json(['message' => 'Pro / Free accounts only the owner can log in. Please upgrade'], 403); @@ -420,13 +437,30 @@ class LoginController extends BaseController $cu = CompanyUser::query() ->where('user_id', auth()->user()->id); - $cu->first()->account->companies->each(function ($company) use($cu){ + // $cu->first()->account->companies->each(function ($company) use($cu){ - if($company->tokens()->where('is_system', true)->count() == 0) + // if($company->tokens()->where('is_system', true)->count() == 0) + // { + // CreateCompanyToken::dispatchNow($company, $cu->first()->user, request()->server('HTTP_USER_AGENT')); + // } + // }); + + if($existing_login_user->company_users()->count() != $existing_login_user->tokens()->count()) { - CreateCompanyToken::dispatchNow($company, $cu->first()->user, request()->server('HTTP_USER_AGENT')); + + $existing_login_user->companies->each(function($company) use($existing_login_user){ + + if(!CompanyToken::where('user_id', $existing_login_user->id)->where('company_id', $company->id)->exists()){ + + CreateCompanyToken::dispatchNow($company, $existing_login_user, "Google_O_Auth"); + + } + + }); + } - }); + + if(Ninja::isHosted() && !$cu->first()->is_owner && !$existing_login_user->account->isEnterpriseClient()) return response()->json(['message' => 'Pro / Free accounts only the owner can log in. Please upgrade'], 403); @@ -458,13 +492,30 @@ class LoginController extends BaseController $cu = CompanyUser::query() ->where('user_id', auth()->user()->id); - $cu->first()->account->companies->each(function ($company) use($cu){ + // $cu->first()->account->companies->each(function ($company) use($cu){ - if($company->tokens()->where('is_system', true)->count() == 0) + // if($company->tokens()->where('is_system', true)->count() == 0) + // { + // CreateCompanyToken::dispatchNow($company, $cu->first()->user, request()->server('HTTP_USER_AGENT')); + // } + // }); + + + if($existing_login_user->company_users()->count() != $existing_login_user->tokens()->count()) { - CreateCompanyToken::dispatchNow($company, $cu->first()->user, request()->server('HTTP_USER_AGENT')); + + $existing_login_user->companies->each(function($company) use($existing_login_user){ + + if(!CompanyToken::where('user_id', $existing_login_user->id)->where('company_id', $company->id)->exists()){ + + CreateCompanyToken::dispatchNow($company, $existing_login_user, "Google_O_Auth"); + + } + + }); + } - }); + if(Ninja::isHosted() && !$cu->first()->is_owner && !$existing_login_user->account->isEnterpriseClient()) return response()->json(['message' => 'Pro / Free accounts only the owner can log in. Please upgrade'], 403); @@ -502,13 +553,30 @@ class LoginController extends BaseController $cu = CompanyUser::whereUserId(auth()->user()->id); - $cu->first()->account->companies->each(function ($company) use($cu){ + // $cu->first()->account->companies->each(function ($company) use($cu){ + + // if($company->tokens()->where('is_system', true)->count() == 0) + // { + // CreateCompanyToken::dispatchNow($company, $cu->first()->user, request()->server('HTTP_USER_AGENT')); + // } + // }); + + if(auth()->user()->company_users()->count() != auth()->user()->tokens()->count()) + { + + auth()->user()->companies->each(function($company) { + + if(!CompanyToken::where('user_id', auth()->user()->id)->where('company_id', $company->id)->exists()){ + + CreateCompanyToken::dispatchNow($company, auth()->user(), "Google_O_Auth"); + + } + + }); + + } + - if($company->tokens()->where('is_system', true)->count() == 0) - { - CreateCompanyToken::dispatchNow($company, $cu->first()->user, request()->server('HTTP_USER_AGENT')); - } - }); if(Ninja::isHosted() && !$cu->first()->is_owner && !auth()->user()->account->isEnterpriseClient()) return response()->json(['message' => 'Pro / Free accounts only the owner can log in. Please upgrade'], 403); diff --git a/app/Listeners/Quote/QuoteApprovedNotification.php b/app/Listeners/Quote/QuoteApprovedNotification.php index 59199d0c535d..591e2a8b8102 100644 --- a/app/Listeners/Quote/QuoteApprovedNotification.php +++ b/app/Listeners/Quote/QuoteApprovedNotification.php @@ -57,9 +57,6 @@ class QuoteApprovedNotification implements ShouldQueue if(!$user) continue; - /* This is only here to handle the alternate message channels - ie Slack */ - // $notification = new EntitySentNotification($event->invitation, 'quote'); - /* Returns an array of notification methods */ $methods = $this->findUserNotificationTypes($quote->invitations()->first(), $company_user, 'quote', ['all_notifications', 'quote_approved', 'quote_approved_all']); @@ -67,7 +64,6 @@ class QuoteApprovedNotification implements ShouldQueue if (($key = array_search('mail', $methods)) !== false) { unset($methods[$key]); - $nmo->to_user = $user; NinjaMailerJob::dispatch($nmo); @@ -76,11 +72,6 @@ class QuoteApprovedNotification implements ShouldQueue $first_notification_sent = false; } - /* Override the methods in the Notification Class */ - // $notification->method = $methods; - - // Notify on the alternate channels - // $user->notify($notification); } } } diff --git a/app/Services/Quote/QuoteService.php b/app/Services/Quote/QuoteService.php index dcc4016e802b..f830ba6bc76f 100644 --- a/app/Services/Quote/QuoteService.php +++ b/app/Services/Quote/QuoteService.php @@ -110,7 +110,7 @@ class QuoteService $contact = $this->quote->invitations->first()->contact; } - event(new QuoteWasApproved($contact, $this->quote, $this->quote->company, Ninja::eventVars())); + // event(new QuoteWasApproved($contact, $this->quote, $this->quote->company, Ninja::eventVars())); if ($this->quote->client->getSetting('auto_convert_quote')) { $this->convert(); @@ -123,12 +123,6 @@ class QuoteService } - - // if ($this->quote->client->getSetting('auto_archive_quote')) { - // $quote_repo = new QuoteRepository(); - // $quote_repo->archive($this->quote); - // } - return $this; }