. Changes required to support dm/eur currency where required.
[infodrom.org/service.infodrom.org] / src / InfoCon / buch / list.wml
index 6e2294e..041f78e 100644 (file)
 
   pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
 
+  if ($currency == "eur") {
+    $table = "sales";
+  } elseif ($currency == "dm") {
+    $table = "sales_dm";
+  } else {
+    die ("Unknown currency");
+  }
+
   if (strlen($year)) {
     # $where[] = "date >= '$year-01-01'";
     # $year++;
     # $where[] = "date < '$year-01-01'";
     $where[] = "date ~* '$year'";
+
+    # Implicit selection of currency
+    if ($year < 2002) {
+      $table = "sales_dm";
+    } elseif ($year > 2001) {
+      $table = "sales";
+    }
   }
   if (strlen($category)) {
     $where[] = "category = '$category'";
@@ -30,7 +45,7 @@
     $where[] = "price < 0.0";
   }
 
-  $query = "SELECT date,oid,category,description,price FROM sales ";
+  $query = "SELECT date,oid,category,description,price FROM $table ";
   if (count($where) > 0) {
     $query .= " WHERE " . implode ($where, " AND ");
   }
@@ -51,8 +66,8 @@
     printf ("<tr bgcolor=\"#%s\">", $color);
     printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\">%s</font></td>", $date);
     printf ("<td width=\"20%%\"><font face=\"Helvetica,Arial\">%s</font></td>", $row['category']);
-    printf ("<td width=\"50%%\"><font face=\"Helvetica,Arial\"><a href=\"edit.php3?oid=%d\">%s</a></font></td>",
-      $row['oid'], $row['description']);
+    printf ("<td width=\"50%%\"><font face=\"Helvetica,Arial\"><a href=\"edit.php3?oid=%d&cur=%s\">%s</a></font></td>",
+      $row['oid'], $currency, $row['description']);
     printf ("<td width=\"15%%\" align=\"right\"><font face=\"Helvetica,Arial\">%5.2f</font></td>", $row['price']);
     $sum += $row['price'];
     echo ("</tr>");
@@ -65,7 +80,7 @@
 
   if (!strlen($category)) {
 
-    $query = "SELECT DISTINCT category FROM sales ";
+    $query = "SELECT DISTINCT category FROM $table ";
     if (strlen($year)) {
       $query .= "WHERE date ~* '$year'";
     }
 
       $color = "<cold>";
       for ($i=0; $i < count ($catz); $i++) {
-        $query = sprintf ("SELECT SUM (price) FROM sales WHERE category = '%s' AND price > 0.0", $catz[$i]);
+        $query = sprintf ("SELECT SUM (price) FROM $table WHERE category = '%s' AND price > 0.0", $catz[$i]);
         $color = $color=="<cold>"?"<coln>":"<cold>";
 
        if (strlen($year)) {
         $sth = pg_exec ($dbh, $query); // or die("Datenbank-Abfrage!");
        $row = pg_fetch_array ($sth, 0);
        $input = $row[0]; $sum_input += $input;
-        $query = sprintf ("SELECT SUM (price) FROM sales WHERE category = '%s' AND price < 0.0", $catz[$i]);
+        $query = sprintf ("SELECT SUM (price) FROM $table WHERE category = '%s' AND price < 0.0", $catz[$i]);
        if (strlen($year)) {
          $query .= " AND date ~* '$year'";
        }
 # Local variables:
 # mode: text
 # mode: auto-fill
-# mode: iso-accents
 # end: