From 6a911149cad9e0790595f737a03b376ff3ddb052 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 8 Jul 2022 17:28:49 +1000 Subject: [PATCH 1/7] Pad out expense when converted from Purchase Order --- .../PurchaseOrder/PurchaseOrderExpense.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/Services/PurchaseOrder/PurchaseOrderExpense.php b/app/Services/PurchaseOrder/PurchaseOrderExpense.php index f7c5857b0510..183dc236fb50 100644 --- a/app/Services/PurchaseOrder/PurchaseOrderExpense.php +++ b/app/Services/PurchaseOrder/PurchaseOrderExpense.php @@ -36,11 +36,23 @@ class PurchaseOrderExpense $expense->public_notes = $this->purchase_order->public_notes; $expense->uses_inclusive_taxes = $this->purchase_order->uses_inclusive_taxes; $expense->calculate_tax_by_amount = true; + $expense->private_notes = ctrans('texts.purchase_order_number_short') . " " . $this->purchase_order->number; + + $line_items = $this->purchase_order->line_items; + + $expense->public_notes = ''; + + foreach($line_items as $line_item){ + $expense->public_notes .= $line_item->quantity . " x " . $line_item->product_key. " [ " .$line_item->notes . " ]\n"; + } $tax_map = $this->purchase_order->calc()->getTaxMap(); - $expense->tax_amount1 = $this->purchase_order->total_taxes; - $expense->tax_name1 = ctrans("texts.tax"); + if($this->purchase_order->total_taxes > 0) + { + $expense->tax_amount1 = $this->purchase_order->total_taxes; + $expense->tax_name1 = ctrans("texts.tax"); + } $expense->save(); From 085fa8116924adb8cd6eda75dafd1bee9683ec93 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 8 Jul 2022 17:30:25 +1000 Subject: [PATCH 2/7] Pad out expense when converted from Purchase Order --- app/Services/PurchaseOrder/PurchaseOrderExpense.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Services/PurchaseOrder/PurchaseOrderExpense.php b/app/Services/PurchaseOrder/PurchaseOrderExpense.php index 183dc236fb50..c24597ce795e 100644 --- a/app/Services/PurchaseOrder/PurchaseOrderExpense.php +++ b/app/Services/PurchaseOrder/PurchaseOrderExpense.php @@ -13,9 +13,11 @@ namespace App\Services\PurchaseOrder; use App\Factory\ExpenseFactory; use App\Models\PurchaseOrder; +use App\Utils\Traits\GeneratesCounter; class PurchaseOrderExpense { + use GeneratesCounter; private PurchaseOrder $purchase_order; @@ -41,7 +43,7 @@ class PurchaseOrderExpense $line_items = $this->purchase_order->line_items; $expense->public_notes = ''; - + foreach($line_items as $line_item){ $expense->public_notes .= $line_item->quantity . " x " . $line_item->product_key. " [ " .$line_item->notes . " ]\n"; } @@ -54,6 +56,8 @@ class PurchaseOrderExpense $expense->tax_name1 = ctrans("texts.tax"); } + $expense->number = empty($expense->number) ? $this->getNextExpenseNumber($expense) : $expense->number; + $expense->save(); $this->purchase_order->expense_id = $expense->id; From 1d4e68938e36c3f04dce96fd2e3d54719e4abc60 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 9 Jul 2022 12:15:35 +1000 Subject: [PATCH 3/7] Handle pay now redirects offsite --- .../Controllers/ClientPortal/InvitationController.php | 2 +- .../Controllers/ClientPortal/PaymentController.php | 11 +++++++---- app/Http/Kernel.php | 2 ++ routes/client.php | 8 ++++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/InvitationController.php b/app/Http/Controllers/ClientPortal/InvitationController.php index 7cd2d273174a..26c3f671c4d9 100644 --- a/app/Http/Controllers/ClientPortal/InvitationController.php +++ b/app/Http/Controllers/ClientPortal/InvitationController.php @@ -239,7 +239,7 @@ class InvitationController extends Controller $invitation->contact->restore(); auth()->guard('contact')->loginUsingId($invitation->contact->id, true); - + $invoice = $invitation->invoice; if($invoice->partial > 0) diff --git a/app/Http/Controllers/ClientPortal/PaymentController.php b/app/Http/Controllers/ClientPortal/PaymentController.php index 1459af1bf596..add7551bd9de 100644 --- a/app/Http/Controllers/ClientPortal/PaymentController.php +++ b/app/Http/Controllers/ClientPortal/PaymentController.php @@ -90,14 +90,17 @@ class PaymentController extends Controller public function response(PaymentResponseRequest $request) { - + $gateway = CompanyGateway::findOrFail($request->input('company_gateway_id')); - $payment_hash = PaymentHash::where('hash', $request->payment_hash)->first(); + $payment_hash = PaymentHash::where('hash', $request->payment_hash)->firstOrFail(); $invoice = Invoice::with('client')->find($payment_hash->fee_invoice_id); - $client = $invoice ? $invoice->client : auth()->user()->client; + $client = $invoice ? $invoice->client : auth()->guard('contact')->user()->client; + + // 09-07-2022 catch duplicate responses for invoices that already paid here. + if($invoice && $invoice->status_id == Invoice::STATUS_PAID) + abort(400, 'Invoice paid. Duplicate submission'); return $gateway - // ->driver(auth()->user()->client) ->driver($client) ->setPaymentMethod($request->input('payment_method_id')) ->setPaymentHash($payment_hash) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 9557ade3a718..d73386f10960 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -44,6 +44,7 @@ use App\Http\Middleware\UrlSetDb; use App\Http\Middleware\UserVerified; use App\Http\Middleware\VendorLocale; use App\Http\Middleware\VerifyCsrfToken; +use App\Http\Middleware\VerifyHash; use Illuminate\Auth\Middleware\AuthenticateWithBasicAuth; use Illuminate\Auth\Middleware\Authorize; use Illuminate\Auth\Middleware\EnsureEmailIsVerified; @@ -161,6 +162,7 @@ class Kernel extends HttpKernel 'locale' => Locale::class, 'vendor_locale' => VendorLocale::class, 'contact_register' => ContactRegister::class, + 'verify_hash' => VerifyHash::class, 'shop_token_auth' => ShopTokenAuth::class, 'phantom_secret' => PhantomSecret::class, 'contact_key_login' => ContactKeyLogin::class, diff --git a/routes/client.php b/routes/client.php index b6750d0ca76a..db7a50434008 100644 --- a/routes/client.php +++ b/routes/client.php @@ -53,8 +53,9 @@ Route::group(['middleware' => ['auth:contact', 'locale', 'domain_db','check_clie Route::get('payments', 'ClientPortal\PaymentController@index')->name('payments.index')->middleware('portal_enabled'); Route::get('payments/{payment}', 'ClientPortal\PaymentController@show')->name('payments.show'); - Route::post('payments/process/response', 'ClientPortal\PaymentController@response')->name('payments.response'); - Route::get('payments/process/response', 'ClientPortal\PaymentController@response')->name('payments.response.get'); + + // Route::post('payments/process/response', 'ClientPortal\PaymentController@response')->name('payments.response'); + // Route::get('payments/process/response', 'ClientPortal\PaymentController@response')->name('payments.response.get'); Route::get('profile/{client_contact}/edit', 'ClientPortal\ProfileController@edit')->name('profile.edit'); Route::put('profile/{client_contact}/edit', 'ClientPortal\ProfileController@update')->name('profile.update'); @@ -99,6 +100,9 @@ Route::group(['middleware' => ['auth:contact', 'locale', 'domain_db','check_clie }); +Route::post('payments/process/response', 'ClientPortal\PaymentController@response')->name('client.payments.response')->middleware(['locale', 'domain_db', 'verify_hash']); +Route::get('payments/process/response', 'ClientPortal\PaymentController@response')->name('client.payments.response.get')->middleware(['locale', 'domain_db', 'verify_hash']); + Route::get('client/subscriptions/{subscription}/purchase', 'ClientPortal\SubscriptionPurchaseController@index')->name('client.subscription.purchase')->middleware('domain_db'); Route::group(['middleware' => ['invite_db'], 'prefix' => 'client', 'as' => 'client.'], function () { From 0a717f5ad50749996ae3f04214593d347d0e6353 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 9 Jul 2022 20:50:58 +1000 Subject: [PATCH 4/7] Verify hash --- app/Http/Middleware/VerifyHash.php | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/Http/Middleware/VerifyHash.php diff --git a/app/Http/Middleware/VerifyHash.php b/app/Http/Middleware/VerifyHash.php new file mode 100644 index 000000000000..f572221bac1f --- /dev/null +++ b/app/Http/Middleware/VerifyHash.php @@ -0,0 +1,37 @@ +has('payment_hash')){ + + $ph = PaymentHash::with('fee_invoice')->where('hash', $request->payment_hash)->first(); + + if($ph) + auth()->guard('contact')->loginUsingId($ph->fee_invoice->invitations->first()->contact->id, true); + + return $next($request); + + } + + abort(404, 'Unable to verify payment hash'); + } +} From 3ad3a2d8ea08c0a9a8b3d44c73580adf2a6aa9b1 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 10 Jul 2022 10:01:27 +1000 Subject: [PATCH 5/7] Add index to payment hashes --- ...07_09_235510_add_index_to_payment_hash.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 database/migrations/2022_07_09_235510_add_index_to_payment_hash.php diff --git a/database/migrations/2022_07_09_235510_add_index_to_payment_hash.php b/database/migrations/2022_07_09_235510_add_index_to_payment_hash.php new file mode 100644 index 000000000000..37c475e383a4 --- /dev/null +++ b/database/migrations/2022_07_09_235510_add_index_to_payment_hash.php @@ -0,0 +1,29 @@ +string('hash', 255)->index()->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + } +} From 15da7b841ab5327d326e7f69d34f8f91a387666e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 10 Jul 2022 10:56:37 +1000 Subject: [PATCH 6/7] Fixes for indexes --- app/Jobs/Util/VersionCheck.php | 2 +- .../2022_07_09_235510_add_index_to_payment_hash.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Jobs/Util/VersionCheck.php b/app/Jobs/Util/VersionCheck.php index f74a19e49bb9..71195bd1caeb 100644 --- a/app/Jobs/Util/VersionCheck.php +++ b/app/Jobs/Util/VersionCheck.php @@ -39,7 +39,7 @@ class VersionCheck implements ShouldQueue nlog("latest version = {$version_file}"); - if ($version_file) { + if (Ninja::isSelfHost() && $version_file) { Account::whereNotNull('id')->update(['latest_version' => $version_file]); } diff --git a/database/migrations/2022_07_09_235510_add_index_to_payment_hash.php b/database/migrations/2022_07_09_235510_add_index_to_payment_hash.php index 37c475e383a4..e5495b50a8b3 100644 --- a/database/migrations/2022_07_09_235510_add_index_to_payment_hash.php +++ b/database/migrations/2022_07_09_235510_add_index_to_payment_hash.php @@ -16,6 +16,17 @@ class AddIndexToPaymentHash extends Migration Schema::table('payment_hashes', function (Blueprint $table) { $table->string('hash', 255)->index()->change(); }); + + Schema::table('activities', function (Blueprint $table) { + $table->index(['quote_id', 'company_id']); + $table->index(['recurring_invoice_id', 'company_id']); + $table->index(['purchase_order_id', 'company_id']); + $table->index(['vendor_contact_id', 'company_id']); + }); + + Schema::table('products', function (Blueprint $table) { + $table->index(['company_id', 'user_id', 'assigned_user_id', 'updated_at'],'pro_co_us_up_index'); + }); } /** From c4b0b45144771d39808874fe0b346a3b86a19690 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 10 Jul 2022 14:30:46 +1000 Subject: [PATCH 7/7] Small changes for tests --- resources/lang/en/texts.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 8f8301a1fa4b..47a5724610fb 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2247,7 +2247,7 @@ $LANG = array( 'navigation_variables' => 'Navigation Variables', 'custom_variables' => 'Custom Variables', 'invalid_file' => 'Invalid file type', - 'add_documents_to_invoice' => 'Add documents to invoice', + 'add_documents_to_invoice' => 'Add Documents to Invoice', 'mark_expense_paid' => 'Mark paid', 'white_label_license_error' => 'Failed to validate the license, check storage/logs/laravel-error.log for more details.', 'plan_price' => 'Plan Price',