/** * Execute * * @param sfRequest $request A request object */ public function execute($request) { $user = $this->getUser()->getUserRecord(); $start = $this->getVar('start') ? $this->getVar('start') : $request->getParameter('start', date('Y-m-01')); $start = preg_replace("/(\\d{2})\\.(\\d{2})\\.(\\d{4})/", "\$3-\$2-\$1", $start); $returnJSON = $this->getVar('returnJSON') ? true : false; $budget = new BudgetManager(); $rate = $this->getContext()->getMyCurrencyExchange()->getRate($user->getCurrencyId()); $budgetCategories = $budget->load($user, new DateTime($start)); $this->setVar('budgetCategories', $budgetCategories, $noEscape = true); $this->setVar('returnJSON', $returnJSON); }
/** * Посчитать бюджет на текущий месяц */ public function testLoadBudget() { $user = Doctrine::getTable('User')->findOneByLogin('tester'); $dateStart = new DateTime('2010-11-01'); $budgetManager = new BudgetManager(); $data = $budgetManager->load($user, $dateStart); // Смотри фикстуру budget.yml $expectations = array(1 => array('mean' => 400 / 3, 'plan' => 500, 'adhoc' => 200, 'calendarAccepted' => 100, 'calendarFuture' => 50), 2 => array('mean' => 0, 'plan' => 1000, 'adhoc' => 0, 'calendarAccepted' => 0, 'calendarFuture' => 0)); foreach ($data as $budgetArticle) { $expectation = $expectations[$budgetArticle->key]; foreach ($expectation as $field => $value) { $this->assertEquals($value, $budgetArticle->{$field}, "Поле {$field} статьи бюджета {$budgetArticle->key}"); } } }