From: Metabox Date: Sat, 22 Jun 2019 08:28:21 +0000 (+1000) Subject: camm subrotine. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=ec1679a7b0fde14cf11b8cde6b87c91b9d2d792d;p=LifeLog.git camm subrotine. --- diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 10dbe0a..3c04c1f 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -261,7 +261,7 @@ elsif ($rs_cat_idx) { else { if ($stmD) { $stmt = $stmS . $stmD . $stmE; - } + } } ############### @@ -280,8 +280,8 @@ if ( $tbl_start > 0 ) { #check if we are at the beggining of the LOG table? my $stc = - $db->prepare('select rowid from LOG order by rowid DESC LIMIT 1;'); - $stc->execute(); + $db->prepare('select rowid from LOG order by rowid DESC LIMIT 1;'); + $stc->execute(); my @row = $stc->fetchrow_array(); if ( $row[0] == $rs_prev && $rs_cur == $rs_prev ) { $tbl_start = -1; @@ -305,7 +305,7 @@ 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 $amm = sprintf "%.2f", $row[4]; + my $amm = camm(sprintf "%.2f", $row[4]); #Apostrophe in the log value is doubled to avoid SQL errors. $log =~ s/''/'/g; @@ -927,3 +927,10 @@ sub getConfiguration { print "SERVER ERROR:" . $_; } } + +sub camm { + my $amm = sprintf("%.2f", shift @_); + # Add one comma each time through the do-nothing loop + 1 while $amm =~ s/^(-?\d+)(\d\d\d)/$1,$2/; +return $amm; +} \ No newline at end of file diff --git a/htdocs/cgi-bin/stats.cgi b/htdocs/cgi-bin/stats.cgi index 6cba7c8..9fa7fb4 100755 --- a/htdocs/cgi-bin/stats.cgi +++ b/htdocs/cgi-bin/stats.cgi @@ -47,8 +47,7 @@ $today->set_time_zone( $TIME_ZONE ); my $q = CGI->new; -print $q->header(-expires=>"+6os", -charset=>"UTF-8"); - +print $q->header(-expires=>"+6os", -charset=>"UTF-8"); print $q->start_html(-title => "Log Data Stats", -BGCOLOR=>"#c8fff8", -script=>{-type => 'text/javascript', -src => 'wsrc/main.js'}, -style =>{-type => 'text/css', -src => 'wsrc/main.css'}, @@ -58,8 +57,6 @@ print $q->start_html(-title => "Log Data Stats", -BGCOLOR=>"#c8fff8", my $tbl = ''; - - my $log_rc = selectSQL('select count(rowid) from LOG;'); my $stm = "SELECT count(date) from LOG where date>=date('now','start of year');"; my $log_this_year_rc = selectSQL($stm); @@ -69,12 +66,12 @@ my $id_income = selectSQL('SELECT ID from CAT where name like "Income";'); $stm = 'SELECT sum(ammount) from LOG where date>=date("now","start of year") AND ID_CAT = '.$id_expense.';'; -my $expense = sprintf("%.2f",selectSQL($stm)); +my $expense = big_money(sprintf("%.2f",selectSQL($stm))); $stm = 'SELECT sum(ammount) from LOG where date>=date("now","start of year") AND ID_CAT = '.$id_income.';'; -my $income = sprintf("%.2f",selectSQL($stm)); +my $income = big_money(sprintf("%.2f",selectSQL($stm))); my $revenue = big_money($income - $expense); my $hardware_status =`inxi -b -c0;uptime -p`; $hardware_status =~ s/\n//g; @@ -131,4 +128,11 @@ sub big_money { $number =~ s/^(-?)/$1\$/; return $number; } + +sub camm { + my $amm = sprintf("%.2f", shift @_); + # Add one comma each time through the do-nothing loop + 1 while $amm =~ s/^(-?\d+)(\d\d\d)/$1,$2/; +return $amm; +} ### CGI END
* PERSONAL LOG DATA STATS *