<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="权限功能表查询">
	<query id="CoreProWell.bindCmbProcess" desc="查询">
		<![CDATA[
			SELECT T.PROCESS_CODE, T.PROCESS_DESC
			  FROM COM_BASE_PROCESS T
			 WHERE T.VALIDFLAG = '1'
			 ORDER BY PROCESS_CODE
		]]>
	</query>
	
	<query id="CoreProWell.doQuery" desc="查询">
		<![CDATA[
			SELECT A.WELL_CODE,
			       A.WELL_NAME,
			       SUM(CASE
			             WHEN A.SALE_ORG = '100102' THEN
			              A.USE_WGT
			             ELSE
			              0
			           END) 国际贸易部,
			       SUM(CASE
			             WHEN A.SALE_ORG = '100101' THEN
			              A.USE_WGT
			             ELSE
			              0
			           END) 国内贸易部,
			       SUM(CASE
			             WHEN A.SALE_ORG = '100103' THEN
			              A.USE_WGT
			             ELSE
			              0
			           END) 钢贸公司,
			       ((SELECT MONTH_#MONTH#
			           FROM COM_BASE_WELL_MONTH C
			          WHERE YEAR = '#YEAR#'
			            AND C.WELL_CODE = A.WELL_CODE) - (CASE
			         WHEN SUM(A.USE_WGT) > 0 THEN
			          SUM(A.USE_WGT)
			         ELSE
			          0
			       END)) 剩余量
			  FROM SLM_WELL_USE_LIST A, COM_BASE_WELL B
			 WHERE A.WELL_CODE = B.WELL_CODE
			   AND A.WELL_YEAR = '#YEAR#'
			   AND A.USE_MONTH = '#MONTH#'
			   AND B.PROCESS_CDOE LIKE '%#PROCESS_CODE#%'
			   AND B.VALIDFLAG = '1'
			 GROUP BY A.WELL_CODE, A.WELL_NAME
		]]>
	</query>
	
	<query id="CoreProWell.GetWellDelivery" desc="查询">
		<![CDATA[
			SELECT A.WELL_CODE,
			       A.WELL_NAME,
			       B.ORDER_NO,
			       C.ORDER_SEQ,
			       D.DELIVERY_NO,
			       D.ORD_LN_DLY_PK,
			       B.ORD_PK,
			       C.ORD_LN_PK,
			       (CASE
			         WHEN A.SALE_ORG = '100101' THEN
			          '国内贸易部'
			         WHEN A.SALE_ORG = '100102' THEN
			          '国际贸易部'
			         ELSE
			          '钢贸公司'
			       END) SALE_ORG,
			       C.PSC_DESC,
			       C.ORDER_SPEC_DESC,
			       C.MODEL_DESC,
			       A.USE_WGT
			  FROM SLM_WELL_USE_LIST       A,
			       SLM_ORDER_HEAD          B,
			       SLM_ORDER_LINE          C,
			       SLM_ORDER_LINE_DELIVERY D
			 WHERE A.ORD_LN_DLY_PK = D.ORD_LN_DLY_PK
			   AND D.ORD_LN_PK = C.ORD_LN_PK
			   AND D.ORD_PK = B.ORD_PK
			   AND A.WELL_YEAR = ?
			   AND A.USE_MONTH = ?
			   AND A.WELL_CODE = ?
		]]>
	</query>
	
	
</queryMap>