Added login_log and overdue_reminders

This commit is contained in:
Deon George
2011-09-27 21:22:13 +10:00
parent f38acfe403
commit b6802e4b5d
12 changed files with 302 additions and 21 deletions

View File

@@ -337,7 +337,11 @@ class Model_Invoice extends ORMOSB {
throw new Kohana_Exception('Reminder is not an array? (:reminder)',array(':remind',$this->reminders));
$remind = unserialize($this->reminders);
return isset($remind[$key]) ? $remind[$key] : FALSE;
if (isset($remind[$key]))
return (is_array($remind[$key])) ? end($remind[$key]) : $remind[$key];
else
return FALSE;
}
public function set_remind($key,$value,$add=FALSE) {
@@ -346,20 +350,22 @@ class Model_Invoice extends ORMOSB {
if (! trim($this->reminders)) {
$remind = array();
$remind[$key][] = $value;
} else {
if (! preg_match('/^a:/',$this->reminders))
throw new Kohana_Exception('Reminder is not an array? (:reminder)',array(':remind',$this->reminders));
$remind = unserialize($this->reminders);
if ($add)
$remind[$key][] = $value;
else
$remind[$key] = $value;
}
// If our value is null, we'll remove it.
if (is_null($value) AND isset($remind[$key]))
unset($remind[$key]);
elseif ($add)
$remind[$key][] = $value;
else
$remind[$key] = $value;
$this->reminders = serialize($remind);
$this->save();
return $this->saved();
@@ -390,6 +396,25 @@ class Model_Invoice extends ORMOSB {
return $this->_list_due($time,'<=');
}
/**
* Return a list of invoices that are over their due date with/without auto billing
*/
public function list_overdue_billing($time=NULL,$billing=FALSE) {
$return = array();
foreach ($this->list_overdue($time) as $io) {
$i = FALSE;
foreach ($io->service->find_all() as $so)
if (($billing AND $so->account_billing_id) OR (! $billing AND ! $so->account_billing_id)) {
array_push($return,$io);
break;
}
}
return $return;
}
/**
* Return a list of invoices that are due, excluding overdue.
*/