<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="汽运提单编制">
	<query id="CorePipeCarBill.querySendPlan" 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,
                T1.BASENAME,
                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,
                TO_CHAR(T.PLAN_REL_TIME,'YYYY-MM-DD HH24:MI:SS') PLAN_REL_TIME,
                T.PLAN_WT,
                T.PLAN_NUM,
                T.PLAN_TOTL_LEN,
                T.ACT_WT,
                T.ACT_NUM,
                T.ACT_TOTL_LEN,
                DECODE(T.SEND_PLAN_STATUS,
                       '0',
                       '计划编制',
                       '1',
                       '计划下发',
                       '2',
                       '计划执行',
                       '3',
                       '计划关闭') AS SEND_PLAN_STATUS,
                T.CREATE_NAME,
                TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
                T.MANAGEMENT_NO,
                T.MANAGEMENT_NAME,
                T.SUPPLY_UNIT,
                T.SUPPLY_UNIT_DESC
  FROM YDM_ZC_SENDPLAN_M T,
       COM_BASE_INFO     T1,
       YDM_ZC_BILL_M     T2,
       YDM_ZC_SENDPLAN_C T3
 WHERE T.TRANS_TYPE = T1.BASECODE(+)
   AND T.SEND_PLAN_NO = T2.SEND_PLAN_NO(+)
   AND T.SEND_PLAN_NO=T3.SEND_PLAN_NO(+)
   AND T.PLAN_YEAR_MONTH || '&' LIKE '%' || ? || '%'
     AND T3.ORDER_NO || '&' LIKE '%' || ? || '%'
   AND T.SEND_PLAN_STATUS || '&' LIKE '%' || ? || '%'
   AND T.SEND_PLAN_NO || '&' LIKE '%' || ? || '%'
   AND T2.BILL_NO || '&' LIKE '%' || ? || '%'
   AND T.CUSTOMER_NM || '&' LIKE '%' || ? || '%'
   AND T.RECEIV_NM || '&' LIKE '%' || ? || '%'
   AND T.VALIDFLAG = '1'
   AND T.TRANS_TYPE = '110501'
   AND T.SEND_PLAN_STATUS != '0'
	]]>
	</query>
	
	<query id="CorePipeCarBill.getInventoryCanWgt" desc="查询挂提单资源量">
      <![CDATA[
           SELECT NVL(SUM(ACT_COUNT), 0) SUM_COUNT, NVL(SUM(ACT_WEIGHT), 0) SUM_WGT,NVL(SUM(ACT_LEN),0) SUM_LEN
  FROM (SELECT T.ACT_WEIGHT, T.ACT_COUNT,T.ACT_LEN
          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
         WHERE T.MAT_NO = T1.MAT_NO
           AND (T.JUDGE_RESULT_CODE IS NULL OR T.JUDGE_RESULT_CODE IN ('40740701','40740709'))
           AND T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
           AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND NVL(T.BATCH_NO,'/') = NVL('#BATCH_NO#','/')
           AND T.BATCH_GROUD_NO='#BATCH_GROUD_NO#'
           AND T.MAT_STATUS = '80150301'
           AND T1.STORAGE_NO = '#STORAGE_NO#'
           AND NVL(T1.LOCATION_NO,'/')=NVL('#LOCATION_NO#','/')
           AND NVL(T.STD_CODE,'/')=NVL('#STD_CODE#','/')
           AND NVL(T.STD_NAME,'/')=NVL('#STD_NAME#','/')
           AND NVL(T.MEMO,'/')=NVL('#MEMO#','/')
           AND NVL(T.PLINE_CODE,'/')=NVL('#PLINE_CODE#','/')
           AND T.LOCK_FLAG='0'
         ORDER BY T.MAT_NO)
 WHERE ROWNUM < ?
        ]]>
	</query>

	<query id="CorePipeCarBill.getInventoryCanWgt1" desc="查询挂提单资源量">
		SELECT
		NVL( T2.ACT_COUNT, 0 ) SUM_COUNT,
		NVL( T2.ACT_WEIGHT, 0 ) SUM_WGT,
		NVL( T2.ACT_LEN, 0 ) SUM_LEN
		FROM
		(
		SELECT
		T.JUDGE_STOVE_NO,
		T.BATCH_NO,
		T.BATCH_GROUD_NO,
		T1.STORAGE_NO,
		T1.LOCATION_NO,
		( SELECT T4.STORAGE_NAME FROM YDM_BS_STORAGE T4 WHERE T4.STORAGE_NO = T1.STORAGE_NO ) STORAGE_NAME,
		( SELECT T5.LOCATION_NAME FROM YDM_BS_LOCATION T5 WHERE T5.LOCATION_NO = T1.LOCATION_NO ) LOCATION_NAME,
		T.PLINE_CODE,
		T.PLINE_NAME,
		T.STEELCODE,
		T.STEELNAME,
		( SELECT COM.BASENAME FROM COM_BASE_INFO COM WHERE COM.BASECODE = T.IN_MOLD ) IN_MOLD,
		T.PRODUCCODE,
		T.PRODUCNAME,
		T.STD_CODE,
		T.STD_NAME,
		T.STD_STYLE,
		T.STD_STYLE_DESC,
		T.SPEC_CODE,
		T.SPEC_NAME,
		T.MODEL_CODE,
		T.MODEL_DESC,
		T.ORD_PK,
		T.ORD_LN_PK,
		T.ORD_LN_DLY_PK,
		T.memo,
		TO_CHAR( T.ACT_LEN_MIN, 'FM99990.00' ) AS ACT_LEN_MIN,
		TO_CHAR( T.ACT_LEN_MAX, 'FM99990.00' ) AS ACT_LEN_MAX,
		TO_CHAR( MAX( T.INSTOCK_TIME ), 'YYYY-MM-DD HH24:MI:SS' ) JUDGE_RESULT_TIME,
		'0' SEND_NUM,
		SUM( CASE WHEN T.MAT_STATUS = '80150301' THEN NVL( T.ACT_COUNT, 0 ) ELSE 0 END ) ACT_COUNT,
		SUM( CASE WHEN T.MAT_STATUS = '80150301' THEN NVL( T.ACT_WEIGHT, 0 ) ELSE 0 END ) ACT_WEIGHT,
		SUM( CASE WHEN T.MAT_STATUS = '80150301' THEN NVL( T.ACT_LEN, 0 ) ELSE 0 END ) ACT_LEN,
		SUM( CASE WHEN T.MAT_STATUS = '80150302' THEN NVL( T.ACT_COUNT, 0 ) ELSE 0 END ) YB_COUNT,
		SUM( CASE WHEN T.MAT_STATUS = '80150302' THEN NVL( T.ACT_WEIGHT, 0 ) ELSE 0 END ) YB_WEIGHT,
		SUM( CASE WHEN T.MAT_STATUS = '80150302' THEN NVL( T.ACT_LEN, 0 ) ELSE 0 END ) YB_LEN,
		SUM(
		CASE

		WHEN T.MAT_STATUS = '80150301' THEN
		NVL( T.ACT_COUNT, 0 )
		WHEN T.MAT_STATUS = '80150302' THEN
		NVL( T.ACT_COUNT, 0 ) ELSE 0
		END
		) KC_COUNT,
		SUM(
		CASE

		WHEN T.MAT_STATUS = '80150301' THEN
		NVL( T.ACT_WEIGHT, 0 )
		WHEN T.MAT_STATUS = '80150302' THEN
		NVL( T.ACT_WEIGHT, 0 ) ELSE 0
		END
		) KC_WEIGHT,
		SUM(
		CASE

		WHEN T.MAT_STATUS = '80150301' THEN
		NVL( T.ACT_LEN, 0 )
		WHEN T.MAT_STATUS = '80150302' THEN
		NVL( T.ACT_LEN, 0 ) ELSE 0
		END
		) KC_LEN,
		DECODE( T.ZBS_FLAG, '1', '产销出质保书 ', '2', '老系统出质保书' ) ZBS_FLAG,
		( SELECT B.BASENAME FROM COM_BASE_INFO B WHERE B.BASECODE = T.JUDGE_RESULT_CODE AND B.VALIDFLAG = '1' ) JUDGE_RESULT_CODE
		FROM
		MAT_ZC_M T,
		YDM_ZC_BUTTRESS T1
		WHERE
		T.MAT_NO = T1.MAT_NO
		AND T.MNG_LOCK_FLAG = '0'
		AND T.LOCK_FLAG = '0'
		AND T.LOCK_LIKU = '0'
		AND (
		T.JUDGE_RESULT_CODE IS NULL
		OR T.JUDGE_RESULT_CODE IN ( '40740701', '40740709' ))
		AND T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
		AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
		AND NVL(T.BATCH_NO,'/') = NVL('#BATCH_NO#','/')
		AND NVL(T1.LOCATION_NO,'/')=NVL('#LOCATION_NO#','/')
		AND T.LOCK_FLAG='0'
		GROUP BY
		T.JUDGE_STOVE_NO,
		T.BATCH_NO,
		T.BATCH_GROUD_NO,
		T1.STORAGE_NO,
		T1.LOCATION_NO,
		T.STEELCODE,
		T.STEELNAME,
		T.IN_MOLD,
		T.PRODUCCODE,
		T.PRODUCNAME,
		T.STD_CODE,
		T.STD_NAME,
		T.STD_STYLE,
		T.STD_STYLE_DESC,
		T.SPEC_CODE,
		T.SPEC_NAME,
		T.MODEL_CODE,
		T.MODEL_DESC,
		T.ORD_PK,
		T.ORD_LN_PK,
		T.ORD_LN_DLY_PK,
		T.ACT_LEN_MIN,
		T.ACT_LEN_MAX,
		T.memo,
		T.PLINE_CODE,
		T.PLINE_NAME,
		T.ZBS_FLAG,
		t.JUDGE_RESULT_CODE
		ORDER BY
		T.JUDGE_STOVE_NO,
		T.BATCH_NO
		) T2
		WHERE
		T2.ACT_COUNT = ?
	</query>

	<query id="CorePipeCarBill.QueryOrderInfo" desc="查询发运合同信息">
 <![CDATA[
SELECT T.SEND_PLAN_NO,
       T.ORDER_NO || '/' || T3.ORDER_SEQ AS ORDER_SEQ_NO,
       T.ORDER_NO,
       T3.ORDER_SEQ,
       T2.DELIVERY_NO,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T3.STD_CODE,
       T3.STD_NAME,
       T3.STEELCODE,
       T3.STEELNAME,
       T3.STD_STYLE,
       T3.STD_STYLE_DESC,
       T3.MODEL_CODE,
       T3.MODEL_DESC,
       T3.PRD_CLS,
       T.PSC,
       T.PSC_DESC,   
       T.LEN_NO,
       T.LEN_DESC,
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       T2.ORDER_UNIT,
       NVL(T2.WGT_ESTMT, 0) AS WGT_ESTMT,
       NVL(T.PLAN_WT, '0') AS PLAN_WT,
       NVL(T.PLAN_NUM, '0') AS PLAN_NUM,
       NVL(T.PLAN_TOTL_LEN, '0') AS PLAN_TOTL_LEN,
       NVL(P.PREP_COUNT, 0) PREP_COUNT,
       NVL(P.PREP_WT, 0) PREP_WT,
       NVL(P.PREP_LEN, 0) PREP_LEN,
       T3.OUTBOUND_CALCULATE,DECODE(T3.MODE_OF_TRANSPORT,'1','散货','2','集装箱') MODE_OF_TRANSPORT
  FROM YDM_ZC_SENDPLAN_C T,
       (SELECT T1.ORD_LN_DLY_PK,
               T1.SEND_PLAN_NO,
               SUM(NVL(T1.PLAN_NUM, '0')) PREP_COUNT,
               SUM(NVL(T1.PLAN_WT, '0')) PREP_WT,
               SUM(NVL(T1.PLAN_TOTL_LEN, '0')) PREP_LEN
          FROM YDM_ZC_BILL_M T1
         GROUP BY T1.ORD_LN_DLY_PK, T1.SEND_PLAN_NO) P,
       SLM_ORDER_LINE_DELIVERY T2,SLM_ORDER_LINE T3
 WHERE T.ORD_LN_DLY_PK = P.ORD_LN_DLY_PK(+)
   AND T.SEND_PLAN_NO = P.SEND_PLAN_NO(+)
   AND T.ORD_LN_DLY_PK = T2.ORD_LN_DLY_PK
   AND T2.ORD_LN_PK=T3.ORD_LN_PK
   AND T2.ORD_PK=T3.ORD_PK
   AND T.SEND_PLAN_NO = ?
   AND T.VALIDFLAG = '1'
   AND T2.VALIDFLAG ='1'
 ORDER BY T.ORDER_NO, T.ORDER_SEQ, T.DELIVERY_NO
 ]]>
	</query>
	<query id="CorePipeCarBill.QueryMatInfo" desc="材料查询">
		<![CDATA[
   SELECT T2.* FROM (
    SELECT T.MEMO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T1.STORAGE_NO,
       (SELECT T4.STORAGE_NAME
          FROM YDM_BS_STORAGE T4
         WHERE T4.STORAGE_NO = T1.STORAGE_NO) STORAGE_NAME,
         T.PLINE_CODE,T.PLINE_NAME,
       T.STEELCODE,
       T.STEELNAME,
       (SELECT COM.BASENAME FROM COM_BASE_INFO COM WHERE COM.BASECODE=T.IN_MOLD) IN_MOLD,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       MIN(TO_CHAR(T.ACT_LEN_MIN,'FM99990.00')) AS ACT_LEN_MIN,
       MAX(TO_CHAR(T.ACT_LEN_MAX,'FM99990.00'))AS ACT_LEN_MAX,
       TO_CHAR(MAX(T.INSTOCK_TIME), 'YYYY-MM-DD') JUDGE_RESULT_TIME,
       '0' SEND_NUM,
         SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_COUNT,0)
             ELSE
              0
           END) ACT_COUNT,
       SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_WEIGHT,0)
             ELSE
              0
           END) ACT_WEIGHT,
           SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_LEN,0)
             ELSE
              0
           END) ACT_LEN,
       SUM(CASE
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_COUNT,0)
             ELSE
              0
           END) YB_COUNT,
       SUM(CASE
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_WEIGHT,0)
             ELSE
              0
           END) YB_WEIGHT,
             SUM(CASE
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_LEN,0)
             ELSE
              0
           END) YB_LEN,
       SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_COUNT,0)
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_COUNT,0)
             ELSE
              0
           END) KC_COUNT,
       SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_WEIGHT,0)
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_WEIGHT,0)
             ELSE
              0
           END) KC_WEIGHT,
           SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_LEN,0)
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_LEN,0)
             ELSE
              0
           END) KC_LEN,
           DECODE(T.ZBS_FLAG,'1','产销出质保书 ','2','老系统出质保书') ZBS_FLAG,
