From ad8ac78100f8c00cb88aedf14e72d31eaf849d30 Mon Sep 17 00:00:00 2001 From: Will Budic Date: Fri, 8 May 2020 22:30:56 +1000 Subject: [PATCH] Bug 21 fix. --- Current Development Check List.md | 2 +- htdocs/cgi-bin/stats.cgi | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Current Development Check List.md b/Current Development Check List.md index 207d062..0b67c7e 100644 --- a/Current Development Check List.md +++ b/Current Development Check List.md @@ -95,7 +95,7 @@ This version is not compatible in data structure to prior versions. Data migrati ### v. 1.9 Encountered/Fixed * ✔ Bug 22 - Delete selection of entries not working after a while, db fix in config page required. -* Bug 21 - Income sum for year in stats is displayed wrong. +* ✔ Bug 21 - Income sum for year in stats is displayed wrong. * ✔ Bug 20 - Autologin bypasses, wanted new alias login (on logoff). ### v. 1.8 Encountered/Fixed diff --git a/htdocs/cgi-bin/stats.cgi b/htdocs/cgi-bin/stats.cgi index 8af0a8a..91d512a 100755 --- a/htdocs/cgi-bin/stats.cgi +++ b/htdocs/cgi-bin/stats.cgi @@ -74,14 +74,29 @@ my $log_rc = selectSQL('select count(rowid) from LOG;'); my ($stm1,$stm2) = "SELECT count(date) from LOG where date>=date('now','start of year');"; my $log_this_year_rc = selectSQL($stm1); my $notes_rc = selectSQL('select count(LID) from NOTES where DOC is not null;'); +my $id; #INCOME -$stm1 = 'SELECT sum(AMOUNT) from LOG where date>=date("now","start of year") AND AFLAG = 1;'; +$stm1 = 'select ID from CAT where NAME like "Income"'; +$id = selectSQL($stm1); +if($id){ + $stm1 = "SELECT sum(AMOUNT) from LOG where date>=date('now','start of year') AND (ID_CAT =$id or AFLAG=1);"; +} +else{ + $stm1 = 'SELECT sum(AMOUNT) from LOG where date>=date("now","start of year") AND AFLAG = 1;'; +} #EXPENSE -$stm2 = 'SELECT sum(AMOUNT) from LOG where date>=date("now","start of year") AND AFLAG = 2;'; +$stm2 = 'select ID from CAT where NAME like "Expense"'; +$id = selectSQL($stm2); +if($id){ + $stm2 = "SELECT sum(AMOUNT) from LOG where date>=date('now','start of year') AND (ID_CAT =$id or AFLAG=2);"; +} +else{ + $stm2 = 'SELECT sum(AMOUNT) from LOG where date>=date("now","start of year") AND AFLAG = 2;'; +} -my $expense = selectSQL($stm1); -my $income = selectSQL($stm2); +my $income = selectSQL($stm1); +my $expense= selectSQL($stm2); my $gross = big_money($income - $expense); $expense = big_money(sprintf("%.2f",$expense)); $income = big_money(sprintf("%.2f",$income)); -- 2.34.1