Added Tasks to KH
This commit is contained in:
48
modules/invoice/classes/controller/task/invoice.php
Normal file
48
modules/invoice/classes/controller/task/invoice.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?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) {
|
||||
$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.'_header');
|
||||
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.'_footer');
|
||||
|
||||
// Send our email
|
||||
$et = EmailTemplate::instance('task_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);
|
||||
}
|
||||
}
|
||||
?>
|
@@ -324,5 +324,37 @@ class Model_Invoice extends ORMOSB {
|
||||
|
||||
$this->_changed[$field] = $field;
|
||||
}
|
||||
|
||||
/** LIST FUNCTIONS **/
|
||||
|
||||
/**
|
||||
* Identify all the invoices that are due
|
||||
*/
|
||||
private function _list_due($time=NULL,$op='<=') {
|
||||
if (is_null($time))
|
||||
$time = time();
|
||||
|
||||
// @todo This rounding should be a system configuration
|
||||
return $this
|
||||
->where('round(total_amt-ifnull(credit_amt,0),2)','>','=billed_amt')
|
||||
->and_where('due_date',$op,$time)
|
||||
->and_where('status','=',1)
|
||||
->order_by('due_date,account_id,id')
|
||||
->find_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of invoices that are over their due date.
|
||||
*/
|
||||
public function list_overdue($time=NULL) {
|
||||
return $this->_list_due($time,'<=');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of invoices that are due, excluding overdue.
|
||||
*/
|
||||
public function list_due($time=NULL) {
|
||||
return $this->_list_due($time,'>');
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user