From b9ff70814c4f8fffb7646fb0ea72a2a60b4068b0 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期三, 14 十月 2026 14:11:09 +0800
Subject: [PATCH] fix: 更新出库金额计算逻辑,确保按销售明细的含税总额折算,避免因小数位数导致的应收差异
---
src/main/resources/mapper/basic/CustomerMapper.xml | 350 ++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 264 insertions(+), 86 deletions(-)
diff --git a/src/main/resources/mapper/basic/CustomerMapper.xml b/src/main/resources/mapper/basic/CustomerMapper.xml
index d098178..86345e5 100644
--- a/src/main/resources/mapper/basic/CustomerMapper.xml
+++ b/src/main/resources/mapper/basic/CustomerMapper.xml
@@ -1,91 +1,269 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE mapper
-PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
-"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.basic.mapper.CustomerMapper">
-
- <resultMap type="com.ruoyi.basic.pojo.Customer" id="CustomerResult">
- <result property="id" column="id" />
- <result property="customerName" column="customer_name" />
- <result property="taxpayerIdentificationNumber" column="taxpayer_identification_number" />
- <result property="companyAddress" column="company_address" />
- <result property="companyPhone" column="company_phone" />
- <result property="contactPerson" column="contact_person" />
- <result property="contactPhone" column="contact_phone" />
- <result property="maintainer" column="maintainer" />
- <result property="maintenanceTime" column="maintenance_time" />
+
+ <!-- 閫氱敤鏌ヨ鏄犲皠缁撴灉 -->
+ <resultMap id="BaseResultMap" type="com.ruoyi.basic.pojo.Customer">
+ <id column="id" property="id" />
</resultMap>
-
- <sql id="selectCustomerVo">
- select id, customer_name, taxpayer_identification_number, company_address, company_phone, contact_person, contact_phone, maintainer, maintenance_time from customer
- </sql>
-
- <select id="selectCustomerList" parameterType="com.ruoyi.basic.pojo.Customer" resultMap="CustomerResult">
- <include refid="selectCustomerVo"/>
- <where>
- <if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
- <if test="taxpayerIdentificationNumber != null and taxpayerIdentificationNumber != ''"> and taxpayer_identification_number = #{taxpayerIdentificationNumber}</if>
- <if test="companyAddress != null and companyAddress != ''"> and company_address = #{companyAddress}</if>
- <if test="companyPhone != null and companyPhone != ''"> and company_phone = #{companyPhone}</if>
- <if test="contactPerson != null and contactPerson != ''"> and contact_person = #{contactPerson}</if>
- <if test="contactPhone != null and contactPhone != ''"> and contact_phone = #{contactPhone}</if>
- <if test="maintainer != null and maintainer != ''"> and maintainer = #{maintainer}</if>
- <if test="maintenanceTime != null "> and maintenance_time = #{maintenanceTime}</if>
+ <select id="listPage" resultType="com.ruoyi.basic.vo.CustomerVo">
+ select
+ c.*,
+ u.nick_name usage_user_name,
+ (
+ select group_concat(u2.user_name separator ', ')
+ from customer_user cu
+ left join sys_user u2 on cu.user_id = u2.user_id
+ where cu.customer_id = c.id
+ and cu.user_id != c.usage_user
+ ) as together_user_names,
+ (
+ select group_concat(cu.user_id separator ',')
+ from customer_user cu
+ where cu.customer_id = c.id
+ and cu.user_id != c.usage_user
+ ) as user_ids_str
+ from customer c
+ left join sys_user u on c.usage_user = u.user_id
+ <where>
+ <if test="c.customerName != null and c.customerName != ''">
+ and customer_name like concat('%', #{c.customerName}, '%')
+ </if>
+ <if test="c.customerType != null and c.customerType != ''">
+ and customer_type = #{c.customerType}
+ </if>
+ <!-- 鍏捣鏌ヨ锛歵ype = 1锛堝叕娴峰鎴凤級-->
+ <if test="c.type != null and c.type == 1">
+ and type = #{c.type}
+ </if>
+ <!-- 绉佹捣鏌ヨ锛歵ype = 0锛堢娴峰鎴凤級鎴栬�� type = 1锛堝叕娴峰鎴凤級涓斿凡琚垎閰嶏紝骞朵笖鏄嚜宸遍鐢ㄣ�佽嚜宸卞垱寤烘垨鑰呭叡浜粰鑷繁鐨勫鎴� -->
+ <if test="c.type != null and c.type == 0">
+ and (
+ (type = #{c.type} or (type = 1 and is_assigned = 1))
+ and (
+ c.usage_user = #{loginUserId}
+ or c.create_user = #{loginUserId}
+ or exists (
+ select 1 from customer_user cu
+ where cu.customer_id = c.id
+ and cu.user_id = #{loginUserId}
+ )
+ )
+ )
+ </if>
</where>
- </select>
-
- <select id="selectCustomerById" parameterType="Long" resultMap="CustomerResult">
- <include refid="selectCustomerVo"/>
- where id = #{id}
+ order by c.id desc
</select>
- <insert id="insertCustomer" parameterType="com.ruoyi.basic.pojo.Customer" useGeneratedKeys="true" keyProperty="id">
- insert into customer
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="customerName != null and customerName != ''">customer_name,</if>
- <if test="taxpayerIdentificationNumber != null and taxpayerIdentificationNumber != ''">taxpayer_identification_number,</if>
- <if test="companyAddress != null and companyAddress != ''">company_address,</if>
- <if test="companyPhone != null and companyPhone != ''">company_phone,</if>
- <if test="contactPerson != null and contactPerson != ''">contact_person,</if>
- <if test="contactPhone != null and contactPhone != ''">contact_phone,</if>
- <if test="maintainer != null and maintainer != ''">maintainer,</if>
- <if test="maintenanceTime != null">maintenance_time,</if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="customerName != null and customerName != ''">#{customerName},</if>
- <if test="taxpayerIdentificationNumber != null and taxpayerIdentificationNumber != ''">#{taxpayerIdentificationNumber},</if>
- <if test="companyAddress != null and companyAddress != ''">#{companyAddress},</if>
- <if test="companyPhone != null and companyPhone != ''">#{companyPhone},</if>
- <if test="contactPerson != null and contactPerson != ''">#{contactPerson},</if>
- <if test="contactPhone != null and contactPhone != ''">#{contactPhone},</if>
- <if test="maintainer != null and maintainer != ''">#{maintainer},</if>
- <if test="maintenanceTime != null">#{maintenanceTime},</if>
- </trim>
- </insert>
-
- <update id="updateCustomer" parameterType="com.ruoyi.basic.pojo.Customer">
- update customer
- <trim prefix="SET" suffixOverrides=",">
- <if test="customerName != null and customerName != ''">customer_name = #{customerName},</if>
- <if test="taxpayerIdentificationNumber != null and taxpayerIdentificationNumber != ''">taxpayer_identification_number = #{taxpayerIdentificationNumber},</if>
- <if test="companyAddress != null and companyAddress != ''">company_address = #{companyAddress},</if>
- <if test="companyPhone != null and companyPhone != ''">company_phone = #{companyPhone},</if>
- <if test="contactPerson != null and contactPerson != ''">contact_person = #{contactPerson},</if>
- <if test="contactPhone != null and contactPhone != ''">contact_phone = #{contactPhone},</if>
- <if test="maintainer != null and maintainer != ''">maintainer = #{maintainer},</if>
- <if test="maintenanceTime != null">maintenance_time = #{maintenanceTime},</if>
- </trim>
- where id = #{id}
- </update>
-
- <delete id="deleteCustomerById" parameterType="Long">
- delete from customer where id = #{id}
- </delete>
-
- <delete id="deleteCustomerByIds" parameterType="String">
- delete from customer where id in
- <foreach item="id" collection="array" open="(" separator="," close=")">
- #{id}
- </foreach>
- </delete>
-</mapper>
\ No newline at end of file
+ <select id="list" resultType="com.ruoyi.basic.vo.CustomerVo">
+ select
+ c.*,
+ u.user_name usage_user_name,
+ (
+ select group_concat(u2.user_name separator ', ')
+ from customer_user cu
+ left join sys_user u2 on cu.user_id = u2.user_id
+ where cu.customer_id = c.id
+ and cu.user_id != c.usage_user
+ ) as together_user_names,
+ (
+ select group_concat(cu.user_id separator ',')
+ from customer_user cu
+ where cu.customer_id = c.id
+ and cu.user_id != c.usage_user
+ ) as user_ids_str
+ from customer c
+ left join sys_user u on c.usage_user = u.user_id
+ <where>
+ <if test="c.ids != null and c.ids.length > 0">
+ and c.id in
+ <foreach collection="c.ids" item="id" open="(" separator="," close=")">
+ #{id}
+ </foreach>
+ </if>
+ <if test="c.customerName != null and c.customerName != ''">
+ and customer_name like concat('%', #{c.customerName}, '%')
+ </if>
+ <if test="c.customerType != null and c.customerType != ''">
+ and customer_type = #{c.customerType}
+ </if>
+ <!-- 鍏捣鏌ヨ锛歵ype = 1锛堝叕娴峰鎴凤級-->
+ <if test="c.type != null and c.type == 1">
+ and type = #{c.type}
+ </if>
+ <!-- 绉佹捣鏌ヨ锛歵ype = 0锛堢娴峰鎴凤級鎴栬�� type = 1锛堝叕娴峰鎴凤級涓斿凡琚垎閰嶏紝骞朵笖鏄嚜宸遍鐢ㄣ�佽嚜宸卞垱寤烘垨鑰呭叡浜粰鑷繁鐨勫鎴� -->
+ <if test="c.type != null and c.type == 0">
+ and (
+ (type = #{c.type} or (type = 1 and is_assigned = 1))
+ and (
+ c.usage_user = #{loginUserId}
+ or c.create_user = #{loginUserId}
+ or exists (
+ select 1 from customer_user cu
+ where cu.customer_id = c.id
+ and cu.user_id = #{loginUserId}
+ )
+ )
+ )
+ </if>
+ </where>
+ order by c.id desc
+ </select>
+ <!--
+ 瀹㈡埛寰�鏉ワ紙鍥炴鍙拌处涓昏〃锛夛細
+ 搴旀敹閲戦 = 鍚勯攢鍞彴璐︾殑搴旀敹閲戦涔嬪拰锛�
+ 鍗曟潯鍙拌处搴旀敹閲戦 = 璇ュ彴璐﹀凡鍑哄簱閲戦 鈭� 宸查��璐ф 鈭� 宸插洖娆鹃噾棰濓紙涓嶅皬浜� 0锛夈��
+ 鍗炽�屽洖娆鹃噾棰濄�嶆槸绱鍥炴锛屻�屽簲鏀堕噾棰濄�嶆槸杩樻病鏀跺洖鏉ョ殑閮ㄥ垎銆�
+ 娉ㄦ剰 鍑哄簱閲戦 = sum(鍑哄簱鏁伴噺 * 6浣嶅皬鏁扮殑鍚◣鍗曚环)锛屼細甯︽湁銆屽垎銆嶄互涓嬬殑闆跺ご锛�
+ 鑰屽洖娆炬槸鎸夊垎褰曞叆鐨勬暣鏁伴噾棰濓紝涓よ�呯浉鍑忎細鍑虹幇 0.0045銆�0.004 杩欑被鏃犳剰涔夌殑灏惧樊锛�
+ 鍥犳鍗曟潯鍙拌处鐨勫簲鏀堕噾棰濇寜鍒嗚绠楋紝鍒嗕互涓嬬殑灏惧樊涓嶈鍏ャ��
+ 娉ㄦ剰 蹇呴』鍏堟寜鍙拌处绠楀ソ搴旀敹銆佸啀鎸夊鎴锋眹鎬伙紙涓� customewTransactionsDetails 鍙e緞涓�鑷达級銆�
+ 鑻ュ厛鎸夊鎴锋眹鎬诲啀鍙栨暣锛屽悇瀹跺彴璐︾殑灏惧樊浼氱疮鍔狅紝鍑虹幇銆屼富琛� 0.01銆佹槑缁嗗叏鏄� 0銆嶇殑瀵逛笉涓婇棶棰樸��
+ 娉ㄦ剰 鈽� 鍑哄簱閲戦鎸夈�岄攢鍞槑缁嗙殑鍚◣鎬婚銆嶆姌绠楋紝涓嶈兘鐩存帴鐢ㄣ�屽嚭搴撴暟閲� 脳 鍚◣鍗曚环銆嶏細
+ 鍑哄簱閲戦 = 危 ROUND( 璇ユ槑缁嗗惈绋庢�婚 脳 LEAST(1, 璇ユ槑缁嗗凡鍑哄簱閲� / 璇ユ槑缁嗛攢鍞暟閲�), 2 )
+ 鍘熷洜锛氶攢鍞暟閲忓彲鑳藉甫 3 浣嶅皬鏁帮紙濡� 47.328锛夛紝鑰屽嚭搴撴暟閲忔寜鎵嬪唽 搂5.6 鍙繚鐣� 2 浣嶏紙47.33锛夈��
+ 鐩存帴鐩镐箻寰� 47.33 脳 172 = 8140.76锛岃�屽紑绁ㄩ噾棰濇槸 47.328 脳 172 = 8140.42锛�
+ 鍑┖澶氬嚭 0.34 鐨勫簲鏀� 鈥斺�� 瀹炴祴榛戦緳姹熷寳鐩涘6鍏冲垎鍏徃 13370.02 宸插叏棰濆洖娆撅紝
+ 椤甸潰涓婂嵈浠嶆樉绀烘瑺 0.34銆�
+ 路 LEAST(1, ...) 鐢ㄦ潵灏侀《锛氬嚭搴撻噺 鈮� 閿�鍞暟閲忔椂鏈�澶氱畻鏁存潯鏄庣粏鐨勫紑绁ㄩ噾棰濓紝瓒呭彂涓嶅鍔犲簲鏀讹紱
+ 鍑哄簱閲� < 閿�鍞暟閲忥紙閮ㄥ垎鍙戣揣锛夋椂鎸夋瘮渚嬭銆�
+ 路 姣忔潯鏄庣粏鍗曠嫭 ROUND 鍒板垎锛岄伩鍏� 0.095 杩欑被鍒嗕互涓嬮浂澶寸疮绉垚搴旀敹銆�
+ 娉ㄦ剰 鍑哄簱閲戦鎸夊彴璐� (sales_ledger.id) 鑱氬悎锛屽悓涓�鍙戣揣鍗曞鎵瑰彿鍑哄簱鏃朵笉浼氶噸澶嶈鏁般��
+ -->
+ <select id="customewTransactions" resultType="com.ruoyi.sales.vo.CustomerTransactionsVo">
+ select T1.customer_id,
+ c.customer_name,
+ T1.contractAmounts,
+ IFNULL(T2.receiptPaymentAmount, 0) AS receiptPaymentAmount,
+ IFNULL(T5.receiptableAmount, 0) AS receiptableAmount
+ from (select customer_id, sum(contract_amount) as contractAmounts from sales_ledger group by customer_id) T1
+ left join (select customer_id, sum(collection_amount) as receiptPaymentAmount from account_sales_collection group by customer_id) T2 on T1.customer_id = T2.customer_id
+ left join (
+ select
+ sl.customer_id,
+ sum(GREATEST(
+ TRUNCATE(IFNULL(T3.outboundAmount, 0) - IFNULL(T4.returnAmount, 0)
+ - IFNULL(T6.receiptPaymentAmount, 0), 2),
+ 0)) AS receiptableAmount
+ from sales_ledger sl
+ left join (
+ select
+ sl.id,
+ sum(t.collection_amount) as receiptPaymentAmount
+ from (
+ select
+ ascc.collection_amount,
+ s.sales_ledger_id
+ from account_sales_collection ascc
+ left join stock_out_record sor on FIND_IN_SET(sor.id, ascc.stock_out_record_ids) > 0
+ left join shipping_info s on sor.record_id = s.id
+ where sor.record_type='13'
+ and sor.approval_status=1
+ group by ascc.id, s.sales_ledger_id
+ ) t
+ left join sales_ledger sl on t.sales_ledger_id = sl.id
+ group by sl.id
+ ) T6 on T6.id = sl.id
+ left join (
+ SELECT
+ sl.id,
+ sum(ROUND(slp.tax_inclusive_total_price
+ * LEAST(1, ship.out_qty / NULLIF(slp.quantity, 0)), 2)) as outboundAmount
+ FROM (
+ SELECT sor.record_id AS shipping_id, SUM(sor.stock_out_num) AS out_qty
+ FROM stock_out_record sor
+ WHERE sor.record_type='13' AND sor.approval_status=1
+ GROUP BY sor.record_id
+ ) ship
+ JOIN shipping_info s ON s.id = ship.shipping_id
+ LEFT JOIN sales_ledger sl ON s.sales_ledger_id = sl.id
+ LEFT JOIN sales_ledger_product slp ON s.sales_ledger_product_id = slp.id
+ WHERE slp.type = 1
+ group by sl.id
+ ) T3 on T3.id = sl.id
+ left join (
+ select
+ sl.id,
+ sum(rm.refund_amount) as returnAmount
+ from return_management rm
+ left join shipping_info si on rm.shipping_id = si.id
+ left join sales_ledger sl on si.sales_ledger_id = sl.id
+ where rm.status=1
+ group by sl.id
+ ) T4 on T4.id = sl.id
+ group by sl.customer_id
+ ) T5 on T5.customer_id = T1.customer_id
+ left join customer c on T1.customer_id = c.id
+ <where>
+ <if test="customerName!=null and customerName!=''">
+ AND c.customer_name LIKE CONCAT('%', #{customerName}, '%')
+ </if>
+ </where>
+ order by T1.customer_id desc
+ </select>
+ <!--
+ 瀹㈡埛寰�鏉ユ槑缁嗭紙鎸夐攢鍞彴璐︼級锛氬簲鏀堕噾棰� = 璇ュ彴璐﹀凡鍑哄簱 鈭� 宸查��璐� 鈭� 宸插洖娆俱��
+ 鍗曟潯鍥炴鍙粺璁′竴娆★細鍚屼竴鍥炴鍙兘鍚屾椂鍛戒腑璇ュ彴璐︾殑澶氭潯鍑哄簱璁板綍锛�
+ 鍏堢敤 GROUP BY ascc.id, sl.id 鍘婚噸锛屽啀鎸夊彴璐︽眰鍜屻��
+ 閲戦鍚屾牱鎸夊垎锛�2 浣嶅皬鏁帮級璁$畻锛屽垎浠ヤ笅鐨勫熬宸笉璁″叆銆�
+ -->
+ <select id="customewTransactionsDetails"
+ resultType="com.ruoyi.sales.vo.CustomerTransactionsDetailsVo">
+ select sl.id salesLedgerId,
+ sl.sales_contract_no,
+ sl.execution_date,
+ sl.contract_amount,
+ IFNULL(T1.receiptPaymentAmount, 0) AS receiptPaymentAmount,
+ GREATEST(
+ TRUNCATE(IFNULL(T2.outboundAmount, 0) - IFNULL(T3.returnAmount, 0)
+ - IFNULL(T1.receiptPaymentAmount, 0), 2),
+ 0) AS receiptableAmount
+ from sales_ledger sl
+ left join (
+ select
+ sl.id,
+ sum(t.collection_amount) as receiptPaymentAmount
+ from (
+ select
+ ascc.collection_amount,
+ s.sales_ledger_id
+ from account_sales_collection ascc
+ left join stock_out_record sor on FIND_IN_SET(sor.id, ascc.stock_out_record_ids) > 0
+ left join shipping_info s on sor.record_id = s.id
+ where sor.record_type='13'
+ and sor.approval_status=1
+ group by ascc.id, s.sales_ledger_id
+ ) t
+ left join sales_ledger sl on t.sales_ledger_id = sl.id
+ group by sl.id
+ )T1 on T1.id = sl.id
+ left join (
+ SELECT
+ sl.id,
+ sum(ROUND(slp.tax_inclusive_total_price
+ * LEAST(1, ship.out_qty / NULLIF(slp.quantity, 0)), 2)) as outboundAmount
+ FROM (
+ SELECT sor.record_id AS shipping_id, SUM(sor.stock_out_num) AS out_qty
+ FROM stock_out_record sor
+ WHERE sor.record_type='13' AND sor.approval_status=1
+ GROUP BY sor.record_id
+ ) ship
+ JOIN shipping_info s ON s.id = ship.shipping_id
+ LEFT JOIN sales_ledger sl ON s.sales_ledger_id = sl.id
+ LEFT JOIN sales_ledger_product slp ON s.sales_ledger_product_id = slp.id
+ WHERE slp.type = 1
+ group by sl.id
+ )T2 on T2.id = sl.id
+ left join (
+ select sl.id,
+ sum(rm.refund_amount) as returnAmount
+ from return_management rm
+ left join shipping_info si on rm.shipping_id = si.id
+ left join sales_ledger sl on si.sales_ledger_id = sl.id
+ where rm.status=1
+ group by sl.id
+ )T3 on T3.id = sl.id
+ where sl.customer_id = #{customerId}
+ order by sl.id desc
+ </select>
+</mapper>
--
Gitblit v1.9.3