<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="理货管理sql">
	<query id="FrmTallYsheet.QueryCustomer" desc="客户信息获取">
		<![CDATA[
	       SELECT CUSTOMER_NM,CUSTOMER_NO FROM SLM_BASE_CUSTOMER WHERE VALIDFLAG='1' ORDER  BY  CUSTOMER_NM ASC
		]]>
	</query>
	<query id="FrmTallYsheet.QueryProductName" desc="品名信息获取">
		<![CDATA[
	          SELECT PRODUCNAME,PRODUCCODE FROM COM_BASE_PRODUCT WHERE VALIDFLAG='1' ORDER  BY  PRODUCNAME ASC
		]]>
	</query>
	<query id="FrmTallYsheet.QueryPrivateSid" desc="专用线信息获取">
		<![CDATA[
	       SELECT SPCL_LN_NM,SPCL_LN_NO FROM SLM_BASE_SPCL_LN WHERE VALIDFLAG='1' ORDER  BY  SPCL_LN_NM ASC
		]]>
	</query>
	<query id="FrmTallYsheet.QueryArriveStation" desc="到站信息获取">
		<![CDATA[
	      SELECT STATION_NM,STATION_NO FROM SLM_BASE_STATION WHERE VALIDFLAG='1' ORDER  BY  STATION_NM ASC
		]]>
	</query>
	<query id="FrmTallYsheet.QuerySendList" desc="理货单号获取">
		<![CDATA[ 
   -- SELECT DISTINCT MAX(TALLYSHEET_NO) AS TALLYSHEET_NO FROM YDM_ZC_TALLYSHEET_M WHERE 
	--TO_CHAR(CREATE_TIME,'YYYY-MM-DD')=?  AND OUT_STOCK_CODE =? 
	   SELECT 'TP'|| ? || ? ||
       LPAD(SUBSTR(NVL(MAX(TALLYSHEET_NO), '00000'), -4, 4) + 1,4, '0') AS TALLYSHEET_NO
   FROM YDM_ZC_TALLYSHEET_M T
  WHERE TO_CHAR(t.CREATE_TIME,'YYYY-MM-DD')=?  AND t.OUT_STOCK_CODE =?
      ]]>
	</query>
	
	<query id="FrmTallYsheet.QuerySendListTh" desc="理货单号获取">
		<![CDATA[ 
	   SELECT 'TP'|| 'THK1' || ? ||
       LPAD(SUBSTR(NVL(MAX(TALLYSHEET_NO), '00000'), -4, 4) + 1,4, '0') AS TALLYSHEET_NO
   FROM YDM_ZC_TALLYSHEET_M T,YDM_ZC_BILL_M T1
  WHERE T.BILL_NO=T1.BILL_NO
  AND TO_CHAR(t.CREATE_TIME,'YYYY-MM-DD')=?  
  AND T1.SUPPLY_UNIT='120504'
  AND T.CREATE_TIME > TO_DATE('2020/12/21 07:39:58','YYYY-MM-DD HH24:MI:SS')
      ]]>
	</query>
	
	<query id="FrmTallYsheet.QuerySendList1" desc="理货单号获取">
		<![CDATA[ 
    SELECT DISTINCT TALLYSHEET_NO FROM YDM_ZC_TALLYSHEET_M WHERE 
      OUT_STOCK_CODE =?  AND LOADVEHICLE_FLAG='0'  ORDER BY TALLYSHEET_NO DESC
      ]]>
	</query>
	<query id="FrmTallYsheet.queryPerformance" desc="根据提单号查询理货单">
		<![CDATA[
	   SELECT T.TALLYSHEET_NO, T.BILL_NO,T.TRANS_TYPE,DECODE(T.LOADVEHICLE_FLAG,'0','未装车','1','装车执行','理货关闭') AS LOADVEHICLE_FLAG,T.PRINT_NUM,
	   TO_CHAR(T.PRINT_FLAG,'YYYY-MM-DD HH24:MI:SS') AS PRINT_FLAG, 
	   TO_CHAR(T.CREATE_TIME,'YYYY-MM-DD HH24:MI:SS') AS CREATE_TIME,
	   TO_CHAR(T.END_TIME,'YYYY-MM-DD HH24:MI:SS') AS END_TIME
		   FROM ydm_zc_tallysheet_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.TALLYSHEET_NO || '&' LIKE ('%' || ? || '%')
		    AND T.BILL_NO || '&' LIKE ('%' || ? || '%')
		    AND T.VALIDFLAG = '1'		
		]]>
	</query>
	<query id="FrmTallYsheet.queryPerforIn" desc="根据提单号,理货单号查询">
		<![CDATA[
	   SELECT DISTINCT VEHICLE_NO, CARRY_COMPANY_CODE,CARRY_COMPANY_NAME FROM  ydm_zc_tallysheet_m 
	   WHERE TALLYSHEET_NO LIKE'%'||?||'%' AND BILL_NO=? ORDER BY VEHICLE_NO ASC
		]]>
	</query>
	<query id="FrmTallYsheet.queryTallaySheet" desc="查询理货主表是否存在该记录">
		<![CDATA[
	   SELECT TALLYSHEET_SQE FROM ydm_zc_tallysheet_m WHERE 1 = 1
		]]>
	</query>
	<query id="FrmTallYsheet.queryTager" desc="查询库号信息">
	<![CDATA[
	SELECT t.STORAGE_ATTR,t.STORAGE_ATTR_NAME,t.STORAGE_TYPE_NO,t.STORAGE_TYPE_NAME,
		t.MANAGEMENT_NO,t.MANAGEMENT_NAME FROM ydm_bs_storage t		
    WHERE t.STORAGE_NO=?
	]]>
	</query>
	<query id="FrmTallYsheet.QuerySendSql" desc="查詢理货单主表序号">
		<![CDATA[
	   SELECT T.TALLYSHEET_SQE FROM YDM_ZC_TALLYSHEET_M T WHERE T.TALLYSHEET_NO=? ORDER BY T.TALLYSHEET_SQE DESC
		]]>
	</query>
	<query id="FrmTallYsheet.QuerySendSql_c" desc="查詢理货单材料表序号">
		<![CDATA[
	   SELECT MAX(T.TALLYSHEET_SQE) TALLYSHEET_SQE FROM YDM_ZC_TALLYSHEET_C T where T.tallysheet_no = ?
		]]>
	</query>
	<query id="FrmTallYsheet.QueryBillSql" desc="按炉批行和提单号查询未理货提单材料主键">
		<![CDATA[
 SELECT 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,
       NVL(ACT_LEN, 0) AS ACT_LEN,
       ACT_LEN_MIN,
       ACT_LEN_MAX,
       NVL(ACT_COUNT, 0) AS ACT_COUNT,
       NVL(ACT_WEIGHT, 0) AS ACT_WEIGHT,
       NVL(ACT_THEORY_WEIGHT, 0) AS ACT_THEORY_WEIGHT,
       NVL(SEND_NUM,0) AS SEND_NUM,
       JUDGE_RESULT_CODE,
       PRO_BC,
       PRO_BZ,
       RPO_TIME,
       STORAGE_NO,
       LOCATION_NO,
       ORD_PK,
       ORD_LN_PK,
       ORD_LN_DLY_PK,ACT_FIX_NUM,ACT_FIX_LEN,FINISHPRO_MOLD,IN_MOLD,IN_TYPE
  FROM YDM_ZC_BILL_C
 WHERE BILL_SQE IN ((SELECT T1.BILL_SQE
                      FROM (SELECT T.MAT_NO, T.BILL_SQE
                              FROM YDM_ZC_BILL_C T,MAT_ZC_M T1
                             WHERE T.BILL_NO =?
                               AND T.MAT_NO=T1.MAT_NO
                               AND T.JUDGE_STOVE_NO = ?
                               AND NVL(T.BATCH_NO,'/') = NVl(?,'/')
                               AND T.order_no||t.order_seq =?
                               AND T.STORAGE_NO = ?
                               AND T.GROUP_NO = ?
                               AND T.LOCATION_NO = ?
                               AND NVL(T1.PIPMEMO,'/') = NVl(?,'/')
                               AND T.EDIT_FLAG ='0'
                               AND T.VALIDFLAG ='1'
                             ORDER BY T.MAT_NO ASC) T1
                     WHERE ROWNUM < #rumCont#))
       ORDER BY  MAT_NO ASC        
 
		]]>
	</query>
	<query id="FrmTallYsheet.QuerySqlBill" desc="按炉批行和提单号查询理货提单材料主键">
		<![CDATA[
		SELECT BILL_SQE FROM YDM_ZC_BILL_C WHERE BILL_NO=? AND JUDGE_STOVE_NO=? AND NVL(T.BATCH_NO,'/') = NVl(?,'/') AND GROUP_NO= ?  AND ROWNUM< ? AND EDIT_FLAG='1'
		]]>
	</query>
	<query id="FrmTallYsheet.QueryLoadSql" desc="根据提货单号，材料号询提单材料主键">
		<![CDATA[
		SELECT BILL_SQE FROM YDM_ZC_BILL_C WHERE BILL_NO=? AND MAT_NO=? AND EDIT_FLAG='1'
		]]>
	</query>
	<query id="FrmTallYsheet.QueryLoadSqlTally" desc="查询提单下是否有理货单">
		<![CDATA[
		SELECT T.TALLYSHEET_NO FROM YDM_ZC_TALLYSHEET_M T WHERE T.BILL_NO=? AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="FrmTallYsheet.QueryBillInfo" desc="查詢提單信息">
		<![CDATA[
		SELECT T1.* FROM(
SELECT T.BILL_NO,
  C.ORDER_NO||'/'||C.ORDER_SEQ AS ORDER_SEQ_NO,
               C.ORDER_NO,
               C.ORDER_SEQ,
               C.DELIVERY_NO,
               (SELECT B.BASENAME
                  FROM COM_BASE_INFO B
                 WHERE B.BASECODE = T.PLAN_TRANS_TYPE) AS PLAN_TRANS_TYPE,
               (SELECT NVL(SUM(T1.ACT_COUNT),0) FROM  YDM_ZC_TALLYSHEET_C T1 
               WHERE T1.ORD_PK=T.ORD_PK AND T1.BILL_NO=T.BILL_NO) ORDER_COUNT,
               (SELECT NVL(SUM(T1.ACT_WEIGHT),0) FROM  YDM_ZC_TALLYSHEET_C T1 
               WHERE T1.ORD_PK=T.ORD_PK AND T1.BILL_NO=T.BILL_NO) ORDER_WEIGHT,
               T.CUSTOMER_NO,
               T.CUSTOMER_NM,
               C.JUDGE_STOVE_NO,
               C.BATCH_NO,
               C.GROUP_NO,
               C.STORAGE_NO,
               S.STORAGE_NAME,
               T.CREATE_NAME,
               TO_CHAR(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.LOCATION_NO,
               (SELECT S.LOCATION_NAME FROM YDM_BS_LOCATION S WHERE S.LOCATION_NO = C.LOCATION_NO)LOCATION_NAME,
               (SELECT COUNT(1) FROM MAT_ZC_M M WHERE M.JUDGE_STOVE_NO = C.JUDGE_STOVE_NO) STOVECOUNT,
               C.VSTEL,
               C.VSTEL_DESC,
               DECODE(T.DELVRY_ADDR,
                      'TPCO库房',
                      DECODE(T.AGENCY_FL,
                             '0',
                             DECODE((SELECT EXTRA_FLAG
                                      FROM SLM_ORDER_LINE_DELIVERY
                                     WHERE ORD_LN_DLY_PK = T.ORD_LN_DLY_PK),
                                    '0',
                                    '客户 付出库费',
                                    '1',
                                    DECODE(T.SALE_ORG_DESC,
                                           '国际贸易部',
                                           '国贸 付出库费',
                                           '销售 付出库费'),
                                    '客户 付出库费'),
                             DECODE(T.SALE_ORG_DESC,
                                    '国际贸易部',
                                    '国贸 付出库费',
                                    '销售 付出库费')),
                      '指定地点',
                      DECODE(T.SALE_ORG_DESC,
                             '国际贸易部',
                             '国贸 付出库费',
                             '销售 付出库费'),
                      'TPCO库房车板',
                      DECODE(T.SALE_ORG_DESC,
                             '国际贸易部',
                             '国贸 付出库费',
                             '销售 付出库费'),
                      DECODE(T.AGENCY_FL,
                             '0',
                             '客户 付出库费',
                             '1',
                             DECODE(T.SALE_ORG_DESC,
                                    '国际贸易部',
                                    '国贸 付出库费',
                                    '销售 付出库费'))) DELVRY_ADDR,
               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,
               S.STORAGE_ADDR_NO,
               --T.SEND_PLAN_NO,
               T.STATION_NM,
               T.SPCL_LN_NM,
               T.STATION_NO,
               T.SPCL_LN_NO,
               T.RECEIV_NO,
               T.RECEIV_NM,
               T.ORD_PK,
               T.ORD_LN_PK,
               T.ORD_LN_DLY_PK,
               T.SALE_ORG,
               T.SALE_ORG_DESC,
               T.CREDIT_NO,
               T.PORT_NO,
               T.PORT_DESC,
               T.SUPPLY_UNIT,
               T.SUPPLY_UNIT_DESC,
               C.MEMO,
               M.PIPMEMO MEMO1,
               DECODE(C.MOVE_LOAD_FLAG,'0','未进行','1','倒库出库','2','入库接收') AS MOVE_LOAD_FLAG,
               NVL(SUM(T.PLAN_WT), 0) AS ACT_WT,
               NVL(SUM(T.PLAN_TOTL_LEN), 0) AS ACT_TOTL_LEN,
               SUM(NVL(C.ACT_COUNT, 0)) AS ACT_COUNT,
               SUM(NVL(C.ACT_WEIGHT, 0)) AS ACT_WEIGHT,
               SUM(NVL(C.ACT_LEN, 0)) AS ACT_LEN,
               SUM(NVL(CASE
                     WHEN C.EDIT_FLAG = '0' THEN
                      C.ACT_COUNT
                     ELSE
                      0
                   END,0)) PLAN_COUNT,
               SUM(NVL(CASE
                     WHEN C.EDIT_FLAG = '0' THEN
                      C.ACT_WEIGHT
                     ELSE
                      0
                   END,0)) PLAN_WEIGHT,
               SUM(NVL(CASE
                     WHEN C.EDIT_FLAG = '0' THEN
                      C.ACT_LEN
                     ELSE
                      0
                   END,0)) PLAN_LEN,
               SUM(NVL(CASE
                     WHEN C.EDIT_FLAG = '1' THEN
                      C.ACT_COUNT
                     ELSE
                      0
                   END,0)) BEEN_COUNT,
               SUM(NVL(CASE
                     WHEN C.EDIT_FLAG = '1' THEN
                      C.ACT_WEIGHT
                     ELSE
                      0
                   END,0)) BEEN_WEIGHT,
               SUM(NVL(CASE
                     WHEN C.EDIT_FLAG = '1' THEN
                      C.ACT_LEN
                     ELSE
                      0
                   END,0)) BEEN_LEN,min(t.IS_OVERSTOCK) IS_OVERSTOCK
          FROM YDM_ZC_BILL_M T,YDM_ZC_BILL_C C,YDM_BS_STORAGE S,MAT_ZC_M M
           WHERE T.BILL_NO = C.BILL_NO(+)
           AND T.ORDER_NO || T.ORDER_SEQ = C.ORDER_NO || C.ORDER_SEQ
           --AND T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK(+)
           AND C.STORAGE_NO = S.STORAGE_NO(+)
           AND C.MAT_NO=M.MAT_NO(+)
           AND T.RETURN_FLAG='0'
           AND C.RETURN_FLAG='0'
           and c.validflag = '1'
           and t.validflag = '1'
		]]>
	</query>
	<query id="FrmTallYsheet.QueryTallyInfoMat" desc="查詢理货材料信息">
		<![CDATA[
	SELECT T.TALLYSHEET_NO,
       T.JUDGE_STOVE_NO,
       T.BATCH_NO,
       T.GROUP_NO,
        T.ORDER_NO||'/'||T.ORDER_SEQ AS ORDER_SEQ_NO,
       T.ORDER_NO,
       T.ORDER_SEQ,
       T.DELIVERY_NO,
       T.STOVE_NO,
       T.MATERIAL_NAME,
       T.PRODUCNAME,
       T.STD_NAME,
       T.GRADENAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.PROCESS_DESC,
       T.PLINE_NAME,
       T.ACT_DIMATER,
       T.ACT_HEIGHT,
       T.ACT_LEN_MIN,
       T.ACT_LEN_MAX,
       T.JUDGE_RESULT_CODE,
       T.CREATE_NAME,
       T.STORAGE_NO,
       T.MEMO,
       (SELECT S.STORAGE_NAME
          FROM YDM_BS_STORAGE S
         WHERE S.STORAGE_NO = T.STORAGE_NO) AS STORAGE_NAME,
       TO_CHAR(MAX(T.CREATE_TIME), 'YYYY-MM-DD HH24:MI:SS') AS CREATE_TIME,
       T.ORD_PK,
       T.ORD_LN_PK,
       T.ORD_LN_DLY_PK,
       T.VSTEL_DESC,
       NVL(SUM(T.ACT_COUNT), '0') AS ACT_COUNT,
       TO_CHAR(NVL(SUM(T.ACT_WEIGHT), '0'),'FM999999990.000') AS ACT_WEIGHT,
       TO_CHAR(NVL(SUM(T.ACT_LEN), '0'),'FM999999990.000') AS ACT_LEN,
       NVL(SUM(T.ACT_THEORY_WEIGHT), '0') AS ACT_THEORY_WEIGHT,
       NVl(SUM(CASE
                 WHEN T.LOADVEHICLE_FLAG = '1' THEN
                  T.ACT_COUNT
                 ELSE
                  0
               END),
           '0') AS BEEN_COUNT,
       TO_CHAR(NVl(SUM(CASE
                 WHEN T.LOADVEHICLE_FLAG = '1' THEN
                  T.ACT_WEIGHT
                 ELSE
                  0
               END),
           '0'),'FM999999990.000') AS BEEN_WEIGHT,
       TO_CHAR(NVl(SUM(CASE
                 WHEN T.LOADVEHICLE_FLAG = '1' THEN
                  T.ACT_LEN
                 ELSE
                  0
               END),
           '0'),'FM999999990.00') AS BEEN_LEN,
       NVl(SUM(CASE
                 WHEN T.LOADVEHICLE_FLAG = '0' THEN
                  T.ACT_COUNT
                 ELSE
                  0
               END),
           '0') AS PREP_COUNT,
       TO_CHAR(NVl(SUM(CASE
                 WHEN T.LOADVEHICLE_FLAG = '0' THEN
                  T.ACT_WEIGHT
                 ELSE
                  0
               END),
           '0'),'FM9999999990.000') AS PREP_WEIGHT,
       TO_CHAR(NVl(SUM(CASE
                 WHEN T.LOADVEHICLE_FLAG = '0' THEN
                  T.ACT_LEN
                 ELSE
                  0
               END),
           '0'),'FM999999990.00') AS PREP_LEN
  FROM YDM_ZC_TALLYSHEET_C T
         WHERE T.BILL_NO = ?
           AND T.TALLYSHEET_NO = ?
           AND T.VALIDFLAG = '1'        
		]]>
	</query>
	<query id="FrmTallYsheet.QueryTallyInfo" desc="查詢理货主信息">
		<![CDATA[
       SELECT  VEHICLE_NO FROM YDM_ZC_TALLYSHEET_T WHERE TALLYSHEET_NO=? ORDER BY VEHICLE_NO
		]]>
	</query>
	<query id="FrmTallYsheet.QueryAddSend" desc="查询要新增到理货主表的数据">
		<![CDATA[
	SELECT PLAN_TRANS_TYPE,
	       RECEIV_NO,
	       RECEIV_NM,
	       STATION_NO,
	       STATION_NM,
	       SPCL_LN_NO,
	       SPCL_LN_NM,
	       PORT_DESC,
	       VSTEL_CODE,
	       VSTEL_DESC,     
	       DELIVY_PLACE_CODE,
	       DELIVY_PLACE_NAME,
	       STLMT_UNIT_NO,
	       STLMT_UNIT_NM,
	       LOADVEHICLE_TYPE,
	       PRD_CLS
	  FROM YDM_ZC_BILL_M
	  WHERE BILL_NO = ?
	   AND order_no||order_seq = ?
		]]>
	</query>
	<query id="FrmTallYsheet.AddTallyInfo" desc="新增理货单主信息">
		<![CDATA[
    INSERT INTO YDM_ZC_TALLYSHEET_M (TALLYSHEET_SQE, BILL_NO, TALLYSHEET_NO, 
		ORDER_NO, ORDER_SEQ, ORDER_SEQ_NO, ACCBATCH_RECY, TRANS_TYPE, 
		RECEIV_NO, RECEIV_NM, STATION_NO, STATION_NM, SPCL_LN_NO, SPCL_LN_NM, PORT_NO, 
		VSTEL_CODE, VSTEL_DESC,
		DELIVY_PLACE_CODE, DELIVY_PLACE_NAME, STLMT_UNIT_NO, STLMT_UNIT_NM, 
		STORAGE_ATTR, STORAGE_ATTR_NAME, STORAGE_TYPE_NO, STORAGE_TYPE_NAME, 
		MANAGEMENT_NO, MANAGEMENT_NAME, CREATE_NAME,LOADVEHICLE_TYPE,ORD_PK,
		ORD_LN_PK,ORD_LN_DLY_PK,STACKING_WT,STACKING_PIECE, CREATE_TIME,LOAD_TIME,DEPARTMENT_CODE,DEPARTMENT_DESC,OUT_STOCK_CODE,STACKING_TOTL_LEN,
		PORT_DESC,CREDIT_NO,PRD_CLS) 
		VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
      	        ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?,?,TO_NUMBER(?),?,
      	        TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'), TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,TO_NUMBER(?),?,?,?)  
		]]>
	</query>
	<query id="FrmTallYsheet.AddTallyCar" desc="新增理货车辆信息">
		<![CDATA[
	  INSERT INTO YDM_ZC_TALLYSHEET_T
	  (TALLYSHEET_NO, VEHICLE_NO, CARRY_COMPANY_CODE, CARRY_COMPANY_NAME,ASK_DAY_NO,TRAIN_TYPE,BILL_NO,PREDICTION_NO)
	VALUES
	  (?, ?, ?, ?,?,?,?,?)
		]]>
	</query>
	<query id="FrmTallYsheet.QueryTallCar" desc="查询同一理货单下是否有相同车号">
		<![CDATA[
	SELECT T.TALLYSHEET_NO, T.VEHICLE_NO, T.CARRY_COMPANY_CODE, T.CARRY_COMPANY_NAME FROM YDM_ZC_TALLYSHEET_T T WHERE T.TALLYSHEET_NO=? AND T.VEHICLE_NO=?
		]]>
	</query>
	<query id="FrmTallYsheet.AddTallyMat" desc="新增理货单材料信息">
		<![CDATA[
  	 INSERT INTO YDM_ZC_TALLYSHEET_C (TALLYSHEET_SQE, BILL_NO, TALLYSHEET_NO, MAT_NO, 
		ORDER_NO, ORDER_SEQ, 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, STORAGE_ATTR, STORAGE_ATTR_NAME, STORAGE_TYPE_NO, 
		STORAGE_TYPE_NAME, MANAGEMENT_NO, MANAGEMENT_NAME, CREATE_NAME, CREATE_TIME,
		DELIVERY_NO,ORD_PK,ORD_LN_PK,ORD_LN_DLY_PK,SALE_ORG,SALE_ORG_DESC,VSTEL,
		VSTEL_DESC,SEND_NUM,ACT_FIX_NUM,ACT_FIX_LEN,FINISHPRO_MOLD,IN_MOLD,MEMO,IN_TYPE)
		VALUES 
		(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
		 ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),
		 ?, ?, ?, ?, ?, ?, ?, ?, ?, TO_DATE(?,'YYYY-MM-DD HH24:MI:SS'),?,?,?,?,
		 ?,?,?,?,TO_NUMBER(?),TO_NUMBER(?),TO_NUMBER(?),?,?,?,?)
		]]>
	</query>
	<query id="FrmTallYsheet.queryAmount" desc="查询库存剩余量">
	<![CDATA[
	SELECT NVL(SUM(T.ACT_COUNT),'0') AS ACT_COUNT
  FROM YDM_ZC_BILL_C T,MAT_ZC_M T1
 WHERE T.BILL_NO = ?
   AND T.MAT_NO=T1.MAT_NO
   AND T.JUDGE_STOVE_NO = ?
   AND NVL(T.BATCH_NO,'/') = NVl(?,'/')
   AND T.order_no||t.order_seq = ?
   AND T.STORAGE_NO=?
   AND T.GROUP_NO=?
   AND T.LOCATION_NO = ?
   AND NVL(T1.PIPMEMO,'/') = NVl(?,'/')
   AND T.EDIT_FLAG='0'
   AND T.VALIDFLAG='1'
		]]>
	</query>
	<query id="FrmTallYsheet.queryMatBillC" desc="查询订单材料表每支材料重量">
	<![CDATA[
	 SELECT NVL(SUM(T1.ACT_WEIGHT),'0') AS ACT_WEIGHT,NVL(SUM(T1.ACT_LEN),0) AS ACT_LEN
        FROM (SELECT T.MAT_NO, T.ACT_WEIGHT,T.ACT_LEN
                FROM YDM_ZC_BILL_C T
               WHERE T.BILL_NO = ?
                 AND T.JUDGE_STOVE_NO = ?
                 AND NVL(T.BATCH_NO,'/') = NVl(?,'/')
                 AND T.ORD_LN_DLY_PK = ?   
                 AND T.STORAGE_NO=? 
                 AND T.GROUP_NO=?
               ORDER BY T.MAT_NO ASC) T1
       WHERE ROWNUM <?
	]]>
	</query>
	<query id="FrmTallYsheet.queryBillType" desc="查询提单状态、提单类型">
	<![CDATA[
SELECT T.LOADVEHICLE_TYPE,
       T.BILL_STATUS, ISPRECLOSE
  FROM YDM_ZC_BILL_M T
 WHERE T.BILL_NO = ?
 GROUP BY T.LOADVEHICLE_TYPE,
       T.BILL_STATUS, ISPRECLOSE
	]]>
	</query>

	<query id="FrmTallYsheet.queryBillTypeXd" desc="按合同行查询是否虚单未理货">
		<![CDATA[
			SELECT
				T.BILL_NO
			FROM
				YDM_ZC_BILL_M T
				INNER JOIN YDM_ZC_BILL_C C ON T.BILL_NO = C.BILL_NO
			WHERE
				T.ORD_LN_PK = ?
				AND T.LOADVEHICLE_TYPE = '2'
				AND C.EDIT_FLAG = '0'
			GROUP BY
				T.BILL_NO
	]]>
	</query>

	<query id="FrmTallYsheet.queryTallMAT" desc="查询理货主表是否存在该数据">
	<![CDATA[
SELECT TALLYSHEET_SQE
  FROM YDM_ZC_TALLYSHEET_M T
 WHERE T.BILL_NO = ?
   AND T.TALLYSHEET_NO = ?
   AND T.order_no||t.order_seq = ?
   AND T.VALIDFLAG='1'
	]]>
	</query>
	<query id="FrmTallYsheet.doQueryAskDay" desc="查询日请车数据">
	<![CDATA[
 SELECT T.ASK_DAY_NO,
       T.ASK_MONTH_NO,
       T.ASK_DAY_PK,
       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.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,
       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.BILL_NO=?
 AND T.STATION_NO=?
 AND DECODE(T.SPCL_LN_NO,'','N',SPCL_LN_NO)=?
 AND T.RECEIV_NO=?
   AND T.VALIDFLAG = '1'
   AND T.APP_FLAG='1'
   AND NVL(T.BATCH_DAY_NUM,'0')!= NVL(T.ACT_DAY_NUM,'0')
	]]>
	</query>
	<query id="FrmTallYsheet.queryAskTallyT" desc="查询理货车辆信息车皮数">
	<![CDATA[
SELECT COUNT(1) AS BATCHDAY FROM YDM_ZC_TALLYSHEET_T T  WHERE  T.ASK_DAY_NO=? AND T.BILL_NO=?
	]]>
	</query>
	<query id="FrmTallYsheet.queryAskTallyTM" desc="查询理货车辆信息车皮数">
	<![CDATA[
SELECT ASK_DAY_NO,TRAIN_TYPE FROM YDM_ZC_TALLYSHEET_T T  WHERE  T.TALLYSHEET_NO=?
	]]>
	</query>
	<query id="FrmTallYsheet.updateBillC" desc="修改提单材料表理货状态">
	<![CDATA[
 UPDATE YDM_ZC_BILL_C SET EDIT_FLAG = '1' WHERE BILL_SQE IN ((SELECT T1.BILL_SQE
                      FROM (SELECT T.BILL_SQE
                              FROM YDM_ZC_BILL_C T,MAT_ZC_M T1
                             WHERE T.MAT_NO=T1.MAT_NO
                               AND T.BILL_NO = ?
                               AND T.JUDGE_STOVE_NO = ?
                               AND NVL(T.BATCH_NO,'/') = NVl(?,'/')
                               AND T.order_no||t.order_seq =?
                               AND T.STORAGE_NO = ?
                               AND T.GROUP_NO = ?
                               AND T.LOCATION_NO = ?
                               AND t.EDIT_FLAG = '0'
                               AND t.VALIDFLAG = '1'
                               AND NVL(T1.PIPMEMO,'/') = NVl(?,'/')
                             ORDER BY T.BILL_SQE ASC) T1
                     WHERE ROWNUM <?))
	]]>
	</query>
	<query id="FrmTallYsheet.updateTallM" desc="修改理货主表理货量">
	<![CDATA[
 UPDATE YDM_ZC_TALLYSHEET_M SET STACKING_WT =TO_NUMBER(NVL(STACKING_WT,'0'))+TO_NUMBER(?),
 STACKING_PIECE=TO_NUMBER(NVL(STACKING_PIECE,'0'))+TO_NUMBER(?),
 STACKING_TOTL_LEN=TO_NUMBER(NVL(STACKING_TOTL_LEN,'0'))+TO_NUMBER(?) 
  WHERE TALLYSHEET_SQE=?
  AND VALIDFLAG='1'
	]]>
	</query>
	<query id="FrmTallYsheet.updateBillM" desc="修改提单主表提单状态">
	<![CDATA[
 UPDATE YDM_ZC_BILL_M SET BILL_STATUS = '3'
 WHERE BILL_NO=? 
 AND VALIDFLAG='1'
	]]>
	</query>
	<query id="FrmTallYsheet.updateAskDay60" desc="修改日请车使用数">
	<![CDATA[
UPDATE YDM_ZC_ASK_DAY  SET ACT_DAY_NUM = TO_NUMBER('1')+TO_NUMBER(NVL(ACT_DAY_NUM,'0')),
 ACT_DAY_60NUM =TO_NUMBER('1')+TO_NUMBER(NVL(ACT_DAY_60NUM,'0')) 
  WHERE ASK_DAY_PK =?
	]]>
	</query>
	<query id="FrmTallYsheet.updateAskDay70" desc="修改日请车使用数">
	<![CDATA[
UPDATE YDM_ZC_ASK_DAY  SET ACT_DAY_NUM = TO_NUMBER('1')+TO_NUMBER(NVL(ACT_DAY_NUM,'0')),
 ACT_DAY_70NUM =TO_NUMBER('1')+TO_NUMBER(NVL(ACT_DAY_70NUM,'0')) 
  WHERE ASK_DAY_PK =?
	]]>
	</query>
	<query id="FrmTallYsheet.updateBillC1" desc="修改理货材料表理货状态">
	<![CDATA[
UPDATE YDM_ZC_BILL_C T SET T.EDIT_FLAG = '0'
                      WHERE MAT_NO IN
                            ((SELECT C.MAT_NO FROM YDM_ZC_TALLYSHEET_C C
                              WHERE C.BILL_NO =?
                                AND C.TALLYSHEET_NO =?
                                AND C.MAT_NO = T.MAT_NO))
	]]>
	</query>
	<query id="FrmTallYsheet.updateAskDay601" desc="修改日请车使用数">
	<![CDATA[
UPDATE YDM_ZC_ASK_DAY  SET ACT_DAY_NUM = TO_NUMBER(NVL(ACT_DAY_NUM,'0'))-TO_NUMBER('1'),
 ACT_DAY_60NUM =TO_NUMBER(NVL(ACT_DAY_60NUM,'0'))-TO_NUMBER('1')
  WHERE ASK_DAY_PK =?
	]]>
	</query>
	<query id="FrmTallYsheet.updateAskDay701" desc="修改日请车使用数">
	<![CDATA[
UPDATE YDM_ZC_ASK_DAY  SET ACT_DAY_NUM = TO_NUMBER(NVL(ACT_DAY_NUM,'0'))-TO_NUMBER('1'),
 ACT_DAY_70NUM =TO_NUMBER(NVL(ACT_DAY_70NUM,'0'))-TO_NUMBER('1') 
  WHERE ASK_DAY_PK =?
	]]>
	</query>
		<query id="FrmTallYsheet.queryTallType" desc="查询理货状态">
	<![CDATA[
SELECT MAX(T.BILL_NO) AS BILL_NO,MAX(T.LOADVEHICLE_FLAG) AS LOADVEHICLE_FLAG
  FROM YDM_ZC_TALLYSHEET_M T
 WHERE T.BILL_NO = ?
   AND T.TALLYSHEET_NO = ?
	]]>
	</query>
			<query id="FrmTallYsheet.updatePintFlag" desc="回写打印次数，打印时间">
	<![CDATA[
UPDATE YDM_ZC_TALLYSHEET_M T
   SET T.PRINT_NUM = TO_NUMBER(NVL(T.PRINT_NUM, 0)) +'1', T.PRINT_FLAG = TO_DATE(?,'YYYY-MM-DD HH24:MI:SS') WHERE T.TALLYSHEET_NO = ? AND T.BILL_NO = ?
	]]>
	</query>
</queryMap>