Fixed bug 27140: Useless usage of hex_to_int()
authorVíctor Martínez Romanos <victor.martinez@openbravo.com>
Mon, 04 Aug 2014 14:47:58 +0200
changeset 24157 4882d76b8d6a
parent 24156 4f449d9a56f7
child 24158 752c92d2f31a
Fixed bug 27140: Useless usage of hex_to_int()
src-db/database/model/functions/C_ORDER_POST1.xml
--- a/src-db/database/model/functions/C_ORDER_POST1.xml	Mon Aug 04 14:10:59 2014 +0200
+++ b/src-db/database/model/functions/C_ORDER_POST1.xml	Mon Aug 04 14:47:58 2014 +0200
@@ -61,8 +61,9 @@
   v_IsBinding CHAR(1):='Y';
   v_istaxincluded CHAR(1);
   --
-  ToDeliver NUMBER;
-  ToInvoice NUMBER;
+  ToDeliver CHAR(1):='N';
+  ToInvoice CHAR(1):='N';
+  ToDeliverOrToInvoice CHAR(1):='N';
   --
   InOut_ID VARCHAR2(32);
   Invoice_ID VARCHAR2(32);
@@ -1358,14 +1359,11 @@
      */
       BEGIN
         v_ResultStr:='OrderCompleteCheck';
-        SELECT SUM(QtyOrdered*hex_to_int(C_OrderLine_ID)) -SUM(QtyDelivered*hex_to_int(C_OrderLine_ID)),
-            SUM(QtyOrdered*hex_to_int(C_OrderLine_ID)) -SUM(QtyInvoiced*hex_to_int(C_OrderLine_ID))
-          INTO ToDeliver,
-            ToInvoice
-        FROM C_ORDERLINE
-        WHERE C_Order_ID=v_Record_ID;
-        -- If no lines, ToDeliver is NULL
-        IF ((ToDeliver=0 AND ToInvoice=0) OR(ToDeliver IS NULL AND ToInvoice IS NULL)) THEN
+        SELECT 'Y' INTO ToDeliverOrToInvoice FROM DUAL
+        WHERE 0 <> ANY (select QtyOrdered - QtyDelivered from c_orderline where c_order_id = v_Record_ID)
+        OR    0 <> ANY (select QtyOrdered - QtyInvoiced  from c_orderline where c_order_id = v_Record_ID);
+        -- If something to deliver or to invoice, then ToDeliverOrToInvoice = 'Y'
+        IF (ToDeliverOrToInvoice <> 'Y') THEN
           DBMS_OUTPUT.PUT_LINE('OrderComplete') ;
           IF (v_DocAction='CL') THEN
             END_PROCESSING:=TRUE;
@@ -1508,17 +1506,15 @@
      /**
       * Final Completeness check
       */
-      SELECT SUM(QtyOrdered*hex_to_int(C_OrderLine_ID)) -SUM(QtyDelivered*hex_to_int(C_OrderLine_ID)),
-          SUM(QtyOrdered*hex_to_int(C_OrderLine_ID)) -SUM(QtyInvoiced*hex_to_int(C_OrderLine_ID))
-        INTO ToDeliver,
-          ToInvoice
-      FROM C_ORDERLINE
-      WHERE C_Order_ID=v_Record_ID;
+      SELECT 'Y' INTO ToDeliver FROM DUAL
+      WHERE 0 <> ANY (select QtyOrdered - QtyDelivered from c_orderline where c_order_id = v_Record_ID);
+      SELECT 'Y' INTO ToInvoice FROM DUAL
+      WHERE 0 <> ANY (select QtyOrdered - QtyInvoiced from c_orderline where c_order_id = v_Record_ID);
       DBMS_OUTPUT.PUT_LINE('To deliver - ' || ToDeliver) ;
       DBMS_OUTPUT.PUT_LINE('ToInvoice - ' || ToInvoice) ;
       DBMS_OUTPUT.PUT_LINE('v_DocSubTypeSO - ' || v_DocSubTypeSO) ;
       -- Nothing to Deliver + Invoice for (W)illCall(I)nvoice and (W)alkIn(R)eceipt
-      IF (v_DocSubTypeSO IN ('WI', 'WR') AND ToDeliver=0 AND ToInvoice=0) THEN
+      IF (v_DocSubTypeSO IN ('WI', 'WR') AND ToDeliver <> 'Y' AND ToInvoice <> 'Y') THEN
         UPDATE C_ORDER
         SET DocStatus='CO',
             DocAction='--',
@@ -1534,7 +1530,7 @@
         END IF;
       END IF;
       -- Nothing to Deliver for (W)illCall(P)ickup (Invoice generated independently)
-      IF (v_DocSubTypeSO='WP' AND ToDeliver=0) THEN
+      IF (v_DocSubTypeSO='WP' AND ToDeliver <> 'Y') THEN
         UPDATE C_ORDER
         SET DocStatus='CO',
             DocAction='--',