<?php defined('SYSPATH') or die('No direct access allowed.');

/**
 * This class provides Reseller Summary Stats
 *
 * @package    OSB
 * @category   Controllers/Reseller
 * @author     Deon George
 * @copyright  (c) 2009-2013 Open Source Billing
 * @license    http://dev.osbill.net/license.html
 */
class Controller_Reseller_Summary extends Controller_Account {
	protected $secure_actions = array(
		'index'=>TRUE,
	);

	/**
	 */
	public function action_index() {
		$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));
	}
}
?>
