]> lifelog.hopto.org Git - LifeLog.git/commitdiff
camm subrotine.
authorMetabox <redacted>
Sat, 22 Jun 2019 08:28:21 +0000 (18:28 +1000)
committerMetabox <redacted>
Sat, 22 Jun 2019 08:28:21 +0000 (18:28 +1000)
htdocs/cgi-bin/main.cgi
htdocs/cgi-bin/stats.cgi

index 10dbe0a7095c720cfe5f60c07585164d3e72e5a2..3c04c1f9c08a83f9ae226bc0587800e43642b713 100755 (executable)
@@ -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 "<font color=red><b>SERVER ERROR</b></font>:" . $_;
     }
 }
+
+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
index 6cba7c8f2442fe5cf38b081d9a38d5c9706b3ee9..9fa7fb41edcbb35b8b845861b97fd3e17222e456 100755 (executable)
@@ -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 = '<table class="tbl" border="1px"><tr class="r0"><td colspan="4"><b>* PERSONAL LOG DATA STATS *</b></td></tr>';
 
-
-
 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/<br\/>/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