<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="铁运出厂月计划运号审批">

<query id="FrmShipmentApp.doQuery" desc="运号审批查询">
  <![CDATA[	 
  SELECT T.ASK_MONTH_PK,
        T.ASK_MONTH_NO,
        T.PLAN_YEAR_MONTH,
        T.WAGONS_PLAN_NO,
       NVL(T.VEHICLE_MONTH_NUM, '0') AS VEHICLE_MONTH_NUM,
       NVL(T.BATCH_MONTH_NUM, '0') AS BATCH_MONTH_NUM,
       NVL(T.ACT_MONTH_NUM, '0') AS ACT_MONTH_NUM,
       DECODE(T.WAGONS_FLAG, '1', 'FALSE', '2', 'TRUE') AS WAGONS_FLAG,
       (SELECT B.BASENAME FROM COM_BASE_INFO B WHERE B.BASECODE=T.STATION_CODE ) AS STATION_NAME,
       T.STATION_NM,
       T.SPCL_LN_NM,
       T.CUSTOMER_NM,
       T.RECEIV_NM,
       T.SALE_ORG_DESC,
       T.PRODUC_DESC,
       T.PUR_NAME,
       TO_CHAR(T.PUR_TIME, 'YYYY-MM-DD HH24:MI:SS') AS PUR_TIME,
       TO_CHAR(T.APP_TIME, 'YYYY-MM-DD HH24:MI:SS') AS APP_TIME,
       T.APP_NAME,
       DECODE(T.APP_FLAG, '1', '已审批', '0', '未审批') AS APP_FLAG,
       T.DEPARTMENT_DESC,
       T.MANAGEMENT_NAME,
       T.MEMO
  FROM YDM_ZC_ASK_MONTH T
 WHERE T.ASK_MONTH_NO || '&' LIKE ('%' || ? || '%')
   AND T.APP_FLAG || '&' LIKE ('%' || ? || '%')
   AND DECODE(?, NULL, SYSDATE, T.PUR_TIME) 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="FrmShipmentApp.doUpdate" desc="修改车皮运号，批复数">
  <![CDATA[	
   UPDATE YDM_ZC_ASK_MONTH
   SET WAGONS_PLAN_NO  = ?,
       BATCH_MONTH_NUM = TO_NUMBER(?),
       UPDATE_NAME     = ?,
       UPDATE_TIME     = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
 WHERE ASK_MONTH_PK=?
 AND VALIDFLAG='1'
    ]]>
</query>
<query id="FrmShipmentApp.doApp" desc="审批">
  <![CDATA[	
   UPDATE YDM_ZC_ASK_MONTH
   SET APP_FLAG  = '1',
       APP_NAME  = ?,
       APP_TIME  =  TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
 WHERE ASK_MONTH_PK=?
 AND VALIDFLAG='1'
    ]]>
</query>
<query id="FrmShipmentApp.doDeleteApp" desc="取消">
  <![CDATA[	
   UPDATE YDM_ZC_ASK_MONTH
   SET APP_FLAG  = '0',
       APP_NAME  = ?,
       APP_TIME  = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
 WHERE ASK_MONTH_PK=?
 AND VALIDFLAG='1'
    ]]>
</query>
<query id="FrmShipmentApp.doQueryFalg" desc="查询批复状态">
<![CDATA[	
SELECT T.APP_FLAG,
       T.WAGONS_PLAN_NO,
       NVL(T.BATCH_MONTH_NUM, '0') AS BATCH_MONTH_NUM
  FROM YDM_ZC_ASK_MONTH T
 WHERE T.ASK_MONTH_PK =?
    ]]>
</query>
<query id="FrmShipmentApp.QuerySENDPLANM" desc="查询月出厂计划主表">
		<![CDATA[
	 SELECT T.RECEIV_NO,
       T.RECEIV_NM,
       T.TRANS_TYPE,
       T.PLAN_YEAR_MONTH,
       T.STATION_NM,
       T.STATION_NO,
       T.SPCL_LN_NM,
       T.SPCL_LN_NO,
       NVL((SELECT SUM(M.VEHICLE_MONTH_NUM)
          FROM ydm_zc_ask_month M
         WHERE M.STATION_NO = T.STATION_NO
          AND DECODE(M.SPCL_LN_NO,'','N',SPCL_LN_NO) = DECODE(T.SPCL_LN_NO,'','N',SPCL_LN_NO)
           AND M.RECEIV_NO = T.RECEIV_NO
           AND M.PLAN_YEAR_MONTH = T.PLAN_YEAR_MONTH),0) AS HAVE_MONTH_NUM,
       SUM(NVL(T1.PLAN_WT, 0)) AS PLAN_WT     
  FROM YDM_ZC_SENDPLAN_M T, YDM_ZC_SENDPLAN_C T1
 WHERE T.SEND_PLAN_NO = T1.SEND_PLAN_NO(+)
   AND T.PLAN_YEAR_MONTH || '&' LIKE ('%' || ? || '%')
   AND T.STATION_NO || '&' LIKE ('%' || ? || '%')
   AND T.SPCL_LN_NO || '&' LIKE ('%' || ? || '%')
   AND T1.ORDER_NO || '&' LIKE ('%' || ? || '%')
   AND T.RECEIV_NM || '&' LIKE('%' || ? || '%')
   AND T.VALIDFLAG = '1'
   AND T.TRANS_TYPE = '110502'
   AND T.SEND_PLAN_STATUS IN ('1', '2')
		]]>
	</query>
<query id="FrmShipmentApp.AddAskMonth" desc="新增月度请车">
		<![CDATA[
		INSERT INTO YDM_ZC_ASK_MONTH (ASK_MONTH_NO, VEHICLE_MONTH_NUM, 
		WAGONS_FLAG, STATION_NO, STATION_NM, SPCL_LN_NO, SPCL_LN_NM,RECEIV_NO, RECEIV_NM, PUR_NAME, PUR_TIME, 
		DEPARTMENT_CODE, DEPARTMENT_DESC, MANAGEMENT_NO, MANAGEMENT_NAME, CREATE_NAME, 
		CREATE_TIME,PLAN_YEAR_MONTH) 
		VALUES (?,  TO_NUMBER(?), ?, ?, ?, ?, ?, ?, ?, ?, 
		TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), ?, ?, ?, ?, ?, TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),?)
		]]>
	</query>
