Moved Invoice reminders into Minion Tasks
This commit is contained in:
@@ -49,63 +49,6 @@ class Controller_Task_Invoice extends Controller_Task {
|
||||
$this->response->body(_('Due Reminders Sent: ').join('|',$action));
|
||||
}
|
||||
|
||||
/**
|
||||
* Email a customers when their invoices are now overdue.
|
||||
*/
|
||||
public function action_remind_overdue() {
|
||||
$action = array();
|
||||
$notice = $this->request->param('id');
|
||||
$x = NULL;
|
||||
|
||||
if (preg_match('/:/',$notice))
|
||||
list($notice,$x) = explode(':',$notice);
|
||||
|
||||
switch ($notice) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
$days = ORM::factory('Invoice')->config('REMIND_OVERDUE_'.$notice);
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->response->body(_('Unknown Remind Period: ').$notice);
|
||||
return;
|
||||
}
|
||||
|
||||
$key = 'remind_overdue_'.$notice;
|
||||
|
||||
foreach (ORM::factory('Invoice')->list_overdue_billing(time()-86400*$days,FALSE) as $io) {
|
||||
// @todo Use another option to supress reminders
|
||||
// If we have already sent a reminder, we'll skip to the next one.
|
||||
if (($io->remind($key) AND (is_null($x=$this->request->param('id')) OR $x != 'again')) OR ($io->account->invoice_delivery != 1))
|
||||
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'=>Company::instance()->email(),
|
||||
'FIRST_NAME'=>$io->account->first_name,
|
||||
'INV_NUM'=>$io->refnum(),
|
||||
'INV_URL'=>URL::site(URL::link('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'=>Company::instance()->name(),
|
||||
);
|
||||
|
||||
// @todo Record email log id if possible.
|
||||
if ($et->send()) {
|
||||
$io->set_remind($key,time());
|
||||
array_push($action,(string)$io);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->body(_('Overdue Reminders Sent: ').join('|',$action));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate our services invoices, based on the service next invoice date
|
||||
*
|
||||
|
@@ -464,19 +464,22 @@ class Model_Invoice extends ORM_OSB implements Cartable {
|
||||
}
|
||||
|
||||
public function set_remind($key,$value,$add=FALSE) {
|
||||
$x = $this->reminders;
|
||||
|
||||
// If our value is null, we'll remove it.
|
||||
if (is_null($value) AND isset($this->reminders[$key]))
|
||||
unset($this->reminders[$key]);
|
||||
if (is_null($value) AND isset($x[$key]))
|
||||
unset($x[$key]);
|
||||
|
||||
elseif ($add) {
|
||||
if (! is_array($a=$this->reminders[$key]))
|
||||
$this->reminders[$key] = array($a);
|
||||
if (! is_array($a=$x[$key]))
|
||||
$x[$key] = array($a);
|
||||
|
||||
$this->reminders[$key][] = $value;
|
||||
$x[$key][] = $value;
|
||||
|
||||
} else
|
||||
$this->reminders[$key] = $value;
|
||||
$x[$key] = $value;
|
||||
|
||||
$this->reminders = $x;
|
||||
$this->save();
|
||||
|
||||
return $this->saved();
|
||||
|
67
modules/invoice/classes/Task/Invoice/Remindoverdue1.php
Normal file
67
modules/invoice/classes/Task/Invoice/Remindoverdue1.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* Send out first reminder for over due invoices.
|
||||
*
|
||||
* @package Invoice
|
||||
* @category Tasks
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Task_Invoice_Remindoverdue1 extends Minion_Task {
|
||||
protected function remind_overdue($notice=1) {
|
||||
$action = array();
|
||||
|
||||
$key = 'remind_overdue_'.$notice;
|
||||
|
||||
switch ($notice) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
$days = ORM::factory('Invoice')->config(strtoupper($key));
|
||||
break;
|
||||
|
||||
default:
|
||||
$this->response->body(_('Unknown Remind Period: ').$notice);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (ORM::factory('Invoice')->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) OR ($io->account->invoice_delivery != 1))
|
||||
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'=>Company::instance()->email(),
|
||||
'FIRST_NAME'=>$io->account->first_name,
|
||||
'INV_NUM'=>$io->refnum(),
|
||||
'INV_URL'=>URL::site(URL::link('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'=>Company::instance()->name(),
|
||||
);
|
||||
|
||||
// @todo Record email log id if possible.
|
||||
if ($eloid = $et->send()) {
|
||||
$io->set_remind($key,time(),FALSE);
|
||||
array_push($action,(string)$io);
|
||||
}
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
protected function _execute(array $params) {
|
||||
$action = $this->remind_overdue(1);
|
||||
|
||||
return _('OverDue Notice #1 Reminders Sent: ').join('|',$action);
|
||||
}
|
||||
}
|
||||
?>
|
19
modules/invoice/classes/Task/Invoice/Remindoverdue2.php
Normal file
19
modules/invoice/classes/Task/Invoice/Remindoverdue2.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* Send out second reminder for over due invoices.
|
||||
*
|
||||
* @package Invoice
|
||||
* @category Tasks
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Task_Invoice_Remindoverdue2 extends Task_Invoice_Remindoverdue1 {
|
||||
protected function _execute(array $params) {
|
||||
$action = $this->remind_overdue(2);
|
||||
|
||||
return _('OverDue Notice #2 Reminders Sent: ').join('|',$action);
|
||||
}
|
||||
}
|
||||
?>
|
19
modules/invoice/classes/Task/Invoice/Remindoverdue3.php
Normal file
19
modules/invoice/classes/Task/Invoice/Remindoverdue3.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* Send out third reminder for over due invoices.
|
||||
*
|
||||
* @package Invoice
|
||||
* @category Tasks
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Task_Invoice_Remindoverdue3 extends Task_Invoice_Remindoverdue1 {
|
||||
protected function _execute(array $params) {
|
||||
$action = $this->remind_overdue(3);
|
||||
|
||||
return _('OverDue Notice #3 Reminders Sent: ').join('|',$action);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user