분할 출하 기능 완료 - 잔량 계산 수정
This commit is contained in:
@@ -3205,4 +3205,32 @@ SELECT option_objid::VARCHAR AS CODE
|
||||
WHERE USER_ID = #{userId}
|
||||
AND MASTER_OBJID::varchar = #{masterObjid}
|
||||
</select>
|
||||
|
||||
<!-- 고객사 정보 조회 -->
|
||||
<select id="getSupplyInfo" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
OBJID,
|
||||
SUPPLY_CODE,
|
||||
SUPPLY_NAME,
|
||||
REG_NO,
|
||||
SUPPLY_ADDRESS,
|
||||
SUPPLY_BUSNAME,
|
||||
SUPPLY_STOCKNAME,
|
||||
SUPPLY_TEL_NO,
|
||||
SUPPLY_FAX_NO,
|
||||
CHARGE_USER_NAME,
|
||||
PAYMENT_METHOD,
|
||||
MANAGER1_NAME,
|
||||
MANAGER1_EMAIL,
|
||||
MANAGER2_NAME,
|
||||
MANAGER2_EMAIL,
|
||||
MANAGER3_NAME,
|
||||
MANAGER3_EMAIL,
|
||||
MANAGER4_NAME,
|
||||
MANAGER4_EMAIL,
|
||||
MANAGER5_NAME,
|
||||
MANAGER5_EMAIL
|
||||
FROM SUPPLY_MNG
|
||||
WHERE OBJID = #{objId}::numeric
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -790,6 +790,102 @@
|
||||
ORDER BY REGDATE DESC
|
||||
</select>
|
||||
|
||||
<!-- 주문서관리 Total 합계 조회 (조회된 데이터 전체 합계) -->
|
||||
<select id="getContractGridTotalAmount" parameterType="map" resultType="map">
|
||||
/* contractMgmt.getContractGridTotalAmount */
|
||||
SELECT
|
||||
COALESCE(SUM(COALESCE(T.ORDER_TOTAL_AMOUNT_KRW, 0)), 0) AS "totalAmountKRW"
|
||||
FROM
|
||||
<include refid="contractBase"/> T
|
||||
WHERE 1=1
|
||||
<if test="Year !=null and Year != '' ">
|
||||
AND SUBSTR(CONTRACT_DATE,0,5) = #{Year}
|
||||
</if>
|
||||
|
||||
<if test="category_cd !=null and category_cd != '' ">
|
||||
AND category_cd = #{category_cd}
|
||||
</if>
|
||||
|
||||
<if test="customer_objid !=null and customer_objid != '' ">
|
||||
AND customer_objid = #{customer_objid}
|
||||
</if>
|
||||
|
||||
<if test="product != null and product !='' ">
|
||||
AND product = #{product}
|
||||
</if>
|
||||
|
||||
<if test="status_cd !=null and status_cd !=''">
|
||||
AND status_cd = #{status_cd}
|
||||
</if>
|
||||
|
||||
<if test="result_cd !=null and result_cd !=''">
|
||||
AND result_cd = #{result_cd}
|
||||
</if>
|
||||
<if test="contract_result !=null and contract_result !=''">
|
||||
AND contract_result = #{contract_result}
|
||||
</if>
|
||||
|
||||
<if test="contract_start_date != null and !''.equals(contract_start_date)">
|
||||
AND TO_DATE(CONTRACT_DATE,'YYYY-MM-DD') <![CDATA[ >= ]]> TO_DATE(#{contract_start_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
<if test="contract_end_date != null and !''.equals(contract_end_date)">
|
||||
AND TO_DATE(CONTRACT_DATE,'YYYY-MM-DD') <![CDATA[ <= ]]> TO_DATE(#{contract_end_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
|
||||
<if test="pm_user_id !=null and pm_user_id !=''">
|
||||
AND pm_user_id = #{pm_user_id}
|
||||
</if>
|
||||
<if test="contract_month != null and !''.equals(contract_month)">
|
||||
AND TO_DATE(TO_CHAR(TO_DATE(CONTRACT_DATE,'YYYY-MM-DD'),'YYYY-MM-DD'),'YYYY-MM') <![CDATA[ = ]]> TO_DATE(SUBSTRING(#{contract_month} FROM 1 FOR 4) || '-' || SUBSTRING(#{contract_month} FROM 5 FOR 2), 'YYYY-MM')
|
||||
</if>
|
||||
|
||||
<!-- 견적관리 추가 검색조건 -->
|
||||
<if test="appr_status !=null and appr_status != '' ">
|
||||
AND APPR_STATUS = #{appr_status}
|
||||
</if>
|
||||
|
||||
<if test="area_cd != null and area_cd !='' ">
|
||||
AND AREA_CD = #{area_cd}
|
||||
</if>
|
||||
|
||||
<if test="paid_type != null and paid_type !='' ">
|
||||
AND PAID_TYPE = #{paid_type}
|
||||
</if>
|
||||
|
||||
<!-- 품번/품명 검색: PART_OBJID로 정확하게 검색 -->
|
||||
<if test="search_partObjId != null and search_partObjId != ''">
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM CONTRACT_ITEM CI
|
||||
WHERE CI.CONTRACT_OBJID = T.OBJID
|
||||
AND CI.STATUS = 'ACTIVE'
|
||||
AND CI.PART_OBJID = #{search_partObjId}
|
||||
)
|
||||
</if>
|
||||
|
||||
<if test="search_serialNo != null and search_serialNo != ''">
|
||||
AND UPPER(SERIAL_NO) LIKE UPPER('%${search_serialNo}%')
|
||||
</if>
|
||||
|
||||
<if test="search_poNo != null and search_poNo != ''">
|
||||
AND UPPER(PO_NO) LIKE UPPER('%${search_poNo}%')
|
||||
</if>
|
||||
|
||||
<if test="order_start_date != null and !''.equals(order_start_date)">
|
||||
AND TO_DATE(ORDER_DATE,'YYYY-MM-DD') <![CDATA[ >= ]]> TO_DATE(#{order_start_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
<if test="order_end_date != null and !''.equals(order_end_date)">
|
||||
AND TO_DATE(ORDER_DATE,'YYYY-MM-DD') <![CDATA[ <= ]]> TO_DATE(#{order_end_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
|
||||
<if test="due_start_date != null and !''.equals(due_start_date)">
|
||||
AND TO_DATE(DUE_DATE,'YYYY-MM-DD') <![CDATA[ >= ]]> TO_DATE(#{due_start_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
<if test="due_end_date != null and !''.equals(due_end_date)">
|
||||
AND TO_DATE(DUE_DATE,'YYYY-MM-DD') <![CDATA[ <= ]]> TO_DATE(#{due_end_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="contractList_bak" parameterType="map" resultType="map">
|
||||
SELECT *
|
||||
FROM (
|
||||
@@ -3870,7 +3966,14 @@ ORDER BY ASM.SUPPLY_NAME
|
||||
FROM
|
||||
CONTRACT_MGMT AS T
|
||||
WHERE
|
||||
OBJID::VARCHAR = #{objId}
|
||||
<choose>
|
||||
<when test="templateObjId != null and templateObjId != '' and templateObjId != '-1' and (objId == null or objId == '' or objId == '-1')">
|
||||
OBJID::VARCHAR = (SELECT CONTRACT_OBJID FROM ESTIMATE_TEMPLATE WHERE OBJID = #{templateObjId})
|
||||
</when>
|
||||
<otherwise>
|
||||
OBJID::VARCHAR = #{objId}
|
||||
</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
|
||||
<!-- 견적서 템플릿 목록 조회 (CONTRACT_OBJID 기준) -->
|
||||
@@ -3935,6 +4038,12 @@ ORDER BY ASM.SUPPLY_NAME
|
||||
ET.TOTAL_AMOUNT_KRW,
|
||||
ET.MANAGER_NAME,
|
||||
ET.MANAGER_CONTACT,
|
||||
ET.PART_NAME,
|
||||
ET.PART_OBJID,
|
||||
ET.NOTES_CONTENT,
|
||||
ET.VALIDITY_PERIOD,
|
||||
ET.CATEGORIES_JSON,
|
||||
ET.GROUP1_SUBTOTAL,
|
||||
ET.WRITER,
|
||||
ET.REGDATE,
|
||||
ET.CHG_USER_ID,
|
||||
@@ -3960,12 +4069,19 @@ ORDER BY ASM.SUPPLY_NAME
|
||||
ESTIMATE_TEMPLATE ET
|
||||
LEFT JOIN CONTRACT_MGMT CM ON ET.CONTRACT_OBJID = CM.OBJID
|
||||
WHERE
|
||||
ET.CONTRACT_OBJID = #{objId}
|
||||
<if test="template_type != null and template_type != ''">
|
||||
AND ET.TEMPLATE_TYPE = #{template_type}
|
||||
</if>
|
||||
ORDER BY ET.REGDATE DESC
|
||||
LIMIT 1
|
||||
<choose>
|
||||
<when test="templateObjId != null and templateObjId != '' and templateObjId != '-1'">
|
||||
ET.OBJID = #{templateObjId}
|
||||
</when>
|
||||
<otherwise>
|
||||
ET.CONTRACT_OBJID = #{objId}
|
||||
<if test="template_type != null and template_type != ''">
|
||||
AND ET.TEMPLATE_TYPE = #{template_type}
|
||||
</if>
|
||||
ORDER BY ET.REGDATE DESC
|
||||
LIMIT 1
|
||||
</otherwise>
|
||||
</choose>
|
||||
</select>
|
||||
|
||||
<!-- 견적서 템플릿 데이터 조회 (OBJID 기준) -->
|
||||
@@ -3991,6 +4107,13 @@ ORDER BY ASM.SUPPLY_NAME
|
||||
ET.TOTAL_AMOUNT_KRW,
|
||||
ET.MANAGER_NAME,
|
||||
ET.MANAGER_CONTACT,
|
||||
ET.SHOW_TOTAL_ROW,
|
||||
ET.PART_NAME,
|
||||
ET.PART_OBJID,
|
||||
ET.NOTES_CONTENT,
|
||||
ET.VALIDITY_PERIOD,
|
||||
ET.CATEGORIES_JSON,
|
||||
ET.GROUP1_SUBTOTAL,
|
||||
ET.WRITER,
|
||||
TO_CHAR(ET.REGDATE, 'YYYY-MM-DD HH24:MI') AS REGDATE,
|
||||
ET.CHG_USER_ID,
|
||||
@@ -4069,6 +4192,30 @@ ORDER BY ASM.SUPPLY_NAME
|
||||
ORDER BY SEQ
|
||||
</select>
|
||||
|
||||
<!-- 견적서 템플릿 품목 조회 (PART_OBJID로) -->
|
||||
<select id="getEstimateTemplateItemByPartObjId" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
OBJID,
|
||||
TEMPLATE_OBJID,
|
||||
SEQ,
|
||||
CATEGORY,
|
||||
PART_OBJID,
|
||||
DESCRIPTION,
|
||||
SPECIFICATION,
|
||||
QUANTITY,
|
||||
UNIT,
|
||||
UNIT_PRICE,
|
||||
AMOUNT,
|
||||
NOTE,
|
||||
REMARK
|
||||
FROM
|
||||
ESTIMATE_TEMPLATE_ITEM
|
||||
WHERE
|
||||
TEMPLATE_OBJID = #{templateObjId}
|
||||
AND PART_OBJID = #{partObjId}
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 견적서 템플릿 저장 -->
|
||||
<insert id="insertEstimateTemplate" parameterType="map">
|
||||
INSERT INTO ESTIMATE_TEMPLATE (
|
||||
@@ -4092,6 +4239,7 @@ ORDER BY ASM.SUPPLY_NAME
|
||||
TOTAL_AMOUNT_KRW,
|
||||
MANAGER_NAME,
|
||||
MANAGER_CONTACT,
|
||||
SHOW_TOTAL_ROW,
|
||||
WRITER,
|
||||
REGDATE,
|
||||
CHG_USER_ID,
|
||||
@@ -4117,6 +4265,7 @@ ORDER BY ASM.SUPPLY_NAME
|
||||
#{total_amount_krw},
|
||||
#{manager_name},
|
||||
#{manager_contact},
|
||||
#{show_total_row},
|
||||
#{writer},
|
||||
NOW(),
|
||||
#{chg_user_id},
|
||||
@@ -4145,6 +4294,7 @@ ORDER BY ASM.SUPPLY_NAME
|
||||
TOTAL_AMOUNT_KRW = #{total_amount_krw},
|
||||
MANAGER_NAME = #{manager_name},
|
||||
MANAGER_CONTACT = #{manager_contact},
|
||||
SHOW_TOTAL_ROW = #{show_total_row},
|
||||
CHG_USER_ID = #{chg_user_id},
|
||||
CHGDATE = NOW()
|
||||
WHERE
|
||||
@@ -4202,6 +4352,67 @@ WHERE
|
||||
OBJID = #{template_objid}
|
||||
</update>
|
||||
|
||||
<!-- 장비 견적서 템플릿 신규 저장 (Template 2) -->
|
||||
<insert id="insertEstimateTemplate2" parameterType="map">
|
||||
INSERT INTO ESTIMATE_TEMPLATE (
|
||||
OBJID,
|
||||
CONTRACT_OBJID,
|
||||
TEMPLATE_TYPE,
|
||||
EXECUTOR_DATE,
|
||||
RECIPIENT,
|
||||
PART_NAME,
|
||||
PART_OBJID,
|
||||
NOTES_CONTENT,
|
||||
VALIDITY_PERIOD,
|
||||
CATEGORIES_JSON,
|
||||
GROUP1_SUBTOTAL,
|
||||
TOTAL_AMOUNT,
|
||||
TOTAL_AMOUNT_KRW,
|
||||
WRITER,
|
||||
REGDATE,
|
||||
CHG_USER_ID,
|
||||
CHGDATE
|
||||
) VALUES (
|
||||
#{template_objid},
|
||||
#{contract_objid},
|
||||
'2',
|
||||
#{executor_date},
|
||||
#{recipient},
|
||||
#{part_name},
|
||||
#{part_objid},
|
||||
#{notes_content},
|
||||
#{validity_period},
|
||||
#{categories_json},
|
||||
#{group1_subtotal},
|
||||
#{total_amount},
|
||||
#{total_amount_krw},
|
||||
#{writer},
|
||||
NOW(),
|
||||
#{chg_user_id},
|
||||
NOW()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 장비 견적서 템플릿 수정 (Template 2) -->
|
||||
<update id="updateEstimateTemplate2" parameterType="map">
|
||||
UPDATE ESTIMATE_TEMPLATE
|
||||
SET
|
||||
EXECUTOR_DATE = #{executor_date},
|
||||
RECIPIENT = #{recipient},
|
||||
PART_NAME = #{part_name},
|
||||
PART_OBJID = #{part_objid},
|
||||
NOTES_CONTENT = #{notes_content},
|
||||
VALIDITY_PERIOD = #{validity_period},
|
||||
CATEGORIES_JSON = #{categories_json},
|
||||
GROUP1_SUBTOTAL = #{group1_subtotal},
|
||||
TOTAL_AMOUNT = #{total_amount},
|
||||
TOTAL_AMOUNT_KRW = #{total_amount_krw},
|
||||
CHG_USER_ID = #{chg_user_id},
|
||||
CHGDATE = NOW()
|
||||
WHERE
|
||||
OBJID = #{template_objid}
|
||||
</update>
|
||||
|
||||
<!-- 최종 차수 견적서 조회 (메일 발송용) -->
|
||||
<select id="getLatestEstimateTemplate" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
@@ -4359,14 +4570,112 @@ WHERE
|
||||
</if>
|
||||
ORDER BY REGDATE DESC
|
||||
</select>
|
||||
|
||||
<!-- 주문서관리 Total 합계 조회 -->
|
||||
<select id="getOrderTotalAmount" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
COALESCE(SUM(COALESCE(T.ORDER_SUPPLY_PRICE_SUM, 0)), 0) AS TOTAL_SUPPLY_PRICE,
|
||||
COALESCE(SUM(COALESCE(T.ORDER_VAT_SUM, 0)), 0) AS TOTAL_VAT,
|
||||
COALESCE(SUM(COALESCE(T.ORDER_TOTAL_AMOUNT_SUM, 0)), 0) AS TOTAL_AMOUNT
|
||||
FROM
|
||||
<include refid="contractBase"/> T
|
||||
WHERE 1=1
|
||||
<if test="Year !=null and Year != '' ">
|
||||
AND SUBSTR(CONTRACT_DATE,0,5) = #{Year}
|
||||
</if>
|
||||
|
||||
<if test="category_cd !=null and category_cd != '' ">
|
||||
AND category_cd = #{category_cd}
|
||||
</if>
|
||||
|
||||
<if test="customer_objid !=null and customer_objid != '' ">
|
||||
AND customer_objid = #{customer_objid}
|
||||
</if>
|
||||
|
||||
<if test="product != null and product !='' ">
|
||||
AND product = #{product}
|
||||
</if>
|
||||
|
||||
<if test="status_cd !=null and status_cd !=''">
|
||||
AND status_cd = #{status_cd}
|
||||
</if>
|
||||
|
||||
<if test="result_cd !=null and result_cd !=''">
|
||||
AND result_cd = #{result_cd}
|
||||
</if>
|
||||
<if test="contract_result !=null and contract_result !=''">
|
||||
AND contract_result = #{contract_result}
|
||||
</if>
|
||||
|
||||
<if test="contract_start_date != null and !''.equals(contract_start_date)">
|
||||
AND TO_DATE(CONTRACT_DATE,'YYYY-MM-DD') <![CDATA[ >= ]]> TO_DATE(#{contract_start_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
<if test="contract_end_date != null and !''.equals(contract_end_date)">
|
||||
AND TO_DATE(CONTRACT_DATE,'YYYY-MM-DD') <![CDATA[ <= ]]> TO_DATE(#{contract_end_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
|
||||
<if test="pm_user_id !=null and pm_user_id !=''">
|
||||
AND pm_user_id = #{pm_user_id}
|
||||
</if>
|
||||
<if test="contract_month != null and !''.equals(contract_month)">
|
||||
AND TO_DATE(TO_CHAR(TO_DATE(CONTRACT_DATE,'YYYY-MM-DD'),'YYYY-MM-DD'),'YYYY-MM') <![CDATA[ = ]]> TO_DATE(SUBSTRING(#{contract_month} FROM 1 FOR 4) || '-' || SUBSTRING(#{contract_month} FROM 5 FOR 2), 'YYYY-MM')
|
||||
</if>
|
||||
|
||||
<!-- 견적관리 추가 검색조건 -->
|
||||
<if test="appr_status !=null and appr_status != '' ">
|
||||
AND APPR_STATUS = #{appr_status}
|
||||
</if>
|
||||
|
||||
<if test="area_cd != null and area_cd !='' ">
|
||||
AND AREA_CD = #{area_cd}
|
||||
</if>
|
||||
|
||||
<if test="paid_type != null and paid_type !='' ">
|
||||
AND PAID_TYPE = #{paid_type}
|
||||
</if>
|
||||
|
||||
<!-- 품번/품명 검색: PART_OBJID로 정확하게 검색 -->
|
||||
<if test="search_partObjId != null and search_partObjId != ''">
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM CONTRACT_ITEM CI
|
||||
WHERE CI.CONTRACT_OBJID = T.OBJID
|
||||
AND CI.STATUS = 'ACTIVE'
|
||||
AND CI.PART_OBJID = #{search_partObjId}
|
||||
)
|
||||
</if>
|
||||
|
||||
<if test="search_serialNo != null and search_serialNo != ''">
|
||||
AND UPPER(SERIAL_NO) LIKE UPPER('%${search_serialNo}%')
|
||||
</if>
|
||||
|
||||
<if test="search_poNo != null and search_poNo != ''">
|
||||
AND UPPER(PO_NO) LIKE UPPER('%${search_poNo}%')
|
||||
</if>
|
||||
|
||||
<if test="order_start_date != null and !''.equals(order_start_date)">
|
||||
AND TO_DATE(ORDER_DATE,'YYYY-MM-DD') <![CDATA[ >= ]]> TO_DATE(#{order_start_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
<if test="order_end_date != null and !''.equals(order_end_date)">
|
||||
AND TO_DATE(ORDER_DATE,'YYYY-MM-DD') <![CDATA[ <= ]]> TO_DATE(#{order_end_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
|
||||
<if test="due_start_date != null and !''.equals(due_start_date)">
|
||||
AND TO_DATE(DUE_DATE,'YYYY-MM-DD') <![CDATA[ >= ]]> TO_DATE(#{due_start_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
<if test="due_end_date != null and !''.equals(due_end_date)">
|
||||
AND TO_DATE(DUE_DATE,'YYYY-MM-DD') <![CDATA[ <= ]]> TO_DATE(#{due_end_date}, 'YYYY-MM-DD')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 영업정보 조회 (수주등록용) -->
|
||||
<select id="getContractInfo" parameterType="map" resultType="map">
|
||||
SELECT
|
||||
OBJID,
|
||||
CONTRACT_NO,
|
||||
CUSTOMER_OBJID,
|
||||
CONTRACT_CURRENCY,
|
||||
(SELECT CODE_NAME FROM TB_CODE WHERE CODE_ID = CONTRACT_CURRENCY) AS CONTRACT_CURRENCY_NAME,
|
||||
(SELECT CODE_NAME FROM COMM_CODE WHERE CODE_ID = CONTRACT_CURRENCY) AS CONTRACT_CURRENCY_NAME,
|
||||
EXCHANGE_RATE,
|
||||
QUANTITY,
|
||||
PART_NO,
|
||||
@@ -4592,8 +4901,8 @@ WHERE
|
||||
CI.CONTRACT_OBJID,
|
||||
CI.SEQ,
|
||||
CI.PART_OBJID,
|
||||
CI.PART_NO,
|
||||
CI.PART_NAME,
|
||||
COALESCE(NULLIF(CI.PART_NO, ''), PM.PART_NO) AS PART_NO,
|
||||
COALESCE(NULLIF(CI.PART_NAME, ''), PM.PART_NAME) AS PART_NAME,
|
||||
CI.QUANTITY,
|
||||
CI.DUE_DATE,
|
||||
CI.CUSTOMER_REQUEST,
|
||||
@@ -4607,6 +4916,8 @@ WHERE
|
||||
LEFT JOIN CONTRACT_ITEM_SERIAL CIS
|
||||
ON CI.OBJID = CIS.ITEM_OBJID
|
||||
AND CIS.STATUS = 'ACTIVE'
|
||||
LEFT JOIN PART_MNG PM
|
||||
ON CI.PART_OBJID = PM.OBJID
|
||||
WHERE
|
||||
CI.CONTRACT_OBJID = #{contractObjId}
|
||||
AND CI.STATUS = 'ACTIVE'
|
||||
@@ -4616,7 +4927,9 @@ WHERE
|
||||
CI.SEQ,
|
||||
CI.PART_OBJID,
|
||||
CI.PART_NO,
|
||||
CI.PART_NAME,
|
||||
CI.PART_NAME,
|
||||
PM.PART_NO,
|
||||
PM.PART_NAME,
|
||||
CI.QUANTITY,
|
||||
CI.DUE_DATE,
|
||||
CI.CUSTOMER_REQUEST,
|
||||
|
||||
@@ -875,16 +875,32 @@
|
||||
(SELECT CM.PRODUCTION_STATUS FROM CONTRACT_MGMT CM WHERE CM.OBJID = T.CONTRACT_OBJID) AS PRODUCTION_STATUS,
|
||||
-- 판매 관련 필드들 (sales_registration 테이블에서 한 번에 가져오기)
|
||||
COALESCE(SR.shipping_order_status, '') AS SHIPPING_ORDER_STATUS,
|
||||
COALESCE(SR.sales_quantity, 0) AS SALES_QUANTITY,
|
||||
-- 판매수량: 모든 분할 출하의 합계
|
||||
COALESCE(
|
||||
(SELECT SUM(sales_quantity)
|
||||
FROM sales_registration
|
||||
WHERE project_no LIKE T.PROJECT_NO || '%'),
|
||||
0
|
||||
) AS SALES_QUANTITY,
|
||||
COALESCE(SR.sales_unit_price, 0) AS SALES_UNIT_PRICE,
|
||||
COALESCE(SR.sales_supply_price, 0) AS SALES_SUPPLY_PRICE,
|
||||
COALESCE(SR.sales_vat, 0) AS SALES_VAT,
|
||||
COALESCE(SR.sales_total_amount, 0) AS SALES_TOTAL_AMOUNT,
|
||||
COALESCE(SR.sales_total_amount, 0) AS SALES_TOTAL_AMOUNT_KRW,
|
||||
-- 잔량 계산: 수주수량 - 판매수량
|
||||
COALESCE(T.QUANTITY::numeric, 0) - COALESCE(SR.sales_quantity, 0) AS REMAINING_QUANTITY,
|
||||
-- 잔량원화총액 계산: (수주수량 - 판매수량) * 판매단가
|
||||
(COALESCE(T.QUANTITY::numeric, 0) - COALESCE(SR.sales_quantity, 0)) * COALESCE(SR.sales_unit_price, 0) AS REMAINING_AMOUNT_KRW,
|
||||
-- 잔량 계산: 수주수량 - 모든 분할 출하의 합계
|
||||
COALESCE(T.QUANTITY::numeric, 0) - COALESCE(
|
||||
(SELECT SUM(sales_quantity)
|
||||
FROM sales_registration
|
||||
WHERE project_no LIKE T.PROJECT_NO || '%'),
|
||||
0
|
||||
) AS REMAINING_QUANTITY,
|
||||
-- 잔량원화총액 계산: (수주수량 - 모든 분할 출하 합계) * 판매단가
|
||||
(COALESCE(T.QUANTITY::numeric, 0) - COALESCE(
|
||||
(SELECT SUM(sales_quantity)
|
||||
FROM sales_registration
|
||||
WHERE project_no LIKE T.PROJECT_NO || '%'),
|
||||
0
|
||||
)) * COALESCE(SR.sales_unit_price, 0) AS REMAINING_AMOUNT_KRW,
|
||||
COALESCE(SR.sales_currency, T.CONTRACT_CURRENCY) AS SALES_CURRENCY,
|
||||
CODE_NAME(COALESCE(SR.sales_currency, T.CONTRACT_CURRENCY)) AS SALES_CURRENCY_NAME,
|
||||
COALESCE(SR.sales_exchange_rate, T.CONTRACT_PRICE_CURRENCY::numeric, 0) AS SALES_EXCHANGE_RATE,
|
||||
@@ -1397,29 +1413,12 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
NULL,
|
||||
</otherwise>
|
||||
</choose>
|
||||
#{shippingMethod},
|
||||
#{manager},
|
||||
#{incoterms},
|
||||
#{cretEmpNo}
|
||||
)
|
||||
ON CONFLICT (project_no)
|
||||
DO UPDATE SET
|
||||
shipping_order_status = EXCLUDED.shipping_order_status,
|
||||
serial_no = EXCLUDED.serial_no,
|
||||
sales_quantity = EXCLUDED.sales_quantity,
|
||||
sales_unit_price = EXCLUDED.sales_unit_price,
|
||||
sales_supply_price = EXCLUDED.sales_supply_price,
|
||||
sales_vat = EXCLUDED.sales_vat,
|
||||
sales_total_amount = EXCLUDED.sales_total_amount,
|
||||
sales_currency = EXCLUDED.sales_currency,
|
||||
sales_exchange_rate = EXCLUDED.sales_exchange_rate,
|
||||
shipping_date = EXCLUDED.shipping_date,
|
||||
shipping_method = EXCLUDED.shipping_method,
|
||||
manager_user_id = EXCLUDED.manager_user_id,
|
||||
incoterms = EXCLUDED.incoterms,
|
||||
upd_date = NOW(),
|
||||
upd_user_id = EXCLUDED.reg_user_id
|
||||
</insert>
|
||||
#{shippingMethod},
|
||||
#{manager},
|
||||
#{incoterms},
|
||||
#{cretEmpNo}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!--
|
||||
/**
|
||||
@@ -1488,9 +1487,10 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
AND UPPER(STATUS) = 'ACTIVE'
|
||||
) THEN 'Y' ELSE 'N' END AS ORDER_ATTACH,
|
||||
(SELECT CM.PRODUCTION_STATUS FROM CONTRACT_MGMT CM WHERE CM.OBJID = T.CONTRACT_OBJID) AS PRODUCTION_STATUS,
|
||||
-- 판매 관련 필드들 (sales_registration 테이블에서 가져오기)
|
||||
COALESCE(SR.shipping_order_status, '') AS SHIPPING_ORDER_STATUS,
|
||||
COALESCE(SR.sales_quantity, 0) AS SALES_QUANTITY,
|
||||
-- 판매 관련 필드들 (sales_registration 테이블에서 가져오기)
|
||||
SR.sale_no AS SALE_NO,
|
||||
COALESCE(SR.shipping_order_status, '') AS SHIPPING_ORDER_STATUS,
|
||||
COALESCE(SR.sales_quantity, 0) AS SALES_QUANTITY,
|
||||
COALESCE(SR.sales_unit_price, 0) AS SALES_UNIT_PRICE,
|
||||
COALESCE(SR.sales_supply_price, 0) AS SALES_SUPPLY_PRICE,
|
||||
COALESCE(SR.sales_vat, 0) AS SALES_VAT,
|
||||
@@ -1619,5 +1619,129 @@ ORDER BY T.REGDATE DESC, T.PROJECT_NO DESC
|
||||
WHERE OBJID::VARCHAR = #{OBJID}
|
||||
</update>
|
||||
|
||||
<!-- 모든 분할 출하의 총 판매 수량 조회 -->
|
||||
<select id="getTotalSalesQuantity" parameterType="map" resultType="map">
|
||||
/* salesNcollectMgmt.getTotalSalesQuantity - project_no로 시작하는 모든 레코드의 판매 수량 합계 */
|
||||
SELECT COALESCE(SUM(sales_quantity), 0) as total
|
||||
FROM sales_registration
|
||||
WHERE project_no LIKE #{orderNo} || '%'
|
||||
</select>
|
||||
|
||||
<!-- sales_registration 개수 조회 (분할 출하 순번용) -->
|
||||
<select id="getSaleRegistrationCount" parameterType="map" resultType="map">
|
||||
/* salesNcollectMgmt.getSaleRegistrationCount - project_no로 시작하는 레코드 개수 */
|
||||
SELECT COUNT(*) as count
|
||||
FROM sales_registration
|
||||
WHERE project_no LIKE #{orderNo} || '%'
|
||||
</select>
|
||||
|
||||
<!-- sales_registration DELETE (기존 데이터 삭제) -->
|
||||
<delete id="deleteSaleRegistration" parameterType="map">
|
||||
/* salesNcollectMgmt.deleteSaleRegistration - sales_registration 삭제 */
|
||||
DELETE FROM sales_registration
|
||||
WHERE project_no = #{orderNo}
|
||||
</delete>
|
||||
|
||||
<!-- sales_registration UPDATE (기존 데이터 수정) -->
|
||||
<update id="updateSaleRegistration" parameterType="map">
|
||||
/* salesNcollectMgmt.updateSaleRegistration - sales_registration 업데이트 */
|
||||
UPDATE sales_registration
|
||||
SET
|
||||
shipping_order_status = <choose>
|
||||
<when test="shippingOrderStatus != null and shippingOrderStatus != ''">
|
||||
#{shippingOrderStatus},
|
||||
</when>
|
||||
<otherwise>
|
||||
'',
|
||||
</otherwise>
|
||||
</choose>
|
||||
serial_no = #{serialNo},
|
||||
sales_quantity = #{salesQuantity}::integer,
|
||||
sales_unit_price = #{salesUnitPrice}::numeric,
|
||||
sales_supply_price = #{salesSupplyPrice}::numeric,
|
||||
sales_vat = #{salesVat}::numeric,
|
||||
sales_total_amount = #{salesTotalAmount}::numeric,
|
||||
sales_currency = #{salesCurrency},
|
||||
sales_exchange_rate = #{salesExchangeRate}::numeric,
|
||||
shipping_date = <choose>
|
||||
<when test="shippingDate != null and shippingDate != ''">
|
||||
TO_DATE(#{shippingDate}, 'YYYY-MM-DD'),
|
||||
</when>
|
||||
<otherwise>
|
||||
NULL,
|
||||
</otherwise>
|
||||
</choose>
|
||||
shipping_method = #{shippingMethod},
|
||||
manager_user_id = #{manager},
|
||||
incoterms = #{incoterms},
|
||||
upd_date = NOW(),
|
||||
upd_user_id = #{cretEmpNo}
|
||||
WHERE project_no = #{orderNo}
|
||||
</update>
|
||||
|
||||
<!-- ========================================
|
||||
분할 출하 관련 쿼리 (shipment_log 테이블 활용)
|
||||
======================================== -->
|
||||
|
||||
<!-- shipment_log의 split_quantity 합산 조회 -->
|
||||
<select id="getShipmentLogTotal" parameterType="map" resultType="map">
|
||||
/* salesNcollectMgmt.getShipmentLogTotal - shipment_log의 split_quantity 합산 */
|
||||
SELECT COALESCE(SUM(split_quantity), 0) as total
|
||||
FROM shipment_log SL
|
||||
INNER JOIN project_mgmt PM ON SL.target_objid = PM.OBJID::VARCHAR
|
||||
WHERE PM.PROJECT_NO = #{orderNo}
|
||||
</select>
|
||||
|
||||
<!-- shipment_log에 분할 출하 기록 저장 -->
|
||||
<insert id="insertShipmentLog" parameterType="map">
|
||||
/* salesNcollectMgmt.insertShipmentLog - 분할 출하 기록 저장 */
|
||||
INSERT INTO shipment_log (
|
||||
target_objid, log_type, log_message, split_quantity, original_quantity,
|
||||
remaining_quantity, shipping_status, shipping_date, shipping_method,
|
||||
sales_unit_price, sales_supply_price, sales_vat, sales_total_amount,
|
||||
sales_currency, sales_exchange_rate, manager_user_id, incoterms,
|
||||
serial_no, parent_sale_no, reg_user_id
|
||||
) VALUES (
|
||||
#{targetObjid}, 'SPLIT_SHIPMENT', '분할 출하',
|
||||
#{salesQuantity}::integer, #{originalQuantity}::integer, #{remainingQuantity}::integer,
|
||||
#{shippingOrderStatus},
|
||||
<choose>
|
||||
<when test="shippingDate != null and shippingDate != ''">
|
||||
TO_DATE(#{shippingDate}, 'YYYY-MM-DD'),
|
||||
</when>
|
||||
<otherwise>NULL,</otherwise>
|
||||
</choose>
|
||||
#{shippingMethod}, #{salesUnitPrice}::numeric, #{salesSupplyPrice}::numeric,
|
||||
#{salesVat}::numeric, #{salesTotalAmount}::numeric, #{salesCurrency},
|
||||
#{salesExchangeRate}::numeric, #{manager}, #{incoterms}, #{serialNo},
|
||||
#{parentSaleNo}::integer, #{cretEmpNo}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- PROJECT_MGMT의 OBJID 조회 (shipment_log의 target_objid로 사용) -->
|
||||
<select id="getProjectObjid" parameterType="map" resultType="map">
|
||||
/* salesNcollectMgmt.getProjectObjid - PROJECT_MGMT의 OBJID 조회 */
|
||||
SELECT OBJID FROM PROJECT_MGMT WHERE PROJECT_NO = #{orderNo}
|
||||
</select>
|
||||
|
||||
<!-- 출하일 상세 내역 조회 (모든 분할 출하 포함) -->
|
||||
<select id="getShippingDetailList" parameterType="map" resultType="map">
|
||||
/* salesNcollectMgmt.getShippingDetailList - 모든 분할 출하 포함 */
|
||||
SELECT
|
||||
COALESCE(TO_CHAR(SR.shipping_date, 'YYYY-MM-DD'), '미등록') AS shipping_date,
|
||||
COALESCE(SR.sales_quantity, 0) AS shipping_quantity,
|
||||
COALESCE(SR.shipping_order_status, '미등록') AS shipping_order_status,
|
||||
COALESCE(SR.serial_no, '-') AS serial_no,
|
||||
SR.project_no,
|
||||
CASE
|
||||
WHEN SR.project_no = #{projectNo} THEN '최초 출하'
|
||||
ELSE '분할 출하 ' || SUBSTRING(SR.project_no FROM LENGTH(#{projectNo}) + 2)
|
||||
END AS source
|
||||
FROM sales_registration SR
|
||||
WHERE SR.project_no LIKE #{projectNo} || '%'
|
||||
|
||||
ORDER BY shipping_date DESC, project_no
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user