<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="铁运出厂日计划运号审批">
<query id="FrmShipmentDayApp.doQuery" desc="运号审批查询">
  <![CDATA[	 
 SELECT 
       T.ASK_DAY_PK,
       T.ASK_DAY_NO,
       T.ASK_MONTH_NO,
       T.WAGONS_PLAN_NO,
       T.BILL_NO,
       NVL(T.VEHICLE_DAY_NUM, '0') AS VEHICLE_DAY_NUM,
       NVL(T.BATCH_DAY_NUM, '0') AS BATCH_DAY_NUM,
       NVL(T.ACT_DAY_NUM, '0') AS ACT_DAY_NUM,
       NVL(T.ACT_DAY_60NUM, '0') AS ACT_DAY_60NUM,
       NVL(T.ACT_DAY_70NUM, '0') AS ACT_DAY_70NUM,
       DECODE(T.WAGONS_FLAG, '1', 'FALSE', '2', 'TRUE') AS WAGONS_FLAG,
       T.STATION_NM,
       T.STATION_NO,
       T.SPCL_LN_NM,
       T.SPCL_LN_NO,
       T.RECEIV_NO,
       T.RECEIV_NM,
       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,
       T.CREATE_NAME,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') AS CREATE_TIME,
       T.UPDATE_NAME,
       TO_CHAR(T.UPDATE_TIME, 'YYYY-MM-DD HH24:MI:SS') AS UPDATE_TIME
  FROM YDM_ZC_ASK_DAY T
 WHERE T.ASK_DAY_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="FrmShipmentDayApp.doUpdate" desc="修改批复数">
  <![CDATA[	
   UPDATE YDM_ZC_ASK_DAY
   SET BATCH_DAY_NUM =TO_NUMBER(?),
   ACT_DAY_60NUM=TO_NUMBER(?),
   ACT_DAY_70NUM=TO_NUMBER(?),
       UPDATE_NAME     = ?,
       UPDATE_TIME     = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS')
 WHERE ASK_DAY_PK =?
    ]]>
</query>
<query id="FrmShipmentDayApp.doQueryFalg" desc="查询批复状态">
  <![CDATA[	
SELECT T.APP_FLAG,
       NVL(T.BATCH_DAY_NUM, '0') AS BATCH_DAY_NUM,
       T.ASK_DAY_NO,
       NVL(T.VEHICLE_DAY_NUM, '0') AS VEHICLE_DAY_NUM,
       NVL(T.ACT_DAY_NUM, 0) AS ACT_DAY_NUM
  FROM YDM_ZC_ASK_DAY T
 WHERE T.ASK_DAY_NO =?
   AND T.ASK_MONTH_NO = ?
   AND T.BILL_NO = ?
   AND T.STATION_NO=?
   AND DECODE(T.SPCL_LN_NO,'','N',SPCL_LN_NO)=?
   AND T.RECEIV_NO=?
   AND VALIDFLAG = '1'
    ]]>
</query>
<query id="FrmShipmentDayApp.doQueryDayAsk" desc="查询是否存在记录">
  <![CDATA[	
SELECT T.ASK_DAY_NO   
  FROM YDM_ZC_ASK_DAY T
 WHERE T.ASK_MONTH_NO = ?
   AND T.BILL_NO = ?
   AND T.STATION_NO=?
   AND DECODE(T.SPCL_LN_NO,'','N',SPCL_LN_NO)=?
   AND T.RECEIV_NO=?
   AND VALIDFLAG = '1'
    ]]>
</query>
<query id="FrmShipmentDayApp.doQueryAskDay" desc="查询日请车批号">
  <![CDATA[	
SELECT T.ASK_DAY_NO
  FROM YDM_ZC_ASK_DAY T
 WHERE TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD') =?
   AND T.VALIDFLAG = '1'
 GROUP BY T.ASK_DAY_NO
 ORDER BY T.ASK_DAY_NO DESC
    ]]>
</query>
<query id="FrmShipmentDayApp.doQueryAskMonth" 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,
       T.STATION_NM,
       T.SPCL_LN_NM,
       T.RECEIV_NM,
       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.STATION_NO = ?
   AND DECODE(T.SPCL_LN_NO,'','N',SPCL_LN_NO)=?
   AND T.RECEIV_NO=?
   --AND T.PLAN_YEAR_MONTH=?
   AND T.VALIDFLAG = '1'
   AND T.APP_FLAG = '1'
   AND NVL(T.BATCH_MONTH_NUM,'0')!= NVL(T.ACT_MONTH_NUM,'0')
    ]]>
