Moved Invoice reminders into Minion Tasks
This commit is contained in:
parent
1b057cd1e5
commit
1b83a5a0b1
@ -160,7 +160,7 @@ class Config extends Kohana_Config {
|
||||
* @return mixed|array - Email to send test emails to
|
||||
*/
|
||||
public static function testmail($template) {
|
||||
$config = Kohana::$config->load('config')->email_admin_only;
|
||||
$config = Kohana::$config->load('debug')->email_admin_only;
|
||||
|
||||
if (is_null($config) OR ! is_array($config) OR empty($config[$template]))
|
||||
return FALSE;
|
||||
|
@ -14,9 +14,6 @@
|
||||
return array(
|
||||
'appname' => 'OS Billing', // Our application name, as shown in the title bar of pages
|
||||
'email_from' => array('noreply@graytech.net.au'=>'Graytech Hosting'),
|
||||
'email_admin_only'=> array(
|
||||
// 'adsl_traffic_notice'=>array('deon@leenooks.vpn'=>'Deon George'),
|
||||
),
|
||||
'method_security' => TRUE, // Enables Method Security. Setting to false means any method can be run without authentication
|
||||
'session_change_trigger'=>array( // Updates to tables to make when our session ID is changed
|
||||
'Cart'=>'session_id',
|
||||
|
@ -16,6 +16,9 @@ return array
|
||||
'ajax'=>FALSE, // AJAX actions can only be run by ajax calls if set to FALSE
|
||||
'etag'=>FALSE, // Force generating ETAGS
|
||||
'checkout_notify'=>FALSE, // Test mode to test a particular checkout_notify item
|
||||
'email_admin_only'=> array( // Override emails and send them to an admin instead
|
||||
// 'task_invoice_list_overdue'=>array('deon@leenooks.net'=>'Deon George'),
|
||||
),
|
||||
'invoice'=>0, // Number of invoices to generate in a pass
|
||||
'site'=>FALSE, // Glogal site debug
|
||||
'show_errors'=>FALSE, // Show errors instead of logging in the DB.
|
||||
|
@ -150,10 +150,10 @@ class Email_Template {
|
||||
|
||||
// @todo - Setup queue mode
|
||||
$result = $e->send($sm);
|
||||
// Store our email log.
|
||||
$elo = ORM::factory('Email_Log');
|
||||
|
||||
if ($result) {
|
||||
// Store our email log.
|
||||
$elo = ORM::factory('Email_Log');
|
||||
|
||||
foreach ($sa as $id) {
|
||||
$elo->clear();
|
||||
@ -166,7 +166,7 @@ class Email_Template {
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
return ($result AND $elo->saved()) ? $elo->id : $result;
|
||||
}
|
||||
|
||||
private function to_accounts() {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
?>
|
@ -58,7 +58,9 @@ class Task_Task_Run extends Minion_Task {
|
||||
|
||||
switch ($to->type) {
|
||||
case 1:
|
||||
$r = Minion_Task::factory(array('site'=>Minion_CLI::options('site'),'task'=>$to->command))->execute();
|
||||
ob_start();
|
||||
Minion_Task::factory(array('site'=>Minion_CLI::options('site'),'task'=>$to->command))->execute();
|
||||
$r = ob_get_clean();
|
||||
$to->running = 0;
|
||||
$to->running_host = NULL;
|
||||
|
||||
|
Reference in New Issue
Block a user