From d9f9bdd799a28c32c2cfd1f85954fc39fa165ec3 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 28 May 2021 22:22:44 +0200 Subject: [PATCH] bug fixes with unit testing --- Admin/Routes/Web/Backend.php | 22 ---- Controller/BackendController.php | 167 +++++++++++++++++++++++++++++ Models/ItemAttributeTypeMapper.php | 2 +- 3 files changed, 168 insertions(+), 23 deletions(-) diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index 5de88a5..8403e12 100755 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -6,28 +6,6 @@ use phpOMS\Account\PermissionType; use phpOMS\Router\RouteVerb; return [ - '^.*/item/attribute/type.*$' => [ - [ - 'dest' => '\Modules\ItemManagement\Controller\BackendController:viewItemManagementAttributeTypes', - 'verb' => RouteVerb::GET, - 'permission' => [ - 'module' => BackendController::MODULE_NAME, - 'type' => PermissionType::READ, - 'state' => PermissionState::ATTRIBUTE, - ], - ], - ], - '^.*/item/attribute/value.*$' => [ - [ - 'dest' => '\Modules\ItemManagement\Controller\BackendController:viewItemManagementAttributeValues', - 'verb' => RouteVerb::GET, - 'permission' => [ - 'module' => BackendController::MODULE_NAME, - 'type' => PermissionType::READ, - 'state' => PermissionState::ATTRIBUTE, - ], - ], - ], '^.*/item/attribute/type.*$' => [ [ 'dest' => '\Modules\ItemManagement\Controller\BackendController:viewItemManagementAttributeTypes', diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 758d5d1..90c6cd7 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -581,4 +581,171 @@ final class BackendController extends Controller return $view; } + + /** + * Routing end-point for application behaviour. + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param mixed $data Generic data + * + * @return RenderableInterface + * + * @since 1.0.0 + * @codeCoverageIgnore + */ + public function viewItemPurchaseAnalysis(RequestAbstract $request, ResponseAbstract $response, $data = null) : RenderableInterface + { + $head = $response->get('Content')->getData('head'); + $head->addAsset(AssetType::CSS, 'Resources/chartjs/Chartjs/chart.css'); + $head->addAsset(AssetType::JSLATE, 'Resources/chartjs/Chartjs/chart.js'); + $head->addAsset(AssetType::JSLATE, 'Modules/ClientManagement/Controller.js', ['type' => 'module']); + + $view = new View($this->app->l11nManager, $request, $response); + $view->setTemplate('/Modules/ItemManagement/Theme/Backend/item-analysis'); + $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1001602001, $request, $response)); + + $monthlySalesCosts = []; + for ($i = 1; $i < 13; ++$i) { + $monthlySalesCosts[] = [ + 'net_sales' => $sales = \mt_rand(1200000000, 2000000000), + 'net_costs' => (int) ($sales * \mt_rand(25, 55) / 100), + 'year' => 2020, + 'month' => $i, + ]; + } + + $view->addData('monthlySalesCosts', $monthlySalesCosts); + + ///// + $monthlySalesCustomer = []; + for ($i = 1; $i < 13; ++$i) { + $monthlySalesCustomer[] = [ + 'net_sales' => $sales = \mt_rand(1200000000, 2000000000), + 'customers' => \mt_rand(200, 400), + 'year' => 2020, + 'month' => $i, + ]; + } + + $view->addData('monthlySalesCustomer', $monthlySalesCustomer); + + $annualSalesCustomer = []; + for ($i = 1; $i < 11; ++$i) { + $annualSalesCustomer[] = [ + 'net_sales' => $sales = \mt_rand(1200000000, 2000000000) * 12, + 'customers' => \mt_rand(200, 400) * 6, + 'year' => 2020 - 10 + $i, + ]; + } + + $view->addData('annualSalesCustomer', $annualSalesCustomer); + + ///// + $monthlyCustomerRetention = []; + for ($i = 1; $i < 10; ++$i) { + $monthlyCustomerRetention[] = [ + 'customers' => \mt_rand(200, 400), + 'year' => \date('y') - 9 + $i, + ]; + } + + $view->addData('monthlyCustomerRetention', $monthlyCustomerRetention); + + ///// + $currentCustomerRegion = [ + 'Europe' => (int) (\mt_rand(200, 400) / 4), + 'America' => (int) (\mt_rand(200, 400) / 4), + 'Asia' => (int) (\mt_rand(200, 400) / 4), + 'Africa' => (int) (\mt_rand(200, 400) / 4), + 'CIS' => (int) (\mt_rand(200, 400) / 4), + 'Other' => (int) (\mt_rand(200, 400) / 4), + ]; + + $view->addData('currentCustomerRegion', $currentCustomerRegion); + + for ($i = 1; $i < 11; ++$i) { + $annualCustomerRegion[] = [ + 'year' => 2020 - 10 + $i, + 'Europe' => $a = (int) (\mt_rand(200, 400) / 4), + 'America' => $b = (int) (\mt_rand(200, 400) / 4), + 'Asia' => $c = (int) (\mt_rand(200, 400) / 4), + 'Africa' => $d = (int) (\mt_rand(200, 400) / 4), + 'CIS' => $e = (int) (\mt_rand(200, 400) / 4), + 'Other' => $f = (int) (\mt_rand(200, 400) / 4), + 'Total' => $a + $b + $c + $d + $e + $f, + ]; + } + + $view->addData('annualCustomerRegion', $annualCustomerRegion); + + ///// + $currentCustomersRep = []; + for ($i = 1; $i < 13; ++$i) { + $currentCustomersRep['Rep ' . $i] = [ + 'customers' => (int) (\mt_rand(200, 400) / 12), + ]; + } + + \uasort($currentCustomersRep, function($a, $b) { return $b['customers'] <=> $a['customers']; }); + + $view->addData('currentCustomersRep', $currentCustomersRep); + + $annualCustomersRep = []; + for ($i = 1; $i < 13; ++$i) { + $annualCustomersRep['Rep ' . $i] = []; + + for ($j = 1; $j < 11; ++$j) { + $annualCustomersRep['Rep ' . $i][] = [ + 'customers' => (int) (\mt_rand(200, 400) / 12), + 'year' => 2020 - 10 + $j, + ]; + } + } + + $view->addData('annualCustomersRep', $annualCustomersRep); + + ///// + $currentCustomersCountry = []; + for ($i = 1; $i < 51; ++$i) { + $country = ISO3166NameEnum::getRandom(); + $currentCustomersCountry[\substr($country, 0, 20)] = [ + 'customers' => (int) (\mt_rand(200, 400) / 12), + ]; + } + + \uasort($currentCustomersCountry, function($a, $b) { return $b['customers'] <=> $a['customers']; }); + + $view->addData('currentCustomersCountry', $currentCustomersCountry); + + $annualCustomersCountry = []; + for ($i = 1; $i < 51; ++$i) { + $countryCode = ISO3166CharEnum::getRandom(); + $countryName = ISO3166NameEnum::getByName('_' . $countryCode); + $annualCustomersCountry[\substr($countryName, 0, 20)] = []; + + for ($j = 1; $j < 11; ++$j) { + $annualCustomersCountry[\substr($countryName, 0, 20)][] = [ + 'customers' => (int) (\mt_rand(200, 400) / 12), + 'year' => 2020 - 10 + $j, + 'name' => $countryName, + 'code' => $countryCode, + ]; + } + } + + $view->addData('annualCustomersCountry', $annualCustomersCountry); + + ///// + $customerGroups = []; + for ($i = 1; $i < 7; ++$i) { + $customerGroups['Group ' . $i] = [ + 'customers' => (int) (\mt_rand(200, 400) / 12), + ]; + } + + $view->addData('customerGroups', $customerGroups); + + return $view; + } } diff --git a/Models/ItemAttributeTypeMapper.php b/Models/ItemAttributeTypeMapper.php index 717d330..2d3b3ac 100755 --- a/Models/ItemAttributeTypeMapper.php +++ b/Models/ItemAttributeTypeMapper.php @@ -37,7 +37,7 @@ final class ItemAttributeTypeMapper extends DataMapperAbstract 'itemmgmt_attr_type_name' => ['name' => 'itemmgmt_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], 'itemmgmt_attr_type_fields' => ['name' => 'itemmgmt_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], 'itemmgmt_attr_type_custom' => ['name' => 'itemmgmt_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'], - 'itemmgmt_attr_type_pattern' => ['name' => 'itemmgmt_attr_type_pattern', 'type' => 'bool', 'internal' => 'validationPattern'], + 'itemmgmt_attr_type_pattern' => ['name' => 'itemmgmt_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'], 'itemmgmt_attr_type_required' => ['name' => 'itemmgmt_attr_type_required', 'type' => 'bool', 'internal' => 'isRequired'], ];