Löschen von Einnahmen und Ausgaben.
authorPascal Hofmann <pascal@bigmac.local>
Mon, 31 Oct 2011 09:20:13 +0000 (10:20 +0100)
committerPascal Hofmann <pascal@bigmac.local>
Mon, 31 Oct 2011 09:20:13 +0000 (10:20 +0100)
include/earnings.php
include/expenses.php
index.php

index e543423..41e5b2e 100644 (file)
@@ -53,6 +53,10 @@ function db_change_earning($earning) {
     return db_update_single(DB_TABLE_EARNINGS, $earning, sprintf('id=\'%1$d\'', db_escape($id)));
 }
 
+function db_delete_earning($earning) {
+    return db_delete_single(DB_TABLE_EARNINGS, sprintf('id=\'%1$d\'', db_escape($earning['id'])));
+}
+
 /* }}} */
 
 
@@ -107,9 +111,9 @@ function action_create_earning() {/*{{{*/
 function action_change_earning() {/*{{{*/
     if (!isset($_REQUEST['id'])) redirect(link_to('finances'));
     $earning = db_get_earning_with_id($_REQUEST['id']);
+    if (!isset($earning)) redirect(link_to('finances'));
     $earning['date'] = format_date(db_date2unixtime($earning['date']));
     $earning['value']= format_money($earning['value']);
-    if (!isset($earning)) redirect(link_to('finances'));
     $log_messages = array();
     if (isset($_POST['submit'])) {
         if (validate_earning($_POST, $earning, $log_messages)) {
@@ -124,6 +128,23 @@ function action_change_earning() {/*{{{*/
 }/*}}}*/
 
 
+function action_delete_earning() {/*{{{*/
+    if (!isset($_REQUEST['id'])) redirect(link_to('finances'));
+    $earning = db_get_earning_with_id($_REQUEST['id']);
+    if (!isset($earning)) redirect(link_to('finances'));
+    $earning['date'] = format_date(db_date2unixtime($earning['date']));
+    $earning['value']= format_money($earning['value']);
+    $log_messages = array();
+    if (isset($_POST['submit'])) {
+        if (db_delete_earning($earning)) {
+            redirect(link_to('finances'));
+        }
+        echo db_error();
+    }
+    form_earning($earning, 'delete', $log_messages);
+}/*}}}*/
+
+
 function form_earning($earning = array(), $task, $log_messages) {/*{{{*/
     global $EARNING_TYPES, $ACCOUNT_TYPES;
 
index 48ca679..dcbd851 100644 (file)
@@ -51,6 +51,10 @@ function db_change_expense($expense) {
     return db_update_single(DB_TABLE_EXPENSES, $expense, sprintf('id=\'%1$d\'', db_escape($id)));
 }
 
+function db_delete_expense($expense) {
+    return db_delete_single(DB_TABLE_EXPENSES, sprintf('id=\'%1$d\'', db_escape($expense['id'])));
+}
+
 /* }}} */
 
 
@@ -105,9 +109,9 @@ function action_create_expense() {/*{{{*/
 function action_change_expense() {/*{{{*/
     if (!isset($_REQUEST['id'])) redirect(link_to('finances'));
     $expense = db_get_expense_with_id($_REQUEST['id']);
+    if (!isset($expense)) redirect(link_to('finances'));
     $expense['date'] = format_date(db_date2unixtime($expense['date']));
     $expense['value']= format_money($expense['value']);
-    if (!isset($expense)) redirect(link_to('finances'));
     $log_messages = array();
     if (isset($_POST['submit'])) {
         if (validate_expense($_POST, $expense, $log_messages)) {
@@ -122,6 +126,23 @@ function action_change_expense() {/*{{{*/
 }/*}}}*/
 
 
+function action_delete_expense() {/*{{{*/
+    if (!isset($_REQUEST['id'])) redirect(link_to('finances'));
+    $expense = db_get_expense_with_id($_REQUEST['id']);
+    if (!isset($expense)) redirect(link_to('finances'));
+    $expense['date'] = format_date(db_date2unixtime($expense['date']));
+    $expense['value']= format_money($expense['value']);
+    $log_messages = array();
+    if (isset($_POST['submit'])) {
+        if (db_delete_expense($expense)) {
+            redirect(link_to('finances'));
+        }
+        echo db_error();
+    }
+    form_expense($expense, 'delete', $log_messages);
+}/*}}}*/
+
+
 function form_expense($expense = array(), $task, $log_messages) {/*{{{*/
     global $EXPENSE_TYPES, $ACCOUNT_TYPES;
 
index 9e938aa..4b4d5c2 100644 (file)
--- a/index.php
+++ b/index.php
@@ -90,6 +90,8 @@ ob_end_clean();
             tr.total { background-color: #eee; font-weight: bold; }
             tr.current { background-color: #eee; font-weight: bold; }
             tr.inactive { color: #999; }
+            #earning_form { background-color: #efe; }
+            #expense_form { background-color: #fee; }
             th { text-align: left; background-color: #eee; font-weight: normal; border-bottom: 1px solid #ccc;  }
             h1, h2, h3, legend { font-family: Georgia, Sans-Serif, Verdana; font-weight: normal; color: #333;}
             #header h1 { font-size: 4em; color: #fff; }