<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="铁运出厂日计划">
	<query id="FrmPipeTrainDay.IsExistPlan" desc="查询发运计划主表是否有信息">
 <![CDATA[
 SELECT T.SEND_DAYPLAN_NO
   FROM YDM_ZC_DAYSENDPLAN_TRAIN_C T, YDM_ZC_DAYSENDPLAN_TRAIN_M T1
  WHERE T.SEND_DAYPLAN_NO = T1.SEND_DAYPLAN_NO
    AND T.ORDER_NO = ?
    AND T1.APPLY_DAY=TO_DATE(?,'YYYY-MM-DD')
    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_DAYPLAN_STATUS = '1'
    AND T1.APP_FLAG='0'
 ]]>
	</query>
	<query id="FrmPipeTrainDay.IsExistPlanC" desc="查询发运计划子表是否有信息">
		<![CDATA[
SELECT T.SEND_DAYPLAN_NO
   FROM YDM_ZC_DAYSENDPLAN_TRAIN_C T, YDM_ZC_DAYSENDPLAN_TRAIN_M T1
  WHERE T.SEND_DAYPLAN_NO= T1.SEND_DAYPLAN_NO
    AND T.SEND_DAYPLAN_NO=?
    AND T.ORDER_NO = ?
    AND T.ORDER_SEQ=?
    AND T.DELIVERY_NO=?
    AND T.VALIDFLAG = '1'
    AND T1.SEND_DAYPLAN_STATUS = '1'
    AND T1.APP_FLAG='0'
		]]>
	</query>
	<query id="FrmPipeTrainDay.QueryMatPlan" desc="库存信息">
	<![CDATA[
 SELECT NVL(SUM(T.ACT_LEN),'0') AS ACT_LEN,
       NVL(SUM(T.ACT_COUNT),'0') AS ACT_COUNT,
       NVL(SUM(T.ACT_WEIGHT),'0') AS ACT_WEIGHT
  FROM MAT_ZC_M T
        WHERE T.ORDER_NO=?
         AND T.ORDER_SEQ=?
         AND T.ORDER_SEQ_NO=?
	]]>
	</query>
	<query id="FrmPipeTrainDay.ADDSENDPLANM" desc="插入计划主表YDM_ZC_DAYSENDPLAN_TRAIN_M">
	<![CDATA[
  INSERT INTO YDM_ZC_DAYSENDPLAN_TRAIN_M (SEND_DAYPLAN_NO, SEND_PLAN_NO, 
	WAGONS_PLAN_NO, VEHICLE_60_NUM, VEHICLE_70_NUM, VEHICLE_DAY_NUM, SALE_ORG, 
	SALE_ORG_DESC, CUSTOMER_NO, CUSTOMER_NM, RECEIV_NO, RECEIV_NM, APPLY_DAY, 
	PLAN_START_TIME, PLAN_END_TIME, PLAN_WT, PLAN_NUM, PLAN_TOTL_LEN, 
	SEND_DAYPLAN_STATUS, STATION_NO, STATION_NM, SPCL_LN_NO, SPCL_LN_NM, CREATE_NAME, 
	DEPARTMENT_CODE,DEPARTMENT_DESC,MANAGEMENT_NO,MANAGEMENT_NAME,CREATE_TIME)
	 VALUES 
	 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, TO_DATE(?, 'YYYY-MM-DD'),
	  TO_DATE(?, 'YYYY-MM-DD'), TO_DATE(?, 'YYYY-MM-DD'), TO_NUMBER(?),
      TO_NUMBER(?),TO_NUMBER(?),'0', ?, ?, ?, ?, ?,?,?,?,?, SYSDATE)
	]]>
	</query>
	<query id="FrmPipeTrainDay.ADDSENDPLANC" desc="插入计划子表材料">
	<![CDATA[
 INSERT INTO YDM_ZC_DAYSENDPLAN_TRAIN_C (
	SEND_DAYPLAN_NO, SEND_PLAN_NO, ORDER_NO, 
	ORDER_SEQ, DELIVERY_NO, MATERIAL_NO, MATERIAL_NAME, 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) 
	VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?)   
	]]>
	</query>

	<query id="FrmPipeTrainDay.UPDATESENDPLANM" desc="修改出厂计划主表YDM_ZC_DAYSENDPLAN_TRAIN_M">
	<![CDATA[
     UPDATE YDM_ZC_DAYSENDPLAN_TRAIN_M
   SET PLAN_WT  = ?,
       PLAN_NUM = ?,       
       PLAN_TOTL_LEN   = ?,
       VEHICLE_DAY_NUM = ?,
       VEHICLE_60_NUM  = ?,
       VEHICLE_70_NUM  = ?,
       UPDATE_NAME     = ?,
       UPDATE_TIME     = SYSDATE
 WHERE SEND_DAYPLAN_NO = ?
   AND VALIDFLAG = '1'
	]]>
	</query>
	<query id="FrmPipeTrainDay.UPDAESENDPLANC" desc="修改出厂计划子表YDM_ZC_DAYSENDPLAN_TRAIN_C">
 <![CDATA[
 UPDATE YDM_ZC_DAYSENDPLAN_TRAIN_C
   SET PLAN_WT       = ?,
       PLAN_NUM      = ?,
       PLAN_TOTL_LEN = ?,
       UPDATE_NAME   = ?,
       UPDATE_TIME   = SYSDATE
 WHERE SEND_DAYPLAN_NO = ?
   AND ORDER_NO = ?
   AND ORDER_SEQ = ?
   AND DELIVERY_NO = ?
   AND VALIDFLAG = '1'
  ]]>
	</query>
	<query id="FrmPipeTrainDay.QuerySENDPLANM" desc="查询 出厂月计划主表">
		<![CDATA[
	 SELECT 
	  '0' VEHICLE_60_NUM,
	 (SELECT NVL(SUM(D.VEHICLE_DAY_NUM), '0')
          FROM YDM_ZC_DAYSENDPLAN_TRAIN_M D
         WHERE D.SEND_PLAN_NO = T.SEND_PLAN_NO
           AND D.VALIDFLAG = '1') AS VEHICLE_DAY_NUM,
       (SELECT NVL(SUM(D.PLAN_WT), '0')
          FROM YDM_ZC_DAYSENDPLAN_TRAIN_M D
         WHERE D.SEND_PLAN_NO = T.SEND_PLAN_NO
           AND D.VALIDFLAG = '1') AS EDI_WT, 
            (SELECT NVL(SUM(D.BATCH_DAY_NUM), '0')
          FROM YDM_ZC_DAYSENDPLAN_TRAIN_M D
         WHERE D.SEND_PLAN_NO = T.SEND_PLAN_NO
           AND D.VALIDFLAG = '1') AS BATCH_DAY_NUM,
       NVL(T.BATCH_MONTH_NUM,'0') AS BATCH_MONTH_NUM,
       NVL(T.ACT_MONTH_NUM,'0') AS ACT_MONTH_NUM,
       NVL(T.VEHICLE_MONTH_NUM,'0') AS VEHICLE_MONTH_NUM,
       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,
       T.DELVRY_BDATE,
       T.DELVRY_EDATE,
       T.PLAN_YEAR_MONTH,
       T.PLAN_START_TIME,
       T.PLAN_END_TIME,
       T.ACT_START_TIME,
       T.ACT_END_TIME,
       T.PLAN_REL_TIME,
       DECODE(T.WAGONS_FLAG,'1','FALSE','2','TRUE') AS WAGONS_FLAG,
       T.STATION_NO,
       T.STATION_NM,
       T.SPCL_LN_NO,
       T.SPCL_LN_NM,
       T.WAGONS_PLAN_NO,
       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') AS CREATE_TIME,
       T.UPDATE_NAME,
       T.UPDATE_TIME,
       T.DEPARTMENT_CODE,
       T.DEPARTMENT_DESC,
       T.MANAGEMENT_NO,
       T.MANAGEMENT_NAME
       FROM YDM_ZC_SENDPLAN_M T 
       LEFT JOIN COM_BASE_INFO B ON B.BASECODE=T.TRANS_TYPE
       WHERE DECODE(?,NULL,'1',T.CUSTOMER_NO)=DECODE(?,NULL,'1',?)   
       AND DECODE(?,NULL,'1',T.SPCL_LN_NO)=DECODE(?,NULL,'1',?)
       AND DECODE(?,NULL,'1',T.STATION_NO)=DECODE(?,NULL,'1',?)
       AND T.PLAN_YEAR_MONTH LIKE '%'||?||'%'
       AND T.VALIDFLAG='1'
       AND T.TRANS_TYPE='110502'
       AND T.SEND_PLAN_STATUS IN ('1','2') 
		]]>
	</query>
	<query id="FrmPipeTrainDay.QuerySENDPLANC" desc="查询出厂月计划子表">
		<![CDATA[
	    select * from V_YDM_ZC_DAYSENDPLAN_TRAIN_C t
		]]>
	</query>	
