Added list_expiring to show services expiring
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user