Browse Source

본부별 공사대장 SQL 수정

SBK 1 year ago
parent
commit
6416f85ee9
1 changed files with 29 additions and 45 deletions
  1. 29 45
      src/main/resources/sqlmap/mappers/co/co0103/CO01030001UMapper.xml

+ 29 - 45
src/main/resources/sqlmap/mappers/co/co0103/CO01030001UMapper.xml

@@ -34,7 +34,11 @@
 		     , TRUNC(NVL(A.SALE_AMT,0) / #{unit}, 0) SALE_AMT --G.매출액[ A*D ](VAT제외)
 		     , TRUNC(NVL(A.SALE_PROF_AMT,0) / #{unit}, 0) SALE_PROF_AMT --H.매출총이익[ G-F ]
 		     , TRUNC(NVL(G.COMPL_AMT_PLAN,0) * (A.ORCO_DVD_RT / 100) / #{unit}, 0) COMPL_AMT_PLAN --준공예정원가
-		     , ((NVL(G.COMPL_AMT_PLAN,0) * (A.ORCO_DVD_RT / 100)) / NVL(A.ORCO_CONT_AMT,0)) * 100 COMPL_AMT_PLAN_RT --준공예정원가율
+		     , CASE WHEN NVL(G.COMPL_AMT_PLAN,0) = 0 THEN 0
+		            WHEN A.ORCO_DVD_RT = 0 THEN 0
+		            WHEN NVL(A.ORCO_CONT_AMT,0) = 0 THEN 0
+		            ELSE ((NVL(G.COMPL_AMT_PLAN,0) * (A.ORCO_DVD_RT / 100)) / NVL(A.ORCO_CONT_AMT,0)) * 100
+		        END COMPL_AMT_PLAN_RT --준공예정원가율
 		     , CASE WHEN TRUNC((NVL(A.SALE_AMT,0) - NVL(B.PYRQ_NAS_AMT,0)) / #{unit}, 0) <![CDATA[>]]> 0 THEN TRUNC((NVL(A.SALE_AMT,0) - NVL(B.PYRQ_NAS_AMT,0)) / #{unit}, 0)
 		            WHEN TRUNC((NVL(A.SALE_AMT,0) - NVL(B.PYRQ_NAS_AMT,0)) / #{unit}, 0) <![CDATA[<]]> 0 THEN 0
 		            ELSE 0
@@ -43,8 +47,8 @@
 		     , TRUNC(NVL(B.PYRQ_AMT,0) / #{unit}, 0) PYRQ_AMT --K.기성청구액누계(VAT포함)
 		     , TRUNC(NVL(C.CTMN_AMT,0) / #{unit}, 0) CTMN_AMT --L.수금액누계(VAT포함)
 		     , TRUNC((NVL(B.PYRQ_NAS_AMT,0) - NVL(A.COST_TOT_NAS_AMT,0)) / #{unit}, 0) PYRQ_COSTNAS_AMT--M.투입원가대비청구액[ J-E ](VAT제외)
-		     , TRUNC(NVL(D.NON_CTMN_AMT_N,0) / #{unit}, 0) NOT_ADVENT_CTMN_AMT--N.기성미수금(미도래)[ K-L ](VAT포함)
-		     , TRUNC(NVL(D.NON_CTMN_AMT_Y,0) / #{unit}, 0) ADVENT_CTMN_AMT --O.기성미수금(도래)[ K-L ](VAT포함)
+		     , TRUNC(NVL(D.MIDORE,0) / #{unit}, 0) NOT_ADVENT_CTMN_AMT--N.기성미수금(미도래)[ K-L ](VAT포함)
+		     , TRUNC(NVL(D.DORE,0) / #{unit}, 0) ADVENT_CTMN_AMT --O.기성미수금(도래)[ K-L ](VAT포함)
 		     , NVL(C.CTMN_AMT / B.PYRQ_AMT * 100,0) CTMN_RT--수금율[ L/K ]
 		     , A.PYRQ_CNDT --청구조건
 		     , A.CTMN_CNDT --수금조건
@@ -70,49 +74,29 @@
 					  FROM CON_PJT_CTMN 
 					 GROUP BY CMPN_CD, STD_YM, CC_CD
 				) C ON C.CMPN_CD = A.CMPN_CD AND C.STD_YM = A.STD_YM AND C.CC_CD = A.CC_CD
-		  LEFT JOIN 
+		  LEFT JOIN  
 		  		(
-	  				SELECT CMPN_CD
-						 , STD_YM
-						 , CC_CD
-						 , SUM(NON_CTMN_AMT_N) AS NON_CTMN_AMT_N
-						 , SUM(NON_CTMN_AMT_Y) AS NON_CTMN_AMT_Y
-					  FROM	(
-								SELECT A.CMPN_CD
-									 , A.STD_YM
-									 , A.CC_CD
-									 , CASE WHEN NVL(A.PYRQ_AMT,0) - SUM(NVL(B.CTMN_AMT,0))  <![CDATA[<>]]>  0 AND A.CTMN_EXP_DT  <![CDATA[>]]>  TO_CHAR(SYSDATE,'YYYYMMDD') THEN NVL(A.PYRQ_AMT,0) - SUM(NVL(B.CTMN_AMT,0)) 
-								       	    ELSE 0  
-								       END AS NON_CTMN_AMT_N
-									 , CASE WHEN NVL(A.PYRQ_AMT,0) - SUM(NVL(B.CTMN_AMT,0))  <![CDATA[<>]]>  0 AND A.CTMN_EXP_DT  <![CDATA[<]]>  TO_CHAR(SYSDATE,'YYYYMMDD') THEN NVL(A.PYRQ_AMT,0) - SUM(NVL(B.CTMN_AMT,0))
-								            ELSE 0
-								       END AS NON_CTMN_AMT_Y
-								  FROM	(
-								      		SELECT CMPN_CD
-								                 , STD_YM
-								                 , CC_CD
-								                 , DOCU_NO
-								                 , PYRQ_DT
-								                 , CTMN_EXP_DT
-								                 , SUM(NVL(PYRQ_NAS_AMT,0)) PYRQ_NAS_AMT
-								                 , SUM(NVL(PYRQ_AMT,0)) PYRQ_AMT
-								              FROM CON_PJT_PYRQ
-								             GROUP BY CMPN_CD, STD_YM, CC_CD, DOCU_NO, PYRQ_DT, CTMN_EXP_DT
-										) A
-								  LEFT JOIN 
-								  		(
-								      		SELECT CMPN_CD
-								                 , STD_YM
-								                 , CC_CD
-								                 , DOCU_NO
-								                 , SUM(NVL(CTMN_AMT,0)) CTMN_AMT
-								              FROM CON_PJT_CTMN
-								             GROUP BY CMPN_CD, STD_YM, CC_CD, DOCU_NO
-										) B ON B.CMPN_CD = A.CMPN_CD AND B.STD_YM = A.STD_YM AND B.CC_CD = A.CC_CD AND B.DOCU_NO = A.DOCU_NO
-								 GROUP BY A.CMPN_CD, A.STD_YM, A.CC_CD, A.DOCU_NO, A.CTMN_EXP_DT, A.PYRQ_AMT
-							)
-					 GROUP BY CMPN_CD, STD_YM, CC_CD
-	  			) D ON D.CMPN_CD = A.CMPN_CD AND D.STD_YM = A.STD_YM AND D.CC_CD = A.CC_CD
+		  			SELECT CMPN_CD, CCGRP_CD, CC_CD, SUM(DORE) DORE , SUM(MIDORE) MIDORE
+					  FROM 	(
+					  			SELECT CMPN_CD, STD_YM, CCGRP_CD, CC_CD, PYRQ_DGR_CN
+								     , CASE WHEN CTMN_EXP_DT  <![CDATA[<]]>  TO_CHAR(SYSDATE,'YYYYMMDD') THEN NVL(PYRQ_AMT,0) - NVL(SUM(CTMN_AMT),0) ELSE 0 END AS DORE
+									 , CASE WHEN CTMN_EXP_DT  <![CDATA[>]]>  TO_CHAR(SYSDATE,'YYYYMMDD') THEN NVL(PYRQ_AMT,0) - NVL(SUM(CTMN_AMT),0) ELSE 0 END AS MIDORE
+								  FROM 	(
+								  			SELECT DISTINCT A.CMPN_CD , A.STD_YM , A.CCGRP_CD, A.CC_CD, B.DOCU_NO, B.PYRQ_DGR_CN 
+												 , TO_CHAR(TO_DATE(B.PYRQ_DT,'YYYY-MM-DD'),'YYYY-MM-DD') PYRQ_DT
+												 , B.CTMN_EXP_DT
+												 , NVL(B.PYRQ_AMT,0) PYRQ_AMT
+												 , NVL(C.CTMN_AMT,0) CTMN_AMT
+											  FROM CON_PJT_MST A
+											  LEFT JOIN CON_PJT_PYRQ B ON B.CMPN_CD = A.CMPN_CD AND B.STD_YM = A.STD_YM AND B.CC_CD = A.CC_CD AND SUBSTR(B.PYRQ_DT,0,6) = B.STD_YM
+											  LEFT JOIN CON_PJT_CTMN C ON C.CMPN_CD = B.CMPN_CD AND C.CC_CD = B.CC_CD AND C.DOCU_NO = B.DOCU_NO 
+											 WHERE A.CMPN_CD =  #{cmpnCd}
+											   AND A.STD_YM <![CDATA[<=]]> #{stdYm}
+								  		)
+								 GROUP BY CMPN_CD, STD_YM, CCGRP_CD, CC_CD, PYRQ_DGR_CN, PYRQ_AMT, CTMN_EXP_DT
+					  		)
+					 GROUP BY CMPN_CD, CCGRP_CD, CC_CD
+		  		) D ON D.CMPN_CD = A.CMPN_CD AND D.CCGRP_CD = A.CCGRP_CD AND D.CC_CD = A.CC_CD
 		  LEFT JOIN CON_PJT_RESN F ON F.CMPN_CD = A.CMPN_CD AND F.STD_YM = A.STD_YM AND F.CC_CD = A.CC_CD
 		  LEFT JOIN 
 		  		(