2013-07-05 13:37:06 +00:00
|
|
|
<?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 {
|
2013-11-28 06:41:34 +00:00
|
|
|
// @todo This should be moved to somewhere else
|
|
|
|
private $_css = '
|
|
|
|
<style type="text/css">
|
|
|
|
table.box-left { border: 1px solid #AAAACC; margin-right: auto; }
|
|
|
|
tr.head { font-weight: bold; }
|
|
|
|
td.head { font-weight: bold; }
|
|
|
|
td.right { text-align: right; }
|
|
|
|
tr.odd { background-color: #FCFCFE; }
|
|
|
|
tr.even { background-color: #F6F6F8; }
|
|
|
|
</style>';
|
|
|
|
|
2013-07-05 13:37:06 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-11 02:08:50 +00:00
|
|
|
foreach (ORM::factory('Invoice')->list_overdue_billing(time()-86400*$days,FALSE,FALSE) as $io) {
|
2013-07-05 13:37:06 +00:00
|
|
|
// 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.
|
2013-11-28 06:41:34 +00:00
|
|
|
'PAYMENTS_TABLE'=>$this->_css.$io->account->payment->list_recent_table(),
|
2013-07-05 13:37:06 +00:00
|
|
|
'SITE_NAME'=>Company::instance()->name(),
|
|
|
|
);
|
|
|
|
|
2013-12-19 23:00:32 +00:00
|
|
|
$et->module = $io->mid();
|
|
|
|
$et->module_data = $io->id;
|
|
|
|
|
2013-07-05 13:37:06 +00:00
|
|
|
// @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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|