setDBO(VoxelCareDB::getDatabase()); $view =JRequest::getVar('view'); $optionArray = (array)$option; $this->filter_order_Dir = $mainframe->getUserStateFromRequest( $optionArray[0].$view.'.filter_order_Dir', 'filter_order_Dir', '', 'word' ); $this->filter_order = $mainframe->getUserStateFromRequest( $optionArray[0].$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( "{$optionArray[0]}.$view.searchid", 'searchid', '', 'string' ); $this->searchid = JString::strtolower( $this->searchid ); $this->searchreference = $mainframe->getUserStateFromRequest( "{$optionArray[0]}.$view.searchreference", 'searchreference', '', 'string' ); $this->searchreference = JString::strtolower( $this->searchreference ); $this->searchcustomer = $mainframe->getUserStateFromRequest( "{$optionArray[0]}.$view.searchcustomer", 'searchcustomer', '', 'string' ); $this->searchcustomer = JString::strtolower( $this->searchcustomer ); $customerId = (int) JRequest::getVar('customerId'); if ($customerId) $this->searchcustomerid = $customerId; $this->searchfranchise = $mainframe->getUserStateFromRequest( "{$optionArray[0]}.$view.searchfranchise", 'searchfranchise', '', 'string' ); if (!$this->searchfranchise) { $userId =LegacyHelper::getUserId(); $this->_db->setQuery("SELECT uf.franchise id FROM #__vxc_userfranchise uf WHERE uf.userid = ".$userId); $this->searchfranchise = $this->_db->loadResult(); } $this->searchkind = $mainframe->getUserStateFromRequest( "{$optionArray[0]}.$view.searchkind", 'searchkind', 'MYUSER', 'string' ); $this->searchkind = JString::strtolower( $this->searchkind ); if ($this->searchkind == 'byuser') { $this->searchuserid = $mainframe->getUserStateFromRequest( "{$optionArray[0]}.$view.searchuserid", 'searchuserid', '0', 'string' ); $this->searchuserid = JString::strtolower( $this->searchuserid ); } //$limit = $mainframe->getUserStateFromRequest( 'global.list.limit', 'limit', 10, 'int' ); $limit = -1; //$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 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 delete($ids) { if (count($ids)) { $sql = "UPDATE #__vxc_order SET deleted = TRUE WHERE id IN (".implode(',',$ids).")"; $this->_db->execute($sql); } } function _buildQuery() { $where = array(); if ($this->searchcustomerid) $where[] = ' o.customer = '.$this->searchcustomerid; if ($this->searchreference) $where[] = ' LOWER(o.reference) LIKE '. $this->_db->Quote('%'.$this->searchreference.'%') ; if ($this->searchcustomer) { $cond = " ((LOWER(CONCAT_WS(' ',c.name,c.middlename,c.surname)) LIKE ".$this->_db->Quote('%'.$this->searchcustomer.'%').')'; if (LegacyHelper::getNewMode()) $cond .=" OR (LOWER(CONCAT_WS(' ',atfirst.value,atmiddle.value,atlast.value)) LIKE ".$this->_db->Quote('%'.$this->searchcustomer.'%').')'; $cond .= ')'; $where[] = $cond; } if ($this->searchid) $where[] = " o.id = ". $this->searchid; 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[] = " o.user = ".$this->searchuserid; break; case 'myuser': default: $userId = LegacyHelper::getUserId(); $where[] = " o.user = $userId"; } $where[] = ' o.deleted IS NOT TRUE '; $where[] = " (os.nameid = 'COMPLETED' OR os.nameid = 'PRECONFIRMED') "; if (!LegacyHelper::getNewMode() && LegacyHelper::updatedDB()) $where[] = " o.`uuid` IS NULL "; $where =( count($where) ) ? ' WHERE ' . implode( ' AND ', $where ) : ''; $orderby = ''; $orders = array('id','customerfullname','reference','creationdate','price'); 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; } $newModeFields = ''; $newJoins = ''; $oldModeFields =''; if (LegacyHelper::getNewMode()) { $newModeFields = "o.uuid uuid, CONCAT_WS(' ',NULLIF(CONCAT_WS(' ',NULLIF(c.name,''),NULLIF(c.middlename,''),NULLIF(c.surname,'')),''),NULLIF(atfirst.value,''),NULLIF(atmiddle.value,''),NULLIF(atlast.value,'')) customerfullname,"; $newJoins = " LEFT JOIN jos_vxc_attribute atfirst ON atfirst.orderid = o.id AND atfirst.name = 'patient.firstName' LEFT JOIN jos_vxc_attribute atmiddle ON atmiddle.orderid = o.id AND atmiddle.name = 'patient.middleName' LEFT JOIN jos_vxc_attribute atlast ON atlast.orderid = o.id AND atlast.name = 'patient.lastName' "; } else { $oldModeFields = "CONCAT_WS(' ',NULLIF(c.name,''),NULLIF(c.middlename,''),NULLIF(c.surname,'')) customerfullname,"; } $this->_query = " SELECT o.id id,o.user user, $newModeFields o.customer customer, o.reference reference, o.creationdate creationdate, o.currentStep currentStep, o.completedSteps completedSteps, $oldModeFields o.price price, u.name username, r.id receipt, r.paid receiptpaid, r.paid_date receiptpaiddate " . ' FROM #__vxc_order o LEFT JOIN #__vxc_receipt r ON r.orderid = o.id LEFT JOIN #__vxc_user u ON u.id = o.user LEFT JOIN #__vxc_userfranchise uf ON uf.userid = u.id LEFT JOIN #__vxc_orderstate os ON os.id = o.state LEFT JOIN #__vxc_customer c ON c.id = o.customer '.$newJoins . ' ' . $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('id'); $modelOrder =& JModel::getInstance('ModelOrder','vxc'); foreach($this->_data as $orderData) { $modelOrder->SetId($orderData->id); $orderData->price = $modelOrder->getCurrentCompanyPrice(); } } return $this->_data; } function getCustomers() { $userId = LegacyHelper::getUserId(); $db =& $this->_db; $sql = "SELECT id id, CONCAT_WS(' ',name,middlename,surname) fullname FROM #__vxc_customer WHERE user = $userId AND deleted IS NOT TRUE"; $db->setQuery($sql); $customers = $db->loadObjectList(); return $customers; } function getList() { // table ordering $lists['order_Dir'] = $this->filter_order_Dir; $lists['order'] = $this->filter_order; // search filter $lists['searchreference']= $this->searchreference; $lists['searchcustomer']= $this->searchcustomer; $lists['searchuserid']= $this->searchuserid; $lists['searchkind']= $this->searchkind; $lists['searchid'] = $this->searchid; $lists['searchfranchise']= $this->searchfranchise; $lists['users'] = $this->getUsers(); //$lists['franchises'] = $this->getFranchises(); 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