Beispiel #1
0
 public function _geography($request)
 {
     $geographyService = \Akzo\Geography\Service::getInstance();
     $searchToken = $request->getParam('searchStr');
     $filter = $request->getParam('filter');
     if (isset($filter['depots'])) {
         $depots = $geographyService->getDepots($searchToken);
     }
     if (isset($filter['zones'])) {
         $zones = $geographyService->getZones($searchToken);
     }
     if (isset($filter['regions'])) {
         $regions = $geographyService->getRegions($searchToken);
     }
     $depotlist = array();
     if (!empty($depots)) {
         foreach ($depots as $idx => $res) {
             $depotlist[] = array('name' => $res->name, 'gid' => $res->gid);
         }
     }
     $zonelist = array();
     if (!empty($zones)) {
         foreach ($zones as $idx => $res) {
             $zonelist[] = array('name' => $res->name, 'gid' => $res->gid);
         }
     }
     $regionlist = array();
     if (!empty($regions)) {
         foreach ($regions as $idx => $res) {
             $regionlist[] = array('name' => $res->name, 'gid' => $res->gid);
         }
     }
     // $GLOBALS['logger']->info('request is there'.PHP_EOL.print_r($productlist,1));
     $result = json_encode(array(array('name' => 'Depots', 'children' => $depotlist, 'disabled' => true), array('name' => 'Zones', 'children' => $zonelist, 'disabled' => true), array('name' => 'Regions', 'children' => $regionlist, 'disabled' => true)));
     // $GLOBALS['logger']->info('request is there'.PHP_EOL.print_r($result,1));
     // $jsondata = '[{'name':'cluster','children':[{'name':'Chillium','code':'ISOPOP'},{'name':'Netplode','code':'SARASONIC'},{'name':'Progenex','code':'ZEDALIS'},{'name':'Undertap','code':'MAGNEATO'},{'name':'Amtap','code':'EXPOSA'},{'name':'Kongene','code':'AMRIL'},{'name':'Uxmox','code':'LYRIA'},{'name':'Pheast','code':'COMVEX'},{'name':'Matrixity','code':'DATAGENE'},{'name':'Pearlesex','code':'NORSUL'}]},{'name':'group','children':[{'name':'Senmao','code':'VISALIA'},{'name':'Ecosys','code':'GLOBOIL'},{'name':'Zenolux','code':'LEXICONDO'},{'name':'Geekosis','code':'GOKO'},{'name':'Macronaut','code':'FANFARE'},{'name':'Eschoir','code':'KROG'},{'name':'Zyple','code':'COMFIRM'},{'name':'Multiflex','code':'SOFTMICRO'},{'name':'Comveyor','code':'ISOLOGIX'},{'name':'Voipa','code':'REPETWIRE'}]},{'name':'subbrand','children':[{'name':'Orbixtar','code':'FITCORE'},{'name':'Rotodyne','code':'LUNCHPAD'},{'name':'Callflex','code':'MANGLO'},{'name':'Microluxe','code':'SPEEDBOLT'},{'name':'Jetsilk','code':'VALREDA'}]},{'name':'product','children':[{'code':'CODACT','name':'Wendy Lopez','shortcode':'Thredz','packsize':6.107,'dpl':7720.43,'mrp':3443.05},{'code':'ZENTRY','name':'Harvey Lindsay','shortcode':'Cytrak','packsize':9.549,'dpl':9485.6,'mrp':3974.32},{'code':'CORMORAN','name':'Patrica Simmons','shortcode':'Locazone','packsize':6.885,'dpl':5143.81,'mrp':2124.88},{'code':'UNQ','name':'Dena Poole','shortcode':'Oulu','packsize':6.116,'dpl':4326.3,'mrp':2800.09},{'code':'QUIZKA','name':'Walker Owens','shortcode':'Caxt','packsize':5.716,'dpl':4293.69,'mrp':975},{'code':'ZBOO','name':'Burton Hatfield','shortcode':'Zinca','packsize':1.481,'dpl':1772.67,'mrp':3421.87}]}]';
     $json = json_decode($result, true);
     $this->_response = new HttpResponse('json');
     $this->_response->setBody($json);
 }
