2011-08-16 02:27:19 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides OSB invoice task capabilities.
|
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @subpackage Invoice
|
|
|
|
* @category Controllers/Task
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
|
|
|
class Controller_Task_Invoice extends Controller_Task {
|
2011-09-26 10:12:54 +00:00
|
|
|
public function action_list() {
|
|
|
|
$mode = $this->request->param('id');
|
|
|
|
|
2011-08-16 02:27:19 +00:00
|
|
|
$io = ORM::factory('invoice');
|
|
|
|
$tm = 'list_'.$mode;
|
|
|
|
|
|
|
|
if (! method_exists($io,$tm))
|
|
|
|
throw new Kohana_Exception('Unknown Task List command :command',array(':command'=>$mode));
|
|
|
|
|
|
|
|
$total = $numinv = 0;
|
2011-08-27 06:33:46 +00:00
|
|
|
$duelist = View::factory('invoice/task/'.$tm.'_head');
|
2011-08-16 02:27:19 +00:00
|
|
|
foreach ($io->$tm() as $t) {
|
|
|
|
$duelist .= View::factory('invoice/task/'.$tm.'_body')
|
|
|
|
->set('io',$t);
|
|
|
|
|
|
|
|
$numinv++;
|
|
|
|
$total += $t->due();
|
|
|
|
}
|
2011-08-27 06:33:46 +00:00
|
|
|
$duelist .= View::factory('invoice/task/'.$tm.'_foot');
|
2011-08-16 02:27:19 +00:00
|
|
|
|
|
|
|
// Send our email
|
2011-09-26 10:12:54 +00:00
|
|
|
$et = Email_Template::instance('task_list_invoice_overdue');
|
2011-08-16 02:27:19 +00:00
|
|
|
|
|
|
|
// @todo Update this to be dynamic
|
|
|
|
$et->to = array('account'=>array(1,68));
|
|
|
|
$et->variables = array(
|
|
|
|
'TABLE'=>$duelist,
|
|
|
|
'NUM_INV'=>$numinv,
|
|
|
|
'TOTAL'=>$total,
|
|
|
|
);
|
|
|
|
$et->send();
|
|
|
|
|
|
|
|
$output = sprintf('List (%s) sent to: %s',$mode,implode(',',array_keys($et->to)));
|
|
|
|
$this->response->body($output);
|
|
|
|
}
|
2011-09-26 10:12:54 +00:00
|
|
|
|
|
|
|
public function action_remind_due() {
|
|
|
|
// @todo This should go in a config somewhere
|
|
|
|
$days = 5;
|
|
|
|
$io = ORM::factory('invoice');
|
|
|
|
|
|
|
|
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'))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Send our email
|
|
|
|
$et = Email_Template::instance('task_invoice_due_reminder');
|
|
|
|
|
|
|
|
$et->to = array('account'=>array($io->account_id));
|
|
|
|
$et->variables = array(
|
|
|
|
'DUE'=>$io->due(TRUE),
|
|
|
|
'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());
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = _('Overdue Reminders Sent.');
|
|
|
|
$this->response->body($output);
|
|
|
|
}
|
2011-08-16 02:27:19 +00:00
|
|
|
}
|
|
|
|
?>
|