public function get_get_telesales_report_period($center = null) { if ($center == "ALL") { $center = null; } $startDate = null; $endDate = null; $month = $this->param('month'); if ($month == "month") { $startDate = date("Y-m-01"); $endDate = date("Y-m-t"); } else { $startDate = date("Y-m-d"); $endDate = date("Y-m-d"); } $reportArray = Controller_Reports::generate_telesales_report($center, $startDate, $endDate); return $this->response(array('titles' => array('Name', 'Referrals', 'Pack Outs', 'Conversion Rate', 'Points', 'Commission'), 'report' => $reportArray['report'], 'centerVals' => $reportArray['centerVals'])); }
/** * Function to move telesales staff based on performance. * * @access public * @return void */ public function move_telesales_staff($chosenDay = null) { print "Running"; // Work out days are required $chosenDate = is_null($chosenDay) ? strtotime(date('o-\\WW')) : strtotime($chosenDay); $earlyDate = is_null($chosenDay) ? strtotime(date("jS F Y", $chosenDate) . ' -7 days') : strtotime($chosenDay . ' -7 days'); // How many Bolton staff $premierPercent = 20; // Number of agents promoted / demoted daily $promotionCount = 3; // Providing the day is not a weekend we run the script if ((int) date("N", $chosenDate) < 6) { // Get list of top staff $staffListRequestSecondary = \Controller_Reports::generate_telesales_report(null, date("Y-m-d", $chosenDate), date("Y-m-d", $chosenDate)); // Get list of details over the past 7 days for extra checking purposes $staffListRequest = \Controller_Reports::generate_telesales_report(null, date("Y-m-d", $earlyDate), date("Y-m-d", $chosenDate)); // Number of staff required for the premier campaign $requiredPremier = ceil(count($staffListRequest['report']) * ($premierPercent / 100)); // Create a list of user IDs so we can easily pull the keys required from the main array // First one is for the daily results $staffDiallerList = array(); $staffList = $staffListRequest['report']; foreach ($staffList as $key => $single) { $staffDiallerList[$single['dialler_id']] = $key; } // Second is for the 7 day results $staffSecondDiallerList = array(); $staffSecondList = $staffListRequestSecondary['report']; foreach ($staffSecondList as $key => $single) { $staffSecondDiallerList[$single['dialler_id']] = $key; } $premierAll = array(); $standardAll = array(); // Get PREMIER-GBS $premierGBS = \DB::query("SELECT user FROM vicidial_users WHERE user_group='PREMIER-GBS';")->cached(0)->execute('gabdialler'); foreach ($premierGBS as $single) { $premierAll[] = array('user' => $single['user'], 'center' => 'GBS'); } // Get PREMIER-GBS //$premierRESOLVEPART = \DB::query("SELECT user FROM vicidial_users WHERE user_group='PREMIER-RESOLVEPART';")->cached(0)->execute('gabdialler'); //foreach ($premierRESOLVEPART as $single) $premierAll[] = array('user' => $single['user'], 'center' => 'RESOLVEPART'); // Get PREMIER-GBS //$premierRESOLVE = \DB::query("SELECT user FROM vicidial_users WHERE user_group='PREMIER-RESOLVE';")->cached(0)->execute('gabdialler'); //foreach ($premierRESOLVE as $single) $premierAll[] = array('user' => $single['user'], 'center' => 'RESOLVE'); // Get PREMIER-GAB $premierGAB = \DB::query("SELECT user FROM vicidial_users WHERE user_group='PREMIER-GAB';")->cached(0)->execute('gabdialler'); foreach ($premierGAB as $single) { $premierAll[] = array('user' => $single['user'], 'center' => 'GAB'); } // Get STANDARD-GBS $standardGBS = \DB::query("SELECT user FROM vicidial_users WHERE user_group='STANDARD-GBS';")->cached(0)->execute('gabdialler'); foreach ($standardGBS as $single) { $standardAll[] = array('user' => $single['user'], 'center' => 'GBS'); } // Get STANDARD-GAB //$standardRESOLVEPART = \DB::query("SELECT user FROM vicidial_users WHERE user_group='STANDARD-RESOLVEPART';")->cached(0)->execute('gabdialler'); //foreach ($standardRESOLVEPART as $single) $standardAll[] = array('user' => $single['user'], 'center' => 'RESOLVEPART'); // Get STANDARD-GAB //$standardRESOLVE = \DB::query("SELECT user FROM vicidial_users WHERE user_group='STANDARD-RESOLVE';")->cached(0)->execute('gabdialler'); //foreach ($standardRESOLVE as $single) $standardAll[] = array('user' => $single['user'], 'center' => 'RESOLVE'); // Get STANDARD-GAB $standardGAB = \DB::query("SELECT user FROM vicidial_users WHERE user_group='STANDARD-GAB';")->cached(0)->execute('gabdialler'); foreach ($standardGAB as $single) { $standardAll[] = array('user' => $single['user'], 'center' => 'GAB'); } // Add scores to premier users $premierAllWithScores = array(); $premierCount = 0; foreach ($premierAll as $single) { if (isset($staffDiallerList[$single['user']])) { $premierAllWithScores[$premierCount] = $staffList[$staffDiallerList[$single['user']]]; $premierAllWithScores[$premierCount]['backup'] = $staffSecondList[$staffSecondDiallerList[$single['user']]]['points']; $premierAllWithScores[$premierCount]['center'] = $single['center']; } else { \DB::query("UPDATE vicidial_users SET user_group='STANDARD-" . $single['center'] . "' WHERE user='******'user'] . "';")->execute('gabdialler'); } $premierCount++; } // Sort premier users by daily points and weekly points as a backup $premierAllWithScores = \Arr::multisort($premierAllWithScores, array('points' => SORT_ASC), true); // Add scores to standard users $standardAllWithScores = array(); $standardCount = 0; foreach ($standardAll as $single) { if (isset($staffDiallerList[$single['user']])) { $standardAllWithScores[$standardCount] = $staffList[$staffDiallerList[$single['user']]]; $standardAllWithScores[$standardCount]['backup'] = $staffSecondList[$staffSecondDiallerList[$single['user']]]['points']; $standardAllWithScores[$standardCount]['center'] = $single['center']; } else { \DB::query("UPDATE vicidial_users SET user_group='STANDARD-" . $single['center'] . "' WHERE user='******'user'] . "';")->execute('gabdialler'); } $standardCount++; } // Sort standard users by daily points and weekly points as a backup $standardAllWithScores = \Arr::multisort($standardAllWithScores, array('points' => SORT_DESC), true); // Work out Demotions $totalInPremierATM = count($premierAllWithScores); $demotionsToStandard = array(); for ($i = 0; $i <= $promotionCount - 1 + ($totalInPremierATM - $requiredPremier); $i++) { if (isset($premierAllWithScores[$i])) { $demotionsToStandard[] = $premierAllWithScores[$i]; unset($premierAllWithScores[$i]); } } // Work out Promotions $promotionsToPremier = array(); for ($i = 0; $i <= $promotionCount - 1; $i++) { $promotionsToPremier[] = $standardAllWithScores[$i]; unset($standardAllWithScores[$i]); } // Generate new User group lists $newPremierList = array_merge(array_reverse($premierAllWithScores), $promotionsToPremier); $newStandardList = array_merge($demotionsToStandard, $standardAllWithScores); // Update the dialler with the new groups foreach ($newPremierList as $single) { \DB::query("UPDATE vicidial_users SET user_group='PREMIER-" . $single['center'] . "' WHERE user='******'dialler_id'] . "';")->execute('gabdialler'); } foreach ($newStandardList as $single) { \DB::query("UPDATE vicidial_users SET user_group='STANDARD-" . $single['center'] . "' WHERE user='******'dialler_id'] . "';")->execute('gabdialler'); } // E-Mail Managers with new campaign lists $email = \Email::forge(); $email->from('*****@*****.**', 'Expert Money Solutions'); $email->to(array('*****@*****.**' => 'Telesales Group Updates')); $email->priority(\Email::P_HIGH); $email->subject('Dialler Staff Ranking Update'); $email->html_body(\View::forge('emails/dialler/ranking', array('top' => \Arr::multisort($newPremierList, array('points' => SORT_DESC, 'backup' => SORT_DESC), true), 'bottom' => \Arr::multisort($newStandardList, array('points' => SORT_DESC, 'backup' => SORT_DESC), true), 'promotions' => $promotionsToPremier, 'demotions' => $demotionsToStandard, 'chosendate' => $earlyDate, 'chosenenddate' => $chosenDate))); $email->send(); } }
public function get_dispositions() { if (strtotime($this->param('enddate')) - strtotime($this->param('startdate')) < -2678400) { $this->response(array('status' => 'FAIL', 'message' => 'Sorry, you cannot get a disposition report for a larger period than one month!')); } else { $this->response(Controller_Reports::generate_disposition_report($this->param('center'), Auth::has_access('reports.disposition'), Auth::has_access('reports.all_centers'), $this->param('startdate'), $this->param('enddate'))); } }