src-db/database/model/functions/M_RESERVATION_POST.xml
changeset 18693 7b17189c848b
parent 18689 a17b382229ce
child 18695 f584300636c8
equal deleted inserted replaced
18692:f9f27a33fbda 18693:7b17189c848b
    38   v_resstatus       VARCHAR2(60);
    38   v_resstatus       VARCHAR2(60);
    39   v_newstatus       VARCHAR2(60);
    39   v_newstatus       VARCHAR2(60);
    40   v_newaction       VARCHAR2(60);
    40   v_newaction       VARCHAR2(60);
    41   v_orderline_id    VARCHAR2(32);
    41   v_orderline_id    VARCHAR2(32);
    42   v_count           NUMBER;
    42   v_count           NUMBER;
       
    43   v_quantity        NUMBER;
       
    44   v_reservedqty     NUMBER;
    43 
    45 
    44 TYPE RECORD IS REF CURSOR;
    46 TYPE RECORD IS REF CURSOR;
    45   Cur_Parameter RECORD;
    47   Cur_Parameter RECORD;
    46 
    48 
    47 BEGIN
    49 BEGIN
    71     v_resaction := p_resaction;
    73     v_resaction := p_resaction;
    72     v_user_id := p_user_id;
    74     v_user_id := p_user_id;
    73   END IF;
    75   END IF;
    74 
    76 
    75 BEGIN
    77 BEGIN
    76   SELECT res_status, c_orderline_id
    78   SELECT res_status, c_orderline_id, quantity, reservedqty
    77     INTO v_resstatus, v_orderline_id
    79     INTO v_resstatus, v_orderline_id, v_quantity, v_reservedqty
    78   FROM m_reservation
    80   FROM m_reservation
    79   WHERE m_reservation_id = v_reservation_id;
    81   WHERE m_reservation_id = v_reservation_id;
    80   
    82   
    81   IF (v_resaction = 'PR') THEN
    83   IF (v_resaction = 'PR') THEN
    82   /*
    84   /*
    83     Reservation Complete Process
    85     Reservation Complete Process
    84   */
    86   */
    85     IF (v_resstatus != 'DR') THEN
    87     DECLARE
    86       RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
    88       v_sales_order_id        VARCHAR2(32);
    87     END IF;
    89       v_linecount             NUMBER;
    88     IF (v_orderline_id IS NOT NULL) THEN
    90       v_creservedcount        NUMBER;
    89       SELECT count(*) INTO v_count
    91       v_preservedcount        NUMBER;
    90       FROM m_reservation
    92     BEGIN
    91       WHERE c_orderline_id = v_orderline_id
    93       IF (v_resstatus != 'DR') THEN
    92         AND res_status != 'CL'
    94         RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
    93         AND m_reservation_id != v_reservation_id;
    95       END IF;
    94       IF (v_count > 0) THEN
    96       IF (v_orderline_id IS NOT NULL) THEN
    95         RAISE_APPLICATION_ERROR(-20000, '@SOLineWithMoreThanOneOpenReservation@');
    97         SELECT count(*) INTO v_count
    96       END IF;
    98         FROM m_reservation
    97     END IF;
    99         WHERE c_orderline_id = v_orderline_id
    98 
   100           AND res_status != 'CL'
    99     v_newstatus := 'CO';
   101           AND m_reservation_id != v_reservation_id;
   100     v_newaction := 'HO';
   102         IF (v_count > 0) THEN
   101     -- ADD RESERVED STOCK
   103           RAISE_APPLICATION_ERROR(-20000, '@SOLineWithMoreThanOneOpenReservation@');
   102     M_RESERVE_STOCK_AUTO(v_reservation_id, v_user_id, v_message);
   104         END IF;
       
   105   
       
   106         UPDATE c_orderline
       
   107         SET so_res_status = CASE WHEN v_quantity = v_reservedqty THEN 'CR'
       
   108                                  ELSE 'PR'
       
   109                             END
       
   110         WHERE c_orderline_id = v_orderline_id;
       
   111   
       
   112         SELECT c_order_id INTO v_sales_order_id
       
   113         FROM c_orderline
       
   114         WHERE c_orderline_id = v_orderline_id;
       
   115         SELECT COUNT(*), SUM(CASE so_res_status WHEN 'CR' THEN 1 ELSE 0 END), SUM(CASE so_res_status WHEN 'PR' THEN 1 ELSE 0 END)
       
   116           INTO v_linecount, v_creservedcount, v_preservedcount
       
   117         FROM c_orderline
       
   118         WHERE c_order_id = v_sales_order_id;
       
   119   
       
   120         UPDATE c_order
       
   121         SET so_res_status = CASE WHEN v_linecount = v_creservedcount THEN 'CR'
       
   122                                  WHEN v_creservedcount + v_preservedcount > 0 THEN 'PR'
       
   123                                  ELSE 'NR'
       
   124                             END
       
   125         WHERE c_order_id = v_sales_order_id;
       
   126       END IF;
       
   127   
       
   128       v_newstatus := 'CO';
       
   129       v_newaction := 'HO';
       
   130       -- ADD RESERVED STOCK
       
   131       M_RESERVE_STOCK_AUTO(v_reservation_id, v_user_id, v_message);
       
   132     END;
   103 
   133 
   104   ELSIF (v_resaction = 'HO') THEN
   134   ELSIF (v_resaction = 'HO') THEN
   105   /*
   135   /*
   106     Reservation Hold Process
   136     Reservation Hold Process
   107   */
   137   */
   124 
   154 
   125   ELSIF (v_resaction = 'RE') THEN
   155   ELSIF (v_resaction = 'RE') THEN
   126   /*
   156   /*
   127     Reservation Reactivate Process
   157     Reservation Reactivate Process
   128   */
   158   */
   129     IF (v_resstatus != 'CO') THEN
   159     DECLARE
   130       RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
   160       v_sales_order_id        VARCHAR2(32);
   131     END IF;
   161       v_reservedcount         NUMBER;
   132     v_newstatus := 'DR';
   162     BEGIN
   133     v_newaction := 'PR';
   163 
       
   164       IF (v_resstatus != 'CO') THEN
       
   165         RAISE_APPLICATION_ERROR(-20000, '@ActionNotSupported@');
       
   166       END IF;
       
   167 
       
   168       UPDATE c_orderline
       
   169       SET so_res_status = 'NR'
       
   170       WHERE c_orderline_id = v_orderline_id;
       
   171 
       
   172       SELECT c_order_id INTO v_sales_order_id
       
   173       FROM c_orderline
       
   174       WHERE c_orderline_id = v_orderline_id;
       
   175       SELECT COUNT(*) INTO v_reservedcount
       
   176       FROM c_orderline
       
   177       WHERE c_order_id = v_sales_order_id
       
   178         AND so_res_status <> 'NR';
       
   179 
       
   180       UPDATE c_order
       
   181       SET so_res_status = CASE WHEN v_reservedcount > 0 THEN 'PR'
       
   182                                ELSE 'NR'
       
   183                           END
       
   184       WHERE c_order_id = v_sales_order_id;
       
   185 
       
   186       v_newstatus := 'DR';
       
   187       v_newaction := 'PR';
       
   188     END;
   134   
   189   
   135   ELSIF (v_resaction = 'CL') THEN
   190   ELSIF (v_resaction = 'CL') THEN
   136   /*
   191   /*
   137     Reservation Close Process
   192     Reservation Close Process
   138   */
   193   */