setDBO(VoxelCareDB::getDatabase()); $view =JRequest::getVar('view'); $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', 'creationdate', 'cmd' ); if ($this->filter_order=='creationdate' && !$this->filter_order_Dir) $this->filter_order_Dir = 'desc'; $this->searchid = $mainframe->getUserStateFromRequest( "$option.$view.searchid", 'searchid', '', 'string' ); $this->searchid = JString::strtolower( $this->searchid ); $this->searchuserid = $mainframe->getUserStateFromRequest( "$option.$view.searchuserid", 'searchuserid', '', 'string' ); $this->searchuserid = JString::strtolower( $this->searchuserid ); $this->searchbatch = $mainframe->getUserStateFromRequest( "$option.$view.searchbatch", 'searchbatch', '', 'string' ); $this->searchbatch = JString::strtolower( $this->searchbatch ); /* $this->searchreference = $mainframe->getUserStateFromRequest( "$option.$view.searchreference", 'searchreference', '', 'string' ); $this->searchreference = JString::strtolower( $this->searchreference ); $this->searchcustomer = $mainframe->getUserStateFromRequest( "$option.$view.searchcustomer", 'searchcustomer', '', 'string' ); $this->searchcustomer = JString::strtolower( $this->searchcustomer ); $customerId = (int) JRequest::getVar('customerId'); if ($customerId) $this->searchcustomerid = $customerId; */ $this->searchfranchise = $mainframe->getUserStateFromRequest( "$option.$view.searchfranchise", 'searchfranchise', '', 'string' ); if (!$this->searchfranchise) { $userId = LegacyHelper::getUserId(); $this->_db->setQuery("SELECT uf.franchise id FROM jos_vxc_userfranchise uf WHERE uf.userid = ".$userId); $this->searchfranchise = $this->_db->loadResult(); } $this->searchkind = $mainframe->getUserStateFromRequest( "$option.$view.searchkind", 'searchkind', 'MYUSER', 'string' ); $this->searchkind = JString::strtolower( $this->searchkind ); if ($this->searchkind == 'byuser') { $this->searchuserid = $mainframe->getUserStateFromRequest( "$option.$view.searchuserid", 'searchuserid', '0', 'string' ); $this->searchuserid = JString::strtolower( $this->searchuserid ); } $limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', 10, 'int' ); $limitstart = JRequest::getVar('limitstart',0); $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0); $this->setState('limit', $limit); $this->setState('limitstart', $limitstart); } function delete($ids) { if (count($ids)) { $sql = "UPDATE #__vxc_deliverynote SET deleted = TRUE WHERE id IN (".implode(',',$ids).")"; $this->_db->execute($sql); } } function _buildQuery() { $where = array(); if ($this->searchid) $where[] = ' dn.id = '.$this->searchid; if ($this->searchbatch) $where[] = ' dn.batch = '. $this->searchbatch; if ($this->searchfranchise) $where[] = " uf.franchise = ". $this->searchfranchise; switch($this->searchkind) { case 'all': break; case 'myfranchise': case 'byfranchise': if ($this->searchfranchise) $where[] = ' uf.franchise = '. $this->searchfranchise; break; case 'byuser': if ($this->searchuserid) $where[] = " dn.userid = ".$this->searchuserid; break; case 'myuser': default: $userId = LegacyHelper::getUserId(); $where[] = " dn.userid = $userId"; } $where[] = " dn.deleted IS NOT TRUE "; $where =( count($where) ) ? ' WHERE ' . implode( ' AND ', $where ) : ''; $orderby = ''; $orders = array('id','username','price','vat','total','amount','paid','batch','concept'); 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 dn.id id, dn.userid userid, dn.batch batch, dn.price price, dn.amount amount, dn.vat vat, dn.total total, dn.concept concept, dn.paid paid, u.name username " . ' FROM #__vxc_deliverynote dn LEFT JOIN #__vxc_user u ON u.id = dn.userid LEFT JOIN #__vxc_userfranchise uf ON u.id = uf.userid ' . $where . $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(); } 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 u.id = uf.userid WHERE uf.franchise = $franchiseId AND uf.deleted IS NOT TRUE ORDER BY u.name"; $db->setQuery($sql); return $db->loadObjectList(); } function getList() { // table ordering $lists['order_Dir'] = $this->filter_order_Dir; $lists['order'] = $this->filter_order; // search filter $lists['searchid']= $this->searchid; $lists['searchuserid']= $this->searchuserid; $lists['searchbatch']= $this->searchbatch; $lists['searchkind'] = $this->searchkind; $lists['users'] = $this->getUsers(); 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') ); } return $this->_pagination; } }// class