Calculate sum in euro based on calculated time
authorJoey Schulze <joey@infodrom.org>
Mon, 26 Jan 2015 16:23:51 +0000 (16:23 +0000)
committerJoey Schulze <joey@infodrom.org>
Mon, 26 Jan 2015 16:23:51 +0000 (16:23 +0000)
src/InfoCon/stempel/common.inc
src/InfoCon/stempel/status.wml

index bcfa427..36fcd15 100644 (file)
@@ -38,9 +38,9 @@
     global $dbh;
     $info = array();
 
-    $sth = pg_exec ($dbh, 'SELECT short,name FROM stempel_customer');
+    $sth = pg_exec ($dbh, 'SELECT short,name,hourly_rate FROM stempel_customer');
     while ($row = pg_fetch_array ($sth))
-      $info[$row['short']] = $row['name'];
+      $info[$row['short']] = array('name' => $row['name'], 'rate' => $row['hourly_rate']);
 
     return $info;
   }
index d067f8a..63075eb 100644 (file)
@@ -32,7 +32,7 @@
 
     $name = load_customers();
 
-    $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d);</script>
+    $table_head = '<h3 class="bar">Kunde: %s</h3><script type="text/javascript">plant(%d,%.2f);</script>
   <form action="status.php" method="POST">
   <table class="smallfont border" width="100%%" cellpadding=0 cellspacing=0>
   <tr class="head" onclick="edit_task_finish(this)">
@@ -82,9 +82,9 @@
          printf($table_foot, $fieldnr);
          $form++;
        }
-       $cname = $name[$row['customer']];
+       $cname = $name[$row['customer']]['name'];
        if (!strlen($cname)) $cname = ucfirst($row['customer']);
-       printf($table_head, $cname, $form);
+       printf($table_head, $cname, $form, $name[$row['customer']]['rate']);
        $customer = $row['customer'];
        $fieldnr = 0;
        $sum = 0;
@@ -188,6 +188,8 @@ function strtime(time)
 function check(id, value)
 {
   var form = document.forms[id];
+  var hours=document.getElementById('time_'+id.toString());
+  var rate= document.getElementById('rate_'+id.toString());
   var sum = document.getElementById('sum_'+id.toString()); 
   var newval = 0;
 
@@ -203,35 +205,41 @@ function check(id, value)
       }
   }
 
-  sum.innerHTML = timestr(newval);
+  hours.innerHTML = timestr(newval);
+  sum.innerHTML = '&euro;' + ((newval/60)*rate.value).toFixed(2);
 }
 
-function plant(form)
+function plant(form, rate)
 {
   document.write('<div class="jscode">');
+  document.write('<input type="hidden" id="rate_'+form+'" value="'+rate+'">');
   document.write('<a href="javascript:check('+form+',true)">Check all</a>');
   document.write("&nbsp;/&nbsp;");
   document.write('<a href="javascript:check('+form+',false)">Uncheck all</a>');
   document.write("&nbsp;");
-  document.write('<span id="sum_'+form+'" class="sum">0:00</span>');
+  document.write('<span id="time_'+form+'" class="sum">0:00</span>' );
+  document.write('<span id="sum_'+form+'" class="sum">&euro;0.00</span>');
   document.write("&nbsp;");
   document.write('</div>');
 }
 
 function add_sum(form, checkbox)
 {
+    var hours = document.getElementById('time_'+form.toString());
+    var rate= document.getElementById('rate_'+form.toString());
     var sum = document.getElementById('sum_'+form.toString()); 
     var time = strtime(checkbox.parentNode.nextSibling.innerHTML);
     var newval;
 
     if (checkbox.checked) {
-       newval = strtime(sum.innerHTML) + time;
+       newval = strtime(hours.innerHTML) + time;
        checkbox.parentNode.parentNode.style.backgroundColor = color_checked;
     } else {
-       newval = strtime(sum.innerHTML) - time;
+       newval = strtime(hours.innerHTML) - time;
        checkbox.parentNode.parentNode.style.backgroundColor = '';
     }
-    sum.innerHTML = timestr(newval);
+    hours.innerHTML = timestr(newval);
+    sum.innerHTML = '&euro;' + ((newval/60)*rate.value).toFixed(2);
 }
 
 var task_parent = null;