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);
}
/**
* 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() {
return $this->service_number;
}

View File

@ -44,6 +44,10 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin {
return '';
}
public function expire() {
return $this->domain_expire;
}
public function 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 '';
}
public function expire() {
return $this->host_expire;
}
public function 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,
'listadslbilling'=>TRUE,
'listadslservices'=>TRUE,
'listexpiring'=>TRUE,
'listdomainservices'=>TRUE,
'listdomainservicesbysupplier'=>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() {
$svs = ORM::factory('service')->list_bylistgroup('HSPA');
$data = $this->consoltraffic($svs,time());
@ -560,7 +587,13 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
continue;
}
list($id,$ref,$unknown,$linedata,$q,$cost,$total) = explode(',',$line);
// @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);
// Extract the phone number from the $linedata
@list($service,$description) = explode(':',(preg_replace('/([0-9]+)\s+-\s+(.*)$/',"$1:$2",$linedata)));

View File

@ -75,6 +75,38 @@ class Model_Service extends ORMOSB {
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
*/
@ -190,6 +222,32 @@ class Model_Service extends ORMOSB {
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.
*

View File

@ -24,6 +24,11 @@ abstract class Model_Service_Plugin extends ORMOSB {
*/
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.
*/

View File

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