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; + } /**