Added login_log and overdue_reminders
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user