diff --git a/Admin/Install/Navigation.install.json b/Admin/Install/Navigation.install.json index d25052c..f7b8b8c 100755 --- a/Admin/Install/Navigation.install.json +++ b/Admin/Install/Navigation.install.json @@ -323,5 +323,20 @@ "permission": { "permission": 2, "type": null, "element": null }, "parent": 1001602001, "children": [] + }, + { + "id": 1004809002, + "pid": "/purchase/analysis", + "type": 3, + "subtype": 1, + "name": "Article", + "uri": "{/prefix}purchase/analysis/item", + "target": "self", + "icon": null, + "order": 10, + "from": "ItemManagement", + "permission": { "permission": 2, "type": null, "element": null }, + "parent": 1002106001, + "children": [] } ] diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index 4a53334..5de88a5 100755 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -151,7 +151,7 @@ return [ ], '^.*/sales/analysis/item(\?.*|$)$' => [ [ - 'dest' => '\Modules\ItemManagement\Controller\BackendController:viewItemAnalysis', + 'dest' => '\Modules\ItemManagement\Controller\BackendController:viewItemSalesAnalysis', 'verb' => RouteVerb::GET, 'permission' => [ 'module' => BackendController::MODULE_NAME, @@ -160,4 +160,15 @@ return [ ], ], ], + '^.*/purchase/analysis/item(\?.*|$)$' => [ + [ + 'dest' => '\Modules\ItemManagement\Controller\BackendController:viewItemPurchaseAnalysis', + 'verb' => RouteVerb::GET, + 'permission' => [ + 'module' => BackendController::MODULE_NAME, + 'type' => PermissionType::READ, + 'state' => PermissionState::PURCHASE_ITEM, + ], + ], + ], ]; diff --git a/Controller/BackendController.php b/Controller/BackendController.php index b996f1e..758d5d1 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -27,6 +27,8 @@ use Modules\ItemManagement\Models\ItemMapper; use Modules\Media\Models\Media; use phpOMS\Asset\AssetType; use phpOMS\Contract\RenderableInterface; +use phpOMS\Localization\ISO3166CharEnum; +use phpOMS\Localization\ISO3166NameEnum; use phpOMS\Localization\Money; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; @@ -412,4 +414,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 viewItemSalesAnalysis(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/Theme/Backend/Lang/ar.lang.php b/Theme/Backend/Lang/ar.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/cs.lang.php b/Theme/Backend/Lang/cs.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/da.lang.php b/Theme/Backend/Lang/da.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/de.lang.php b/Theme/Backend/Lang/de.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/el.lang.php b/Theme/Backend/Lang/el.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/es.lang.php b/Theme/Backend/Lang/es.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/fi.lang.php b/Theme/Backend/Lang/fi.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/fr.lang.php b/Theme/Backend/Lang/fr.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/hu.lang.php b/Theme/Backend/Lang/hu.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/it.lang.php b/Theme/Backend/Lang/it.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/ja.lang.php b/Theme/Backend/Lang/ja.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/ko.lang.php b/Theme/Backend/Lang/ko.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/no.lang.php b/Theme/Backend/Lang/no.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/pl.lang.php b/Theme/Backend/Lang/pl.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/pt.lang.php b/Theme/Backend/Lang/pt.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/ru.lang.php b/Theme/Backend/Lang/ru.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/sv.lang.php b/Theme/Backend/Lang/sv.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/th.lang.php b/Theme/Backend/Lang/th.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/tr.lang.php b/Theme/Backend/Lang/tr.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/uk.lang.php b/Theme/Backend/Lang/uk.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/Lang/zh.lang.php b/Theme/Backend/Lang/zh.lang.php old mode 100644 new mode 100755 diff --git a/Theme/Backend/item-analysis.tpl.php b/Theme/Backend/item-analysis.tpl.php new file mode 100644 index 0000000..035d04c --- /dev/null +++ b/Theme/Backend/item-analysis.tpl.php @@ -0,0 +1,22 @@ +getData('nav')->render(); +?>