Open Source Billing
This commit is contained in:
134
modules/adsl/classes/ADSL.php
Normal file
134
modules/adsl/classes/ADSL.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class looks after ADSL products
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Product
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class ADSL {
|
||||
// Map the table fields
|
||||
static $map = array(
|
||||
'base_up_offpeak'=>'extra_up_offpeak',
|
||||
'base_down_offpeak'=>'extra_down_offpeak',
|
||||
'base_up_peak'=>'extra_up_peak',
|
||||
'base_down_peak'=>'extra_down_peak',
|
||||
);
|
||||
|
||||
/**
|
||||
* Return an instance of this class
|
||||
*
|
||||
* @return ADSL
|
||||
*/
|
||||
public static function instance() {
|
||||
return new ADSL;
|
||||
}
|
||||
|
||||
public function contract_view($data,$price_base,$price_setup) {
|
||||
// @todo - this test shouldnt be required
|
||||
if (preg_match('/^a:/',$data))
|
||||
throw new Kohana_Exception('Data shouldnt be a serialized array');
|
||||
|
||||
$ao = ORM::factory('ADSL_Plan',$data);
|
||||
$output = View::factory('adsl/contract_view')
|
||||
->set('record',$ao)
|
||||
->set('price_base',$price_base)
|
||||
->set('price_setup',$price_setup);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect information for the cart
|
||||
*/
|
||||
public function product_cart() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the metric fields to their excess rate
|
||||
*/
|
||||
public static function map($metric) {
|
||||
return ADSL::$map[$metric];
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the allowance array or traffic used array
|
||||
*
|
||||
* If:
|
||||
* + UPLOADS are charged and there are no PEAK/OFFPEAK periods (therefore all
|
||||
* traffic is charged), the allowance will be shown as 1 metric - TRAFFIC.
|
||||
* + UPLOADS are charged and there are PEAK/OFFPEAK periods the allowance
|
||||
* will be shown as 2 metrics - PEAK/OFFPEAK.
|
||||
* + UPLOADS are NOT charged and there are no PEAK/OFFPEAK periods the allowance
|
||||
* will be shown as 1 metrics - TRAFFIC.
|
||||
* + UPLOADS are NOT charged and there are PEAK/OFFPEAK periods the allowance
|
||||
* will be shown as 2 metrics - PEAK/OFFPEAK.
|
||||
*
|
||||
* Thus:
|
||||
* + If base_x_Y is NULL, all Y traffic is FREE (ignore respective extra_x_Y setting).
|
||||
* + If base_x_Y is a number, all Y traffic is FREE up to the number (evaluate extra_x_Y setting).
|
||||
* + If extra_x_Y is a number, charge this amount for traffic over base_x_Y.
|
||||
* + If extra_down_peak is NULL this is invalid, treat base_down_peak as NULL
|
||||
* + If extra_down_offpeak is NULL add traffic_down_offpeak to traffic_down_peak
|
||||
* + If extra_up_peak is NULL add traffic_up_peak to traffic_down_peak
|
||||
* + If extra_up_offpeak is NULL add traffic_up_offpeak to traffic_down_offpeak
|
||||
*
|
||||
* @param array $plan - the allowance plan
|
||||
*/
|
||||
public static function allowance($plan) {
|
||||
// Map the NULL relationships
|
||||
$extras = array(
|
||||
'extra_up_offpeak'=>'base_down_offpeak',
|
||||
'extra_down_offpeak'=>'base_down_peak',
|
||||
'extra_up_peak'=>'base_down_peak',
|
||||
'extra_down_peak'=>'base_down_peak',
|
||||
);
|
||||
|
||||
// Work out if we charge each period
|
||||
$a = array();
|
||||
if (! isset($plan['extra_down_peak']) OR is_null($plan['extra_down_peak']))
|
||||
$a['base_down_peak'] = 0;
|
||||
|
||||
foreach (ADSL::$map as $k => $v) {
|
||||
// Work through attributes we count.
|
||||
if (isset($plan[$k]) AND ! is_null($plan[$k])) {
|
||||
|
||||
// Work through attributes that are merged
|
||||
if (! isset($plan[$v]) OR is_null($plan[$v])) {
|
||||
|
||||
if (isset($a[$k])) {
|
||||
if (isset($a[$extras[$v]]))
|
||||
$a[$extras[$v]] += $a[$k];
|
||||
else
|
||||
$a[$extras[$v]] = $a[$k];
|
||||
|
||||
unset($a[$k]);
|
||||
}
|
||||
|
||||
if (isset($a[$extras[$v]]))
|
||||
$a[$extras[$v]] += $plan[$k];
|
||||
else
|
||||
$a[$extras[$v]] = $plan[$k];
|
||||
|
||||
} else {
|
||||
if (isset($a[$k]))
|
||||
$a[$k] += $plan[$k];
|
||||
else
|
||||
$a[$k] = $plan[$k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the output sorted
|
||||
$result = array();
|
||||
foreach (array('base_down_peak','base_down_offpeak','base_up_peak','base_up_offpeak') as $k)
|
||||
if (isset($a[$k]))
|
||||
$result[$k] = $a[$k];
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
38
modules/adsl/classes/Model/ADSL/Plan.php
Normal file
38
modules/adsl/classes/Model/ADSL/Plan.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports ADSL Plans
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_ADSL_Plan extends ORM_OSB {
|
||||
// Relationships
|
||||
// @todo This model should probably be joined with product_plugin_adsl
|
||||
protected $_belongs_to = array(
|
||||
'adsl_supplier_plan'=>array('model'=>'ADSL_Supplier_Plan'),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'extra_down_peak'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'extra_down_offpeak'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'extra_up_peak'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'extra_up_offpeak'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
);
|
||||
}
|
||||
?>
|
72
modules/adsl/classes/Model/ADSL/Supplier.php
Normal file
72
modules/adsl/classes/Model/ADSL/Supplier.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports ADSL Suppliers
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_ADSL_Supplier extends ORM_OSB {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'adsl_supplier_plan'=>array('model'=>'ADSL_Supplier_Plan','foreign_key'=>'supplier_id','far_key'=>'id'),
|
||||
);
|
||||
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
/**
|
||||
* Return a list of plans that this supplier makes available
|
||||
*/
|
||||
public function plans($active=TRUE) {
|
||||
$a = $this->adsl_supplier_plan;
|
||||
|
||||
if ($active)
|
||||
$a->where_active();
|
||||
|
||||
return $a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of plans that we provide by this supplier
|
||||
*/
|
||||
public function adsl_plans($active=TRUE) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->plans($active)->find_all() as $po)
|
||||
foreach ($po->adsl_plan->find_all() as $apo)
|
||||
$result[$apo->id] = $apo;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of services for this supplier
|
||||
*
|
||||
* @param boolean $active TRUE List only active Services|False List all services
|
||||
*/
|
||||
public function services($active=TRUE) {
|
||||
$services = array();
|
||||
|
||||
// Get a list of plans made for this supplier
|
||||
$plans = array_keys($this->adsl_plans(FALSE));
|
||||
|
||||
// Start with all our ADSL Plans
|
||||
foreach (ORM::factory('Service')->list_bylistgroup('ADSL') as $so)
|
||||
if (! $active OR $so->status)
|
||||
if (in_array($so->product->prod_plugin_data,$plans) OR in_array($so->plugin()->provided_adsl_plan_id,$plans))
|
||||
array_push($services,$so);
|
||||
|
||||
// @todo poor cludge, we should find them without using list_bylistgroup()
|
||||
if (! $services)
|
||||
foreach (ORM::factory('Service')->list_bylistgroup('HSPA') as $so)
|
||||
if (! $active OR $so->status)
|
||||
if (in_array($so->product->prod_plugin_data,$plans) OR in_array($so->plugin()->provided_adsl_plan_id,$plans))
|
||||
array_push($services,$so);
|
||||
|
||||
return $services;
|
||||
}
|
||||
}
|
||||
?>
|
38
modules/adsl/classes/Model/ADSL/Supplier/Plan.php
Normal file
38
modules/adsl/classes/Model/ADSL/Supplier/Plan.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports ADSL Plans
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_ADSL_Supplier_Plan extends ORM_OSB {
|
||||
// Relationships
|
||||
protected $_has_many = array(
|
||||
'adsl_plan'=>array('model'=>'ADSL_Plan','far_key'=>'id'),
|
||||
);
|
||||
protected $_belongs_to = array(
|
||||
'adsl_supplier'=>array('model'=>'ADSL_Supplier','foreign_key'=>'supplier_id'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Show the ADSL allowance as a peak/offpeak metric
|
||||
*/
|
||||
public function allowance() {
|
||||
return sprintf('%s/%s',$this->base_down_peak+$this->base_up_peak,$this->base_down_offpeak+$this->base_up_offpeak);
|
||||
}
|
||||
|
||||
public function tax() {
|
||||
// @todo This should be taken from the users session
|
||||
// @todo rounding should be a system default
|
||||
return round($this->base_cost*.1,2);
|
||||
}
|
||||
|
||||
public function name() {
|
||||
return $this->product_id;
|
||||
}
|
||||
}
|
||||
?>
|
59
modules/adsl/classes/Model/Product/Plugin/Adsl.php
Normal file
59
modules/adsl/classes/Model/Product/Plugin/Adsl.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports ADSL products
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Product_Plugin_Adsl extends Model_Product_Plugin {
|
||||
protected $_table_name = 'adsl_plan';
|
||||
|
||||
protected $_belongs_to = array(
|
||||
'adsl_supplier_plan'=>array('model'=>'ADSL_Supplier_Plan'),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'extra_down_peak'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
'extra_down_offpeak'=>array(
|
||||
array('Tax::add',array(':value')),
|
||||
array('Currency::display',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
public function admin_update() {
|
||||
return '';
|
||||
}
|
||||
|
||||
// Our required abstract methods
|
||||
public function feature_summary() {
|
||||
// @todo This view should render based on the the results of this::allowance();
|
||||
return View::factory('product/plugin/adsl/feature_summary')
|
||||
->set('po',$this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the ADSL allowance as a peak/offpeak metric
|
||||
*/
|
||||
public function allowance($string=TRUE) {
|
||||
$output = ADSL::allowance(array(
|
||||
'base_down_peak'=>$this->base_down_peak,
|
||||
'base_down_offpeak'=>$this->base_down_offpeak,
|
||||
'base_up_peak'=>$this->base_up_peak,
|
||||
'base_up_offpeak'=>$this->base_up_offpeak,
|
||||
'extra_down_peak'=>$this->extra_down_peak,
|
||||
'extra_down_offpeak'=>$this->extra_down_offpeak,
|
||||
'extra_up_peak'=>$this->extra_up_peak,
|
||||
'extra_up_offpeak'=>$this->extra_up_offpeak,
|
||||
));
|
||||
|
||||
return $string ? implode('/',$output) : $output;
|
||||
}
|
||||
}
|
||||
?>
|
398
modules/adsl/classes/Model/Service/Plugin/Adsl.php
Normal file
398
modules/adsl/classes/Model/Service/Plugin/Adsl.php
Normal file
@@ -0,0 +1,398 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports Services
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Service_Plugin_Adsl extends Model_Service_Plugin {
|
||||
protected $_table_name = 'service__adsl';
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'service'=>array(),
|
||||
);
|
||||
|
||||
protected $_has_one = array(
|
||||
'adsl_plan'=>array('model'=>'ADSL_Plan','far_key'=>'provided_adsl_plan_id','foreign_key'=>'id'),
|
||||
);
|
||||
|
||||
protected $_display_filters = array(
|
||||
'service_connect_date'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
'service_contract_date'=>array(
|
||||
array('Config::date',array(':value')),
|
||||
),
|
||||
);
|
||||
|
||||
// Required abstract functions
|
||||
public function admin_update() {
|
||||
return View::factory('service/admin/adsl/update')
|
||||
->set('mediapath',Route::get('default/media'))
|
||||
->set('so',$this);
|
||||
}
|
||||
|
||||
/**
|
||||
* When does this service expire
|
||||
*/
|
||||
public function expire() {
|
||||
// @todo This should work out if the invoices are currently due, then the expire is the invoice date, otherwise the next invoice date.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public function name() {
|
||||
return $this->service_number;
|
||||
}
|
||||
|
||||
public function product() {
|
||||
if ($this->provided_adsl_plan_id)
|
||||
return $this->adsl_plan;
|
||||
else
|
||||
return $this->service->product->plugin();
|
||||
}
|
||||
|
||||
public function service_view() {
|
||||
return View::factory('service/user/plugin/adsl/view')
|
||||
->set('so',$this);
|
||||
}
|
||||
|
||||
public function username_value() {
|
||||
return $this->service_username;
|
||||
}
|
||||
|
||||
public function password_value() {
|
||||
return $this->service_password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the IP Address for the service
|
||||
*/
|
||||
public function ipaddress() {
|
||||
return $this->ipaddress ? $this->ipaddress : _('Dynamic');
|
||||
}
|
||||
|
||||
public function contract_date_start() {
|
||||
return Config::date($this->service_contract_date);
|
||||
}
|
||||
|
||||
public function contract_date_end() {
|
||||
return Config::date(strtotime(sprintf('+%s months',$this->contract_term),$this->service_contract_date));
|
||||
}
|
||||
|
||||
public function hasOffpeak() {
|
||||
return ((is_null($this->product()->base_down_offpeak) OR $this->product()->base_down_offpeak) AND (is_null($this->product()->base_up_offpeak) OR $this->product()->base_up_offpeak)) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will return the months that have traffic data.
|
||||
* This array can be used in a select list to display the traffic for that month
|
||||
*/
|
||||
public function get_traffic_months() {
|
||||
$keys = $months = array();
|
||||
|
||||
foreach ($this->get_traffic_data_monthly() as $metric => $data)
|
||||
$keys = array_unique(array_merge($keys,array_keys($data)));
|
||||
|
||||
foreach ($keys as $v)
|
||||
$months[$v] = $v;
|
||||
|
||||
arsort($months);
|
||||
|
||||
return $months;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the total traffic used in a month
|
||||
*/
|
||||
private function get_traffic_data_month($period=NULL,$cache=NULL) {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->get_traffic_data_daily($period,TRUE,$cache) as $tdata)
|
||||
foreach ($tdata as $k => $v)
|
||||
if (isset($result[$k]))
|
||||
$result[$k] += $v;
|
||||
else
|
||||
$result[$k] = $v;
|
||||
|
||||
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) {
|
||||
$result = array();
|
||||
|
||||
// @temp - caching is broken?
|
||||
$cache=0;
|
||||
if (is_null($period))
|
||||
$period = strtotime('yesterday');
|
||||
|
||||
$t = ORM::factory('Service_Plugin_Adsl_Traffic')
|
||||
->where('service','=',$this->service_username)
|
||||
->and_where('date','>=',date('Y-m-d',mktime(0,0,0,date('m',$period),1,date('Y',$period))))
|
||||
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))))
|
||||
->cached($cache);
|
||||
|
||||
foreach ($t->find_all() as $to) {
|
||||
$day = date('d',strtotime($to->date));
|
||||
|
||||
if ($bydate)
|
||||
$result[$day] = $to->traffic($this->service->product->plugin());
|
||||
else
|
||||
foreach ($to->traffic($this->service->product->plugin()) as $k => $v)
|
||||
$result[$k][$day] = $v;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of the data used in a year by month
|
||||
*/
|
||||
public function get_traffic_data_monthly($period=NULL,$bydate=FALSE) {
|
||||
$result = array();
|
||||
|
||||
if (is_null($period))
|
||||
$period = strtotime('yesterday');
|
||||
|
||||
$t = ORM::factory('Service_Plugin_Adsl_Traffic')
|
||||
->select(
|
||||
array('date_format(date,\'%y-%m\')','month'),
|
||||
array('sum(up_peak)','up_peak'),
|
||||
array('sum(up_offpeak)','up_offpeak'),
|
||||
array('sum(down_peak)','down_peak'),
|
||||
array('sum(down_offpeak)','down_offpeak')
|
||||
)
|
||||
->where('service','=',$this->service_username)
|
||||
->and_where('date','>=',date('Y-m-d',mktime(0,0,0,date('m',$period),1,date('Y',$period)-1)))
|
||||
->and_where('date','<=',date('Y-m-d',strtotime('last day of '.date('M Y',$period))))
|
||||
->group_by('date_format(date,\'%Y-%m\')');
|
||||
|
||||
foreach ($t->find_all() as $to)
|
||||
if ($bydate)
|
||||
$result[$to->month] = $to->traffic($this->service->product->plugin());
|
||||
else
|
||||
foreach ($to->traffic($this->service->product->plugin()) as $k => $v)
|
||||
$result[$k][$to->month] = $v;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function traffic_month($month,$string=TRUE,$cache=NULL) {
|
||||
return $string ? implode('/',$this->get_traffic_data_month($month,$cache)) :
|
||||
$this->get_traffic_data_month($month,$cache);
|
||||
}
|
||||
|
||||
public function traffic_lastmonth($string=TRUE) {
|
||||
// We need it to be last month as of yesterday
|
||||
return $this->traffic_month(strtotime('last month')-86400,$string);
|
||||
}
|
||||
|
||||
public function traffic_thismonth($string=TRUE) {
|
||||
return $this->traffic_month(strtotime('yesterday'),$string);
|
||||
}
|
||||
|
||||
public function traffic_lastmonth_exceed($all=FALSE,$date=NULL) {
|
||||
$result = array();
|
||||
|
||||
if (is_null($date))
|
||||
$date = strtotime('last month')-86400;
|
||||
|
||||
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)) {
|
||||
$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 $result;
|
||||
}
|
||||
|
||||
public function template_variables($array) {
|
||||
$friendly = array(
|
||||
'base_down_peak'=>'Peak',
|
||||
'base_down_offpeak'=>'OffPeak',
|
||||
'cumulative_base_down_peak'=>'Total Peak',
|
||||
'cumulative_base_down_offpeak'=>'Total OffPeak',
|
||||
);
|
||||
|
||||
$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));
|
||||
|
||||
$allowance = $this->service->product->plugin()->allowance(FALSE);
|
||||
|
||||
$period = strtotime('yesterday');
|
||||
$traffic_data = $this->get_traffic_data_daily($period,FALSE);
|
||||
$traffic = $this->get_traffic_data_month($period);
|
||||
|
||||
$traffic_type = $this->get_traffic_data_daily($period,TRUE);
|
||||
$day = count($traffic_type) ? max(array_keys($traffic_type)) : 1;
|
||||
$date = mktime(0,0,0,date('n',$period),$day,date('Y',$period));
|
||||
$daysleft = date('d',strtotime('last day of',$date))-$day;
|
||||
|
||||
$google = GoogleChart::factory('Legacy')
|
||||
->type('vertical_bar')
|
||||
->title(sprintf('DSL traffic usage as at %s',Config::date($date)));
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->sdata(array('yl'=>($x=isset($friendly[$k]) ? $friendly[$k] : $k)),array($x=>$traffic_data[$k]));
|
||||
|
||||
// Work out comulative numbers
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->sdata(array('yr'=>($x=isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)),array($x=>$this->cumulative($traffic_data[$k])));
|
||||
|
||||
foreach ($array as $item) {
|
||||
switch ($item) {
|
||||
case 'MONTH_GRAPH': $value = (string)$google; break;
|
||||
case 'MONTH_TABLE': $value = $google->table(FALSE,array(
|
||||
'table'=>'style="border: 1px solid #bebcb7; padding: 5px 5px; background: none repeat scroll 0% 0% #f8f7f5; font-size: 70%;"',
|
||||
)); break;
|
||||
|
||||
case 'OFFPEAK_ALLOWANCE': $value = isset($allowance['base_down_offpeak']) ? $allowance['base_down_offpeak'].' MB' : '-'; break;
|
||||
case 'OFFPEAK_USAGE': $value = isset($traffic['base_down_offpeak']) ? $traffic['base_down_offpeak'].' MB' : '-'; break;
|
||||
|
||||
case 'PEAK_ALLOWANCE': $value = isset($allowance['base_down_peak']) ? $allowance['base_down_peak'].' MB' : '-'; break;
|
||||
case 'PEAK_USAGE': $value = isset($traffic['base_down_peak']) ? $traffic['base_down_peak'].' MB' : '-'; break;
|
||||
|
||||
case 'OFFPEAK_AVERAGE': $value = isset($traffic['base_down_offpeak']) ? round($traffic['base_down_offpeak']/$day,2).' MB' : '-'; break;
|
||||
case 'OFFPEAK_AVERAGE_REMAIN': $value = ((isset($traffic['base_down_offpeak']) AND ($allowance['base_down_offpeak'] > $traffic['base_down_offpeak']) AND $daysleft) ? round(($allowance['base_down_offpeak']-$traffic['base_down_offpeak'])/$daysleft,2).' MB' : '-'); break;
|
||||
|
||||
case 'PEAK_AVERAGE': $value = isset($traffic['base_down_peak']) ? round($traffic['base_down_peak']/$day,2).' MB' : '-'; break;
|
||||
case 'PEAK_AVERAGE_REMAIN': $value = ((isset($traffic['base_down_peak']) AND ($allowance['base_down_peak'] > $traffic['base_down_peak']) AND $daysleft) ? round(($allowance['base_down_peak']-$traffic['base_down_peak'])/$daysleft,2).' MB' : '-'); break;
|
||||
|
||||
case 'SERVICE_NUMBER': $value = $this->service_number; break;
|
||||
case 'USAGE_DATE': $value = Config::date($date); break;
|
||||
case 'USER_NAME': $value = $this->service->account->name(); break;
|
||||
default:
|
||||
$value = '';
|
||||
}
|
||||
|
||||
$result[$item] = $value;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will take an array of numbers and change it into a cumulative array
|
||||
*/
|
||||
public function cumulative($array) {
|
||||
$result = array();
|
||||
$s = 0;
|
||||
|
||||
foreach ($array as $k => $v)
|
||||
$result[$k] = ($s += $v);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if we alert traffic
|
||||
*
|
||||
* We alert traffic if:
|
||||
* + 80% of usage every 3 days
|
||||
* + average daily usage > allowance every 5 days
|
||||
* + last day of the period
|
||||
*/
|
||||
public function report_traffic() {
|
||||
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));
|
||||
|
||||
$allowance = $this->service->product->plugin()->allowance(FALSE);
|
||||
|
||||
$period = strtotime('yesterday');
|
||||
$traffic_data = $this->get_traffic_data_daily($period,FALSE);
|
||||
$traffic = $this->get_traffic_data_month($period);
|
||||
|
||||
$traffic_type = $this->get_traffic_data_daily($period,TRUE);
|
||||
// @todo If no data comes in, then this can be stuck reporting traffic for an old date.
|
||||
$day = count($traffic_type) ? max(array_keys($traffic_type)) : 1;
|
||||
$lastday = date('d',strtotime('last day of',$period));
|
||||
|
||||
foreach ($traffic as $k => $v) {
|
||||
// If we are the last day of the period
|
||||
if ($day == $lastday AND $v)
|
||||
return TRUE;
|
||||
|
||||
// If we are at 80% usage
|
||||
if ($v/($allowance[$k] > 0 ? $allowance[$k] : 1) >= .8 AND $day%3 == 0)
|
||||
return TRUE;
|
||||
|
||||
// If our average is greater than our allowance
|
||||
if ($day%5 == 0 AND ($v/$day > $allowance[$k]/$day))
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// If we get here, then we dont need to report usage.
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific service details for use in other modules
|
||||
* For Example: Invoice
|
||||
*
|
||||
* @todo Make the rendered items configurable
|
||||
* @todo Change this method name, now that it is public
|
||||
*/
|
||||
public function _details($type) {
|
||||
switch ($type) {
|
||||
case 'invoice_detail_items':
|
||||
return array(
|
||||
_('Service Address')=>$this->service_address ? $this->display('service_address') : '>NotSet<',
|
||||
_('Contract Until')=>$this->contract_date_end(),
|
||||
);
|
||||
break;
|
||||
default:
|
||||
return parent::$_details($type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a google chart of traffic
|
||||
*/
|
||||
public function graph_traffic($month=NULL) {
|
||||
$google = GoogleChart::factory('Legacy')
|
||||
->type('vertical_bar');
|
||||
|
||||
// If we came in via a post to show a particular month, then show that, otherwise show the yearly result
|
||||
if (! is_null($month) AND trim($month)) {
|
||||
$google->title(sprintf('DSL traffic usage for %s',$_POST['month']));
|
||||
$traffic_data = $this->get_traffic_data_daily(strtotime($_POST['month'].'-01'));
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->sdata(array('yl'=>($x=isset($friendly[$k]) ? $friendly[$k] : $k)),array($x=>$traffic_data[$k]));
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->sdata(array('yr'=>($x=isset($friendly['cumulative'.$k]) ? $friendly['cumulative'.$k] : 'cumulative'.$k)),array($x=>$this->cumulative($traffic_data[$k])));
|
||||
|
||||
} else {
|
||||
// @todo Change the date to the last record date
|
||||
$google->title(sprintf('Monthly DSL traffic usage as at %s',Config::date(strtotime('yesterday'))));
|
||||
$traffic_data = $this->get_traffic_data_monthly();
|
||||
|
||||
foreach ($traffic_data as $k => $details)
|
||||
$google->sdata(array('yl'=>($x=isset($friendly[$k]) ? $friendly[$k] : $k)),array($x=>$traffic_data[$k]));
|
||||
}
|
||||
|
||||
return (string)$google;
|
||||
}
|
||||
|
||||
public function table_traffic($month=NULL) {
|
||||
return View::factory('service/user/plugin/adsl/table_traffic')
|
||||
->set('traffic',$this->traffic_month((! is_null($month) AND trim($month)) ? strtotime($month.'-01') : NULL,FALSE));
|
||||
}
|
||||
}
|
||||
?>
|
43
modules/adsl/classes/Model/Service/Plugin/Adsl/Traffic.php
Normal file
43
modules/adsl/classes/Model/Service/Plugin/Adsl/Traffic.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports Services Traffic for ADSL
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Service_Plugin_Adsl_Traffic extends ORM_OSB {
|
||||
protected $_table_name = 'service__adsl_traffic';
|
||||
protected $_primary_key = 'service';
|
||||
protected $_disable_wild_select = TRUE;
|
||||
|
||||
protected $_created_column = FALSE;
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
public function rules() {
|
||||
$result = parent::rules();
|
||||
|
||||
// We don use the "ID" field.
|
||||
unset($result['id']);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function traffic(Model_Product_Plugin_Adsl $plan) {
|
||||
// Roll up the charges according to the product plan configuration
|
||||
return ADSL::allowance(array(
|
||||
'base_down_peak'=>is_null($plan->base_down_peak) ? NULL : $this->down_peak,
|
||||
'base_down_offpeak'=>is_null($plan->base_down_offpeak) ? NULL : $this->down_offpeak,
|
||||
'base_up_peak'=>is_null($plan->base_up_peak) ? NULL : $this->up_peak,
|
||||
'base_up_offpeak'=>is_null($plan->base_up_offpeak) ? NULL : $this->up_offpeak,
|
||||
'extra_down_peak'=>$plan->extra_down_peak,
|
||||
'extra_down_offpeak'=>$plan->extra_down_offpeak,
|
||||
'extra_up_peak'=>$plan->extra_up_peak,
|
||||
'extra_up_offpeak'=>$plan->extra_up_offpeak,
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
166
modules/adsl/classes/Service/Traffic/Adsl.php
Normal file
166
modules/adsl/classes/Service/Traffic/Adsl.php
Normal file
@@ -0,0 +1,166 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class will take care of ADSL Traffic.
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Service
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_Adsl {
|
||||
protected $so;
|
||||
protected $today;
|
||||
protected $fetchresult = NULL;
|
||||
protected $curlopts = array(
|
||||
CURLOPT_CONNECTTIMEOUT => 60,
|
||||
CURLOPT_FAILONERROR => TRUE,
|
||||
CURLOPT_FOLLOWLOCATION => FALSE,
|
||||
CURLOPT_HEADER => FALSE,
|
||||
CURLOPT_HTTPPROXYTUNNEL => FALSE,
|
||||
CURLOPT_RETURNTRANSFER => TRUE,
|
||||
CURLOPT_TIMEOUT => 30,
|
||||
CURLOPT_SSL_VERIFYHOST => FALSE,
|
||||
CURLOPT_SSL_VERIFYPEER => FALSE,
|
||||
CURLOPT_VERBOSE => FALSE,
|
||||
);
|
||||
|
||||
/**
|
||||
* Setup this class. We need to get our supplier details out of the database.
|
||||
*/
|
||||
public function __construct() {
|
||||
// Our DB record must be the suffix of this class name
|
||||
$supplier = preg_replace('/^'.get_parent_class($this).'_/','',get_class($this));
|
||||
|
||||
$so = ORM::factory('ADSL_Supplier')
|
||||
->where('name','=',$supplier)
|
||||
->find();
|
||||
|
||||
if (! $so->loaded())
|
||||
throw new Kohana_Exception('Supplier :supplier not defined in the database',array(':supplier'=>$supplier));
|
||||
|
||||
$this->so = $so;
|
||||
$this->today = date('Y-m-d',strtotime('yesterday'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of this class
|
||||
*
|
||||
* @return HeadImage
|
||||
*/
|
||||
public static function instance($supplier) {
|
||||
$sc = Kohana::classname(get_called_class().'_'.$supplier);
|
||||
|
||||
if (! class_exists($sc))
|
||||
throw new Kohana_Exception('Class doesnt exist for :supplier',array(':supplier'=>$supplier));
|
||||
else
|
||||
return new $sc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last date we obtained the stats.
|
||||
*/
|
||||
private function last_update() {
|
||||
return $this->so->stats_lastupdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Traffic data from supplier
|
||||
*/
|
||||
public function update_traffic() {
|
||||
if (Minion_CLI::options('verbose'))
|
||||
echo ' - Last: '.date('Y-m-d',strtotime($this->last_update().'+1 day'))."\n";
|
||||
|
||||
$alreadyrun = FALSE;
|
||||
for ($querydate=date('Y-m-d',strtotime($this->last_update().'+1 day'));
|
||||
$querydate<=$this->today;
|
||||
$querydate=date('Y-m-d',strtotime($querydate.'+1 day'))) {
|
||||
|
||||
if (Minion_CLI::options('verbose'))
|
||||
echo " - Date: $querydate\n";
|
||||
|
||||
$goodfetch = false;
|
||||
// @todo log this fetch in a "log"
|
||||
|
||||
// Supplier specific output
|
||||
// Data returned should be in MB's
|
||||
$data = $this->getdata($querydate);
|
||||
|
||||
if (Minion_CLI::options('verbose'))
|
||||
print_r($data);
|
||||
|
||||
if (! $this->fetchresult) {
|
||||
echo 'Bad fetch'.get_class($this);
|
||||
break;
|
||||
}
|
||||
|
||||
$traffic = ORM::factory('Service_Plugin_Adsl_Traffic');
|
||||
foreach ($data as $item) {
|
||||
$traffic->values($item,array_keys($item));
|
||||
$traffic->supplier_id = $this->so->id;
|
||||
|
||||
if ($traffic->check())
|
||||
$traffic->save();
|
||||
|
||||
if (! $traffic->saved())
|
||||
throw new Kohana_Exception('Unable to save traffic record');
|
||||
|
||||
$traffic->clear();
|
||||
}
|
||||
}
|
||||
|
||||
$this->so->stats_lastupdate = $this->today;
|
||||
$this->so->save();
|
||||
}
|
||||
|
||||
public function charge_excess_traffic() {
|
||||
$date = strtotime('last month');
|
||||
|
||||
// @todo need a way to find out services that have traffic charges dynamically.
|
||||
foreach ($this->so->services() as $so) {
|
||||
if ($charge = $so->plugin()->traffic_lastmonth_exceed(FALSE,$date)) {
|
||||
foreach ($charge as $metric => $details) {
|
||||
$co = ORM::factory('Charge');
|
||||
|
||||
$co->status = 0;
|
||||
$co->sweep_type = 6;
|
||||
$co->account_id = $so->account_id;
|
||||
$co->service_id = $so->id;
|
||||
$co->amount = $details['rate'];
|
||||
// @todo This needs to be calculated.
|
||||
$co->taxable = TRUE;
|
||||
$co->quantity = ceil($details['excess']/1000);
|
||||
$co->description = _('Excess Traffic');
|
||||
// @todo This need to be improved = strtotime function should be the one used in the function call
|
||||
$co->attributes = implode("\n",array(
|
||||
sprintf('ADSL Service==%s',$so->plugin()->service_number),
|
||||
sprintf('Allowance==%s',$details['allowance']),
|
||||
sprintf('Metric==%s',$metric),
|
||||
sprintf('Used==%s',$details['used']),
|
||||
sprintf('Month==%s',date('Y-m',$date)),
|
||||
));
|
||||
|
||||
$co->check();
|
||||
$co->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function alert_traffic() {
|
||||
$et = Email_Template::instance('adsl_traffic_notice');
|
||||
|
||||
foreach ($this->so->services() as $so) {
|
||||
if (! $so->plugin()->report_traffic())
|
||||
continue;
|
||||
|
||||
// Get our variable data
|
||||
$et->to = array('account'=>array($so->account_id));
|
||||
$et->variables = $so->plugin()->template_variables($et->variables());
|
||||
|
||||
$et->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
186
modules/adsl/classes/Service/Traffic/Adsl/Exetelhspa.php
Normal file
186
modules/adsl/classes/Service/Traffic/Adsl/Exetelhspa.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is able to collect traffic information for Exetel hspa
|
||||
*
|
||||
* Traffic information is collected by each service, and cached,
|
||||
* returning just the date in question.
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Service
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl {
|
||||
private $login_user_field = 'login_name';
|
||||
private $login_pass_field = 'password';
|
||||
private $date_field = 'date';
|
||||
|
||||
static $result = array();
|
||||
|
||||
/**
|
||||
* Get the data for Exetel hspa services
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getdata($date) {
|
||||
// Assume we have a good fetch, unless otherwise specified.
|
||||
$this->fetchresult = TRUE;
|
||||
|
||||
// If we have already collected the date data, return it.
|
||||
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';
|
||||
|
||||
// Find our services that need to be collected this way.
|
||||
$update = array();
|
||||
|
||||
foreach ($this->so->services() as $so) {
|
||||
if (Minion_CLI::options('verbose'))
|
||||
echo " = Service: ".$so->name()."\n";
|
||||
|
||||
if ($so->plugin()->service_stats_collect AND $so->plugin()->service_stats_lastupdate < $date) {
|
||||
// Start Session
|
||||
$request = Request::factory($this->so->stats_url)
|
||||
->method('POST')
|
||||
->post($this->login_user_field,$so->plugin()->service_username)
|
||||
->post($this->login_pass_field,$so->plugin()->service_password)
|
||||
->post('doLogin',1)
|
||||
->post('submit','Login');
|
||||
|
||||
$request->client()->options($this->curlopts+array(
|
||||
CURLOPT_COOKIEJAR=>sprintf('/tmp/usage.cookies.%s.txt',$so->plugin()->service_number),
|
||||
));
|
||||
|
||||
$response = $request->execute();
|
||||
$data = $response->body();
|
||||
|
||||
if (! $data) {
|
||||
// @todo Log into a log file
|
||||
printf('Bad fetch for %s [%s]',$so->plugin()->service_number,$this->so->stats_lastupdate);
|
||||
#$html = new simple_html_dom();
|
||||
#$html->load($data);
|
||||
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.login.html',$so->plugin()->service_number,'login'));
|
||||
continue;
|
||||
}
|
||||
|
||||
for ($servicedate=date('Y-m-d',strtotime($this->so->stats_lastupdate.'+1 day'));
|
||||
$servicedate <= $this->today;
|
||||
$servicedate=date('Y-m-d',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01')))) {
|
||||
#print_r(array('sn'=>$so->plugin()->service_number,'sd'=>$servicedate));
|
||||
|
||||
$lastday = date('Y-m-d',strtotime('-1 second',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01'))));
|
||||
if (strtotime($lastday) > time())
|
||||
$lastday = date('Y-m-d',strtotime('yesterday'));
|
||||
|
||||
$html = new simple_html_dom();
|
||||
$notdebug = TRUE;
|
||||
if ($notdebug) {
|
||||
$request = Request::factory($this->so->stats_url.'usage_customize_query.php')
|
||||
->method('POST')
|
||||
->post('year_search_key',date('Y',strtotime($servicedate)))
|
||||
->post('month_search_key',date('m',strtotime($servicedate)))
|
||||
->post('start_day_search_key',date('d',strtotime($servicedate)))
|
||||
->post('end_day_search_key',date('d',strtotime($lastday)))
|
||||
->post('do_usage_search',1);
|
||||
|
||||
$request->client()->options($this->curlopts+array(
|
||||
CURLOPT_COOKIEFILE=>sprintf('/tmp/usage.cookies.%s.txt',$so->plugin()->service_number),
|
||||
));
|
||||
|
||||
$response = $request->execute();
|
||||
$result = $response->body();
|
||||
|
||||
$html->load($result);
|
||||
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->plugin()->service_number,$servicedate)); die();
|
||||
} else {
|
||||
$html->load_file(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->plugin()->service_number,$servicedate));
|
||||
}
|
||||
|
||||
$header = array();
|
||||
$data = array();
|
||||
|
||||
foreach ($html->find('fieldset') as $index => $fieldset) {
|
||||
if (! preg_match('/^Usage Detail/',$fieldset->find('legend',0)->plaintext))
|
||||
continue;
|
||||
|
||||
#echo "X:";print_r($fieldset->find('table',0)->find('tr')->plaintext); echo "\n";
|
||||
foreach ($fieldset->find('table',0)->find('tr') as $key => $values) {
|
||||
foreach ($values->children() as $a => $b) {
|
||||
#print_r(array('a'=>$a,'b'=>$b));
|
||||
|
||||
# Header
|
||||
if ($key == 0) {
|
||||
switch ($b->plaintext) {
|
||||
case 'Date': $header[$a] = 'date'; break;
|
||||
case 'OffPeak Upload': $header[$a] = 'up_offpeak'; break;
|
||||
case 'Peak Upload': $header[$a] = 'up_peak'; break;
|
||||
case 'Upload': $header[$a] = 'up_peak'; break;
|
||||
case 'OffPeak Download': $header[$a] = 'down_offpeak'; break;
|
||||
case 'Peak Download': $header[$a] = 'down_peak'; break;
|
||||
case 'Download': $header[$a] = 'down_peak'; break;
|
||||
case 'Duration': break;
|
||||
case 'Total': break;
|
||||
default:
|
||||
printf('Unkown header :%s',$b->plaintext);
|
||||
$this->fetchresult = FALSE;
|
||||
continue;
|
||||
}
|
||||
#echo "INDEX: $key:$a\n";
|
||||
#echo "TAG: ".$b->tag."\n";
|
||||
#echo "HEADER: ".$b->plaintext."\n";
|
||||
|
||||
# Data
|
||||
} else {
|
||||
if (isset($header[$a]))
|
||||
$data[$header[$a]] = $b->plaintext;
|
||||
#echo "INDEX: $key:$a\n";
|
||||
#echo "TAG: ".$b->tag."\n";
|
||||
#echo "VALUES: ".$b->plaintext."\n";
|
||||
}
|
||||
}
|
||||
#print_r($data);
|
||||
|
||||
if (isset($data['date']) && preg_match('/^[0-9]{4}/',$data['date'])) {
|
||||
$sdate = date('Y-m-d',strtotime($data['date']));
|
||||
unset($data['date']);
|
||||
|
||||
if (isset($update[$so->plugin()->service_number][$sdate]))
|
||||
foreach ($data as $key => $value)
|
||||
$update[$so->plugin()->service_number][$sdate][$key] += $value;
|
||||
else
|
||||
$update[$so->plugin()->service_number][$sdate] = $data;
|
||||
|
||||
$update[$so->plugin()->service_number][$sdate]['service'] = $so->plugin()->service_number;
|
||||
$update[$so->plugin()->service_number][$sdate]['date'] = $sdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we got here and have data, we had a good fetch, update the stats date
|
||||
$so->plugin()->service_stats_lastupdate = $lastday;
|
||||
$so->plugin()->save();
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no updates, return an empty array
|
||||
if (! $update)
|
||||
return array();
|
||||
|
||||
// Reformat the data into date order.
|
||||
foreach ($update as $service => $sdata)
|
||||
foreach ($sdata as $sdate => $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::$result[$date]))
|
||||
return array();
|
||||
|
||||
// Return the date we asked for
|
||||
return Service_Traffic_Adsl_Exetelhspa::$result[$date];
|
||||
}
|
||||
}
|
||||
?>
|
179
modules/adsl/classes/Service/Traffic/Adsl/Exetelpe.php
Normal file
179
modules/adsl/classes/Service/Traffic/Adsl/Exetelpe.php
Normal file
@@ -0,0 +1,179 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is able to collect traffic information for Exetel PE
|
||||
*
|
||||
* Traffic information is collected by each service, and cached,
|
||||
* returning just the date in question.
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Service
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_Adsl_Exetelpe extends Service_Traffic_Adsl {
|
||||
private $login_user_field = 'login_name';
|
||||
private $login_pass_field = 'password';
|
||||
private $date_field = 'date';
|
||||
|
||||
static $result = array();
|
||||
|
||||
/**
|
||||
* Get the data for Exetel PE services
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getdata($date) {
|
||||
// Assume we have a good fetch, unless otherwise specified.
|
||||
$this->fetchresult = TRUE;
|
||||
|
||||
// If we have already collected the date data, return it.
|
||||
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';
|
||||
|
||||
// Find our services that need to be collected this way.
|
||||
$update = array();
|
||||
|
||||
foreach ($this->so->services() as $so) {
|
||||
if ($so->plugin()->service_stats_collect AND $so->plugin()->service_stats_lastupdate < $date) {
|
||||
// Start Session
|
||||
$request = Request::factory($this->so->stats_url)
|
||||
->method('POST')
|
||||
->post($this->login_user_field,$so->plugin()->service_username == NULL ? '' : $so->plugin()->service_username)
|
||||
->post($this->login_pass_field,$so->plugin()->service_password == NULL ? '' : $so->plugin()->service_password)
|
||||
->post('doLogin',1)
|
||||
->post('submit','Login');
|
||||
|
||||
$request->client()->options($this->curlopts+array(
|
||||
CURLOPT_COOKIEJAR=>sprintf('/tmp/usage.cookies.%s.txt',$so->plugin()->service_number),
|
||||
));
|
||||
|
||||
$response = $request->execute();
|
||||
$data = $response->body();
|
||||
|
||||
if (! $data) {
|
||||
// @todo Log into a log file
|
||||
printf('Bad fetch for %s [%s]',$so->plugin()->service_number,$this->so->stats_lastupdate);
|
||||
#$html = new simple_html_dom();
|
||||
#$html->load($data);
|
||||
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.login.html',$so->plugin()->service_number,'login'));
|
||||
continue;
|
||||
}
|
||||
|
||||
for ($servicedate=date('Y-m-d',strtotime($this->so->stats_lastupdate.'+1 day'));
|
||||
$servicedate <= $this->today;
|
||||
$servicedate=date('Y-m-d',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01')))) {
|
||||
|
||||
$lastday = date('Y-m-d',strtotime('-1 second',strtotime('+1 month',strtotime(date('Y-m',strtotime($servicedate)).'-01'))));
|
||||
if (strtotime($lastday) > time())
|
||||
$lastday = date('Y-m-d',strtotime('yesterday'));
|
||||
|
||||
$html = new simple_html_dom();
|
||||
$notdebug = TRUE;
|
||||
if ($notdebug) {
|
||||
$request = Request::factory($this->so->stats_url.'usage_customize_query.php')
|
||||
->method('POST')
|
||||
->post('year_search_key',date('Y',strtotime($servicedate)))
|
||||
->post('month_search_key',date('m',strtotime($servicedate)))
|
||||
->post('start_day_search_key',date('d',strtotime($servicedate)))
|
||||
->post('end_day_search_key',date('d',strtotime($lastday)))
|
||||
->post('do_usage_search',1);
|
||||
|
||||
$request->client()->options($this->curlopts+array(
|
||||
CURLOPT_COOKIEFILE=>sprintf('/tmp/usage.cookies.%s.txt',$so->plugin()->service_number),
|
||||
));
|
||||
|
||||
$response = $request->execute();
|
||||
$result = $response->body();
|
||||
|
||||
$html->load($result);
|
||||
#$html->save(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->plugin()->service_number,$servicedate));
|
||||
} else {
|
||||
$html->load_file(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->plugin()->service_number,$servicedate));
|
||||
}
|
||||
|
||||
$header = array();
|
||||
$data = array();
|
||||
|
||||
foreach ($html->find('td') as $index => $fieldset) {
|
||||
if (! preg_match('/Usage Detail/',$fieldset->plaintext))
|
||||
continue;
|
||||
|
||||
foreach ($fieldset->find('table',0)->find('tr',0)->find('td',0)->find('table',0)->find('tr') as $key => $values) {
|
||||
foreach ($values->children() as $a => $b) {
|
||||
#print_r(array('a'=>$a,'b'=>$b->plaintext));
|
||||
|
||||
# Header
|
||||
if ($key == 0) {
|
||||
switch ($b->plaintext) {
|
||||
case 'Date': $header[$a] = 'date'; break;
|
||||
case 'OffPeak Upload': $header[$a] = 'up_offpeak'; break;
|
||||
case 'Peak Upload': $header[$a] = 'up_peak'; break;
|
||||
case 'Upload': $header[$a] = 'up_peak'; break;
|
||||
case 'OffPeak Download': $header[$a] = 'down_offpeak'; break;
|
||||
case 'Peak Download': $header[$a] = 'down_peak'; break;
|
||||
case 'Download': $header[$a] = 'down_peak'; break;
|
||||
case 'Duration': break;
|
||||
default:
|
||||
printf('Unkown header :%s',$b->plaintext);
|
||||
$this->fetchresult = FALSE;
|
||||
continue;
|
||||
}
|
||||
#echo "INDEX: $key:$a\n";
|
||||
#echo "TAG: ".$b->tag."\n";
|
||||
#echo "HEADER: ".$b->plaintext."\n";
|
||||
|
||||
# Data
|
||||
} else {
|
||||
if (isset($header[$a]))
|
||||
$data[$header[$a]] = $b->plaintext;
|
||||
#echo "INDEX: $key:$a\n";
|
||||
#echo "TAG: ".$b->tag."\n";
|
||||
#echo "VALUES: ".$b->plaintext."\n";
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($data['date']) && preg_match('/[0-9]{4}$/',$data['date'])) {
|
||||
$sdate = date('Y-m-d',strtotime(str_replace('/','-',$data['date'])));
|
||||
unset($data['date']);
|
||||
|
||||
if (isset($update[$so->plugin()->service_number][$sdate]))
|
||||
foreach ($data as $key => $value)
|
||||
$update[$so->plugin()->service_number][$sdate][$key] += $value;
|
||||
else
|
||||
$update[$so->plugin()->service_number][$sdate] = $data;
|
||||
|
||||
$update[$so->plugin()->service_number][$sdate]['service'] = $so->plugin()->service_number;
|
||||
$update[$so->plugin()->service_number][$sdate]['date'] = $sdate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we got here and have data, we had a good fetch, update the stats date
|
||||
$so->plugin()->service_stats_lastupdate = $lastday;
|
||||
$so->plugin()->save();
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no updates, return an empty array
|
||||
if (! $update)
|
||||
return array();
|
||||
|
||||
// Reformat the data into date order.
|
||||
foreach ($update as $service => $sdata)
|
||||
foreach ($sdata as $sdate => $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::$result[$date]))
|
||||
return array();
|
||||
|
||||
// Return the date we asked for
|
||||
return Service_Traffic_Adsl_Exetelpe::$result[$date];
|
||||
}
|
||||
}
|
||||
?>
|
67
modules/adsl/classes/Service/Traffic/Adsl/Exetelvisp.php
Normal file
67
modules/adsl/classes/Service/Traffic/Adsl/Exetelvisp.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is able to collect traffic information for Exetel VISP
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Service
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_Adsl_Exetelvisp extends Service_Traffic_Adsl {
|
||||
private $login_user_field = 'username';
|
||||
private $login_pass_field = 'password';
|
||||
private $date_field = 'date';
|
||||
|
||||
protected function getdata($date) {
|
||||
$result = array();
|
||||
|
||||
// Assume we have a bad fetch, unless otherwise specified.
|
||||
$this->fetchresult = FALSE;
|
||||
|
||||
$request = Request::factory($this->so->stats_url)
|
||||
->method('POST')
|
||||
->post($this->login_user_field,$this->so->stats_username)
|
||||
->post($this->login_pass_field,$this->so->stats_password)
|
||||
->post($this->date_field,$date);
|
||||
|
||||
$request->client()->options($this->curlopts+array(
|
||||
CURLOPT_POST => TRUE,
|
||||
));
|
||||
|
||||
$response = $request->execute();
|
||||
$data = $response->body();
|
||||
|
||||
$resultarray = explode("\n",$data);
|
||||
|
||||
// The first field should be a header, so we can ignore it:
|
||||
if (preg_match('/^Login/',$resultarray[0])) {
|
||||
array_shift($resultarray);
|
||||
$this->fetchresult = TRUE;
|
||||
}
|
||||
|
||||
// If we got the expected data, we can parse it.
|
||||
if ($this->fetchresult)
|
||||
foreach ($resultarray as $details) {
|
||||
if (! trim($details))
|
||||
continue;
|
||||
|
||||
$valuesarray = explode(',',$details);
|
||||
|
||||
// Extel VISP stores data in MB's*100.
|
||||
$attrs = array();
|
||||
$attrs['service'] = $valuesarray[0];
|
||||
$attrs['date'] = $valuesarray[1];
|
||||
$attrs['up_peak'] = $valuesarray[2]/100;
|
||||
$attrs['down_peak'] = $valuesarray[3]/100;
|
||||
$attrs['up_offpeak'] = $valuesarray[4]/100;
|
||||
$attrs['down_offpeak'] = $valuesarray[5]/100;
|
||||
|
||||
array_push($result,$attrs);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
61
modules/adsl/classes/Service/Traffic/Adsl/PeopleAgent.php
Normal file
61
modules/adsl/classes/Service/Traffic/Adsl/PeopleAgent.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is able to collect traffic information for People Agent
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Service
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_ADSL_PeopleAgent extends Service_Traffic_ADSL {
|
||||
private $login_user_field = 'username';
|
||||
private $login_pass_field = 'password';
|
||||
private $date_field = 'date';
|
||||
|
||||
protected function getdata($date) {
|
||||
// Assume we have a bad fetch, unless otherwise specified.
|
||||
$this->fetchresult = FALSE;
|
||||
|
||||
$result = array();
|
||||
$url_suffix = sprintf('traffic_V34_%s.xml',date('Ymd',strtotime($date)));
|
||||
|
||||
try {
|
||||
$data = Remote::get($this->so->stats_url.$url_suffix,$this->curlopts+array(
|
||||
CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
|
||||
CURLOPT_USERPWD => sprintf('%s:%s',$this->so->stats_username,$this->so->stats_password),
|
||||
));
|
||||
}
|
||||
|
||||
catch (Exception $e) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->fetchresult = TRUE;
|
||||
foreach (XML::factory(NULL,NULL,$data)->get('user') as $user) {
|
||||
$attrs = array();
|
||||
|
||||
$userattrs = $user->attributes();
|
||||
$attrs['service'] = $userattrs['username'];
|
||||
$attrs['date'] = $date;
|
||||
|
||||
foreach ($user->year->month->day->get('hour') as $hour => $traffic) {
|
||||
foreach (array('external'=>'down_peak','internal'=>'internal','peering'=>'peer') as $t => $k) {
|
||||
$tatters = $traffic->$t->attributes();
|
||||
|
||||
// Traffic is in bytes, need to convert to MB
|
||||
if (empty($attrs[$k]))
|
||||
$attrs[$k] = $tatters['bytes']/1000/1000;
|
||||
else
|
||||
$attrs[$k] += $tatters['bytes']/1000/1000;
|
||||
}
|
||||
}
|
||||
|
||||
array_push($result,$attrs);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
?>
|
123
modules/adsl/classes/Service/Traffic/Adsl/iiNetADSL.php
Normal file
123
modules/adsl/classes/Service/Traffic/Adsl/iiNetADSL.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class is able to collect traffic information for iiNet ADSL
|
||||
*
|
||||
* Traffic information is collected by each service, and cached,
|
||||
* returning just the date in question.
|
||||
*
|
||||
* @package ADSL
|
||||
* @category Service
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Service_Traffic_ADSL_iiNetADSL extends Service_Traffic_ADSL {
|
||||
private $login_user_field = 'username';
|
||||
private $login_pass_field = 'password';
|
||||
private $date_field = 'period';
|
||||
|
||||
static $result = array();
|
||||
|
||||
// The fields in the XML which are translated into database columns
|
||||
private $fields = array(
|
||||
'peak'=>'down_peak',
|
||||
'offpeak'=>'down_offpeak',
|
||||
'uploads'=>'up_peak',
|
||||
'freezone'=>'internal',
|
||||
);
|
||||
|
||||
/**
|
||||
* Get the data for iiNet ADSL services
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getdata($date) {
|
||||
// Assume we have a bad fetch, unless otherwise specified.
|
||||
$this->fetchresult = FALSE;
|
||||
|
||||
// If we have already collected the date data, return it.
|
||||
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();
|
||||
foreach ($this->so->services() as $so) {
|
||||
if ($so->service_adsl->service_stats_collect AND $so->service_adsl->service_stats_lastupdate < $date) {
|
||||
$lastperiod = '';
|
||||
for ($servicedate=date('Y-m-d',strtotime($this->so->stats_lastupdate.'+1 day'));
|
||||
$servicedate <= $this->today;
|
||||
$servicedate=date('Y-m-d',strtotime('+1 day',strtotime($servicedate)))) {
|
||||
|
||||
$debug = FALSE;
|
||||
$debug_file = '/tmp/data';
|
||||
|
||||
// IINET gives us data a month at a time.
|
||||
if ($lastperiod != date('Ym',strtotime($servicedate))) {
|
||||
$lastperiod = date('Ym',strtotime($servicedate));
|
||||
|
||||
$postfields = http_build_query(array(
|
||||
$this->login_user_field=>$so->service_adsl->service_username,
|
||||
$this->login_pass_field=>$so->service_adsl->service_password,
|
||||
'period'=>$lastperiod,
|
||||
'usage_view'=>'month',
|
||||
'action'=>'login',
|
||||
));
|
||||
|
||||
if ($debug AND file_exists($debug_file))
|
||||
$data = file_get_contents($debug_file);
|
||||
else
|
||||
$data = Remote::get($this->so->stats_url,$this->curlopts+array(CURLOPT_POSTFIELDS=>$postfields));
|
||||
|
||||
// @todo There exists a possibility to skip a month, if we get a bad fetch on a previous month.
|
||||
if ($data)
|
||||
$this->fetchresult = TRUE;
|
||||
|
||||
if ($debug AND ! file_exists($debug_file))
|
||||
file_put_contents($debug_file,$data);
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach (XML::factory(NULL,'ii_feed',$data)->volume_usage->volume_usage->get('day_hour') as $day_hour) {
|
||||
$attrs = array();
|
||||
|
||||
$period = $day_hour->attributes();
|
||||
// If we find a field we dont understand, we'll return.
|
||||
if (empty($period['period']))
|
||||
return array();
|
||||
|
||||
foreach ($day_hour->get('usage') as $usage) {
|
||||
$fields = $usage->attributes();
|
||||
|
||||
// If we find a field we dont understand, we'll return.
|
||||
if (empty($fields['type']) OR empty($this->fields[$fields['type']]))
|
||||
return array();
|
||||
|
||||
// Traffic is in bytes, need to convert to MB
|
||||
if (empty($attrs[$this->fields[$fields['type']]]))
|
||||
$attrs[$this->fields[$fields['type']]] = $usage->value()/1000/1000;
|
||||
else
|
||||
$attrs[$this->fields[$fields['type']]] += $usage->value()/1000/1000;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
// If we got here and have data, we had a good fetch, update the stats date
|
||||
$so->service_adsl->service_stats_lastupdate = $date;
|
||||
$so->service_adsl->save();
|
||||
}
|
||||
}
|
||||
|
||||
// If the date we want is empty, return an array
|
||||
if (empty(Service_Traffic_ADSL_iiNetADSL::$result[$date]))
|
||||
return array();
|
||||
|
||||
// Return the date we asked for
|
||||
return Service_Traffic_ADSL_iiNetADSL::$result[$date];
|
||||
}
|
||||
}
|
||||
?>
|
12
modules/adsl/views/adsl/contract_view.php
Normal file
12
modules/adsl/views/adsl/contract_view.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<!-- //@todo To translate -->
|
||||
<table class="box-full">
|
||||
<tr>
|
||||
<td style="width: 60%;">Contract Term</td>
|
||||
<td class="head" colspan="2"><?php echo $record->display('contract_term'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<!-- @todo This should get tax settings from the session -->
|
||||
<td>Minimum Cost</td>
|
||||
<td class="head" colspan="2"><?php echo Currency::display(Tax::add($record->contract_term*$price_base+$price_setup)); ?> <span style="font-size: 80%; font-weight:normal;"><?php printf('(%s * %s + %s)',$record->contract_term,Tax::add($price_base),Tax::add($price_setup)); ?></span></td>
|
||||
</tr>
|
||||
</table>
|
28
modules/adsl/views/product/plugin/adsl/feature_summary.php
Normal file
28
modules/adsl/views/product/plugin/adsl/feature_summary.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<!-- //@todo To translate -->
|
||||
<table class="box-full">
|
||||
<tr>
|
||||
<td style="width: 40%;">Speed</td>
|
||||
<td class="data" style="width: 60%;" colspan="2"><?php echo $po->display('speed'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td>Peak</td>
|
||||
<?php if ($po->base_down_offpeak OR $po->extra_down_offpeak) { ?>
|
||||
<td>Off Peak</td>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Included Download Traffic</td>
|
||||
<!-- // @todo Since price is stored in the DB in GB, so should the traffic. -->
|
||||
<td class="data"><?php echo $po->base_down_peak/1000; ?> GB</td>
|
||||
<td class="data"><?php echo $po->base_down_offpeak ? ($po->base_down_offpeak/1000).'GB' : HTML::nbsp(''); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Extra Download Traffic</td>
|
||||
<td class="data"><?php echo $po->display('extra_down_peak'); ?>/GB</td>
|
||||
<td class="data"><?php echo $po->extra_down_offpeak ? $po->display('extra_down_offpeak').'/GB' : HTML::nbsp(''); ?></td>
|
||||
</tr>
|
||||
</table>
|
46
modules/adsl/views/service/admin/adsl/update.php
Normal file
46
modules/adsl/views/service/admin/adsl/update.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<!-- @todo NEEDS TO BE TRANSLATED -->
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td class="head" colspan="2">Plugin Details</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="width: 40%;">Service Number</td>
|
||||
<td style="width: 60%;" class="data"><?php echo Form::input('plugin[service_number]',$so->service_number); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Address</td>
|
||||
<td class="data"><?php echo Form::input('plugin[service_address]',$so->service_address); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Connect Date</td>
|
||||
<td class="data">
|
||||
<?php echo Form::input('plugin[service_connect_date]',$so->service_connect_date,array('id'=>'service_connect_date')); ?>
|
||||
<?php echo HTML::anchor('#',
|
||||
HTML::image($mediapath->uri(array('file'=>'img/calendar.png')),array('alt'=>_('Calendar'),'style'=>'cursor: pointer;')),
|
||||
array('title'=>'Click to popup a dialog to select a date graphically','onclick'=>"dateSelector('service_connect_date')")); ?>
|
||||
<script type="text/javascript">defaults['service_connect_date'] = '%s';</script>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Contract Date</td>
|
||||
<td class="data">
|
||||
<?php echo Form::input('plugin[service_contract]',$so->service_contract_date,array('id'=>'service_contract_date')); ?>
|
||||
<?php echo HTML::anchor('#',
|
||||
HTML::image($mediapath->uri(array('file'=>'img/calendar.png')),array('alt'=>_('Calendar'),'style'=>'cursor: pointer;')),
|
||||
array('title'=>'Click to popup a dialog to select a date graphically','onclick'=>"dateSelector('service_contract_date')")); ?>
|
||||
<script type="text/javascript">defaults['service_contract_date'] = '%s';</script>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Username</td>
|
||||
<td class="data"><?php echo Form::input('plugin[service_username]',$so->service_username); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Password</td>
|
||||
<td class="data"><?php echo Form::input('plugin[service_password]',$so->service_password); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service IP Address</td>
|
||||
<td class="data"><?php echo Form::input('plugin[ipaddress]',$so->ipaddress); ?></td>
|
||||
</tr>
|
||||
</table>
|
1
modules/adsl/views/service/admin/adslstat/body_data.php
Normal file
1
modules/adsl/views/service/admin/adslstat/body_data.php
Normal file
@@ -0,0 +1 @@
|
||||
<td><?php echo $count; ?></td><td><?php echo $percent; ?></td>
|
1
modules/adsl/views/service/admin/adslstat/body_end.php
Normal file
1
modules/adsl/views/service/admin/adslstat/body_end.php
Normal file
@@ -0,0 +1 @@
|
||||
</tr>
|
4
modules/adsl/views/service/admin/adslstat/body_head.php
Normal file
4
modules/adsl/views/service/admin/adslstat/body_head.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<tr class="list-data">
|
||||
<td><?php echo $speed; ?></td>
|
||||
<td><?php echo $count; ?></td>
|
||||
<td><?php echo $percent; ?></td>
|
1
modules/adsl/views/service/admin/adslstat/foot.php
Normal file
1
modules/adsl/views/service/admin/adslstat/foot.php
Normal file
@@ -0,0 +1 @@
|
||||
</table>
|
3
modules/adsl/views/service/admin/adslstat/head.php
Normal file
3
modules/adsl/views/service/admin/adslstat/head.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<table class="list-box-left">
|
||||
<tr class="list-head">
|
||||
<th><?php echo $name; ?></th>
|
1
modules/adsl/views/service/admin/adslstat/head_data.php
Normal file
1
modules/adsl/views/service/admin/adslstat/head_data.php
Normal file
@@ -0,0 +1 @@
|
||||
<th><?php echo $name; ?></th><th>%</th>
|
1
modules/adsl/views/service/admin/adslstat/head_end.php
Normal file
1
modules/adsl/views/service/admin/adslstat/head_end.php
Normal file
@@ -0,0 +1 @@
|
||||
</tr>
|
11
modules/adsl/views/service/admin/listadslbilling/body.php
Normal file
11
modules/adsl/views/service/admin/listadslbilling/body.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<tr class="<?php echo $i ? 'odd' : 'even'; ?>">
|
||||
<td><?php echo $service->plugin()->display('service_number'); ?></td>
|
||||
<td><?php echo $plan->adsl_supplier_plan->name().($planoverride ? '*' : ''); ?></td>
|
||||
<td><?php echo $service->plugin()->contract_date_start(); ?></td>
|
||||
<td><?php echo $service->plugin()->contract_date_end(); ?></td>
|
||||
<td><?php echo Currency::display($plan->adsl_supplier_plan->base_cost); ?></td>
|
||||
<td><?php echo Currency::display($plan->adsl_supplier_plan->base_cost+$plan->adsl_supplier_plan->tax()); ?></td>
|
||||
<td><input type="checkbox" <?php echo $checked; ?> onchange="paid(this);"/></td>
|
||||
<td><input type="text" name="payment[<?php echo $service->plugin()->service_number; ?>]" value="<?php echo $amount; ?>" id="p<?php echo $service->plugin()->id; ?>" size="8"/></td>
|
||||
<td><?php echo $excess ? sprintf('(%s)',$excess) : ' '; ?></td>
|
||||
</tr>
|
@@ -0,0 +1,4 @@
|
||||
<tr class="head">
|
||||
<td colspan="7"> </td>
|
||||
<td><?php echo $total; ?></td>
|
||||
</tr>
|
@@ -0,0 +1,7 @@
|
||||
<script type="text/javascript" >
|
||||
<!--
|
||||
function paid(form) {
|
||||
alert(form);
|
||||
}
|
||||
//-->
|
||||
</script>
|
10
modules/adsl/views/service/admin/listadslbilling/summary.php
Normal file
10
modules/adsl/views/service/admin/listadslbilling/summary.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<tr class="<?php echo $i ? 'odd' : 'even'; ?>">
|
||||
<td><?php echo $service->plugin()->display('service_number'); ?></td>
|
||||
<td><?php echo $plan->adsl_supplier_plan->name().($planoverride ? '*' : ''); ?></td>
|
||||
<td><?php echo $service->plugin()->contract_date_start(); ?></td>
|
||||
<td><?php echo $service->plugin()->contract_date_end(); ?></td>
|
||||
<td><?php echo Currency::display($service->product->plugin()->adsl_supplier_plan->base_cost); ?></td>
|
||||
<td><?php echo Currency::display($service->product->plugin()->adsl_supplier_plan->base_cost+$service->product->plugin()->adsl_supplier_plan->tax()); ?></td>
|
||||
<td><?php echo $amount; ?></td>
|
||||
<td><?php echo $service->product->plugin()->adsl_supplier_plan->base_cost+$service->product->plugin()->adsl_supplier_plan->tax()-$amount; ?></td>
|
||||
</tr>
|
@@ -0,0 +1,6 @@
|
||||
<tr class="<?php echo $i ? 'odd' : 'even'; ?>">
|
||||
<td><?php echo $service; ?></td>
|
||||
<td><?php echo empty($item['info']) ? ' ' : $item['info']; ?></td>
|
||||
<td><?php echo empty($item['cost']) ? ' ' : $item['cost']; ?></td>
|
||||
<td><?php echo empty($item['credit']) ? ' ' : $item['credit']; ?></td>
|
||||
</tr>
|
@@ -0,0 +1,9 @@
|
||||
<!-- @todo NEEDS TO BE TRANSLATED -->
|
||||
<table class="box-left">
|
||||
<?php foreach ($traffic as $metric => $usage) { ?>
|
||||
<tr>
|
||||
<td><?php echo $metric; ?></td>
|
||||
<td class="head"><?php echo $usage; ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
79
modules/adsl/views/service/user/plugin/adsl/view.php
Normal file
79
modules/adsl/views/service/user/plugin/adsl/view.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<!-- //@todo To translate -->
|
||||
<table class="box-full">
|
||||
<tr>
|
||||
<td class="head" colspan="3">Service Details</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3"> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width: 40%;">Service Number</td>
|
||||
<td style="width: 60%;" class="data"><?php echo $so->display('service_number'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Address</td>
|
||||
<td class="data"><?php echo $so->display('service_address'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Contract Term</td>
|
||||
<td class="data"><?php echo $so->display('contract_term'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Connect Date</td>
|
||||
<td class="data"><?php echo $so->display('service_connect_date'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Contract End Date</td>
|
||||
<td class="data"><?php echo $so->contract_date_end(); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Username</td>
|
||||
<td class="data"><?php echo $so->display('service_username'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service Password</td>
|
||||
<td class="data"><?php # @todo Enable the ability to hide this value echo $so->display('service_password'); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Service IP</td>
|
||||
<td class="data"><?php echo $so->ipaddress(); ?></td>
|
||||
</tr>
|
||||
<?php if ($so->hasOffPeak() AND $so->offpeak_start AND $so->offpeak_end) { ?>
|
||||
<tr>
|
||||
<td>Offpeak Period</td>
|
||||
<td class="data"><?php printf('%s-%s',$so->offpeak_start,$so->offpeak_end); ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
</td>
|
||||
<td style="vertical-align: top;" colspan="2">
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width: 40%;">Traffic Used This Month</td>
|
||||
<td style="width: 60%;" class="data"><?php echo $so->traffic_month(NULL); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Traffic Used Last Month</td>
|
||||
<td class="data"><?php echo $so->traffic_lastmonth(); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<table>
|
||||
<tr>
|
||||
<td>View Daily Traffic for Month</td>
|
||||
<td><?php echo Form::open(); echo Form::select('month',array_merge(array(''),$so->get_traffic_months()),(isset($_POST['month']) ? $_POST['month'] : '')); echo Form::submit('submit',_('Show'),array('class'=>'form_button')); echo Form::close(); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><?php echo $so->graph_traffic(isset($_POST['month']) ? $_POST['month'] : ''); ?></td>
|
||||
<td><?php echo $so->table_traffic(isset($_POST['month']) ? $_POST['month'] : ''); ?></td>
|
||||
</tr>
|
||||
</table>
|
Reference in New Issue
Block a user