summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Reichel <sre@ring0.de>2012-11-04 00:09:04 +0100
committerSebastian Reichel <sre@ring0.de>2012-11-04 00:09:04 +0100
commit7857ca5c733d8516ab636a5be4f7f6b61f8cf28e (patch)
tree21352ea962d806d2894181005611f140b2409963
parent0c7e43956cd13730dd61d3eea4c6eb420115f057 (diff)
downloadserial-barcode-scanner-7857ca5c733d8516ab636a5be4f7f6b61f8cf28e.tar.bz2
support € values with . notation in web forms
-rw-r--r--src/price.vapi9
-rw-r--r--src/web.vala6
2 files changed, 12 insertions, 3 deletions
diff --git a/src/price.vapi b/src/price.vapi
index b60e2a6..ab7abee 100644
--- a/src/price.vapi
+++ b/src/price.vapi
@@ -6,4 +6,13 @@ public struct Price : int {
public new string to_string() {
return "%d.%02d".printf(this / 100, this % 100);
}
+
+ public static Price parse(string data) {
+ if("." in data) {
+ var parts = data.split(".");
+ return int.parse(parts[0])*100 + int.parse(parts[1]);
+ } else {
+ return int.parse(data);
+ }
+ }
}
diff --git a/src/web.vala b/src/web.vala
index ae6cbca..6722f17 100644
--- a/src/web.vala
+++ b/src/web.vala
@@ -472,8 +472,8 @@ public class WebServer {
if(query != null && query.contains("name") && query.contains("id") && query.contains("memberprice") && query.contains("guestprice")) {
var name = query["name"];
var ean = uint64.parse(query["id"]);
- Price memberprice = int.parse(query["memberprice"]);
- Price guestprice = int.parse(query["guestprice"]);
+ Price memberprice = Price.parse(query["memberprice"]);
+ Price guestprice = Price.parse(query["guestprice"]);
if(ean > 0 && memberprice > 0 && guestprice > 0 && db.new_product(ean, name, memberprice, guestprice)) {
template.replace("NAME", name);
@@ -516,7 +516,7 @@ public class WebServer {
if(query != null && query.contains("amount") && query.contains("price")) {
int amount = int.parse(query["amount"]);
- Price price = int.parse(query["price"]);
+ Price price = Price.parse(query["price"]);
if(amount >= 1 && price >= 1) {
if(db.restock(session.user, id, amount, price)) {