Consistent use of return , payment refund handling

This commit is contained in:
Deon George 2013-04-05 23:50:08 +11:00
parent 43dfd88bce
commit 52d9005b64
30 changed files with 255 additions and 210 deletions

View File

@ -105,9 +105,9 @@ class Config extends Kohana_Config {
* security).
*/
public static function modules() {
static $return = array();
static $result = array();
if (! count($return)) {
if (! count($result)) {
// We need to know our site here, so that we can subsequently load our enabled modules.
if (PHP_SAPI === 'cli') {
if (! $site = Minion_CLI::options('site'))
@ -118,10 +118,10 @@ class Config extends Kohana_Config {
}
foreach (ORM::factory('Module')->list_external() as $mo)
$return[$mo->name] = MODPATH.$mo->name;
$result[$mo->name] = MODPATH.$mo->name;
}
return $return;
return $result;
}
public static function module_config($item) {

View File

@ -21,14 +21,14 @@ class Controller_Reseller_Account extends Controller_Account {
* @note list_autocomplete() will limit to authorised accounts
*/
public function action_ajaxlist() {
$return = array();
$result = array();
if (isset($_REQUEST['term']) AND trim($_REQUEST['term']))
$return += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
$result += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
$this->auto_render = FALSE;
$this->response->headers('Content-Type','application/json');
$this->response->body(json_encode(array_values($return)));
$this->response->body(json_encode(array_values($result)));
}
/**

View File

@ -68,13 +68,13 @@ class Model_Account extends Model_Auth_UserDefault {
* @param int Date (in secs) to only retrieve invoices prior to this date
*/
public function invoices_due($date=NULL) {
$return = array();
$result = array();
foreach ($this->invoices() as $io)
if ((is_null($date) OR $io->date_orig < $date) AND $io->due())
$return[$io->id] = $io;
$result[$io->id] = $io;
return $return;
return $result;
}
/**
@ -139,7 +139,7 @@ class Model_Account extends Model_Auth_UserDefault {
* Search for accounts matching a term
*/
public function list_autocomplete($term,$index='id',array $limit=array()) {
$return = array();
$result = array();
$ao = Auth::instance()->get_user();
$this->clear();
@ -183,12 +183,12 @@ class Model_Account extends Model_Auth_UserDefault {
$this->and_where('id','IN',$ao->RTM->customers($ao->RTM));
foreach ($this->find_all() as $o)
$return[$o->$index] = array(
$result[$o->$index] = array(
'value'=>$o->$index,
'label'=>sprintf('ACC %s: %s',$o->id,Table::resolve($o,$value)),
);
return $return;
return $result;
}
}
?>

View File

@ -42,21 +42,21 @@ class Model_Group extends Model_Auth_RoleDefault {
* are also related to this group, in the group heirarchy.
*/
public function list_childgrps($incParent=FALSE) {
$return = array();
$result = array();
if (! $this->loaded())
return $return;
return $result;
foreach (ORM::factory('Group')->where_active()->and_where('parent_id','=',$this)->find_all() as $go) {
array_push($return,$go);
array_push($result,$go);
$return = array_merge($return,$go->list_childgrps());
$result = array_merge($result,$go->list_childgrps());
}
if ($incParent)
array_push($return,$this);
array_push($result,$this);
return $return;
return $result;
}
/**
@ -64,21 +64,21 @@ class Model_Group extends Model_Auth_RoleDefault {
* are also related to this group, in the group heirarchy.
*/
public function list_parentgrps($incParent=FALSE) {
$return = array();
$result = array();
if (! $this->loaded())
return $return;
return $result;
foreach (ORM::factory('Group')->where_active()->and_where('id','=',$this->parent_id)->find_all() as $go) {
array_push($return,$go);
array_push($result,$go);
$return = array_merge($return,$go->list_parentgrps());
$result = array_merge($result,$go->list_parentgrps());
}
if ($incParent)
array_push($return,$this);
array_push($result,$this);
return $return;
return $result;
}
}
?>

View File

@ -20,15 +20,15 @@ class Model_RTM extends ORM_OSB {
);
public function customers(Model_RTM $rtmo) {
$return = array();
$result = array();
foreach ($rtmo->agents_direct() as $artmo)
$return = $return+$rtmo->customers($artmo);
$result = $result+$rtmo->customers($artmo);
foreach ($rtmo->customers_direct() as $ao)
array_push($return,$ao);
array_push($result,$ao);
return $return;
return $result;
}
public function agents_direct() {

View File

@ -106,7 +106,7 @@ class Period {
// Change our end date to the day before
$period_end -= 86400;
$return = array(
$result = array(
'start'=>$period_start,
'start_time'=>$start,
'date'=>$start,
@ -121,9 +121,9 @@ class Period {
if ($df)
foreach (array('start','date','end') as $key)
$return[$key] = Config::date($return[$key]);
$result[$key] = Config::date($result[$key]);
return $return;
return $result;
}
}
?>

View File

@ -123,12 +123,12 @@ class ADSL {
}
// Return the output sorted
$return = array();
$result = array();
foreach (array('base_down_peak','base_down_offpeak','base_up_peak','base_up_offpeak') as $k)
if (isset($a[$k]))
$return[$k] = $a[$k];
$result[$k] = $a[$k];
return $return;
return $result;
}
}
?>

View File

@ -33,13 +33,13 @@ class Model_Adsl_Supplier extends ORM_OSB {
* Return a list of plans that we provide by this supplier
*/
public function adsl_plans($active=TRUE) {
$return = array();
$result = array();
foreach ($this->plans($active)->find_all() as $po)
foreach ($po->adsl_plan->find_all() as $apo)
$return[$apo->id] = $apo;
$result[$apo->id] = $apo;
return $return;
return $result;
}
/**

View File

@ -111,23 +111,23 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
* Calculate the total traffic used in a month
*/
private function get_traffic_data_month($period=NULL,$cache=NULL) {
$return = array();
$result = array();
foreach ($this->get_traffic_data_daily($period,TRUE,$cache) as $tdata)
foreach ($tdata as $k => $v)
if (isset($return[$k]))
$return[$k] += $v;
if (isset($result[$k]))
$result[$k] += $v;
else
$return[$k] = $v;
$result[$k] = $v;
return $return;
return $result;
}
/**
* Return an array of the data used in a month by day
*/
public function get_traffic_data_daily($period=NULL,$bydate=FALSE,$cache=NULL) {
$return = array();
$result = array();
// @temp - caching is broken?
$cache=0;
@ -144,20 +144,20 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
$day = date('d',strtotime($to->date));
if ($bydate)
$return[$day] = $to->traffic($this->service->product->plugin());
$result[$day] = $to->traffic($this->service->product->plugin());
else
foreach ($to->traffic($this->service->product->plugin()) as $k => $v)
$return[$k][$day] = $v;
$result[$k][$day] = $v;
}
return $return;
return $result;
}
/**
* Return an array of the data used in a year by month
*/
public function get_traffic_data_monthly($period=NULL,$bydate=FALSE) {
$return = array();
$result = array();
if (is_null($period))
$period = strtotime('yesterday');
@ -177,12 +177,12 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
foreach ($t->find_all() as $to)
if ($bydate)
$return[$to->month] = $to->traffic($this->service->product->plugin());
$result[$to->month] = $to->traffic($this->service->product->plugin());
else
foreach ($to->traffic($this->service->product->plugin()) as $k => $v)
$return[$k][$to->month] = $v;
$result[$k][$to->month] = $v;
return $return;
return $result;
}
public function traffic_month($month,$string=TRUE,$cache=NULL) {
@ -200,7 +200,7 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
}
public function traffic_lastmonth_exceed($all=FALSE,$date=NULL) {
$return = array();
$result = array();
if (is_null($date))
$date = strtotime('last month')-86400;
@ -208,16 +208,16 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
foreach ($this->traffic_month($date,FALSE,0) as $k => $v) {
// We shouldnt need to eval for nulls, since the traffic calc does that
if ($all OR ($v > $this->service->product->plugin()->$k)) {
$return[$k]['allowance'] = $this->service->product->plugin()->$k;
$return[$k]['used'] = $v;
$return[$k]['shaped'] = (! empty($this->service->product->plugin()->extra_shaped) AND $this->service->product->plugin()->extra_shaped AND $v > $this->service->product->plugin()->$k) ? TRUE : FALSE;
$return[$k]['excess'] = (! empty($this->service->product->plugin()->extra_charged) AND $this->service->product->plugin()->extra_charged AND $v > $this->service->product->plugin()->$k) ? $v-$this->service->product->plugin()->$k : 0;
$return[$k]['rate'] = $this->service->product->plugin()->{ADSL::map($k)};
$return[$k]['charge'] = ceil(($return[$k]['excess'])/1000)*$return[$k]['rate'];
$result[$k]['allowance'] = $this->service->product->plugin()->$k;
$result[$k]['used'] = $v;
$result[$k]['shaped'] = (! empty($this->service->product->plugin()->extra_shaped) AND $this->service->product->plugin()->extra_shaped AND $v > $this->service->product->plugin()->$k) ? TRUE : FALSE;
$result[$k]['excess'] = (! empty($this->service->product->plugin()->extra_charged) AND $this->service->product->plugin()->extra_charged AND $v > $this->service->product->plugin()->$k) ? $v-$this->service->product->plugin()->$k : 0;
$result[$k]['rate'] = $this->service->product->plugin()->{ADSL::map($k)};
$result[$k]['charge'] = ceil(($result[$k]['excess'])/1000)*$result[$k]['rate'];
}
}
return $return;
return $result;
}
public function template_variables($array) {
@ -228,7 +228,7 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
'cumulative_base_down_offpeak'=>'Total OffPeak',
);
$return = array();
$result = array();
if ($this->service->product->prod_plugin_file != 'ADSL')
throw new Kohana_Exception('Huh? How did this get called, for a non ADSL product (:ppf)',array(':ppf'=>$this->service_id));
@ -280,10 +280,10 @@ class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
$value = '';
}
$return[$item] = $value;
$result[$item] = $value;
}
return $return;
return $result;
}
/**

View File

@ -17,7 +17,7 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl {
private $login_pass_field = 'password';
private $date_field = 'date';
static $return = array();
static $result = array();
/**
* Get the data for Exetel hspa services
@ -29,8 +29,8 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl {
$this->fetchresult = TRUE;
// If we have already collected the date data, return it.
if (! empty(Service_Traffic_Adsl_Exetelhspa::$return[$date]))
return Service_Traffic_Adsl_Exetelhspa::$return[$date];
if (! empty(Service_Traffic_Adsl_Exetelhspa::$result[$date]))
return Service_Traffic_Adsl_Exetelhspa::$result[$date];
include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php';
@ -173,14 +173,14 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl {
// Reformat the data into date order.
foreach ($update as $service => $sdata)
foreach ($sdata as $sdate => $details)
Service_Traffic_Adsl_Exetelhspa::$return[$sdate][$service] = $details;
Service_Traffic_Adsl_Exetelhspa::$result[$sdate][$service] = $details;
// If the date we want is empty, return an array
if (empty(Service_Traffic_Adsl_Exetelhspa::$return[$date]))
if (empty(Service_Traffic_Adsl_Exetelhspa::$result[$date]))
return array();
// Return the date we asked for
return Service_Traffic_Adsl_Exetelhspa::$return[$date];
return Service_Traffic_Adsl_Exetelhspa::$result[$date];
}
}
?>

View File

@ -17,7 +17,7 @@ class Service_Traffic_Adsl_Exetelpe extends Service_Traffic_Adsl {
private $login_pass_field = 'password';
private $date_field = 'date';
static $return = array();
static $result = array();
/**
* Get the data for Exetel PE services
@ -29,8 +29,8 @@ class Service_Traffic_Adsl_Exetelpe extends Service_Traffic_Adsl {
$this->fetchresult = TRUE;
// If we have already collected the date data, return it.
if (! empty(Service_Traffic_Adsl_Exetelpe::$return[$date]))
return Service_Traffic_Adsl_Exetelpe::$return[$date];
if (! empty(Service_Traffic_Adsl_Exetelpe::$result[$date]))
return Service_Traffic_Adsl_Exetelpe::$result[$date];
include_once 'includes/kohana/modules/simplehtmldom/classes/simple_html_dom.php';
@ -166,14 +166,14 @@ class Service_Traffic_Adsl_Exetelpe extends Service_Traffic_Adsl {
// Reformat the data into date order.
foreach ($update as $service => $sdata)
foreach ($sdata as $sdate => $details)
Service_Traffic_Adsl_Exetelpe::$return[$sdate][$service] = $details;
Service_Traffic_Adsl_Exetelpe::$result[$sdate][$service] = $details;
// If the date we want is empty, return an array
if (empty(Service_Traffic_Adsl_Exetelpe::$return[$date]))
if (empty(Service_Traffic_Adsl_Exetelpe::$result[$date]))
return array();
// Return the date we asked for
return Service_Traffic_Adsl_Exetelpe::$return[$date];
return Service_Traffic_Adsl_Exetelpe::$result[$date];
}
}
?>

View File

@ -15,7 +15,7 @@ class Service_Traffic_Adsl_Exetelvisp extends Service_Traffic_Adsl {
private $date_field = 'date';
protected function getdata($date) {
$return = array();
$result = array();
// Assume we have a bad fetch, unless otherwise specified.
$this->fetchresult = FALSE;
@ -58,10 +58,10 @@ class Service_Traffic_Adsl_Exetelvisp extends Service_Traffic_Adsl {
$attrs['up_offpeak'] = $valuesarray[4]/100;
$attrs['down_offpeak'] = $valuesarray[5]/100;
array_push($return,$attrs);
array_push($result,$attrs);
}
return $return;
return $result;
}
}
?>

View File

@ -18,7 +18,7 @@ class Service_Traffic_ADSL_PeopleAgent extends Service_Traffic_ADSL {
// Assume we have a bad fetch, unless otherwise specified.
$this->fetchresult = FALSE;
$return = array();
$result = array();
$url_suffix = sprintf('traffic_V34_%s.xml',date('Ymd',strtotime($date)));
try {
@ -52,10 +52,10 @@ class Service_Traffic_ADSL_PeopleAgent extends Service_Traffic_ADSL {
}
}
array_push($return,$attrs);
array_push($result,$attrs);
}
return $return;
return $result;
}
}
?>

View File

@ -17,7 +17,7 @@ class Service_Traffic_ADSL_iiNetADSL extends Service_Traffic_ADSL {
private $login_pass_field = 'password';
private $date_field = 'period';
static $return = array();
static $result = array();
// The fields in the XML which are translated into database columns
private $fields = array(
@ -37,8 +37,8 @@ class Service_Traffic_ADSL_iiNetADSL extends Service_Traffic_ADSL {
$this->fetchresult = FALSE;
// If we have already collected the date data, return it.
if (! empty(Service_Traffic_ADSL_iiNetADSL::$return[$date]))
return Service_Traffic_ADSL_iiNetADSL::$return[$date];
if (! empty(Service_Traffic_ADSL_iiNetADSL::$result[$date]))
return Service_Traffic_ADSL_iiNetADSL::$result[$date];
// Find our services that need to be collected this way.
$update = array();
@ -77,7 +77,7 @@ class Service_Traffic_ADSL_iiNetADSL extends Service_Traffic_ADSL {
file_put_contents($debug_file,$data);
}
$return = array();
$result = array();
foreach (XML::factory(NULL,'ii_feed',$data)->volume_usage->volume_usage->get('day_hour') as $day_hour) {
$attrs = array();
@ -100,9 +100,9 @@ class Service_Traffic_ADSL_iiNetADSL extends Service_Traffic_ADSL {
$attrs[$this->fields[$fields['type']]] += $usage->value()/1000/1000;
}
Service_Traffic_ADSL_iiNetADSL::$return[$period['period']][$so->service_adsl->service_username] = $attrs;
Service_Traffic_ADSL_iiNetADSL::$return[$period['period']][$so->service_adsl->service_username]['date'] = $period['period'];
Service_Traffic_ADSL_iiNetADSL::$return[$period['period']][$so->service_adsl->service_username]['service'] = $so->service_adsl->service_username;
Service_Traffic_ADSL_iiNetADSL::$result[$period['period']][$so->service_adsl->service_username] = $attrs;
Service_Traffic_ADSL_iiNetADSL::$result[$period['period']][$so->service_adsl->service_username]['date'] = $period['period'];
Service_Traffic_ADSL_iiNetADSL::$result[$period['period']][$so->service_adsl->service_username]['service'] = $so->service_adsl->service_username;
}
}
@ -113,11 +113,11 @@ class Service_Traffic_ADSL_iiNetADSL extends Service_Traffic_ADSL {
}
// If the date we want is empty, return an array
if (empty(Service_Traffic_ADSL_iiNetADSL::$return[$date]))
if (empty(Service_Traffic_ADSL_iiNetADSL::$result[$date]))
return array();
// Return the date we asked for
return Service_Traffic_ADSL_iiNetADSL::$return[$date];
return Service_Traffic_ADSL_iiNetADSL::$result[$date];
}
}
?>

View File

@ -97,14 +97,14 @@ class Email_Template {
}
public function variables() {
$return = array();
$result = array();
foreach ($this->components as $v)
foreach ($this->etto->variables($v) as $x => $y)
if (! in_array($y,$return))
array_push($return,$y);
if (! in_array($y,$result))
array_push($result,$y);
return $return;
return $result;
}
public function send(array $admin=array()) {

View File

@ -43,9 +43,9 @@ class GoogleChart_ComboChart extends GoogleChart {
}
public function json() {
$return = array();
$result = array();
$return['cols'][] = array(
$result['cols'][] = array(
'id'=>'date',
'label'=>'date',
'type'=>'string',
@ -53,7 +53,7 @@ class GoogleChart_ComboChart extends GoogleChart {
// Columns
foreach (array_keys($this->_axis) as $l) {
$return['cols'][] = array(
$result['cols'][] = array(
'id'=>$l,
'label'=>$l,
'type'=>'number',
@ -69,7 +69,7 @@ class GoogleChart_ComboChart extends GoogleChart {
foreach ($this->_axis as $l => $axis)
array_push($data,array('v'=>isset($v[$l]) ? $v[$l] : 0));
$return['rows'][] = array('c'=>$data);
$result['rows'][] = array('c'=>$data);
}
$options = array(
@ -81,7 +81,7 @@ class GoogleChart_ComboChart extends GoogleChart {
'series' => $this->series(),
);
return json_encode(array('data'=>$return,'options'=>$options));
return json_encode(array('data'=>$result,'options'=>$options));
}
public function render() {
@ -149,7 +149,7 @@ function drawChart_".$this->_divname."() {
}
private function series() {
$return = array();
$result = array();
$c = $this->seriescolors();
$j = count($c);
@ -157,14 +157,14 @@ function drawChart_".$this->_divname."() {
foreach ($this->_axis as $l => $axis) {
// @todo This shouldnt be hard coded
if ($axis == 'yl')
array_push($return,array('type'=>'bar','color'=>$c[$i%$j],'targetAxisIndex'=>0));
array_push($result,array('type'=>'bar','color'=>$c[$i%$j],'targetAxisIndex'=>0));
else
array_push($return,array('type'=>'line','color'=>$c[$i%$j],'targetAxisIndex'=>1));
array_push($result,array('type'=>'line','color'=>$c[$i%$j],'targetAxisIndex'=>1));
$i++;
}
return $return;
return $result;
}
}
?>

View File

@ -77,51 +77,51 @@ class GoogleChart_Legacy extends GoogleChart {
* Calculate our maximum for each side of the chart
*/
private function maxes() {
$return = array();
$result = array();
foreach ($this->_axis as $l => $axis) {
if (! isset($return[$axis]))
$return[$axis] = 0;
if (! isset($result[$axis]))
$result[$axis] = 0;
$return[$axis] += $this->_max[$l]*1.1; // @todo This scaleup should be configurable
$result[$axis] += $this->_max[$l]*1.1; // @todo This scaleup should be configurable
}
return $return;
return $result;
}
/** CHART FIELDS **/
private function chd() {
$return = array();
$result = array();
$maxes = $this->maxes();
// Perform our encoding
foreach ($this->_axis as $l => $axis)
array_push($return,$this->encode($this->_data[$l],$maxes[$axis]));
array_push($result,$this->encode($this->_data[$l],$maxes[$axis]));
$prefix = (count($maxes) > 1) ? sprintf('%s:',$this->axiscount('yl')) : ':';
// If encoding is text, we need to separate the series with a |
return ($this->_encodetype == 't') ? $prefix.implode('|',$return) : $prefix.implode(',',$return);
return ($this->_encodetype == 't') ? $prefix.implode('|',$result) : $prefix.implode(',',$result);
}
private function chm() {
$return = array();
$result = array();
$sc = $this->seriescolors();
$i = 0;
foreach ($this->_axis as $l => $axis) {
if ($axis == 'yr')
array_push($return,sprintf('%s,%s,%s,%s,%s,%s','D',$sc[$i],$i,0,2,2));// @todo 'D,0,2,2' May need to be configurable
array_push($result,sprintf('%s,%s,%s,%s,%s,%s','D',$sc[$i],$i,0,2,2));// @todo 'D,0,2,2' May need to be configurable
$i++;
}
return count($return) ? implode('|',$return) : '';
return count($result) ? implode('|',$result) : '';
}
private function chxl() {
$return = array();
$result = array();
// @todo This should be performed better - it may be a wrong assumption that all keys in the series have data.
foreach ($this->_data as $series => $data)
@ -130,13 +130,13 @@ class GoogleChart_Legacy extends GoogleChart {
}
private function chxr() {
$return = array();
$result = array();
$i = 1;
foreach ($this->maxes() as $key => $value)
array_push($return,sprintf('%s,0,%s,0',$i++,$value));
array_push($result,sprintf('%s,0,%s,0',$i++,$value));
return implode('|',$return);
return implode('|',$result);
}
public function json() {}

View File

@ -119,7 +119,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
}
/**
* Return a list of invoice items for this payment.
* Return a list of invoice items for this invoice.
* @param type [CHARGE|CREDIT|ALL]
* @see invoice_items
*/
@ -128,6 +128,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
foreach ($this->invoice_items as $ito) {
$return = FALSE;
switch ($type) {
case 'CHARGE':
if ($ito->quantity > 0)
@ -143,7 +144,6 @@ class Model_Invoice extends ORM_OSB implements Cartable {
default:
$return = TRUE;
break;
}
if ($return)
@ -530,7 +530,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
* Search for invoices matching a term
*/
public function list_autocomplete($term,$index='id') {
$return = array();
$result = array();
if (is_numeric($term)) {
$this->clear();
@ -541,13 +541,13 @@ class Model_Invoice extends ORM_OSB implements Cartable {
// @todo This should limit the results so that users dont see other users services.
foreach ($this->find_all() as $o)
$return[$o->$index] = array(
$result[$o->$index] = array(
'value'=>$o->$index,
'label'=>sprintf('INV %s: %s',$o->id,Table::resolve($o,$value)),
);
}
return $return;
return $result;
}
private function _list_due() {
@ -589,19 +589,19 @@ class Model_Invoice extends ORM_OSB implements Cartable {
* Return a list of invoices that are over their due date with/without auto billing
*/
public function list_overdue_billing($time=NULL,$billing=FALSE) {
$return = array();
$result = array();
foreach ($this->list_overdue($time) as $io) {
$i = FALSE;
foreach ($io->service->find_all() as $so)
if (($billing AND $so->account_billing_id) OR (! $billing AND ! $so->account_billing_id)) {
array_push($return,$io);
array_push($result,$io);
break;
}
}
return $return;
return $result;
}
/**

View File

@ -20,16 +20,16 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
);
public function action_ajaxlist() {
$return = array();
$result = array();
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
$return += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
$return += ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'account_id');
$result += ORM::factory('Account')->list_autocomplete($_REQUEST['term']);
$result += ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'account_id');
}
$this->auto_render = FALSE;
$this->response->headers('Content-Type','application/json');
$this->response->body(json_encode(array_values($return)));
$this->response->body(json_encode(array_values($result)));
}
public function action_autoitemlist() {

View File

@ -46,29 +46,39 @@ class Model_Payment extends ORM_OSB {
}
/**
* Return a list of invoice items for this payment.
* Add an item to this payment
*
* @param $inv number, to allocate payment to an invoice
*/
public function items() {
return $this->payment_items;
}
public function add_item($invnum) {
if ($this->loaded() and ! $this->payment_items)
throw new Kohana_Exception('Need to load payment_items?');
/**
* Add an item to an invoice
*/
public function add_item($iid) {
// Find our id, if it exists
foreach ($this->payment_items as $pio)
if ($pio->invoice_id == $iid)
if ($pio->invoice_id == $invnum)
return $pio;
// New Item
$c = count($this->payment_items);
$this->payment_items[$c] = ORM::factory('Payment_Item');
$this->payment_items[$c]->invoice_id = $iid;
$this->payment_items[$c]->invoice_id = $invnum;
return $this->payment_items[$c];
}
/**
* Calculate the remaining balance available for this payment
*/
public function balance($format=FALSE) {
$result = $this->total();
foreach ($this->items('ALLOC') as $pio)
$result -= $pio->alloc_amt;
return $format ? Currency::display($result) : $result;
}
/**
* Find all items that are exportable.
*
@ -80,34 +90,69 @@ class Model_Payment extends ORM_OSB {
->find_all();
}
/**
* Calculate the remaining balance available for this payment
*/
public function balance($format=FALSE) {
$t = 0;
foreach ($this->payment_item->find_all() as $pio)
$t += $pio->alloc_amt;
return $format ? Currency::display($this->total_amt-$t) : $this->total_amt-$t;
}
/**
* Return a list of invoices that this payment is applied to
*/
public function invoices() {
$invoices = array();
$result = array();
foreach ($this->payment_item->find_all() as $pio)
array_push($invoices,$pio->invoice);
foreach ($this->payment_items as $pio)
array_push($result,$pio->invoice);
return $invoices;
return $result;
}
public function invoicelist() {
return join(',',$this->invoices());
}
/**
* Return a list of payment items for this payment.
* @param type [ALLOC|CREDIT|ALL]
* @see payment_items
*/
public function items($type='ALL') {
$result = array();
foreach ($this->payment_items as $pio) {
$return = FALSE;
switch ($type) {
case 'ALLOC':
if ($pio->alloc_amt > 0)
$return = TRUE;
break;
case 'CREDIT':
if ($pio->alloc_amt < 0)
$return = TRUE;
break;
case 'ALL':
default:
$return = TRUE;
break;
}
if ($return)
array_push($result,$pio);
}
return $result;
}
/**
* Show the total amount of a payment.
*/
public function total($format=FALSE) {
$result = $this->total_amt;
foreach ($this->items('CREDIT') as $pio)
$result += $pio->alloc_amt;
return $format ? Currency::display($result) : Currency::round($result);
}
/** LIST FUNCTIONS **/
public function list_unapplied() {

View File

@ -11,15 +11,15 @@
*/
class Payment_Bulk_Ezypay {
public function form() {
$return = '';
$result = '';
$return .= Form::open(NULL,array('enctype'=>'multipart/form-data'));
$return .= Form::hidden('payer',$_POST['payer']);
$return .= View::factory('payment/admin/addbulk/ezypay');
$return .= Form::submit('submit','submit',array('class'=>'form_button'));
$return .= Form::close();
$result .= Form::open(NULL,array('enctype'=>'multipart/form-data'));
$result .= Form::hidden('payer',$_POST['payer']);
$result .= View::factory('payment/admin/addbulk/ezypay');
$result .= Form::submit('submit','submit',array('class'=>'form_button'));
$result .= Form::close();
return $return;
return $result;
}
public function process() {
@ -83,8 +83,8 @@ class Payment_Bulk_Ezypay {
$payments[$array[3]]->checkout_plugin_id = 4;
}
$return = '';
$return .= View::Factory('payment/admin/addbulk/ezypay/head');
$result = '';
$result .= View::Factory('payment/admin/addbulk/ezypay/head');
$total = $fees = 0;
foreach ($payments as $po) {
@ -93,15 +93,15 @@ class Payment_Bulk_Ezypay {
$total += $po->total_amt;
$fees += $po->fees_amt;
$return .= View::Factory('payment/admin/addbulk/ezypay/body')
$result .= View::Factory('payment/admin/addbulk/ezypay/body')
->set('o',$po);
}
$return .= View::Factory('payment/admin/addbulk/ezypay/foot')
$result .= View::Factory('payment/admin/addbulk/ezypay/foot')
->set('total',$total)
->set('fees',$fees);;
return $return;
return $result;
}
}
?>

View File

@ -16,7 +16,7 @@
</tr>
<tr>
<td>Amount</td>
<td><?php echo Form::input('total_amt',$po->total_amt); ?></td>
<td><?php echo Form::input('total_amt',$po->total()); ?></td>
</tr>
<tr>
<td>Fees</td>

View File

@ -34,13 +34,13 @@ class Model_Product_Category extends ORM_OSB {
* @todo Consider if we should cache this
*/
public function products() {
$return = array();
$result = array();
foreach (ORM::factory('Product')->where_active()->find_all() as $po)
if (in_array($this->id,$po->categories()))
array_push($return,$po);
array_push($result,$po);
return $return;
return $result;
}
public function list_bylistgroup($cat) {

View File

@ -33,20 +33,20 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
);
public function action_ajaxlist() {
$return = array();
$result = array();
$return += ORM::factory('Service')->list_autocomplete(
$result += ORM::factory('Service')->list_autocomplete(
isset($_REQUEST['term']) ? $_REQUEST['term'] : '',
'id',
isset($_REQUEST['aid']) ? array(array('account_id','=',$_REQUEST['aid'])) : array());
$this->auto_render = FALSE;
$this->response->headers('Content-Type','application/json');
$this->response->body(json_encode(array_values($return)));
$this->response->body(json_encode(array_values($result)));
}
public function action_ajaxjson_traffic() {
$return = array();
$result = array();
$svs = ORM::factory('Service')->list_bylistgroup('ADSL');
$data = $this->consoltraffic($svs,time());
@ -610,7 +610,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
return;
$start = $end = FALSE;
$return = array();
$result = array();
foreach (preg_split("/\n/",$data) as $line) {
// Items start after "Item ID"
if (! $start && preg_match('/^Item ID,/',$line)) {
@ -638,18 +638,18 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
// If the description says Monthly Charge, we know its the monthly fee.
if (preg_match('/^Monthly Charge/',$description))
$return[$service]['cost'] = preg_replace('/\$/','',$total);
$result[$service]['cost'] = preg_replace('/\$/','',$total);
// If the description says VISP credit, we know this is commission.
elseif (preg_match('/^VISP Credit/',$description))
$return[$service]['credit'] = preg_replace('/\$/','',$total);
$result[$service]['credit'] = preg_replace('/\$/','',$total);
// If the description says Excess, we know this is excess charges.
elseif (preg_match('/^Excess usage/',$description))
$return[$service]['excess'] = preg_replace('/\$/','',$total);
$result[$service]['excess'] = preg_replace('/\$/','',$total);
else
$return[$service]['info'] = $line;
$result[$service]['info'] = $line;
}
return $return;
return $result;
}
/**

View File

@ -182,7 +182,7 @@ class Model_Service extends ORM_OSB {
* Search for services matching a term
*/
public function list_autocomplete($term,$index='id',array $limit=array()) {
$return = array();
$result = array();
$this->clear();
$this->where_active();
@ -200,12 +200,12 @@ class Model_Service extends ORM_OSB {
}
foreach ($this->find_all() as $o)
$return[$o->$index] = array(
$result[$o->$index] = array(
'value'=>$o->$index,
'label'=>sprintf('SVC %s: %s',$o->id,Table::resolve($o,$value)),
);
return $return;
return $result;
}
public function list_bylistgroup($cat) {
@ -237,13 +237,13 @@ class Model_Service extends ORM_OSB {
* List invoices for this service
*/
public function list_invoices($due=FALSE) {
$return = array();
$result = array();
foreach ($this->invoice->find_all() as $io)
if (! $due OR $io->due())
array_push($return,$io);
array_push($result,$io);
return $return;
return $result;
}
/**

View File

@ -119,16 +119,16 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin {
}
public function cacerts() {
$return = array();
$result = array();
$x = $this->ssl_ca_id;
while ($x) {
$sco = ORM::factory('SSL_CA',$x);
array_push($return,$sco->sign_cert);
array_push($result,$sco->sign_cert);
$x = $sco->parent_ssl_ca_id;
}
return $return;
return $result;
}
public function renew() {

View File

@ -50,7 +50,7 @@ class SSL {
* @param $key Return just that index
*/
private function _aki($key=NULL) {
$return = array();
$result = array();
$aki = $this->_extensions('authorityKeyIdentifier');
if (! $aki)
@ -62,11 +62,11 @@ class SSL {
if (strstr($x,':')) {
list($a,$b) = explode(':',$x,2);
$return[strtolower($a)] = $b;
$result[strtolower($a)] = $b;
}
}
return is_null($key) ? $return : (isset($return[$key]) ? $return[$key] : '');
return is_null($key) ? $result : (isset($result[$key]) ? $result[$key] : '');
}
private function _bc() {
@ -92,26 +92,26 @@ class SSL {
* @param $key Return just that index
*/
private function _extensions($key=NULL) {
$return = $this->_details('extensions');
$result = $this->_details('extensions');
return is_null($key) ? $return : (isset($return[$key]) ? $return[$key] : '');
return is_null($key) ? $result : (isset($result[$key]) ? $result[$key] : '');
}
/**
* Render a DN array as a string
*/
private function _dn(array $array) {
$return = '';
$result = '';
$i = 0;
foreach ($array as $k=>$v) {
if ($i++)
$return .= ',';
$result .= ',';
$return .= sprintf('%s=%s',$k,$v);
$result .= sprintf('%s=%s',$k,$v);
}
return $return;
return $result;
}
public function get_aki_dirname() {

View File

@ -22,7 +22,7 @@ class Controller_Admin_Statement extends Controller_TemplateDefault_Admin {
$ta = array();
foreach ($ao->payment->find_all() as $o) {
if (round($o->total_amt-$o->refund_status,0) == 0)
if ( ! $o->total())
continue;
$i = count($ta);
@ -49,7 +49,7 @@ class Controller_Admin_Statement extends Controller_TemplateDefault_Admin {
if (isset($v['invoice']))
$t += $v['invoice']->total();
elseif (isset($v['payment']))
$t -= $v['payment']->total_amt-$v['payment']->refund_status;
$t -= $v['payment']->total();
$ta[$k]['total'] = $t;
$a = $v['time'];

View File

@ -8,7 +8,7 @@
<td><?php echo $o['payment']->display('date_payment'); ?></td>
<td>Payment</td>
<td><?php printf('%s - %s',$o['payment']->id,$o['payment']->checkout->display('name')); ?></td>
<td class="right"><?php echo $o['payment']->display('total_amt')-$o['payment']->refund_status; ?></td>
<td class="right"><?php echo $o['payment']->total(TRUE); ?></td>
<?php } ?>
<td class="right"><?php echo Currency::display($o['total']); ?></td>
</tr>

View File

@ -81,27 +81,27 @@ class Model_Task extends ORM_OSB {
/** LIST FUNCTIONS **/
public function list_active() {
$return = array();
$result = array();
foreach ($this->_where_active()->find_all() 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);
$result[$to->id]['task'] = $to;
$result[$to->id]['next'] = $c->next($to->date_run);
}
return $return;
return $result;
}
public function list_next() {
$return = array();
$result = array();
foreach ($this->list_active() as $v)
if ((! $return OR $v['next']<$return['next']) AND ! $v['task']->running)
$return = $v;
if ((! $result OR $v['next']<$result['next']) AND ! $v['task']->running)
$result = $v;
return array($return['task']->id=>$return);
return array($result['task']->id=>$result);
}
}
?>