/** * */ include 'zmysqlConn.class.php'; include 'extrakits.inc.php'; $today = date("Y-m-d"); $lastday = date("Y-m-d", strtotime(date('Y-m-d') . " Sunday")); if (date("w") == 0) { $lastday = date("Y-m-d", strtotime($lastday . " + 6 days")); } else { $lastday = date("Y-m-d", strtotime($lastday . " - 1 days")); } $weekend = $lastday; $weekstart = date("Y-m-d", strtotime($lastday . " - 6 days")); $curbiweek = __getCurBiweek(); $curbiweekse = explode(",", $curbiweek); $biweekstart = $curbiweekse[0]; $biweekend = $curbiweekse[1]; if ($today < INTOHALFMONTHLYBIWEEKDAY) { $biweekstart0 = date("Y-m-d", strtotime($biweekstart . " - 2 weeks")); $biweekend0 = date("Y-m-d", strtotime($biweekstart0 . " + 2 weeks - 1 day")); if ($biweekend == '2016-11-30') { $biweekstart0 = '2016-10-30'; $biweekend0 = '2016-11-12'; } } else { $se = __getPreBiweek($curbiweek); $se = explode(",", $se); $biweekstart0 = $se[0]; $biweekend0 = $se[1];
function index($id = null) { if (!$this->Auth->user()) { $this->redirect(array('controller' => 'accounts', 'action' => 'login')); } $this->layout = 'defaultlayout'; /*try to archive the bulletin*/ if ($id == -1 && $this->Auth->user('Account.role') == 0) { $this->Bulletin->updateAll(array('archdate' => "'" . date('Y-m-d h:i:s') . "'"), array('archdate' => null)); if ($this->Bulletin->getAffectedRows() > 0) { $this->Session->setFlash("Bulletin archived."); } else { $this->Session->setFlash("No current bulletin exists."); } } /*prepare the historical bulletins*/ $archdata = $this->Bulletin->find('all', array('fields' => array('id', 'title', 'archdate'), 'conditions' => array('archdate not' => null), 'order' => array('archdate desc'))); $this->set(compact('archdata')); /*prepare the ALERTS for the current logged-in user*/ $info = array(); if ($id == null) { $info = $this->Bulletin->find('first', array('fields' => array('info'), 'conditions' => array('archdate' => null))); } else { $info = $this->Bulletin->find('first', array('fields' => array('info'), 'conditions' => array('id' => $id))); } $this->set('topnotes', empty($info) ? '...' : $info['Bulletin']['info']); if ($this->Auth->user('Account.role') == 0) { //means an administrator $this->set('notes', ''); //set the additional notes here } else { if ($this->Auth->user('Account.role') == 1) { //means a company $cominfo = $this->Company->find('first', array('fields' => array('agentnotes'), 'conditions' => array('id' => $this->Auth->user('Account.id')))); $this->set('notes', ''); //set the additional notes here } else { //means an agent $aginfo = $this->Agent->find('first', array('fields' => array('companyid'), 'conditions' => array('id' => $this->Auth->user('Account.id')))); $cominfo = $this->Company->find('first', array('fileds' => array('agentnotes'), 'conditions' => array('id' => $aginfo['Agent']['companyid']))); $this->set('notes', '<font size="3"><b>Office news </b></font>' . $cominfo['Company']['agentnotes']); } } /* * for the "selling contestants" stuff */ //avoid those data which are not in types $conds['startdate'] = '0000-00-00'; $conds['enddate'] = date('Y-m-d'); $rs = $this->Top10->find('all', array('conditions' => array('flag' => 0), 'order' => 'sales desc')); $this->set(compact('rs')); $weekend = date("Y-m-d", strtotime(date('Y-m-d') . " Saturday")); $weekstart = date("Y-m-d", strtotime($weekend . " - 6 days")); $curbiweek = __getCurBiweek(); $curbiweekse = explode(",", $curbiweek); $biweekstart = $curbiweekse[0]; $biweekend = $curbiweekse[1]; $conds['startdate'] = $weekstart; $conds['enddate'] = $weekend; $weekrs = $this->Top10->find('all', array('conditions' => array('flag' => 1), 'order' => 'sales desc')); $conds['startdate'] = $biweekstart; $conds['enddate'] = $biweekend; $biweekrs = $this->Top10->find('all', array('conditions' => array('flag' => 3), 'order' => 'sales desc')); $biweekrs0 = $this->Top10->find('all', array('conditions' => array('flag' => 4), 'order' => 'sales desc')); $this->set(compact('weekrs')); $this->set(compact('weekstart')); $this->set(compact('weekend')); $this->set(compact('biweekrs')); $this->set(compact('biweekrs0')); $this->set(compact('biweekstart')); $this->set(compact('biweekend')); /* * trials and bonus top 10 for new style (2 steps) sales */ $trbors = $this->TrboTop10->find('all', array('conditions' => array('flag' => 0), 'order' => 'sales desc')); $trboweekrs = $this->TrboTop10->find('all', array('conditions' => array('flag' => 1), 'order' => 'sales desc')); $this->set(compact('trbors')); $this->set(compact('trboweekrs')); /*prepare the totals demo data*/ /*## for accounts overview*/ /* $totals = array('cpofflines' => 0, 'cponlines' => 0, 'agofflines' => 0, 'agonlines' => 0, 'cpacts' => 0, 'cpsusps' => 0, 'agacts' => 0, 'agsusps' => 0); $totals['cpofflines'] = $this->ViewCompany->find('count', array('conditions' => array('online' => 0)) ); $totals['cponlines'] = $this->ViewCompany->find('count', array('conditions' => array('online' => 1)) ); $totals['agofflines'] = $this->ViewAgent->find('count', array('conditions' => array('online' => 0)) ); $totals['agonlines'] = $this->ViewAgent->find('count', array('conditions' => array('online' => 1)) ); $totals['cpsusps'] = $this->ViewCompany->find('count', array('conditions' => array('status' => 0)) ); $totals['cpacts'] = $this->ViewCompany->find('count', array('conditions' => array('status' => 1)) ); $totals['agsusps'] = $this->ViewAgent->find('count', array('conditions' => array('status' => 0)) ); $totals['agacts'] = $this->ViewAgent->find('count', array('conditions' => array('status' => 1)) ); $this->set('totals', $totals); */ /*prepare the online demo data*/ /* $this->set('cprs', $this->ViewCompany->find('all', array( 'fields' => array('username', 'officename', 'contactname', 'regtime'), 'conditions' => array('online' => 1) ) ) ); $this->set('agrs', $this->ViewAgent->find('all', array( 'fields' => array('username', 'officename', 'name', 'regtime'), 'conditions' => array('online' => 1) ) ) ); */ }
function __getPeriods() { $lastday = date("Y-m-d", strtotime(date('Y-m-d') . " Sunday")); if (date("w") == 0) { $lastday = date("Y-m-d", strtotime($lastday . " + 6 days")); } else { $lastday = date("Y-m-d", strtotime($lastday . " - 1 days")); } $weekend = $lastday; $weekstart = date("Y-m-d", strtotime($lastday . " - 6 days")); $periods = array(); for ($i = 0; $i < 52; $i++) { $oneweek = date("Y-m-d", strtotime($lastday . " - " . (7 * $i + 6) . " days")) . ',' . date("Y-m-d", strtotime($lastday . " - " . 7 * $i . " days")); $v = "[W]{$oneweek}"; switch ($i) { case 0: $v = 'THIS WEEK'; break; case 1: $v = 'LAST WEEK'; break; default: break; } $periods += array($oneweek => $v); } $curbiweek = __getCurBiweek(); $curbiweekse = explode(",", $curbiweek); $biweekstart = $curbiweekse[0]; $biweekend = $curbiweekse[1]; $periods += array($biweekstart . "," . $biweekend => "[2W]" . $biweekstart . "," . $biweekend); /* * and after 2016-11-30, biweek should be 1-15, and 16-the end of a month */ for ($i = 1; $i <= 26; $i++) { $biweek = null; if (date("Y-m-d") < INTOHALFMONTHLYBIWEEKDAY) { $biweek = date("Y-m-d", strtotime($biweekstart . sprintf(" - %d", $i * 2) . " weeks")) . ',' . date("Y-m-d", strtotime($biweekstart . sprintf(" - %d", ($i - 1) * 2) . " weeks - 1 day")); } else { $biweek = __getPreBiweek($curbiweek); $curbiweek = $biweek; } $periods += array($biweek => "[2W]{$biweek}"); } return $periods; }