Added Tasks to KH

This commit is contained in:
Deon George 2011-08-16 12:27:19 +10:00
parent f272bc254d
commit 4c9b214ff7
53 changed files with 773 additions and 170 deletions

View File

@ -102,6 +102,7 @@ Kohana::$config->attach(new Config_File);
Kohana::modules(array( Kohana::modules(array(
'auth' => SMDPATH.'auth', // Basic authentication 'auth' => SMDPATH.'auth', // Basic authentication
'cache' => SMDPATH.'cache', // Caching with multiple backends 'cache' => SMDPATH.'cache', // Caching with multiple backends
'cron' => SMDPATH.'cron', // Kohana Cron Module
// 'codebench' => SMDPATH.'codebench', // Benchmarking tool // 'codebench' => SMDPATH.'codebench', // Benchmarking tool
'database' => SMDPATH.'database', // Database access 'database' => SMDPATH.'database', // Database access
// 'image' => SMDPATH.'image', // Image manipulation // 'image' => SMDPATH.'image', // Image manipulation

View File

@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Block_Sub extends lnApp_Block_Sub {}
?>

View File

@ -0,0 +1,70 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB Admin Main home page
*
* @package OSB
* @subpackage Page/Home
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Admin_Welcome extends Controller_TemplateDefault {
protected $auth_required = TRUE;
public $secure_actions = array(
'index'=>TRUE,
);
public function action_index() {
$ao = ORM::factory('account',Auth::instance()->get_user()->id);
$t = time();
// Show outstanding invoices
$o = ORM::factory('invoice');
Block_Sub::add(array(
'title'=>'Invoices Overdue',
'body'=>Table::limit(
$o->list_overdue($t),
30,
array('Due Date'=>'display("due_date")','Account'=>'account->name()','Active'=>'account->display("status")','ID'=>'id()','Amount Due'=>'due(TRUE)'),
'due()'),
'position'=>1,
'order'=>1,
));
Block_Sub::add(array(
'title'=>'Invoices Due',
'body'=>Table::limit(
$o->list_due($t),
30,
array('Due Date'=>'display("due_date")','Account'=>'account->name()','Active'=>'account->display("status")','ID'=>'id()','Amount Due'=>'due(TRUE)'),
'due()'),
'position'=>2,
'order'=>1,
));
// Show un-applied payments
$o = ORM::factory('payment');
Block_Sub::add(array(
'title'=>'Unapplied Payments',
'body'=>Table::limit(
$o->list_unapplied(),
30,
array('ID'=>'id','Account'=>'account->name()','Total'=>'display("total_amt")','Balance'=>'balance(TRUE)'),
'balance(TRUE)'),
'position'=>3,
'order'=>1,
));
Block::add(array(
'title'=>sprintf('%s: %s %s',$ao->accnum(),$ao->first_name,$ao->last_name),
'subtitle'=>_('Administrator Overview'),
'body'=>(string)Block_Sub::factory(),
));
}
}
?>

View File

@ -0,0 +1,21 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides the default controller for tasks.
*
* @package lnApp
* @subpackage Task
* @category Abstract/Controllers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class Controller_lnApp_Task extends Controller {
public function before() {
if (! Kohana::$is_cli)
throw new Kohana_Exception('Cant run :method, it must be run by the CLI',array(':method'=>$this->request->action()));
parent::before();
}
}
?>

View File

@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_Task extends Controller_lnApp_Task {}
?>

View File

@ -28,3 +28,4 @@ class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
Request::factory()->redirect('welcome'); Request::factory()->redirect('welcome');
} }
} }
?>

View File

@ -0,0 +1,95 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for rendering HTML sub body blocks.
*
* It will provide a header, body and footer.
*
* @package lnApp
* @subpackage Page
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
* @uses Style
*/
class lnApp_Block_Sub extends HTMLRender {
protected static $_data = array();
protected static $_spacer = '<table><tr class="spacer"><td>&nbsp;</td></tr></table>';
protected static $_required_keys = array('body','position');
/**
* Add a block to be rendered
*
* @param array Block attributes
*/
public static function add($block,$prepend=FALSE) {
parent::add($block);
// Detect any style sheets.
if (! empty($block['style']) && is_array($block['style']))
foreach ($block['style'] as $data=>$media)
Style::add(array(
'type'=>'file',
'data'=>$data,
'media'=>$media,
));
}
/**
* Return an instance of this class
*
* @return Block
*/
public static function factory() {
return new Block_Sub;
}
/**
* Render this block
*
* @see HTMLRender::render()
*/
protected function render() {
$output = '';
$o = array();
$i = 0;
$x = $y = 0;
Sort::MAsort(static::$_data,'order,position,title,subtitle');
foreach (static::$_data as $value) {
$i = (! isset($value['order'])) ? $i+1 : $value['order'];
// Work out our dimentions
if ($value['position'] > $y)
$y = $value['position'];
if ($i > $x)
$x = $i;
// @todo Alert if a sub block has already been defined.
$o[$i][$value['position']] = '<table class="subblock" border="0">';
if (! empty($value['title']))
$o[$i][$value['position']] .= sprintf('<tr class="title"><td>%s</td></tr>',$value['title']);
if (! empty($value['subtitle']))
$o[$i][$value['position']] .= sprintf('<tr class="subtitle"><td>%s</td></tr>',$value['subtitle']);
$o[$i][$value['position']] .= sprintf('<tr class="body"><td>%s</td></tr>',$value['body']);
if (! empty($value['footer']))
$o[$i][$value['position']] .= sprintf('<tr class="footer"><td>%s</td></tr>',$value['footer']);
$o[$i][$value['position']] .= '</table>';
}
// Render our output.
$output .= '<table class="subblockhead">';
foreach ($o as $k => $v)
$output .= sprintf('<tr><td style="width: %s%%;">%s</td></tr>',round(100/$y,0),implode('</td><td>',$v));
$output .= '</table>';
return $output;
}
}
?>

