Added Account list, DB changes for account

This commit is contained in:
Deon George
2012-07-30 17:47:28 +10:00
parent 84145ac24f
commit 8f56da789e
6 changed files with 158 additions and 32 deletions

View File

@@ -24,15 +24,15 @@ class Model_Account extends Model_Auth_UserDefault {
);
protected $_display_filters = array(
'active'=>array(
array('StaticList_YesNo::display',array(':value')),
),
'date_orig'=>array(
array('Config::date',array(':value')),
),
'date_last'=>array(
array('Config::date',array(':value')),
),
'status'=>array(
array('StaticList_YesNo::display',array(':value')),
),
);
/**
@@ -49,6 +49,15 @@ class Model_Account extends Model_Auth_UserDefault {
return sprintf('%s-%04s',Config::siteid(TRUE),$this->id);
}
public function sortkey($withcompany=FALSE) {
$sk = '';
if ($withcompany AND $this->company)
$sk .= $this->company.' ';
return $sk.sprintf('%s %s',$this->last_name,$this->first_name);
}
public function title($name) {
return StaticList_Title::form($name,$this->title);
}
@@ -124,6 +133,28 @@ class Model_Account extends Model_Auth_UserDefault {
return $alo->saved();
}
private function _active() {
return $this->where('active','=',TRUE);
}
public function list_active() {
return $this->_active()->order_by('company,last_name,first_name')->find_all();
}
public function list_affiliates() {
$return = array();
foreach ($this->list_services() as $so)
if (! isset($return[$so->affiliate_id]))
$return[$so->affiliate_id] = $so->affiliate;
return $return;
}
public function count_services($active=TRUE,$afid=NULL) {
return count($this->list_services($active,$afid));
}
/**
* Search for accounts matching a term
*/
@@ -167,5 +198,14 @@ class Model_Account extends Model_Auth_UserDefault {
return $return;
}
public function list_services($active=TRUE,$afid=NULL) {
$svs = $this->service->where('active','=',$active);
if ($afid)
$svs->where('affiliate_id','=',$afid);
return $svs->find_all();
}
}
?>