<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc="基础物料投入与产出">

	<query id="CoreOrderListInformation.queryOrderList" desc="查询基础物料">
		<![CDATA[
	   SELECT A.ORD_PK,
       MANAG_NO,
       ORDER_NO,
       CUSTM_ORDER_NO,
       REVW_RPT_NO,
       ORDER_TYP,
       ORDER_TYP_DESC,
       PROTCL_NO,
       CUSTOMER_NO,
       CUSTOMER_NM,
       MARKET_SYS,
       MARKET_SYS_DESC,
       ABRVITION,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = SUPPLY_UNIT) SUPPLY_UNIT,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = PRICE_FL) PRICE_FL,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = CURRENCY) CURRENCY,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = MNY_ASK_TYP) MNY_ASK_TYP,
       STLMT_UNIT_NO,
       STLMT_UNIT_NM,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = FST_DRAWEE_UNIT) FST_DRAWEE_UNIT,
       LEGAL_PSN,
       AGENT,
       ADDRESS,
       ZIP_CODE,
       BANK,
       ACCOUNT,
       TAX_ID,
       PHONE,
       FAX,
       ORDER_WGT,
       ORDER_MNY_TAX,
       ORDER_MNY_NTAX,
       MNY_ASK_DESC,
       SIGN_PERSON,
       TO_CHAR(SIGN_DATE,'YYYY-MM-DD') SIGN_DATE,
       SIGN_ADDRESS,
       ORDER_YEAR,
       ORDER_BDATE,
       ORDER_EDATE,
       ORDER_SCAN_NO,
       CUSTOMER_MODEL_FL,
       ORDER_MODEL_NO,
       ORDER_MODEL_DESC,
       SALE_ORG,
       SALE_ORG_DESC,
       SALE_AREA_NO,
       SALE_AREA_DESC,
       A.MEMO,
       BE_ORDER_STS,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = ORDER_STS) ORDER_STS,
       ORDER_STS_DESC,
       APPROVAL_MAN,
       APPROVAL_TIME,
       EFFECT_MAN,
       EFFECT_TIME,
       CLOSE_MAN,
       CLOSE_TIME,
       C.VALIDFLAG,
       B.CREATE_NAME,
       A.CREATE_DEPT,
       B.CREATE_TIME,
       B.UPDATE_NAME,
       B.UPDATE_TIME,
       C.DELETE_NAME,
       C.DELETE_TIME,
       ORD_PK_OLD,
       BE_ORDER_STS_DESC,
       PRICE_NO,
       A.ISLOCK,
       PRINT_PRICE,
       PRICE_PLAN,
       DECODE(CONTAIN_TAX,'1','含税','不含税') CONTAIN_TAX,
       DECODE(ORDER_ARCHIVE,'1','归档','未归档') ORDER_ARCHIVE,
       PASS_TIME,
       CONFIRM_TIME,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = TRADE_TYPE) TRADE_TYPE,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = ORDER_CLASSIFY) ORDER_CLASSIFY,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = BUSINESS_TYPE) BUSINESS_TYPE,
       C.ORD_LN_PK,
       ORDER_NO||'/'||ORDER_SEQ ORDER_SEQ,
       CUST_ALPHA_NO,
       PSC,
       PSC_DESC,
       MSC,
       MSC_DESC,
       MSC_STYLE,
       USE_CODE,
       USE_DESC,
       PRD_CLS,
       PRODUCCODE,
       PRODUCNAME,
       STD_CODE,
       STD_NAME,
       STEELCODE,
       STEELNAME,
       STD_STYLE,
       STD_STYLE_DESC,
       ORDER_SPEC_CODE,
       ORDER_SPEC_DESC,
       SPEC_CODE,
       SPEC_NAME,
       DIMATER,
       HEIGHT,
       MODEL_CODE,
       MODEL_DESC,
       LEN_NO,
       LEN_DESC,
       LEN_UNIT,
       LEN_MIN,
       LEN_MAX,
       SHRT_LEN_RATO,
       SHORTEST,
       LONG_LEN_RATO,
       LONGEST,
       SHRT_STOVE,
       AVG_LEN_MIN,
       DIFRNC_LEN_MAX,
       ENDLEN_SPECSTD,
       SIGL_LEN,
       C.ORDER_UNIT,
       ORDER_QTY,
       ORD_ENSU_TOTL_LEN,
       PRDCT_WGT,
       '(-' || TO_CHAR(B.DELVRY_RANGE_MIN) ||
                DECODE(B.DELVRY_RANGE_TPE, '%', '%', '') || ',' ||
                TO_CHAR(B.DELVRY_RANGE_MAX) ||
                DECODE(B.DELVRY_RANGE_TPE, '%', '%', '') || ')' DELVRY_RANGE_TPE,
       DELVRY_RANGE_MIN,
       DELVRY_RANGE_MAX,
       FINAL_USER,
       FINAL_USER_DESC,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = OUTS_BILLET_FL) OUTS_BILLET_FL,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = OUTS_STL_PIPE_FL) OUTS_STL_PIPE_FL,
       DECODE(ASSEL_FL,'1','是','否') ASSEL_FL,
       DECODE(PRODUCER_FL,'1','是','否') PRODUCER_FL,
       PRDCR_NO,
        (SELECT WM_CONCAT(C.BASENAME)
          FROM SLM_ORDER_LINE_PRDCR F, COM_BASE_INFO C
         WHERE C.BASECODE = F.PRDCR_DESC
           AND F.PRDCR_NO = B.PRDCR_NO) PRDCR_DESC,
       MPS_FL,
       MPS_NO,
       MPS_DESC,
       DELVRY_DESC,
       TRANS_DESC,
       ADD_ASK_NO,
       ORDER_ADD_DESC,
       ORDER_SPECIAL_FL,
       ORDER_SPECIAL_HEAD,
       ORDER_SPECIAL_PATH,
       ORDER_SPECIAL_DESC,
       ZBS,
       ORDER_PRICE,
       TRANS_PRICE,
       TEST_ID,
       TEST_PRICE,
       OUT_PRICE,
       BALNCE_PRICE,
       BE_ORDER_LN_STATUS,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = ORDER_LN_STATUS) ORDER_LN_STATUS,
       ORD_LN_PK_OLD,
       CUST_ALPHA_NO2,
       CHGE_ORD_LN_PK,
       DECODE(BALNCE_PRICE_STS,'1','确认','未确认') BALNCE_PRICE_STS,
       BALNCE_PRICE_ORG,
       BALNCE_PRICE_ORG_STS,
       PAK_PRICE,
       AW,
       ORD_LN_DLY_PK,
       DELIVERY_NO,
       C.DELVRY_BDATE,
       TO_CHAR(C.DELVRY_EDATE,'YYYY-MM-DD') DELVRY_EDATE,
       DELVRY_QTY,
       WGT_ESTMT,
       ENSU_TOTL_LEN,
       RECEIV_NO,
       RECEIV_NM,
       DELVRY_ADDR,
       DECODE(AGENCY_FL,'1','代办','无代办') AGENCY_FL,
       RECEIV_ADDR,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = TRANSIT_TYP) TRANSIT_TYP,
       TRANSIT_PLAN,
       TRANSIT_MNY,
       BE_DELIVERY_STATUS,
       (SELECT BASENAME FROM COM_BASE_INFO WHERE BASECODE = DELIVERY_STATUS) DELIVERY_STATUS,
       PICKUP_FLAG,
       
       (SELECT NVL(SUM(T.ORDER_QTY), 0)
                  FROM PLN_SALEORD T
                 WHERE T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK
                   AND T.PORDERSTATUS > '0') APP_NUM,
                                      
                   (SELECT NVL(SUM(T.PLAN_P_MAIN),0)                   
               FROM PLN_SALEORD_PROC T
              WHERE T.ORDER_SOURCE != '备料需求'
              AND  T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK)PSS_WGT,
              
                 (SELECT NVL(SUM(JK.ACT_COUNT),0)             
               FROM YDM_ZC_INLIST JK  WHERE  JK.INSTOCK_TYPE_CODE IN ('800701', '800706')
                   AND JK.PRODUCT_FLAG = '801403' AND JK.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK  AND JK.ORD_LN_PK = C.ORD_LN_PK ) PAY_NUM,
                (SELECT NVL(SUM(JK.ACT_WEIGHT),0)             
              FROM YDM_ZC_INLIST JK WHERE  JK.INSTOCK_TYPE_CODE IN ('800701', '800706')
                   AND JK.PRODUCT_FLAG = '801403' AND JK.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK AND JK.ORD_LN_PK = C.ORD_LN_PK ) PAY_WGT,

               (SELECT  NVL(SUM(T.ACT_COUNT), 0)
                  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS K
                 WHERE T.MAT_NO = K.MAT_NO
                   AND T.MAT_STATUS = '80150301'
                   AND T.PRODUCT_FLAG = '801403'
                   AND T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK ) INSTORAGE_NUM,
               (SELECT  NVL(SUM(T.ACT_WEIGHT), 0)
                  FROM MAT_ZC_M T, YDM_ZC_BUTTRESS K
                 WHERE T.MAT_NO = K.MAT_NO
                   AND T.MAT_STATUS = '80150301'
                   AND T.PRODUCT_FLAG = '801403'
                   AND T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK ) INSTORAGE_WGT,
           
                (SELECT NVL(SUM(FH.ACT_COUNT),0)            
              FROM YDM_ZC_LOADVEHICLE_MAT FH WHERE  FH.RETURN_FLAG = '0'
               AND FH.VALIDFLAG > '1' AND FH.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK ) OUT_NUM,              
                (SELECT 
                  NVL(SUM(CASE
                       WHEN FH.PONDER_NO IS NOT NULL THEN
                        NVL(FH.PONDER_GROSS_WT, 0)
                       ELSE
                        NVL(FH.ACT_WEIGHT, 0)
                     END),0)               
              FROM YDM_ZC_LOADVEHICLE_MAT FH WHERE  FH.RETURN_FLAG = '0'
               AND FH.VALIDFLAG > '1' AND FH.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK ) OUT_WGT, 

               (SELECT NVL(SUM(TD.ACT_COUNT),0) FROM YDM_ZC_BILL_C TD WHERE  TD.RETURN_FLAG = '0' AND TD.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK) SENDBILL_NUM,
               (SELECT NVL(SUM(TD.ACT_WEIGHT),0) FROM YDM_ZC_BILL_C TD WHERE  TD.RETURN_FLAG = '0' AND TD.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK) SENDBILL_WGT,

             
               (SELECT NVL(SUM(T.QUANTITY),0) FROM SLM_BALANCEINFO T WHERE  T.BALANCESTATUS = '3' AND T.REALINVOICENO IS NOT NULL AND T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK) ACCOUNT_NUM,
               (SELECT NVL(SUM(DECODE(NVL(T.SEND_NUM, 0), 0, T.WEIGHT, T.SEND_NUM)),0) FROM SLM_BALANCEINFO T WHERE  T.BALANCESTATUS = '3' AND T.REALINVOICENO IS NOT NULL AND T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK) ACCOUNT_WGT,
             
              
              (SELECT NVL(SUM(T.ACT_COUNT), 0)FROM MAT_ZC_TRACK T WHERE T.EVENT_ID = '900101' AND T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK) ELIM_NUM,
              (SELECT NVL(SUM(T.ACT_WEIGHT), 0)FROM MAT_ZC_TRACK T WHERE T.EVENT_ID = '900101' AND T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK) ELIM_WGT,

              
              (SELECT NVL(SUM(T.ACT_COUNT), 0)FROM MAT_ZC_TRACK T WHERE T.EVENT_ID = '900102' AND T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK) CHARGE_NUM,
              (SELECT NVL(SUM(T.ACT_WEIGHT), 0)FROM MAT_ZC_TRACK T WHERE T.EVENT_ID = '900102' AND T.ORD_LN_DLY_PK = C.ORD_LN_DLY_PK) CHARGE_WGT
  FROM SLM_ORDER_HEAD A,
       SLM_ORDER_LINE B
       LEFT JOIN SLM_ORDER_LINE_DELIVERY C
     ON C.ORD_LN_PK = B.ORD_LN_PK
     AND C.VALIDFLAG = '1'
  WHERE A.ORDER_NO LIKE '%'||?||'%'
  AND A.ORD_PK = B.ORD_PK
  AND A.VALIDFLAG = '1'
  AND B.VALIDFLAG = '1'
  
	   
		]]>
	</query>

	 
</queryMap>