<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="汽运出厂计划">

	<query id="CorePipeLeaveFactory.queryOrderInfo" desc="合同查询">
		<![CDATA[	 
 SELECT T1.*,
       'FALSE' CHK,
       TO_NUMBER(NVL(T1.DELVRY_QTY, '0')) -
       TO_NUMBER(NVL(T1.SEND_COUNT, '0')) NOTSEND_COUNT,
       (TO_NUMBER(NVL(T1.PLANWT, '0')) +
       TO_NUMBER(NVL(T1.STORAGE_COUNT, '0')) -
       TO_NUMBER(NVL(T1.BEEN_WT, '0'))) PREP_WT
  FROM (SELECT T.CUSTOMER_NO,
               T.CUSTOMER_NM,
               T.TRANSIT_TYP,
               T.RECEIV_NO,
               T.RECEIV_NM,
               NVL(SUM(T.DELVRY_QTY), '0') DELVRY_QTY,
               NVL(SUM(T.STORAGE_UNIT), '0') STORAGE_UNIT,
               NVL(SUM(T.STORAGE_COUNT), '0') STORAGE_COUNT,
               NVL(SUM(T.STORAGE_METER), '0') STORAGE_METER,
               NVL(SUM(T.PLANWEIGHT), '0') PLANWEIGHT,
               NVL(SUM(T.PAYDOWNWEIGHT), '0') PAYDOWN_COUNT,
               NVL(SUM(T.PLAN_NUM), '0') PLAN_NUM,
               NVL(SUM(T.PAYDOWN_NUM), '0') PAYDOWN_NUM,
               NVL(SUM(T.SEND_COUNT), '0') SEND_COUNT,
               NVL(SUM((SELECT SUM(C.PLAN_WT)
                         FROM YDM_ZC_SENDPLAN_C C
                        WHERE C.ORDER_NO = T.ORDER_NO
                          AND C.ORDER_SEQ = T.ORDER_SEQ
                          AND C.DELIVERY_NO = T.DELIVERY_NO
                          AND C.VALIDFLAG = '1')),
                   '0') BEEN_WT,
               SUM(CASE
                     WHEN TO_NUMBER(NVL(T.PLANWEIGHT, '0')) -
                          TO_NUMBER(NVL(T.PAYDOWNWEIGHT, '0')) < 0 THEN
                      0
                     WHEN TO_NUMBER(NVL(T.PLANWEIGHT, '0')) -
                          TO_NUMBER(NVL(T.PAYDOWNWEIGHT, '0')) >= 0 THEN
                      TO_NUMBER(NVL(T.PLANWEIGHT, '0')) -
                      TO_NUMBER(NVL(T.PAYDOWNWEIGHT, '0'))
                   END) AS PLANWT,
               SUM(CASE
                     WHEN TO_NUMBER(NVL(T.PLAN_NUM, '0')) -
                          TO_NUMBER(NVL(T.PAYDOWN_NUM, '0')) < 0 THEN
                      0
                     WHEN TO_NUMBER(NVL(T.PLAN_NUM, '0')) -
                          TO_NUMBER(NVL(T.PAYDOWN_NUM, '0')) >= 0 THEN
                      TO_NUMBER(NVL(T.PLAN_NUM, '0')) -
                      TO_NUMBER(NVL(T.PAYDOWN_NUM, '0'))
                   END) AS PlANNUM,
               T.SALE_ORG,
               T.SALE_ORG_DESC,
               T.CREATE_DEPT,
               T.DEPARTNAME
          FROM V_YDM_ZC_SENDPLAN_C T
         WHERE DECODE(?, NULL, '1', T.CUSTOMER_NM) = DECODE(?, NULL, '1', ?)
           AND T.DELVRY_EDATE BETWEEN ? AND ?
           AND T.ORDER_NO || '&' LIKE ('%' || ? || '%')
         GROUP BY T.CUSTOMER_NO,
                  T.CUSTOMER_NM,
                  T.TRANSIT_TYP,
                  T.RECEIV_NO,
                  T.RECEIV_NM,
                  T.SALE_ORG,
                  T.SALE_ORG_DESC,
                  T.CREATE_DEPT,
                  T.DEPARTNAME) T1
 WHERE 1 = 1
   AND (T1.STORAGE_COUNT > 0 OR T1.PLAN_NUM > 0)
		]]>
	</query>

	<query id="CorePipeLeaveFactory.GetCustomer" desc="用户获取">
		<![CDATA[
	       SELECT   CUSTOMER_NM,CUSTOMER_NO
	       FROM SLM_BASE_CUSTOMER
	       WHERE VALIDFLAG='1'
	       ORDER BY CUSTOMER_NM ASC
		]]>
	</query>
	<query id="CorePipeLeaveFactory.QueryChild" desc="材料查询">
		<![CDATA[  
    SELECT T1.*,
       'FALSE' CHK,
       (TO_NUMBER(NVL(T1.DELVRY_QTY, '0')) -
       TO_NUMBER(NVL(T1.SEND_COUNT, '0'))) NOTSEND_COUNT,
       TO_NUMBER(NVL(T1.PLANWT, '0')) +
       TO_NUMBER(NVL(T1.STORAGE_COUNT, '0')) -
       TO_NUMBER(NVL(T1.BEEN_WT, '0')) PREP_WT,
       TO_NUMBER(NVL(T1.PLANWT, '0')) +
       TO_NUMBER(NVL(T1.STORAGE_COUNT, '0')) -
       TO_NUMBER(NVL(T1.BEEN_WT, '0')) PLAN_COUNT
  FROM (SELECT T.*,
               NVL((SELECT SUM(C.PLAN_WT)
                     FROM YDM_ZC_SENDPLAN_C C
                    WHERE C.ORDER_NO = T.ORDER_NO
                      AND C.ORDER_SEQ = T.ORDER_SEQ
                      AND C.DELIVERY_NO = T.DELIVERY_NO
                      AND C.VALIDFLAG = '1'),
                   '0') BEEN_WT,
               CASE
                 WHEN TO_NUMBER(NVL(T.PLANWEIGHT, '0')) -
                      TO_NUMBER(NVL(T.PAYDOWNWEIGHT, '0')) < 0 THEN
                  0
                 WHEN TO_NUMBER(NVL(T.PLANWEIGHT, '0')) -
                      TO_NUMBER(NVL(T.PAYDOWNWEIGHT, '0')) >= 0 THEN
                  TO_NUMBER(NVL(T.PLANWEIGHT, '0')) -
                  TO_NUMBER(NVL(T.PAYDOWNWEIGHT, '0'))
               END AS PLANWT,
               CASE
                 WHEN TO_NUMBER(NVL(T.PLAN_NUM, '0')) -
                      TO_NUMBER(NVL(T.PAYDOWN_NUM, '0')) < 0 THEN
                  0
                 WHEN TO_NUMBER(NVL(T.PLAN_NUM, '0')) -
                      TO_NUMBER(NVL(T.PAYDOWN_NUM, '0')) >= 0 THEN
                  TO_NUMBER(NVL(T.PLAN_NUM, '0')) -
                  TO_NUMBER(NVL(T.PAYDOWN_NUM, '0'))
               END AS PlANNUM
          FROM V_YDM_ZC_SENDPLAN_C T
         WHERE t.CUSTOMER_NO = ?
           and t.RECEIV_NO = ?
           and t.SALE_ORG = ?
           and t.CREATE_DEPT = ?
           AND T.DELVRY_EDATE BETWEEN ? AND ?
           AND T.ORDER_NO || '&' LIKE ('%' || ? || '%')
           ) T1
 WHERE 1 = 1
   AND (T1.STORAGE_COUNT > 0 OR T1.PLAN_NUM > 0)
 ORDER BY T1.ORDER_NO, T1.ORDER_SEQ, T1.DELIVERY_NO
		]]>
	</query>

	<query id="CorePipeLeaveFactory.IsExistPlan" desc="查询发运计划主表是否有信息">
 <![CDATA[
 SELECT T.SEND_PLAN_NO
   FROM YDM_ZC_SENDPLAN_C T, YDM_ZC_SENDPLAN_M T1
  WHERE T.SEND_PLAN_NO = T1.SEND_PLAN_NO
    AND T.ORDER_NO = ?
    AND T1.PLAN_YEAR_MONTH=?
    AND T.ORDER_SEQ=?
  --AND T.DELIVERY_NO=?
    AND T1.CUSTOMER_NO=?
    AND T1.RECEIV_NO=?
    AND T.VALIDFLAG = '1'
    AND T1.SEND_PLAN_STATUS = '0'
 ]]>
	</query>
	<query id="CorePipeLeaveFactory.IsExistPlanC" desc="查询发运计划子表是否有信息">
		<![CDATA[
SELECT T.SEND_PLAN_NO
   FROM YDM_ZC_SENDPLAN_C T, YDM_ZC_SENDPLAN_M T1
  WHERE T.SEND_PLAN_NO = T1.SEND_PLAN_NO
    AND T.SEND_PLAN_NO=?
    AND T.ORDER_NO = ?
    AND T.ORDER_SEQ=?
    AND T.DELIVERY_NO=?
    AND T.VALIDFLAG = '1'
    AND T1.SEND_PLAN_STATUS = '0'
		]]>
	</query>
	<query id="CorePipeLeaveFactory.ADDSENDPLANM" desc="插入计划主表YDM_ZC_SENDPLAN_M">
		<![CDATA[
    INSERT INTO YDM_ZC_SENDPLAN_M
  (SEND_PLAN_NO,
   SALE_ORG,
   SALE_ORG_DESC,
   CUSTOMER_NO,
   CUSTOMER_NM,
   RECEIV_NO,
   RECEIV_NM,
   TRANS_TYPE,
   PLAN_YEAR_MONTH,
   PLAN_START_TIME,
   PLAN_END_TIME,
   PLAN_WT,
   PLAN_NUM,
   PLAN_TOTL_LEN,
   CREATE_NAME,
   SEND_PLAN_STATUS,
   CREATE_TIME,
   DEPARTMENT_CODE,
   DEPARTMENT_DESC,
   MANAGEMENT_NO,
   MANAGEMENT_NAME)
VALUES
  (?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   ?,
   TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
   TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
   TO_NUMBER(?),
   TO_NUMBER(?),
   TO_NUMBER(?),
   ?,
   '0',
   SYSDATE,
   ?,
   ?,
   ?,
   ?)
		]]>
	</query>

	<query id="CorePipeLeaveFactory.ADDSENDPLANC" desc="插入计划子表材料">
		<![CDATA[
	      INSERT INTO YDM_ZC_SENDPLAN_C
  (SEND_PLAN_NO,
   ORDER_NO,
   ORDER_SEQ,
   DELIVERY_NO,
   PRODUCCODE,
   PRODUCNAME,
   PRD_CLS,
   PSC,
   PSC_DESC,
   SPEC_CODE,
   SPEC_NAME,
   LEN_NO,
   LEN_DESC,
   PLAN_WT,
   PLAN_NUM,
   PLAN_TOTL_LEN,
   CREATE_NAME,
   CREATE_TIME,
   ORD_PK,
   ORD_LN_PK,
   ORD_LN_DLY_PK,
   DELVRY_BDATE,
   DELVRY_EDATE
   )
   VALUES
   (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, SYSDATE,?,?,?,TO_DATE(?,'YYYY-MM-DD'),TO_DATE(?,'YYYY-MM-DD'))
	      
		]]>
	</query>

	<query id="CorePipeLeaveFactory.UPDATESENDPLANM" desc="修改出厂计划主表YDM_ZC_SENDPLAN_M">
		<![CDATA[
       UPDATE YDM_ZC_SENDPLAN_M
       SET
       SALE_ORG           = ?,
       SALE_ORG_DESC      = ?,
       CUSTOMER_NO        = ?,
       CUSTOMER_NM        = ?,
       RECEIV_NO          = ?,
       RECEIV_NM          = ?,
       --STLMT_UNIT_NO      = ?,
       --STLMT_UNIT_NM      = ?,
       TRANS_TYPE         = ?,
       --DELIVY_PLACE_CODE  = ?,
       --DELIVY_PLACE_NAME  = ?,
       DELVRY_BDATE       = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       DELVRY_EDATE       = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       PLAN_YEAR_MONTH    = ?,
       PLAN_START_TIME    = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       PLAN_END_TIME      = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
       PLAN_WT            = (SELECT TO_NUMBER(PLAN_WT)+TO_NUMBER(?) FROM
       YDM_ZC_SENDPLAN_M T  WHERE SEND_PLAN_NO = ? ),
       PLAN_NUM           = (SELECT TO_NUMBER(PLAN_NUM)+TO_NUMBER(?) FROM
       YDM_ZC_SENDPLAN_M T  WHERE SEND_PLAN_NO = ? ),
       PLAN_TOTL_LEN      = (SELECT TO_NUMBER(PLAN_TOTL_LEN)+TO_NUMBER(?) FROM
       YDM_ZC_SENDPLAN_M T  WHERE SEND_PLAN_NO = ? ),
       UPDATE_NAME        = ?,
       UPDATE_TIME        = SYSDATE
       WHERE  SEND_PLAN_NO  = ?
       AND VALIDFLAG     ='1' 
         
		]]>
	</query>
	<query id="CorePipeLeaveFactory.UPDAESENDPLANC" desc="修改出厂计划子表YDM_ZC_SENDPLAN_C">
 <![CDATA[
 UPDATE YDM_ZC_SENDPLAN_C
   SET PLAN_WT        =
       (SELECT TO_NUMBER(PLAN_WT) + TO_NUMBER(?)
          FROM YDM_ZC_SENDPLAN_C T
         WHERE SEND_PLAN_NO = ?
           AND ORDER_NO = ?
           AND ORDER_SEQ = ?
           AND DELIVERY_NO = ?),
       PLAN_NUM       =
       (SELECT TO_NUMBER(PLAN_NUM) + TO_NUMBER(?)
          FROM YDM_ZC_SENDPLAN_C T
         WHERE SEND_PLAN_NO = ?
           AND ORDER_NO = ?
           AND ORDER_SEQ = ?
           AND DELIVERY_NO = ?),
       PLAN_TOTL_LEN  =
       (SELECT TO_NUMBER(PLAN_TOTL_LEN) + TO_NUMBER(?)
          FROM YDM_ZC_SENDPLAN_C T
         WHERE SEND_PLAN_NO = ?
           AND ORDER_NO = ?
           AND ORDER_SEQ = ?
           AND DELIVERY_NO = ?),
       UPDATE_NAME     = ?,
       UPDATE_TIME     = SYSDATE
 WHERE SEND_PLAN_NO = ?
   AND ORDER_NO = ?
   AND ORDER_SEQ = ?
   AND DELIVERY_NO = ?
   AND VALIDFLAG = '1'   
  ]]>
	</query>
	<query id="CorePipeLeaveFactory.QuerySENDPLANM" desc="查询 出厂计划主表">
		<![CDATA[
	    SELECT DISTINCT T.SEND_PLAN_NO,
                T.SALE_ORG,
                T.SALE_ORG_DESC,
                T.CUSTOMER_NO,
                T.CUSTOMER_NM,
                T.RECEIV_NO,
                T.RECEIV_NM,
                T.TRANS_TYPE,
                B.BASENAME,
                T.ACT_TRANS_TYPE,
                TO_CHAR(T.DELVRY_BDATE, 'YYYY-MM-DD') AS DELVRY_BDATE,
                TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD') AS DELVRY_EDATE,
                T.PLAN_YEAR_MONTH,
                TO_CHAR(T.PLAN_START_TIME, 'YYYY-MM-DD') AS PLAN_START_TIME,
                TO_CHAR(T.PLAN_END_TIME, 'YYYY-MM-DD') AS PLAN_END_TIME,
                T.ACT_START_TIME,
                T.ACT_END_TIME,
                T.PLAN_REL_TIME,
                T.PLAN_WT,
                T.PLAN_NUM,
                T.PLAN_TOTL_LEN,
                DECODE(T.SEND_PLAN_STATUS,
                       '0',
                       '编辑',
                       '1',
                       '下发',
                       '2',
                       '执行',
                       '关闭') SEND_PLAN_STATUS,
                DECODE(T.VALIDFLAG, '1', '有效', '无效') VALIDFLAG,
                T.CREATE_NAME,
                TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
                T.UPDATE_NAME,
                T.UPDATE_TIME
  FROM YDM_ZC_SENDPLAN_M T, YDM_ZC_SENDPLAN_C T1, COM_BASE_INFO B
 WHERE T.TRANS_TYPE = B.BASECODE(+)
   AND T.SEND_PLAN_NO = T1.SEND_PLAN_NO(+)
   AND T.PLAN_YEAR_MONTH || '&' LIKE ('%' || ? || '%')
   AND T.SEND_PLAN_STATUS || '&' LIKE ('%' || ? || '%')
   AND T1.ORDER_NO || '&' LIKE ('%' || ? || '%')
   AND T.CUSTOMER_NM || '&' LIKE ('%' || ? || '%')
   AND T.VALIDFLAG = '1'
   AND T.TRANS_TYPE = '110501'
		]]>
	</query>

	<query id="CorePipeLeaveFactory.QuerySENDPLANC" desc="查询出厂计划子表">
		<![CDATA[
	 SELECT 
       SEND_PLAN_NO,
       --SEND_ORDER_BATCH,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       PRODUCCODE,
       PRODUCNAME,
       PRD_CLS,
       PSC,
       PSC_DESC,
       SPEC_CODE,
       SPEC_NAME,
       LEN_NO,
       LEN_DESC,
       PLAN_WT,
       PLAN_NUM,
       PLAN_TOTL_LEN,
       DECODE(VALIDFLAG,'1','有效','无效') VALIDFLAG,
       CREATE_NAME,
       TO_CHAR(CREATE_TIME,'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       TO_CHAR(DELVRY_EDATE,'YYYY-MM-DD') DELVRY_EDATE
       FROM YDM_ZC_SENDPLAN_C
       WHERE VALIDFLAG='1'
       AND SEND_PLAN_NO=? 
       ORDER BY ORDER_NO,ORDER_SEQ,DELIVERY_NO
		]]>
	</query>

	<query id="CorePipeLeaveFactory.GetMaxSendPlanNo" desc="查询发运计划号的后四位最大流水号">
		<![CDATA[	      
     SELECT T.PLANNO
     FROM (SELECT MAX(SUBSTR(SEND_PLAN_NO, -4, 4)) AS PLANNO
          FROM YDM_ZC_SENDPLAN_M) T
     WHERE T.PLANNO IS NOT NULL

		]]>
	</query>

	<query id="CorePipeLeaveFactory.ChildMaxBatch" desc="更新数据状态">
		<![CDATA[
	        SELECT T.PLANNO
     FROM (SELECT MAX(SUBSTR(SEND_ORDER_BATCH, -3, 3)) AS PLANNO
          FROM YDM_ZC_SENDPLAN_C WHERE SEND_PLAN_NO = ?) T
     WHERE T.PLANNO IS NOT NULL 
		]]>
	</query>
	<query id="CorePipeLeaveFactory.DeltePlanSend" desc="删除子表数据">
<![CDATA[
DELETE YDM_ZC_SENDPLAN_C
 WHERE SEND_PLAN_NO = ?
   AND ORDER_NO = ?
   AND ORDER_SEQ = ?
   AND DELIVERY_NO = ?
   AND VALIDFLAG= '1'
]]>
	</query>
	<query id="CorePipeLeaveFactory.UdatePlan" desc="更新子表状态">
<![CDATA[
--UPDATE YDM_ZC_SENDPLAN_C
--   SET VALIDFLAG = '0',    
--      UPDATE_NAME = ?,
--      UPDATE_TIME = SYSDATE
DELETE YDM_ZC_SENDPLAN_C
 WHERE SEND_PLAN_NO = ?
   AND ORDER_NO = ?
   AND ORDER_SEQ = ?
   AND DELIVERY_NO = ?
   AND VALIDFLAG='1'
]]>
	</query>
	<query id="CorePipeLeaveFactory.UdateSendPlan" desc="更新主表状态">
<![CDATA[
--UPDATE YDM_ZC_SENDPLAN_M
   --SET VALIDFLAG = '0', UPDATE_NAME = ?, UPDATE_TIME = SYSDATE
DELETE YDM_ZC_SENDPLAN_M
 WHERE SEND_PLAN_NO = ?
   AND SEND_PLAN_STATUS = '0'
   AND VALIDFLAG = '1'
]]>
	</query>
	<query id="CorePipeLeaveFactory.UdateSendPlanChild" desc="更新主表支、吨、米">
<![CDATA[
UPDATE YDM_ZC_SENDPLAN_M
   SET PLAN_WT      =
       (SELECT SUM(TO_NUMBER(T.PLAN_WT))
          FROM YDM_ZC_SENDPLAN_C T
         WHERE T.SEND_PLAN_NO = ?
           AND T.VALIDFLAG = '1'),
       PLAN_NUM     =
       (SELECT SUM(TO_NUMBER(T.PLAN_NUM))
          FROM YDM_ZC_SENDPLAN_C T
         WHERE T.SEND_PLAN_NO = ?
           AND T.VALIDFLAG = '1'),
       PLAN_TOTL_LEN =
       (SELECT SUM(TO_NUMBER(T.PLAN_TOTL_LEN))
          FROM YDM_ZC_SENDPLAN_C T
         WHERE T.SEND_PLAN_NO = ?
           AND T.VALIDFLAG = '1')
 WHERE SEND_PLAN_NO = ?
   AND SEND_PLAN_STATUS = '0'
   AND VALIDFLAG = '1'
]]>
	</query>
	<query id="CorePipeLeaveFactory.QueryPlanIssued" desc="下发计划">
<![CDATA[
UPDATE YDM_ZC_SENDPLAN_M
   SET SEND_PLAN_STATUS = '1',
       UPDATE_NAME      = ?,
       UPDATE_TIME      = SYSDATE
 WHERE SEND_PLAN_NO = ?
   AND VALIDFLAG = '1'
]]>
	</query>
	<query id="CorePipeLeaveFactory.QueryPlanState" desc="查询主表发货计划状态">
<![CDATA[
SELECT DECODE(SEND_PLAN_STATUS,
              '0',
              '编辑',
              '1',
              '下发',
              '2',
              '执行',
              '关闭') SEND_PLAN_STATUS
  FROM YDM_ZC_SENDPLAN_M
 WHERE SEND_PLAN_NO = ?
   AND VALIDFLAG = '1'
]]>
	</query>
	<query id="CorePipeLeaveFactory.QuerySendSl" desc="查询发运计划号">
<![CDATA[
SELECT MAX(T.SEND_PLAN_NO) MAX_SEQ
  FROM YDM_ZC_SENDPLAN_M T
 WHERE SUBSTR(T.SEND_PLAN_NO, 4, 4) = TO_CHAR(SYSDATE, 'YYMM')
   AND T.SALE_ORG = ?
]]>
	</query>

	<query id="CorePipeLeaveFactory.getCustomerBySalg" desc="查询订货单位客户信息">
       <![CDATA[
          SELECT DISTINCT T1.CUSTOMER_NO, T1.CUSTOMER_NM, T2.SALE_ORG
  FROM SLM_BASE_CUSTOMER T1, SLM_BASE_CUSTM_USE T2
 WHERE T1.CUSTOMER_NO = T2.CUSTOMER_NO
   AND T1.VALIDFLAG = '1'
   AND T2.VALIDFLAG = '1'
   AND T2.CUSTM_USE='100202'
         ]]>
	</query>
	<query id="CorePipeLeaveFactory.QueryMatPlan" desc="库存可编制量信息">
	<![CDATA[
SELECT (TO_NUMBER(NVL(T1.PLANWT, '0')) +
       TO_NUMBER(NVL(T1.STORAGE_COUNT, '0')) -
       TO_NUMBER(NVL(T1.BEEN_WT, '0'))) PREP_WT,
       NVL(T1.DELVRY_QTY,'0') AS DELVRY_QTY,
       NVL(T1.DELVRY_RANGE_MAX,'0') AS DELVRY_RANGE_MAX,
       T1.BEEN_WT
  FROM (SELECT T.STORAGE_COUNT,T.DELVRY_QTY,T.DELVRY_RANGE_MAX,
               NVL((SELECT SUM(C.PLAN_WT)
                     FROM YDM_ZC_SENDPLAN_C C
                    WHERE C.ORD_PK = T.ORD_PK
                      AND C.ORD_LN_PK = T.ORD_LN_PK
                      AND C.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK 
                      AND C.VALIDFLAG = '1'),
                   '0') BEEN_WT,
               CASE
                 WHEN TO_NUMBER(NVL(T.PLANWEIGHT, '0')) -
                      TO_NUMBER(NVL(T.PAYDOWNWEIGHT, '0')) < 0 THEN
                  0
                 WHEN TO_NUMBER(NVL(T.PLANWEIGHT, '0')) -
                      TO_NUMBER(NVL(T.PAYDOWNWEIGHT, '0')) >= 0 THEN
                  TO_NUMBER(NVL(T.PLANWEIGHT, '0')) -
                  TO_NUMBER(NVL(T.PAYDOWNWEIGHT, '0'))
               END AS PLANWT
          FROM V_YDM_ZC_SENDPLAN_C T
         WHERE T.ORD_PK = ?
           AND T.ORD_LN_PK = ?
           AND T.ORD_LN_DLY_PK = ?) T1
	]]>
	</query>
	
	
</queryMap>