<?xml version="1.0" encoding="UTF-8"?>
<queryMap desc = "对基础信息实绩操作">
	<query id = "ComCalculation.queryAll" desc = "查询基础信息">
	<![CDATA[
  SELECT 
       T.YEAR_MONTH,
       T.WL_TS,
       T.WL_ST,
       T.WL_FG,
       T.WL_TS_COST,
       T.WL_ST_COST,
       T.WL_FG_COST,
       T.SUM_COST,
       TO_CHAR(T.CREATE_TIME, 'YYYY-MM-DD HH24:MI:SS') CREATE_TIME,
       T.MEMO,
       T.WEIGTH_S_T,
       T.WEIGTH_S_A,
       T.WEIGTH_S_B,
       T.WEIGTH_S_C,
       T.WEIGTH_S_D,
       T.WEIGTH_S_E,
       T.WEIGTH_S_F,
       T.WEIGTH_S_G,
       T.WEIGTH_S_H,
       T.WL_WG
 FROM COST_CALCULATION_GTL T
 WHERE 1=1
	]]>
	</query>
	<query id = "ComCalculation.queryA" desc = "查询基础信息">
	<![CDATA[
SELECT T.YEAR_MONTH,
       T.PRO_PLAN_ID,
       T.ORD_LN_PK,
       T.DESGIN_KEY,
       T.INDEX_SEQ,
       T.BOM,
       T.CRAFT_SEQ,
       T.A_IN_MATERIAL_NO,
       T.A_OUT_MATERIAL_NO,
       T.B_IN_MATERIAL_NO,
       T.B_OUT_MATERIAL_NO,
       T.C_IN_MATERIAL_NO,
       T.C_OUT_MATERIAL_NO,
       cpl.pline_name A_PLINE,
       cp.pline_name B_PLINE,
       cbp.pline_name C_PLINE,
       T.A_HR_CAPCTY,
       T.A_PRD_RATE,
       T.B_HR_CAPCTY,
       T.B_PRD_RATE,
       T.C_HR_CAPCTY,
       T.C_PRD_RATE,
       T.WEIGTH_S_T,
       T.WEIGTH_S_A,
       T.WEIGTH_S_B,
       T.WEIGTH_S_C,
       T.IN_WEIGTH_S,
       T.A_ZZCB_COST,
       T.A_FH_COST,
       T.A_ZBJGF_COST,
       T.B_ZBJGF_COST,
       T.C_ZBJGF_COST，
       T.A_ZCB_COST,
       T.B_ZCB_COST,
       T.C_ZCB_COST,
       T.B_ZZCB_COST,
       T.B_FH_COST,
       T.C_ZZCB_COST,
       T.C_FH_COST,
       t.a_in_material_desc,
       t.a_out_material_desc,
       t.b_in_material_desc,
       t.b_out_material_desc,
       t.c_in_material_desc,
       t.c_out_material_desc,
       T.PRODUCNAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.ORDER_NO,
       T.CUSTOMER_NM,
       T.SALE_ORG_DESC
  FROM COST_CALCULATION_A T
  left join com_base_pline cpl on cpl.pline_code=t.a_pline
  left join com_base_pline cp on cp.pline_code = t.b_pline
  left join com_base_pline cbp on cbp.pline_code = t.c_pline
 WHERE 1=1
	]]>
	</query>
	<query id = "ComCalculation.queryD" desc = "查询基础信息">
	<![CDATA[
 SELECT 
       T.YEAR_MONTH,
       T.PRO_PLAN_ID,
       T.D_IN_MATERIAL_NO,
       T.D_OUT_MATERIAL_NO,
       cpl.pline_name D_PLINE,
       T.D_HR_CAPCTY,
       T.D_PRD_RATE,
       T.WEIGTH_S_D,
       T.IN_WEIGTH_S,
       T.D_ZZCB_COST,
       T.D_FH_COST,
       T.D_ZBJGF_COST,
       T.D_ZCB_COST,
       T.ORD_LN_DLY_PK,
       T.OUTS_BILLET_FL,
       T.OUTS_STL_PIPE_FL,
       t.d_in_material_desc,
       t.d_out_material_desc,
       T.PRODUCNAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.ORDER_NO,
       T.CUSTOMER_NM,
       T.SALE_ORG_DESC
 FROM COST_CALCULATION_D T
 left join com_base_pline cpl on cpl.pline_code=t.D_PLINE
 WHERE 1=1
	]]>
	</query>
	<query id = "ComCalculation.queryE" desc = "查询基础信息">
	<![CDATA[
 SELECT 
       T.YEAR_MONTH,
       T.PRO_PLAN_ID,
       T.E_IN_MATERIAL_NO,
       T.E_OUT_MATERIAL_NO,
       cpl.pline_name E_PLINE,
       T.E_HR_CAPCTY,
       T.E_PRD_RATE,
       T.WEIGTH_S_E,
       T.E_ZZCB_COST,
       T.E_FH_COST,
       T.PRO_PLAN_ID_E,
       T.E_ZBJGF_COST,
       T.E_ZCB_COST,
       T.e_IN_WEIGTH_S,
       t.e_in_material_desc,
       t.e_out_material_desc,
       T.PRODUCNAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.ORDER_NO,
       T.CUSTOMER_NM,
       T.SALE_ORG_DESC
 FROM COST_CALCULATION_E T
 left join com_base_pline cpl on cpl.pline_code=t.E_PLINE
 WHERE 1=1
	]]>
	</query>
	<query id = "ComCalculation.queryF" desc = "查询基础信息">
	<![CDATA[
 SELECT 
       T.YEAR_MONTH,
       T.PRO_PLAN_ID,
       T.F_IN_MATERIAL_NO,
       T.F_OUT_MATERIAL_NO,
       cpl.pline_name F_PLINE,
       T.F_HR_CAPCTY,
       T.F_PRD_RATE,
       T.WEIGTH_S_F,
       T.F_ZZCB_COST,
       T.F_FH_COST,
       T.PRO_PLAN_ID_F,
       T.F_ZBJGF_COST,
       T.F_ZCB_COST,
       T.f_IN_WEIGTH_S,
       t.f_in_material_desc,
       t.f_out_material_desc,
       T.PRODUCNAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.ORDER_NO,
       T.CUSTOMER_NM,
       T.SALE_ORG_DESC
 FROM COST_CALCULATION_F T
 left join com_base_pline cpl on cpl.pline_code=t.F_PLINE
 WHERE 1=1
	]]>
	</query>
	<query id = "ComCalculation.queryG" desc = "查询基础信息">
	<![CDATA[
 SELECT 
       T.YEAR_MONTH,
       T.PRO_PLAN_ID,
       T.G_IN_MATERIAL_NO,
       T.G_OUT_MATERIAL_NO,
       cpl.pline_name G_PLINE,
       T.G_HR_CAPCTY,
       T.G_PRD_RATE,
       T.WEIGTH_S_G,
       T.G_ZZCB_COST,
       T.G_FH_COST,
       T.PRO_PLAN_ID_G,
       T.G_ZBJGF_COST,
       T.G_ZCB_COST,
       T.G_IN_WEIGTH_S,
       t.g_in_material_desc,
       t.g_out_material_desc,
       T.PRODUCNAME,
       T.STEELNAME,
       T.STD_STYLE_DESC,
       T.SPEC_NAME,
       T.MODEL_DESC,
       T.ORDER_NO,
       T.CUSTOMER_NM,
       T.SALE_ORG_DESC
 FROM COST_CALCULATION_G T
 left join com_base_pline cpl on cpl.pline_code=t.g_pline
 WHERE 1=1
	]]>
	</query>
	<query id = "ComCalculation.queryERR" desc = "查询基础信息">
	<![CDATA[
 SELECT 
       TO_CHAR(T.ERROR_TIME, 'YYYY-MM-DD HH24:MI:SS') ERROR_TIME,
       T.ERROR_TEXT,
       T.ERROR_FROM
 FROM COST_CALCULATION_ERROR T
 WHERE 1=1
	]]>
	</query>
	<query id = "ComCalculation.querypliao" desc = "查询物料信息">
	<![CDATA[
SELECT T.BASECODE,T.BASENAME
FROM COM_BASE_INFO T 
WHERE T.VALIDFLAG='1'
	]]>
	</query>
	
	<query id = "ComCalculation.querycount" desc = "查询物料信息">
	<![CDATA[
SELECT V.*, ROUND(V.ZCB_COST / V.WEIGTH_S, 3) DD_PRICE
  FROM (SELECT T.PRO_PLAN_ID,
               T.SALE_ORG_DESC,
               T.CUSTOMER_NM,
               T.ORDER_NO,
               T.PRODUCNAME,
               T.STD_STYLE_DESC,
               T.STEELNAME,
               T.SPEC_NAME,
               T.MODEL_DESC,
               (CASE
                 WHEN ((SELECT COUNT(*)
                          FROM COST_CALCULATION_G
                         WHERE PRO_PLAN_ID = T.PRO_PLAN_ID) > 0) THEN
                  (SELECT SUM(G_ZCB_COST)
                     FROM COST_CALCULATION_G
                    WHERE PRO_PLAN_ID = T.PRO_PLAN_ID)
                 ELSE
                  (CASE
                    WHEN ((SELECT COUNT(*)
                             FROM COST_CALCULATION_F
                            WHERE PRO_PLAN_ID = T.PRO_PLAN_ID) > 0) THEN
                     (SELECT SUM(F_ZCB_COST)
                        FROM COST_CALCULATION_F
                       WHERE PRO_PLAN_ID = T.PRO_PLAN_ID)
                    ELSE
                     (CASE
                       WHEN ((SELECT COUNT(*)
                                FROM COST_CALCULATION_E
                               WHERE PRO_PLAN_ID = T.PRO_PLAN_ID) > 0) THEN
                        (SELECT SUM(E_ZCB_COST)
                           FROM COST_CALCULATION_E
                          WHERE PRO_PLAN_ID = T.PRO_PLAN_ID)
                       ELSE
                        (SELECT SUM(D_ZCB_COST)
                           FROM COST_CALCULATION_D
                          WHERE PRO_PLAN_ID = T.PRO_PLAN_ID)
                     END)
                  END)
               END) ZCB_COST,
               
               (CASE
                 WHEN ((SELECT COUNT(*)
                          FROM COST_CALCULATION_G
                         WHERE PRO_PLAN_ID = T.PRO_PLAN_ID) > 0) THEN
                  (SELECT SUM(WEIGTH_S_G)
                     FROM COST_CALCULATION_G
                    WHERE PRO_PLAN_ID = T.PRO_PLAN_ID)
                 ELSE
                  (CASE
                    WHEN ((SELECT COUNT(*)
                             FROM COST_CALCULATION_F
                            WHERE PRO_PLAN_ID = T.PRO_PLAN_ID) > 0) THEN
                     (SELECT SUM(WEIGTH_S_F)
                        FROM COST_CALCULATION_F
                       WHERE PRO_PLAN_ID = T.PRO_PLAN_ID)
                    ELSE
                     (CASE
                       WHEN ((SELECT COUNT(*)
                                FROM COST_CALCULATION_E
                               WHERE PRO_PLAN_ID = T.PRO_PLAN_ID) > 0) THEN
                        (SELECT SUM(WEIGTH_S_E)
                           FROM COST_CALCULATION_E
                          WHERE PRO_PLAN_ID = T.PRO_PLAN_ID)
                       ELSE
                        (SELECT SUM(WEIGTH_S_D)
                           FROM COST_CALCULATION_D
                          WHERE PRO_PLAN_ID = T.PRO_PLAN_ID)
                     END)
                  END)
               END) WEIGTH_S
          FROM COST_CALCULATION_D T
         WHERE T.YEAR_MONTH = {0}
         GROUP BY T.PRO_PLAN_ID,
                  T.SALE_ORG_DESC,
                  T.CUSTOMER_NM,
                  T.ORDER_NO,
                  T.PRODUCNAME,
                  T.STD_STYLE_DESC,
                  T.STEELNAME,
                  T.SPEC_NAME,
                  T.MODEL_DESC) V
	]]>
	</query>
</queryMap>