View File

@ -84,6 +84,20 @@ abstract class lnApp_Config extends Kohana_Config {
return date(Kohana::config('config.date_format'),$date); return date(Kohana::config('config.date_format'),$date);
} }
/**
* Show a date using a site configured format
*/
public static function time($date) {
return date(Kohana::config('config.time_format'),$date);
}
/**
* Show a date using a site configured format
*/
public static function datetime($date) {
return date(Kohana::config('config.date_format').' '.Kohana::config('config.time_format'),$date);
}
/** /**
* See if our emails for the template should be sent to configured admin(s) * See if our emails for the template should be sent to configured admin(s)
* *

View File

@ -77,9 +77,7 @@ abstract class lnApp_HTMLRender {
// Display the exception message // Display the exception message
catch (Exception $e) { catch (Exception $e) {
Kohana::exception_handler($e); Kohana_Exception::handler($e);
return '';
} }
} }

View File

@ -0,0 +1,63 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for rendering a table of data.
*
* @package lnApp
* @subpackage Page
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
* @uses Style
*/
class lnApp_Table {
public static function limit($data,$rows,array $cols,$other) {
if (! (array)$data)
return '';
$output = '';
$other = $i = 0;
$output = '<table border="0">';
$output .= '<tr><th>'.implode('</th><th>',array_keys($cols)).'</th></tr>';
foreach ($data as $do) {
if ($i++ < $rows) {
$output .= '<tr>';
foreach (array_values($cols) as $col) {
if (is_array($do) AND isset($do[$col]))
$x = $do[$col];
// If the col is a method, we need to eval it
elseif (preg_match('/\(/',$col))
eval("\$x = \$do->$col;");
else
$x = $do->{$col};
$output .= sprintf('<td>%s</td>',$x);
}
$output .= '</tr>';
} else {
if (is_array($do) AND isset($do[$col]))
$x = $do[$col];
// If the col is a method, we need to eval it
elseif (preg_match('/\(/',$col))
eval("\$x = \$do->$col;");
else
$x = $do->{$col};
$other += $x;
}
}
if ($other)
$output .= sprintf('<tr><td>Other</td><td colspan="%s">(%s) %s</td></tr>',count($cols)-1,$i-$rows,$other);
$output .= '</table>';
return $output;
}
}
?>

View File

@ -0,0 +1,4 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Table extends lnApp_Table {}
?>

View File

@ -13,6 +13,7 @@ return array(
'cache_type' => 'file', 'cache_type' => 'file',
'currency_format' => '2', 'currency_format' => '2',
'date_format' => 'd-M-Y', 'date_format' => 'd-M-Y',
'time_format' => 'H:i:s',
'email_admin_only'=> array( 'email_admin_only'=> array(
'adsl_traffic_notice'=>array('deon@c5t61p.leenooks.vpn'=>'Deon George'), 'adsl_traffic_notice'=>array('deon@c5t61p.leenooks.vpn'=>'Deon George'),
), ),

View File

@ -197,6 +197,21 @@ table.page tr.pagemain td.pagebody table.content table.block {
width: 100%; width: 100%;
} }
table.page tr.pagemain td.pagebody table.content table.block td {
vertical-align: top;
}
table.page tr.pagemain td.pagebody table.content table.subblockhead {
width: 100%;
}
table.page tr.pagemain td.pagebody table.content table.subblock {
width: 100%;
border: 1px solid #AAAACC;
margin-right: auto;
width: 100%;
}
table.page tr.pagemain td.pagebody table.content tr.title { table.page tr.pagemain td.pagebody table.content tr.title {
text-align: left; text-align: left;
margin: 0px; margin: 0px;

View File

@ -1 +0,0 @@
<!-- This template is shown via CLI tasks -->

View File

@ -18,6 +18,18 @@ class Model_Account extends Model_Auth_UserDefault {
'service' => array('far_key'=>'id'), 'service' => array('far_key'=>'id'),
); );
protected $_display_filters = array(
'date_orig'=>array(
array('Config::date',array(':value')),
),
'date_last'=>array(
array('Config::date',array(':value')),
),
'status'=>array(
array('StaticList_YesNo::display',array(':value')),
),
);
/** /**
* Return an account name * Return an account name
*/ */
@ -32,10 +44,6 @@ class Model_Account extends Model_Auth_UserDefault {
return sprintf('%02s-%04s',Config::siteid(),$this->id); return sprintf('%02s-%04s',Config::siteid(),$this->id);
} }
public function date_last() {
return Config::date($this->date_last);
}
public function title($name) { public function title($name) {
return StaticList_Title::form($name,$this->title); return StaticList_Title::form($name,$this->title);
} }

View File

@ -78,3 +78,4 @@ class Model_Auth_UserDefault extends Model_Auth_User {
->as_array(); ->as_array();
} }
} }
?>

View File

@ -3,7 +3,7 @@
<table class="box-center"> <table class="box-center">
<tr> <tr>
<td class="head">Last Updated</td> <td class="head">Last Updated</td>
<td><?php echo $record->date_last(); ?></td> <td><?php echo $record->display('date_last'); ?></td>
</tr> </tr>
<tr> <tr>
<td class="head">User Name</td> <td class="head">User Name</td>

View File