<query id="FrmShipmentApp.queryAskMonth" desc="查询月度请车">
  <![CDATA[
  SELECT NVL(T.VEHICLE_MONTH_NUM, '0') AS VEHICLE_MONTH_NUM,
       NVL(T.BATCH_MONTH_NUM, '0') AS BATCH_MONTH_NUM,
       T.APP_FLAG,T.ASK_MONTH_NO,T.WAGONS_FLAG
  FROM YDM_ZC_ASK_MONTH T
 WHERE T.PLAN_YEAR_MONTH = ?
 AND T.STATION_NO=?
 AND DECODE(T.SPCL_LN_NO,'','N',SPCL_LN_NO) =?
 AND T.RECEIV_NO=?
 AND T.ASK_MONTH_NO=?
   AND T.VALIDFLAG = '1'
  	]]>
</query>
<query id="FrmShipmentApp.doQueryAskMonth" desc="查询月度请车批车号">
  <![CDATA[
  SELECT T.ASK_MONTH_NO
  FROM YDM_ZC_ASK_MONTH T
 WHERE TO_CHAR(T.CREATE_TIME, 'YYYY-MM') || '&' LIKE
       ('%' || ? || '%')
   AND T.VALIDFLAG = '1'
 GROUP BY T.ASK_MONTH_NO
 ORDER BY T.ASK_MONTH_NO DESC
  	]]>
</query>
<query id="FrmShipmentApp.doDeleteAdd" desc="取消请车">
  <![CDATA[	
   DELETE YDM_ZC_ASK_MONTH  WHERE ASK_MONTH_PK=?
    ]]>
</query>
<query id="FrmShipmentApp.queryAskMonthFlag" desc="查询请车信息">
  <![CDATA[
  SELECT NVL(T.VEHICLE_MONTH_NUM, '0') AS VEHICLE_MONTH_NUM,
       NVL(T.BATCH_MONTH_NUM, '0') AS BATCH_MONTH_NUM,
       T.APP_FLAG,T.ASK_MONTH_NO,T.WAGONS_FLAG
  FROM YDM_ZC_ASK_MONTH T
 WHERE T.ASK_MONTH_PK=?
   AND T.VALIDFLAG = '1'
  	]]>
</query>
<query id="FrmShipmentApp.doQueryDayFalg" desc="FrmShipmentApp.doQueryDayFalg">
  <![CDATA[
SELECT T.ASK_DAY_NO FROM YDM_ZC_ASK_DAY T WHERE T.ASK_MONTH_NO=? AND T.SEND_PLAN_NO =?
  	]]>
</query>
<query id="FrmShipmentApp.QuerySENDPLANC" desc="查询出厂计划子表">
		<![CDATA[
	 SELECT T.SEND_PLAN_NO,
       T.ORDER_NO || '/' || T.ORDER_SEQ AS ORDERSEQNO,
       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,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') AS CREATE_TIME
  FROM YDM_ZC_SENDPLAN_C T
 WHERE T.VALIDFLAG = '1'       
		]]>
	</query>
	<query id="FrmShipmentApp.QuerySendPlanMat" desc="根据到站、专用线、收货单位、计划年月 查询出厂计划号">
		<![CDATA[
	 SELECT T.SEND_PLAN_NO
  FROM YDM_ZC_SENDPLAN_M T
 WHERE T.PLAN_YEAR_MONTH = ?
   AND T.STATION_NO =?
   AND DECODE(T.SPCL_LN_NO,'','N',SPCL_LN_NO) =?
   AND T.RECEIV_NO = ?
   AND T.TRANS_TYPE = '110502'
   AND T.SEND_PLAN_STATUS IN ('1', '2')
		]]>
	</query>
	<query id="FrmShipmentApp.doQueryMonthask" desc="根据到站、专用线、收货单位、计划年月查询是否已有月请车">
		<![CDATA[
	 SELECT T.ASK_MONTH_NO
  FROM YDM_ZC_ASK_MONTH T
 WHERE T.PLAN_YEAR_MONTH = ?
   AND T.STATION_NO = ?
   AND DECODE(T.SPCL_LN_NO, '', 'N', SPCL_LN_NO) = ?
   AND T.RECEIV_NO = ?
   AND T.VALIDFLAG = '1'
		]]>
	</query>
</queryMap>