Browse Source

프로젝트공사대장 / 미청구/미수금 현황 SQL 수정

SBK 1 year ago
parent
commit
e82776bf0c

+ 5 - 5
src/main/resources/sqlmap/mappers/co/co0104/CO01040001UMapper.xml

@@ -51,7 +51,7 @@
 								  FROM CON_PJT_MST A
 								  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_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
 								 WHERE A.CMPN_CD = #{cmpnCd}
 								 WHERE A.CMPN_CD = #{cmpnCd}
-								   AND A.STD_YM <![CDATA[<=]]> #{stdYm}
+								   AND A.STD_YM <![CDATA[<]]>= #{stdYm}
 								   AND A.CC_CD LIKE #{ccCd}
 								   AND A.CC_CD LIKE #{ccCd}
 								 GROUP BY A.CMPN_CD , A.STD_YM , A.CCGRP_CD, A.CC_CD, A.SALE_AMT, A.PYRQ_CNDT, A.CTMN_CNDT
 								 GROUP BY A.CMPN_CD , A.STD_YM , A.CCGRP_CD, A.CC_CD, A.SALE_AMT, A.PYRQ_CNDT, A.CTMN_CNDT
 					  		)
 					  		)
@@ -71,7 +71,7 @@
 						 , TO_CHAR(TO_DATE(B.CTMN_EXP_DT,'YYYY-MM-DD'),'YYYY-MM-DD') CTMN_EXP_DT
 						 , TO_CHAR(TO_DATE(B.CTMN_EXP_DT,'YYYY-MM-DD'),'YYYY-MM-DD') CTMN_EXP_DT
 					  FROM CON_PJT_MST A
 					  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_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.STD_YM = #{stdYm} AND C.CC_CD = B.CC_CD AND C.DOCU_NO = B.DOCU_NO 
+					  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}
 					 WHERE A.CMPN_CD = #{cmpnCd}
 					   AND A.STD_YM <![CDATA[<=]]> #{stdYm}
 					   AND A.STD_YM <![CDATA[<=]]> #{stdYm}
 					   AND A.CC_CD LIKE #{ccCd}
 					   AND A.CC_CD LIKE #{ccCd}
@@ -91,7 +91,7 @@
 												 , NVL(C.CTMN_AMT,0) CTMN_AMT
 												 , NVL(C.CTMN_AMT,0) CTMN_AMT
 											  FROM CON_PJT_MST A
 											  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_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.STD_YM = #{stdYm} AND C.CC_CD = B.CC_CD AND C.DOCU_NO = B.DOCU_NO 
+											  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}
 											 WHERE A.CMPN_CD = #{cmpnCd}
 											   AND A.STD_YM <![CDATA[<=]]> #{stdYm}
 											   AND A.STD_YM <![CDATA[<=]]> #{stdYm}
 											   AND A.CC_CD LIKE #{ccCd}
 											   AND A.CC_CD LIKE #{ccCd}
@@ -108,7 +108,7 @@
 						 , A.CC_CD
 						 , A.CC_CD
 						 , SUM(B.PYRQ_AMT) OVER (ORDER BY A.STD_YM) AS PYRQ_AMT_SUM
 						 , SUM(B.PYRQ_AMT) OVER (ORDER BY A.STD_YM) AS PYRQ_AMT_SUM
 					  FROM CON_PJT_MST A
 					  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) = A.STD_YM
+					  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
 					 WHERE A.CMPN_CD = #{cmpnCd}
 					 WHERE A.CMPN_CD = #{cmpnCd}
 					   AND A.STD_YM <![CDATA[<=]]> #{stdYm}
 					   AND A.STD_YM <![CDATA[<=]]> #{stdYm}
 					   AND A.CC_CD LIKE #{ccCd}
 					   AND A.CC_CD LIKE #{ccCd}
