Email invoices to users
This commit is contained in:
@@ -60,10 +60,10 @@ class Controller_Task_Invoice extends Controller_Task {
|
||||
$action = array();
|
||||
// @todo This should go in a config somewhere
|
||||
$days = 5;
|
||||
$io = ORM::factory('invoice');
|
||||
$i = ORM::factory('invoice');
|
||||
$key = 'remind_due';
|
||||
|
||||
foreach ($io->list_due(time()+86400*$days) as $io) {
|
||||
foreach ($i->list_due(time()+86400*$days) as $io) {
|
||||
// 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'))
|
||||
continue;
|
||||
@@ -96,7 +96,7 @@ class Controller_Task_Invoice extends Controller_Task {
|
||||
*/
|
||||
public function action_remind_overdue() {
|
||||
$action = array();
|
||||
$io = ORM::factory('invoice');
|
||||
$i = ORM::factory('invoice');
|
||||
$notice = $this->request->param('id');
|
||||
$x = NULL;
|
||||
|
||||
@@ -125,9 +125,8 @@ class Controller_Task_Invoice extends Controller_Task {
|
||||
}
|
||||
|
||||
$key = 'remind_overdue_'.$notice;
|
||||
$template = 'task_invoice_'.$key;
|
||||
|
||||
foreach ($io->list_overdue_billing(time()-86400*$days,FALSE) as $io) {
|
||||
foreach ($i->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;
|
||||
@@ -230,6 +229,56 @@ class Controller_Task_Invoice extends Controller_Task {
|
||||
$this->response->body(_('Services Invoiced: ').join('|',$action));
|
||||
}
|
||||
|
||||
public function action_invoice_send() {
|
||||
$action = array();
|
||||
$iid = $this->request->param('id');
|
||||
$x = NULL;
|
||||
|
||||
if (preg_match('/:/',$iid))
|
||||
list($iid,$x) = explode(':',$iid);
|
||||
|
||||
// @todo The parameter for email should be a system CONSTANT?
|
||||
$i = $iid ? ORM::factory('invoice')->where('id','=',$iid) : ORM::factory('invoice')->tosend(1);
|
||||
|
||||
$key = 'send';
|
||||
|
||||
foreach ($i->find_all() 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);
|
||||
$token = ORM::factory('module_method_token')
|
||||
->method(array('invoice','user_download'))
|
||||
->account($io->account)
|
||||
->expire(time()+86400*21)
|
||||
->uses(3)
|
||||
->generate();
|
||||
|
||||
$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,
|
||||
'HTML_INVOICE'=>$io->html(),
|
||||
'INV_NUM'=>$io->refnum(),
|
||||
'INV_URL'=>URL::site('user/invoice/view/'.$io->id,'http'),
|
||||
'INV_URL_DOWNLOAD'=>URL::site(sprintf('user/invoice/download/%s?token=%s',$io->id,$token),'http'),
|
||||
'SITE_NAME'=>Config::sitename(),
|
||||
);
|
||||
|
||||
// @todo Record email log id if possible.
|
||||
if ($et->send()) {
|
||||
$io->set_remind($key,time());
|
||||
array_push($action,(string)$io);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->body(_('Invoices Sent: ').join('|',$action));
|
||||
}
|
||||
|
||||
/** END **/
|
||||
|
||||
public function action_audit_invoice_items() {
|
||||
@@ -241,19 +290,9 @@ class Controller_Task_Invoice extends Controller_Task {
|
||||
$iio->product_name = null;
|
||||
$iio->save();
|
||||
} else {
|
||||
print_r(array("DIFF",'id'=>$iio->id,'pn'=>serialize($iio->product_name),'ppn'=>serialize($iio->product->name()),'pid'=>$iio->product_id,'test'=>strcasecmp($iio->product_name,$iio->product->name())));
|
||||
print_r(array("DIFF",'id'=>$iio->id,'pn'=>serialize($iio->product_name),'ppn'=>serialize($iio->product->name()),'pid'=>$iio->product_id,'test'=>strcasecmp($iio->product_name,$iio->product->name())));
|
||||
}
|
||||
}
|
||||
|
||||
#if ($iio->product->prod_plugin_file == 'HOST') {
|
||||
# if ($iio->service->name() == strtoupper($iio->domain_name))
|
||||
# $iio->domain_name=null;
|
||||
#}
|
||||
#if ($iio->product->prod_plugin_file == 'ADSL') {
|
||||
# if ($iio->service->name() == strtoupper($iio->domain_name))
|
||||
# $iio->domain_name=null;
|
||||
# #print_r(array('pid'=>$iio->domain_name,'iio-service-name'=>$iio->service->name(),'iii-domain_name'=>$iio->domain_name));
|
||||
#}
|
||||
}
|
||||
|
||||
$this->response->body($output);
|
||||
|
Reference in New Issue
Block a user