<query id="FrmPipeTrainDay.queryPlanDayInfoM" desc="查询出厂日计划主表">
		<![CDATA[
	 SELECT T.SEND_DAYPLAN_NO,
       T.WAGONS_PLAN_NO,
       T.VEHICLE_60_NUM,
       T.VEHICLE_70_NUM,
       T.VEHICLE_DAY_NUM,
       T.BATCH_DAY_NUM,
       T.ACT_DAY_NUM,
       TO_CHAR(T.APPLY_DAY,'YYYY-MM-DD') AS APPLY_DAY,
       T.SEND_PLAN_NO,
       T.SALE_ORG_DESC,
       T.CUSTOMER_NM,
       T.RECEIV_NM,
       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.STATION_NM,
       T.STATION_NO,
       T.SPCL_LN_NM,
       T.SPCL_LN_NO,
       T.PLAN_WT,
       T.PLAN_NUM,
       T.PLAN_TOTL_LEN,
       DECODE(T.SEND_DAYPLAN_STATUS,
              '0',
              '编辑',
              '1',
              '下发',
              '2',
              '执行',
              '关闭') SEND_DAYPLAN_STATUS,
       DECODE(T.VALIDFLAG, '1', '有效', '无效') VALIDFLAG,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME,'YYYY-MM-DD HH24:MI:SS')     
  FROM YDM_ZC_DAYSENDPLAN_TRAIN_M T
 WHERE DECODE(?, NULL, '1', T.CUSTOMER_NO) = DECODE(?, NULL, '1', ?)
   AND DECODE(?, NULL, '1', T.SPCL_LN_NO) = DECODE(?, NULL, '1', ?)
   AND DECODE(?, NULL, '1', T.STATION_NO) = DECODE(?, NULL, '1', ?)
   AND  DECODE(?, NULL, SYSDATE,T.APPLY_DAY) BETWEEN DECODE(?, NULL, SYSDATE,TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'))
   AND DECODE(?, NULL, SYSDATE,TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'))
   AND T.VALIDFLAG = '1'
		]]>
</query>
<query id="FrmPipeTrainDay.queryPlanDayInfoC" desc="查询出厂日计划主表">
	<![CDATA[
	SELECT SEND_DAYPLAN_NO,
       SEND_PLAN_NO,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       MATERIAL_NAME,
       PRODUCNAME,
       PRD_CLS,
       PSC_DESC,
       SPEC_NAME,
       LEN_DESC,
       NVL(PLAN_WT,'0') AS PLAN_WT,
       NVL(PLAN_NUM,'0') AS PLAN_NUM,
       NVL(PLAN_TOTL_LEN,'0') AS PLAN_TOTL_LEN,
       DECODE(VALIDFLAG,'1','有效','无效') VALIDFLAG,
       CREATE_NAME,
       TO_CHAR(CREATE_TIME,'YYYY-MM-DD HH24:MI:SS') AS CREATE_TIME
       FROM YDM_ZC_DAYSENDPLAN_TRAIN_C
       WHERE VALIDFLAG='1' ORDER BY SEND_DAYPLAN_NO,
       SEND_PLAN_NO,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO
	]]>
</query>	
	<query id="FrmPipeTrainDay.GetMaxSendPlanNo" desc="查询发运计划号的后四位最大流水号">
		<![CDATA[	      
     SELECT T.PLANNO
     FROM (SELECT MAX(SUBSTR(SEND_DAYPLAN_NO, -4, 4)) AS PLANNO
          FROM YDM_ZC_DAYSENDPLAN_TRAIN_M) T
     WHERE T.PLANNO IS NOT NULL
		]]>
	</query>
	<query id="FrmPipeTrainDay.UdatePlan" desc="更新子表状态">
<![CDATA[
UPDATE YDM_ZC_DAYSENDPLAN_TRAIN_C
   SET VALIDFLAG = '0',    
       UPDATE_NAME = ?,
       UPDATE_TIME = SYSDATE
 WHERE SEND_DAYPLAN_NO = ?
   AND SEND_PLAN_NO = ?
   AND ORDER_NO = ?
   AND ORDER_SEQ = ?
   AND DELIVERY_NO = ?
   AND VALIDFLAG='1'
]]>
</query>
<query id="FrmPipeTrainDay.UdateSendPlan" desc="更新主表状态">
<![CDATA[
UPDATE YDM_ZC_DAYSENDPLAN_TRAIN_M
   SET VALIDFLAG = '0', UPDATE_NAME = ?, UPDATE_TIME = SYSDATE
 WHERE SEND_DAYPLAN_NO = ?
   AND SEND_DAYPLAN_STATUS = '1'
   AND VALIDFLAG = '1'
]]>
	</query>
	<query id="FrmPipeTrainDay.QueryPlanIssued" desc="下发计划">
<![CDATA[
UPDATE YDM_ZC_DAYSENDPLAN_TRAIN_M
   SET SEND_DAYPLAN_STATUS = '2',
       UPDATE_NAME      = ?,
       UPDATE_TIME      = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
 WHERE SEND_DAYPLAN_NO = ?
   AND VALIDFLAG = '1'
]]>
	</query>
<query id="FrmPipeTrainDay.QueryPlanState" desc="查询主表发货计划状态">
<![CDATA[
SELECT DECODE(SEND_DAYPLAN_STATUS,
              '0',
              '编辑',
              '1',
              '下发',
              '2',
              '执行',
              '关闭') SEND_DAYPLAN_STATUS,
              WAGONS_PLAN_NO,
              APP_FLAG
  FROM YDM_ZC_DAYSENDPLAN_TRAIN_M
 WHERE SEND_DAYPLAN_NO = ?
   AND VALIDFLAG = '1'
]]>
</query>
<query id="FrmPipeTrainDay.QuerySendC" desc="查询出厂月计划子表">
 <![CDATA[
  select * from V_YDM_ZC_DAYSENDPLAN_TRAIN_C t where t.SEND_PLAN_NO=?
 ]]>
</query>
<query id="FrmPipeTrainDay.QuerySendSl" desc="查询铁运日计划是否有计划号">
<![CDATA[
SELECT SEND_DAYPLAN_NO
  FROM YDM_ZC_DAYSENDPLAN_TRAIN_M
 WHERE CREATE_TIME LIKE '%' || TO_DATE(?, 'YYYY/MM/DD') || '%'
 AND SALE_ORG=?
 ORDER BY SEND_DAYPLAN_NO DESC
]]>
</query>
<query id="FrmPipeTrainDay.queryDaySendPlan" desc="查询发运日计划表批复数量">
<![CDATA[
SELECT NVL(SUM(T.BATCH_DAY_NUM),'0') AS BATCH_DAY_NUM FROM YDM_ZC_DAYSENDPLAN_TRAIN_M T WHERE T.SEND_PLAN_NO=? AND T.VALIDFLAG='1'
]]>
</query>
<query id="FrmPipeTrainDay.queryPlanDay" desc="查询库存可编制量">
<![CDATA[
SELECT TO_NUMBER(NVL(SUM(T.PLAN_WT), '0')) -
       TO_NUMBER(NVL(SUM((SELECT SUM(T1.PLAN_WT)
                        FROM YDM_ZC_DAYSENDPLAN_TRAIN_C T1
                       WHERE T1.SEND_PLAN_NO = T.SEND_PLAN_NO
                         AND T1.ORD_PK = T.ORD_PK
                         AND T1.ORD_LN_PK = T.ORD_LN_PK
                         AND T1.ORD_LN_DLY_PK = T.ORD_LN_DLY_PK
                         AND T1.VALIDFLAG = '1' AND T.VALIDFLAG='1')),
                 '0')) AS PLAN_WT
  FROM YDM_ZC_SENDPLAN_C T
 WHERE T.SEND_PLAN_NO = ?
   AND T.ORD_PK= ?
   AND T.ORD_LN_PK = ?
   AND T.ORD_LN_DLY_PK = ?
   AND T.VALIDFLAG = '1'
]]>
</query>
<query id="FrmPipeTrainDay.queryTallDayPlanM" desc="查询库存可编制量">
<![CDATA[
SELECT NVL(SUM(T.REM_WT),'0') AS REM_WT FROM V_YDM_ZC_DAYSENDPLAN_TRAIN_C T WHERE T.SEND_PLAN_NO=?
]]>
</query>
<query id="FrmPipeTrainDay.queryTallDayPlanC" desc="查询库存可编制量">
<![CDATA[
SELECT NVL(SUM(T.PLAN_WT),'0') AS PLAN_WT FROM YDM_ZC_DAYSENDPLAN_TRAIN_C T WHERE T.SEND_PLAN_NO=? AND T.VALIDFLAG='1'
]]>
</query>
<query id="FrmPipeTrainDay.queryTallMatchSend" desc="查询车皮月度剩余数">
<![CDATA[
SELECT TO_NUMBER(NVL(T.BATCH_MONTH_NUM, '0')) -
       TO_NUMBER(NVL(T.ACT_MONTH_NUM, '0')) -TO_NUMBER(
       (SELECT NVL(SUM(T1.VEHICLE_DAY_NUM),'0')
          FROM YDM_ZC_DAYSENDPLAN_TRAIN_M T1
         WHERE T1.SEND_PLAN_NO = T.SEND_PLAN_NO
           AND T1.APP_FLAG = '0' AND T1.VALIDFLAG='1')) AS SENDNUM
  FROM YDM_ZC_SENDPLAN_M T
 WHERE T.SEND_PLAN_NO = ?
 AND T.VALIDFLAG='1'

]]>
</query>
</queryMap>