src-db/database/model/functions/M_INOUT_POST.xml
changeset 30926 a57c4aa5d672
parent 30916 97937c788c1c
parent 30782 50698b513147
child 31620 9c931e5263c1
child 32399 a031e45f7316
equal deleted inserted replaced
30925:8138ee07c1cb 30926:a57c4aa5d672
    78     v_NextNo VARCHAR2(32);
    78     v_NextNo VARCHAR2(32);
    79     v_Qty NUMBER;
    79     v_Qty NUMBER;
    80     v_QtyPO NUMBER;
    80     v_QtyPO NUMBER;
    81     v_QtySO NUMBER;
    81     v_QtySO NUMBER;
    82     v_QuantityOrder NUMBER;
    82     v_QuantityOrder NUMBER;
    83     v_QuantityOrderPO NUMBER;
       
    84     v_QuantityOrderSO NUMBER;
       
    85     v_RDocumentNo VARCHAR2(40) ;
    83     v_RDocumentNo VARCHAR2(40) ;
    86     v_RInOut_ID VARCHAR2(32);
    84     v_RInOut_ID VARCHAR2(32);
    87     v_IsStocked NUMBER;
    85     v_IsStocked NUMBER;
    88     v_DoctypeReversed_ID VARCHAR2(32);
    86     v_DoctypeReversed_ID VARCHAR2(32);
    89     --MODIFIED BY F.IRIAZABAL
    87     --MODIFIED BY F.IRIAZABAL
   528             v_QuantityOrder:=Cur_InOutLine.QuantityOrder;
   526             v_QuantityOrder:=Cur_InOutLine.QuantityOrder;
   529             IF(SUBSTR(Cur_InOut.MovementType, 2)='-') THEN
   527             IF(SUBSTR(Cur_InOut.MovementType, 2)='-') THEN
   530               v_Qty:=- Cur_InOutLine.MovementQty;
   528               v_Qty:=- Cur_InOutLine.MovementQty;
   531               v_QuantityOrder:=-Cur_InOutLine.QuantityOrder;
   529               v_QuantityOrder:=-Cur_InOutLine.QuantityOrder;
   532             END IF;
   530             END IF;
   533             IF(Cur_InOut.IsSOTrx='N') THEN
   531             IF (Cur_InOut.IsSOTrx='N' AND v_isreturndoctype='N') THEN
   534               v_QtySO:=0;
   532               v_QtySO:=0;
   535               v_QtyPO:=Cur_InOutLine.MovementQty;
   533               v_QtyPO:=Cur_InOutLine.MovementQty;
   536               v_QuantityOrderSO:=0;
       
   537               v_QuantityOrderPO:=Cur_InOutLine.QuantityOrder;
       
   538             ELSE
   534             ELSE
   539               v_QtySO:=Cur_InOutLine.MovementQty;
   535               v_QtySO:=Cur_InOutLine.MovementQty;
   540               v_QtyPO:=0;
   536               v_QtyPO:=0;
   541               v_QuantityOrderSO:=Cur_InOutLine.QuantityOrder;
       
   542               v_QuantityOrderPO:=0;
       
   543             END IF;
   537             END IF;
   544             -- UOM Conversion
   538             -- UOM Conversion
   545             -- Is it a standard stocked product:3
   539             -- Is it a standard stocked product:3
   546             SELECT COUNT(*)
   540             SELECT COUNT(*)
   547             INTO v_IsStocked
   541             INTO v_IsStocked
   745             IF(Cur_InOutLine.M_Product_ID IS NOT NULL AND Cur_InOut.IsSOTrx='Y') THEN
   739             IF(Cur_InOutLine.M_Product_ID IS NOT NULL AND Cur_InOut.IsSOTrx='Y') THEN
   746               A_ASSET_CREATE(NULL, Cur_InOutLine.M_InOutLine_ID) ;
   740               A_ASSET_CREATE(NULL, Cur_InOutLine.M_InOutLine_ID) ;
   747             END IF;
   741             END IF;
   748             v_ResultStr:='UpdateOrderLine';
   742             v_ResultStr:='UpdateOrderLine';
   749             IF(Cur_InOutLine.C_OrderLine_ID IS NOT NULL) THEN
   743             IF(Cur_InOutLine.C_OrderLine_ID IS NOT NULL) THEN
   750               if(Cur_InOut.ISSOTRX='Y') THEN
   744               IF (Cur_InOut.ISSOTRX='Y' OR (Cur_InOut.ISSOTRX='N' AND v_isreturndoctype='Y')) THEN
   751                 -- Sets DateDelivered with the recent shipment date
   745                 -- Sets DateDelivered with the recent shipment date
   752                 -- of the shipment/s done for the orderline.
   746                 -- of the shipment/s done for the orderline.
   753                 SELECT MAX(M.MOVEMENTDATE) INTO v_DateDelivered
   747                 SELECT MAX(M.MOVEMENTDATE) INTO v_DateDelivered
   754                 FROM M_INOUTLINE ML, M_INOUT M
   748                 FROM M_INOUTLINE ML, M_INOUT M
   755                 WHERE ML.C_OrderLine_ID = Cur_InOutLine.C_OrderLine_ID
   749                 WHERE ML.C_OrderLine_ID = Cur_InOutLine.C_OrderLine_ID
   806                 SELECT name INTO v_ProductName FROM M_Product WHERE M_Product_id = Cur_InOutLine.M_Product_ID;
   800                 SELECT name INTO v_ProductName FROM M_Product WHERE M_Product_id = Cur_InOutLine.M_Product_ID;
   807 			    RAISE_APPLICATION_ERROR(-20000, v_Message||' '||'@line@'||' '||Cur_InOutLine.line||', '||'@Product@'||' '||v_ProductName) ;
   801 			    RAISE_APPLICATION_ERROR(-20000, v_Message||' '||'@line@'||' '||Cur_InOutLine.line||', '||'@Product@'||' '||v_ProductName) ;
   808               END IF;
   802               END IF;
   809             END IF;
   803             END IF;
   810           END LOOP; -- For all InOut Lines
   804           END LOOP; -- For all InOut Lines
       
   805 
       
   806          -- Update the C_Order.IsDelivered flag only for Sales or RTV flows
       
   807          -- This should be extended for other flows too in the future
       
   808          IF (v_isSoTrx='Y' OR (v_isSoTrx='N' AND v_isreturndoctype='Y')) THEN
       
   809            FOR Cur_Order IN
       
   810            (SELECT o.c_order_id
       
   811             FROM C_Order o
       
   812             WHERE EXISTS (SELECT 1
       
   813                           FROM C_ORDERLINE ol
       
   814                           JOIN M_INOUTLINE iol ON iol.C_ORDERLINE_ID = ol.C_ORDERLINE_ID
       
   815                           WHERE ol.C_Order_ID = o.C_Order_ID
       
   816                           AND iol.m_inout_id = CUR_InOut.m_inout_id
       
   817                           )
       
   818            )
       
   819            LOOP
       
   820              IF (v_IsReversedDoc = 'N') THEN
       
   821                -- Normal Scenario
       
   822                UPDATE C_Order o
       
   823                SET IsDelivered = 'Y'
       
   824                WHERE o.c_order_id = Cur_Order.c_order_id
       
   825                AND o.IsDelivered = 'N'
       
   826                AND EXISTS (SELECT 1
       
   827                            FROM C_ORDERLINE ol
       
   828                            WHERE ol.C_Order_ID = o.C_Order_ID
       
   829                            AND ol.c_order_discount_id IS NULL
       
   830                            GROUP BY ol.C_Order_ID
       
   831                            HAVING SUM(ol.QTYORDERED) = SUM(ol.QTYDELIVERED));
       
   832              ELSIF (v_IsReversedDoc = 'Y') THEN
       
   833                -- Void Scenario
       
   834                UPDATE C_Order o
       
   835                SET IsDelivered = 'N'
       
   836                WHERE o.c_order_id = Cur_Order.c_order_id
       
   837                AND o.IsDelivered = 'Y'
       
   838                AND EXISTS (SELECT 1
       
   839                            FROM C_ORDERLINE ol
       
   840                            WHERE ol.C_Order_ID = o.C_Order_ID
       
   841                            AND ol.c_order_discount_id IS NULL
       
   842                            AND ol.QTYORDERED <> ol.QTYDELIVERED);
       
   843              END IF;
       
   844            END LOOP;
       
   845          END IF;
       
   846 
   811           /*******************
   847           /*******************
   812           * PO Matching
   848           * PO Matching
   813           ******************/
   849           ******************/
   814           IF(Cur_InOut.IsSOTrx='N') THEN
   850           IF(Cur_InOut.IsSOTrx='N') THEN
   815             DECLARE
   851             DECLARE