From d6b13086b344ddd59b10dabffabf81b801980431 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 8 Apr 2023 04:36:25 +0200 Subject: [PATCH] fix billing process --- .github/user_bug_report.md | 14 +++++-- Controller/ApiController.php | 58 ++++++++++++++++---------- Models/Client.php | 2 +- Theme/Backend/client-analysis.tpl.php | 20 ++++----- tests/Controller/ApiControllerTest.php | 2 +- 5 files changed, 58 insertions(+), 38 deletions(-) diff --git a/.github/user_bug_report.md b/.github/user_bug_report.md index 9e5f2a5..4b92a8e 100755 --- a/.github/user_bug_report.md +++ b/.github/user_bug_report.md @@ -8,9 +8,11 @@ assignees: '' --- # Bug Description + A clear and concise description of what the bug is. # How to Reproduce + Steps to reproduce the behavior: 1. Go to '...' @@ -19,16 +21,20 @@ Steps to reproduce the behavior: 4. See error # Expected Behavior + A clear and concise description of what you expected to happen. # Screenshots + If applicable, add screenshots to help explain your problem. # System Information - - System: [e.g. PC or iPhone11, ...] - - OS: [e.g. iOS] - - Browser [e.g. chrome, safari] - - KarakaVersion [e.g. 22] + +- System: [e.g. PC or iPhone11, ...] +- OS: [e.g. iOS] +- Browser [e.g. chrome, safari] +- KarakaVersion [e.g. 22] # Additional Information + Add any other context about the problem here. diff --git a/Controller/ApiController.php b/Controller/ApiController.php index aac9192..25b211b 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -65,6 +65,21 @@ use phpOMS\Utils\StringUtils; */ final class ApiController extends Controller { + public function findClientForAccount(int $account, int $unit = null) : ?Client + { + $clientMapper = ClientMapper::get() + ->where('account', $account); + + if (!empty($unit)) { + $clientMapper->where('unit', $unit); + } + + /** @var \Modules\ClientManagement\Models\Client $client */ + $client = $clientMapper->execute(); + + return $client instanceof NullAccount ? null : $client; + } + /** * Api method to create news article * @@ -224,8 +239,8 @@ final class ApiController extends Controller private function validateClientCreate(RequestAbstract $request) : array { $val = []; - if (($val['number'] = empty($request->getData('number'))) - || ($val['account'] = empty($request->getData('name1')) && empty($request->getData('account'))) + if (($val['number'] = !$request->hasData('number')) + || ($val['account'] = !$request->hasData('name1') && !$request->hasData('account')) ) { return $val; } @@ -297,7 +312,7 @@ final class ApiController extends Controller private function validateMainAddressUpdate(RequestAbstract $request) : array { $val = []; - if (($val['client'] = (empty($request->getData('client') && empty($request->getData('account'))))) + if (($val['client'] = (!$request->hasData('client') && !$request->hasData('account'))) ) { return $val; } @@ -308,9 +323,8 @@ final class ApiController extends Controller /** * Method to update an account from a request * - * @param RequestAbstract $request Request - * @param Address $address Address - * @param bool $allowPassword Allow to change password + * @param RequestAbstract $request Request + * @param Address $address Address * * @return Address * @@ -321,8 +335,8 @@ final class ApiController extends Controller $address->address = $request->getDataString('address') ?? $address->address; $address->postal = $request->getDataString('postal') ?? $address->postal; $address->city = $request->getDataString('city') ?? $address->city; + $address->state = $request->getDataString('state') ?? $address->state; $address->setCountry($request->getDataString('country') ?? $address->getCountry()); - $address->state = $request->getDataString('state') ?? $address->state; return $address; } @@ -388,9 +402,9 @@ final class ApiController extends Controller private function validateClientL11nCreate(RequestAbstract $request) : array { $val = []; - if (($val['client'] = empty($request->getData('client'))) - || ($val['type'] = empty($request->getData('type'))) - || ($val['description'] = empty($request->getData('description'))) + if (($val['client'] = !$request->hasData('client')) + || ($val['type'] = !$request->hasData('type')) + || ($val['description'] = !$request->hasData('description')) ) { return $val; } @@ -455,7 +469,7 @@ final class ApiController extends Controller private function validateClientL11nTypeCreate(RequestAbstract $request) : array { $val = []; - if (($val['title'] = empty($request->getData('title')))) { + if (($val['title'] = !$request->hasData('title'))) { return $val; } @@ -530,9 +544,9 @@ final class ApiController extends Controller private function validateClientAttributeCreate(RequestAbstract $request) : array { $val = []; - if (($val['type'] = empty($request->getData('type'))) - || ($val['value'] = (empty($request->getData('value')) && empty($request->getData('custom')))) - || ($val['client'] = empty($request->getData('client'))) + if (($val['type'] = !$request->hasData('type')) + || ($val['value'] = (!$request->hasData('value') && !$request->hasData('custom'))) + || ($val['client'] = !$request->hasData('client')) ) { return $val; } @@ -600,8 +614,8 @@ final class ApiController extends Controller private function validateClientAttributeTypeL11nCreate(RequestAbstract $request) : array { $val = []; - if (($val['title'] = empty($request->getData('title'))) - || ($val['type'] = empty($request->getData('type'))) + if (($val['title'] = !$request->hasData('title')) + || ($val['type'] = !$request->hasData('type')) ) { return $val; } @@ -671,8 +685,8 @@ final class ApiController extends Controller private function validateClientAttributeTypeCreate(RequestAbstract $request) : array { $val = []; - if (($val['title'] = empty($request->getData('title'))) - || ($val['name'] = empty($request->getData('name'))) + if (($val['title'] = !$request->hasData('title')) + || ($val['name'] = !$request->hasData('name')) ) { return $val; } @@ -756,8 +770,8 @@ final class ApiController extends Controller private function validateClientAttributeValueCreate(RequestAbstract $request) : array { $val = []; - if (($val['type'] = empty($request->getData('type'))) - || ($val['value'] = empty($request->getData('value'))) + if (($val['type'] = !$request->hasData('type')) + || ($val['value'] = !$request->hasData('value')) ) { return $val; } @@ -825,8 +839,8 @@ final class ApiController extends Controller private function validateClientAttributeValueL11nCreate(RequestAbstract $request) : array { $val = []; - if (($val['title'] = empty($request->getData('title'))) - || ($val['value'] = empty($request->getData('value'))) + if (($val['title'] = !$request->hasData('title')) + || ($val['value'] = !$request->hasData('value')) ) { return $val; } diff --git a/Models/Client.php b/Models/Client.php index b4ec815..d5faec6 100755 --- a/Models/Client.php +++ b/Models/Client.php @@ -300,7 +300,7 @@ class Client { foreach ($this->attributes as $attribute) { if ($attribute->type->name === $attrName) { - return $attribute->value; + return $attribute; } } diff --git a/Theme/Backend/client-analysis.tpl.php b/Theme/Backend/client-analysis.tpl.php index 7b27116..a401f17 100755 --- a/Theme/Backend/client-analysis.tpl.php +++ b/Theme/Backend/client-analysis.tpl.php @@ -207,7 +207,7 @@ echo $this->getData('nav')->render(); ?> - getCurrency(); ?> + getCurrency(); ?> @@ -327,7 +327,7 @@ echo $this->getData('nav')->render(); ?> - getCurrency(); ?> + getCurrency(); ?> @@ -1329,7 +1329,7 @@ echo $this->getData('nav')->render(); ?> - getCurrency(); ?> + getCurrency(); ?> @@ -1449,7 +1449,7 @@ echo $this->getData('nav')->render(); ?> - getCurrency(); ?> + getCurrency(); ?> @@ -2394,7 +2394,7 @@ echo $this->getData('nav')->render(); ?> - getCurrency(); ?> + getCurrency(); ?> @@ -2514,7 +2514,7 @@ echo $this->getData('nav')->render(); ?> - getCurrency(); ?> + getCurrency(); ?> @@ -3476,7 +3476,7 @@ echo $this->getData('nav')->render(); ?> - getCurrency(); ?> + getCurrency(); ?> @@ -3599,7 +3599,7 @@ echo $this->getData('nav')->render(); ?> - getCurrency(); ?> + getCurrency(); ?> @@ -4306,7 +4306,7 @@ echo $this->getData('nav')->render(); ?> - getCurrency(); ?> + getCurrency(); ?> @@ -4428,7 +4428,7 @@ echo $this->getData('nav')->render(); ?> - getCurrency(); ?> + getCurrency(); ?> diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index b24ddaf..7c3bd36 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -69,7 +69,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase $permission = new AccountPermission(); $permission->setUnit(1); - $permission->setApp('backend'); + $permission->setApp(2); $permission->setPermission( PermissionType::READ | PermissionType::CREATE