$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'); $budgetModel->setTitleWeight('h3'); $views_to_load = array(); if ($hasTitle) { $views_to_load[] = " <h2>{$todayDateFormated}</h2>"; } $views_to_load[] = ' ' . AddView2::render($addModel); $views_to_load[] = '_paging.php'; $views_to_load[] = ' ' . TableView2::render($categoryModel); $views_to_load[] = ' ' . TableView2::render($recurringModel); $views_to_load[] = ' ' . TableView2::render($budgetModel); $views_to_load[] = '_paging.php'; include $relative_base_path . 'views/_generic.php'; }