@ -9,8 +9,6 @@
* @license http://dev.leenooks.net/license.html * @license http://dev.leenooks.net/license.html
*/ */
class Model_Group extends Model_Auth_RoleDefault { class Model_Group extends Model_Auth_RoleDefault {
protected $_object_formated = array();
// Relationships // Relationships
protected $_has_many = array( protected $_has_many = array(
'account'=>array('through'=>'account_group'), 'account'=>array('through'=>'account_group'),
@ -20,10 +18,6 @@ class Model_Group extends Model_Auth_RoleDefault {
'name'=>'ASC', 'name'=>'ASC',
); );
protected $_formats = array(
'status'=>array('StaticList_YesNo::display'=>array()),
);
// Validation rules // Validation rules
protected $_rules = array( protected $_rules = array(
'name' => array( 'name' => array(
@ -35,5 +29,11 @@ class Model_Group extends Model_Auth_RoleDefault {
'max_length' => array(255), 'max_length' => array(255),
), ),
); );
protected $_display_filters = array(
'status'=>array(
array('StaticList_YesNo::display',array(':value')),
),
);
} }
?> ?>

View File

@ -38,10 +38,12 @@ class Model_ADSL_Supplier extends ORMOSB {
return $services; return $services;
} }
/** LIST FUNCTIONS **/
/** /**
* Return a list of active suppliers * Return a list of active suppliers
*/ */
public function active() { public function list_active() {
return $this->where('status','=',1)->find_all(); return $this->where('status','=',1)->find_all();
} }
} }

View File

@ -15,3 +15,4 @@ class Currency {
return Num::format($amount,2,TRUE); return Num::format($amount,2,TRUE);
} }
} }
?>

View File

@ -0,0 +1,20 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Email Logging
*
* @package OSB
* @subpackage Email
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Email_Log extends ORMOSB {
protected $_display_filters = array(
'date_orig'=>array(
array('Config::datetime',array(':value')),
),
);
}
?>

View File

@ -39,12 +39,18 @@ class EmailTemplate {
public function __set($key,$value) { public function __set($key,$value) {
switch ($key) { switch ($key) {
case 'to':
if (! is_array($value) OR ! array_intersect(array('email','account'),array_keys($value)))
throw new Kohana_Exception('Values for to should be an array of either "mail" or "account", however :value was given',array(':value'=>serialize($value)));
$this->email_data[$key] = $value;
break;
case 'variables': case 'variables':
// Our variables should be an array // Our variables should be an array
if (! is_array($value)) if (! is_array($value))
throw new Kohana_Exception('Values for variables should be an array, however :value was given',array(':value'=>$value)); throw new Kohana_Exception('Values for variables should be an array, however :value was given',array(':value'=>$value));
case 'to':
$this->email_data[$key] = $value; $this->email_data[$key] = $value;
break; break;
@ -53,12 +59,44 @@ class EmailTemplate {
} }
} }
public function __get($key) {
switch ($key) {
case 'to':
if (empty($this->email_data[$key]))
return array();
elseif (isset($this->email_data[$key]['email']))
return $this->email_data[$key]['email'];
elseif (isset($this->email_data[$key]['account'])) {
$list = array();
foreach ($this->email_data[$key]['account'] as $id) {
$ao = ORM::factory('account',$id);
if ($ao->loaded())
$list[$ao->email] = $ao->name();
}
return $list;
}
break;
case 'variables':
return $this->email_data[$key];
default:
throw new Kohana_Exception('Unknown variable :key (:value)',array(':key'=>$key,':value'=>is_string($value) ? $value : serialize($value)));
}
}
public static function instance($template) { public static function instance($template) {
return new EmailTemplate($template); return new EmailTemplate($template);
} }
public function variables() { public function variables() {
$return = array(); $return = array();
foreach ($this->components as $v) foreach ($this->components as $v)
foreach ($this->template_mail->variables($v) as $x=>$y) foreach ($this->template_mail->variables($v) as $x=>$y)
if (! in_array($y,$return)) if (! in_array($y,$return))
@ -93,14 +131,46 @@ class EmailTemplate {
} }
} }
// @todo This should go to the admin defined in email_setup // @todo This should go to the admin defined in email_setup
if ($admin OR ($mail = Config::testmail($this->template->name))) if ($admin OR ($admin = Config::testmail($this->template->name))) {
$sm->setTo($mail); $sm->setTo($admin);
else $sa = array(1);
$sm->setTo($this->email_data['to']);
} else {
$sm->setTo($this->to);
$sa = $this->to_accounts();
}
// @todo - Setup queue mode // @todo - Setup queue mode
$e->send($sm); $result = $e->send($sm);
if ($result) {
// Store our email log.
$data = gzcompress(serialize($this->email_data['variables']));
$elo = ORM::factory('email_log');
foreach ($sa as $id) {
$elo->clear();
$elo->account_id = $id;
$elo->email_template_id = $this->template_mail->id;
$elo->data = $data;
$elo->save();
}
}
return $result;
}
private function to_accounts() {
// @todo Set the default account in a configuration file.
$default = array(1);
if (! isset($this->email_data['to']) OR ! is_array($this->email_data['to']) OR ! array_intersect(array('email','account'),array_keys($this->email_data['to'])))
return $default;
return isset($this->email_data['to']['account']) ? $this->email_data['to']['account'] : $default;
} }
} }
?> ?>

View File

@ -13,19 +13,21 @@ class Model_EmailTemplate extends ORMOSB {
protected $_table_name = 'email_template'; protected $_table_name = 'email_template';
protected $_has_many = array( protected $_has_many = array(
'emailtemplate_translate'=>array('foreign_key'=>'email_template_id'), 'emailtemplate_translate'=>array('foreign_key'=>'email_template_id','far_key'=>'id'),
); );
// This module doesnt keep track of column updates automatically // This module doesnt keep track of column updates automatically
protected $_created_column = FALSE; protected $_created_column = FALSE;
protected $_updated_column = FALSE; protected $_updated_column = FALSE;
protected $_formats = array(
'active'=>array('StaticList_YesNo::display'=>array()),
);
protected $_sorting = array( protected $_sorting = array(
'name'=>'ASC', 'name'=>'ASC',
); );
protected $_display_filters = array(
'status'=>array(
array('StaticList_YesNo::display',array(':value')),
),
);
} }
?> ?>

