示例#1
0
文件: model.php 项目: leowh/crm
 /** 
  * Get customer list.
  * 
  * @param  string  $mode 
  * @param  mix     $param 
  * @param  string  $relation  client|provider
  * @param  string  $orderBy 
  * @param  object  $pager 
  * @access public
  * @return array
  */
 public function getList($mode = 'all', $param = null, $relation = 'client', $orderBy = 'id_desc', $pager = null)
 {
     $customerIdList = $this->getCustomersSawByMe();
     if (empty($customerIdList)) {
         return array();
     }
     $this->app->loadClass('date', $static = true);
     $thisMonth = date::getThisMonth();
     $thisWeek = date::getThisWeek();
     if ($this->session->customerQuery == false) {
         $this->session->set('customerQuery', ' 1 = 1');
     }
     $customerQuery = $this->loadModel('search', 'sys')->replaceDynamic($this->session->customerQuery);
     if (strpos($orderBy, 'id') === false) {
         $orderBy .= ', id_desc';
     }
     return $this->dao->select('*')->from(TABLE_CUSTOMER)->where('deleted')->eq(0)->beginIF($relation == 'client')->andWhere('relation')->ne('provider')->beginIF($relation == 'provider')->andWhere('relation')->ne('client')->beginIF($mode == 'field')->andWhere('mode')->eq($param)->fi()->beginIF($mode == 'past')->andWhere('nextDate')->lt(helper::today())->fi()->beginIF($mode == 'today')->andWhere('nextDate')->eq(helper::today())->fi()->beginIF($mode == 'tomorrow')->andWhere('nextDate')->eq(formattime(date::tomorrow(), DT_DATE1))->fi()->beginIF($mode == 'thisweek')->andWhere('nextDate')->between($thisWeek['begin'], $thisWeek['end'])->fi()->beginIF($mode == 'thismonth')->andWhere('nextDate')->between($thisMonth['begin'], $thisMonth['end'])->fi()->beginIF($mode == 'public')->andWhere('public')->eq('1')->fi()->beginIF($mode == 'assignedTo')->andWhere('assignedTo')->eq($this->app->user->account)->fi()->beginIF($mode == 'query')->andWhere($param)->fi()->beginIF($mode == 'bysearch')->andWhere($customerQuery)->fi()->beginIF(strpos('all, bysearch, public, assignedTo, query', $mode) === false)->andWhere('nextDate')->ne('0000-00-00')->fi()->andWhere('id')->in($customerIdList)->orderBy($orderBy)->page($pager)->fetchAll('id');
 }
