From 830676f673aa55e3beb952af65beec460dde22e4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 17 Oct 2022 07:15:56 +1100 Subject: [PATCH 1/4] Add custom values into Expenses --- app/Import/Definitions/ExpenseMap.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Import/Definitions/ExpenseMap.php b/app/Import/Definitions/ExpenseMap.php index a0df8ed87655..e9075e5d7c72 100644 --- a/app/Import/Definitions/ExpenseMap.php +++ b/app/Import/Definitions/ExpenseMap.php @@ -36,6 +36,10 @@ class ExpenseMap 17 => 'expense.tax_rate3', 18 => 'expense.uses_inclusive_taxes', 19 => 'expense.payment_date', + 20 => 'expense.custom_value1', + 21 => 'expense.custom_value2', + 22 => 'expense.custom_value3', + 23 => 'expense.custom_value4', ]; } @@ -63,6 +67,10 @@ class ExpenseMap 17 => 'texts.tax_rate3', 18 => 'texts.uses_inclusive_taxes', 19 => 'texts.payment_date', + 20 => 'texts.custom_value1', + 21 => 'texts.custom_value2', + 22 => 'texts.custom_value3', + 23 => 'texts.custom_value4', ]; } From 76525ceacfcc452e9df78113457df9fea95f66ce Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 18 Oct 2022 20:30:55 +1100 Subject: [PATCH 2/4] System Log Checkout Failures --- app/Jobs/Account/CreateAccount.php | 2 +- app/PaymentDrivers/BaseDriver.php | 10 +++++----- app/PaymentDrivers/CheckoutCom/CreditCard.php | 12 ++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/Jobs/Account/CreateAccount.php b/app/Jobs/Account/CreateAccount.php index 1e104c5e3d4e..e09128daa28f 100644 --- a/app/Jobs/Account/CreateAccount.php +++ b/app/Jobs/Account/CreateAccount.php @@ -86,7 +86,7 @@ class CreateAccount $sp794f3f->hosted_company_count = config('ninja.quotas.free.max_companies'); $sp794f3f->account_sms_verified = true; - if(in_array($this->getDomain($this->request['email']), ['gmail.com', 'hotmail.com', 'outlook.com', 'yahoo.com', 'aol.com', 'mail.ru'])){ + if(in_array($this->getDomain($this->request['email']), ['yopmail.com','gmail.com', 'hotmail.com', 'outlook.com', 'yahoo.com', 'aol.com', 'mail.ru'])){ $sp794f3f->account_sms_verified = false; } diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index d637dfd6a1eb..fc57b368e589 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -602,11 +602,11 @@ class BaseDriver extends AbstractPaymentDriver } } - if ($this->company_gateway->require_contact_email) { - if ($this->checkRequiredResource($this->email)) { - $this->required_fields[] = 'contact_email'; - } - } + // if ($this->company_gateway->require_contact_email) { + // if ($this->checkRequiredResource($this->email)) { + // $this->required_fields[] = 'contact_email'; + // } + // } // if ($this->company_gateway->require_contact_name) { // if ($this->checkRequiredResource($this->first_name)) { diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index c645eb01e5e9..6e298ff1d276 100644 --- a/app/PaymentDrivers/CheckoutCom/CreditCard.php +++ b/app/PaymentDrivers/CheckoutCom/CreditCard.php @@ -14,9 +14,11 @@ namespace App\PaymentDrivers\CheckoutCom; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; +use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\Models\Payment; +use App\Models\SystemLog; use App\PaymentDrivers\CheckoutComPaymentDriver; use App\PaymentDrivers\Common\MethodInterface; use App\Utils\Traits\MakesHash; @@ -242,6 +244,16 @@ class CreditCard implements MethodInterface if ($response['status'] == 'Declined') { $this->checkout->unWindGatewayFees($this->checkout->payment_hash); + //18-10-2022 + SystemLogger::dispatch( + $response, + SystemLog::CATEGORY_GATEWAY_RESPONSE, + SystemLog::EVENT_GATEWAY_ERROR, + SystemLog::TYPE_CHECKOUT, + $this->checkout->client, + $this->checkout->client->company, + ); + return $this->processUnsuccessfulPayment($response); } } catch (CheckoutApiException $e) { From b72222c3c72051c705313daafbc22a281cc5a3d4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Oct 2022 09:17:32 +1100 Subject: [PATCH 3/4] Fixes for formatting of quantity column --- app/Utils/Number.php | 22 +++++- app/Utils/Traits/MakesInvoiceValues.php | 2 +- tests/Feature/ClientApiTest.php | 86 ++++++++++++++++++++++ tests/Unit/NumberTest.php | 94 ------------------------- 4 files changed, 106 insertions(+), 98 deletions(-) diff --git a/app/Utils/Number.php b/app/Utils/Number.php index e7e0c66673b5..f424dd5c739a 100644 --- a/app/Utils/Number.php +++ b/app/Utils/Number.php @@ -54,17 +54,33 @@ class Number * Formats a given value based on the clients currency. * * @param float $value The number to be formatted - * @param object $currency The client currency object * * @return string The formatted value */ - public static function formatValueNoTrailingZeroes($value, $currency) :string + public static function formatValueNoTrailingZeroes($value, $entity) :string { $value = floatval($value); + $currency = $entity->currency(); + $thousand = $currency->thousand_separator; $decimal = $currency->decimal_separator; - $precision = $currency->precision; + // $precision = $currency->precision; + + if ($entity instanceof Company) { + $country = $entity->country(); + } else { + $country = $entity->country; + } + + /* Country settings override client settings */ + if (isset($country->thousand_separator) && strlen($country->thousand_separator) >= 1) { + $thousand = $country->thousand_separator; + } + + if (isset($country->decimal_separator) && strlen($country->decimal_separator) >= 1) { + $decimal = $country->decimal_separator; + } $precision = 10; diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index e9e009a7b989..1c30b237b0fc 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -306,7 +306,7 @@ trait MakesInvoiceValues $data[$key][$table_type.".{$_table_type}4"] = strlen($item->custom_value4) >= 1 ? $helpers->formatCustomFieldValue($this->company->custom_fields, "{$_table_type}4", $item->custom_value4, $entity) : ''; if ($item->quantity > 0 || $item->cost > 0) { - $data[$key][$table_type.'.quantity'] = Number::formatValueNoTrailingZeroes($item->quantity, $entity_currency); + $data[$key][$table_type.'.quantity'] = Number::formatValueNoTrailingZeroes($item->quantity, $entity); $data[$key][$table_type.'.unit_cost'] = Number::formatMoneyNoRounding($item->cost, $entity); diff --git a/tests/Feature/ClientApiTest.php b/tests/Feature/ClientApiTest.php index 6ea5af053c29..aae531575656 100644 --- a/tests/Feature/ClientApiTest.php +++ b/tests/Feature/ClientApiTest.php @@ -12,6 +12,7 @@ namespace Tests\Feature; use App\Models\Country; +use App\Utils\Number; use App\Utils\Traits\MakesHash; use Illuminate\Database\Eloquent\Model; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -401,4 +402,89 @@ class ClientApiTest extends TestCase $response->assertStatus(302); } + + public function testRoundingDecimalsTwo() + { + $currency = $this->company; + + $x = Number::formatValueNoTrailingZeroes(0.05, $currency); + + $this->assertEquals(0.05, $x); + } + + public function testRoundingDecimalsThree() + { + $currency = $this->company; + + $x = Number::formatValueNoTrailingZeroes(0.005, $currency); + + $this->assertEquals(0.005, $x); + } + + public function testRoundingDecimalsFour() + { + $currency = $this->company; + + $x = Number::formatValueNoTrailingZeroes(0.0005, $currency); + + $this->assertEquals(0.0005, $x); + } + + public function testRoundingDecimalsFive() + { + $currency = $this->company; + + $x = Number::formatValueNoTrailingZeroes(0.00005, $currency); + + $this->assertEquals(0.00005, $x); + } + + public function testRoundingDecimalsSix() + { + $currency = $this->company; + + $x = Number::formatValueNoTrailingZeroes(0.000005, $currency); + + $this->assertEquals(0.000005, $x); + } + + public function testRoundingDecimalsSeven() + { + $currency = $this->company; + + $x = Number::formatValueNoTrailingZeroes(0.0000005, $currency); + + $this->assertEquals(0.0000005, $x); + } + + public function testRoundingDecimalsEight() + { + $currency = $this->company; + + $x = Number::formatValueNoTrailingZeroes(0.00000005, $currency); + + $this->assertEquals(0.00000005, $x); + } + + public function testRoundingPositive() + { + $currency = $this->company; + + $x = Number::formatValueNoTrailingZeroes(1.5, $currency); + $this->assertEquals(1.5, $x); + + $x = Number::formatValueNoTrailingZeroes(1.50, $currency); + $this->assertEquals(1.5, $x); + + $x = Number::formatValueNoTrailingZeroes(1.500, $currency); + $this->assertEquals(1.5, $x); + + $x = Number::formatValueNoTrailingZeroes(1.50005, $currency); + $this->assertEquals(1.50005, $x); + + $x = Number::formatValueNoTrailingZeroes(1.50000005, $currency); + $this->assertEquals(1.50000005, $x); + } + + } diff --git a/tests/Unit/NumberTest.php b/tests/Unit/NumberTest.php index 7ed201b8e69c..f76e15685bec 100644 --- a/tests/Unit/NumberTest.php +++ b/tests/Unit/NumberTest.php @@ -89,18 +89,6 @@ class NumberTest extends TestCase $this->assertEquals(2.15, $rounded); } - //this method proved an error! removing this method from production - // public function testImportFloatConversion() - // { - - // $amount = '€7,99'; - - // $converted_amount = Number::parseStringFloat($amount); - - // $this->assertEquals(799, $converted_amount); - - // } - public function testParsingStringCurrency() { $amount = '€7,99'; @@ -110,86 +98,4 @@ class NumberTest extends TestCase $this->assertEquals(7.99, $converted_amount); } - public function testRoundingDecimalsTwo() - { - $currency = Currency::find(1); - - $x = Number::formatValueNoTrailingZeroes(0.05, $currency); - - $this->assertEquals(0.05, $x); - } - - public function testRoundingDecimalsThree() - { - $currency = Currency::find(1); - - $x = Number::formatValueNoTrailingZeroes(0.005, $currency); - - $this->assertEquals(0.005, $x); - } - - public function testRoundingDecimalsFour() - { - $currency = Currency::find(1); - - $x = Number::formatValueNoTrailingZeroes(0.0005, $currency); - - $this->assertEquals(0.0005, $x); - } - - public function testRoundingDecimalsFive() - { - $currency = Currency::find(1); - - $x = Number::formatValueNoTrailingZeroes(0.00005, $currency); - - $this->assertEquals(0.00005, $x); - } - - public function testRoundingDecimalsSix() - { - $currency = Currency::find(1); - - $x = Number::formatValueNoTrailingZeroes(0.000005, $currency); - - $this->assertEquals(0.000005, $x); - } - - public function testRoundingDecimalsSeven() - { - $currency = Currency::find(1); - - $x = Number::formatValueNoTrailingZeroes(0.0000005, $currency); - - $this->assertEquals(0.0000005, $x); - } - - public function testRoundingDecimalsEight() - { - $currency = Currency::find(1); - - $x = Number::formatValueNoTrailingZeroes(0.00000005, $currency); - - $this->assertEquals(0.00000005, $x); - } - - public function testRoundingPositive() - { - $currency = Currency::find(1); - - $x = Number::formatValueNoTrailingZeroes(1.5, $currency); - $this->assertEquals(1.5, $x); - - $x = Number::formatValueNoTrailingZeroes(1.50, $currency); - $this->assertEquals(1.5, $x); - - $x = Number::formatValueNoTrailingZeroes(1.500, $currency); - $this->assertEquals(1.5, $x); - - $x = Number::formatValueNoTrailingZeroes(1.50005, $currency); - $this->assertEquals(1.50005, $x); - - $x = Number::formatValueNoTrailingZeroes(1.50000005, $currency); - $this->assertEquals(1.50000005, $x); - } } From c1ac1647f67244c3c03a90ed0722cee34cec1269 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 19 Oct 2022 09:33:00 +1100 Subject: [PATCH 4/4] Fixes for policies --- app/Policies/EntityPolicy.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Policies/EntityPolicy.php b/app/Policies/EntityPolicy.php index c7c45f28e9e6..99ca027916e3 100644 --- a/app/Policies/EntityPolicy.php +++ b/app/Policies/EntityPolicy.php @@ -49,8 +49,8 @@ class EntityPolicy return ($user->isAdmin() && $entity->company_id == $user->companyId()) || ($user->hasPermission('edit_'.strtolower(\Illuminate\Support\Str::snake(class_basename($entity)))) && $entity->company_id == $user->companyId()) || ($user->hasPermission('edit_all') && $entity->company_id == $user->companyId()) - || $user->owns($entity) - || $user->assigned($entity); + || ($user->owns($entity) && $entity->company_id == $user->companyId()) + || ($user->assigned($entity) && $entity->company_id == $user->companyId()); } /** @@ -66,7 +66,7 @@ class EntityPolicy return ($user->isAdmin() && $entity->company_id == $user->companyId()) || ($user->hasPermission('view_'.strtolower(\Illuminate\Support\Str::snake(class_basename($entity)))) && $entity->company_id == $user->companyId()) || ($user->hasPermission('view_all') && $entity->company_id == $user->companyId()) - || $user->owns($entity) - || $user->assigned($entity); + || ($user->owns($entity) && $entity->company_id == $user->companyId()) + || ($user->assigned($entity) && $entity->company_id == $user->companyId()); } }