<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="">
	<query id="CrmSlmOrderServer.Query" desc="crm合同信息查询">
		<![CDATA[
			 SELECT
				   T.ORD_PK,
				   T.ORD_LN_PK,
				   T.ORD_LN_DLY_PK,
				   T.ORDER_NO,
				   T.ORDER_SEQ,
				   T.DELIVERY_NO,
				   T.CUSTM_ORDER_NO,
				   T.ORDER_TYP,
				   T.ORDER_TYP_DESC,
				   T.REGION_NO,
				   T.REGION_NAME,
				   T.SALE_ORG,
				   T.SALE_ORG_DESC,
				   T.SALE_AREA_NO,
				   T.SALE_AREA_DESC,
				   T.CUSTOMER_NO,
				   T.CUSTOMER_NM,
				   T.RECEIV_NO,
				   T.RECEIV_NM,
				   T.PRICE_FL,
				   T.ORDER_QTY,
				   T.BALNCE_PRICE,
				   T.CURRENCY,
				   T.MNY_ASK_TYP,
				   DECODE(T.CONTAIN_TAX, '0', '否', '1', '是') CONTAIN_TAX,
				   T.ORDER_UNIT,
				   T.PRODUCCODE,
				   T.PRODUCNAME,
				   T.STD_CODE,
				   T.STD_NAME,
				   T.STEELCODE,
				   T.STEELNAME,
				   T.STD_STYLE,
				   T.STD_STYLE_DESC,
				   T.MODEL_CODE,
				   T.MODEL_DESC,
				   T.ORDER_SPEC_CODE,
				   T.ORDER_SPEC_DESC,
				   T.SPEC_CODE,
				   T.SPEC_NAME,
				   T.DIMATER,
				   T.HEIGHT,
				   T.LEN_NO,
				   T.LEN_DESC,
				   T.LEN_UNIT,
				   T.OUTS_BILLET_FL,
				   T.OUTS_STL_PIPE_FL,
				   T.MNY_ASK_DESC,
				   T.ISLOCK,
				   T.PRDCR_DESC,
				   T.MPS_DESC,
				   T.STLMT_UNIT_NO,
				   T.STLMT_UNIT_NM,
				   T.DELVRY_RANGE_TPE,
				   T.DELVRY_RANGE_MIN,
				   T.DELVRY_RANGE_MAX,
				   T.ADD_ASK_NO,
				   T.ORDER_ADD_DESC,
				   T.ORDER_SPECIAL_DESC,
				   T.ORDER_STS,
				   T.ORDER_STS_DESC,
				   T.ORDER_HEAD_STS,
				   T.ORDER_HEAD_STS_DESC,
				   T.SUPPLY_UNIT_CODE,
				   T.SUPPLY_UNIT,
				   T.WGT_ESTMT,
				   TO_CHAR(T.DELVRY_EDATE, 'YYYY-MM-DD HH24:MI:SS') DELVRY_EDATE,
				   TO_CHAR(T.EFFECT_TIME, 'YYYY-MM-DD HH24:MI:SS') EFFECT_TIME,
				   TO_CHAR(T.TIBAO_TIME, 'YYYY-MM-DD HH24:MI:SS') TIBAO_TIME,
				   DECODE(T.IS_FLAG, '0', '未同步', '1', '已同步', '2', 'crm数据问题', '3', '产销数据问题', '4', '数据过滤') IS_FLAG,
				   DECODE(T.DATA_STATUS, '0', '新增', '1', '修改', '2','删除') DATA_STATUS,
				   T.CRM_FLAG,
				   TO_CHAR(T.SYNCHRO_TIME, 'YYYY-MM-DD HH24:MI:SS') SYNCHRO_TIME,
				   T.ID,
				   TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
				   TO_CHAR(T.CREATE_TIMESTAMP, 'YYYY-MM-DD HH24:MI:SS.ff') CREATE_TIMESTAMP,
				   T.ORDER_LN_STS,
				   T.ORDER_LN_STS_DESC,
				   T.CREATE_NAME,
				   T.FST_DRAWEE_UNIT,
				   T.KEEP_TYPE,
				   DECODE(T.DATA_FLAG, '0', '合同头', '1', '合同行', '2','交货行') DATA_FLAG,
				   DECODE(T.BALNCE_PRICE_STS, '0', '录入', '1', '确认') BALNCE_PRICE_STS,
				   T.PROBLEM_MSG,
				  -- DECODE(T.PORDERSTATUS,'0','待接收','1','已接收','2','已下发','3','生产中','4','生产完成','5','缴库完成','6','发运完毕','7','结算完毕','8','合同关闭','','未提报') PORDERSTATUS,
				   BOM.MATERIAL_NO,BOM.MATERIAL_DESC
			 FROM CRM_SLM_ORDER T
			 LEFT JOIN (
				SELECT DISTINCT
					MAX( A1.MATERIAL_NO ) MATERIAL_NO,
					MAX( A1.MATERIAL_DESC ) MATERIAL_DESC,
					A3.ORD_LN_PK
				FROM
					SLM_ORD_DESIGN_BOM A1,
					SLM_ORD_LINE_BOM A2,
					SLM_ORD_DESIGN_MSC A3
				WHERE
					A3.VALIDFLAG = '1'
					AND A2.DESGIN_KEY = A3.DESGIN_KEY
					AND A1.BOM = A2.BOM
				GROUP BY
					A3.ORD_LN_PK
				) BOM
				ON BOM.ORD_LN_PK = T.ORD_LN_PK
			 WHERE
				1 = 1
		]]>
	</query>

	<query id="CrmSlmOrderServer.updateIsFlag" desc="修改crm同步状态">
		<![CDATA[
			UPDATE CRM_SLM_ORDER SET IS_FLAG = '0' WHERE ID = ?
		]]>
	</query>
</queryMap>