From 637bc9bc7d65b625a322385b5700bfc169f877c0 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Wed, 10 Apr 2013 16:55:40 -0400 Subject: [PATCH] Record donations in grams. Donations are entered as kilograms to two decimal places but are stored internally as integers. Convert the donation to grams so we can save an integer value to the database. --- lib/donation.php | 4 ++-- lib/functions.php | 4 ++-- lib/order.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/donation.php b/lib/donation.php index 8a62a84..16b0197 100644 --- a/lib/donation.php +++ b/lib/donation.php @@ -197,7 +197,7 @@ /* Quantity. */ echo "\n"; echo " Quantity (kg)\n"; - echo " "; input("quantity", $donation->getQuantity()); echo "\n"; + echo " "; input("quantity", sprintf("%0.2f", $donation->getQuantity() / 1000)); echo "\n"; echo "\n"; } @@ -274,7 +274,7 @@ $donation->setDate($date); $donation->setContactId($contact_id); $donation->setHubId($hub_id); - $donation->setQuantity($quantity); + $donation->setQuantity($quantity * 1000); try { $donation->save(); diff --git a/lib/functions.php b/lib/functions.php index 86c8140..f9da713 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -196,11 +196,11 @@ } function get_donation_displayname($donation) { - return $donation->getQuantity() . "kg on " . $donation->getDate(); + return sprintf("%0.2fkg on %s", $donation->getQuantity() / 1000, $donation->getDate()); } function get_order_displayname($order) { - return $order->getQuantity() . "kg on " . $order->getDate(); + return sprintf("%0.2fkg on %s", $order->getQuantity() / 1000, $order->getDate()); } function get_address_area($address) { diff --git a/lib/order.php b/lib/order.php index 5c7e0d8..12a34aa 100644 --- a/lib/order.php +++ b/lib/order.php @@ -293,7 +293,7 @@ /* Quantity. */ echo "\n"; echo " Quantity (kg)\n"; - echo " "; input("quantity", $order->getQuantity()); echo "\n"; + echo " "; input("quantity", sprintf("%0.2f", $order->getQuantity() / 1000)); echo "\n"; echo "\n"; /* Driver. */ @@ -428,7 +428,7 @@ $order->setRequesterId($requester_id); $order->setBeneficiaryId($beneficiary_id); $order->setHubId($hub_id); - $order->setQuantity($quantity); + $order->setQuantity($quantity * 1000); /* XXX: begin/commit */ try { -- 2.7.4