Fix discount and parenthesis
authorMaxime Bourget <bmx007@gmail.com>
Sun, 26 May 2013 17:32:45 +0000 (18:32 +0100)
committerMaxime Bourget <bmx007@gmail.com>
Sun, 26 May 2013 17:46:56 +0000 (18:46 +0100)
Now parse line return the *raw* discount (instead of /100).
Meaning its treated exactly as the other.

Before formula where converted to integer (/100)
before being expanded or evaluated.

includes/textcart_manager.inc
test/textcartManager/parseTest.php
test/textcartManager/processTest.php

index c0f1bfb1d4242069aa1ebecb1d9211bc1b18ca10..45acd24c31b936da85d32d4e7e0652ece82aa809 100644 (file)
@@ -223,6 +223,9 @@ class TextCartManager {
 
       }
 
+                       // convert the percentage to float.
+                       if($discount) $discount /= 100;
+
       #echo "Stock Code : $stock_code</br><ul>";
       #echo "<li>mode : $mode</li>";
       #echo "<li>quantity : $quantity</li>"   ;
@@ -422,7 +425,7 @@ class TextCartManager {
       ,"stock_code" => $stock_code
       ,"quantity" => $quantity
       ,"price" => $price
-      ,"discount" => $discount !== null && $discount !== '' ? $discount/100.0 : null
+      ,"discount" => $discount
       ,"description" => $description
       ,"date" => $date
     );
@@ -438,7 +441,7 @@ class TextCartManager {
 
        function get_default_discount($cart, $stock_code) {
                if(empty($cart)) return null;
-               return $cart->default_discount;
+               return 100*$cart->default_discount;
        }
 
        function get_kit_description($cart, $stock_code) {
index 45d20359bc28532b4d2eb60365db5f14c1607268..f1e5a2cec68605e39488ee552145b105a118edcb 100644 (file)
@@ -49,8 +49,8 @@ class ParseTest extends PHPUnit_Framework_TestCase {
                                                        ,array("A ^2013/03/01 10", "A", '10', null, null, null, 'Date: 2013/3/1')
                                                        ,array("A 2013/03/01 10", "A", '10', null, null, null, 'Date: 2013/3/1')
                                                        /*** Everything is passed ***/
-                                                       ,array("A 10 5.0 3% ^2013/03/01 | hello", "A", '10', '5.0', 0.03, "hello", 'Date: 2013/3/1')
-                                                       ,array("A 3% 10 5.0 ^2013/03/01 | hello", "A", '10', '5.0', 0.03, "hello", 'Date: 2013/3/1')
+                                                       ,array("A 10 5.0 3% ^2013/03/01 | hello", "A", '10', '5.0', 3, "hello", 'Date: 2013/3/1')
+                                                       ,array("A 3% 10 5.0 ^2013/03/01 | hello", "A", '10', '5.0', 3, "hello", 'Date: 2013/3/1')
                );
        }
 /**
index 0d2a9fda701a60084d1b234fafd47e300e19e414..d200257f34eb612bed95c70acbb125afab5b0292 100644 (file)
@@ -19,6 +19,7 @@ class ProcessTest extends PHPUnit_Framework_TestCase {
 
        public function processNormalExamples() {
                return array(
+/*
                                                        array("A", "A", 1, 5.2, 0.02)
                                                        ,array("A 3", "A", 3, 5.2, 0.02)
                                                        ,array("A $3", "A", 1, 3, 0.02)
@@ -28,6 +29,14 @@ class ProcessTest extends PHPUnit_Framework_TestCase {
                                                        ,array(":# 5%\nA", "A", 1, 5.2, 0.05)
                                                        ,array("A 0%", "A", 1, 5.2, 0)
                                                        ,array("A 10%", "A", 1, 5.2, 0.1)
+
+                                                       // overriding discount 
+                                                       ,array(":# 0%\nA 5%", "A", 1, 5.2, 0.05) // line win
+                                                       ,array(":# 10%\nA 0%", "A", 1, 5.2, 0)
+                                                       ,array(":# (0)%\nA 0.5%", "A", 1, 5.2, 0) // template win
+                                                       ,array(":# (10)%\nA 0%", "A", 1, 5.2, 0.1)
+                                                       ,*/array(":A (10)%\nA ", "A", 1, 5.2, 0.1)
+                                                       ,array(":# 10%\nA 35 ", "A", 1, 5.2, 0.1)
                                                        );
        }