From 66a19407d13801afab283e45f25c81474e4ba033 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 8 Feb 2022 23:29:59 +1100 Subject: [PATCH] Fixes for currency set for paymentsa --- .../ClientPortal/EntityViewController.php | 59 ++++++++++++++++++- .../ClientPortal/InvitationController.php | 11 ++++ app/Repositories/PaymentRepository.php | 1 + resources/lang/en/texts.php | 1 + routes/client.php | 1 + 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/ClientPortal/EntityViewController.php b/app/Http/Controllers/ClientPortal/EntityViewController.php index 3308e8a5c6..014faf172d 100644 --- a/app/Http/Controllers/ClientPortal/EntityViewController.php +++ b/app/Http/Controllers/ClientPortal/EntityViewController.php @@ -2,12 +2,19 @@ namespace App\Http\Controllers\ClientPortal; +use App\Events\Credit\CreditWasViewed; +use App\Events\Invoice\InvoiceWasViewed; +use App\Events\Misc\InvitationWasViewed; +use App\Events\Quote\QuoteWasViewed; use App\Http\Controllers\Controller; +use App\Utils\Ninja; use App\Utils\Traits\MakesHash; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Str; use Illuminate\View\View; class EntityViewController extends Controller @@ -19,7 +26,7 @@ class EntityViewController extends Controller * * @var array */ - private $entity_types = ['invoice', 'quote']; + private $entity_types = ['invoice', 'quote', 'credit', 'recurring_invoice']; /** * Show the entity outside client portal. @@ -118,4 +125,54 @@ class EntityViewController extends Controller return back(); } + + public function handlePasswordSet(Request $request) + { + $entity_obj = 'App\Models\\'.ucfirst(Str::camel($request->entity_type)).'Invitation'; + $key = $request->entity_type.'_id'; + + $invitation = $entity_obj::where('key', $request->invitation_key) + ->whereHas($request->entity_type, function ($query) { + $query->where('is_deleted',0); + }) + ->with('contact.client') + ->first(); + + $contact = $invitation->contact; + $contact->password = Hash::make($request->password); + $contact->save(); + + $request->session()->invalidate(); + auth()->guard('contact')->loginUsingId($contact->id, true); + + if (! $invitation->viewed_date) { + $invitation->markViewed(); + + event(new InvitationWasViewed($invitation->{$request->entity_type}, $invitation, $invitation->{$request->entity_type}->company, Ninja::eventVars())); + + $this->fireEntityViewedEvent($invitation, $request->entity_type); + } + + return redirect()->route('client.'.$request->entity_type.'.show', [$request->entity_type => $this->encodePrimaryKey($invitation->{$key})]); + + } + + private function fireEntityViewedEvent($invitation, $entity_string) + { + switch ($entity_string) { + case 'invoice': + event(new InvoiceWasViewed($invitation, $invitation->company, Ninja::eventVars())); + break; + case 'quote': + event(new QuoteWasViewed($invitation, $invitation->company, Ninja::eventVars())); + break; + case 'credit': + event(new CreditWasViewed($invitation, $invitation->company, Ninja::eventVars())); + break; + default: + // code... + break; + } + } + } diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index 0748afca7a..6554ecbbb6 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -102,6 +102,17 @@ class InvitationController extends Controller auth()->guard('contact')->loginUsingId($client_contact->id, true); } elseif ((bool) $invitation->contact->client->getSetting('enable_client_portal_password') !== false) { + + //if no contact password has been set - allow user to set password - then continue to view entity + if(empty($invitation->contact->password)){ + + return $this->render('view_entity.set_password', [ + 'root' => 'themes', + 'entity_type' => $entity, + 'invitation_key' => $invitation_key + ]); + } + $this->middleware('auth:contact'); return redirect()->route('client.login'); diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index be59fe955d..850814295d 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -210,6 +210,7 @@ class PaymentRepository extends BaseRepository { $payment->exchange_currency_id = $company_currency; $payment->currency_id = $client_currency; + return $payment; } $payment->currency_id = $company_currency; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 894ce33d4c..bf4f62a6d5 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -4544,6 +4544,7 @@ $LANG = array( 'activity_123' => ':user deleted recurring expense :recurring_expense', 'activity_124' => ':user restored recurring expense :recurring_expense', 'fpx' => "FPX", + 'to_view_entity_set_password' => 'To view the :entity you need to set password.', ); diff --git a/routes/client.php b/routes/client.php index ecdf91f81a..3e69a4d082 100644 --- a/routes/client.php +++ b/routes/client.php @@ -18,6 +18,7 @@ Route::post('client/password/reset', 'Auth\ContactResetPasswordController@reset' Route::get('view/{entity_type}/{invitation_key}', 'ClientPortal\EntityViewController@index')->name('client.entity_view'); Route::get('view/{entity_type}/{invitation_key}/password', 'ClientPortal\EntityViewController@password')->name('client.entity_view.password'); Route::post('view/{entity_type}/{invitation_key}/password', 'ClientPortal\EntityViewController@handlePassword'); +Route::post('set_password', 'ClientPortal\EntityViewController@handlePasswordSet')->name('client.set_password'); Route::get('tmp_pdf/{hash}', 'ClientPortal\TempRouteController@index')->name('tmp_pdf');