(SELECT B.BASENAME FROM COM_BASE_INFO B WHERE B.BASECODE=T.JUDGE_RESULT_CODE AND B.VALIDFLAG='1') JUDGE_RESULT_CODE
  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
 WHERE T.MAT_NO = T1.MAT_NO
     AND T.MNG_LOCK_FLAG='0'
     AND T.LOCK_FLAG='0'
   AND  T.LOCK_LIKU='0'
   AND (T.JUDGE_RESULT_CODE IS NULL OR T.JUDGE_RESULT_CODE IN ('40740701','40740709'))
   AND T.ORD_LN_DLY_PK = ?
 GROUP BY T.MEMO,
          T.JUDGE_STOVE_NO,
          T.BATCH_NO,
          T.BATCH_GROUD_NO,
          T1.STORAGE_NO,
          T.STEELCODE,
          T.STEELNAME,
          T.IN_MOLD,
          T.PRODUCCODE,
          T.PRODUCNAME,
          T.STD_CODE,
          T.STD_NAME,
          T.STD_STYLE,
          T.STD_STYLE_DESC,
          T.SPEC_CODE,
          T.SPEC_NAME,
          T.MODEL_CODE,
          T.MODEL_DESC,
          T.ORD_PK,
          T.ORD_LN_PK,
          T.ORD_LN_DLY_PK,
         T.PLINE_CODE,T.PLINE_NAME,T.ZBS_FLAG,T.JUDGE_RESULT_CODE
 ORDER BY T.JUDGE_STOVE_NO, T.BATCH_NO
 )T2 WHERE T2.ACT_COUNT != '0'

		]]>
	</query>

	<query id="CorePipeCarBill.QueryMatInfoTH" desc="材料查询">
		<![CDATA[
   SELECT T2.* FROM (
    SELECT T.MEMO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T1.STORAGE_NO,
       T1.LOCATION_NO,
       (SELECT T4.STORAGE_NAME
          FROM YDM_BS_STORAGE T4
         WHERE T4.STORAGE_NO = T1.STORAGE_NO) STORAGE_NAME,
         (SELECT T5.LOCATION_NAME
          FROM YDM_BS_LOCATION T5
         WHERE T5.LOCATION_NO = T1.LOCATION_NO) LOCATION_NAME,
         T.PLINE_CODE,T.PLINE_NAME,
       T.STEELCODE,
       T.STEELNAME,
       (SELECT COM.BASENAME FROM COM_BASE_INFO COM WHERE COM.BASECODE=T.IN_MOLD) IN_MOLD,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       MIN(TO_CHAR(T.ACT_LEN_MIN,'FM99990.00')) AS ACT_LEN_MIN,
       MAX(TO_CHAR(T.ACT_LEN_MAX,'FM99990.00'))AS ACT_LEN_MAX,
       TO_CHAR(MAX(T.INSTOCK_TIME), 'YYYY-MM-DD') JUDGE_RESULT_TIME,
       '0' SEND_NUM,
         SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_COUNT,0)
             ELSE
              0
           END) ACT_COUNT,
       SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_WEIGHT,0)
             ELSE
              0
           END) ACT_WEIGHT,
           SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_LEN,0)
             ELSE
              0
           END) ACT_LEN,
       SUM(CASE
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_COUNT,0)
             ELSE
              0
           END) YB_COUNT,
       SUM(CASE
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_WEIGHT,0)
             ELSE
              0
           END) YB_WEIGHT,
             SUM(CASE
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_LEN,0)
             ELSE
              0
           END) YB_LEN,
       SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_COUNT,0)
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_COUNT,0)
             ELSE
              0
           END) KC_COUNT,
       SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_WEIGHT,0)
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_WEIGHT,0)
             ELSE
              0
           END) KC_WEIGHT,
           SUM(CASE
             WHEN T.MAT_STATUS = '80150301' THEN
              NVL(T.ACT_LEN,0)
             WHEN T.MAT_STATUS = '80150302' THEN
              NVL(T.ACT_LEN,0)
             ELSE
              0
           END) KC_LEN,
           DECODE(T.ZBS_FLAG,'1','产销出质保书 ','2','老系统出质保书') ZBS_FLAG,
(SELECT B.BASENAME FROM COM_BASE_INFO B WHERE B.BASECODE=T.JUDGE_RESULT_CODE AND B.VALIDFLAG='1') JUDGE_RESULT_CODE,
	GET_PACK_NUM_MAT(T.JUDGE_STOVE_NO) Bound_Num
  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
 WHERE T.MAT_NO = T1.MAT_NO
     AND T.MNG_LOCK_FLAG='0'
     AND T.LOCK_FLAG='0'
   AND  T.LOCK_LIKU='0'
   AND (T.JUDGE_RESULT_CODE IS NULL OR T.JUDGE_RESULT_CODE IN ('40740701','40740709'))
   AND T.ORD_LN_DLY_PK = ?
 GROUP BY T.MEMO,
          T.JUDGE_STOVE_NO,
          T.BATCH_NO,
          T.BATCH_GROUD_NO,
          T1.STORAGE_NO,
          T1.LOCATION_NO,
          T.STEELCODE,
          T.STEELNAME,
          T.IN_MOLD,
          T.PRODUCCODE,
          T.PRODUCNAME,
          T.STD_CODE,
          T.STD_NAME,
          T.STD_STYLE,
          T.STD_STYLE_DESC,
          T.SPEC_CODE,
          T.SPEC_NAME,
          T.MODEL_CODE,
          T.MODEL_DESC,
          T.ORD_PK,
          T.ORD_LN_PK,
          T.ORD_LN_DLY_PK,
         T.PLINE_CODE,T.PLINE_NAME,T.ZBS_FLAG,T.JUDGE_RESULT_CODE
 ORDER BY T.JUDGE_STOVE_NO, T.BATCH_NO
 )T2 WHERE T2.ACT_COUNT != '0'

		]]>
	</query>

	<query id="CorePipeCarBill.queryCarNoInfo" desc="查询订单主表信息">
<![CDATA[	      
SELECT T.BILL_NO,
		T.CAR_NO,
		T.IN_NAME,
		T.IN_TIME,
		T.OUT_NAME,
		T.OUT_TIME,
		T.ID
  FROM YDM_BILL_CARNO T
 WHERE T.BILL_NO = ?

	]]>
	</query>
	
		<query id="CorePipeCarBill.queryCarNoWeightInfo" desc="查询订单主表信息">
<![CDATA[	      
SELECT T.BILL_NO,
		T.CAR_NO,
		T.IN_NAME,
		T.IN_TIME,
		T.OUT_NAME,
		T.OUT_TIME,
		T.ID
  FROM YDM_BILL_CARNO T
 WHERE T.BILL_NO = ?
 AND EXISTS (SELECT 1 FROM 
  CMM_WEIGHT_RECORD T1  WHERE T1.VALIDFLAG ='1' AND T1.WT_TYPE ='0' AND T1.CAR_NO=T.CAR_NO
 )

	]]>
	</query>
	
		<query id="CorePipeCarBill.queryCarNoWeightInfoNew" desc="查询订单主表信息">
<![CDATA[	      
SELECT T1.CAR_NO,to_char(T1.RECORD_DATE,'yyyy/mm/dd hh24:mi:ss')||'  皮重'||T1.RECORD_WEIGHT RECORD_DATE FROM 
  CMM_WEIGHT_RECORD T1  WHERE T1.VALIDFLAG ='1' AND T1.WT_TYPE ='0' 
AND T1.CAR_NO NOT LIKE '%厂内%'
ORDER BY T1.CAR_NO
	]]>
	</query>

	<query id="CorePipeCarBill.queryCarNoWeightInfoNewBySteel" desc="查询订单主表信息">
		<![CDATA[
		SELECT ROWNUM num,A.* from (
		SELECT
			T1.CAR_NO,
			to_char( T1.RECORD_DATE, 'yyyy/mm/dd hh24:mi:ss' ) RECORD_DATE,
			T1.RECORD_WEIGHT RECORD_WEIGHT,VALIDFLAG,
			(	SELECT
					MIN(AFFIRM_FLAG)
				FROM
					YDM_ZC_LOADVEHICLE
				WHERE
					LOADVEHICLE_TYPE = '1'
					AND TRANS_TYPE = '110501'
					AND TO_CHAR(LOAD_TIME,'YYYY-MM-DD') = TO_CHAR(SYSDATE,'YYYY-MM-DD')
					and VEHICLE_NO = T1.CAR_NO
					GROUP BY VEHICLE_NO
			) STATE
		FROM
			CMM_WEIGHT_RECORD T1
		WHERE
			T1.VALIDFLAG in('1','2')
			AND T1.WT_TYPE = '0'
			AND T1.CAR_NO NOT LIKE '%厂内%'
			AND TO_CHAR(RECORD_DATE,'YYYY-MM-DD') = TO_CHAR(SYSDATE,'YYYY-MM-DD')
			AND memo = '钢管'
		order by RECORD_DATE) A
	]]>
	</query>

	<query id="CorePipeCarBill.queryCarNoWeightInfoNewBySteel1" desc="查询订单主表信息">
		<![CDATA[
		SELECT ROWNUM num,A.* from (
		SELECT
			T1.CAR_NO,
			to_char( T1.RECORD_DATE, 'yyyy/mm/dd hh24:mi:ss' ) RECORD_DATE,
			T1.RECORD_WEIGHT RECORD_WEIGHT,
			(	SELECT
					MIN(AFFIRM_FLAG)
				FROM
					YDM_ZC_LOADVEHICLE
				WHERE
					LOADVEHICLE_TYPE = '1'
					AND TRANS_TYPE = '110501'
					AND TO_CHAR(LOAD_TIME,'YYYY-MM-DD') = TO_CHAR(SYSDATE,'YYYY-MM-DD')
					and VEHICLE_NO = T1.CAR_NO
					GROUP BY VEHICLE_NO
			) STATE
		FROM
			CMM_WEIGHT_RECORD T1
		WHERE
			T1.VALIDFLAG = '1'
			AND T1.WT_TYPE = '0'
			AND T1.CAR_NO NOT LIKE '%厂内%'
		order by RECORD_DATE) A
	]]>
	</query>

	<query id="CorePipeCarBill.queryCarNoLoadvehicleBySteel" desc="当日装车信息">
		<![CDATA[
		SELECT
			*
		FROM
			YDM_ZC_LOADVEHICLE t
		WHERE
			-- LOADVEHICLE_TYPE = '1'
			-- AND
			TRANS_TYPE = '110501'
			AND ZOUT_FLAG = '0'
			AND TO_CHAR( LOAD_TIME, 'YYYY-MM-DD' ) = TO_CHAR( SYSDATE, 'YYYY-MM-DD' )
			AND EXISTS (
			SELECT
				1
			FROM
				SLM_ORDER_HEAD H
				INNER JOIN YDM_ZC_LOADVEHICLE_MAT M ON H.ORDER_NO = M.ORDER_NO
			WHERE
				M.LOADVEHICLE_NO = t.LOADVEHICLE_NO
				AND H.SUPPLY_UNIT = '120504'
			AND ROWNUM = 1
			)
		]]>
	</query>

	<query id="CorePipeCarBill.QueryBillM" desc="查询订单主表信息">
