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

/**
 * This class provides User Statement functions
 *
 * @package    Statement
 * @category   Controllers/User
 * @author     Deon George
 * @copyright  (c) 2009-2013 Open Source Billing
 * @license    http://dev.osbill.net/license.html
 */
class Controller_User_Statement extends Controller_Statement {
	protected $secure_actions = array(
		'show'=>TRUE,
	);

	/**
	 * Show a payments received
	 */
	public function action_show() {
		$result = array();
		$total = 0;

		foreach ($this->ao->payment->find_all() as $o) {
			$key = $o->date_payment;

			while (isset($result[$key]))
				$key += 1;

			$result[$key] = $o;

			$total -= Currency::round($o->total());
		}

		foreach ($this->ao->invoice->list_active() as $o) {
			$key = $o->date_orig;

			while (isset($result[$key]))
				$key += 1;

			$result[$key] = $o;

			$total += Currency::round($o->total());
		}

		krsort($result);

		Block::factory()
			->title(sprintf('%s: %s - %s',_('Transactions For'),$this->ao->accnum(),$this->ao->name(TRUE)))
			->title_icon('icon-tasks')
			->body(View::factory('statement/user/show')->set('result',$result)->set('total',$total));
	}
}
?>
