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

@ -0,0 +1,40 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Admin Account management
*
* @package lnApp
* @subpackage Page/Account
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Admin_Account extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'listlog'=>TRUE,
);
/**
* Show a list of account logins
*/
public function action_listlog() {
Block::add(array(
'title'=>_('Account Login Log'),
'body'=>Table::display(
ORM::factory('account_log')->order_by('id','DESC')->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'admin/account/view/'),
'date_orig'=>array('label'=>'Date'),
'account->name()'=>array('label'=>'Account'),
'ip'=>array('label'=>'IP Address'),
'details'=>array('label'=>'Details'),
),
array(
'page'=>TRUE,
)),
));
}
}
?>

View File

@ -24,9 +24,9 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault {
$o = ORM::factory('invoice');
Block_Sub::add(array(
'title'=>'Invoices Overdue',
'title'=>'Invoices Overdue - No Auto Billing',
'body'=>Table::display(
$o->list_overdue($t),
$o->list_overdue_billing($t),
25,
array(
'due_date'=>array('label'=>'Due Date'),
@ -40,6 +40,23 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault {
'order'=>1,
));
Block_Sub::add(array(
'title'=>'Invoices Overdue - Auto Billing',
'body'=>Table::display(
$o->list_overdue_billing($t,TRUE),
25,
array(
'due_date'=>array('label'=>'Due Date'),
'account->name()'=>array('label'=>'Account'),
'account->display("status")'=>array('label'=>'Active'),
'id()'=>array('label'=>'ID'),
'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
),
array('page'=>TRUE)),
'position'=>2,
'order'=>1,
));
Block_Sub::add(array(
'title'=>'Invoices Due',
'body'=>Table::display(
@ -53,7 +70,7 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault {
'due(TRUE)'=>array('label'=>'Amount Due','class'=>'right'),
),
array('show_other'=>'due()')),
'position'=>2,
'position'=>3,
'order'=>1,
));
@ -73,8 +90,8 @@ class Controller_Admin_Welcome extends Controller_TemplateDefault {
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
),
array('show_other'=>'balance()')),
'position'=>3,
'order'=>1,
'position'=>1,
'order'=>2,
));
Block::add(array(

View File

@ -168,6 +168,9 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
'USER_NAME'=>sprintf('%s %s',$mt->account->first_name,$mt->account->last_name),
);
$et->send();
// Log the password reset
$ao->log('Password reset token sent');
}
// Redirect to our password reset, the Auth will validate the token.

View File

@ -15,7 +15,9 @@ class Controller_lnApp_Logout extends Controller {
public function action_index() {
# If user already signed-in
if (Auth::instance()->logged_in()!= 0) {
$ao = Auth::instance()->get_user();
Auth::instance()->logout();
$ao->log('Logged Out');
Request::current()->redirect('login');
}

View File

@ -34,6 +34,10 @@ class Controller_User_Account extends Controller_TemplateDefault_User {
));
$this->ao->save();
// Log the password reset
$this->ao->log('Password reset');
Request::current()->redirect('login');
} else {
@ -50,6 +54,12 @@ class Controller_User_Account extends Controller_TemplateDefault_User {
'body'=>_('Your updates didnt pass validation.').'<br/>'.$output,
));
}
else
SystemMessage::add(array(
'title'=>_('Record NOT updated'),
'type'=>'info',
'body'=>_('Your account has NOT been updated.')
));
Block::add(array(
'title'=>_('Password Reset'),

View File

@ -112,5 +112,16 @@ class Model_Account extends Model_Auth_UserDefault {
return $format ? Currency::display($result) : $result;
}
public function log($message) {
// Log the logout
$alo = ORM::factory('account_log');
$alo->account_id = $this->id;
$alo->ip = $_SERVER['REMOTE_ADDR'];
$alo->details = $message;
$alo->save();
return $alo->saved();
}
}
?>

View File

@ -0,0 +1,24 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Account Login Logging
*
* @package OSB
* @subpackage Account
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Account_Log extends ORMOSB {
protected $_belongs_to = array(
'account'=>array(),
);
protected $_display_filters = array(
'date_orig'=>array(
array('Config::datetime',array(':value')),
),
);
}
?>

View File

@ -55,7 +55,9 @@ class Model_Auth_UserDefault extends Model_Auth_User {
* We can also do some other post-login actions here.
* @todo Maybe we can do our session update here.
*/
public function complete_login() {}
public function complete_login() {
return $this->log('Logged In');
}
/**
* Test to see if a record has been changed

View File

@ -32,7 +32,7 @@ class Controller_Task_Invoice extends Controller_Task {
$duelist .= View::factory('invoice/task/'.$tm.'_foot');
// Send our email
$et = Email_Template::instance('task_list_invoice_overdue');
$et = Email_Template::instance('task_invoice_list_overdue');
// @todo Update this to be dynamic
$et->to = array('account'=>array(1,68));
@ -51,32 +51,93 @@ class Controller_Task_Invoice extends Controller_Task {
// @todo This should go in a config somewhere
$days = 5;
$io = ORM::factory('invoice');
$key = 'remind_due';
foreach ($io->list_due(time()-86400*$days) as $io) {
// If we have already sent a reminder, we'll skip to the next one.
if ($io->remind('due_reminder') AND (is_null($x=$this->request->param('id')) OR $x != 'again'))
if ($io->remind($key) AND (is_null($x=$this->request->param('id')) OR $x != 'again'))
continue;
// Send our email
$et = Email_Template::instance('task_invoice_due_reminder');
$et = Email_Template::instance('task_invoice_'.$key);
$et->to = array('account'=>array($io->account_id));
$et->variables = array(
'DUE'=>$io->due(TRUE),
'DUE_DATE'=>$io->display('due_date'),
'FIRST_NAME'=>$io->account->first_name,
'INV_NUM'=>$io->refnum(),
'INV_URL'=>URL::site('user/invoice/view/'.$io->id,'http'),
'DUE_DATE'=>$io->display('due_date'),
'FIRSTNAME'=>$io->account->first_name,
'SITE_NAME'=>Config::sitename(),
);
// @todo Record email log id if possible.
if ($et->send())
$io->set_remind('due_reminder',time());
$io->set_remind($key,time());
}
$output = _('Overdue Reminders Sent.');
$this->response->body($output);
$this->response->body(_('Due Reminders Sent.'));
}
public function action_remind_overdue() {
$io = ORM::factory('invoice');
$notice = $this->request->param('id');
$x = NULL;
if (preg_match('/:/',$notice))
list($notice,$x) = explode(':',$notice);
switch ($notice) {
case 1:
// @todo This should go in a config somewhere
$days = 2;
break;
case 2:
// @todo This should go in a config somewhere
$days = 7;
break;
case 3:
// @todo This should go in a config somewhere
$days = 21;
break;
default:
$this->response->body(_('Unknown Remind Period: ').$notice);
return;
}
$key = 'remind_overdue_'.$notice;
$template = 'task_invoice_'.$key;
foreach ($io->list_overdue_billing(time()-86400*$days,FALSE) as $io) {
// If we have already sent a reminder, we'll skip to the next one.
if ($io->remind($key) AND (is_null($x) OR $x != 'again'))
continue;
// Send our email
$et = Email_Template::instance('task_invoice_'.$key);
$et->to = array('account'=>array($io->account_id));
$et->variables = array(
'DUE'=>$io->due(TRUE),
'DUE_DATE'=>$io->display('due_date'),
'EMAIL'=>'accounts@graytech.net.au', // @todo This should come from a config.
'FIRST_NAME'=>$io->account->first_name,
'INV_NUM'=>$io->refnum(),
'INV_URL'=>URL::site('user/invoice/view/'.$io->id,'http'),
'LATE_FEE'=>'5.50', // @todo This should come from a config file.
'PAYMENTS_TABLE'=>$io->account->payment->list_recent_table(),
'SITE_NAME'=>Config::sitename(),
);
// @todo Record email log id if possible.
if ($et->send())
$io->set_remind($key,time());
}
$this->response->body(_('Overdue Reminders Sent: ').$notice);
}
}
?>

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,19 +350,21 @@ 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)
// 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();
@ -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.
*/

View File

@ -88,5 +88,32 @@ class Model_Payment extends ORMOSB {
return $this->where('id','IN',$pi)->order_by('account_id')->find_all();
}
public function list_recent_table() {
// @todo This should be in a config file.
$css = '<style type="text/css">';
$css .= 'table.box-left { border: 1px solid #AAAACC; margin-right: auto; }';
$css .= 'tr.head { font-weight: bold; }';
$css .= 'td.head { font-weight: bold; }';
$css .= 'td.right { text-align: right; }';
$css .= 'tr.odd { background-color: #FCFCFE; }';
$css .= 'tr.even { background-color: #F6F6F8; }';
$css .= '</style>';
return $css.Table::display(
$this->limit(10)->find_all(),
25,
array(
'id'=>array('label'=>'ID'),
'date_payment'=>array('label'=>'Date'),
'checkout->display("name")'=>array('label'=>'Method'),
'total_amt'=>array('label'=>'Total','class'=>'right'),
'balance(TRUE)'=>array('label'=>'Balance','class'=>'right'),
'invoicelist()'=>array('label'=>'Invoices'),
),
array(
'type'=>'list',
));
}
}
?>

View File

@ -0,0 +1,59 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Services
*
* @package OSB
* @subpackage DOMAIN
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Service_DOMAIN extends Model_Service {
protected $_table_name = 'service__domain';
protected $_updated_column = FALSE;
// Relationships
protected $_has_one = array(
'host_tld'=>array('foreign_key'=>'id','far_key'=>'domain_tld_id'),
'host_registrar_plugin'=>array('foreign_key'=>'id','far_key'=>'domain_registrar_id'),
);
protected $_belongs_to = array(
'service'=>array(),
);
protected $_display_filters = array(
'domain_expire'=>array(
array('Config::date',array(':value')),
),
);
protected function _service_name() {
return sprintf('%s - %s','Domain',$this->name());
}
protected function _service_view() {
}
/**
* Get specific service details for use in other modules
* For Example: Invoice
*
* @todo Make the rendered items configurable
*/
protected function _details($type) {
switch ($type) {
default:
throw new Kohana_Exception('Unkown detail request :type',array(':type'=>$type));
}
}
protected function _admin_update() {
}
public function name() {
return sprintf('%s.%s',$this->domain_name,$this->host_tld->name);
}
}
?>