src-db/database/model/functions/M_INOUT_POST.xml
changeset 21879 42d8b6d87b76
parent 21852 304b13b3a917
child 21884 3533b03979da
equal deleted inserted replaced
21878:cf81ea534d47 21879:42d8b6d87b76
    55   v_isreturndoctype CHAR(1);
    55   v_isreturndoctype CHAR(1);
    56   v_available_period NUMBER:=0;
    56   v_available_period NUMBER:=0;
    57   v_is_ready AD_Org.IsReady%TYPE;
    57   v_is_ready AD_Org.IsReady%TYPE;
    58   v_is_tr_allow AD_OrgType.IsTransactionsAllowed%TYPE;
    58   v_is_tr_allow AD_OrgType.IsTransactionsAllowed%TYPE;
    59   v_DateAcct DATE;
    59   v_DateAcct DATE;
       
    60   v_DateDelivered TIMestamp without time zone;
    60   v_isacctle AD_OrgType.IsAcctLegalEntity%TYPE;
    61   v_isacctle AD_OrgType.IsAcctLegalEntity%TYPE;
    61   v_org_bule_id AD_Org.AD_Org_ID%TYPE;
    62   v_org_bule_id AD_Org.AD_Org_ID%TYPE;
    62   -- Parameter
    63   -- Parameter
    63   TYPE RECORD IS REF CURSOR;
    64   TYPE RECORD IS REF CURSOR;
    64     Cur_Parameter RECORD;
    65     Cur_Parameter RECORD;
   643             IF(Cur_InOutLine.M_Product_ID IS NOT NULL AND Cur_InOut.IsSOTrx='Y') THEN
   644             IF(Cur_InOutLine.M_Product_ID IS NOT NULL AND Cur_InOut.IsSOTrx='Y') THEN
   644               A_ASSET_CREATE(NULL, Cur_InOutLine.M_InOutLine_ID) ;
   645               A_ASSET_CREATE(NULL, Cur_InOutLine.M_InOutLine_ID) ;
   645             END IF;
   646             END IF;
   646             v_ResultStr:='UpdateOrderLine';
   647             v_ResultStr:='UpdateOrderLine';
   647             IF(Cur_InOutLine.C_OrderLine_ID IS NOT NULL) THEN
   648             IF(Cur_InOutLine.C_OrderLine_ID IS NOT NULL) THEN
       
   649               if(Cur_InOut.ISSOTRX='Y') THEN
       
   650                 -- Sets DateDelivered with the recent shipment date
       
   651                 -- of the shipment/s done for the orderline.
       
   652                 SELECT MAX(M.MOVEMENTDATE) INTO v_DateDelivered
       
   653                 FROM M_INOUTLINE ML, M_INOUT M
       
   654                 WHERE ML.C_OrderLine_ID = Cur_InOutLine.C_OrderLine_ID
       
   655                 AND ML.M_INOUT_ID = M.M_INOUT_ID
       
   656                 AND M.DOCSTATUS='CO';
       
   657               ELSE
       
   658                 v_DateDelivered := null;
       
   659               END IF;
       
   660 
       
   661               IF(v_QtySO > 0) THEN
       
   662                 IF(v_DateDelivered IS NULL OR v_DateDelivered < Cur_InOut.MovementDate ) THEN
       
   663                   v_DateDelivered:=Cur_InOut.MovementDate;
       
   664                 END IF;
       
   665               END IF;
       
   666               
   648               -- stocked product
   667               -- stocked product
   649               IF(Cur_InOutLine.M_Product_ID IS NOT NULL AND v_IsStocked=1) THEN
   668               IF(Cur_InOutLine.M_Product_ID IS NOT NULL AND v_IsStocked=1) THEN
   650                 -- Update OrderLine (if C-, Qty is negative)
   669                 -- Update OrderLine (if C-, Qty is negative)
   651                 SELECT DOCSTATUS into v_DocStatus
   670                 SELECT DOCSTATUS into v_DocStatus
   652                 FROM C_ORDER
   671                 FROM C_ORDER
   654                                     FROM C_ORDERLINE 
   673                                     FROM C_ORDERLINE 
   655                                     WHERE C_ORDERLINE_ID=Cur_InOutLine.C_OrderLine_ID);
   674                                     WHERE C_ORDERLINE_ID=Cur_InOutLine.C_OrderLine_ID);
   656                 IF (v_DocStatus = 'DR') THEN
   675                 IF (v_DocStatus = 'DR') THEN
   657                   UPDATE C_ORDERLINE
   676                   UPDATE C_ORDERLINE
   658                     SET QtyDelivered=QtyDelivered + v_QtySO,
   677                     SET QtyDelivered=QtyDelivered + v_QtySO,
       
   678                     DATEDELIVERED=(CASE WHEN (QtyDelivered + v_QtySO) > 0 THEN v_DateDelivered ELSE NULL END),
   659                     Updated=now(),
   679                     Updated=now(),
   660                     UpdatedBy=v_User
   680                     UpdatedBy=v_User
   661                   WHERE C_OrderLine_ID=Cur_InOutLine.C_OrderLine_ID;
   681                   WHERE C_OrderLine_ID=Cur_InOutLine.C_OrderLine_ID;
   662                 ELSE 
   682                 ELSE 
   663                   UPDATE C_ORDERLINE
   683                   UPDATE C_ORDERLINE
   664                     SET QtyReserved=QtyReserved - v_QtyPO - v_QtySO,
   684                     SET QtyReserved=QtyReserved - v_QtyPO - v_QtySO,
       
   685                     DATEDELIVERED=(CASE WHEN (QtyReserved - v_QtyPO - v_QtySO) > 0 THEN v_DateDelivered ELSE NULL END),
   665                     QtyDelivered=QtyDelivered + v_QtySO,
   686                     QtyDelivered=QtyDelivered + v_QtySO,
   666                     Updated=now(),
   687                     Updated=now(),
   667                     UpdatedBy=v_User
   688                     UpdatedBy=v_User
   668                    WHERE C_OrderLine_ID=Cur_InOutLine.C_OrderLine_ID;
   689                    WHERE C_OrderLine_ID=Cur_InOutLine.C_OrderLine_ID;
   669                 END IF;
   690                 END IF;
   670                 -- Products not stocked
   691                 -- Products not stocked
   671               ELSE
   692               ELSE
   672                 -- Update OrderLine (if C-, Qty is negative)
   693                 -- Update OrderLine (if C-, Qty is negative)
   673                 UPDATE C_ORDERLINE
   694                 UPDATE C_ORDERLINE
   674                   SET QtyDelivered=QtyDelivered + v_QtySO,
   695                   SET QtyDelivered=QtyDelivered + v_QtySO,
       
   696                   DATEDELIVERED=(CASE WHEN (QtyDelivered + v_QtySO) > 0 THEN v_DateDelivered ELSE NULL END),
   675                   Updated=now(),
   697                   Updated=now(),
   676                   UpdatedBy=v_User
   698                   UpdatedBy=v_User
   677                 WHERE C_OrderLine_ID=Cur_InOutLine.C_OrderLine_ID;
   699                 WHERE C_OrderLine_ID=Cur_InOutLine.C_OrderLine_ID;
   678               END IF;
   700               END IF;
   679             END IF;
   701             END IF;