</query>
<query id="FrmShipmentDayApp.doQueryBilM" desc="查询提单主表">
  <![CDATA[	
SELECT T.BILL_NO,
       SUM(T.PLAN_NUM) PLAN_NUM,
       SUM(T.PLAN_WT) PLAN_WT,
       T.RECEIV_NO,
       T.RECEIV_NM,
       T.STATION_NO,
       T.STATION_NM,
       T.SPCL_LN_NO,
       T.SPCL_LN_NM,
        NVL((SELECT SUM(M.VEHICLE_DAY_NUM)
          FROM YDM_ZC_ASK_DAY M
         WHERE M.BILL_NO=T.BILL_NO),0) AS VEHICLE_DAY
  FROM YDM_ZC_BILL_M T
 WHERE DECODE(?, NULL, SYSDATE, T.CREATE_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.ORDER_NO || '&' LIKE ('%' || ? || '%')
   AND T.STATION_NO || '&' LIKE ('%' || ? || '%')
   AND T.SPCL_LN_NO || '&' LIKE ('%' || ? || '%')
   AND T.RECEIV_NM || '&' LIKE ('%' || ? || '%')
   AND T.VALIDFLAG = '1'
   AND T.PLAN_TRANS_TYPE = '110502'
   AND T.BILL_STATUS IN ('1','3')
    ]]>
</query>
<query id="FrmShipmentDayApp.queryAskMonth" desc="查询月度请车">
  <![CDATA[
 SELECT T.ASK_MONTH_PK,
       NVL(T.BATCH_MONTH_NUM, '0') AS BATCH_MONTH_NUM,
       NVL(T.ACT_MONTH_NUM,0) AS ACT_MONTH_NUM,
       NVL(T1.VEHICLE_DAY_NUM,0) AS VEHICLE_DAY_NUM,
       NVL(T1.BATCH_DAY_NUM,0) AS BATCH_DAY_NUM, 
       T1.APP_FLAG,
       T.ASK_MONTH_NO,
       T.WAGONS_FLAG
  FROM YDM_ZC_ASK_MONTH T, YDM_ZC_ASK_DAY T1
 WHERE T.ASK_MONTH_NO = T1.ASK_MONTH_NO(+)
   AND T.STATION_NO = T1.STATION_NO(+)
   AND NVL(T.SPCL_LN_NO,'N') =NVL(T1.SPCL_LN_NO(+),'N')
   AND T.RECEIV_NO = T1.RECEIV_NO(+)
   AND T.ASK_MONTH_PK = ?
   AND T.VALIDFLAG = '1'
  	]]>
</query>
<query id="FrmShipmentDayApp.AddAskDay" desc="新增日请车">
  <![CDATA[
 INSERT INTO YDM_ZC_ASK_DAY (ASK_DAY_NO, ASK_MONTH_NO, 
WAGONS_PLAN_NO, BILL_NO, VEHICLE_DAY_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,MEMO) 
VALUES (?, ?, ?, ?, TO_NUMBER(?), ?, ?, ?, ?, ?, ?, ?, ?,
TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'), ?, ?, ?, ?, ?, TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),?)
  	]]>
</query>
<query id="FrmShipmentDayApp.doDelete" desc="取消日请车">
  <![CDATA[
DELETE YDM_ZC_ASK_DAY  WHERE ASK_DAY_PK=?
  	]]>
</query>
<query id="FrmShipmentDayApp.doQueryFalgAsk" desc="查询日请车审批状态信息">
  <![CDATA[
SELECT T.APP_FLAG,
       NVL(T.BATCH_DAY_NUM, '0') AS BATCH_DAY_NUM,
       T.ASK_DAY_NO,
       NVL(T.VEHICLE_DAY_NUM, '0') AS VEHICLE_DAY_NUM,
       NVL(T.ACT_DAY_NUM, 0) AS ACT_DAY_NUM
  FROM YDM_ZC_ASK_DAY T
 WHERE T.ASK_DAY_PK=?
   AND VALIDFLAG = '1'
  	]]>
</query>
<query id="FrmShipmentDayApp.updateAskMonth" desc="修改月请车使用数">
  <![CDATA[
UPDATE YDM_ZC_ASK_MONTH
   SET ACT_MONTH_NUM = TO_NUMBER(NVL(ACT_MONTH_NUM, 0)) - TO_NUMBER(?)
 WHERE STATION_NO = ?
   AND DECODE(SPCL_LN_NO,'','N',SPCL_LN_NO) = ?
   AND RECEIV_NO = ?
   AND ASK_MONTH_NO = ?
  	]]>
</query>
</queryMap>