Пример #1
0
 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'])));
     $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');