<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="出厂月计划(管坯)">
	<query id="FrmCasTrainMonth.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.PRD_CLS,
       (SELECT T4.BASENAME
          FROM COM_BASE_INFO T4
         WHERE T4.BASECODE = T.PRD_CLS) PRD_CLSNAME,
       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_GP_SENDPLAN_M_TRAINS T
 WHERE T.DELVRY_EDATE BETWEEN ? AND ?
   AND T.ORDER_NO || '&' LIKE ('%' || ? || '%')
		]]>
	</query>
	<query id="FrmCasTrainMonth.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.*,
               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_GP_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 NVL(T.PRD_CLS,'/')=NVL(?,'/')
           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>
</queryMap>