Added list_expiring to show services expiring

This commit is contained in:
Deon George 2012-10-08 23:52:21 +11:00
parent 23247a5d4e
commit 59321a6877
7 changed files with 117 additions and 1 deletions

View File

@ -36,6 +36,14 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
->set('so',$this); ->set('so',$this);
} }
/**
* When does this service expire
*/
public function expire() {
// @todo This should work out if the invoices are currently due, then the expire is the invoice date, otherwise the next invoice date.
return NULL;
}
public function name() { public function name() {
return $this->service_number; return $this->service_number;
} }

View File

@ -44,6 +44,10 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin {
return ''; return '';
} }
public function expire() {
return $this->domain_expire;
}
public function name() { public function name() {
return sprintf('%s.%s',$this->display('domain_name'),$this->domain_tld->display('name')); return sprintf('%s.%s',$this->display('domain_name'),$this->domain_tld->display('name'));
} }

View File

@ -41,6 +41,10 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin {
return ''; return '';
} }
public function expire() {
return $this->host_expire;
}
public function name() { public function name() {
return sprintf('%s.%s',$this->display('domain_name'),$this->domain_tld->display('name')); return sprintf('%s.%s',$this->display('domain_name'),$this->domain_tld->display('name'));
} }

View File

@ -19,6 +19,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'listbycheckout'=>TRUE, 'listbycheckout'=>TRUE,
'listadslbilling'=>TRUE, 'listadslbilling'=>TRUE,
'listadslservices'=>TRUE, 'listadslservices'=>TRUE,
'listexpiring'=>TRUE,
'listdomainservices'=>TRUE, 'listdomainservices'=>TRUE,
'listdomainservicesbysupplier'=>TRUE, 'listdomainservicesbysupplier'=>TRUE,
'listdomainservicesbydnshost'=>TRUE, 'listdomainservicesbydnshost'=>TRUE,
@ -212,6 +213,32 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
)); ));
} }
/**
* Show a list of services that are expiring or have expired
*/
public function action_listexpiring() {
$svs = ORM::factory('service')->list_expiring();
Sort::MAsort($svs,'expire()');
Block::add(array(
'title'=>_('ADSL Services'),
'body'=>Table::display(
$svs,
NULL,
array(
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Service'),
'expire(TRUE)'=>array('label'=>'Expires'),
'due(TRUE)'=>array('label'=>'Due'),
),
array(
'type'=>'select',
'form'=>'user/service/view',
)),
));
}
public function action_listhspaservices() { public function action_listhspaservices() {
$svs = ORM::factory('service')->list_bylistgroup('HSPA'); $svs = ORM::factory('service')->list_bylistgroup('HSPA');
$data = $this->consoltraffic($svs,time()); $data = $this->consoltraffic($svs,time());
@ -560,6 +587,12 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
continue; continue;
} }
// @todo This is to workaround SEP2012 CSV invoice which had extra columns.
if (count(explode(',',$line)) == 9)
list($id,$ref,$unknown,$unknown,$unknown,$linedata,$q,$cost,$total) = explode(',',$line);
elseif (count(explode(',',$line)) == 10)
list($id,$ref,$unknown,$unknown,$unknown,$unknown,$linedata,$q,$cost,$total) = explode(',',$line);
else
list($id,$ref,$unknown,$linedata,$q,$cost,$total) = explode(',',$line); list($id,$ref,$unknown,$linedata,$q,$cost,$total) = explode(',',$line);
// Extract the phone number from the $linedata // Extract the phone number from the $linedata

View File

@ -75,6 +75,38 @@ class Model_Service extends ORMOSB {
return is_null($plugin=$this->plugin()) ? $this->product->name() : $plugin->name(); return is_null($plugin=$this->plugin()) ? $this->product->name() : $plugin->name();
} }
/**
* Display how much is due on this service
*/
public function due($format=FALSE) {
$total = 0;
foreach ($this->list_invoices(TRUE) as $io)
$total += $io->due();
return $format ? Currency::display($total) : $total;
}
/**
* When does this service expire
*/
public function expire($format=FALSE) {
// For plugins the plugin determins expiry
$expire = (is_null($plugin=$this->plugin()) ? NULL : $plugin->expire());
// If $expire is NULL, we'll use the next invoice date
$expire = is_null($expire) ? $this->date_next_invoice-86400 : $expire;
return $format ? Config::date($expire) : $expire;
}
/**
* Determine if a service expires in the next $days.
*/
public function expiring($days) {
return time()+$days*86400 > $this->expire();
}
/** /**
* Return the service charge * Return the service charge
*/ */
@ -190,6 +222,32 @@ class Model_Service extends ORMOSB {
return $result; return $result;
} }
/**
* List services expiring
*/
public function list_expiring($days=14) {
$result = array();
foreach ($this->list_active() as $so)
if ($so->expiring($days))
array_push($result,$so);
return $result;
}
/**
* List invoices for this service
*/
public function list_invoices($due=FALSE) {
$return = array();
foreach ($this->invoice->find_all() as $io)
if (! $due OR $io->due())
array_push($return,$io);
return $return;
}
/** /**
* List services that need to be billed. * List services that need to be billed.
* *

View File

@ -24,6 +24,11 @@ abstract class Model_Service_Plugin extends ORMOSB {
*/ */
abstract public function name(); abstract public function name();
/**
* When does our service expire
*/
abstract public function expire();
/** /**
* Show our service name as defined in the DB with product suffix. * Show our service name as defined in the DB with product suffix.
*/ */

View File

@ -40,6 +40,10 @@ class Model_Service_Plugin_SSL extends Model_Service_Plugin {
->set('so',$this); ->set('so',$this);
} }
public function expire() {
return $this->valid_to();
}
public function name() { public function name() {
if ($this->cert) { if ($this->cert) {
return sprintf('%s:%s',$this->ssl_ca->subject(),$this->display('cert')); return sprintf('%s:%s',$this->ssl_ca->subject(),$this->display('cert'));