diff --git a/application/classes/Controller/Reseller/Welcome.php b/application/classes/Controller/Reseller/Welcome.php index f7899fcb..ee34c1d6 100644 --- a/application/classes/Controller/Reseller/Welcome.php +++ b/application/classes/Controller/Reseller/Welcome.php @@ -69,7 +69,7 @@ class Controller_Reseller_Welcome extends Controller_Welcome { ->title_icon('icon-info-sign') ->span(6) ->body(Table::factory() - ->data($o->list_due()) + ->data($o->list_due(time())) ->columns(array( 'id'=>'ID', 'due_date'=>'Due', diff --git a/application/classes/StaticList/ItemType.php b/application/classes/StaticList/ItemType.php index a2c934df..a7dc928b 100644 --- a/application/classes/StaticList/ItemType.php +++ b/application/classes/StaticList/ItemType.php @@ -18,6 +18,7 @@ class StaticList_ItemType extends StaticList { 3=> _('Service Change Fee'), 4=> _('Service Connection Fee'), 5=>_('Excess Usage'), // Excess Service Item, of item 0 + 6=> _('Service Cancellation Fee'), 125=>_('Payment Fee'), // Payment processing fee 126=> _('Rounding'), 127=> _('Late Payment Fee'), diff --git a/modules/adsl/classes/ADSL.php b/modules/adsl/classes/ADSL.php deleted file mode 100644 index d599fcc0..00000000 --- a/modules/adsl/classes/ADSL.php +++ /dev/null @@ -1,134 +0,0 @@ -'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('Product_Plugin_Adsl',$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; - } -} -?> diff --git a/modules/adsl/classes/Controller/Admin/Adsl.php b/modules/adsl/classes/Controller/Admin/Adsl.php index 720873c4..f22d016f 100644 --- a/modules/adsl/classes/Controller/Admin/Adsl.php +++ b/modules/adsl/classes/Controller/Admin/Adsl.php @@ -14,6 +14,7 @@ class Controller_Admin_Adsl extends Controller_Adsl { 'index'=>TRUE, 'edit'=>TRUE, 'list'=>TRUE, + 'stat'=>TRUE, 'traffic'=>TRUE, ); @@ -119,6 +120,51 @@ class Controller_Admin_Adsl extends Controller_Adsl { ); } + /** + * Usage statistics for the previous moth + */ + public function action_stat() { + // @todo This needs to be configurable. + $traffic = array(1000,2000,5000,10000,25000,50000,75000,100000); + + $svs = ORM::factory('Service')->list_bylistgroup('ADSL'); + $stats = array(); + $output = ''; + $ts = 0; + + foreach ($svs as $a=>$so) { + // Number of services + if (! isset($stats[$so->product->plugin()->supplier_plan->speed]['c'])) + $stats[$so->product->plugin()->supplier_plan->speed]['c'] = 0; + + $stats[$so->product->plugin()->supplier_plan->speed]['c']++; + $ts++; + + $a = 0; + foreach (array_reverse($traffic) as $i) { + if ($i < $so->plugin()->traffic_month(strtotime('last month'),TRUE)) + break; + + $a = $i; + } + + if (! isset($stats[$so->product->plugin()->supplier_plan->speed]['d'][$a])) + $stats[$so->product->plugin()->supplier_plan->speed]['d'][$a] = 0; + + $stats[$so->product->plugin()->supplier_plan->speed]['d'][$a]++; + } + + Block::factory() + ->title('ADSL Traffic Summary Stats - Last Month') + ->title_icon('icon-list') + ->body( + View::factory('adsl/admin/stats') + ->set('stats',$stats) + ->set('traffic',$traffic) + ->set('ts',$ts) + ); + } + /** * Reconcile billing for an ADSL supplier */ diff --git a/modules/adsl/classes/Controller/Admin/Service/Adsl.php b/modules/adsl/classes/Controller/Admin/Service/Adsl.php deleted file mode 100644 index e9fbd9f1..00000000 --- a/modules/adsl/classes/Controller/Admin/Service/Adsl.php +++ /dev/null @@ -1,60 +0,0 @@ -TRUE, - ); - - public function action_stat() { - // @todo This needs to be configurable. - $traffic = array(1000,2000,5000,10000,25000,50000,75000,100000); - - $svs = ORM::factory('Service')->list_bylistgroup('ADSL'); - $stats = array(); - $output = ''; - $ts = 0; - - foreach ($svs as $a=>$so) { - // Number of services - if (! isset($stats[$so->product->plugin()->adsl_supplier_plan->speed]['c'])) - $stats[$so->product->plugin()->adsl_supplier_plan->speed]['c'] = 0; - - $stats[$so->product->plugin()->adsl_supplier_plan->speed]['c']++; - $ts++; - - // Amount of traffic - $t = array_sum($so->plugin()->traffic_lastmonth(FALSE)); - $a = 0; - foreach (array_reverse($traffic) as $i) { - if ($i < $t) - break; - $a = $i; - } - - if (! isset($stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a])) - $stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a] = 0; - - $stats[$so->product->plugin()->adsl_supplier_plan->speed]['d'][$a]++; - } - - Block::factory() - ->title('ADSL Traffic Summary Stats - Last Month') - ->title_icon('icon-list') - ->body( - View::factory('service/admin/adslstat') - ->set('stats',$stats) - ->set('traffic',$traffic) - ->set('ts',$ts) - ); - } -} -?> diff --git a/modules/adsl/classes/Service/Traffic/Adsl/Exetelhspa.php b/modules/adsl/classes/Service/Traffic/Adsl/Exetelhspa.php index b9843f80..65317f4c 100644 --- a/modules/adsl/classes/Service/Traffic/Adsl/Exetelhspa.php +++ b/modules/adsl/classes/Service/Traffic/Adsl/Exetelhspa.php @@ -42,28 +42,39 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl { echo " = Service: ".$so->name()."\n"; if ($so->plugin()->service_stats_collect AND $so->plugin()->service_stats_lastupdate < $date) { - // Start Session - $request = Request::factory($this->aso->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'); + $debug = FALSE; - $request->client()->options($this->curlopts+array( - CURLOPT_COOKIEJAR=>sprintf('/tmp/usage.cookies.%s.txt',$so->plugin()->service_number), - )); + if (! $debug) { + // Start Session + $request = Request::factory($this->aso->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'); - $response = $request->execute(); - $data = $response->body(); + $request->client()->options($this->curlopts+array( + CURLOPT_COOKIEJAR=>sprintf('/tmp/usage.cookies.%s.txt',$so->plugin()->service_number), + )); - if (! $data) { - // @todo Log into a log file - printf('Bad fetch for %s [%s]',$so->plugin()->service_number,$this->aso->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; + $response = $request->execute(); + $data = $response->body(); + + if (! $data) { + // Record some debugging if we are in verbose mode + if (Minion_CLI::options('verbose')) { + file_put_contents('/tmp/osb.response.txt',print_r($response,TRUE)); + file_put_contents('/tmp/osb.request.txt',print_r($request,TRUE)); + file_put_contents('/tmp/osb.data.txt',print_r($data,TRUE)); + } + + // @todo Log into a log file + printf('Bad fetch for %s [%s]',$so->plugin()->service_number,$this->aso->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->aso->stats_lastupdate.'+1 day')); @@ -75,9 +86,13 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl { if (strtotime($lastday) > time()) $lastday = date('Y-m-d',strtotime('yesterday')); + if (Minion_CLI::options('verbose')) { + echo " - From Date: ".$servicedate."\n"; + echo " - To Date: ".$lastday."\n"; + } + $html = new simple_html_dom(); - $notdebug = TRUE; - if ($notdebug) { + if (! $debug) { $request = Request::factory($this->aso->stats_url.'usage_customize_query.php') ->method('POST') ->post('year_search_key',date('Y',strtotime($servicedate))) @@ -94,22 +109,31 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl { $result = $response->body(); $html->load($result); - #$html->save(sprintf('/afs/local/tmp/usage.%s.%s.html',$so->plugin()->service_number,$servicedate)); die(); + + if (Minion_CLI::options('verbose')) + $html->save(sprintf('/tmp/osb.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)); + if (Minion_CLI::options('verbose')) + echo " ! From Debug File: \n"; + + $html->load_file(sprintf('/tmp/osb.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)) + if (! preg_match('/Usage Detail/',$fieldset->find('legend',0)->plaintext)) continue; - #echo "X:";print_r($fieldset->find('table',0)->find('tr')->plaintext); echo "\n"; + #if (Minion_CLI::options('verbose')) + # echo "X:";print_r((string)$fieldset->find('table',0)); 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)); + #if (Minion_CLI::options('verbose')) + # print_r(array('a'=>(string)$a,'b'=>(string)$b)); # Header if ($key == 0) { @@ -129,7 +153,7 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl { continue; } #echo "INDEX: $key:$a\n"; - #echo "TAG: ".$b->tag."\n"; + #echo "TAG: ".$b->tag."\n";d #echo "HEADER: ".$b->plaintext."\n"; # Data @@ -141,7 +165,9 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl { #echo "VALUES: ".$b->plaintext."\n"; } } - #print_r($data); + + #if (Minion_CLI::options('verbose')) + # print_r($data); if (isset($data['date']) && preg_match('/^[0-9]{4}/',$data['date'])) { $sdate = date('Y-m-d',strtotime($data['date'])); @@ -158,11 +184,18 @@ class Service_Traffic_Adsl_Exetelhspa extends Service_Traffic_Adsl { } } } + + #if (Minion_CLI::options('verbose')) + # print_r($update); } // 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(); + $x = $so->plugin(); + $x->service_stats_lastupdate = $lastday; + $x->save(); + + if (Minion_CLI::options('verbose')) + printf(" = Update Service %s to %s\n",$so->plugin()->service_number,$so->plugin()->service_stats_lastupdate); } } diff --git a/modules/adsl/views/service/admin/adslstat.php b/modules/adsl/views/adsl/admin/stats.php similarity index 100% rename from modules/adsl/views/service/admin/adslstat.php rename to modules/adsl/views/adsl/admin/stats.php diff --git a/modules/invoice/classes/Model/Invoice.php b/modules/invoice/classes/Model/Invoice.php index 5f8483f1..532289ef 100644 --- a/modules/invoice/classes/Model/Invoice.php +++ b/modules/invoice/classes/Model/Invoice.php @@ -746,11 +746,8 @@ class Model_Invoice extends ORM_OSB implements Cartable { public function list_due($time=NULL,$authorised=TRUE) { $result = array(); - if (is_null($time)) - $time = time(); - foreach ($this->_list_due($authorised) as $io) - if ($io->due_date > $time) + if (is_null($time) OR $io->due_date > $time) array_push($result,$io); return $result; diff --git a/modules/service/views/service/admin/edit.php b/modules/service/views/service/admin/edit.php index 91980d32..cbc85d75 100644 --- a/modules/service/views/service/admin/edit.php +++ b/modules/service/views/service/admin/edit.php @@ -35,6 +35,12 @@ +
+
+ price_override,array('label'=>'Override Price','class'=>'span1')); ?> +
+
+