/**
  * 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);
 }
Esempio n. 2
0
 /**
  * Посчитать бюджет на текущий месяц
  */
 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}");
         }
     }
 }
<?php

require_once '../../views/_secureHead.php';
require_once $relative_base_path . 'models/edit.php';
if (isset($sessionManager) && $sessionManager->isAuthorized()) {
    $id = request_isset('id');
    $record = BudgetManager::getRecurringRecord($id);
    $page_title = 'Edit | Bookmarks';
    // build edit view
    $editModel = new EditModel('Edit', 'update_by_id', $id, 'recurring.php');
    $editModel->addRow('amount', 'Amount', $record['amount']);
    $editModel->addRow('category', 'Category', $record['category']);
    $editModel->addRow('store', 'Store', $record['store']);
    $editModel->addRow('items', 'Items', $record['items']);
    $editModel->addRow('startdate', 'Start date', $record['startDate']);
    $editModel->addRow('enddate', 'End date', $record['endDate']);
    $views_to_load = array();
    $views_to_load[] = ' ' . EditView2::render($editModel);
    include $relative_base_path . 'views/_generic.php';
}
Esempio n. 4
0
<?php

require_once '../../views/_secureHead.php';
require_once $relative_base_path . 'models/edit.php';
if (isset($sessionManager) && $sessionManager->isAuthorized()) {
    $id = request_isset('id');
    $budgetManager = new BudgetManager();
    $record = $budgetManager->getRecord($id);
    $page_title = 'Edit | Bookmarks';
    $record_date_split = explode(' ', $record['date']);
    $date = $record_date_split[0];
    $time = $record_date_split[1];
    // build edit view
    $editModel = new EditModel('Edit', 'update_by_id', $id);
    //		$editModel->addRow ('amount', 'Amount', $record['amount'] );
    //		$editModel->addRow ('category', 'Category', $record['category'] );
    $editModel->addRow('store', 'Store', $record['store']);
    //		$editModel->addRow ('items', 'Items', $record['items'] );
    $editModel->addRow('dateOption', 'dateOption', 'dateOption-selectTime', 'readonly=readonly');
    $editModel->addRow('selectTime-date', 'Date', $date);
    $editModel->addRow('selectTime-time', 'Time', $time);
    $views_to_load = array();
    $views_to_load[] = ' ' . EditView2::render($editModel);
    include $relative_base_path . 'views/_generic.php';
}
Esempio n. 5
0
         $db_update_success = BudgetManager::updateItemRecord($item_id, $item_name, $amount, $qty, $category, $brand, $size, $size_unit, $tax, $sale);
         break;
     case 'add_receipt_item':
         $id = $budget_id;
         $db_add_success = BudgetManager::addItemRecord($budget_id, $item_name, $amount, $qty, $category, $brand, $size, $size_unit, $tax, $sale);
         break;
     case 'delete_item_by_id':
         $id = BudgetManager::getBudgetIdFromItemId($item_id);
         $db_delete_success = BudgetManager::deleteItemRecord($item_id);
         break;
     case 'add_budget_item':
         $id = BudgetManager::addRecord($store, $date);
         break;
 }
 $spending_history_data = BudgetManager::getRecord($id);
 $items = BudgetManager::getItems($id);
 $receipt_total = 0;
 $page_title = 'Receipt | Budget';
 $alt_menu = getAddButton() . getBackButton();
 // add Item form
 $addModel = new AddModel('Add', 'add_receipt_item');
 $addModel->addRow('item_name', 'Item');
 $addModel->addRow('amount', 'Amount');
 $addModel->addRow('qty', 'Qty', 1);
 $addModel->addRow('category', 'Category');
 $addModel->addRow('brand', 'Brand');
 $addModel->addRow('size', 'Size');
 $addModel->addRow('size_unit', 'Units');
 $addModel->addRow('sale', 'Sale');
 $addModel->addOptionBox('tax', 'Tax', ['13%', '0%']);
 $addModel->addRow('budget_id', 'budget_id', $id);