示例#2
0
文件: model.php 项目: leowh/colla
 /** 
  * Get order list.
  * 
  * @param  string  $mode 
  * @param  mix     $param 
  * @param  string  $orderBy 
  * @param  object  $pager 
  * @access public
  * @return array
  */
 public function getList($mode = 'all', $param = null, $owner = '', $orderBy = 'id_desc', $pager = null)
 {
     $customerIdList = $this->loadModel('customer')->getCustomersSawByMe();
     if (empty($customerIdList)) {
         return array();
     }
     $products = $this->loadModel('product')->getPairs();
     $this->app->loadClass('date', $static = true);
     $thisMonth = date::getThisMonth();
     $thisWeek = date::getThisWeek();
     /* Process search condition. */
     if ($this->session->orderQuery == false) {
         $this->session->set('orderQuery', ' 1 = 1');
     }
     $orderQuery = $this->loadModel('search', 'sys')->replaceDynamic($this->session->orderQuery);
     if (strpos($orderBy, 'status') !== false) {
         $orderBy .= ', closedReason';
     }
     if (strpos($orderBy, 'id') === false) {
         $orderBy .= ', id_desc';
     }
     $userList = $this->loadModel('user')->getSubUsers($this->app->user);
     $orders = $this->dao->select('o.*, c.name as customerName, c.level as level')->from(TABLE_ORDER)->alias('o')->leftJoin(TABLE_CUSTOMER)->alias('c')->on("o.customer=c.id")->where('o.deleted')->eq(0)->beginIF($userList != '')->andWhere()->markLeft(1)->where('o.assignedTo')->in($userList)->orWhere('o.createdBy')->in($userList)->orWhere('o.editedBy')->in($userList)->orWhere('o.signedBy')->in($userList)->markRight(1)->fi()->beginIF($mode == 'past')->andWhere('o.nextDate')->andWhere('o.nextDate')->lt(helper::today())->fi()->beginIF($mode == 'today')->andWhere('o.nextDate')->eq(helper::today())->fi()->beginIF($mode == 'tomorrow')->andWhere('o.nextDate')->eq(formattime(date::tomorrow(), DT_DATE1))->fi()->beginIF($mode == 'thisweek')->andWhere('o.nextDate')->between($thisWeek['begin'], $thisWeek['end'])->fi()->beginIF($mode == 'thismonth')->andWhere('o.nextDate')->between($thisMonth['begin'], $thisMonth['end'])->fi()->beginIF($mode == 'public')->andWhere('public')->eq('1')->fi()->beginIF($mode == 'assignedTo')->andWhere('o.assignedTo')->eq($this->app->user->account)->fi()->beginIF($mode == 'createdBy')->andWhere('o.createdBy')->eq($this->app->user->account)->fi()->beginIF($mode == 'signedBy')->andWhere('o.signedBy')->eq($this->app->user->account)->fi()->beginIF($mode == 'query')->andWhere($param)->fi()->beginIF($mode == 'bysearch')->andWhere($orderQuery)->fi()->andWhere('o.customer')->in($customerIdList)->orderBy($orderBy)->page($pager)->fetchAll('id');
     foreach ($orders as $order) {
         $order->products = array();
         $productList = explode(',', $order->product);
         foreach ($productList as $product) {
             if (isset($products[$product])) {
                 $order->products[] = $products[$product];
             }
         }
     }
     foreach ($orders as $order) {
         $productName = count($order->products) > 1 ? current($order->products) . $this->lang->etc : current($order->products);
         $order->title = sprintf($this->lang->order->titleLBL, $order->customerName, $productName, date('Y-m-d', strtotime($order->createdDate)));
     }
     return $orders;
 }
示例#3
0
 /**
  * Compute the begin date and end date of a period.
  * 
  * @param  string    $period   all|today|yesterday|twodaysago|latest2days|thisweek|lastweek|thismonth|lastmonth
  * @access public
  * @return array
  */
 public function computeBeginAndEnd($period)
 {
     $this->app->loadClass('date');
     $today = date::today();
     $tomorrow = date::tomorrow();
     $yesterday = date::yesterday();
     $twoDaysAgo = date::twoDaysAgo();
     $period = strtolower($period);
     if ($period == 'all') {
         return array('begin' => '1970-1-1', 'end' => '2109-1-1');
     }
     if ($period == 'today') {
         return array('begin' => $today, 'end' => $tomorrow);
     }
     if ($period == 'yesterday') {
         return array('begin' => $yesterday, 'end' => $today);
     }
     if ($period == 'twodaysago') {
         return array('begin' => $twoDaysAgo, 'end' => $yesterday);
     }
     if ($period == 'latest3days') {
         return array('begin' => $twoDaysAgo, 'end' => $tomorrow);
     }
     /* If the period is by week, add the end time to the end date. */
     if ($period == 'thisweek' or $period == 'lastweek') {
         $func = "get{$period}";
         extract(date::$func());
         return array('begin' => $begin, 'end' => $end . ' 23:59:59');
     }
     if ($period == 'thismonth') {
         return date::getThisMonth();
     }
     if ($period == 'lastmonth') {
         return date::getLastMonth();
     }
 }