Beispiel #2
0
 private function _loadSchemeDealers($salesGeography, $dealerAttributes, $segment, $groupDealersByCreditCode = true, $offset = 0, $count = null)
 {
     $dealers = array();
     // Get depots by geography
     foreach ($salesGeography as $idx => $geo) {
         $dealer = \Akzo\Geography\Service::getInstance()->getDealersByGid($geo->gid, $dealerAttributes, $segment, $groupDealersByCreditCode, $offset, $count);
         $dealers = array_merge($dealers, $dealer);
     }
     // TODO: Have a better code for this
     // Index dealer objects by their code
     $codeIndexedDealers = array();
     foreach ($dealers as $idx => $dealer) {
         // Use dealer code or dealer credit code based on what to collate by
         if ($groupDealersByCreditCode) {
             $this->logger->info("dealer: |||||||||||||||||||||||| " . $idx . " ||||||||||  " . print_r($dealer->credit_code, 1));
             $codeIndexedDealers[$dealer->credit_code] = $dealer;
         } else {
             $codeIndexedDealers[$dealer->code] = $dealer;
         }
     }
     return $codeIndexedDealers;
 }
Beispiel #3
0
 public function _geography($request)
 {
     $searchToken = $request->getParam('searchStr');
     $filter = $request->getParam('filter');
     $geographyService = \Akzo\Geography\Service::getInstance();
     $includeRegions = false;
     // If the user is an ZM, search in its zone & its zones' depots
     if ($this->user->identity->type == \Akzo\User\IdentityType::ZM) {
         // Filter ZM's zone using the searchToken
         if (isset($filter['zones']) && preg_match('/' . $searchToken . '/i', $this->user->identity->zone->name)) {
             $zones = array($this->user->identity->zone);
         }
         // Filter depots under ZM's zone using the searchToken
         if (isset($filter['depots'])) {
             $depots = $geographyService->getDepotsInZone($this->user->identity->zone, $searchToken);
         }
         if (isset($filter['dealers'])) {
             $dealers = $geographyService->getDealersInZone($this->user->identity->zone, $searchToken);
         }
         // If the user is an RM, search in its region, its region's zones & its region's depots
     } else {
         if ($this->identity->type == \Akzo\User\IdentityType::RM) {
             $includeRegions = true;
             // Filter RM's region using token
             if (isset($filter['regions']) && (preg_match('/' . $searchToken . '/i', $this->user->identity->region->name) || preg_match('/' . $searchToken . '/i', $this->user->identity->region->code))) {
                 $regions = array($this->user->identity->region);
             }
             // Filter zones under RM's region
             if (isset($filter['zones'])) {
                 $zones = $geographyService->getZonesInRegion($this->user->identity->region, $searchToken);
             }
             // Filter dealers under RM's region
             if (isset($filter['dealers'])) {
                 $dealers = $geographyService->getDealersInRegion($this->user->identity->region, $searchToken);
             }
             // Filter depots under ZM's zone
             if (isset($filter['depots'])) {
                 $depots = $geographyService->getDepotsInRegion($this->user->identity->region, $searchToken);
             }
         }
     }
     $depotlist = array();
     if (!empty($depots)) {
         foreach ($depots as $idx => $res) {
             $depotlist[] = array('name' => str_replace(',', '', $res->name), 'gid' => $res->gid);
         }
     }
     $zonelist = array();
     if (!empty($zones)) {
         foreach ($zones as $idx => $res) {
             $zonelist[] = array('name' => str_replace(',', '', $res->name), 'gid' => $res->gid);
         }
     }
     $regionlist = array();
     if (!empty($regions) && $includeRegions) {
         foreach ($regions as $idx => $res) {
             $regionlist[] = array('name' => str_replace(',', '', $res->name), 'gid' => $res->gid);
         }
     }
     $dealerlist = array();
     if (!empty($dealers)) {
         foreach ($dealers as $idx => $res) {
             $dealerlist[] = array('name' => str_replace(',', '', $res->name), 'gid' => $res->gid);
         }
     }
     $result = array(array('name' => 'Depots', 'children' => $depotlist, 'disabled' => true), array('name' => 'Zones', 'children' => $zonelist, 'disabled' => true), array('name' => 'Dealers', 'children' => $dealerlist, 'disabled' => true));
     if ($includeRegions) {
         $result[] = array('name' => 'Regions', 'children' => $regionlist, 'disabled' => true);
     }
     $this->__sendResponse('json', null, $result);
 }
