src-db/database/model/functions/M_INOUT_POST.xml
changeset 22931 2aa45e3949b4
parent 22052 70a1852c6c64
child 22934 875ccb64c6c5
equal deleted inserted replaced
22930:ad890ff93c7e 22931:2aa45e3949b4
   107     v_goods_blocked VARCHAR2(1):='N';
   107     v_goods_blocked VARCHAR2(1):='N';
   108     v_bpartner_name c_bpartner.name%TYPE;
   108     v_bpartner_name c_bpartner.name%TYPE;
   109     v_DocAction VARCHAR2(60);
   109     v_DocAction VARCHAR2(60);
   110     v_voiddoccount NUMBER:=0;
   110     v_voiddoccount NUMBER:=0;
   111 
   111 
       
   112     v_penqty NUMBER;
       
   113     v_qtysumorders NUMBER;
       
   114     v_released  NUMBER;
       
   115 
   112   BEGIN
   116   BEGIN
       
   117   
   113     IF(p_PInstance_ID IS NOT NULL) THEN
   118     IF(p_PInstance_ID IS NOT NULL) THEN
   114       --  Update AD_PInstance
   119       --  Update AD_PInstance
   115       DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
   120       DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID) ;
   116       v_ResultStr:='PInstanceNotFound';
   121       v_ResultStr:='PInstanceNotFound';
   117       AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
   122       AD_UPDATE_PINSTANCE(p_PInstance_ID, NULL, 'Y', NULL, NULL) ;
   474               IF (cur_inout.issotrx = 'Y' AND cur_inoutline.c_orderline_id IS NOT NULL AND v_qty < 0 AND cur_inoutline.canceled_inoutline_id IS NULL) THEN
   479               IF (cur_inout.issotrx = 'Y' AND cur_inoutline.c_orderline_id IS NOT NULL AND v_qty < 0 AND cur_inoutline.canceled_inoutline_id IS NULL) THEN
   475                 -- Manage reservations.
   480                 -- Manage reservations.
   476                 SELECT count(*), max(m_reservation_id)
   481                 SELECT count(*), max(m_reservation_id)
   477                   INTO v_aux, v_reservation_id
   482                   INTO v_aux, v_reservation_id
   478                 FROM m_reservation
   483                 FROM m_reservation
   479                 WHERE c_orderline_id = cur_inoutline.c_orderline_id;
   484                 WHERE c_orderline_id = cur_inoutline.c_orderline_id
       
   485                 AND res_status NOT IN ('DR', 'CL');
   480                 IF (v_aux > 1) THEN
   486                 IF (v_aux > 1) THEN
   481                   RAISE_APPLICATION_ERROR(-20000, '@SOLineWithMoreThanOneOpenReservation@');
   487                   RAISE_APPLICATION_ERROR(-20000, '@SOLineWithMoreThanOneOpenReservation@');
   482                 ELSIF (v_aux = 1) THEN
   488                 ELSIF (v_aux = 1) THEN
   483                   M_RESERVATION_CONSUMPTION(v_reservation_id, cur_inoutline.m_locator_id, cur_inoutline.m_attributesetinstance_id, cur_inoutline.movementqty, v_user, v_result, v_message);
   489                   M_RESERVATION_CONSUMPTION(v_reservation_id, cur_inoutline.m_locator_id, cur_inoutline.m_attributesetinstance_id, cur_inoutline.movementqty, v_user, v_result, v_message);
   484                 END IF;
   490                 END IF;
   490                   v_undoqty NUMBER;
   496                   v_undoqty NUMBER;
   491                 BEGIN
   497                 BEGIN
   492                   SELECT count(*), max(m_reservation_id)
   498                   SELECT count(*), max(m_reservation_id)
   493                     INTO v_aux, v_reservation_id
   499                     INTO v_aux, v_reservation_id
   494                   FROM m_reservation
   500                   FROM m_reservation
   495                   WHERE c_orderline_id = cur_inoutline.c_orderline_id;
   501                   WHERE c_orderline_id = cur_inoutline.c_orderline_id
       
   502                   AND res_status NOT IN ('DR', 'CL');
   496                   IF (v_aux > 1) THEN
   503                   IF (v_aux > 1) THEN
   497                     RAISE_APPLICATION_ERROR(-20000, '@SOLineWithMoreThanOneOpenReservation@');
   504                     RAISE_APPLICATION_ERROR(-20000, '@SOLineWithMoreThanOneOpenReservation@');
   498                   ELSIF (v_aux = 1) THEN
   505                   ELSIF (v_aux = 1) THEN
   499                     v_qtyaux := v_qty;
   506                     v_qtyaux := v_qty;
   500                     FOR cur_released_stock IN (
   507                     FOR cur_released_stock IN (
   536                     SELECT count(*), max(m_reservation_stock_id) INTO v_aux, v_res_stock_id
   543                     SELECT count(*), max(m_reservation_stock_id) INTO v_aux, v_res_stock_id
   537                     FROM m_reservation_stock
   544                     FROM m_reservation_stock
   538                     WHERE c_orderline_id = cur_inoutline.c_orderline_id
   545                     WHERE c_orderline_id = cur_inoutline.c_orderline_id
   539                       AND m_locator_id = cur_inoutline.m_locator_id
   546                       AND m_locator_id = cur_inoutline.m_locator_id
   540                       AND m_reservation_id = cur_reserve_stock.m_reservation_id
   547                       AND m_reservation_id = cur_reserve_stock.m_reservation_id
   541                       AND isallocated = 'Y'
   548                       AND isallocated = cur_reserve_stock.isallocated
   542                       AND COALESCE(m_attributesetinstance_id, '0') = COALESCE(Cur_InOutLine.M_AttributeSetInstance_ID, '0');
   549                       AND COALESCE(m_attributesetinstance_id, '0') = COALESCE(Cur_InOutLine.M_AttributeSetInstance_ID, '0');
   543                     -- Update existing prereserved stock to decrease reserved qty
   550                     -- Update existing prereserved stock to decrease reserved qty
   544                     UPDATE m_reservation_stock
   551                     UPDATE m_reservation_stock
   545                     SET quantity = quantity - v_qtyaux
   552                     SET quantity = quantity - v_qtyaux
   546                     WHERE m_reservation_stock_id = cur_reserve_stock.m_reservation_stock_id;
   553                     WHERE m_reservation_stock_id = cur_reserve_stock.m_reservation_stock_id;
   557                         quantity, releasedqty, isallocated
   564                         quantity, releasedqty, isallocated
   558                       ) VALUES (
   565                       ) VALUES (
   559                         get_uuid(), cur_reserve_stock.ad_client_id, cur_reserve_stock.ad_org_id, 'Y',
   566                         get_uuid(), cur_reserve_stock.ad_client_id, cur_reserve_stock.ad_org_id, 'Y',
   560                         now(), v_user, now(), v_user,
   567                         now(), v_user, now(), v_user,
   561                         cur_reserve_stock.m_reservation_id, cur_inoutline.m_attributesetinstance_id, cur_inoutline.m_locator_id, cur_inoutline.c_orderline_id,
   568                         cur_reserve_stock.m_reservation_id, cur_inoutline.m_attributesetinstance_id, cur_inoutline.m_locator_id, cur_inoutline.c_orderline_id,
   562                         v_qtyaux, 0, 'Y'
   569                         v_qtyaux, 0, cur_reserve_stock.isallocated
   563                       );
   570                       );
   564                     END IF;
   571                     END IF;
   565                     v_pendingqty := v_pendingqty - v_qtyaux;
   572                     v_pendingqty := v_pendingqty - v_qtyaux;
   566                     IF (v_pendingqty <= 0) THEN
   573                     IF (v_pendingqty <= 0) THEN
   567                       EXIT;
   574                       EXIT;
   572                     AND quantity = 0
   579                     AND quantity = 0
   573                     AND COALESCE(releasedqty, 0) = 0;
   580                     AND COALESCE(releasedqty, 0) = 0;
   574                 END;
   581                 END;
   575               ELSIF (cur_inout.issotrx = 'N' AND cur_inoutline.canceled_inoutline_id IS NOT NULL AND v_qty < 0) THEN
   582               ELSIF (cur_inout.issotrx = 'N' AND cur_inoutline.canceled_inoutline_id IS NOT NULL AND v_qty < 0) THEN
   576                 -- Revert to pre-reservations
   583                 -- Revert to pre-reservations
       
   584 
       
   585                   select  sum(iol.movementqty)
       
   586                   into v_qtysumorders
       
   587                   from m_inoutline iol
       
   588                   WHERE  iol.c_orderline_id=cur_inoutline.c_orderline_id
       
   589                   and iol.m_locator_id=cur_inoutline.m_locator_id;
       
   590 
       
   591                   select rs.quantity
       
   592                   into v_released
       
   593                   from m_reservation_stock rs
       
   594                   where c_orderline_id=cur_inoutline.c_orderline_id
       
   595                   and rs.m_locator_id=cur_inoutline.m_locator_id;
       
   596 
       
   597                   v_penqty := -v_qty - ((v_qtysumorders+(-cur_inoutline.movementqty))-v_released);
       
   598 
   577                 DECLARE
   599                 DECLARE
   578                   cur_reserve_stock     RECORD;
   600                   cur_reserve_stock     RECORD;
   579                   v_pendingqty          NUMBER;
   601                   v_pendingqty          NUMBER;
   580                   v_qtyaux              NUMBER;
   602                   v_qtyaux              NUMBER;
   581                   v_res_stock_id        VARCHAR2(32);
   603                   v_res_stock_id        VARCHAR2(32);
   582                   v_aux_released NUMBER:= 0;
   604                   v_aux_released NUMBER:= 0;
   583                 BEGIN
   605                 BEGIN
   584                   v_pendingqty := -v_qty;
   606                   v_pendingqty:=v_penqty;
   585                   FOR cur_reserve_stock IN (
   607                   FOR cur_reserve_stock IN (
   586                       SELECT rs.quantity, COALESCE(rs.releasedqty,0) AS releasedqty, rs.m_reservation_stock_id, rs.m_reservation_id,
   608                       SELECT rs.quantity, COALESCE(rs.releasedqty,0) AS releasedqty, rs.m_reservation_stock_id, rs.m_reservation_id,
   587                           rs.ad_org_id, rs.ad_client_id
   609                           rs.ad_org_id, rs.ad_client_id, rs.isallocated
   588                       FROM m_reservation_stock rs JOIN m_reservation r ON rs.m_reservation_id = r.m_reservation_id
   610                       FROM m_reservation_stock rs JOIN m_reservation r ON rs.m_reservation_id = r.m_reservation_id
   589                       WHERE rs.c_orderline_id = cur_inoutline.c_orderline_id
   611                       WHERE rs.c_orderline_id = cur_inoutline.c_orderline_id
   590                         AND rs.m_locator_id = cur_inoutline.m_locator_id
   612                         AND rs.m_locator_id = cur_inoutline.m_locator_id
   591                         AND r.res_status NOT IN ('DR', 'CL')
   613                         AND r.res_status NOT IN ('DR', 'CL')
   592                   ) LOOP
   614                   ) LOOP
   598                       FROM m_reservation_stock
   620                       FROM m_reservation_stock
   599                       WHERE c_orderline_id = cur_inoutline.c_orderline_id
   621                       WHERE c_orderline_id = cur_inoutline.c_orderline_id
   600                         AND m_locator_id IS NULL
   622                         AND m_locator_id IS NULL
   601                         AND m_reservation_id = cur_reserve_stock.m_reservation_id;
   623                         AND m_reservation_id = cur_reserve_stock.m_reservation_id;
   602                       -- Update existing prereserved stock to decrease reserved qty
   624                       -- Update existing prereserved stock to decrease reserved qty
       
   625 
   603                       UPDATE m_reservation_stock
   626                       UPDATE m_reservation_stock
   604                       SET quantity = quantity - v_qtyaux
   627                       SET quantity = quantity - v_qtyaux
   605                       WHERE m_reservation_stock_id = cur_reserve_stock.m_reservation_stock_id;
   628                       WHERE m_reservation_stock_id = cur_reserve_stock.m_reservation_stock_id;
   606                       -- Insert or update reserved stock by same quantity
   629                       -- Insert or update reserved stock by same quantity
   607                       IF (v_aux > 0) THEN
   630                       IF (v_aux > 0) THEN
   616                           quantity, releasedqty, isallocated
   639                           quantity, releasedqty, isallocated
   617                         ) VALUES (
   640                         ) VALUES (
   618                           get_uuid(), cur_reserve_stock.ad_client_id, cur_reserve_stock.ad_org_id, 'Y',
   641                           get_uuid(), cur_reserve_stock.ad_client_id, cur_reserve_stock.ad_org_id, 'Y',
   619                           now(), v_user, now(), v_user,
   642                           now(), v_user, now(), v_user,
   620                           cur_reserve_stock.m_reservation_id, '0', NULL, cur_inoutline.c_orderline_id,
   643                           cur_reserve_stock.m_reservation_id, '0', NULL, cur_inoutline.c_orderline_id,
   621                           v_qtyaux, 0, 'Y'
   644                           v_qtyaux, 0, cur_reserve_stock.isallocated
   622                         );
   645                         );
   623                       END IF;
   646                       END IF;
   624                       v_pendingqty := v_pendingqty - v_qtyaux;
   647                       v_pendingqty := v_pendingqty - v_qtyaux;
   625                       IF (v_pendingqty <= 0) THEN
   648                       IF (v_pendingqty <= 0) THEN
   626                         EXIT;
   649                         EXIT;
   634                   DELETE FROM m_reservation_stock
   657                   DELETE FROM m_reservation_stock
   635                   WHERE c_orderline_id = cur_inoutline.c_orderline_id
   658                   WHERE c_orderline_id = cur_inoutline.c_orderline_id
   636                     AND quantity = 0
   659                     AND quantity = 0
   637                     AND COALESCE(releasedqty, 0) = 0;
   660                     AND COALESCE(releasedqty, 0) = 0;
   638                 END;
   661                 END;
       
   662 
   639               END IF;
   663               END IF;
   640               
   664 
   641               v_ResultStr:='CreateTransaction';
   665               v_ResultStr:='CreateTransaction';
   642               Ad_Sequence_Next('M_Transaction', Cur_InOutLine.AD_Org_ID, v_NextNo) ;
   666               Ad_Sequence_Next('M_Transaction', Cur_InOutLine.AD_Org_ID, v_NextNo) ;
   643               INSERT
   667               INSERT
   644               INTO M_TRANSACTION
   668               INTO M_TRANSACTION
   645                 (
   669                 (