示例#4
0
文件: model.php 项目: XMGmen/zentao
 /**
  * Get todo list of a user.
  * 
  * @param  date   $date 
  * @param  string $account 
  * @param  string $status   all|today|thisweek|lastweek|before, or a date.
  * @param  int    $limit    
  * @access public
  * @return void
  */
 public function getList($date = 'today', $account = '', $status = 'all', $limit = 0, $pager = null, $orderBy = "date, status, begin")
 {
     $this->app->loadClass('date');
     $todos = array();
     $date = strtolower($date);
     if ($date == 'today') {
         $begin = date::today();
         $end = $begin;
     } elseif ($date == 'yesterday') {
         $begin = date::yesterday();
         $end = $begin;
     } elseif ($date == 'thisweek') {
         extract(date::getThisWeek());
     } elseif ($date == 'lastweek') {
         extract(date::getLastWeek());
     } elseif ($date == 'thismonth') {
         extract(date::getThisMonth());
     } elseif ($date == 'lastmonth') {
         extract(date::getLastMonth());
     } elseif ($date == 'thisseason') {
         extract(date::getThisSeason());
     } elseif ($date == 'thisyear') {
         extract(date::getThisYear());
     } elseif ($date == 'future') {
         $begin = '2030-01-01';
         $end = $begin;
     } elseif ($date == 'all') {
         $begin = '1970-01-01';
         $end = '2109-01-01';
     } elseif ($date == 'before') {
         $begin = '1970-01-01';
         $end = date::yesterday();
     } else {
         $begin = $end = $date;
     }
     if ($account == '') {
         $account = $this->app->user->account;
     }
     $stmt = $this->dao->select('*')->from(TABLE_TODO)->where('account')->eq($account)->andWhere("date >= '{$begin}'")->andWhere("date <= '{$end}'")->beginIF($status != 'all' and $status != 'undone')->andWhere('status')->in($status)->fi()->beginIF($status == 'undone')->andWhere('status')->ne('done')->fi()->orderBy($orderBy)->beginIF($limit > 0)->limit($limit)->fi()->page($pager)->query();
     /* Set session. */
     $sql = explode('WHERE', $this->dao->get());
     $sql = explode('ORDER', $sql[1]);
     $this->session->set('todoReportCondition', $sql[0]);
     while ($todo = $stmt->fetch()) {
         if ($todo->type == 'task') {
             $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_TASK)->fetch('name');
         }
         if ($todo->type == 'bug') {
             $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_BUG)->fetch('title');
         }
         $todo->begin = date::formatTime($todo->begin);
         $todo->end = date::formatTime($todo->end);
         /* If is private, change the title to private. */
         if ($todo->private and $this->app->user->account != $todo->account) {
             $todo->name = $this->lang->todo->thisIsPrivate;
         }
         $todos[] = $todo;
     }
     return $todos;
 }
示例#5
0
文件: model.php 项目: XMGmen/zentao
 /**
  Replace dynamic account and date. 
 * 
 * @param  string $query 
 * @access public
 * @return string 
 */
 public function replaceDynamic($query)
 {
     $this->app->loadClass('date');
     $lastWeek = date::getLastWeek();
     $thisWeek = date::getThisWeek();
     $lastMonth = date::getLastMonth();
     $thisMonth = date::getThisMonth();
     $yesterday = date::yesterday();
     $today = date::today();
     if (strpos($query, '$') !== false) {
         $query = str_replace('$@me', $this->app->user->account, $query);
         $query = str_replace("'\$lastMonth'", "'" . $lastMonth['begin'] . "' and '" . $lastMonth['end'] . "'", $query);
         $query = str_replace("'\$thisMonth'", "'" . $thisMonth['begin'] . "' and '" . $thisMonth['end'] . "'", $query);
         $query = str_replace("'\$lastWeek'", "'" . $lastWeek['begin'] . "' and '" . $lastWeek['end'] . "'", $query);
         $query = str_replace("'\$thisWeek'", "'" . $thisWeek['begin'] . "' and '" . $thisWeek['end'] . "'", $query);
         $query = str_replace("'\$yesterday'", "'" . $yesterday . "' and '" . $yesterday . "'", $query);
         $query = str_replace("'\$today'", "'" . $today . "' and '" . $today . "'", $query);
     }
     return $query;
 }