Beispiel #4
0
 public function _simulate($request)
 {
     global $logger;
     $data = array();
     $results = array();
     // Request Parameters
     $groups = $request->getParam('groups');
     $actuals = $request->getParam('actuals');
     $executionType = \Akzo\Scheme\ExecuteActionDataType::TARGET;
     if ($request->hasParam('actuals') && $request->getParam('actuals') === 'true') {
         $executionType = \Akzo\Scheme\ExecuteActionDataType::ACTUAL;
         $this->logger->info("ACTUALS:: true ");
     }
     // TODO: Send this as parameter from the front-end
     $groupDealersByCreditCode = true;
     // $request->getParam('groupByCreditCode');
     // Iterate through the scheme groups and collect scheme codes
     $schemes = array();
     if (!empty($groups) && is_array($groups)) {
         foreach ($groups as $groupIdx => $group) {
             foreach ($group['value'] as $schemeIdx => $code) {
                 if (!in_array($code, $schemes)) {
                     $schemes[] = $code;
                 }
             }
         }
     }
     $simulationResults = $schemeDetails = array();
     foreach ($schemes as $schemeIdx => $code) {
         // Get simulation / execution status
         $simulationResults[$schemeIdx] = \Akzo\Scheme\Service::getInstance()->getSchemeExecutionResult($code, $executionType, $groupDealersByCreditCode);
         // $this->logger->info("RESULTS: ".PHP_EOL.print_r($simulationResults,1));
         // Get the scheme detai;s
         $schemeDetails[$schemeIdx] = \Akzo\Scheme\Service::getInstance()->getSchemeByCode($code);
         // TODO: Add a check do not need scheme dealers always, only load once
         // Get the scheme dealers
         $simulationResults[$schemeIdx]['dealers'] = \Akzo\Scheme\Service::getInstance()->getSchemeDealers($code, $groupDealersByCreditCode);
     }
     // $this->logger->info("RESULTS: ".PHP_EOL.print_r($simulationResults,1));
     // $data['results'] = $this->__getResults($simulationResults);
     // $this->logger->info("RESULTS: ".PHP_EOL.print_r($simulationResults,1));
     $data['simulation'] = $simulationResults;
     $data['details'] = $schemeDetails;
     // Periods for getting sales / budget data
     $prevPeriod = array('startDate' => date("Y-1-1", strtotime("this year")), 'endDate' => date("Y-m-t", strtotime("last month")));
     $currPeriod = array('startDate' => date("Y-m-1", strtotime("this month")), 'endDate' => date("Y-m-d"));
     $ovrPeriod = array('startDate' => date("Y-1-1", strtotime("this year")), 'endDate' => date("Y-m-d"));
     $dealerIDs = \Akzo\Geography\Service::getInstance()->getDealerIDsUnderZM($this->user->identity);
     // Plugin Sales Data
     $data['prevSalesData'] = $this->__getSalesData($prevPeriod, $dealerIDs);
     $data['currSalesData'] = $this->__getSalesData($currPeriod, $dealerIDs);
     // $data['ovrSalesData'] = $this->__getSalesData($this->user->identity, $ovrPeriod, $dealerIDs);
     $data['ovrSalesData'] = array("value" => (string) (floatval($data['prevSalesData']['value']) + floatval($data['currSalesData']['value'])), "volume" => (string) (floatval($data['prevSalesData']['volume']) + floatval($data['currSalesData']['volume'])));
     $this->__sendResponse('json', null, $data);
 }