From 8d345cc1b86c9fb500e5c45ff2d5481551334beb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 14 Oct 2023 11:44:58 +1100 Subject: [PATCH 1/3] Adjustment for missing props --- app/Http/Requests/ClientPortal/RegisterRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/ClientPortal/RegisterRequest.php b/app/Http/Requests/ClientPortal/RegisterRequest.php index c2c5e8ecfcea..860628340369 100644 --- a/app/Http/Requests/ClientPortal/RegisterRequest.php +++ b/app/Http/Requests/ClientPortal/RegisterRequest.php @@ -40,7 +40,7 @@ class RegisterRequest extends FormRequest $rules = []; foreach ($this->company()->client_registration_fields as $field) { - if ($field['visible']) { + if ($field['visible'] ?? true) { $rules[$field['key']] = $field['required'] ? ['bail','required'] : ['sometimes']; } } From 17d11710a7147db67b3623386365398752b4bbcf Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 15 Oct 2023 05:49:14 +1100 Subject: [PATCH 2/3] Minor fixes --- .../Invoices/ProcessInvoicesInBulkRequest.php | 11 ++++++ .../Requests/Payment/StorePaymentRequest.php | 2 +- app/Utils/HtmlEngine.php | 10 ++--- app/Utils/Traits/MakesHash.php | 22 ++++++++++- app/Utils/VendorHtmlEngine.php | 39 +++++++++++-------- 5 files changed, 61 insertions(+), 23 deletions(-) diff --git a/app/Http/Requests/ClientPortal/Invoices/ProcessInvoicesInBulkRequest.php b/app/Http/Requests/ClientPortal/Invoices/ProcessInvoicesInBulkRequest.php index 1ee0490b8fb6..73724da000c3 100644 --- a/app/Http/Requests/ClientPortal/Invoices/ProcessInvoicesInBulkRequest.php +++ b/app/Http/Requests/ClientPortal/Invoices/ProcessInvoicesInBulkRequest.php @@ -28,4 +28,15 @@ class ProcessInvoicesInBulkRequest extends FormRequest 'invoices' => ['array'], ]; } + + public function prepareForValidation() + { + $input = $this->all(); + + if(isset($input['invoices'])){ + $input['invoices'] = array_unique($input['invoices']); + } + + $this->replace($input); + } } diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index e51eeb50bc57..b110abcf38ec 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -51,7 +51,7 @@ class StorePaymentRequest extends Request $credits_total = 0; if (isset($input['client_id']) && is_string($input['client_id'])) { - $input['client_id'] = $this->decodePrimaryKey($input['client_id']); + $input['client_id'] = $this->decodePrimaryKey($input['client_id'], true); } if (array_key_exists('assigned_user_id', $input) && is_string($input['assigned_user_id'])) { diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index f96d37be5df8..538b40b1d311 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -1014,17 +1014,17 @@ html { */ protected function generateEntityImagesMarkup() { - // if (!$this->client->getSetting('embed_documents') && !$this->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) { - // return ''; - // } + if (!$this->client->getSetting('embed_documents') || !$this->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) { + return ''; + } $dom = new \DOMDocument('1.0', 'UTF-8'); $container = $dom->createElement('div'); $container->setAttribute('style', 'display:grid; grid-auto-flow: row; grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr);justify-items: center;'); - foreach ($this->entity->documents as $document) { - if (!$document->isImage()) { + foreach ($this->entity->documents()->where('is_public',true)->get() as $document) { + if (!$document->isImage()) { continue; } diff --git a/app/Utils/Traits/MakesHash.php b/app/Utils/Traits/MakesHash.php index 63c151b93530..dc8d6d158a40 100644 --- a/app/Utils/Traits/MakesHash.php +++ b/app/Utils/Traits/MakesHash.php @@ -62,8 +62,27 @@ trait MakesHash return $hashids->encode($value); } - public function decodePrimaryKey($value) + public function decodePrimaryKey($value, $return_string_failure = false) { + + try { + $hashids = new Hashids(config('ninja.hash_salt'), 10); + + $decoded_array = $hashids->decode($value); + + if(isset($decoded_array[0]) ?? false) { + return $decoded_array[0]; + } elseif($return_string_failure) { + return "Invalid Primary Key"; + } else { + throw new \Exception('Invalid Primary Key'); + } + + } catch (\Exception $e) { + return response()->json(['error'=>'Invalid primary key'], 400); + } + + /* try { $hashids = new Hashids(config('ninja.hash_salt'), 10); @@ -77,6 +96,7 @@ trait MakesHash } catch (\Exception $e) { return response()->json(['error'=>'Invalid primary key'], 400); } + */ } public function transformKeys($keys) diff --git a/app/Utils/VendorHtmlEngine.php b/app/Utils/VendorHtmlEngine.php index eb1f595584e5..7bd05d75924c 100644 --- a/app/Utils/VendorHtmlEngine.php +++ b/app/Utils/VendorHtmlEngine.php @@ -12,18 +12,19 @@ namespace App\Utils; -use App\Models\Country; -use App\Models\CreditInvitation; -use App\Models\InvoiceInvitation; -use App\Models\PurchaseOrderInvitation; -use App\Models\QuoteInvitation; -use App\Models\RecurringInvoiceInvitation; -use App\Utils\Traits\AppSetup; -use App\Utils\Traits\DesignCalculator; -use App\Utils\Traits\MakesDates; use Exception; +use App\Models\Account; +use App\Models\Country; +use App\Utils\Traits\AppSetup; +use App\Models\QuoteInvitation; +use App\Models\CreditInvitation; +use App\Utils\Traits\MakesDates; +use App\Models\InvoiceInvitation; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; +use App\Utils\Traits\DesignCalculator; +use App\Models\PurchaseOrderInvitation; +use App\Models\RecurringInvoiceInvitation; /** * Note the premise used here is that any currencies will be formatted back to the company currency and not @@ -775,31 +776,37 @@ html { */ protected function generateEntityImagesMarkup() { - if ($this->company->getSetting('embed_documents') === false) { + + if (!$this->vendor->getSetting('embed_documents') || !$this->company->account->hasFeature(Account::FEATURE_DOCUMENTS)) { return ''; } $dom = new \DOMDocument('1.0', 'UTF-8'); $container = $dom->createElement('div'); - $container->setAttribute('style', 'display:grid; grid-auto-flow: row; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr);'); - - foreach ($this->entity->documents as $document) { + $container->setAttribute('style', 'display:grid; grid-auto-flow: row; grid-template-columns: repeat(2, 1fr); grid-template-rows: repeat(2, 1fr);justify-items: center;'); + + foreach ($this->entity->documents()->where('is_public',true)->get() as $document) { if (!$document->isImage()) { continue; } $image = $dom->createElement('img'); - $image->setAttribute('src', $document->generateUrl()); - $image->setAttribute('style', 'max-height: 100px; margin-top: 20px;'); + $image->setAttribute('src', "data:image/png;base64,".base64_encode($document->getFile())); + $image->setAttribute('style', 'max-width: 50%; margin-top: 20px;'); $container->appendChild($image); } $dom->appendChild($container); - return $dom->saveHTML(); + $html = $dom->saveHTML(); + + $dom = null; + + return $html; + } /** From 14144f72e4da70b05392b8f22ef311ad2e55db61 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 15 Oct 2023 16:57:17 +1100 Subject: [PATCH 3/3] Updated translations --- lang/en/texts.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lang/en/texts.php b/lang/en/texts.php index 49eb412a6202..5fe2741906a1 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -3679,9 +3679,9 @@ $LANG = array( 'send_date' => 'Send Date', 'auto_bill_on' => 'Auto Bill On', 'minimum_under_payment_amount' => 'Minimum Under Payment Amount', - 'allow_over_payment' => 'Allow Over Payment', + 'allow_over_payment' => 'Allow Overpayment', 'allow_over_payment_help' => 'Support paying extra to accept tips', - 'allow_under_payment' => 'Allow Under Payment', + 'allow_under_payment' => 'Allow Underpayment', 'allow_under_payment_help' => 'Support paying at minimum the partial/deposit amount', 'test_mode' => 'Test Mode', 'calculated_rate' => 'Calculated Rate', @@ -3978,8 +3978,8 @@ $LANG = array( 'account_balance' => 'Account Balance', 'thanks' => 'Thanks', 'minimum_required_payment' => 'Minimum required payment is :amount', - 'under_payments_disabled' => 'Company doesn\'t support under payments.', - 'over_payments_disabled' => 'Company doesn\'t support over payments.', + 'under_payments_disabled' => 'Company doesn\'t support underpayments.', + 'over_payments_disabled' => 'Company doesn\'t support overpayments.', 'saved_at' => 'Saved at :time', 'credit_payment' => 'Credit applied to Invoice :invoice_number', 'credit_subject' => 'New credit :number from :account', @@ -4654,8 +4654,8 @@ $LANG = array( 'search_purchase_order' => 'Search Purchase Order', 'search_purchase_orders' => 'Search Purchase Orders', 'login_url' => 'Login URL', - 'enable_applying_payments' => 'Enable Applying Payments', - 'enable_applying_payments_help' => 'Support separately creating and applying payments', + 'enable_applying_payments' => 'Manual Overpayments', + 'enable_applying_payments_help' => 'Support adding an overpayment amount manually on a payment', 'stock_quantity' => 'Stock Quantity', 'notification_threshold' => 'Notification Threshold', 'track_inventory' => 'Track Inventory',