View File

@ -12,3 +12,4 @@
*/ */
class Model_Export extends ORMOSB { class Model_Export extends ORMOSB {
} }
?>

View File

@ -33,3 +33,4 @@ abstract class OSBExport {
return array_values($this->_data); return array_values($this->_data);
} }
} }
?>

View File

@ -64,3 +64,4 @@ class Quicken extends OSBExport {
return $export; return $export;
} }
} }
?>

View File

@ -24,3 +24,4 @@ class Quicken_Invoice extends Quicken {
array_push($this->_payments,$item); array_push($this->_payments,$item);
} }
} }
?>

View File

@ -12,3 +12,4 @@
*/ */
class Quicken_InvoiceItem extends Quicken { class Quicken_InvoiceItem extends Quicken {
} }
?>

View File

@ -15,3 +15,4 @@ class Quicken_Payment extends Quicken {
'TRNSTYPE'=>'PAYMENT' 'TRNSTYPE'=>'PAYMENT'
); );
} }
?>

View File

@ -102,3 +102,4 @@ class Controller_HostServer extends Controller {
print_r(array('s'=>(string)$result,'r'=>(string)$result)); print_r(array('s'=>(string)$result,'r'=>(string)$result));
} }
} }
?>

View 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);
}
}
?>

View File

@ -324,5 +324,37 @@ class Model_Invoice extends ORMOSB {
$this->_changed[$field] = $field; $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,'>');
}
} }
?> ?>

View File