示例#6
0
文件: model.php 项目: leowh/colla
 /**
  * Get todo list of a user.
  * 
  * @param  string $mode     all|self|assignedToOther|assignedToMe
  * @param  string $account 
  * @param  date   $date     all|today|thisweek|lastweek|before, or a date. 
  * @param  string $status   
  * @param  string $orderBy   
  * @param  object $pager   
  * @access public
  * @return void
  */
 public function getList($mode = 'self', $account = '', $date = 'all', $status = 'all', $orderBy = "date, status, begin", $pager = null)
 {
     if ($account == '') {
         $account = $this->app->user->account;
     }
     $mode = strtolower($mode);
     $this->app->loadClass('date');
     $todos = array();
     if (!is_array($date)) {
         $date = strtolower($date);
     }
     if (is_array($date)) {
         $begin = strtolower($date['begin']);
         $end = strtolower($date['end']);
     } elseif ($date == 'today') {
         $begin = date::today();
         $end = $begin;
     } elseif ($date == 'yesterday') {
         $begin = date::yesterday();
         $end = $begin;
     } elseif ($date == 'thisweek') {
         extract(date::getThisWeek());
     } elseif ($date == 'lastweek') {
         extract(date::getLastWeek());
     } elseif ($date == 'thismonth') {
         extract(date::getThisMonth());
     } elseif ($date == 'lastmonth') {
         extract(date::getLastMonth());
     } elseif ($date == 'thisseason') {
         extract(date::getThisSeason());
     } elseif ($date == 'thisyear') {
         extract(date::getThisYear());
     } elseif ($date == 'future') {
         $begin = '0000-00-00';
         $end = '1970-01-01';
     } elseif ($date == 'all') {
         $begin = '1970-01-01';
         $end = '2109-01-01';
     } elseif ($date == 'before') {
         $begin = '1970-01-01';
         $end = date::yesterday();
     } else {
         $begin = $end = $date;
     }
     $stmt = $this->dao->select('*')->from(TABLE_TODO)->where('1=1')->beginIF($mode == 'self')->andWhere()->markLeft()->where('account')->eq($account)->orWhere('assignedTo')->eq($account)->markRight()->fi()->beginIF($mode == 'assignedtoother')->andWhere('account')->eq($account)->andWhere('assignedTo')->ne($account)->andWhere('assignedTo')->ne('')->fi()->beginIF($mode == 'assignedtome')->andWhere('account')->ne($account)->andWhere('assignedTo')->eq($account)->fi()->andWhere("date >= '{$begin}'")->andWhere("date <= '{$end}'")->beginIF($status != 'all' and $status != 'undone' and $status != 'unclosed')->andWhere('status')->in($status)->fi()->beginIF($status == 'undone')->andWhere('status')->notin('done,closed')->fi()->beginIF($status == 'unclosed')->andWhere('status')->ne('closed')->fi()->orderBy($orderBy)->page($pager)->query();
     /* Set session. */
     $sql = explode('WHERE', $this->dao->get());
     $sql = explode('ORDER', $sql[1]);
     $this->session->set('todoReportCondition', $sql[0]);
     while ($todo = $stmt->fetch()) {
         if ($todo->type == 'task') {
             $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_TASK)->fetch('name');
         }
         if ($todo->type == 'customer') {
             $todo->name = $this->dao->findById($todo->idvalue)->from(TABLE_CUSTOMER)->fetch('name');
         }
         if ($todo->type == 'order') {
             $order = $this->dao->select('c.name, o.createdDate')->from(TABLE_ORDER)->alias('o')->leftJoin(TABLE_CUSTOMER)->alias('c')->on('o.customer=c.id')->where('o.id')->eq($todo->idvalue)->fetch();
             $todo->name = $order->name . '|' . date('Y-m-d', strtotime($order->createdDate));
         }
         $todo->begin = date::formatTime($todo->begin);
         $todo->end = date::formatTime($todo->end);
         /* If is private, change the title to private. */
         if ($todo->private and $this->app->user->account != $todo->account) {
             $todo->name = $this->lang->todo->thisIsPrivate;
         }
         $todos[] = $todo;
     }
     return $todos;
 }