<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="铁运出厂月计划">
	<query id="FrmPipeTrainMonth.queryOrderInfo" desc="合同查询">
		<![CDATA[ 
SELECT T.CUSTOMER_NO,
       T.CUSTOMER_NM,
       (SELECT T2.BASENAME
          FROM COM_BASE_INFO T2
         WHERE T2.BASECODE = T.TRANSIT_TYP) TRANSIT_TYP_NAME,
       T.TRANSIT_TYP,
       T.RECEIV_NO,
       T.RECEIV_NM,
       T.STATION_NO,
       T.STATION_NM,
       T.SPCL_LN_NO,
       T.SPCL_LN_NM,
       T.SALE_ORG,
       T.SALE_ORG_DESC,
       T.CREATE_DEPT,
       T.DEPARTNAME,
       T.SUPPLY_UNIT,
       (SELECT T2.BASENAME
          FROM COM_BASE_INFO T2
         WHERE T2.BASECODE = T.SUPPLY_UNIT) SUPPLY_UNIT_DESC,
       SUM(TO_NUMBER(NVL(T.DELVRY_QTY, 0))) DELVRY_QTY,
       SUM(TO_NUMBER(NVL(T.STORAGE_COUNT, 0))) STORAGE_WGT,
       SUM(TO_NUMBER(NVL(T.STORAGE_UNIT, 0))) STORAGE_COUNT,
       SUM(TO_NUMBER(NVL(T.STORAGE_METER, 0))) STORAGE_METER,
       SUM(TO_NUMBER(NVL(T.PLANWEIGHT, 0))) PLAN_WGT,
       SUM(TO_NUMBER(NVL(T.PAYDOWNWEIGHT, 0))) PAYDOWN_WGT,
       SUM(TO_NUMBER(NVL(T.PLAN_NUM, 0))) PLAN_COUNT,
       SUM(TO_NUMBER(NVL(T.PAYDOWN_NUM, 0))) PAYDOWN_COUNT,
       SUM(TO_NUMBER(NVL(T.SEND_COUNT, 0))) SEND_WGT,
       SUM(TO_NUMBER(NVL((SELECT SUM(C.PLAN_WT)
                           FROM YDM_ZC_SENDPLAN_C C
                          WHERE C.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                            AND C.VALIDFLAG = '1'),
                         '0'))) BEEN_WGT
  FROM V_YDM_ZC_SENDPLAN_M_TRAINS T
 WHERE T.DELVRY_EDATE BETWEEN ? AND ?
   AND T.ORDER_NO || '&' LIKE ('%' || ? || '%')
		]]>
	</query>

	<query id="FrmPipeTrainMonth.GetCustomer" desc="查询订货单位">
		<![CDATA[
	     SELECT DISTINCT T1.CUSTOMER_NO, T1.CUSTOMER_NM
  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="FrmPipeTrainMonth.queryOrderInfoC" desc="材料查询">
		<![CDATA[  
      SELECT T1.*,
       'FALSE' CHK,
       --(TO_NUMBER(NVL(T1.STORAGE_COUNT, '0')) -
       --TO_NUMBER(NVL(T1.SEND_COUNT, '0'))) NOTSEND_COUNT,
       --(case when (TO_NUMBER(NVL(T1.PLANWT, '0')) +TO_NUMBER(NVL(T1.STORAGE_COUNT, '0')) -TO_NUMBER(NVL(T1.BEEN_WT, '0')) +TO_NUMBER(NVL(T1.SEND_COUNT, '0')))<0 then 0 
       --else (TO_NUMBER(NVL(T1.PLANWT, '0')) +TO_NUMBER(NVL(T1.STORAGE_COUNT, '0')) -TO_NUMBER(NVL(T1.BEEN_WT, '0')) +TO_NUMBER(NVL(T1.SEND_COUNT, '0'))) end) PREP_WT,
       --(case when (TO_NUMBER(NVL(T1.PLANWT, '0')) +TO_NUMBER(NVL(T1.STORAGE_COUNT, '0')) -TO_NUMBER(NVL(T1.BEEN_WT, '0')) +TO_NUMBER(NVL(T1.SEND_COUNT, '0')))<0 then 0 
       --else (TO_NUMBER(NVL(T1.PLANWT, '0')) +TO_NUMBER(NVL(T1.STORAGE_COUNT, '0')) -TO_NUMBER(NVL(T1.BEEN_WT, '0')) +TO_NUMBER(NVL(T1.SEND_COUNT, '0'))) end) PLAN_COUNT,
       (SELECT T2.BASENAME FROM COM_BASE_INFO T2 WHERE T2.BASECODE=T1.TRANSIT_TYP) TRANSIT_TYP_NAME
  FROM (SELECT T.*,
  (SELECT T4.BASENAME
          FROM COM_BASE_INFO T4
         WHERE T4.BASECODE = T.PRD_CLS) PRD_CLSNAME,
               NVL((SELECT SUM(C1.ACT_WT)
                     FROM YDM_ZC_SENDPLAN_C C1
                    WHERE C1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                      AND C1.VALIDFLAG = '1'),
                   '0') ActWeightBeen,
               NVL((SELECT SUM(C.PLAN_WT)
                     FROM YDM_ZC_SENDPLAN_C C
                    WHERE 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_M_TRAINS T
         WHERE T.DELVRY_EDATE BETWEEN ? AND ?
           AND T.DELVRY_EDATE BETWEEN ? AND ?
           AND NVL(T.SPCL_LN_NO,'/') = NVL(?,'/')
           AND NVL(T.STATION_NO ,'/')=  NVL(?,'/')
           AND NVL(T.CUSTOMER_NO ,'/') =  NVL(?,'/')
           AND NVL(T.RECEIV_NO ,'/') =  NVL(?,'/')
           AND T.SALE_ORG = ?
           AND T.CREATE_DEPT = ?
           AND T.ORDER_NO || '&' LIKE ('%' || ? || '%')
           AND T.TRANSIT_TYP =?
           AND T.SUPPLY_UNIT= ?
           ) T1
 WHERE 1 = 1
--AND T1.STORAGE_UNIT!='0'
   ORDER BY T1.ORDER_NO,T1.ORDER_SEQ,T1.DELIVERY_NO
		]]>
	</query>

	<query id="FrmPipeTrainMonth.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 T1.STATION_NO=?
    AND T1.SPCL_LN_NO=?
    AND T.VALIDFLAG = '1'
    AND T1.SEND_PLAN_STATUS = '0'
    AND T1.APP_FLAG='0'
 ]]>
	</query>
	<query id="FrmPipeTrainMonth.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'
    AND T1.APP_FLAG='0'
		]]>
	</query>
	<query id="FrmPipeTrainMonth.QueryMatPlan" desc="库存可编制量信息">
	<![CDATA[
SELECT NVL(T.DELVRY_QTY, 0) AS DELVRY_QTY,
       T.DELVRY_RANGE_MAX,
       NVL((SELECT SUM(C.PLAN_WT)
             FROM YDM_ZC_SENDPLAN_C C
            WHERE C.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
              AND C.VALIDFLAG = '1'),
           '0') BEEN_WT,
       NVL((SELECT SUM(C1.ACT_WT)
                     FROM YDM_ZC_SENDPLAN_C C1
                    WHERE C1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                      AND C1.VALIDFLAG = '1'),
                   '0') ActWeightBeen,
       NVL(T.PAYDOWNWEIGHT, 0) PAYDOWNWEIGHT,
       NVL(T.PLANWEIGHT, 0) PLANWEIGHT,
       NVL(T.STORAGE_COUNT, 0) STORAGE_COUNT
  FROM V_YDM_ZC_SENDPLAN_M_TRAINS T
 WHERE T.ORD_LN_DLY_PK = ?
	]]>
	</query>
	<query id="FrmPipeTrainMonth.QueryMatPlan1" desc="库存可编制量信息(管坯)">
	<![CDATA[
SELECT NVL(T.DELVRY_QTY, 0) AS DELVRY_QTY,
       T.DELVRY_RANGE_MAX,
       NVL((SELECT SUM(C.PLAN_WT)
             FROM YDM_ZC_SENDPLAN_C C
            WHERE C.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
              AND C.VALIDFLAG = '1'),
           '0') BEEN_WT,
       NVL((SELECT SUM(C1.ACT_WT)
                     FROM YDM_ZC_SENDPLAN_C C1
                    WHERE C1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                      AND C1.VALIDFLAG = '1'),
                   '0') ActWeightBeen,
       NVL(T.PAYDOWNWEIGHT, 0) PAYDOWNWEIGHT,
       NVL(T.PLANWEIGHT, 0) PLANWEIGHT,
       NVL(T.STORAGE_COUNT, 0) STORAGE_COUNT
  FROM V_YDM_GP_SENDPLAN_M_TRAINS T
 WHERE T.ORD_LN_DLY_PK = ?
	]]>
	</query>
	<query id="FrmPipeTrainMonth.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,
   SEND_PLAN_STATUS,
   STATION_NO,
   STATION_NM,
   SPCL_LN_NO,
   SPCL_LN_NM,
   CREATE_NAME,
   CREATE_TIME,
   DEPARTMENT_CODE,
   DEPARTMENT_DESC,
   MANAGEMENT_NO,
   MANAGEMENT_NAME,
   SUPPLY_UNIT,
   SUPPLY_UNIT_DESC)
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="FrmPipeTrainMonth.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="FrmPipeTrainMonth.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 = ? ),
       VEHICLE_MONTH_NUM  = (SELECT TO_NUMBER(VEHICLE_MONTH_NUM)+TO_NUMBER(?) FROM
       YDM_ZC_SENDPLAN_M T  WHERE SEND_PLAN_NO = ? ),
       UPDATE_NAME        = ?,
       UPDATE_TIME        = SYSDATE
       --APP_FLAG           ='0'
       WHERE  SEND_PLAN_NO  = ?
       AND VALIDFLAG     ='1'        
	]]>
	</query>
	<query id="FrmPipeTrainMonth.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="FrmPipeTrainMonth.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 AS TRANS_TYPE_NAME,
                T.ACT_TRANS_TYPE,
                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.STATION_NM,
                T.SPCL_LN_NM,
                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,
                NVL(T.ACT_WT,0) AS  ActWeightBeen,
                T.SUPPLY_UNIT,
                T.SUPPLY_UNIT_DESC
  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 T.STATION_NO || '&' LIKE ('%' || ? || '%')
   AND T.SPCL_LN_NO || '&' LIKE ('%' ||? || '%')
   AND T1.ORDER_NO || '&' LIKE ('%' || ? || '%')
   AND T.CUSTOMER_NM || '&' LIKE ('%' || ? || '%')
   AND T.TRANS_TYPE || '&' LIKE ('%' || ? || '%')
   AND T.VALIDFLAG = '1'

		]]>
	</query>

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

	<query id="FrmPipeTrainMonth.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="FrmPipeTrainMonth.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="FrmPipeTrainMonth.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="FrmPipeTrainMonth.UdatePlan" desc="更新子表状态">