@ -2465,17 +2465,17 @@ AND (
$this->setRecordAttr('account_id',$so->getRecordAttr('account_id')); $this->setRecordAttr('account_id',$so->getRecordAttr('account_id'));
$this->setRecordAttr('account_billing_id',$so->getRecordAttr('account_billing_id')); $this->setRecordAttr('account_billing_id',$so->getRecordAttr('account_billing_id'));
$this->setRecordAttr('billed_currency_id',$ao->getRecordAttr('currency_id')); $this->setRecordAttr('billed_currency_id',$ao->getRecordAttr('currency_id'));
$this->setRecordAttr('actual_billed_currency_id',DEFAULT_CURRENCY); // $this->setRecordAttr('actual_billed_currency_id',DEFAULT_CURRENCY);
$this->setRecordAttr('reseller_id',$ao->getRecordAttr('reseller_id')); $this->setRecordAttr('reseller_id',$ao->getRecordAttr('reseller_id'));
$this->setRecordAttr('checkout_plugin_id',$ao->getRecordAttr('checkout_plugin_id')); $this->setRecordAttr('checkout_plugin_id',$ao->getRecordAttr('checkout_plugin_id'));
$this->setRecordAttr('checkout_plugin_data',$ao->getRecordAttr('checkout_plugin_data')); // $this->setRecordAttr('checkout_plugin_data',$ao->getRecordAttr('checkout_plugin_data'));
$this->setRecordAttr('grace_period',$ao->getRecordAttr('invoice_grace')); // $this->setRecordAttr('grace_period',$ao->getRecordAttr('invoice_grace'));
# @todo this may unintentially allocate all service revenue to an affiliate, which should be configurable (not just the service that the account signed up for initially) # @todo this may unintentially allocate all service revenue to an affiliate, which should be configurable (not just the service that the account signed up for initially)
$this->setRecordAttr('affiliate_id',$ao->getRecordAttr('affiliate_id')); // $this->setRecordAttr('affiliate_id',$ao->getRecordAttr('affiliate_id'));
# @todo the parent invoice should bring this campaign id. # @todo the parent invoice should bring this campaign id.
$this->setRecordAttr('campaign_id',null); // $this->setRecordAttr('campaign_id',null);
} }
$this->setRecordAttr('due_date',$so->getRecordAttr('date_next_invoice')); $this->setRecordAttr('due_date',$so->getRecordAttr('date_next_invoice'));
@ -2519,7 +2519,7 @@ AND (
$last_invoice = $x; $last_invoice = $x;
} }
array_push($invoice['recur_schedules'],$so->getRecordAttr('recur_schedule')); // array_push($invoice['recur_schedules'],$so->getRecordAttr('recur_schedule'));
# Update the last & next invoice date for this service # Update the last & next invoice date for this service
$rs = $db->Execute(sqlUpdate($db,'service', $rs = $db->Execute(sqlUpdate($db,'service',
@ -2616,17 +2616,17 @@ AND (
else else
$grace_period = GRACE_PERIOD; $grace_period = GRACE_PERIOD;
$this->setRecordAttr('notice_next_date',time()); // $this->setRecordAttr('notice_next_date',time());
$this->setRecordAttr('billing_status',0); $this->setRecordAttr('billing_status',0);
$this->setRecordAttr('print_status',0); $this->setRecordAttr('print_status',0);
$this->setRecordAttr('process_status',0); $this->setRecordAttr('process_status',0);
$this->setRecordAttr('status',1); $this->setRecordAttr('status',1);
// $this->setRecordAttr('suspend_billing',0); // $this->setRecordAttr('suspend_billing',0);
$this->setRecordAttr('billed_amt',0); $this->setRecordAttr('billed_amt',0);
$this->setRecordAttr('actual_billed_amt',0); // $this->setRecordAttr('actual_billed_amt',0);
$this->setRecordAttr('notice_count',0); // $this->setRecordAttr('notice_count',0);
$this->setRecordAttr('type',1); // $this->setRecordAttr('type',1);
$this->setRecordAttr('notice_max',MAX_BILLING_NOTICE); // $this->setRecordAttr('notice_max',MAX_BILLING_NOTICE);
$rs = $this->sql_SaveRecord(true); $rs = $this->sql_SaveRecord(true);
if (! $rs) { if (! $rs) {
@ -2761,10 +2761,10 @@ AND (
'total_amt' => $total, 'total_amt' => $total,
'billed_amt' => 0, 'billed_amt' => 0,
'billed_currency_id'=> DEFAULT_CURRENCY, 'billed_currency_id'=> DEFAULT_CURRENCY,
'actual_billed_amt' => 0, // 'actual_billed_amt' => 0,
'actual_billed_currency_id' => @$invoice['actual_billed_currency_id'], // 'actual_billed_currency_id' => @$invoice['actual_billed_currency_id'],
'notice_count' => 0, 'notice_count' => 0,
'notice_next_date' => time(), // 'notice_next_date' => time(),
'notice_max' => MAX_BILLING_NOTICE, 'notice_max' => MAX_BILLING_NOTICE,
'grace_period' => 0, 'grace_period' => 0,
'due_date' => $due_date 'due_date' => $due_date
@ -3402,7 +3402,7 @@ AND (
$sInvoicesBal = array(); $sInvoicesBal = array();
$db = &DB(); $db = &DB();
$rs = $db->Execute(sqlSelect('invoice','date_orig,account_id,id,total_amt,billed_amt,IFNULL(credit_amt,0) as credit_amt,ROUND(total_amt-billed_amt-IFNULL(credit_amt,0),2) as balance', $rs = $db->Execute(sqlSelect('invoice','date_orig,account_id,id,total_amt,billed_amt,IFNULL(credit_amt,0) as credit_amt,ROUND(total_amt-billed_amt-IFNULL(credit_amt,0),2) as balance',
array('where'=>'(refund_status=0 OR refund_status IS NULL) AND status=1 AND total_amt-billed_amt-IFNULL(credit_amt,0)!=0','orderby'=>'account_id,date_orig,id'))); array('where'=>'status=1 AND total_amt-billed_amt-IFNULL(credit_amt,0)!=0','orderby'=>'account_id,date_orig,id')));
if ($rs && $rs->RecordCount()) { if ($rs && $rs->RecordCount()) {
while (! $rs->EOF) { while (! $rs->EOF) {
$invoice = array(); $invoice = array();

View File

@ -19,19 +19,13 @@
<index> <index>
<orig>date_orig</orig> <orig>date_orig</orig>
<last>date_last</last> <last>date_last</last>
<parent>parent_id</parent>
<billing>billing_status</billing> <billing>billing_status</billing>
<process>process_status</process> <process>process_status</process>
<suspend>suspend_billing</suspend>
<refund>refund_status</refund>
<account>account_id</account> <account>account_id</account>
<affiliate>affiliate_id</affiliate>
<campaign>campaign_id</campaign>
<reseller>reseller_id</reseller> <reseller>reseller_id</reseller>
<amount>total_amt</amount> <amount>total_amt</amount>
<due_date>due_date</due_date> <due_date>due_date</due_date>
<checkout>checkout_plugin_id</checkout> <checkout>checkout_plugin_id</checkout>
<tax>tax_id</tax>
<net_term>net_term_id</net_term> <net_term>net_term_id</net_term>
</index> </index>
@ -66,16 +60,6 @@
<display>Active</display> <display>Active</display>
<type>L</type> <type>L</type>
</status> </status>
<!-- @todo UNKNOWN - used when recurring payments come in, they must be linked to an invoice number -->
<!-- DELETED
<parent_id>
<type>I4</type>
</parent_id>
-->
<!-- NULL = IMPORTED INVOICE, 0=UNUSED, 2 = CHECKOUT INVOICE,1 = REOCURRING INVOICE -->
<type>
<type>L</type>
</type>
<!-- Invoice Approved: 1=YES, 0=UNUSED, NULL = NO (Approved invoices can have services provisioned) --> <!-- Invoice Approved: 1=YES, 0=UNUSED, NULL = NO (Approved invoices can have services provisioned) -->
<process_status> <process_status>
<type>L</type> <type>L</type>
@ -85,17 +69,6 @@
<display>Invoice Status</display> <display>Invoice Status</display>
<type>L</type> <type>L</type>
</billing_status> </billing_status>
<!-- Invoice has been refunded when STATUS = 1 -->
<refund_status>
<display>Refund Status</display>
<type>L</type>
</refund_status>
<!-- Suspend billing of reocurring invoices, where this invoice is the 1st/parent invoice -->
<!-- DELETED
<suspend_billing>
<type>L</type>
</suspend_billing>
-->
<!-- 1 = Has this invoice been printed --> <!-- 1 = Has this invoice been printed -->
<print_status> <print_status>
<type>L</type> <type>L</type>
@ -115,16 +88,6 @@
<affiliate_id> <affiliate_id>
<type>C(32)</type> <type>C(32)</type>
</affiliate_id> </affiliate_id>
<!-- The compaign that resulted in this revenue -->
<campaign_id>
<type>I4</type>
</campaign_id>
<!-- @todo UNKNOWN -->
<!-- DELETED
<custom_affiliate_status>
<type>L</type>
</custom_affiliate_status>
-->
<!-- The reseller who should be credited for this invoice revenue --> <!-- The reseller who should be credited for this invoice revenue -->
<reseller_id> <reseller_id>
<type>C(32)</type> <type>C(32)</type>
@ -138,13 +101,6 @@
<type>C(255)</type> <type>C(255)</type>
<convert>array</convert> <convert>array</convert>
</checkout_plugin_data> </checkout_plugin_data>
<!-- The TAX id applicable for this invoice -->
<!-- DELETED
<tax_id>
<display>Taxes</display>
<type>I4</type>
</tax_id>
-->
<!-- The amount of TAX this invoice includes --> <!-- The amount of TAX this invoice includes -->
<tax_amt> <tax_amt>
<display>Total Taxes</display> <display>Total Taxes</display>
@ -155,24 +111,11 @@
<display>Total Credits</display> <display>Total Credits</display>
<type>F</type> <type>F</type>
</credit_amt> </credit_amt>
<!-- @todo - ? The discounts that were applied to this invoice -->
<!-- DELETED
<discount_arr>
<type>C(255)</type>
<convert>array</convert>
</discount_arr>
-->
<!-- The amount of DISCOUNT this invoice includes --> <!-- The amount of DISCOUNT this invoice includes -->
<discount_amt> <discount_amt>
<display>Total Discounts</display> <display>Total Discounts</display>
<type>F</type> <type>F</type>
</discount_amt> </discount_amt>
<!-- @todo?? The amount of re-ocurring items on this invoice -->
<!-- DELETED
<recur_amt>
<type>F</type>
</recur_amt>
-->
<!-- Invoice Total Charges (including taxes ??) --> <!-- Invoice Total Charges (including taxes ??) -->
<total_amt> <total_amt>
<display>Amount</display> <display>Amount</display>
@ -195,34 +138,12 @@
<actual_billed_currency_id> <actual_billed_currency_id>
<type>I4</type> <type>I4</type>
</actual_billed_currency_id> </actual_billed_currency_id>
<!-- @todo ?? -->
<notice_count>
<type>I4</type>
</notice_count>
<!-- @todo ?? -->
<notice_max>
<type>I4</type>
</notice_max>
<!-- @todo ?? -->
<notice_next_date>
<type>I8</type>
<convert>date-time</convert>
</notice_next_date>
<!-- @todo ?? -->
<grace_period>
<type>I4</type>
</grace_period>
<!-- The date this invoice is due --> <!-- The date this invoice is due -->
<due_date> <due_date>
<display>Date Due</display> <display>Date Due</display>
<type>I8</type> <type>I8</type>
<convert>date-time</convert> <convert>date-time</convert>
</due_date> </due_date>
<!-- @todo ?? -->
<!-- DELETED
<recur_arr>
<type>X</type>
</recur_arr> -->
<!-- Admin notes attached to the invoice --> <!-- Admin notes attached to the invoice -->
<notes> <notes>
<type>X</type> <type>X</type>
@ -231,33 +152,20 @@
<net_term_id> <net_term_id>
<type>L</type> <type>L</type>
</net_term_id> </net_term_id>
<!-- @todo ?? -->
<net_term_date_last>
<type>I8</type>
</net_term_date_last>
<!-- @todo ?? -->
<net_term_intervals>
<type>I4</type>
</net_term_intervals>
<!-- @todo ?? -->
<!-- DELETED
<ip>
<type>C(32)</type>
</ip> -->
</field> </field>
<!-- Methods for this class, and the fields they have access to, if applicable --> <!-- Methods for this class, and the fields they have access to, if applicable -->
<method> <method>
<add>id,type,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,checkout_plugin_data,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,status</add> <add>id,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,status</add>
<update>id,date_last,type,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,checkout_plugin_data,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</update> <update>id,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</update>
<delete>id</delete> <delete>id</delete>
<view>id,date_orig,date_last,type,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,checkout_plugin_data,tax_amt,discount_amt,total_amt,billed_amt,credit_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</view> <view>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,credit_amt,billed_currency_id,due_date,net_term_id</view>
<search>id,date_orig,date_last,type,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,checkout_plugin_data,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</search> <search>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</search>
<export_excel>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</export_excel> <export_excel>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</export_excel>
<export_pdf>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</export_pdf> <export_pdf>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</export_pdf>
<export_xml>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</export_xml> <export_xml>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</export_xml>
<export_csv>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</export_csv> <export_csv>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</export_csv>
<export_tab>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,affiliate_id,campaign_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,actual_billed_amt,actual_billed_currency_id,notice_count,notice_max,notice_next_date,grace_period,due_date,net_term_date_last,net_term_id,net_term_intervals</export_tab> <export_tab>id,date_orig,date_last,process_status,billing_status,print_status,account_id,account_billing_id,reseller_id,checkout_plugin_id,tax_amt,discount_amt,total_amt,billed_amt,billed_currency_id,due_date,net_term_id</export_tab>
</method> </method>
<!-- Method triggers --> <!-- Method triggers -->

View File

@ -0,0 +1,6 @@
<tr>
<td><?php echo $io->account->name(); ?></td>
<td><?php echo $io->display('due_date'); ?></td>
<td><?php echo $io->id(); ?></td>
<td><?php echo $io->due(TRUE); ?></td>
</tr>

View File

@ -0,0 +1 @@
</table>

View File

@ -0,0 +1,7 @@
<table>
<tr>
<td>Account</td>
<td>Due Date</td>
<td>Inv ID</td>
<td>Amount Due</td>
</tr>

View File

@ -14,10 +14,8 @@
<limit>25</limit> <limit>25</limit>
<!-- define database indexes --> <!-- define database indexes -->
<index> <index>
<parent>parent_id</parent>
<invoice>invoice_id,site_id</invoice> <invoice>invoice_id,site_id</invoice>
<product>product_id</product> <product>product_id</product>
<accountid>account_id</accountid>
<serviceid>service_id,site_id</serviceid> <serviceid>service_id,site_id</serviceid>
<invserviceid>service_id,invoice_id</invserviceid> <invserviceid>service_id,invoice_id</invserviceid>
<sku>sku</sku> <sku>sku</sku>
@ -39,16 +37,6 @@
<date_orig> <date_orig>
<type>I8</type> <type>I8</type>
</date_orig> </date_orig>
<!-- DELETED
<parent_id>
<type>I8</type>
</parent_id>
-->
<!-- DELETED
<account_id>
<type>I8</type>
</account_id>
-->
<!-- If service_id is NULL, it is either a 1 time charge, or a new service not yet provisioned, details should be in product_attr_cart --> <!-- If service_id is NULL, it is either a 1 time charge, or a new service not yet provisioned, details should be in product_attr_cart -->
<service_id> <service_id>
<type>I8</type> <type>I8</type>
@ -131,10 +119,10 @@
<!-- define all the methods for this class, and the fields they have access to, if applicable. --> <!-- define all the methods for this class, and the fields they have access to, if applicable. -->
<method> <method>
<add>account_id,invoice_id,product_id,product_name,service_id,charge_id,quantity,item_type,product_attr,product_attr_cart,price_type,price_base,price_setup,total_amt,discount_amt,tax_amt,recurring_schedule,domain_name,domain_tld,domain_term,domain_type,date_start,date_stop</add> <add>account_id,invoice_id,product_id,product_name,service_id,charge_id,quantity,item_type,product_attr,product_attr_cart,price_type,price_base,price_setup,total_amt,discount_amt,tax_amt,recurring_schedule,domain_name,domain_tld,domain_term,domain_type,date_start,date_stop</add>
<update>date_orig,invoice_id,product_id,sku,quantity,item_type,product_attr,product_attr_cart,price_base,price_setup,recurring_schedule,domain_name,domain_tld,domain_term,domain_type,invoice_item_parent_id</update> <update>date_orig,invoice_id,product_id,sku,quantity,item_type,product_attr,product_attr_cart,price_base,price_setup,recurring_schedule,domain_name,domain_tld,domain_term,domain_type</update>
<delete>id,site_id,date_orig,invoice_id,product_id,sku,quantity,item_type,product_attr,product_attr_cart,price_base,price_setup,recurring_schedule,domain_name,domain_tld,domain_term,domain_type,invoice_item_parent_id</delete> <delete>id,site_id,date_orig,invoice_id,product_id,sku,quantity,item_type,product_attr,product_attr_cart,price_base,price_setup,recurring_schedule,domain_name,domain_tld,domain_term,domain_type</delete>
<view>id,site_id,date_orig,invoice_id,product_id,sku,quantity,item_type,product_attr,product_attr_cart,price_base,price_setup,recurring_schedule,domain_name,domain_tld,domain_term,domain_type,invoice_item_parent_id</view> <view>id,site_id,date_orig,invoice_id,product_id,sku,quantity,item_type,product_attr,product_attr_cart,price_base,price_setup,recurring_schedule,domain_name,domain_tld,domain_term,domain_type</view>
<search>id,site_id,date_orig,invoice_id,product_id,sku,quantity,item_type,product_attr,product_attr_cart,price_base,price_setup,recurring_schedule,domain_name,domain_tld,domain_term,domain_type,invoice_item_parent_id</search> <search>id,site_id,date_orig,invoice_id,product_id,quantity,item_type,price_base,price_setup</search>
</method> </method>
<!-- define the method triggers --> <!-- define the method triggers -->
<trigger>0</trigger> <trigger>0</trigger>

View File

@ -26,8 +26,10 @@ class Model_Module_Method extends ORMOSB {
'name'=>'ASC', 'name'=>'ASC',
); );
protected $_formats = array( protected $_display_filters = array(
'menu_display'=>array('StaticList_YesNo::display'=>array()), 'menu_display'=>array(
array('StaticList_YesNo::display',array(':value')),
),
); );
// This module doesnt keep track of column updates automatically // This module doesnt keep track of column updates automatically

View File

@ -72,4 +72,21 @@ class Model_Payment extends ORMOSB {
public function invoicelist() { public function invoicelist() {
return join(',',$this->invoices()); return join(',',$this->invoices());
} }
/** LIST FUNCTIONS **/
public function list_unapplied() {
$pi = array();
// @todo database suffix needs to be dynamically calculated
foreach (DB::Query(Database::SELECT,
sprintf('SELECT A.id AS id,A.total_amt as total_amt FROM ab_%s A,ab_%s B WHERE A.site_id=B.site_id AND A.id=B.payment_id GROUP BY B.payment_id HAVING ROUND(SUM(B.alloc_amt),2)!=A.total_amt ORDER BY account_id,payment_id','payment','payment_item'))
->execute() as $values) {
array_push($pi,$values['id']);
} }
return $this->where('id','IN',$pi)->order_by('account_id')->find_all();
}
}
?>

View File

@ -13,3 +13,4 @@
class Model_Payment_Item extends ORMOSB { class Model_Payment_Item extends ORMOSB {
protected $_belongs_to = array('payment'=>array(),'invoice'=>array()); protected $_belongs_to = array('payment'=>array(),'invoice'=>array());
} }
?>

View File

@ -21,8 +21,10 @@ class Model_Product extends ORMOSB {
'sku'=>'asc', 'sku'=>'asc',
); );
protected $_display_format = array( protected $_display_filters = array(
'price_type'=>array('StaticList_PriceType::display'=>array()), 'price_type'=>array(
array('StaticList_PriceType::display',array(':value')),
),
); );
/** /**
@ -43,7 +45,7 @@ class Model_Product extends ORMOSB {
/** /**
* Return the object of the product plugin * Return the object of the product plugin
*/ */
private function plugin() { public function plugin() {
if (! $this->prod_plugin_file) if (! $this->prod_plugin_file)
return NULL; return NULL;

View File

@ -10,11 +10,11 @@
* @copyright (c) 2010 Open Source Billing * @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class Controller_Task_Service extends Controller_Template { class Controller_Task_Service extends Controller_Task {
private function _traffic_suppliers($active=FALSE) { private function _traffic_suppliers($active=FALSE) {
$suppliers = ORM::factory('adsl_supplier'); $suppliers = ORM::factory('adsl_supplier');
return $active ? $suppliers->active() : $suppliers->find_all(); return $active ? $suppliers->list_active() : $suppliers->find_all();
} }
/** /**

View File

@ -338,7 +338,7 @@ class Model_Service_ADSL extends Model_Service {
} }
protected function _service_view() { protected function _service_view() {
return View::factory($this->viewpath(strtolower($this->service->prod_plugin_name))) return View::factory('service/user/adsl/view')
->set('so',$this); ->set('so',$this);
} }

View File

@ -61,3 +61,4 @@ class Controller_StaticPage_Category extends Controller_TemplateDefault {
->find_all(); ->find_all();
} }
} }
?>

View File

@ -25,3 +25,4 @@ class Model_StaticPage extends ORMOSB {
'staticpage_category'=>array('foreign_key'=>'static_page_category_id'), 'staticpage_category'=>array('foreign_key'=>'static_page_category_id'),
); );
} }
?>

View File

@ -17,3 +17,4 @@ class Model_StaticPage_Category extends ORMOSB {
'name'=>'asc', 'name'=>'asc',
); );
} }
?>

View File

@ -17,3 +17,4 @@ class Model_StaticPage_Translate extends ORMOSB {
'staticpage'=>array('foreign_key'=>'id'), 'staticpage'=>array('foreign_key'=>'id'),
); );
} }
?>

View File

@ -0,0 +1,59 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides OSB task running capabilities.
*
* @package OSB
* @subpackage Task
* @category Controllers/Admin
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Task_Task extends Controller_Task {
/**
* List all tasks
*/
public function action_list() {
$output = '';
$to = ORM::factory('task');
$tm = 'list_'.$this->request->param('id');
if (! method_exists($to,$tm))
throw new Kohana_Exception('Unknown Task List command :command',array(':command'=>$mode));
$output .= sprintf('%2s %30s %21s %21s %40s',
'ID','Command','Last Run','Next Run','Description');
$output .= "\n";
foreach ($to->$tm() as $t) {
$output .= sprintf('%2s %30s %21s %21s %40s',
$t['task']->id,
$t['task']->command,
$t['task']->display('date_run'),
Config::datetime($t['next']),
$t['task']->display('description')
);
$output .= "\n";
};
$this->response->body($output);
}
public function action_run() {
if ($id = $this->request->param('id')) {
$to = ORM::factory('task',$id);
$to->run();
} else {
$tlo = ORM::factory('task');
$t = time();
foreach ($tlo->list_active() as $to)
if ($to['next'] < $t)
$to['task']->run();
}
}
}
?>

View File

@ -0,0 +1,107 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Tasks
*
* @package OSB
* @subpackage Task
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Task extends ORMOSB {
protected $_display_filters = array(
'date_run'=>array(
array('Config::datetime',array(':value')),
),
);
public function run() {
$r = rand(0,9999);
$tlo = ORM::factory('task_log');
$tlo->task_id = $this->id;
if (! $this->loaded())
$tlo->message = sprintf('Unknown Task ID %s',$this->id);
elseif (! $this->status)
$tlo->message = sprintf('Task %s is not active',$this->id);
elseif ($this->running)
$tlo->message = sprintf('Task %s is already running',$this->id);
elseif (! preg_match('/\//',$this->command))
$tlo->message = sprintf('Task %s uses the old configuration, ignoring :command',$this->id,$this->command);
else {
try {
// Get a lock
$this->running = 1;
$this->running_host = $r;
$this->save();
// Check we are the winning host to run this task
$this->reload();
if ($this->running_host != $r)
return;
switch ($this->type) {
case 0:
$r = Request::factory($this->command)->execute();
break;
default:
throw new Kohana_Exception('Unknown task type :type',array(':type'=>$this->type));
}
// Clear our lock and update the last run time
$this->date_run = time();
$this->running = 0;
$this->running_host = NULL;
$this->save();
$tlo->result = 0;
$tlo->message = $r->body();
}
catch (Exception $e) {
$tlo->result = $e->getCode();
$tlo->message = $e->getMessage();
}
}
if ($this->log)
$tlo->save();
}
/** LIST FUNCTIONS **/
private function _list_active() {
return $this->where('status','=',1)->find_all();
}
public function list_active() {
$return = array();
foreach ($this->_list_active() as $to) {
$ct = sprintf('%s %s %s %s %s',$to->int_min,$to->int_hour,$to->int_month_day,$to->int_month,$to->int_week_day);
$c = new Cron($ct,$to->command);
$return[$to->id]['task'] = $to;
$return[$to->id]['next'] = $c->next($to->date_run);
}
return $return;
}
public function list_next() {
$return = array();
foreach ($this->list_active() as $v)
if ((! $return OR $v['next']<$return['next']) AND ! $v['task']->running)
$return = $v;
return array($return['task']->id=>$return);
}
}
?>

View File

@ -0,0 +1,20 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Task Logging
*
* @package OSB
* @subpackage Task
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Task_Log extends ORMOSB {
protected $_display_filters = array(
'date_orig'=>array(
array('Config::datetime',array(':value')),
),
);
}
?>

View File

@ -57,8 +57,8 @@ class task extends OSB_module {
printf("%s: Selecting Job [%s] (%s)\n",__METHOD__,$result['command'],$this->id); printf("%s: Selecting Job [%s] (%s)\n",__METHOD__,$result['command'],$this->id);
$task = array(); $task = array();
$task['start'] = (int)$result['date_start']; $task['start'] = 0;
$task['end'] = (int)$result['date_expire']; $task['end'] = 0;
$task['lastrun'] = (int)$result['date_run']; $task['lastrun'] = (int)$result['date_run'];
$task['cron'] = sprintf('%s %s %s %s %s', $task['cron'] = sprintf('%s %s %s %s %s',
$result['int_min'], $result['int_min'],