diff --git a/application/classes/Controller/Reseller/Welcome.php b/application/classes/Controller/Reseller/Welcome.php
index 4c29229e..f544f4ad 100644
--- a/application/classes/Controller/Reseller/Welcome.php
+++ b/application/classes/Controller/Reseller/Welcome.php
@@ -13,6 +13,7 @@ class Controller_Reseller_Welcome extends Controller_Welcome {
protected $auth_required = TRUE;
public $secure_actions = array(
'index'=>TRUE,
+ 'revenue'=>TRUE,
);
public function action_index() {
@@ -102,5 +103,32 @@ class Controller_Reseller_Welcome extends Controller_Welcome {
))
);
}
+
+ /**
+ * Show Revenue Summary Information
+ */
+ public function action_revenue() {
+ $result = array();
+
+ // ADSL
+ $svs = ORM::factory('Service')->where_authorised()->list_active();
+ foreach ($svs as $so) {
+ if (! isset($result[$so->product->prod_plugin_file][$so->product->supplier()])) {
+ $result[$so->product->prod_plugin_file][$so->product->supplier()]['count'] = 0;
+ $result[$so->product->prod_plugin_file][$so->product->supplier()]['cost'] = 0;
+ $result[$so->product->prod_plugin_file][$so->product->supplier()]['revenue'] = 0;
+ }
+
+ $result[$so->product->prod_plugin_file][$so->product->supplier()]['count']++;
+ $result[$so->product->prod_plugin_file][$so->product->supplier()]['cost'] += $so->product->cost(TRUE);
+ $result[$so->product->prod_plugin_file][$so->product->supplier()]['revenue'] += $so->revenue(TRUE);
+ }
+
+ Block::factory()
+ ->title('Revenue / Cost Analysis')
+ ->title_icon('icon-info-sign')
+ ->span(6)
+ ->body(View::factory('summary/reseller/index')->set('o',$result));
+ }
}
?>
diff --git a/application/classes/Period.php b/application/classes/Period.php
index eca3c874..77e6fe62 100644
--- a/application/classes/Period.php
+++ b/application/classes/Period.php
@@ -125,5 +125,19 @@ class Period {
return $result;
}
+
+ public static function multiple($rs) {
+ switch($rs) {
+ case 0: $multiple=52; break;
+ case 1: $multiple=12; break;
+ case 2: $multiple=4; break;
+ case 3: $multiple=2; break;
+ case 4: $multiple=1; break;
+ case 5: $multiple=0.5; break;
+ case 6: $multiple=0.33; break;
+ }
+
+ return $multiple;
+ }
}
?>
diff --git a/application/config/debug.php b/application/config/debug.php
index f3e3a1e9..6db7ce9c 100644
--- a/application/config/debug.php
+++ b/application/config/debug.php
@@ -17,11 +17,7 @@ return array
'checkout_notify'=>FALSE, // Test mode to test a particular checkout_notify item
'disabled_noaccess_redirect'=>FALSE, // Disable redirect when noaccess
'email_admin_only'=> array( // Override emails and send them to an admin instead
- 'task_invoice_list_overdue'=>array('deon@leenooks.net'=>'Deon George'),
- 'task_invoice_remind_overdue_1'=>array('deon@leenooks.net'=>'Deon George'),
- 'task_invoice_remind_overdue_2'=>array('deon@leenooks.net'=>'Deon George'),
- 'task_invoice_remind_overdue_3'=>array('deon@leenooks.net'=>'Deon George'),
- 'adsl_traffic_notice'=>array('deon@leenooks.net'=>'Deon George'),
+ #'task_invoice_list_overdue'=>array('deon@leenooks.net'=>'Deon George'),
),
'invoice'=>0, // Number of invoices to generate in a pass
'site'=>FALSE, // Glogal site debug
diff --git a/application/views/summary/reseller/index.php b/application/views/summary/reseller/index.php
new file mode 100644
index 00000000..96cbb9c2
--- /dev/null
+++ b/application/views/summary/reseller/index.php
@@ -0,0 +1,29 @@
+
+
+
+ Category |
+ Supplier |
+ Count |
+ Revenue |
+ Cost |
+ % |
+
+
+
+
+ $details) : ?>
+ | |
+
+
+ $summary) : ?>
+ |
+ |
+ |
+ |
+ |
+ |
+
+
+
+
+
diff --git a/modules/adsl/classes/Adsl/Billing/Exetelvisp.php b/modules/adsl/classes/Adsl/Billing/Exetelvisp.php
index 8b7de3f5..12ac310b 100644
--- a/modules/adsl/classes/Adsl/Billing/Exetelvisp.php
+++ b/modules/adsl/classes/Adsl/Billing/Exetelvisp.php
@@ -13,6 +13,7 @@ class ADSL_Billing_Exetelvisp {
private $data = NULL;
private $data_exception = NULL;
private $exception = array();
+ private $excess = 0;
private $total = 0;
public function excess($service) {
@@ -56,6 +57,7 @@ class ADSL_Billing_Exetelvisp {
if ($cost != $this->charge($service))
$this->exception[$service]['info'] = 'Charging difference: '.Currency::display($cost-$this->charge($service));
+ $this->excess += $this->excess($service);
$this->total += $this->charge($service);
}
}
@@ -151,8 +153,11 @@ class ADSL_Billing_Exetelvisp {
return $this;
}
- public function total($format=FALSE) {
+ public function totalcharge($format=FALSE) {
return $format ? Currency::display($this->total) : $this->total;
}
+ public function totalexcess($format=FALSE) {
+ return $format ? Currency::display($this->excess) : $this->excess;
+ }
}
?>
diff --git a/modules/adsl/classes/Model/Product/Plugin/Adsl.php b/modules/adsl/classes/Model/Product/Plugin/Adsl.php
index 0d4bc8b6..deed99c1 100644
--- a/modules/adsl/classes/Model/Product/Plugin/Adsl.php
+++ b/modules/adsl/classes/Model/Product/Plugin/Adsl.php
@@ -32,12 +32,22 @@ class Model_Product_Plugin_Adsl extends Model_Product_Plugin {
}
// Our required abstract methods
+ public function cost($annual=FALSE) {
+ $x = $this->adsl_supplier_plan->total();
+
+ return $annual ? $x*12 : $x;
+ }
+
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);
}
+ public function supplier() {
+ return $this->adsl_supplier_plan->supplier_id;
+ }
+
/**
* Show the ADSL allowance as a peak/offpeak metric
*/
diff --git a/modules/adsl/classes/Service/Traffic/Adsl.php b/modules/adsl/classes/Service/Traffic/Adsl.php
index 417952ae..16516dc0 100644
--- a/modules/adsl/classes/Service/Traffic/Adsl.php
+++ b/modules/adsl/classes/Service/Traffic/Adsl.php
@@ -119,6 +119,8 @@ abstract class Service_Traffic_Adsl {
$co->sweep_type = 6;
$co->account_id = $so->account_id;
$co->service_id = $so->id;
+ // @todo This needs to be calculated.
+ $co->type = 5;
$co->amount = $details['rate'];
// @todo This needs to be calculated.
$co->taxable = TRUE;
diff --git a/modules/adsl/views/adsl/reseller/billing.php b/modules/adsl/views/adsl/reseller/billing.php
index f65c9996..393cfec9 100644
--- a/modules/adsl/views/adsl/reseller/billing.php
+++ b/modules/adsl/views/adsl/reseller/billing.php
@@ -1,6 +1,7 @@
Service |
+ ID |
Supplier Plan |
Contract Start |
Contract End |
@@ -16,6 +17,7 @@
|
+ id),$so->id); ?> |
adsl_supplier_plan->name().($p->provided_adsl_plan_id ? '*' : ''); ?> |
contract_date_start(TRUE); ?> |
contract_date_end(TRUE); ?> |
@@ -26,6 +28,6 @@
- | total(TRUE); ?> | |
+ | totalcharge(TRUE); ?> | | totalexcess(TRUE); ?> |
diff --git a/modules/domain/classes/Model/Product/Plugin/Domain.php b/modules/domain/classes/Model/Product/Plugin/Domain.php
index e4c4c0c6..30e9d438 100644
--- a/modules/domain/classes/Model/Product/Plugin/Domain.php
+++ b/modules/domain/classes/Model/Product/Plugin/Domain.php
@@ -16,6 +16,13 @@ class Model_Product_Plugin_Domain extends Model_Product_Plugin {
// Our required abstract methods
public function admin_update() {}
+
+ public function cost($annual=FALSE) {
+ $x = 0;
+
+ return $annual ? $x*12 : $x;
+ }
+
public function feature_summary() {}
// @todo This is not used, but should be.
@@ -37,5 +44,9 @@ class Model_Product_Plugin_Domain extends Model_Product_Plugin {
return $output;
}
+
+ public function supplier() {
+ return 'internal';
+ }
}
?>
diff --git a/modules/host/classes/Model/Product/Plugin/Host.php b/modules/host/classes/Model/Product/Plugin/Host.php
index fe31feca..2567b972 100644
--- a/modules/host/classes/Model/Product/Plugin/Host.php
+++ b/modules/host/classes/Model/Product/Plugin/Host.php
@@ -16,10 +16,20 @@ class Model_Product_Plugin_Host extends Model_Product_Plugin {
// Our required abstract methods
public function admin_update() {}
+
+ public function cost($annual=FALSE) {
+ $x = 0;
+
+ return $annual ? $x*12 : $x;
+ }
+
public function feature_summary() {}
// @todo This is not used, but should be.
- public function order_features() {
+ public function order_features() {}
+
+ public function supplier() {
+ return 'internal';
}
}
?>
diff --git a/modules/product/classes/Model/Product.php b/modules/product/classes/Model/Product.php
index 33218abc..62703b96 100644
--- a/modules/product/classes/Model/Product.php
+++ b/modules/product/classes/Model/Product.php
@@ -51,6 +51,10 @@ class Model_Product extends ORM_OSB {
return $this->avail_category;
}
+ public function cost($annual=FALSE) {
+ return $this->plugin() ? $this->plugin()->cost($annual) : 0;
+ }
+
/**
* Return the translated description for a category.
*/
@@ -134,6 +138,10 @@ class Model_Product extends ORM_OSB {
return $active ? $this->service->where_active() : $this->service;
}
+ public function supplier() {
+ return $this->plugin() ? $this->plugin()->supplier() : 'other';
+ }
+
private function translate() {
return $this->product_translate->where('language_id','=',Config::language())->find();
}
diff --git a/modules/product/classes/Model/Product/Plugin.php b/modules/product/classes/Model/Product/Plugin.php
index 9934d828..a5f097df 100644
--- a/modules/product/classes/Model/Product/Plugin.php
+++ b/modules/product/classes/Model/Product/Plugin.php
@@ -19,10 +19,17 @@ abstract class Model_Product_Plugin extends ORM_OSB {
*/
abstract public function admin_update();
+ /**
+ * The cost of this service
+ */
+ abstract public function cost($annual=FALSE);
+
/**
* The feature summary should be implemented in plugins.
* It is displayed on the product overview page, as a summary of the products features.
*/
abstract public function feature_summary();
+
+ abstract public function supplier();
}
?>
diff --git a/modules/service/classes/Model/Service.php b/modules/service/classes/Model/Service.php
index e0248810..c3e4aa47 100644
--- a/modules/service/classes/Model/Service.php
+++ b/modules/service/classes/Model/Service.php
@@ -203,6 +203,15 @@ class Model_Service extends ORM_OSB {
return $type ? $o->$type : $o;
}
+ public function revenue($annual=FALSE) {
+ $multiple = $annual ? Period::multiple($this->recur_schedule) : 1;
+
+ if ($this->suspend_billing)
+ $multiple = 0;
+
+ return $this->price(TRUE)*$multiple;
+ }
+
public function service_change() {
return $this->service_change->where_active()->where_open()->and_where('complete','!=',1)->or_where('complete','IS',null)->where_close()->find();
}
@@ -258,7 +267,7 @@ class Model_Service extends ORM_OSB {
}
public function transactions() {
- return $this->invoice_item->order_by('date_start,date_stop');
+ return $this->invoice_item->order_by('date_start')->order_by('date_stop');
}
/** LIST FUNCTIONS **/
diff --git a/modules/ssl/classes/Model/Product/Plugin/Ssl.php b/modules/ssl/classes/Model/Product/Plugin/Ssl.php
index 7388bf1b..22443dda 100644
--- a/modules/ssl/classes/Model/Product/Plugin/Ssl.php
+++ b/modules/ssl/classes/Model/Product/Plugin/Ssl.php
@@ -15,10 +15,20 @@ class Model_Product_Plugin_Ssl extends Model_Product_Plugin {
// Our required abstract methods
public function admin_update() {}
+ public function cost($annual=FALSE) {
+ $x = 0;
+
+ return $annual ? $x*12 : $x;
+ }
+
public function feature_summary() {
// @todo This view should render based on the the results of this::allowance();
return View::factory('product/plugin/ssl/feature_summary')
->set('po',$this);
}
+
+ public function supplier() {
+ return 'internal';
+ }
}
?>