setDBO(VoxelCareDB::getDatabase()); global $mainframe,$option; $view =JRequest::getVar('view'); //global $option; $this->filter_order_Dir = $mainframe->getUserStateFromRequest( $option.$view.'.filter_order_Dir', 'filter_order_Dir', '', 'word' ); $this->filter_order = $mainframe->getUserStateFromRequest( $option.$view.'.filter_order', 'filter_order', 'payment_date', 'cmd' ); if ($this->filter_order=='payment_date' && !$this->filter_order_Dir) $this->filter_order_Dir = 'asc'; $this->searchmethod = $mainframe->getUserStateFromRequest( "$option.$view.searchmethod", 'searchmethod', '', 'string' ); $userId = LegacyHelper::getUserId(); $this->searchuserid = $mainframe->getUserStateFromRequest( "$option.$view.searchuserid", 'searchuserid', $userId, 'int' ); $this->searchid = $mainframe->getUserStateFromRequest( "$option.$view.searchid", 'searchid', '', 'string' ); $this->searchfranchise = $mainframe->getUserStateFromRequest( "$option.$view.searchfranchise", 'searchfranchise', '', 'string' ); if (!$this->searchfranchise) { $this->_db->setQuery("SELECT uf.franchise id FROM #__vxc_userfranchise uf WHERE uf.userid = ".$userId); $this->searchfranchise = $this->_db->loadResult(); } $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', 10, 'int' ); //$limitstart = $mainframe->getUserStateFromRequest( $option.'.limitstart', 'limitstart', 0, 'int' ); $limitstart = JRequest::getVar('limitstart',0); $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0); $this->setState('limit', $limit); $this->setState('limitstart', $limitstart); } function _buildQuery() { $where = array(); $having= array(); $groupby= array(); $groupby[] ='id'; $groupby[] ='user'; if ($this->searchfranchise) $where[] = "uf.franchise = ". $this->searchfranchise; if ($this->searchmethod) $where[] = "sm.nameid = ".$this->_db->Quote($this->searchmethod); if ($this->searchuserid) $having[] = " user = ".$this->searchuserid; if ($this->searchid) $where[] = " b.id = ".$this->searchid; $where[] = " o.deleted is not true "; $where =( count($where) ) ? ' WHERE ' . implode( ' AND ', $where ) : ''; $having =( count($having) ) ? ' HAVING ' . implode( ' AND ', $having ) : ''; $groupby =( count($groupby) ) ? ' GROUP BY ' . implode( ' , ', $groupby ) : ''; $orderby = ''; $orders = array('id','state','username','payment_date','shipping_date','est_shipping_date','tracking_number','agencyname','numorders'); if (!in_array($this->filter_order,$orders)) $this->filter_order = 'id'; if (($this->filter_order) && ($this->filter_order_Dir)) { $orderby = ' ORDER BY '. $this->filter_order .' '. $this->filter_order_Dir; } $this->_query = " SELECT b.id id, b.state state, bs.nameid statenameid, bs.name statename, b.payment_date payment_date, b.shipping_date shipping_date, b.est_shipping_date est_shipping_date, b.tracking_number tracking_number, count(o.id) numorders,o.user user, u.name username, b.agency agency, a.name agencyname " . ' FROM #__vxc_batch b LEFT JOIN LEFT JOIN #__vxc_batchstate bs ON bs.id = b.state LEFT JOIN #__vxc_order o ON o.batch = b.id LEFT JOIN #__vxc_user u ON u.id = o.user LEFT JOIN #__vxc_userfranchise uf ON uf.userid = u.id LEFT JOIN #__vxc_agency a ON a.id = b.agency ' . $where . $groupby . $having . $orderby ; return $this->_query; } function getData() { if (empty($this->_data)) { $query = $this->_buildQuery(); $this->_db->setQuery( $query,$this->getState('limitstart'), $this->getState('limit') ); $this->_data = $this->_db->loadObjectList('id'); } return $this->_data; } function getUsers() { $franchiseId = $this->searchfranchise; if (!$franchiseId ) return array(); $db =& $this->_db; $sql = "SELECT u.id id , u.name name FROM #__vxc_user u LEFT JOIN #__vxc_userfranchise uf ON uf.userid = u.id WHERE uf.franchise = $franchiseId AND uf.deleted IS NOT TRUE ORDER BY u.name"; $db->setQuery($sql); return $db->loadObjectList(); } function getBatchStates() { $db =& $this->_db; $sql = "SELECT bs.nameid value , bs.name text FROM #__vxc_batchstate bs "; $db->setQuery($sql); return $db->loadObjectList(); } function getAgencies() { $sql = "SELECT a.id id, a.name name FROM #__vxc_agency a ORDER BY a.sorting "; $this->_db->setQuery($sql); return $this->_db->loadObjectList(); } function getList() { // table ordering $lists['order_Dir'] = $this->filter_order_Dir; $lists['order'] = $this->filter_order; // search filter $lists['searchstate']= $this->searchstate; $lists['searchid']= $this->searchid; $lists['searchuserid']= $this->searchuserid; $lists['batchstates'] = $this->getBatchStates(); $lists['users'] = $this->getUsers(); $lists['agencies'] = $this->getAgencies(); return $lists; } function getTotal() { // Load the content if it doesn't already exist if (empty($this->_total)) { $query = $this->_buildQuery(); $this->_total = $this->_getListCount($query); } return $this->_total; } function getPagination() { // Load the content if it doesn't already exist if (empty($this->_pagination)) { jimport('joomla.html.pagination'); $this->_pagination = new JPagination($this->getTotal(), $this->getState('limitstart'), $this->getState('limit') ); $this->_pagination->maxlimit = 100; } return $this->_pagination; } }// class