<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="调整交货期">
	<query id="FrmOrderDelverEdate.doQuery" desc="查询">  
        <![CDATA[ 
SELECT T2.ORD_PK,
       T2.ORD_LN_PK,
       T2.ORD_LN_DLY_PK,
       T.ORDER_NO,
       T1.ORDER_SEQ,
       T2.DELIVERY_NO,
       TO_CHAR(T1.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE_LINE,
       TO_CHAR(T2.DELVRY_EDATE, 'YYYY-MM-DD') DELVRY_EDATE,
       T3.REVIEW_ASK,
       C.BASENAME DELIVERY_STATUS,
       T.SALE_ORG,
       T.SALE_ORG_DESC
  FROM SLM_ORDER_HEAD               T,
       SLM_ORDER_LINE               T1,
       SLM_ORDER_LINE_DELIVERY      T2,
       SLM_ORD_DESIGN_MSC_PL_PC_LST T3,
       COM_BASE_INFO                C
 WHERE T.ORD_PK = T1.ORD_PK
   AND T1.ORD_PK = T2.ORD_PK
   AND T1.ORD_LN_PK = T2.ORD_LN_PK
   AND T2.ORD_LN_DLY_PK = T3.ORD_LN_DLY_PK(+)
   AND T3.PROCESS_CODE(+) = 'D'
   AND T2.DELIVERY_STATUS = C.BASECODE(+)
   AND T.VALIDFLAG = '1'
   AND T1.VALIDFLAG = '1'
   AND T2.VALIDFLAG = '1'
   AND T2.DELIVERY_STATUS IN ('12020301', '12020302','12020210')
                ]]>
	</query>
	
	<query id="FrmOrderDelverEdate.doQueryEdateRecord" desc="查询交货期调整记录">  
        <![CDATA[ 
select T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       DECODE(T.FLAG, '0', '前调', '1', '后调') FLAG,
       T.DAY_NO,
       DECODE(T.FLAG_LINE, '0', '调整交货期', '1', '仅调合同行交货期') FLAG_LINE,
       T.USER_ID,
       T.USER_NAME,
       T.COL_TIME
  from SLM_ORDER_DELVRY_EDATE_RECORD t 
  WHERE 1 = 1
                ]]>
	</query>
	
	
	<query id="FrmOrderDelverEdate.updateDelvryEdate" desc="调整交货期">  
        <![CDATA[ 
DECLARE
  V_ORD_PK        SLM_ORDER_LINE_DELIVERY.ORD_PK%type := ?;
  V_ORD_LN_PK     SLM_ORDER_LINE_DELIVERY.ORD_LN_PK%type := ?;
  V_ORD_LN_DLY_PK SLM_ORDER_LINE_DELIVERY.ORD_LN_DLY_PK%type := ?;
  V_ORDER_NO      SLM_ORDER_HEAD.ORDER_NO%type := ?;
  V_ORDER_SEQ     SLM_ORDER_LINE.ORDER_SEQ%type := ?;
  V_DELIVERY_NO   SLM_ORDER_LINE_DELIVERY.DELIVERY_NO%type := ?;
  V_USER_NAME     SLM_ORDER_DELVRY_EDATE_RECORD.USER_NAME%type := ?;
  V_USER_ID       SLM_ORDER_DELVRY_EDATE_RECORD.USER_ID%type := ?;
  V_FLAG          SLM_ORDER_DELVRY_EDATE_RECORD.FLAG%type := ?;
  V_DAY_NO        SLM_ORDER_DELVRY_EDATE_RECORD.DAY_NO%type := ?;
BEGIN
  UPDATE SLM_ORDER_LINE_DELIVERY T
     SET T.DELVRY_EDATE = T.DELVRY_EDATE + DECODE(V_FLAG,'0',- V_DAY_NO,'1',V_DAY_NO)
   WHERE T.ORD_PK = V_ORD_PK
     AND T.ORD_LN_PK = V_ORD_LN_PK
     AND T.ORD_LN_DLY_PK = V_ORD_LN_DLY_PK;

  UPDATE SLM_ORD_DESIGN_MSC_PL_PC_LST T
     SET T.REVIEW_ASK = TO_CHAR(TO_DATE(T.REVIEW_ASK, 'YYYY-MM-DD') +
                                DECODE(V_FLAG, '0', -V_DAY_NO, '1', V_DAY_NO),
                                'YYYY-MM-DD')
   WHERE T.ORD_LN_DLY_PK = V_ORD_LN_DLY_PK;

  UPDATE SLM_ORD_DESIGN_MSC_PL_PC T
     SET T.DELVRY_EDATE = T.DELVRY_EDATE + DECODE(V_FLAG,'0',- V_DAY_NO,'1',V_DAY_NO)
   WHERE T.ORD_LN_DLY_PK = V_ORD_LN_DLY_PK;

 INSERT INTO SLM_ORDER_DELVRY_EDATE_RECORD(
        ORD_PK,
        ORD_LN_PK,
        ORD_LN_DLY_PK,
        ORDER_NO,
        ORDER_SEQ,
        DELIVERY_NO,
        FLAG,
        DAY_NO,
        FLAG_LINE,
        USER_ID,
        USER_NAME,
        COL_TIME)
 VALUES( 
        V_ORD_PK,
        V_ORD_LN_PK,
        V_ORD_LN_DLY_PK,
        V_ORDER_NO,
        V_ORDER_SEQ,
        V_DELIVERY_NO,
        V_FLAG,
        V_DAY_NO,
        '0',
        V_USER_ID,
        V_USER_NAME,
        SYSDATE);
END;
                ]]>
	</query>
	
	<query id="FrmOrderDelverEdate.updateDelvryEdateLine" desc="仅调合同行交货期">  
        <![CDATA[ 
DECLARE
  V_ORD_PK        SLM_ORDER_LINE_DELIVERY.ORD_PK%type := ?;
  V_ORD_LN_PK     SLM_ORDER_LINE_DELIVERY.ORD_LN_PK%type := ?;
  V_ORD_LN_DLY_PK SLM_ORDER_LINE_DELIVERY.ORD_LN_DLY_PK%type := ?;
  V_ORDER_NO      SLM_ORDER_HEAD.ORDER_NO%type := ?;
  V_ORDER_SEQ     SLM_ORDER_LINE.ORDER_SEQ%type := ?;
  V_DELIVERY_NO   SLM_ORDER_LINE_DELIVERY.DELIVERY_NO%type := ?;
  V_USER_NAME     SLM_ORDER_DELVRY_EDATE_RECORD.USER_NAME%type := ?;
  V_USER_ID       SLM_ORDER_DELVRY_EDATE_RECORD.USER_ID%type := ?;
  V_FLAG          SLM_ORDER_DELVRY_EDATE_RECORD.FLAG%type := ?;
  V_DAY_NO        SLM_ORDER_DELVRY_EDATE_RECORD.DAY_NO%type := ?;
  V_FLAG_LINE     SLM_ORDER_DELVRY_EDATE_RECORD.FLAG_LINE%type := ?;
BEGIN
  UPDATE SLM_ORDER_LINE T
     SET T.DELVRY_EDATE = T.DELVRY_EDATE +
                          DECODE(V_FLAG, '0', -V_DAY_NO, '1', V_DAY_NO),
         T.DELVRY_DESC  = REPLACE(T.DELVRY_DESC,
                                  TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD'),
                                  TO_CHAR(T.DELVRY_EDATE +
                                          DECODE(V_FLAG,
                                                 '0',
                                                 -V_DAY_NO,
                                                 '1',
                                                 V_DAY_NO),
                                          'YYYY-MM-DD'))
   WHERE T.ORD_PK = V_ORD_PK
     AND T.ORD_LN_PK = V_ORD_LN_PK;
     
  IF (V_FLAG_LINE = '1') THEN
    INSERT INTO SLM_ORDER_DELVRY_EDATE_RECORD
      (ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       FLAG,
       DAY_NO,
       FLAG_LINE,
       USER_ID,
       USER_NAME,
       COL_TIME)
    VALUES
      (V_ORD_PK,
       V_ORD_LN_PK,
       V_ORD_LN_DLY_PK,
       V_ORDER_NO,
       V_ORDER_SEQ,
       V_DELIVERY_NO,
       V_FLAG,
       V_DAY_NO,
       '1',
       V_USER_ID,
       V_USER_NAME,
       SYSDATE);
  END IF;
END;
                ]]>
	</query>
	
	

</queryMap>