@@ -128,7 +128,7 @@
 												 , NVL(C.CTMN_AMT,0) CTMN_AMT
 												 , NVL(C.CTMN_AMT,0) CTMN_AMT
 											  FROM CON_PJT_MST A
 											  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_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.STD_YM = #{stdYm} AND C.CC_CD = B.CC_CD AND C.DOCU_NO = B.DOCU_NO 
+											  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}
 											 WHERE A.CMPN_CD = #{cmpnCd}
 											   AND A.STD_YM <![CDATA[<=]]> #{stdYm}
 											   AND A.STD_YM <![CDATA[<=]]> #{stdYm}
 											   AND A.CC_CD LIKE #{ccCd}
 											   AND A.CC_CD LIKE #{ccCd}

+ 29 - 64
src/main/resources/sqlmap/mappers/co/co0105/CO01050001UMapper.xml

@@ -14,14 +14,14 @@
 					     , A.CC_NM --PJT명
 					     , A.CC_NM --PJT명
 					     , A.ORDER_NM --발주처
 					     , A.ORDER_NM --발주처
 					     , TO_CHAR(TO_DATE(A.PRJT_START_DT,'YYYY/MM/DD'),'YYYY/MM/DD') || '~' || TO_CHAR(TO_DATE(A.PRJT_END_DT,'YYYY/MM/DD'),'YYYY/MM/DD') PRJT_DT --공사기간
 					     , TO_CHAR(TO_DATE(A.PRJT_START_DT,'YYYY/MM/DD'),'YYYY/MM/DD') || '~' || TO_CHAR(TO_DATE(A.PRJT_END_DT,'YYYY/MM/DD'),'YYYY/MM/DD') PRJT_DT --공사기간