<![CDATA[	      
SELECT T.BILL_NO,
		(select wm_concat(DISTINCT b.STORAGE_NAME) from
			YDM_ZC_BILL_c a left join YDM_BS_STORAGE b on a.STORAGE_NO = b.STORAGE_NO
			where a.BILL_NO = T.BILL_NO) STORAGE_NAME,
        DECODE(CASE
                WHEN T.BILL_TICKET_STATUS = 0 AND T.OUTSTOCK_TICKET_STATUS = 0 AND
                     T.TRANSMNY_TICKET_STATUS = 0 THEN
                 0
                WHEN T.BILL_TICKET_STATUS = 2 AND T.OUTSTOCK_TICKET_STATUS = 2 AND
                     T.TRANSMNY_TICKET_STATUS = 2 THEN
                 2
                ELSE
                 (CASE
                   WHEN T.BILL_STATUS >= 4 THEN
                    1
                   ELSE
                    4
                 END)
              END,
              '1',
              '票据对齐('||T.BILL_TICKET_STATUS || T.OUTSTOCK_TICKET_STATUS ||
              T.TRANSMNY_TICKET_STATUS
              ||')',
              '2',
              '提单结束',
              DECODE(T.BILL_STATUS,
                     '0',
                     '提单编制',
                     '1',
                     '提单下发',
                     '2',
                     '(预留)',
                     '3',
                     '提单执行',
                     '4',
                     '提单关闭',
                     '5',
                     '结算接收')) AS BILL_STATUS,
	   (CASE
		 WHEN MIN(T.SALE_ORG) = '100102' THEN
		  DECODE(MIN(T.REALINVOICENO1), '', '0', '1')
		 ELSE
		  DECODE(MIN(T.REALINVOICENO), '', '0', '1')
	   END) AS REALINVOICENO1,
       DECODE(LOADVEHICLE_TYPE, '1', '实际', '虚拟') LOADVEHICLE_TYPE,
       DECODE(T.LOADVEHICLE_TYPE,'2',DECODE(ISPRECLOSE,'0','未关闭','1','一次关闭','2','货款对齐','无'),'') ISPRECLOSE,
       (SELECT T1.BASENAME FROM COM_BASE_INFO T1 WHERE T1.BASECODE=T.PLAN_TRANS_TYPE) PLAN_TRANS_TYPE,
       T.SEND_PLAN_NO,
       NVL(SUM(T.PLAN_NUM),0) PLAN_NUM,
       NVL(SUM(T.PLAN_WT),0) PLAN_WT,
       NVL(SUM(T.PLAN_TOTL_LEN),0) PLAN_TOTL_LEN,
       T.CUSTOMER_NO,
       T.CUSTOMER_NM,
       T.RECEIV_NO,
       T.RECEIV_NM,
       T.SALE_ORG,
       T.SALE_ORG_DESC,
       T.STLMT_UNIT_NO,
       T.STLMT_UNIT_NM,
       T.DELVRY_ADDR,
       T.SUPPLY_UNIT,
       T.SUPPLY_UNIT_DESC,
       MAX(T.PRINT_NUMBER) PRINT_NUMBER,
       MAX(TO_CHAR(T.PRINT_TIME, 'YYYY-MM-DD HH24:MI:SS')) PRINT_TIME,
       MIN(TO_CHAR(T.ACT_START_TIME, 'YYYY-MM-DD')) ACT_START_TIME,
       MIN(TO_CHAR(T.ACT_END_TIME, 'YYYY-MM-DD')) ACT_END_TIME,
       T.CREATE_NAME,
       DECODE(T.ZOUT_FLAG,'1','是','0','否') AS ZOUT_FLAG,
       MIN(TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS')) CREATE_TIME,
       BILL_SEND_NUM(T.BILL_NO) SEND_NUM,
       T.MEMO,MAX(T.DELVRY_WHEREABOUTS)DELVRY_WHEREABOUTS,
        GET_PACK_NUM_BILL(T.BILL_NO) BOUND_NUM,
        MIN(DECODE(T.LET_DELIVERY_FLAG,'1','一次确认','2','一次确认','未确认')) LET_DELIVERY_FLAG,
        MIN(DECODE(T.STOVE_TICKET_FLAG,'0','未齐炉','1','已齐炉')) STOVE_TICKET_FLAG,
        MAX((SELECT ORDER_NO || '/'|| ORDER_SEQ FROM PLN_ORDER_ZG_S WHERE TH_ORDER_NO_SEQ = T.ORDER_NO || '/'||T.ORDER_SEQ)) ORDER_NO_SEQ_GLJY
  FROM YDM_ZC_BILL_M T
  LEFT JOIN SLM_ORDER_HEAD H ON H.ORD_PK = T.ORD_PK
 WHERE T.CREATE_TIME BETWEEN TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS') AND
       TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
   AND T.ORDER_NO || '&' LIKE ('%' || ? || '%')
   AND T.BILL_STATUS || '&' LIKE ('%' || ? || '%')
   AND T.BILL_NO || '&' LIKE ('%' || ? || '%')
   AND T.SEND_PLAN_NO || '&' LIKE ('%' || ? || '%')
   AND T.CUSTOMER_NM || '&' LIKE ('%' || ? || '%')
   AND T.RECEIV_NM || '&' LIKE ('%' || ? || '%')
   AND T.VALIDFLAG = '1'
   AND T.PLAN_TRANS_TYPE = '110501'
   AND T.RETURN_FLAG!='1'
   AND T.ZOUT_FLAG || '&' LIKE ('%' || ? || '%')
	]]>
	</query>
	<query id="CorePipeCarBill.QueryBillC" desc="查询提单材料表信息">
 <![CDATA[
SELECT T.BILL_NO,
DECODE(T.PRT_FLAG,'1','是','0','否') AS PRT_FLAG,
       T.ORDER_NO||'/'|| T.ORDER_SEQ AS ORDER_SEQ_NO,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.GROUP_NO,
       T.MATERIAL_NAME,
       T.PRODUCNAME,
       T.STD_NAME,
       T.GRADENAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.STORAGE_NO,
       --T.LOCATION_NO,
       T.CREATE_NAME,
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       DECODE(T.EDIT_FLAG,'1','已理货','未理货') EDIT_FLAG,
       DECODE(T.LOADVEHICLE_FLAG,'1','已装车','未装车') LOADVEHICLE_FLAG,
       SUM(CASE WHEN T.EDIT_FLAG='1' THEN T.ACT_LEN ELSE 0 END) PREP_LEN,
       SUM(CASE WHEN T.EDIT_FLAG='1' THEN T.ACT_COUNT ELSE 0 END) PREP_COUNT,
       SUM(CASE WHEN T.EDIT_FLAG='1' THEN T.ACT_WEIGHT ELSE 0 END) PREP_WEIGHT,
       SUM(CASE WHEN T.EDIT_FLAG='1' THEN T.ACT_THEORY_WEIGHT ELSE 0 END) PREP_THEORY_WEIGHT,
       SUM(CASE WHEN T.EDIT_FLAG='0' THEN T.ACT_LEN ELSE 0 END) BEEN_LEN,
       SUM(CASE WHEN T.EDIT_FLAG='0' THEN T.ACT_COUNT ELSE 0 END) BEEN_COUNT,
       SUM(CASE WHEN T.EDIT_FLAG='0' THEN T.ACT_WEIGHT ELSE 0 END) BEEN_WEIGHT,
       SUM(CASE WHEN T.EDIT_FLAG='0' THEN T.ACT_THEORY_WEIGHT ELSE 0 END) BEEN_THEORY_WEIGHT,
       NVL(SUM(T.ACT_COUNT), '0') AS ACT_COUNT,
       NVL(SUM(T.ACT_LEN), '0') AS ACT_LEN,
       NVL(SUM(T.ACT_WEIGHT), '0') AS ACT_WEIGHT,
       NVL(SUM(T.ACT_THEORY_WEIGHT), '0') AS ACT_THEORY_WEIGHT,
       NVL(SUM(T.SEND_NUM),0) AS SEND_NUM,
       MAX(T.BOUND_NUM) BOUND_NUM
  FROM YDM_ZC_BILL_C T
  LEFT JOIN YDM_BS_STORAGE B
    ON T.STORAGE_NO = B.STORAGE_NO
 WHERE T.BILL_NO = ?
 AND T.RETURN_FLAG='0'
 GROUP BY T.BILL_NO,
          T.PRT_FLAG,
          T.ORDER_NO,
          T.ORDER_SEQ,
          T.DELIVERY_NO,
          T.JUDGE_STOVE_NO,
          T.BATCH_NO,
          T.GROUP_NO,
          T.MATERIAL_NAME,
          T.PRODUCNAME,
          T.STD_NAME,
          T.GRADENAME,
          T.STEELNAME,
          T.STD_STYLE_DESC,
          T.SPEC_NAME,
          T.MODEL_DESC,
          T.PLINE_NAME,
          T.ACT_DIMATER,
          T.ACT_HEIGHT,
          T.ACT_LEN_MIN,
          T.ACT_LEN_MAX,
          T.STORAGE_NO,
          T.CREATE_NAME,
          T.EDIT_FLAG,
          T.LOADVEHICLE_FLAG,
          T.ORD_PK,
          T.ORD_LN_PK,
          T.ORD_LN_DLY_PK
 ORDER BY T.ORDER_NO,T.ORDER_SEQ,T.DELIVERY_NO,T.JUDGE_STOVE_NO, T.BATCH_NO 
 ]]>
	</query>

	<query id="CorePipeCarBill.QueryBillCTH" desc="查询提单材料表信息">
		<![CDATA[
SELECT T.BILL_NO,
DECODE(T.PRT_FLAG,'1','是','0','否') AS PRT_FLAG,
       T.ORDER_NO||'/'|| T.ORDER_SEQ AS ORDER_SEQ_NO,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.GROUP_NO,
       T.MEMO,
       T.MATERIAL_NAME,
       T.PRODUCNAME,
       T.STD_NAME,
       T.GRADENAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.STORAGE_NO,
       T.LOCATION_NO,
       (SELECT T1.LOCATION_NAME FROM YDM_BS_LOCATION T1 WHERE T1.LOCATION_NO = T.LOCATION_NO)LOCATION_NAME,
       T.CREATE_NAME,
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       DECODE(T.EDIT_FLAG,'1','已理货','未理货') EDIT_FLAG,
       DECODE(T.LOADVEHICLE_FLAG,'1','已装车','未装车') LOADVEHICLE_FLAG,
       SUM(CASE WHEN T.EDIT_FLAG='1' THEN T.ACT_LEN ELSE 0 END) PREP_LEN,
       SUM(CASE WHEN T.EDIT_FLAG='1' THEN T.ACT_COUNT ELSE 0 END) PREP_COUNT,
       SUM(CASE WHEN T.EDIT_FLAG='1' THEN T.ACT_WEIGHT ELSE 0 END) PREP_WEIGHT,
       SUM(CASE WHEN T.EDIT_FLAG='1' THEN T.ACT_THEORY_WEIGHT ELSE 0 END) PREP_THEORY_WEIGHT,
       SUM(CASE WHEN T.EDIT_FLAG='0' THEN T.ACT_LEN ELSE 0 END) BEEN_LEN,
       SUM(CASE WHEN T.EDIT_FLAG='0' THEN T.ACT_COUNT ELSE 0 END) BEEN_COUNT,
       SUM(CASE WHEN T.EDIT_FLAG='0' THEN T.ACT_WEIGHT ELSE 0 END) BEEN_WEIGHT,
       SUM(CASE WHEN T.EDIT_FLAG='0' THEN T.ACT_THEORY_WEIGHT ELSE 0 END) BEEN_THEORY_WEIGHT,
       NVL(SUM(T.ACT_COUNT), '0') AS ACT_COUNT,
       NVL(SUM(T.ACT_LEN), '0') AS ACT_LEN,
       NVL(SUM(T.ACT_WEIGHT), '0') AS ACT_WEIGHT,
       NVL(SUM(T.ACT_THEORY_WEIGHT), '0') AS ACT_THEORY_WEIGHT,
       NVL(SUM(T.SEND_NUM),0) AS SEND_NUM,
       MAX(T.BOUND_NUM) BOUND_NUM
  FROM YDM_ZC_BILL_C T
  LEFT JOIN YDM_BS_STORAGE B
    ON T.STORAGE_NO = B.STORAGE_NO
 WHERE T.BILL_NO = ?
 AND T.RETURN_FLAG='0'
 GROUP BY T.BILL_NO,
          T.PRT_FLAG,
          T.ORDER_NO,
          T.ORDER_SEQ,
          T.DELIVERY_NO,
          T.JUDGE_STOVE_NO,
          T.BATCH_NO,
          T.GROUP_NO,
          T.MEMO,
          T.MATERIAL_NAME,
          T.PRODUCNAME,
          T.STD_NAME,
          T.GRADENAME,
          T.STEELNAME,
          T.STD_STYLE_DESC,
          T.SPEC_NAME,
          T.MODEL_DESC,
          T.PLINE_NAME,
          T.ACT_DIMATER,
          T.ACT_HEIGHT,
          T.ACT_LEN_MIN,
          T.ACT_LEN_MAX,
          T.STORAGE_NO,
          T.LOCATION_NO,
          T.CREATE_NAME,
          T.EDIT_FLAG,
          T.LOADVEHICLE_FLAG,
          T.ORD_PK,
          T.ORD_LN_PK,
          T.ORD_LN_DLY_PK
 ORDER BY T.ORDER_NO,T.ORDER_SEQ,T.DELIVERY_NO,T.JUDGE_STOVE_NO, T.BATCH_NO
 ]]>
	</query>

	<query id="CorePipeCarBill.QueryBillCByBillNo" desc="查询提单材料表信息">
 <![CDATA[
SELECT T.BILL_NO,
		T.ORD_LN_DLY_PK,
       max(T.JUDGE_STOVE_NO) JUDGE_STOVE_NO,
       max(T.BATCH_NO) BATCH_NO,
       max(T.GROUP_NO) GROUP_NO,
       max(T.MATERIAL_NO) MATERIAL_NO,
       max(T.MATERIAL_NAME) MATERIAL_NAME,
       max(T.SPEC_NAME) SPEC_NAME,
       max(T.ACT_DIMATER) ACT_DIMATER,
       max(T.ACT_HEIGHT) ACT_HEIGHT,
       max(T.ACT_LEN_MIN) ACT_LEN_MIN,
       max(T.ACT_LEN_MAX) ACT_LEN_MAX,
       max(T.ACT_LEN) ACT_LEN,
       sum(T.ACT_COUNT) ACT_COUNT,
       sum(T.ACT_WEIGHT) ACT_WEIGHT
  FROM YDM_ZC_BILL_C T
  LEFT JOIN YDM_BS_STORAGE B
    ON T.STORAGE_NO = B.STORAGE_NO
 WHERE T.BILL_NO = ?
 AND T.RETURN_FLAG='0'
 GROUP BY T.BILL_NO,
          T.ORD_LN_DLY_PK

 ]]>
	</query>

	<query id="CorePipeCarbill.UpdateBillSeq" desc="修改提单主表提单状态">
 <![CDATA[
  DECLARE
  V_BELONG_CODE YDM_ZC_BILL_M.SALE_ORG%TYPE := NULL;
  V_TRAN_TYPE YDM_ZC_BILL_M.PLAN_TRANS_TYPE%TYPE := NULL;
BEGIN
  SELECT S1.SALE_ORG
    INTO V_BELONG_CODE
    FROM YDM_ZC_BILL_M S1
   WHERE S1.BILL_NO = ?
   AND ROWNUM = 1;

   SELECT T.PLAN_TRANS_TYPE INTO V_TRAN_TYPE FROM YDM_ZC_BILL_M T WHERE T.BILL_NO = ? AND ROWNUM = 1;

  IF ((V_BELONG_CODE = '100101' OR V_BELONG_CODE = '100103') AND V_TRAN_TYPE = '110501') THEN
    FOR MYROW IN (SELECT S.* FROM YDM_ZC_BILL_C S WHERE S.BILL_NO = ?) LOOP
      UPDATE MAT_ZC_M T
         SET T.LOCK_BILL_FLAG = '1'
       WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
         AND T.BATCH_NO = MYROW.BATCH_NO
         AND T.BATCH_GROUD_NO = MYROW.GROUP_NO
         AND T.MAT_NO = MYROW.MAT_NO
         AND T.SUPPLY_UNIT_CODE='120501';
    END LOOP;
    UPDATE YDM_ZC_BILL_M
       SET BILL_STATUS    = '1',
           UPDATE_NAME    = ?,
           UPDATE_TIME    = SYSDATE,
           LOCK_BILL_FLAG = '1'
     WHERE BILL_NO = ?
       AND VALIDFLAG = '1';
  ELSE
    UPDATE YDM_ZC_BILL_M
       SET BILL_STATUS = '1', UPDATE_NAME = ?, UPDATE_TIME = SYSDATE
     WHERE BILL_NO = ?
       AND VALIDFLAG = '1';
  END IF;
END;
 ]]>
	</query>

	<query id="CorePipeCarBill.createBillNo" desc="生成提单号">
 <![CDATA[
SELECT 'TH' || ? || TO_CHAR(SYSDATE, 'YYMMDD') ||
       LPAD(TO_CHAR(NVL(SUBSTR(MAX(T.BILL_NO), 10), 0) + 1), 4, 0) BILL_NO
  FROM YDM_ZC_BILL_NO T
 WHERE INSTR(T.BILL_NO, ? || TO_CHAR(SYSDATE, 'YYMMDD')) > 0
 AND T.BILL_NO LIKE '#BILLNO#%'
 ]]>
	</query>

	<query id="CorePipeCarBill.checkBillStatus" desc="验证提单号">
        <![CDATA[
               SELECT DISTINCT T.BILL_STATUS,T.SEND_PLAN_NO,T.VSTEL_CODE,T.ZBS_SOURCE,T.FLAG_LEN,T.CREATE_NAME
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
   AND T.VALIDFLAG = '1'
         ]]>
	</query>

	<query id="CorePipeCarBill.checkIsCommon" desc="验证提单修改或者新增">
        <![CDATA[
            SELECT COUNT(1) COUNT
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
   AND 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="CorePipeCarBill.checkIsPrtByJustNo" desc="验证是否分炉">
      <![CDATA[
          SELECT COUNT(1) COUNT
  FROM MAT_ZC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND NVL(T.BATCH_NO,'/') = NVL(?,'/')
   AND T.BATCH_GROUD_NO=?
   AND (T.JUDGE_RESULT_CODE IS NULL OR T.JUDGE_RESULT_CODE IN ('40740701','40740709'))
        ]]>
	</query>

	<query id="CorePipeCarBill.GetBillNoSeq" desc="查询提单主表主键">
 <![CDATA[
 SELECT ? ||
            LPAD(NVL(TO_NUMBER(SUBSTR(MAX(BILL_NO_SEQ), 14, 4)), 0) + 1,
                 4,
                 0) BILL_NO_SEQ
       FROM YDM_ZC_BILL_M
      WHERE BILL_NO = ?
 ]]>
	</query>
	<query id="FrmPipeTrainBill.QueryBillNoSeq" desc="查询改提货单是否已存在对应的计划号下">
 <![CDATA[
SELECT T.SEND_DAYPLAN_NO FROM YDM_ZC_BILL_M T WHERE T.BILL_NO=? AND T.VALIDFLAG='1'
 ]]>
	</query>
	<query id="CorePipeCarBill.GetBillSeq" desc="查询提单材料表主键">
 <![CDATA[
 SELECT ? ||
            LPAD(NVL(TO_NUMBER(SUBSTR(MAX(BILL_SQE), LENGTH(MAX(BILL_SQE))-3)), 0) + 1,
                 4,
                 0) BILL_SQE
       FROM YDM_ZC_BILL_C
      WHERE MAT_NO = ?
 ]]>
	</query>
	<query id="CorePipeCarBill.GetBillM" desc="查询提单材料表主键">
 <![CDATA[
SELECT T.BILL_NO_SEQ
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
   AND T.ORDER_NO = ?
   AND T.ORDER_SEQ = ?
   AND T.DELIVERY_NO = ?
 ]]>
	</query>
	<query id="CorePipeCarBill.UpdateBillM" desc="修改库存材料表材料状态">
 <![CDATA[
UPDATE MAT_ZC_M SET MAT_STATUS = '80150302' WHERE MAT_NO = ? 
 ]]>
	</query>
	<query id="CorePipeCarBill.QueryBillMat" desc="查询提单材料表材料号">
 <![CDATA[
SELECT BILL_SQE,MAT_NO
  FROM YDM_ZC_BILL_C T
 WHERE T.BILL_NO = ?
   AND T.ORDER_NO = ?
   AND T.ORDER_SEQ = ?
   AND T.DELIVERY_NO = ?
   AND T.VALIDFLAG = '1'
 ]]>
	</query>
	<query id="CorePipeCarBill.DeleteBillM" desc="修改提单主表有效标志">
 <![CDATA[
 DELETE YDM_ZC_BILL_M
 WHERE BILL_NO = ?
 ]]>
	</query>
	<query id="CorePipeCarBill.DeleteBillC" desc="修改提单材料表有效标志">
 <![CDATA[
DELETE FROM YDM_ZC_BILL_C T
 WHERE T.BILL_NO = ?
   AND T.ORD_LN_PK = ?
   AND T.ORD_LN_DLY_PK = ?
 ]]>
	</query>
	<query id="CorePipeCarBill.DeleteMat" desc="修改库存材料表材料状态">
 <![CDATA[
   UPDATE MAT_ZC_M
   SET MAT_STATUS = '80150301', UPDATE_NAME = ?, UPDATE_TIME = SYSDATE
 WHERE MAT_NO IN (SELECT T1.MAT_NO
                    FROM YDM_ZC_BILL_C T1
                   WHERE T1.BILL_NO = ?
                     AND T1.ORD_LN_PK = ?
                     AND T1.ORD_LN_DLY_PK = ?
                     AND T1.VALIDFLAG = '1')
 ]]>
	</query>
	<query id="CorePipeCarBill.QueryBillNoSeq" desc="提货单是否存在">
 <![CDATA[
SELECT T.SEND_PLAN_NO FROM  YDM_ZC_BILL_M T WHERE T.BILL_NO=?
 ]]>
	</query>

	<query id="CorePipeCarBill.getBillNoBySendPlanNo" desc="查询计划号已经生成的提单号">
        <![CDATA[
              SELECT DISTINCT T.BILL_NO, T.LOADVEHICLE_TYPE,T.DELVRY_ADDR
  FROM YDM_ZC_BILL_M T
 WHERE T.SEND_PLAN_NO = ?
   AND T.PLAN_TRANS_TYPE = ?
   AND T.BILL_STATUS ='0'
   AND T.VALIDFLAG = '1'
          ]]>
	</query>

	<query id="CorePipeCarBill.getSendPlanNoByBillNo" desc="根据提单号验证计划号">
        <![CDATA[
             SELECT T.SEND_PLAN_NO
   FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
   AND T.VALIDFLAG = '1'
          ]]>
	</query>

	<query id="CorePipeCarBill.getsendPlanInfoBySendPlanNo" desc="通过计划号查询计划信息">
        <![CDATA[
             SELECT SEND_PLAN_NO,
       SALE_ORG,
       SALE_ORG_DESC,
       CUSTOMER_NO,
       CUSTOMER_NM,
       RECEIV_NO,
       RECEIV_NM,
       TRANS_TYPE,
       ACT_TRANS_TYPE,
       STATION_NO,
       STATION_NM,
       SPCL_LN_NO,
       SPCL_LN_NM,
       PORT_NO,
       PORT_DESC,
       PLAN_YEAR_MONTH,
       TO_CHAR(PLAN_START_TIME,'YYYY-MM-DD HH24:MI:SS') PLAN_START_TIME,
       TO_CHAR(PLAN_END_TIME,'YYYY-MM-DD HH24:MI:SS') PLAN_END_TIME,
       TO_CHAR(PLAN_REL_TIME,'YYYY-MM-DD HH24:MI:SS') PLAN_REL_TIME,
       PLAN_WT,
       PLAN_NUM,
       PLAN_TOTL_LEN,
       ACT_START_TIME,
       ACT_END_TIME,
       SEND_PLAN_STATUS,
       MEMO,
       VALIDFLAG,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       MANAGEMENT_NO,
       MANAGEMENT_NAME
  FROM YDM_ZC_SENDPLAN_M T
 WHERE T.SEND_PLAN_NO = ?
   AND T.VALIDFLAG = '1'
          ]]>
	</query>

	<query id="CorePipeCarBill.getPlanCInfoByordLnPkAndSPNo" desc="根据计划号和合同行主键查询发运计划子信息">
        <![CDATA[
         SELECT 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,
       ACT_WT,
       ACT_NUM,
       ACT_TOTL_LEN,
       MEMO,
       VALIDFLAG,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK
  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="CorePipeCarBill.checkBillNoByBillNo" desc="验证提单号">
        <![CDATA[
             SELECT COUNT(1) COUNT
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
   AND T.VALIDFLAG = '1'
          ]]>
	</query>

	<query id="CorePipeCarBill.getMatMInfo80150301" desc="查询仓库可编制量">
        <![CDATA[
            SELECT T.MAT_NO,
       T.PRODUCT_FLAG,
       T.MAT_STATUS,
       T.LOT_NO,
       T.STOVE_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.BATCH_GROUD_NO,
       T.MATERIAL_NO,
       T.MATERIAL_NAME,
       T.PRODUCCODE,
       T.PRODUCNAME,
       T.STEELCODE,
       T.STEELNAME,
       T.GRADECODE,
       T.GRADENAME,
       T.SPEC_CODE,
       T.SPEC_NAME,
       T.MODEL_CODE,
       T.MODEL_DESC,
       T.STD_CODE,
       T.STD_NAME,
       T.STD_STYLE,
       T.STD_STYLE_DESC,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.ORDER_SEQ_NO,
       T.PLINE_CODE,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.ACT_COUNT,
       T.ACT_WEIGHT,
       T.ACT_THEORY_WEIGHT,
       T.JUDGE_RESULT_CODE,
       T.PRO_BC,
       T.PRO_BZ,
       T.RPO_TIME,
       T.MEMO,
       T.CREATE_NAME,
       T.CREATE_TIME,
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK
  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
 WHERE T.MAT_NO = T1.MAT_NO 
   AND (T.JUDGE_RESULT_CODE IS NULL OR T.JUDGE_RESULT_CODE IN ('40740701','40740709'))
   AND T.ORD_LN_DLY_PK = ?
   AND T.JUDGE_STOVE_NO = ?
   AND NVL(T.BATCH_NO,'/') = NVL(?,'/')
   AND T.BATCH_GROUD_NO=?
   AND T.MAT_STATUS = '80150301'
   AND T1.STORAGE_NO = ?
   ORDER BY MAT_NO
          ]]>
	</query>

	<query id="CorePipeCarBill.updateMatZcMByMatNo" desc="修改库存信息">
        <![CDATA[
            UPDATE MAT_ZC_M T SET T.MAT_STATUS = '80150302' WHERE T.MAT_NO = ?
          ]]>
	</query>
<query id="CorePipeCarBill.updateMatZcMByMatNolen" desc="修改库存长度">
        <![CDATA[
            UPDATE MAT_ZC_M T SET T.ACT_LEN=TO_NUMBER(?)  WHERE T.MAT_NO = ?
          ]]>
	</query>
	<query id="CorePipeCarBill.getMaxSeqByBillNo" desc="查询提单号最大序号">
        <![CDATA[
            SELECT NVL(TO_NUMBER(SUBSTR(MAX(T.BILL_NO_SEQ), 14)), 0) + 1 INDEX_SEQ
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
          ]]>
	</query>

	<query id="CorePipeCarBill.addBillMInfo" desc="新增提单主表信息">
        <![CDATA[
            INSERT INTO YDM_ZC_BILL_M
  (DEPARTMENT_DESC,
   MANAGEMENT_NO,
   MANAGEMENT_NAME,
   CUSTOMER_NM,
   RECEIV_NO,
   RECEIV_NM,
   STLMT_UNIT_NO,
   STLMT_UNIT_NM,
   CARRY_COMPANY_CODE,
   CARRY_COMPANY_NAME,
   PRD_CLS,
   PRODUCCODE,
   PRODUCNAME,
   STD_CODE,
   STD_NAME,
   STEELCODE,
   STEELNAME,
   PLAN_START_TIME,
   PLAN_END_TIME,
   ACT_START_TIME,
   ACT_END_TIME,
   PLAN_WT,
   PLAN_NUM,
   PLAN_TOTL_LEN,
   ACT_WT,
   ACT_NUM,
   ACT_TOTL_LEN,
   SPEC_CODE,
   SPEC_NAME,
   BILL_STATUS,
   MEMO,
   VALIDFLAG,
   CREATE_NAME,
   CREATE_TIME,
   UPDATE_NAME,
   UPDATE_TIME,
   DELETE_NAME,
   DELETE_TIME,
   DEPARTMENT_CODE,
   BILL_NO_SEQ,
   BILL_NO,
   ORDER_NO,
   ORDER_SEQ,
   DELIVERY_NO,
   SEND_PLAN_NO,
   VSTEL_CODE,
   VSTEL_DESC,
   PLAN_TRANS_TYPE,
   ACT_TRANS_TYPE,
   STATION_NO,
   STATION_NM,
   SPCL_LN_NO,
   SPCL_LN_NM,
   PORT_NO,
   PORT_DESC,
   DELIVY_PLACE_CODE,
   DELIVY_PLACE_NAME,
   SALE_ORG,
   SALE_ORG_DESC,
   CUSTOMER_NO,
   LOADVEHICLE_TYPE,
   FST_DRAWEE_UNIT,
   ORD_PK,
   ORD_LN_PK,
   ORD_LN_DLY_PK,
   AGENCY_FL,
   RECEIV_ADDR,
   DELVRY_ADDR,
   PICKUP_FLAG,CREDIT_NO,EXTRA_FLAG,SINGLE_NO,ITEM_NO,LICENSE_NO,ZBS_SOURCE,FLAG_LEN,WIND_UP_FLAG,SUPPLY_UNIT,SUPPLY_UNIT_DESC,
   DELVRY_WHEREABOUTS,IS_OVERSTOCK)
VALUES
  ('#DEPARTMENT_DESC#',
   '#MANAGEMENT_NO#',
   '#MANAGEMENT_NAME#',
   '#CUSTOMER_NM#',
   '#RECEIV_NO#',
   '#RECEIV_NM#',
   '#STLMT_UNIT_NO#',
   '#STLMT_UNIT_NM#',
   '#CARRY_COMPANY_CODE#',
   '#CARRY_COMPANY_NAME#',
   '#PRD_CLS#',
   '#PRODUCCODE#',
   '#PRODUCNAME#',
   '#STD_CODE#',
   '#STD_NAME#',
   '#STEELCODE#',
   '#STEELNAME#',
   TO_DATE('#PLAN_START_TIME#','YYYY/MM/DD HH24:MI:SS'),
   TO_DATE('#PLAN_END_TIME#','YYYY/MM/DD HH24:MI:SS'),
   TO_DATE('#ACT_START_TIME#','YYYY-MM-DD'),
   TO_DATE('#ACT_END_TIME#','YYYY-MM_DD'),
   '#PLAN_WT#',
   '#PLAN_NUM#',
   '#PLAN_TOTL_LEN#',
   '#ACT_WT#',
   '#ACT_NUM#',
   '#ACT_TOTL_LEN#',
   '#SPEC_CODE#',
   '#SPEC_NAME#',
   '#BILL_STATUS#',
   '#MEMO#',
   '#VALIDFLAG#',
   '#CREATE_NAME#',
   TO_DATE('#CREATE_TIME#','YYYY-MM-DD HH24:MI:SS'),
   NULL,
   NULL,
   NULL,
   NULL,
   '#DEPARTMENT_CODE#',
   '#BILL_NO_SEQ#',
   '#BILL_NO#',
   '#ORDER_NO#',
   '#ORDER_SEQ#',
   '#DELIVERY_NO#',
   '#SEND_PLAN_NO#',
   '#VSTEL_CODE#',
   '#VSTEL_DESC#',
   '#PLAN_TRANS_TYPE#',
   '#ACT_TRANS_TYPE#',
   '#STATION_NO#',
   '#STATION_NM#',
   '#SPCL_LN_NO#',
   '#SPCL_LN_NM#',
   '#PORT_NO#',
   '#PORT_DESC#',
   '#DELIVY_PLACE_CODE#',
   '#DELIVY_PLACE_NAME#',
   '#SALE_ORG#',
   '#SALE_ORG_DESC#',
   '#CUSTOMER_NO#',
   '#LOADVEHICLE_TYPE#',
   '#FST_DRAWEE_UNIT#',
   '#ORD_PK#',
   '#ORD_LN_PK#',
   '#ORD_LN_DLY_PK#',
   '#AGENCY_FL#',
   '#RECEIV_ADDR#',
   '#DELVRY_ADDR#',
   '#PICKUP_FLAG#','#CREDIT_NO#','#EXTRA_FLAG#','#SINGLE_NO#','#ITEM_NO#','#LICENSE_NO#',?,?,'0','#SUPPLY_UNIT#','#SUPPLY_UNIT_DESC#',
   (SELECT STORAGE_NAME FROM SLM_BASE_CUST_STORAGE WHERE CUSTOMER_NO = '#RECEIV_NO#' AND VALIDFLAG = '1' AND ROWNUM = 1),
   '#OVERSTOCK#')
          ]]>
	</query>

	<query id="CorePipeCarBill.getBillCMaxSeq" desc="查询提单从表最大序号">
        <![CDATA[
            SELECT ? ||
       LPAD(SUBSTR(NVL(MAX(T.BILL_SQE), '0000'), -4, 4) + 1, 4, '0') AS BILL_SQE
  FROM YDM_ZC_BILL_C T
 WHERE T.Mat_No=?
          ]]>
	</query>

	<query id="CorePipeCarBill.addBillCInfo" desc="新增提单从表信息">
        <![CDATA[
          INSERT INTO YDM_ZC_BILL_C (PRT_FLAG, ORD_PK, ORD_LN_PK, ORD_LN_DLY_PK, BILL_SQE, 
BILL_NO, ORDER_NO, ORDER_SEQ, MAT_NO, LOT_NO, JUDGE_STOVE_NO, BATCH_NO, 
GROUP_NO, STOVE_NO, MATERIAL_NO, MATERIAL_NAME, PRODUCCODE, PRODUCNAME, 
STD_CODE, STD_NAME, GRADECODE, GRADENAME, STEELCODE, STEELNAME, STD_STYLE, 
STD_STYLE_DESC, SPEC_CODE, SPEC_NAME, MODEL_CODE, MODEL_DESC, PLINE_CODE, 
PLINE_NAME, ACT_DIMATER, ACT_HEIGHT, ACT_LEN, ACT_LEN_MIN, ACT_LEN_MAX, 
ACT_COUNT, ACT_WEIGHT, ACT_THEORY_WEIGHT, JUDGE_RESULT_CODE, PRO_BC, PRO_BZ, 
RPO_TIME, STORAGE_NO, LOCATION_NO, CREATE_NAME, CREATE_TIME, DELIVERY_NO,
VSTEL,VSTEL_DESC,SEND_NUM,BOUND_NUM,FINISHPRO_MOLD,IN_MOLD,ZBS_ID,JG_ZBS_ID,MEMO,IN_TYPE,RECEIVE_FLAG)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, 
?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, TO_DATE(?,'YYYY-MM-DD 
HH24:MI:SS'), (SELECT T.STORAGE_NO FROM YDM_ZC_BUTTRESS T WHERE T.MAT_NO=?), 
(SELECT T.LOCATION_NO FROM YDM_ZC_BUTTRESS T WHERE T.MAT_NO=?), ?, 
TO_DATE(?,'YYYY- MM-DD HH24:MI:SS'), ?,?,?,TO_NUMBER(?),TO_NUMBER(?),?,?,?,?,?,?,'0')
          ]]>
	</query>

	<query id="CorePipeCarBill.checkIsPrtByJust" desc="查詢库存炉总量">
        <![CDATA[
            SELECT COUNT(1) COUNT
  FROM MAT_ZC_M T
 WHERE T.JUDGE_STOVE_NO = ?
   AND NVL(T.BATCH_NO,'/') = NVL(?,'/')
   AND (T.JUDGE_RESULT_CODE IS NULL OR T.JUDGE_RESULT_CODE IN ('40740701','40740709'))
          ]]>
	</query>

	<query id="CorePipeCarBill.getBillWgtBySendNo" desc="查询提单已编制量">
        <![CDATA[
            SELECT SUM(T.PLAN_WT) SUM_PLAN_WT
  FROM YDM_ZC_BILL_M 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="CorePipeCarBill.getBillStatusByBillNo" desc="查询提单状态">
        <![CDATA[
            select T.BILL_STATUS,T.LOADVEHICLE_TYPE from YDM_ZC_BILL_M t where T.BILL_NO=?
          ]]>
	</query>

	<query id="CorePipeCarBill.checkBillByBillNo" desc="验证提单">
        <![CDATA[
            SELECT COUNT(1) COUNT
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
   AND T.SEND_PLAN_NO = ?
   AND T.ORD_LN_DLY_PK = ?
   AND T.VALIDFLAG = '1'
          ]]>
	</query>


	<query id="CorePipeCarBill.updateBillByBillNo" desc="修改提单">
        <![CDATA[
            update YDM_ZC_BILL_M T
   SET T.PLAN_NUM = TO_NUMBER(T.PLAN_NUM) + TO_NUMBER(?),
       T.PLAN_WT  = TO_NUMBER(T.PLAN_WT) + TO_NUMBER(?),
       T.PLAN_TOTL_LEN  = TO_NUMBER(PLAN_TOTL_LEN) + TO_NUMBER(?)
 WHERE T.BILL_NO = ?
   AND T.SEND_PLAN_NO = ?
   AND T.ORD_LN_DLY_PK = ?
          ]]>
	</query>

	<query id="CorePipeCarBill.getBillInfoByBillNoSeq" desc="根据提单序号查询提单信息">
        <![CDATA[
            SELECT BILL_NO_SEQ,
       BILL_NO,
       ORDER_NO,
       ORDER_SEQ,
       DELIVERY_NO,
       SEND_PLAN_NO,
       VSTEL_CODE,
       VSTEL_DESC,
       PLAN_TRANS_TYPE,
       ACT_TRANS_TYPE,
       STATION_NO,
       STATION_NM,
       SPCL_LN_NO,
       SPCL_LN_NM,
       PORT_NO,
       PORT_DESC,
       DELIVY_PLACE_CODE,
       DELIVY_PLACE_NAME,
       SALE_ORG,
       SALE_ORG_DESC,
       CUSTOMER_NO,
       CUSTOMER_NM,
       RECEIV_NO,
       RECEIV_NM,
       STLMT_UNIT_NO,
       STLMT_UNIT_NM,
       CARRY_COMPANY_CODE,
       CARRY_COMPANY_NAME,
       PRD_CLS,
       PRODUCCODE,
       PRODUCNAME,
       STD_CODE,
       STD_NAME,
       STEELCODE,
       STEELNAME,
       PLAN_START_TIME,
       PLAN_END_TIME,
       ACT_START_TIME,
       ACT_END_TIME,
       PLAN_WT,
       PLAN_NUM,
       PLAN_TOTL_LEN,
       ACT_WT,
       ACT_NUM,
       ACT_TOTL_LEN,
       SPEC_CODE,
       SPEC_NAME,
       BILL_STATUS,
       MEMO,
       VALIDFLAG,
       CREATE_NAME,
       CREATE_TIME,
       UPDATE_NAME,
       UPDATE_TIME,
       DELETE_NAME,
       DELETE_TIME,
       LOADVEHICLE_TYPE,
       FST_DRAWEE_UNIT,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,
       AGENCY_FL,
       RECEIV_ADDR,
       DELVRY_ADDR,
       PICKUP_FLAG,
       DEPARTMENT_CODE,
       DEPARTMENT_DESC,
       MANAGEMENT_NO,
       MANAGEMENT_NAME,
       LOCK_BILL_FLAG
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
   AND T.VALIDFLAG = '1'

          ]]>
	</query>

	<query id="CorePipeCarBill.getOrdNoInfoByOrdLnPk" desc="查询合同物料信息">
        <![CDATA[
     SELECT T3.PRODUCCODE,
       T3.PRODUCNAME,
       T3.STD_CODE,
       T3.STD_NAME,
       T3.STEELCODE,
       T3.STEELNAME,
       T3.STD_STYLE,
       T3.STD_STYLE_DESC,
       T3.SPEC_CODE,
       T3.SPEC_NAME,
       T3.DIMATER,
       T3.HEIGHT,
       T3.MODEL_CODE,
       T3.MODEL_DESC,
       T3.LEN_NO,
       T3.LEN_DESC,
       T3.LEN_UNIT,
       T3.LEN_MIN,
       T3.LEN_MAX,
       T2.STLMT_UNIT_NO,
       T2.STLMT_UNIT_NM,
       T1.AGENCY_FL,
       T1.PICKUP_FLAG,
       T2.FST_DRAWEE_UNIT,
       T1.RECEIV_ADDR,
       T1.DELVRY_ADDR,
       T1.EXTRA_FLAG,
       T3.PRD_CLS
  FROM SLM_ORDER_LINE_DELIVERY T1, SLM_ORDER_HEAD T2, SLM_ORDER_LINE T3
 WHERE T1.ORD_PK = T2.ORD_PK
   AND T1.ORD_LN_PK = T3.ORD_LN_PK
   AND T1.ORD_LN_DLY_PK =?
   AND T1.VALIDFLAG = '1'
   AND T2.VALIDFLAG = '1'
   AND T3.VALIDFLAG = '1'
          ]]>
	</query>

	<query id="CorePipeCarBill.checkMatWeight" desc="验证数据">
	<![CDATA[
         SELECT NVL(SUM(P.ACT_WEIGHT),0),NVL(SUM(P.ACT_COUNT),0),NVL(SUM(P.ACT_LEN),0)
  FROM (SELECT NVL(T1.ACT_WEIGHT,0) AS ACT_WEIGHT,NVL(T1.ACT_COUNT,0) AS ACT_COUNT,NVL(T1.ACT_LEN,0) AS ACT_LEN, ROWNUM
          FROM MAT_ZC_M T1, YDM_ZC_BUTTRESS T2
         WHERE T1.MAT_NO = T2.MAT_NO
          AND T1.LOCK_LIKU='0'
          AND (T1.JUDGE_RESULT_CODE IS NULL OR T1.JUDGE_RESULT_CODE IN ('40740701','40740709'))
           AND T1.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
           AND T2.STORAGE_NO = '#STORAGE_NO#'
           AND NVL(T2.LOCATION_NO,'/') = NVL('#LOCATION_NO#','/')
           AND T1.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
           AND NVL(T1.BATCH_NO,'/') = NVL('#BATCH_NO#','/')
           AND T1.BATCH_GROUD_NO='#BATCH_GROUD_NO#'
           AND NVL(T1.STD_CODE,'/')=NVL('#STD_CODE#','/')
           AND T1.MAT_STATUS = '80150301'
            AND NVL(T1.MEMO, '/') = NVL('#MEMO#', '/')
           AND T1.MNG_LOCK_FLAG='0'
         ORDER BY T1.MAT_NO) P
 WHERE ROWNUM < ?
		]]>
	</query>

	<query id="CorePipeCarBill.checkDoDown" desc="下发验证">
	<![CDATA[
      SELECT T.BILL_STATUS,T.LOADVEHICLE_TYPE,T.ISPRECLOSE,T.PLAN_TRANS_TYPE FROM YDM_ZC_BILL_M T WHERE T.BILL_NO = ?
      GROUP BY T.BILL_STATUS,T.LOADVEHICLE_TYPE,T.ISPRECLOSE,T.PLAN_TRANS_TYPE
		]]>
	</query>
	
	<query id="CorePipeCarBill.clearInfo" desc="下发验证">
	<![CDATA[
      		DELETE YDM_BILL_CARNO T WHERE T.BILL_NO = ?
		]]>
	</query>
	
	<query id="CorePipeCarBill.deleteById" desc="下发验证">
	<![CDATA[
      		DELETE YDM_BILL_CARNO T WHERE T.ID = ?
		]]>
	</query>
	
		<query id="CorePipeCarBill.insertCarNo" desc="下发验证">
	<![CDATA[
      		INSERT INTO YDM_BILL_CARNO (
      		BILL_NO,
      		CAR_NO
      		)VALUES(
      		?,
      		?
      		)
		]]>
	</query>

	<query id="CorePipeCarbill.UpdateSendPlanStatus" desc="修改发运计划状态">
 <![CDATA[
   UPDATE YDM_ZC_SENDPLAN_M T
   SET T.SEND_PLAN_STATUS = '2'
 WHERE T.SEND_PLAN_NO = ?
   AND T.VALIDFLAG = '1'
 ]]>
	</query>
<query id = "CorePipeCarbill.getMatZc" desc = "按材料号查询">
	SELECT T.MAT_NO,
	T.LOT_NO,
	T.STOVE_NO,
	T.JUDGE_STOVE_NO,
	T.BATCH_NO,
	T.BATCH_GROUD_NO,
	T.MATERIAL_NO,
	T.MATERIAL_NAME,
	T.PRODUCCODE,
	T.PRODUCNAME,
	T.STEELCODE,
	T.STEELNAME,
	T.GRADECODE,
	T.GRADENAME,
	T.SPEC_CODE,
	T.SPEC_NAME,
	T.MODEL_CODE,
	T.MODEL_DESC,
	T.STD_CODE,
	T.STD_NAME,
	T.STD_STYLE,
	T.STD_STYLE_DESC,
	T.ORDER_NO,
	T.ORDER_SEQ,
	T.ORDER_SEQ_NO,
	T.PLINE_CODE,
	T.PLINE_NAME,
	T.ACT_DIMATER,
	T.ACT_HEIGHT,
	T.ACT_LEN,
	T.ACT_LEN_MIN,
	T.ACT_LEN_MAX,
	T.ACT_COUNT,
	T.ACT_WEIGHT,
	T.ACT_THEORY_WEIGHT,
	T.JUDGE_RESULT_CODE,
	T.PRO_BC,
	T.PRO_BZ,
	T.RPO_TIME,
	T.ORD_PK,
	T.ORD_LN_PK,
	T.ORD_LN_DLY_PK,
	T.FINISHPRO_MOLD,
	T.IN_MOLD,
	T.ZBS_FLAG,
	T.ZBS_ID,
	T.JG_ZBS_ID
	FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
	WHERE T.MAT_NO = T1.MAT_NO
	AND T.LOCK_FLAG = '0'
	AND T.MNG_LOCK_FLAG = '0'
	AND T.LOCK_LIKU = '0'
	AND (T.JUDGE_RESULT_CODE IS NULL OR
	T.JUDGE_RESULT_CODE IN ('40740701', '40740709'))
	AND T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
	AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
	AND NVL(T.BATCH_NO, '/') = NVL('#BATCH_NO#', '/')
	AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
	AND T.MAT_STATUS = '80150301'
	AND T1.STORAGE_NO = '#STORAGE_NO#'
	AND NVL(T.STD_CODE, '/') = NVL('#STD_CODE#', '/')
	AND NVL(T.MEMO, '/') = NVL('#MEMO#', '/')
	AND NVL(T.PLINE_CODE, '/') = NVL('#PLINE_CODE#', '/')
	AND NVL((SELECT COM.BASENAME FROM COM_BASE_INFO COM WHERE COM.BASECODE=T.IN_MOLD), '/') = NVL('#IN_MOLD#', '/')
</query>
	<query id = "CorePipeCarbill.getMatZcTH" desc = "按材料号查询">
		SELECT T.MAT_NO,
		T.LOT_NO,
		T.STOVE_NO,
		T.JUDGE_STOVE_NO,
		T.BATCH_NO,
		T.BATCH_GROUD_NO,
		T.MATERIAL_NO,
		T.MATERIAL_NAME,
		T.PRODUCCODE,
		T.PRODUCNAME,
		T.STEELCODE,
		T.STEELNAME,
		T.GRADECODE,
		T.GRADENAME,
		T.SPEC_CODE,
		T.SPEC_NAME,
		T.MODEL_CODE,
		T.MODEL_DESC,
		T.STD_CODE,
		T.STD_NAME,
		T.STD_STYLE,
		T.STD_STYLE_DESC,
		T.ORDER_NO,
		T.ORDER_SEQ,
		T.ORDER_SEQ_NO,
		T.PLINE_CODE,
		T.PLINE_NAME,
		T.ACT_DIMATER,
		T.ACT_HEIGHT,
		T.ACT_LEN,
		T.ACT_LEN_MIN,
		T.ACT_LEN_MAX,
		T.ACT_COUNT,
		T.ACT_WEIGHT,
		T.ACT_THEORY_WEIGHT,
		T.JUDGE_RESULT_CODE,
		T.PRO_BC,
		T.PRO_BZ,
		T.RPO_TIME,
		T.ORD_PK,
		T.ORD_LN_PK,
		T.ORD_LN_DLY_PK,
		T.FINISHPRO_MOLD,
		T.IN_MOLD,
		T.ZBS_FLAG,
		T.ZBS_ID,
		T.JG_ZBS_ID
		FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
		WHERE T.MAT_NO = T1.MAT_NO
		AND T.LOCK_FLAG = '0'
		AND T.MNG_LOCK_FLAG = '0'
		AND T.LOCK_LIKU = '0'
		AND (T.JUDGE_RESULT_CODE IS NULL OR
		T.JUDGE_RESULT_CODE IN ('40740701', '40740709'))
		AND T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
		AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
		AND NVL(T.BATCH_NO, '/') = NVL('#BATCH_NO#', '/')
		AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
		AND T.MAT_STATUS = '80150301'
		AND T1.STORAGE_NO = '#STORAGE_NO#'
		AND NVL(T.STD_CODE, '/') = NVL('#STD_CODE#', '/')
		AND NVL(T.MEMO, '/') = NVL('#MEMO#', '/')
		AND NVL(T.PLINE_CODE, '/') = NVL('#PLINE_CODE#', '/')
		AND NVL((SELECT COM.BASENAME FROM COM_BASE_INFO COM WHERE COM.BASECODE=T.IN_MOLD), '/') = NVL('#IN_MOLD#', '/')
		AND NVL(T1.LOCATION_NO, '/') = NVL('#LOCATION_NO#', '/')
	</query>
	<query id="CorePipeCarbill.getInventoryCanInfo" desc="查询库存可编制资源信息">
      <![CDATA[
       SELECT *
  FROM (SELECT T.MAT_NO,
               T.LOT_NO,
               T.STOVE_NO,
               T.JUDGE_STOVE_NO,
               T.BATCH_NO,
               T.BATCH_GROUD_NO,
               T.MATERIAL_NO,
               T.MATERIAL_NAME,
               T.PRODUCCODE,
               T.PRODUCNAME,
               T.STEELCODE,
               T.STEELNAME,
               T.GRADECODE,
               T.GRADENAME,
               T.SPEC_CODE,
               T.SPEC_NAME,
               T.MODEL_CODE,
               T.MODEL_DESC,
               T.STD_CODE,
               T.STD_NAME,
               T.STD_STYLE,
               T.STD_STYLE_DESC,
               T.ORDER_NO,
               T.ORDER_SEQ,
               T.ORDER_SEQ_NO,
               T.PLINE_CODE,
               T.PLINE_NAME,
               T.ACT_DIMATER,
               T.ACT_HEIGHT,
               T.ACT_LEN,
               T.ACT_LEN_MIN,
               T.ACT_LEN_MAX,
               T.ACT_COUNT,
               T.ACT_WEIGHT,
               T.ACT_THEORY_WEIGHT,
               T.JUDGE_RESULT_CODE,
               T.PRO_BC,
               T.PRO_BZ,
               T.RPO_TIME,
               T.ORD_PK,
               T.ORD_LN_PK,
               T.ORD_LN_DLY_PK,
               T.FINISHPRO_MOLD,
               T.IN_MOLD,
               T.ZBS_FLAG,
               T.ZBS_ID,
               T.JG_ZBS_ID
          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
 WHERE T.MAT_NO = T1.MAT_NO
 AND T.LOCK_FLAG='0'
 AND T.MNG_LOCK_FLAG='0'
 AND T.LOCK_LIKU='0'
 AND (T.JUDGE_RESULT_CODE IS NULL OR T.JUDGE_RESULT_CODE IN ('40740701','40740709'))
   AND T.ORD_LN_DLY_PK='#ORD_LN_DLY_PK#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(T.BATCH_NO,'/') = NVL('#BATCH_NO#','/')
   AND T.BATCH_GROUD_NO='#BATCH_GROUD_NO#'
   AND T.MAT_STATUS = '80150301'
   AND T1.STORAGE_NO = '#STORAGE_NO#'
   AND NVL(T.STD_CODE,'/')=NVL('#STD_CODE#','/')
   AND NVL(T.STD_NAME,'/')=NVL('#STD_NAME#','/')
   AND NVL(T.MEMO,'/') = NVL('#MEMO#','/')
   AND NVL(T.PLINE_CODE,'/') = NVL('#PLINE_CODE#','/')
   AND NVL((SELECT COM.BASENAME FROM COM_BASE_INFO COM WHERE COM.BASECODE=T.IN_MOLD), '/') = NVL('#IN_MOLD#', '/')
 ORDER BY T.MAT_NO  ) 
 WHERE ROWNUM<?    
        ]]>
	</query>
	<query id="CorePipeCarbill.getInventoryCanInfoTH" desc="查询库存可编制资源信息">
		<![CDATA[
       SELECT *
  FROM (SELECT T.MAT_NO,
               T.LOT_NO,
               T.STOVE_NO,
               T.JUDGE_STOVE_NO,
               T.BATCH_NO,
               T.BATCH_GROUD_NO,
               T.MATERIAL_NO,
               T.MATERIAL_NAME,
               T.PRODUCCODE,
               T.PRODUCNAME,
               T.STEELCODE,
               T.STEELNAME,
               T.GRADECODE,
               T.GRADENAME,
               T.SPEC_CODE,
               T.SPEC_NAME,
               T.MODEL_CODE,
               T.MODEL_DESC,
               T.STD_CODE,
               T.STD_NAME,
               T.STD_STYLE,
               T.STD_STYLE_DESC,
               T.ORDER_NO,
               T.ORDER_SEQ,
               T.ORDER_SEQ_NO,
               T.PLINE_CODE,
               T.PLINE_NAME,
               T.ACT_DIMATER,
               T.ACT_HEIGHT,
               T.ACT_LEN,
               T.ACT_LEN_MIN,
               T.ACT_LEN_MAX,
               T.ACT_COUNT,
               T.ACT_WEIGHT,
               T.ACT_THEORY_WEIGHT,
               T.JUDGE_RESULT_CODE,
               T.PRO_BC,
               T.PRO_BZ,
               T.RPO_TIME,
               T.ORD_PK,
               T.ORD_LN_PK,
               T.ORD_LN_DLY_PK,
               T.FINISHPRO_MOLD,
               T.IN_MOLD,
               T.IN_TYPE,
               T.ZBS_FLAG,
               T.ZBS_ID,
               T.JG_ZBS_ID
          FROM MAT_ZC_M T, YDM_ZC_BUTTRESS T1
 WHERE T.MAT_NO = T1.MAT_NO
 AND T.LOCK_FLAG='0'
 AND T.MNG_LOCK_FLAG='0'
 AND T.LOCK_LIKU='0'
 AND (T.JUDGE_RESULT_CODE IS NULL OR T.JUDGE_RESULT_CODE IN ('40740701','40740709'))
   AND T.ORD_LN_DLY_PK='#ORD_LN_DLY_PK#'
   AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
   AND NVL(T.BATCH_NO,'/') = NVL('#BATCH_NO#','/')
   AND T.BATCH_GROUD_NO='#BATCH_GROUD_NO#'
   AND T.MAT_STATUS = '80150301'
   AND T1.STORAGE_NO = '#STORAGE_NO#'
   AND NVL(T.STD_CODE,'/')=NVL('#STD_CODE#','/')
   AND NVL(T.STD_NAME,'/')=NVL('#STD_NAME#','/')
   AND NVL(T.MEMO,'/') = NVL('#MEMO#','/')
   AND NVL(T.PLINE_CODE,'/') = NVL('#PLINE_CODE#','/')
   AND NVL((SELECT COM.BASENAME FROM COM_BASE_INFO COM WHERE COM.BASECODE=T.IN_MOLD), '/') = NVL('#IN_MOLD#', '/')
   AND NVL(T1.LOCATION_NO,'/')=NVL('#LOCATION_NO#','/')
 ORDER BY T.MAT_NO  )
 WHERE ROWNUM<?
        ]]>
	</query>

	<query id="CorePipeCarbill.getBillCMaxSeq" desc="查询提单从表最大序号">
      <![CDATA[
          SELECT ? ||
       LPAD(SUBSTR(NVL(MAX(t.BILL_SQE), '0000'), -4, 4) + 1, 4, '0') AS BILL_SQE
  FROM YDM_ZC_BILL_C T
 WHERE T.Mat_No=?
        ]]>
	</query>

	<query id="CorePipeCarbill.getBillMMaxSeq" desc="查询提单主表最大序号">
      <![CDATA[
          SELECT NVL(TO_NUMBER(SUBSTR(MAX(T.BILL_NO_SEQ),
                            Length(MAX(T.BILL_NO_SEQ)) - 3)),
           0) + 1 INDEX_SEQ
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
        ]]>
	</query>

	<query id="CorePipeCarbill.cancelDown" desc="撤销下发的提单">
 <![CDATA[
   DECLARE
BEGIN
  FOR MYROW IN (SELECT S.* FROM YDM_ZC_BILL_C S WHERE S.BILL_NO = ?) LOOP
    UPDATE MAT_ZC_M T
       SET T.LOCK_BILL_FLAG = '0'
     WHERE T.JUDGE_STOVE_NO = MYROW.JUDGE_STOVE_NO
       AND T.BATCH_NO = MYROW.BATCH_NO
       AND T.BATCH_GROUD_NO = MYROW.GROUP_NO
       AND T.MAT_NO = MYROW.MAT_NO;
  END LOOP;
  UPDATE YDM_ZC_BILL_M
     SET BILL_STATUS    = '0',
         UPDATE_NAME    = ?,
         UPDATE_TIME    = SYSDATE,
         LOCK_BILL_FLAG = '0'
   WHERE BILL_NO = ?
     AND VALIDFLAG = '1';
END;

 ]]>
	</query>

	<query id="CorePipeCarbill.getCountBySendPlanNo" desc="查询计划号的提单数">
       <![CDATA[
         SELECT COUNT(1) COUNT
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO != ?
   AND T.SEND_PLAN_NO = ?
   AND T.BILL_STATUS>'0'
   AND T.VALIDFLAG = '1'
        ]]>
	</query>

	<query id="CorePipeCarbill.updatePlanMBySendPlanNo" desc="将计划号改为下发状态">
       <![CDATA[
          UPDATE YDM_ZC_SENDPLAN_M T
   SET T.SEND_PLAN_STATUS = '1'
 WHERE T.SEND_PLAN_NO = ?
   AND T.VALIDFLAG = '1'
        ]]>
	</query>

	<query id="CorePipeCarbill.getTallysheetNum" desc="通过提单号查询理化信息">
       <![CDATA[
            SELECT COUNT(1) COUNT
  FROM YDM_ZC_TALLYSHEET_M T
 WHERE T.BILL_NO = ?
   AND T.VALIDFLAG = '1'
        ]]>
	</query>

	<query id="CorePipeCarbill.cancelBillDrawOff" desc="撤销划断">
       <![CDATA[
           UPDATE YDM_ZC_BILL_M T SET T.ISPRECLOSE = '0' WHERE T.BILL_NO = ?
        ]]>
	</query>

	<query id="CorePipeCarbill.billDrawOff" desc="提单划断">
       <![CDATA[
           UPDATE YDM_ZC_BILL_M T SET T.ISPRECLOSE = '1' WHERE T.BILL_NO = ?
        ]]>
	</query>

	<query id="CorePipeCarbill.getBillInfoByBillNo" desc="查询提单信息">
       <![CDATA[
 SELECT T.BILL_STATUS,
       T.LOADVEHICLE_TYPE,
       T.ISPRECLOSE,
       T.LOCK_BILL_FLAG,
       T.BILL_NO_SEQ,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.PLAN_NUM,
       T.PLAN_WT,
       T.MANAGEMENT_NAME,
       T.CREATE_TIME,
       T.BILL_NO,
       T.RECEIV_NM,
       CASE
         WHEN T.BILL_TICKET_STATUS = 0 AND T.OUTSTOCK_TICKET_STATUS = 0 AND
              T.TRANSMNY_TICKET_STATUS = 0 THEN
          0
         WHEN T.BILL_TICKET_STATUS = 2 AND T.OUTSTOCK_TICKET_STATUS = 2 AND
              T.TRANSMNY_TICKET_STATUS = 2 THEN
          2
         ELSE
          1
       END BILL_TICKET_STATUS
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
   AND T.VALIDFLAG = '1'
        ]]>
	</query>
	<query id="CorePipeCarBill.deleteBillCByOrdPkAndJust" desc="合同撤销">
       <![CDATA[
          DELETE FROM YDM_ZC_BILL_C T
 WHERE T.Bill_No = ?
   AND T.ORD_LN_DLY_PK = ?
   AND T.JUDGE_STOVE_NO = ?
   AND NVL(T.BATCH_NO,'/') = NVL(?,'/')
   AND T.GROUP_NO=?
   #LOCATION_NO#
        ]]>
	</query>
	
	
	<query id="CorePipeCarBill.deleteMatByOrdPkAndJust" desc="合同撤销">
       <![CDATA[
          UPDATE MAT_ZC_M
   SET MAT_STATUS = '80150301', UPDATE_NAME = ?, UPDATE_TIME = SYSDATE
 WHERE MAT_NO IN (SELECT T1.MAT_NO
                    FROM YDM_ZC_BILL_C T1
                   WHERE T1.BILL_NO = ?
                     AND T1.ORD_PK = ?
                     AND T1.ORD_LN_PK = ?
                     AND T1.ORD_LN_DLY_PK = ?
                     AND T1.JUDGE_STOVE_NO = ?
                     AND NVL(T1.BATCH_NO,'/') = NVL(?,'/')
                     AND T1.GROUP_NO=?
                     #LOCATION_NO#
                     AND T1.VALIDFLAG = '1')
        ]]>
	</query>
	
	<query id="CorePipeCarBill.queryBillMByOrdPkAndJust" desc="合同撤销">
       <![CDATA[
        SELECT SUM(NVL(T.PLAN_NUM, 0)) PLAN_NUM, SUM(NVL(T.PLAN_WT, 0)) PLAN_WT,
        SUM(NVL(T.PLAN_TOTL_LEN,0)) PLAN_TOTL_LEN,T.SEND_PLAN_NO
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
   AND T.ORD_LN_DLY_PK = ?
   GROUP BY T.SEND_PLAN_NO
        ]]>
	</query>
	
	<query id="CorePipeCarBill.queryBillCByOrdPkAndJust" desc="合同撤销">
       <![CDATA[
        SELECT SUM(NVL(T.ACT_COUNT, 0)) ACT_COUNT,
       SUM(NVL(T.ACT_WEIGHT, 0)) ACT_WEIGHT,
       SUM(NVL(T.ACT_LEN,0)) ACT_LEN
  FROM YDM_ZC_BILL_C T
 WHERE T.BILL_NO = ?
   AND T.ORD_LN_DLY_PK = ?
   AND T.JUDGE_STOVE_NO = ?
   AND NVL(T.BATCH_NO,'/') = NVL(?,'/')
   AND T.GROUP_NO=?
   #LOCATION_NO#
        ]]>
	</query>
	
	<query id="CorePipeCarBill.updateBillMByOrdPkAndJust" desc="合同撤销">
       <![CDATA[
     UPDATE YDM_ZC_BILL_M T
   SET T.PLAN_WT = ?, T.PLAN_NUM = ?,T.PLAN_TOTL_LEN=?,T.UPDATE_TIME = SYSDATE
 WHERE T.Bill_No = ?
   AND T.ORD_LN_DLY_PK = ?
        ]]>
	</query>
	
	<query id="CorePipeCarBill.deleteBillMByOrdPkAndJust" desc="合同撤销">
       <![CDATA[
          DELETE FROM YDM_ZC_BILL_M T
 WHERE T.Bill_No = ?
   AND T.ORD_LN_DLY_PK = ?
        ]]>
	</query>
<query id="CorePipeCarBill.updateSendM" desc="反写计划主表计划量">
       <![CDATA[
 UPDATE YDM_ZC_SENDPLAN_M
   SET ACT_WT      = TO_NUMBER(NVL(ACT_WT, 0)) + TO_NUMBER(?),
       UPDATE_NAME = ?,
       UPDATE_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
 WHERE SEND_PLAN_NO = ?
        ]]>
	</query>
<query id="CorePipeCarBill.updateSendC" desc="反写计划从表计划量">
       <![CDATA[
 UPDATE YDM_ZC_SENDPLAN_C
   SET ACT_WT = TO_NUMBER(NVL(ACT_WT, 0)) + 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="CorePipeCarBill.DeleteSendM" desc="删除反写计划主表计划量">
       <![CDATA[
 UPDATE YDM_ZC_SENDPLAN_M
   SET ACT_WT      = TO_NUMBER(NVL(ACT_WT, 0)) - TO_NUMBER(?)
       --UPDATE_NAME = ?,
       --UPDATE_TIME = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')
 WHERE SEND_PLAN_NO = ?
        ]]>
	</query>
<query id="CorePipeCarBill.DeleteSendC" desc="删除反写计划从表计划量">
       <![CDATA[
 UPDATE YDM_ZC_SENDPLAN_C
   SET ACT_WT = TO_NUMBER(NVL(ACT_WT, 0)) - 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="CorePipeCarBill.queryOrderLinDer" desc="交货行交货地点">
       <![CDATA[
 SELECT T.DELVRY_ADDR FROM SLM_ORDER_LINE_DELIVERY T WHERE T.ORD_LN_DLY_PK = ?  AND T.VALIDFLAG='1'
        ]]>
	</query>
	<query id="CorePipeCarBill.queryLockMatNo" desc="查询材料封锁状态">
       <![CDATA[
SELECT T.LOCK_FLAG, T.MNG_LOCK_FLAG FROM MAT_ZC_M T WHERE T.MAT_NO = ? AND (T.JUDGE_RESULT_CODE IS NULL OR T.JUDGE_RESULT_CODE IN ('40740701','40740709'))
        ]]>
	</query>
	
	<query id="CorePipeCarBill.verifiNum" desc="查询材料封锁状态">
       <![CDATA[
			select max(count(1)) num
  from (select t.ord_ln_pk, t.judge_stove_no, t.batch_no
          from ydm_zc_bill_c t
         where t.bill_no = ?
         group by t.ord_ln_pk, t.judge_stove_no, t.batch_no) t1
 group by t1.ord_ln_pk

        ]]>
	</query>
	
	
	<query id="CorePipeCarBill.queryOrdLnDlyPkWT" desc="交货行交货量">
       <![CDATA[
 SELECT T.WGT_ESTMT, L.DELVRY_RANGE_MAX,T.DELVRY_ADDR
  FROM SLM_ORDER_LINE_DELIVERY T, SLM_ORDER_LINE L
 WHERE T.ORD_PK = L.ORD_PK(+)
   AND T.ORD_LN_PK = L.ORD_LN_PK(+)
   AND T.ORD_LN_DLY_PK = ?
   AND T.VALIDFLAG = '1'
   AND l.VALIDFLAG = '1'

        ]]>
	</query>
	<query id="CorePipeCarBill.queryBillWeight" desc="该合同提单量">
       <![CDATA[
       SELECT NVL(SUM(T.ACT_WEIGHT),0) AS ACT_WEIGHT FROM YDM_ZC_BILL_C T WHERE T.ORD_LN_DLY_PK=? AND T.VALIDFLAG='1'
        ]]>
	</query>
	<query id="CorePipeCarBill.UpdatePrtFalg" desc="修改过磅">
       <![CDATA[
       UPDATE YDM_ZC_BILL_C T SET T.PRT_FLAG=? WHERE T.BILL_NO=?
        ]]>
	</query>
	<query id="CorePipeCarBill.QUERYBILLMATNO" desc="查询提单从表材料号">
       <![CDATA[
       SELECT T.MAT_NO,T.EDIT_FLAG FROM YDM_ZC_BILL_C T WHERE T.BILL_NO=?
        AND T.JUDGE_STOVE_NO=?
        AND NVL(T.Batch_No,'/') =NVL(?,'/')
        AND T.GROUP_NO=?
        AND T.EDIT_FLAG='0'
        ORDER BY T.MAT_NO
        ]]>
	</query>
	<query id="CorePipeCarBill.getBillCedit" desc="查询理货状态">
       <![CDATA[
       SELECT MAX(T.EDIT_FLAG) EDIT_FLAG FROM YDM_ZC_BILL_C T WHERE T.BILL_NO=?
        AND T.JUDGE_STOVE_NO=?
        AND NVL(T.Batch_No,'/') =NVL(?,'/')
        AND T.GROUP_NO=?   
        AND T.EDIT_FLAG=?
        ]]>
	</query>
	<query id="CorePipeCarbill.UpdateBillCStorage" desc="修改提单从表出库地点">
       <![CDATA[
      UPDATE YDM_ZC_BILL_C T SET T.STORAGE_NO=? , T.LOCATION_NO=?,T.VSTEL=?,
       T.VSTEL_DESC=?
       WHERE T.BILL_NO=? AND T.MAT_NO=?
        ]]>
	</query>
	<query id="CorePipeCarbill.Updatebuttress" desc="修改位置表出库地点">
       <![CDATA[
      UPDATE YDM_ZC_BUTTRESS T SET T.STORAGE_NO=? ,T.LOCATION_NO=? WHERE T.MAT_NO=?
        ]]>
	</query>
	<query id="CorePipeCarBill.updatePintFlag" desc="回写打印次数，打印时间">
       <![CDATA[
     UPDATE YDM_ZC_BILL_M T
   SET T.PRINT_NUMBER = TO_NUMBER(NVL(T.PRINT_NUMBER, 0)) +'1', T.PRINT_TIME = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') WHERE T.BILL_NO = ? 
        ]]>
	</query>
	<query id="CorePipeCarBill.queryBillMatNoC" desc="查询是否生成提单">
       <![CDATA[
       SELECT T.MAT_NO,T.BILL_NO FROM YDM_ZC_BILL_C T WHERE T.MAT_NO=? AND T.VALIDFLAG='1' AND T.RETURN_FLAG = '0'
      ]]>
	</query>
	<query id="CorePipeCarBill.DeleteBillNo" desc="删除提单号">
       <![CDATA[
       DELETE YDM_ZC_BILL_NO  WHERE BILL_NO = ?
      ]]>
	</query>
	<query id="CorePipeCarBill.InsertDeryL" desc="新增到提单运输表">
       <![CDATA[
      INSERT INTO YDM_ORDER_DELIVERY_TRANSIT
  (ORD_PK,
   ORD_LN_PK,
   ORD_LN_DLY_PK,
   INDEX_SEQ,
   AGENCY_FL,
   TRANSIT_TYP,
   DESTINATION,
   STATION_NO,
   STATION_NM,
   SPCL_LN_NO,
   SPCL_LN_NM,
   PORT_NO,
   PORT_DESC,
   CARRIER_UNIT,
   RECEIVOR,
   TRANSIT_LN_MNY,
   VALIDFLAG,
   CREATE_NAME,
   CREATE_TIME,
   BILL_NO)
  SELECT T.ORD_PK,
         T.ORD_LN_PK,
         T.ORD_LN_DLY_PK,
         T.INDEX_SEQ,
         T.AGENCY_FL,
         T.TRANSIT_TYP,
         T.DESTINATION,
         T.STATION_NO,
         T.STATION_NM,
         T.SPCL_LN_NO,
         T.SPCL_LN_NM,
         T.PORT_NO,
         T.PORT_DESC,
         T.CARRIER_UNIT,
         T.RECEIVOR,
         T.TRANSIT_LN_MNY,
         T.VALIDFLAG,
         ?,
         TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'),
         ?
    FROM SLM_ORDER_DELIVERY_TRANSIT T
   WHERE T.ORD_LN_DLY_PK = ? AND T.VALIDFLAG='1'
      
      ]]>
	</query>
	<query id="CorePipeCarBill.queryDeryL" desc="查询提单运输方式">
       <![CDATA[ 
       SELECT T.ORD_LN_DLY_PK FROM YDM_ORDER_DELIVERY_TRANSIT T WHERE T.ORD_LN_DLY_PK=? AND T.BILL_NO=?
         ]]>
	</query>
	<query id="CorePipeCarBill.DeleteTRANSIT" desc="删除提单运输方式">
       <![CDATA[ 
    DELETE YDM_ORDER_DELIVERY_TRANSIT T WHERE T.BILL_NO=? AND T.ORD_LN_DLY_PK=? 
         ]]>
	</query>
	<query id="CorePipeCarBill.DeleteTRANSIT1" desc="删除提单运输方式">
       <![CDATA[ 
    DELETE YDM_ORDER_DELIVERY_TRANSIT T WHERE T.BILL_NO=?
         ]]>
	</query>
	<query id="CorePipeCarBill.getPortDesc" desc="查询目标港">
       <![CDATA[ 
   SELECT T.BASECODE,T.BASENAME FROM COM_BASE_INFO  T WHERE T.SORTCODE=? AND T.VALIDFLAG='1'
         ]]>
	</query>
	<query id="CorePipeCarBill.queryBillExtie" desc="查询导出数据">
       <![CDATA[ 
 SELECT T.BILL_NO,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       (SELECT B.BASENAME
          FROM COM_BASE_INFO B
         WHERE B.BASECODE = T.PLAN_TRANS_TYPE) AS PLAN_TRANS_TYPE,
       C.JUDGE_STOVE_NO,
       C.BATCH_NO,
       C.GROUP_NO,
       (SELECT S.STORAGE_NAME
          FROM YDM_BS_STORAGE S
         WHERE S.STORAGE_NO = C.STORAGE_NO) AS STORAGE_NO,
       (SELECT S.LOCATION_NAME
          FROM YDM_BS_LOCATION S
         WHERE S.LOCATION_NO = C.LOCATION_NO) AS LOCATION_NO,
       T.CREATE_NAME,
       TO_CHAR(MAX(T.UPDATE_TIME), 'YYYY-MM-DD HH24:MI:SS') AS UPDATE_TIME,
       TO_CHAR(MAX(T.CREATE_TIME), 'YYYY-MM-DD HH24:MI:SS') AS CREATE_TIME,
       C.PRODUCNAME,
       C.STEELNAME,
       C.SPEC_NAME,
       C.STD_NAME,
       C.GRADENAME,
       C.STD_STYLE_DESC,
       C.MODEL_DESC,
       C.VSTEL_DESC,
       DECODE(T.LOADVEHICLE_TYPE, '1', '实际', '2', '虚拟') AS LOADVEHICLE_TYPE,
       DECODE(CASE
                WHEN T.BILL_TICKET_STATUS = 0 AND T.OUTSTOCK_TICKET_STATUS = 0 AND
                     T.TRANSMNY_TICKET_STATUS = 0 THEN
                 0
                WHEN T.BILL_TICKET_STATUS = 2 AND T.OUTSTOCK_TICKET_STATUS = 2 AND
                     T.TRANSMNY_TICKET_STATUS = 2 THEN
                 2
                ELSE
                 (CASE
                   WHEN T.BILL_STATUS >= 4 THEN
                    1
                   ELSE
                    4
                 END)
              END,
              '1',
              '票据对齐(' || T.BILL_TICKET_STATUS || T.OUTSTOCK_TICKET_STATUS ||
              T.TRANSMNY_TICKET_STATUS || ')',
              '2',
              '提单结束',
              DECODE(T.BILL_STATUS,
                     '0',
                     '提单编制',
                     '1',
                     '提单下发',
                     '2',
                     '(预留)',
                     '3',
                     '提单执行',
                     '4',
                     '提单关闭',
                     '5',
                     '结算接收')) AS BILL_STATUS,
       DECODE(T.LOADVEHICLE_TYPE,
              '2',
              DECODE(T.ISPRECLOSE,
                     '0',
                     '未关闭',
                     '1',
                     '一次关闭',
                     '2',
                     '货款对齐'),
              '') AS ISPRECLOSE,
       DECODE(MAX(C.PRT_FLAG), '0', '否', '1', '是') AS PRT_FLAG,
       DECODE(T.PICKUP_FLAG, '0', '否', '1', '是') AS PICKUP_FLAG,
       DECODE(T.ZOUT_FLAG, '0', '否', '1', '是') AS ZOUT_FLAG,
       T.STATION_NM,
       T.SPCL_LN_NM,
       T.RECEIV_NM,
       T.CUSTOMER_NM,
       T.SALE_ORG_DESC,
       H.SALE_AREA_DESC,
       DECODE(C.EDIT_FLAG, '1', '已理货', '未理货') EDIT_FLAG,
       DECODE(C.LOADVEHICLE_FLAG, '1', '已装车', '未装车') LOADVEHICLE_FLAG,
       SUM(CASE
             WHEN C.EDIT_FLAG = '1' THEN
              C.ACT_LEN
             ELSE
              0
           END) PREP_LEN,
       SUM(CASE
             WHEN C.EDIT_FLAG = '1' THEN
              C.ACT_COUNT
             ELSE
              0
           END) PREP_COUNT,
       SUM(CASE
             WHEN C.EDIT_FLAG = '1' THEN
              C.ACT_WEIGHT
             ELSE
              0
           END) PREP_WEIGHT,
       SUM(CASE
             WHEN C.EDIT_FLAG = '1' THEN
              C.ACT_THEORY_WEIGHT
             ELSE
              0
           END) PREP_THEORY_WEIGHT,
       SUM(CASE
             WHEN C.EDIT_FLAG = '0' THEN
              C.ACT_LEN
             ELSE
              0
           END) BEEN_LEN,
       SUM(CASE
             WHEN C.EDIT_FLAG = '0' THEN
              C.ACT_COUNT
             ELSE
              0
           END) BEEN_COUNT,
       SUM(CASE
             WHEN C.EDIT_FLAG = '0' THEN
              C.ACT_WEIGHT
             ELSE
              0
           END) BEEN_WEIGHT,
       SUM(CASE
             WHEN C.EDIT_FLAG = '0' THEN
              C.ACT_THEORY_WEIGHT
             ELSE
              0
           END) BEEN_THEORY_WEIGHT,
       NVL(SUM(C.ACT_COUNT), '0') AS ACT_COUNT,
       NVL(SUM(C.ACT_LEN), '0') AS ACT_LEN,
       NVL(SUM(C.ACT_WEIGHT), '0') AS ACT_WEIGHT,
       NVL(SUM(C.ACT_THEORY_WEIGHT), '0') AS ACT_THEORY_WEIGHT,
       NVL(SUM(C.SEND_NUM), 0) AS SEND_NUM,
       -- ROUND(NVL(SUM(C.ACT_LEN * 3.281 ), 0),2)SEND_NUM_Y,
       NVL( SUM( ROUND(C.ACT_LEN * 3.281 , 2 )), 0 ) SEND_NUM_Y ,
       C.ACT_LEN_MIN,
       C.ACT_LEN_MAX
  FROM YDM_ZC_BILL_C C, YDM_ZC_BILL_M T, SLM_ORDER_HEAD H
 WHERE C.BILL_NO = T.BILL_NO
   AND H.ORD_PK = T.ORD_PK(+)
   AND T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK 
   AND T.VALIDFLAG = '1'
         ]]>
	</query>
	<query id="CorePipeCarBill.queryPlineDepart" desc="根据产线产线管理部门">
       <![CDATA[ 
       SELECT T.DEPARTMENT_CODE_P,T.DEPARTMENT_DESC_P,T.PROCESS_CODE,T.PROCESS_DESC  FROM COM_BASE_PLINE T WHERE T.PLINE_CODE=?
          ]]>
	</query>
	<query id="CorePipeCarBill.getReceivNo" desc="獲取收貨單位">
		<![CDATA[
	  SELECT T.CUSTOMER_NM,T.CUSTOMER_NO FROM SLM_BASE_CUSTOMER T WHERE T.VALIDFLAG='1'  ORDER BY T.CUSTOMER_NM ASC
		]]>
	</query>
	<query id = "CorePipeCarBill.doQueryDataMat" desc = "按管号查询">
		SELECT T.MEASURING_SEQ, T.ACT_LEN, ROUND(T.ACT_LEN * 3.281,2) AS ACT_LEN_Y,
		T.ACT_WEIGHT, T.MAT_NO, T.JUDGE_RESULT
		FROM MAT_ZC_M T
		LEFT JOIN YDM_ZC_BUTTRESS S
		ON T.MAT_NO = S.MAT_NO
		WHERE T.ORD_PK = '#ORD_PK#'
		AND T.ORD_LN_PK = '#ORD_LN_PK#'
		AND T.ORD_LN_DLY_PK = '#ORD_LN_DLY_PK#'
		AND T.JUDGE_STOVE_NO = '#JUDGE_STOVE_NO#'
		AND T.BATCH_NO = '#BATCH_NO#'
		AND T.BATCH_GROUD_NO = '#BATCH_GROUD_NO#'
		AND S.STORAGE_NO = '#STORAGE_NO#'
		AND S.LOCATION_NO = '#LOCATION_NO#'
		AND NVL((SELECT COM.BASENAME FROM COM_BASE_INFO COM WHERE COM.BASECODE=T.IN_MOLD), '/') = NVL('#IN_MOLD#', '/')
		AND T.PRODUCT_FLAG = '801403'
		AND T.MAT_STATUS = '80150301'
		AND T.MNG_LOCK_FLAG = '0'
		AND T.LOCK_FLAG = '0'
		AND NVL(T.MEMO, '/')=NVL('#MEMO#', '/')
		ORDER BY TO_NUMBER(T.MEASURING_SEQ) ASC
	</query>
	
			<query id="CorePipeCarBill.deleteWlInfoByBillNo" desc="产线">
		<![CDATA[
	delete  TMS_DEMAND_M where refe_no like ? ||'%'
		]]>
	</query>
	
		<query id="CorePipeCarBill.getWlInfo" desc="产线">
		<![CDATA[
select t.material_name wlCode,t.material_no wlName  from mat_zc_m t where t.mat_no = ?
		]]>
	</query>
	
	<query id="CorePipeCarBill.getWlInfoFromBackup" desc="产线">
		<![CDATA[
select t.material_name wlCode,t.material_no wlName  from mat_zc_backup t where t.mat_no = ?
		]]>
	</query>
	
		<query id="CorePipeCarBill.getMaxSeq" desc="产线">
		<![CDATA[
SELECT MAX(T.DEMAND_NO) DEMAND_NO FROM TMS_DEMAND_M t WHERE T.DEMAND_NO LIKE ? || '%'
		]]>
	</query>
	
	<query id="CorePipeCarBill.InsertWlInfo" desc="产线">
		<![CDATA[
		INSERT INTO TMS_DEMAND_M
  			(DEMAND_NO,
  			DEMAND_DESC,
  			EXECUTE_SQE,
  			URGENCY_TYPE_CODE,
  			URGENCY_TYPE_DESC,
  			TRAN_CLASS_CODE,
  			TRAN_CLASS_DESC,
  			REFE_NO,
  			START_NODE_CODE,
  			START_NODE_DESC,
  			START_AREA_CODE,
  			START_AREA_DESC,
  			CAR_USE_CODE,
  			CAR_USE_DESC,
  			CAR_TYPE_CODE,
  			CAR_TYPE_DESC,
  			CAR_WT_VAL,
  			WEIGHING_IF,
  			HEAT_NO,
  			BATCH_NO,
  			LOGO_NO,
  			MATERIALS_CODE,
  			MATERIALS_DESC,
  			MATERIALS_SPEC,
  			DIMATER_VAL,
  			HEIGHT_VAL,
  			LEN_VAL,
  			LEN_MIN_VAL,
  			LEN_MAX_VAL,
  			DEMAND_QTY_VAL,
  			DEMAND_WT_VAL,
  			SCRAP_QTY_VAL,
  			SCRAP_WT_VAL,
  			PRO_ORDER_NO,
  			PRO_ORDER_SQE,
  			CURRENT_JOB_NO,
  			PREVIOUS_JOB_NO,
  			SOURCE_SIGN,
  			VALIDFLAG,
  			STATUS,
  			ARCHIVE_FLAG,
  			CREATE_NAME,
  			CREATE_TIME)
			VALUES
  			(?,?,(select to_char(nvl(max(to_number(execute_sqe)),0)+1) execute_sqe from TMS_DEMAND_M),?,?
  			,?,?,?,?,?
  			,?,?,?,?,?
  			,?,?,?,?,?
  			,?,?,?,?,?
  			,?,?,?,?,?
  			,?,?,?,?,?
  			,?,?,?,?,?
  			,?,?,SYSDATE)
		]]>
	</query>

	<query id="CorePipeCarBill.queryLimsData" desc="产线">
		<![CDATA[
		SELECT DISTINCT * FROM (
			SELECT
				M.BILL_NO INDEX_CODE,
				C.PRODUCCODE MATTER_NO,
				C.PRODUCNAME MATTER_NAME,
				C.GRADECODE SPEC_NO,
				C.GRADENAME SPEC_NAME,
				C.MATERIAL_NO MATERIAL_NO,
				C.MATERIAL_NAME MATERIAL_NAME,
				M.BILL_NO CONTRACT_NO,
				C.BATCH_NO BATCH_NO,
				'120501' FORWARDING_UNIT_NO,
				'天津钢管制造有限公司' FORWARDING_UNIT_NAME,
				M.CUSTOMER_NO CUSTOMER_SUPPLIER_NO,
				M.CUSTOMER_NM CUSTOMER_SUPPLIER_NAME,
				M.RECEIV_NO RECEIVING_UINT_NO,
				M.RECEIV_NM RECEIVING_UINT_NAME,
				'0' VALUE_FLAG
			FROM
			YDM_ZC_BILL_M M
				INNER JOIN 	(
					SELECT
						T.BILL_NO,
						T.ORDER_NO || '/' || T.ORDER_SEQ ORDER_NO,
						max(T.BATCH_NO) BATCH_NO,
						T.MATERIAL_NAME,
						T.PRODUCCODE,
						T.PRODUCNAME,
						T.MATERIAL_NO,
						max(T.GRADECODE) GRADECODE,
						max(T.GRADENAME) GRADENAME
				FROM
					YDM_ZC_BILL_C T
					LEFT JOIN YDM_BS_STORAGE B ON T.STORAGE_NO = B.STORAGE_NO
				WHERE
					T.RETURN_FLAG = '0' --AND t.VSTEL = 'LXW1'
					and t.PRT_FLAG = '1'
				GROUP BY
					T.BILL_NO,
					T.ORDER_NO || '/' || T.ORDER_SEQ,
					T.MATERIAL_NAME,
					T.MATERIAL_NO,
					T.PRODUCCODE,
					T.PRODUCNAME
				ORDER BY
					T.ORDER_NO
				) C ON C.BILL_NO = M.BILL_NO
			WHERE
				1 = 1 and m.SUPPLY_UNIT = '120501' and m.IS_OVERSTOCK = '1' #code#
			)
		]]>
	</query>


	<query id="CorePipeCarBill.getMoneyByBuyercode" desc="查询可发金额">
		<![CDATA[
		SELECT BUYERCODE,SUM(MONEY2) MONEY FROM (SELECT
			b.balancesubject,
			b.buyercode,
			b.secondaccount,
			nvl( b.pre_money, 0 ) pre_money,
			nvl( b.pre_money, 0 ) money,
			b.INVOICE_ACCOUNT,
			nvl( inmoney, nvl( c.inoutmoney, 0 ) ) INMONEY,
			nvl( invoice_money, f.money ) INVOICE_MONEY,
			nvl(
				lst_money,
				nvl( b.pre_money, 0 ) + nvl( inmoney, nvl( c.inoutmoney, 0 ) ) - nvl( nvl( invoice_money, f.money ), 0 )
			) LST_MONEY,
			b.invoice_person,
			b.invoice_date,
			b.invoice_date,
			b.invoice_month,
			b.invoice_account,
			b.INVOICE_STS,
			BILL.ACT_WEIGHT,
			BILL.BALNCE_PRICE,
			BALANCE.WEIGHT WEIGHT1,
			BALANCE.MONEY MONEY1,
			nvl( b.pre_money, 0 ) + nvl( inmoney, nvl( c.inoutmoney, 0 ) ) - nvl( BILL.BALNCE_PRICE, 0 ) - nvl( BALANCE.MONEY, 0 ) - nvl( BALANCE2.MONEY, 0 ) MONEY2
		FROM
			SEL_FUND_RECEIVE_ACCOUNT b
			LEFT JOIN (
			SELECT
				sum( c.inoutmoney ) inoutmoney,
				c.balancesubject,
				c.buyercode,
				c.secondaccount
			FROM
				(
				SELECT
					sum( fu.inoutmoney ) inoutmoney,
					fu.balancesubject,
					fu.buyercode,
					fu.secondaccount
				FROM
					sel_fund_cust_fundinout fu
				WHERE
					fu.isvalid = '1'
					AND GET_FISCAL_MONTH1 ( fu.inouttime ) = GET_FISCAL_MONTH1 ( SYSDATE )
					AND busiseq NOT LIKE '%-1'
					AND fu.balancesubject = '国内贸易部'
				GROUP BY
					fu.balancesubject,
					fu.buyercode,
					fu.secondaccount
				) c
			GROUP BY
				c.balancesubject,
				c.buyercode,
				c.secondaccount
			) c ON b.balancesubject = c.balancesubject
			AND b.buyercode = c.buyercode
			AND b.secondaccount = c.secondaccount
			LEFT JOIN (
			SELECT
				sum( s.money ) money,
				s.buyercode,
				s.sale_area_desc,
				s.forecorpcode
			FROM
				(
				SELECT
				CASE
						CONTAIN_TAX
						WHEN '1' THEN
						sum( s.money ) ELSE ROUND( sum( s.money ) * 1.13, 3 )
					END money,
			s.buyercode,
			s.sale_area_desc,
			s.forecorpcode
		FROM
			slm_balanceinfo s
		WHERE
			s.balancestatus = '3'
			AND s.forecorpcode = '国内贸易部'
			AND s.FST_DRAWEE_UNIT = '120604'
			AND GET_FISCAL_MONTH1 ( s.INVOICEDATE ) = GET_FISCAL_MONTH1 ( SYSDATE )
		GROUP BY
			CONTAIN_TAX,
			s.buyercode,
			s.sale_area_desc,
			s.forecorpcode UNION ALL
		SELECT
			sum( b.money ),
			b.buyercode,
			c.sale_area_desc,
			b.forecorpname
		FROM
			slm_balance_transmoney b
			JOIN slm_order_head c ON b.ord_pk = c.ord_pk
		WHERE
			1 = 1
			AND b.status_cd = '2'
			AND b.tickettype = '应收'
			AND b.forecorpname = '国内贸易部'
			AND b.FST_DRAWEE_UNIT = '120604'
			AND GET_FISCAL_MONTH1 ( b.REG_DTIME ) = GET_FISCAL_MONTH1 ( SYSDATE )
		GROUP BY
			b.buyercode,
			c.sale_area_desc,
			b.forecorpname
			) s
		GROUP BY
			s.buyercode,
			s.sale_area_desc,
			s.forecorpcode
			) f ON b.balancesubject = f.forecorpcode
			AND b.buyercode = f.buyercode
			AND b.secondaccount = f.sale_area_desc
			LEFT JOIN (
			SELECT
				T.CUSTOMER_NO,
				T.SALE_ORG_DESC,
				T.MANAGEMENT_NAME,
				SUM( T1.ACT_COUNT ) ACT_COUNT,
				SUM( T1.ACT_WEIGHT ) ACT_WEIGHT,
				SUM( T1.SEND_NUM ) SEND_NUM,
				SUM( t2.BALNCE_PRICE * t1.ACT_WEIGHT ) BALNCE_PRICE
			FROM
				YDM_ZC_BILL_M t
				LEFT JOIN YDM_ZC_BILL_C T1 ON T.BILL_NO = T1.BILL_NO
				AND t.ORD_LN_PK = t1.ORD_LN_PK
				LEFT JOIN SLM_ORDER_LINE t2 ON t.ORD_LN_PK = t2.ORD_LN_PK
			WHERE
				T.BILL_STATUS IN ( '1', '2', '3' )
				AND FST_DRAWEE_UNIT = '120604'
				AND NOT EXISTS ( SELECT 1 FROM SLM_BALANCEINFO WHERE ( BALANCESTATUS = '3' OR BALANCESTATUS_ORG = '3' ) AND ASKPLAN_ID = T.BILL_NO )
			GROUP BY
				T.CUSTOMER_NO,
				T.SALE_ORG_DESC,
				T.MANAGEMENT_NAME
			) BILL ON BILL.CUSTOMER_NO = B.buyercode
			AND BILL.MANAGEMENT_NAME = B.SECONDACCOUNT
			AND BILL.SALE_ORG_DESC = B.INVOICE_ACCOUNT
			LEFT JOIN (
			SELECT
				BUYERCODE,
				FORECORPCODE,
				SALE_AREA_DESC,
				sum( WEIGHT ) WEIGHT,
				sum( MONEY ) MONEY
			FROM
				SLM_BALANCEINFO T
			WHERE
				(
					(
						BALANCESTATUS IN ( '0', '1', '2' )
						AND ISPRECLOSE = '是'
						AND EXISTS ( SELECT 1 FROM YDM_ZC_BILL_M WHERE BILL_NO = T.ASKPLAN_ID AND BILL_STATUS = '4' )
					)
					OR ( BALANCESTATUS IN ( '0', '1', '2' ) AND ISPRECLOSE = '否' )
				)
				AND FST_DRAWEE_UNIT = '120604'
			GROUP BY
				BUYERCODE,
				FORECORPCODE,
				SALE_AREA_DESC
			) BALANCE ON BALANCE.BUYERCODE = B.buyercode
			AND BALANCE.FORECORPCODE = B.INVOICE_ACCOUNT
			AND BALANCE.SALE_AREA_DESC = B.SECONDACCOUNT
			LEFT JOIN (
			SELECT
				BUYERCODE,
				FORECORPCODE,
				SALE_AREA_DESC,
				sum( WEIGHT ) WEIGHT,
				sum( MONEY ) MONEY
			FROM
				SLM_BALANCEINFO T
			WHERE
				INVOICE_MONTH = GET_FISCAL_MONTH1 ( SYSDATE )
				AND BALANCESTATUS = '3'
				AND FST_DRAWEE_UNIT = '120604'
				AND EXISTS ( SELECT 1 FROM YDM_ZC_BILL_M WHERE BILL_STATUS IN ( '4', '5' ) AND BILL_NO = T.ASKPLAN_ID )
			GROUP BY
				BUYERCODE,
				FORECORPCODE,
				SALE_AREA_DESC
			) BALANCE2 ON BALANCE2.BUYERCODE = B.buyercode
			AND BALANCE2.FORECORPCODE = B.INVOICE_ACCOUNT
			AND BALANCE2.SALE_AREA_DESC = B.SECONDACCOUNT
		WHERE
			1 = 1
			AND b.invoice_account = '国内贸易部'
			AND b.invoice_month = GET_FISCAL_MONTH1 ( SYSDATE ))
		WHERE BUYERCODE = ?
		GROUP BY BUYERCODE
		]]>
	</query>


	<query id="CorePipeCarBill.getBillOrder" desc="查询提单合同">
		<![CDATA[
			SELECT
				BILL_NO,
				ORDER_NO,
				ORDER_SEQ,
				MAX( SUPPLY_UNIT ) SUPPLY_UNIT,
				MAX( FST_DRAWEE_UNIT ) FST_DRAWEE_UNIT,
				MAX( MNY_ASK_DESC ) MNY_ASK_DESC,
				SUM( BALNCE_PRICE ) BALNCE_PRICE,
				SUM( PLAN_WT ) PLAN_WT,
				SUM( PLAN_NUM ) PLAN_NUM,
				SUM( PLAN_TOTL_LEN ) PLAN_TOTL_LEN,
				SUM( PLAN_WT ) PLAN_WT,
				SUM( MONEY ) MONEY
			FROM
				(
				SELECT
					T.BILL_NO,
					H.SUPPLY_UNIT,
					H.FST_DRAWEE_UNIT,
					T.ORDER_NO,
					T.ORDER_SEQ,
					L.ORDER_UNIT,
					h.MNY_ASK_DESC,
					T.PLAN_WT,
					T.PLAN_NUM,
					T.PLAN_TOTL_LEN,
					L.BALNCE_PRICE,
				( SELECT NVL( SUM( SEND_NUM ), 0 ) FROM YDM_ZC_BILL_C WHERE BILL_NO = t.BILL_NO AND ORD_LN_PK = t.ORD_LN_PK ) * L.BALNCE_PRICE MONEY
			FROM
				YDM_ZC_BILL_M T
				LEFT JOIN SLM_ORDER_HEAD H ON H.ORD_PK = T.ORD_PK
				LEFT JOIN SLM_ORDER_LINE L ON T.ORD_LN_PK = L.ORD_LN_PK
			WHERE
				T.BILL_NO = ?
				AND T.VALIDFLAG = '1'
				)
			GROUP BY
				BILL_NO,
				ORDER_NO,
				ORDER_SEQ
		]]>
	</query>

</queryMap>