Esempio n. 6
0
            break;
        case 'delete_by_id':
            $db_delete_success = BudgetManager::deleteRecurringRecord($id);
            break;
    }
    $page_title = 'Recurring | Budget';
    $alt_menu = getAddButton() . getBackButton();
    $addModel = new AddModel('Add', 'add_budget_item');
    $addModel->addRow('amount', 'Amount');
    $addModel->addRow('category', 'Category');
    $addModel->addRow('store', 'Store');
    $addModel->addRow('items', 'Items');
    $addModel->addRow('startdate', 'Start Date', 'CURRENT_TIMESTAMP');
    $addModel->addRow('enddate', 'End Date', '2037-12-31 23:59:59');
    // build recurring table model
    $recurringModel = new TableModel('Recurring items', 'recurring');
    $recurringModel->addRow(array(TableView2::createCell('amount', 'Amount', 'th'), TableView2::createCell('category', 'Category', 'th'), TableView2::createCell('store', 'Store', 'th'), TableView2::createCell('items', 'Items', 'th'), TableView2::createCell()));
    $recurring_items_data = BudgetManager::getAllRecurring();
    while (($recurring_items_row = mysql_fetch_array($recurring_items_data)) != null) {
        $amount = $recurring_items_row['amount'];
        $category = $recurring_items_row['category'];
        $recurringModel->addRow(array(TableView2::createCell('amount', format_currency($amount)), TableView2::createCell('category', $category), TableView2::createCell('store', $recurring_items_row['store']), TableView2::createCell('items', $recurring_items_row['items']), TableView2::createEdit($recurring_items_row['RECURRING_ID'], 'editRecurring.php')));
        $total_spent += $amount;
        $category_normalized = strtolower($category);
        $totals[$category_normalized] = isset($totals[$category_normalized]) ? $totals[$category_normalized] + $amount : $amount;
    }
    $views_to_load = array();
    $views_to_load[] = ' ' . AddView2::render($addModel);
    $views_to_load[] = ' ' . TableView2::render($recurringModel);
    include $relative_base_path . 'views/_generic.php';
}
Esempio n. 7
0
     $amount = $recurring_items_row['amount'];
     $category = $recurring_items_row['category'];
     $recurringModel->addRow(array(TableView2::createCell('amount', format_currency($amount)), TableView2::createCell('category', $category), TableView2::createCell('store', $recurring_items_row['store']), TableView2::createCell('items', $recurring_items_row['items'])));
     $total_spent += $amount;
     $category_normalized = strtolower($category);
     $totals[$category_normalized] = isset($totals[$category_normalized]) ? $totals[$category_normalized] + $amount : $amount;
 }
 // build budget table model
 $budgetModel = new TableModel('Reciepts', 'budget');
 $budgetModel->addRow(array(TableView2::createCell('amount', 'Amount', 'th'), TableView2::createCell('store', 'Store', 'th'), TableView2::createCell('date', 'Date', 'th'), TableView2::createCell(), TableView2::createCell()));
 while (($spending_history_row = mysql_fetch_array($spending_history_data)) != null) {
     $this_id = $spending_history_row['BUDGET_ID'];
     $store = $spending_history_row['store'];
     $date = $spending_history_row['date'];
     $total = BudgetManager::getRecieptTotalById($this_id);
     $reciept_items_data = BudgetManager::getItems($this_id);
     while (($reciept_items_row = mysql_fetch_array($reciept_items_data)) != null) {
         $amount = $reciept_items_row['amount'] * $reciept_items_row['qty'] * (1 + $reciept_items_row['tax']);
         $total_spent += $amount;
         $category_normalized = strtolower($reciept_items_row['category']);
         $totals[$category_normalized] = isset($totals[$category_normalized]) ? $totals[$category_normalized] + $amount : $amount;
     }
     $budgetModel->addRow(array(TableView2::createCell('amount', format_currency($total)), TableView2::createCell('store', $spending_history_row['store']), TableView2::createCell('date', $spending_history_row['date']), TableView2::createCell('view', "<a href='receipt.php?id={$this_id}'>View</a>"), TableView2::createEdit($this_id)));
 }
 $categoryModel = new TableModel('Category totals', 'categoryTotals');
 foreach ($totals as $this_category => $this_amount) {
     $categoryModel->addRow(array(TableView2::createCell('category', $this_category, 'th'), TableView2::createCell('amount', format_currency($this_amount))));
 }
 $categoryModel->addRow(array(TableView2::createCell('', 'Total', 'th'), TableView2::createCell('total', format_currency($total_spent))));
 $categoryModel->setTitleWeight('h3');
 $recurringModel->setTitleWeight('h3');
Esempio n. 8
0
<?php

require_once '../../views/_secureHead.php';
require_once $relative_base_path . 'models/edit.php';
if (isset($sessionManager) && $sessionManager->isAuthorized()) {
    $id = request_isset('id');
    $record = BudgetManager::getItemRecord($id);
    $page_title = 'Edit | Reciept | Budget';
    // build edit view
    $editModel = new EditModel('Edit', 'update_item_by_id', $id, 'receipt.php', 'item');
    $editModel->addRow('item_name', 'Name', $record['item_name']);
    $editModel->addRow('amount', 'Price', $record['amount']);
    $editModel->addRow('qty', 'Qty', $record['qty']);
    $editModel->addRow('category', 'Category', $record['category']);
    $editModel->addRow('brand', 'Brand', $record['brand']);
    $editModel->addRow('size', 'Size', $record['size']);
    $editModel->addRow('size_unit', 'units', $record['size_unit']);
    $editModel->addRow('tax', 'Tax', $record['tax']);
    $editModel->addRow('sale', 'sale', $record['sale']);
    $views_to_load = array();
    $views_to_load[] = ' ' . EditView2::render($editModel);
    include $relative_base_path . 'views/_generic.php';
}