src-db/database/model/triggers/M_RESERVATION_TRG.xml
changeset 18702 f326d9aadc41
parent 18693 7b17189c848b
child 18717 7e50023ef517
equal deleted inserted replaced
18701:49214f6e5caa 18702:f326d9aadc41
    53       WHERE c_order_id = v_sales_order_id;
    53       WHERE c_order_id = v_sales_order_id;
    54     END IF;
    54     END IF;
    55   END IF;
    55   END IF;
    56 
    56 
    57   IF (DELETING) THEN
    57   IF (DELETING) THEN
    58     IF (:OLD.res_status NOT IN ('DR', 'CL') AND :OLD.c_orderline_id IS NOT NULL) THEN
    58     IF (:OLD.res_status != 'DR') THEN
    59       UPDATE c_orderline
    59       RAISE_APPLICATION_ERROR(-20000, '@DocumentProcessed@');
    60       SET so_res_status = 'NR'
    60     ELSIF (:OLD.releasedqty <> 0) THEN
    61       WHERE c_orderline_id = :OLD.c_orderline_id;
    61       RAISE_APPLICATION_ERROR(-20000, '@CannotDeleteReleasedReservation@');
    62 
       
    63       SELECT c_order_id INTO v_sales_order_id
       
    64       FROM c_orderline
       
    65       WHERE c_orderline_id = :OLD.c_orderline_id;
       
    66       SELECT COUNT(*) INTO v_reservedcount
       
    67       FROM c_orderline
       
    68       WHERE c_order_id = v_sales_order_id
       
    69         AND so_res_status <> 'NR';
       
    70 
       
    71       UPDATE c_order
       
    72       SET so_res_status = CASE WHEN v_reservedcount > 0 THEN 'PR'
       
    73                                ELSE 'NR'
       
    74                           END
       
    75       WHERE c_order_id = v_sales_order_id;
       
    76     END IF;
    62     END IF;
    77   END IF;
    63   END IF;
    78 END M_RESERVATION_TRG
    64 END M_RESERVATION_TRG
    79 ]]></body>
    65 ]]></body>
    80     </trigger>
    66     </trigger>