-					     , F.COMPL_CD --준공여부코드
-					     , F.COMPL_NM --준공여부
+					     , E.COMPL_CD --준공여부코드
+					     , E.COMPL_NM --준공여부
 					     , TRUNC(NVL(B.PYRQ_AMT,0) / #{unit1}, 0) AMT --청구금액
 					     , TRUNC(NVL(B.PYRQ_AMT,0) / #{unit1}, 0) AMT --청구금액
-					     , TRUNC(NVL(E.CTMN_AMT,0) / #{unit1}, 0) ADVENT_AMT_Y --미수금(도래)
-					     , TRUNC(NVL(D.CTMN_AMT,0) / #{unit1}, 0) ADVENT_AMT_N --미수금(미도래)
-			     		 , TRUNC((NVL(D.CTMN_AMT,0) + NVL(E.CTMN_AMT,0)) / #{unit1}, 0) NON_AMT --미수금
-					     , F.RCAMT_RSN --미수금사유
-					     , F.RCAMT_MEASR --미수금 대책방안
+					     , TRUNC(NVL(D.DORE,0) / #{unit1}, 0) ADVENT_AMT_Y --미수금(도래)
+					     , TRUNC(NVL(D.MIDORE,0) / #{unit1}, 0) ADVENT_AMT_N --미수금(미도래)
+			     		 , TRUNC((NVL(D.DORE,0) + NVL(D.MIDORE,0)) / #{unit1}, 0) NON_AMT --미수금
+					     , E.RCAMT_RSN --미수금사유
+					     , E.RCAMT_MEASR --미수금 대책방안
 					  FROM CON_PJT_MST A
 					  FROM CON_PJT_MST A
 					  LEFT JOIN	
 					  LEFT JOIN	
 					  		(
 					  		(
@@ -41,65 +41,30 @@
 								  FROM CON_PJT_CTMN 
 								  FROM CON_PJT_CTMN 
 								 GROUP BY CMPN_CD, STD_YM, CC_CD
 								 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
 							) 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(NVL(NON_CTMN_AMT,0)) CTMN_AMT
-								  FROM 	(
-								  			SELECT A.CMPN_CD
-											     , A.STD_YM
-											     , A.CC_CD
-											     , NVL(A.PYRQ_AMT,0) - SUM(NVL(B.CTMN_AMT,0)) AS NON_CTMN_AMT
-											     , 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 'Y' ELSE 'N' END AS ADVENT
-											  FROM 	(
-											  			SELECT CMPN_CD
-														     , STD_YM
-														     , CC_CD
-														     , DOCU_NO
-														     , PYRQ_DT
-														     , CTMN_EXP_DT
-														     , 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 CON_PJT_CTMN 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
-								  		)
-								 WHERE ADVENT = 'N'
-								 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
-					  LEFT JOIN 
-					  		(
-				  				SELECT CMPN_CD
-								     , STD_YM
-								     , CC_CD
-								     , SUM(NVL(NON_CTMN_AMT,0)) CTMN_AMT
+					  			SELECT CMPN_CD, CCGRP_CD, CC_CD, SUM(DORE) DORE , SUM(MIDORE) MIDORE
 								  FROM 	(
 								  FROM 	(
-								  			SELECT A.CMPN_CD
-											     , A.STD_YM
-											     , A.CC_CD
-											     , NVL(A.PYRQ_AMT,0) - SUM(NVL(B.CTMN_AMT,0)) AS NON_CTMN_AMT
-											     , 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 'Y' ELSE 'N' END AS ADVENT
+								  			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 	(
 											  FROM 	(
-											  			SELECT CMPN_CD
-														     , STD_YM
-														     , CC_CD
-														     , DOCU_NO
-														     , PYRQ_DT
-														     , CTMN_EXP_DT
-														     , 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 CON_PJT_CTMN 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
+											  			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
 								  		)
 								  		)
-								 WHERE ADVENT = 'Y'
-								 GROUP BY CMPN_CD, STD_YM, CC_CD
-				  			) E ON E.CMPN_CD = A.CMPN_CD AND E.STD_YM = A.STD_YM AND E.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
+								 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 E ON E.CMPN_CD = A.CMPN_CD AND E.STD_YM = A.STD_YM AND E.CC_CD = A.CC_CD
 					  JOIN 	(
 					  JOIN 	(
 					  			SELECT DISTINCT B.CMPN_CD, A.CD_SITE 
 					  			SELECT DISTINCT B.CMPN_CD, A.CD_SITE 
 								  FROM WC_S_SITEAUTH@ERPSQL A 
 								  FROM WC_S_SITEAUTH@ERPSQL A 
@@ -109,10 +74,10 @@
 					  		) Z ON Z.CMPN_CD = A.CMPN_CD AND Z.CD_SITE = A.CC_CD 
 					  		) Z ON Z.CMPN_CD = A.CMPN_CD AND Z.CD_SITE = A.CC_CD 
 					 WHERE A.CMPN_CD = #{cmpnCd}
 					 WHERE A.CMPN_CD = #{cmpnCd}
 					   AND A.STD_YM = #{stdYm}
 					   AND A.STD_YM = #{stdYm}
-					   AND NVL(D.CTMN_AMT,0) + NVL(E.CTMN_AMT,0) >= #{unit2}
+					   AND NVL(D.DORE,0) + NVL(D.MIDORE,0) <![CDATA[>=]]> #{unit2}
 		  		)
 		  		)
 		 WHERE CC_CD NOT IN (SELECT SPEC_CD FROM SM_COM_COMMCD_D A, SM_COM_COMMCD B WHERE A.COMM_CD_ID = B.COMM_CD_ID AND B.COMM_CD = 'CO004' AND A.USE_YN = 'Y') 
 		 WHERE CC_CD NOT IN (SELECT SPEC_CD FROM SM_COM_COMMCD_D A, SM_COM_COMMCD B WHERE A.COMM_CD_ID = B.COMM_CD_ID AND B.COMM_CD = 'CO004' AND A.USE_YN = 'Y') 
-		   AND NON_AMT > 0
+		   AND NON_AMT <![CDATA[>]]> 0
 		<if test="ccgrpCd != 'all'">
 		<if test="ccgrpCd != 'all'">
 		   AND CCGRP_CD = #{ccgrpCd}
 		   AND CCGRP_CD = #{ccgrpCd}
 		</if>
 		</if>