From: Metabox Date: Sun, 21 Jul 2019 02:48:45 +0000 (+1000) Subject: Added sums for income and expenses. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=352fb104075fd67aae42d4da05db449f94af3df3;p=LifeLog.git Added sums for income and expenses. --- diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 68fe14e..18f44ef 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -233,7 +233,8 @@ qq(
Date Time Log# - CategoryEdit + Category + Edit ); if (defined $prm_vc) { #view category form selection @@ -307,6 +308,8 @@ if ( $tbl_start > 0 ) { # my $CID_EVENT = 9; my $tags = ""; +my $sum = 0; +my $exp = 0; $st = $db->prepare($stmt); $rv = $st->execute() or die or die "

Error->" & $DBI::errstri & "

"; if ( $rv < 0 ) { @@ -319,8 +322,13 @@ while ( my @row = $st->fetchrow_array() ) { my $ct = $hshCats{ $row[1] }; my $dt = DateTime::Format::SQLite->parse_datetime( $row[2] ); my $log = $row[3]; - my $am = &cam(sprintf "%.2f", $row[4]); - my $rtf = $row[4]; + my $am = &cam($row[4]); + my $rtf = $row[5]; + if($ct eq 'Expense'){ + $exp += $row[4]; + }else{ + $sum += $row[4]; + } #Apostrophe in the log value is doubled to avoid SQL errors. $log =~ s/''/'/g; @@ -519,13 +527,28 @@ while ( my @row = $st->fetchrow_array() ) { ); $tbl_rc += 1; - if ( $REC_LIMIT > 0 && $tbl_rc == $REC_LIMIT ) { - &buildNavigationButtons; + if ( $REC_LIMIT > 0 && $tbl_rc == $REC_LIMIT ) { last; - } + } } #while end +if ( $tfId == 1 ) { $tfId = 0; } else { $tfId = 1; } + my $tot = $sum - $exp; + $sum = &cam($sum); + $exp = &cam($exp); + $tot = &cam($tot); + $tbl .= qq( + + + # Total: + $sum ($exp) = $tot + ); + + if ( $REC_LIMIT > 0 && $tbl_rc == $REC_LIMIT ) { + &buildNavigationButtons; + } + ## #Fetch Keywords autocomplete we go by words larger then three. # @@ -570,7 +593,7 @@ if ( $tbl_rc == 0 ) { } $tbl .= -qq( +qq([Show All -> ] @@ -687,6 +710,7 @@ print qq( @@ -1033,7 +1057,7 @@ return $am; sub quill { my $log_id = shift; -return qq{ +return <