<![CDATA[
 DELETE YDM_ZC_SENDPLAN_C
 WHERE SEND_PLAN_NO = ? AND VALIDFLAG='1'
]]>
	</query>
	<query id="FrmPipeTrainMonth.UdateSendPlan" desc="更新主表状态">
<![CDATA[
   DELETE YDM_ZC_SENDPLAN_M
 WHERE SEND_PLAN_NO = ?
   AND VALIDFLAG = '1'
]]>
	</query>
	<query id="FrmPipeTrainMonth.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="FrmPipeTrainMonth.QueryPlanIssued" desc="下发计划">
<![CDATA[
UPDATE YDM_ZC_SENDPLAN_M
   SET SEND_PLAN_STATUS = '1',
       UPDATE_NAME      = ?,
       UPDATE_TIME      = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
 WHERE SEND_PLAN_NO = ?
   AND VALIDFLAG = '1'
]]>
	</query>
	<query id="FrmPipeTrainMonth.QueryPlanState" desc="查询主表发货计划状态">
<![CDATA[
SELECT DECODE(SEND_PLAN_STATUS,
              '0',
              '编辑',
              '1',
              '下发',
              '2',
              '执行',
              '关闭') SEND_PLAN_STATUS,
              WAGONS_PLAN_NO,
              APP_FLAG
  FROM YDM_ZC_SENDPLAN_M
 WHERE SEND_PLAN_NO = ?
   AND VALIDFLAG = '1'
]]>
	</query>
	<query id="FrmPipeTrainMonth.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="FrmPipeTrainMonth.getSendPlanStatus" desc="查询计划状态">
        <![CDATA[ 
            select T.SEND_PLAN_STATUS,NVL(T.ACT_WT,0) AS ACT_WT from YDM_ZC_SENDPLAN_M t where t.send_plan_no = ?
         ]]>
	</query>
	
	<query id="FrmPipeTrainMonth.doDown" desc="下发计划">
        <![CDATA[ 
          UPDATE  YDM_ZC_SENDPLAN_M T SET T.SEND_PLAN_STATUS='1',T.PLAN_REL_TIME=SYSDATE WHERE T.SEND_PLAN_NO=?
         ]]>
	</query>
	
	<query id="FrmPipeTrainMonth.canceldoDown" desc="取消下发计划">
        <![CDATA[ 
          UPDATE  YDM_ZC_SENDPLAN_M T SET T.SEND_PLAN_STATUS='0',T.PLAN_REL_TIME=NULL WHERE T.SEND_PLAN_NO=?
         ]]>
	</query>
	
	<query id="FrmPipeTrainMonth.queryBillBySendPlanNo" desc="查询计划号的提单号数">
        <![CDATA[ 
          select COUNT(1) COUNT from YDM_ZC_BILL_M T WHERE T.SEND_PLAN_NO = ?
         ]]>
	</query>
	<query id="FrmPipeTrainMonth.getSendPlanC" desc="查询计划从表数据">
        <![CDATA[ 
          SELECT NVL(T.ACT_WT,0) AS ACT_WT,T.ORD_LN_DLY_PK FROM YDM_ZC_SENDPLAN_C  T WHERE T.SEND_PLAN_NO=?
         ]]>
	</query>
	<query id="FrmPipeTrainMonth.updateSendPlanM" desc="释放计划主表计划量">
        <![CDATA[ 
         UPDATE YDM_ZC_SENDPLAN_M
   SET SEND_PLAN_STATUS='3',
   PLAN_WT      = TO_NUMBER(?),
       UPDATE_NAME = ?,
       UPDATE_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
 WHERE SEND_PLAN_NO = ?
         ]]>
	</query>
	<query id="FrmPipeTrainMonth.updateSendPlanC" desc="释放计划从表计划量">
        <![CDATA[ 
           UPDATE YDM_ZC_SENDPLAN_C
   SET 
   PLAN_WT = TO_NUMBER(?), 
   UPDATE_NAME = ?, 
   UPDATE_TIME = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') 
   WHERE SEND_PLAN_NO = ?
    AND ORD_LN_DLY_PK = ?
         ]]>
	</query>
	<query id="FrmPipeTrainMonth.getBillSendStatus" desc="查询计划号下是否有未关闭提单">
        <![CDATA[ 
        SELECT T.BILL_STATUS  FROM YDM_ZC_BILL_M T WHERE T.SEND_PLAN_NO = ?
         ]]>
	</query>
	<query id="FrmPipeTrainMonth.querySendPlanBillM" desc="查询计划号下提单状态">
        <![CDATA[ 
        SELECT DISTINCT T.BILL_STATUS FROM YDM_ZC_BILL_M T WHERE T.SEND_PLAN_NO = ?
         ]]>
	</query>
</queryMap>