Correct total calculator to use 8 decimals

This commit is contained in:
Rene Vergara 2022-07-22 13:41:19 -05:00
parent 20061285a2
commit 80c6fe6b71
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
3 changed files with 11 additions and 3 deletions

View file

@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed calculation of order total to ensure 8 decimal places
- Fixed test for looking for an order with incorrect ID - Fixed test for looking for an order with incorrect ID
- Fixed payment scan to focus only on new transactions - Fixed payment scan to focus only on new transactions

View file

@ -188,7 +188,7 @@ updateOrderTotals o =
(qprice o) (qprice o)
(newTotal o) (newTotal o)
(if qprice o /= 0 (if qprice o /= 0
then newTotal o / qprice o then roundZec (newTotal o / qprice o)
else 0) else 0)
(qlines o) (qlines o)
(qpaid o) (qpaid o)
@ -215,3 +215,7 @@ markOrderPaid i =
modify modify
(select ["_id" =: (read i :: B.ObjectId)] "orders") (select ["_id" =: (read i :: B.ObjectId)] "orders")
["$set" =: ["paid" =: True]] ["$set" =: ["paid" =: True]]
-- | Helper function to round to 8 decimal places
roundZec :: Double -> Double
roundZec n = fromInteger (round $ n * (10 ^ 8)) / (10.0 ^^ 8)

View file

@ -294,6 +294,10 @@ decodeHexText h = E.decodeUtf8With lenientDecode $ BS.pack $ hexRead h
encodeHexText :: T.Text -> String encodeHexText :: T.Text -> String
encodeHexText t = T.unpack . toText . fromBytes $ E.encodeUtf8 t encodeHexText t = T.unpack . toText . fromBytes $ E.encodeUtf8 t
-- | Helper function to round to 8 decimal places
roundZec :: Double -> Double
roundZec n = fromInteger (round $ n * (10 ^ 8)) / (10.0 ^^ 8)
-- Types for the ZGo database documents -- Types for the ZGo database documents
-- | Type to model a country for the database's country list -- | Type to model a country for the database's country list
data Country = data Country =
@ -788,8 +792,7 @@ scanPayments config pipe = do
getOrderId re t = do getOrderId re t = do
let reg = matchAllText re (T.unpack $ zmemo t) let reg = matchAllText re (T.unpack $ zmemo t)
if not (null reg) if not (null reg)
then do then fst $ head reg ! 1
fst $ head reg ! 1
else "" else ""
-- | RPC methods -- | RPC methods