This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/invoice/classes/controller/task/invoice.php
2012-01-12 19:53:54 +11:00

83 lines
2.3 KiB
PHP

<?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 {
public function action_list() {
$mode = $this->request->param('id');
$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;
$duelist = View::factory('invoice/task/'.$tm.'_head');
foreach ($io->$tm() as $t) {
$duelist .= View::factory('invoice/task/'.$tm.'_body')
->set('io',$t);
$numinv++;
$total += $t->due();
}
$duelist .= View::factory('invoice/task/'.$tm.'_foot');
// Send our email
$et = Email_Template::instance('task_list_invoice_overdue');
// @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);
}
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);
}
}
?>