工程预付款统计功能开发

This commit is contained in:
lSun 2025-04-16 18:52:44 +08:00
parent 11086496c9
commit f13a35d40a
9 changed files with 135 additions and 117 deletions

View File

@ -35,7 +35,10 @@ public class OperationsBean {
private String operator;//更新人 private String operator;//更新人
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
private BigDecimal currentBalance;//当前余额 private BigDecimal currentBalance;//未进行新增修改时余额就是此余额加上调整金额就是现在的金额
@JsonSerialize(using = ToStringSerializer.class)
private BigDecimal currentBalanceNew;//当前余额
private String userId; //用户id private String userId; //用户id
private String userName; //用户名 private String userName; //用户名

View File

@ -98,7 +98,10 @@ public class PrepaymentServiceImpl implements PrepaymentService {
@Override @Override
public void delOperations(Long id) { public void delOperations(Long id) {
String userId =UserUtil.getLoginUser().getId().toString(); String userId =UserUtil.getLoginUser().getId().toString();
OperationsBean bean = dao.getOperationsById(id.toString());
bean.setCurrentBalanceNew(bean.getCurrentBalance());
dao.delOperations(id,userId); dao.delOperations(id,userId);
dao.updatePrepaymentId(bean);
} }
/** /**

View File

@ -6,17 +6,17 @@
<insert id="addPrepayment"> <insert id="addPrepayment">
INSERT INTO `bm_project_prepayment` (`project_code`, `project_name`, `business_unit`, `contact_unit`, `type`, INSERT INTO `bm_project_prepayment` (`project_code`, `project_name`, `business_unit`, `contact_unit`, `type`,
`initial_amount`, `first_payment_date`, `current_balance`, `remarks`,`operator`,`is_active`) `initial_amount`, `first_payment_date`, `current_balance`, `remarks`,
VALUES (#{projectCode},#{projectName},#{businessUnit},#{contactUnit},#{type}, `operator`, `is_active`)
#{initialAmount},#{firstPaymentDate},#{initialAmount},#{remarks},#{operator},'1') VALUES (#{projectCode}, #{projectName}, #{businessUnit}, #{contactUnit}, #{type},
#{initialAmount}, #{firstPaymentDate}, #{initialAmount}, #{remarks}, #{operator}, '1')
</insert> </insert>
<insert id="addOperations"> <insert id="addOperations">
INSERT INTO `bm_monthly_operations` ( `p_id`, `month`, `operation_type`, `amount`, `executor`, `remarks`, INSERT INTO `bm_monthly_operations` (`p_id`, `month`, `operation_type`, `amount`, `executor`, `remarks`,
`next_month`, `proposed_amount`, `handler`, `next_remarks`,`is_active`,`operator` ) `next_month`, `proposed_amount`, `handler`, `next_remarks`, `is_active`,
VALUES `operator`,`current_balance`)
( VALUES (#{prepaymentId},
#{prepaymentId},
#{month}, #{month},
#{operationType}, #{operationType},
#{amount}, #{amount},
@ -25,10 +25,13 @@
#{nextMonth}, #{nextMonth},
#{proposedAmount}, #{proposedAmount},
#{handler}, #{handler},
#{nextRemarks},'1',#{operator}) #{nextRemarks}, '1', #{operator},#{currentBalance})
</insert> </insert>
<update id="updatePrepaymentId"> <update id="updatePrepaymentId">
UPDATE `bm_project_prepayment` SET `current_balance` = #{currentBalance}, `operator` = #{operator} WHERE `id` = #{prepaymentId} UPDATE `bm_project_prepayment`
SET `current_balance` = #{currentBalanceNew},
`operator` = #{operator}
WHERE `id` = #{prepaymentId}
</update> </update>
<update id="updatePrepayment"> <update id="updatePrepayment">
UPDATE `bm_project_prepayment` SET `operator` = #{operator} UPDATE `bm_project_prepayment` SET `operator` = #{operator}
@ -59,11 +62,11 @@
<if test="remarks != null"> <if test="remarks != null">
,remarks = #{remarks} ,remarks = #{remarks}
</if> </if>
WHERE `id` = #{id} WHERE `id` = #{id}
</update> </update>
<update id="updateOperations"> <update id="updateOperations">
UPDATE `bm_monthly_operations` SET `month` = #{month}, `operation_type` = #{operationType}, UPDATE `bm_monthly_operations` SET `month` = #{month}, `operation_type` = #{operationType},
`amount` = #{amount}, `executor` = #{executor},operator = #{operator}, `amount` = #{amount}, `executor` = #{executor},operator = #{operator}
<if test="remarks != null"> <if test="remarks != null">
,remarks = #{remarks} ,remarks = #{remarks}
</if> </if>
@ -83,128 +86,118 @@
</update> </update>
<delete id="delPrepayment"> <delete id="delPrepayment">
UPDATE `bm_project_prepayment` SET `is_active` = '0' , operator = #{userId} WHERE `id` = #{id} UPDATE `bm_project_prepayment`
SET `is_active` = '0',
operator = #{userId}
WHERE `id` = #{id}
</delete> </delete>
<delete id="delOperations"> <delete id="delOperations">
UPDATE `bm_monthly_operations` SET `is_active` = '0' , operator = #{userId} WHERE `id` = #{id} UPDATE `bm_monthly_operations`
SET `is_active` = '0',
operator = #{userId}
WHERE `id` = #{id}
</delete> </delete>
<select id="getList" resultType="com.bonus.boot.manager.ca.bm.entity.PrepaymentBean"> <select id="getList" resultType="com.bonus.boot.manager.ca.bm.entity.PrepaymentBean">
SELECT SELECT
id, bm.id,
project_code as projectCode, bm.project_code as projectCode,
project_name as projectName, bm.project_name as projectName,
business_unit as businessUnit, bm.business_unit as businessUnit,
contact_unit as contactUnit, bm.contact_unit as contactUnit,
type, bm.type,
initial_amount as initialAmount, bm.initial_amount as initialAmount,
first_payment_date as firstPaymentDate, bm.first_payment_date as firstPaymentDate,
current_balance as currentBalance, bm.current_balance as currentBalance,
remarks, bm.remarks,
operator, u.username as operator,
created_time as createdTime, bm.created_time as createdTime,
updated_time as updatedTime, bm.updated_time as updatedTime,
GREATEST(PERIOD_DIFF(DATE_FORMAT(CURDATE(), '%Y%m'), DATE_FORMAT(first_payment_date, '%Y%m')), 0) AS agingMonths, GREATEST(PERIOD_DIFF(DATE_FORMAT(CURDATE(), '%Y%m'), DATE_FORMAT(bm.first_payment_date, '%Y%m')), 0) AS
CASE agingMonths,
WHEN current_balance = 0 THEN 0 CASE
ELSE 1 WHEN bm.current_balance = 0 THEN 0
END AS state ELSE 1
END AS state
FROM FROM
`bm_project_prepayment` `bm_project_prepayment` bm
WHERE is_active = '1' LEFT JOIN sys_user u ON u.id = bm.operator
WHERE bm.is_active = '1'
<if test="params.keyword != null and params.keyword != ''"> <if test="params.keyword != null and params.keyword != ''">
AND ( AND (
project_code LIKE CONCAT('%', #{params.keyword}, '%') bm.project_code LIKE CONCAT('%', #{params.keyword}, '%')
OR project_name LIKE CONCAT('%', #{params.keyword}, '%') OR bm.project_name LIKE CONCAT('%', #{params.keyword}, '%')
OR business_unit LIKE CONCAT('%', #{params.keyword}, '%') OR bm.business_unit LIKE CONCAT('%', #{params.keyword}, '%')
OR contact_unit LIKE CONCAT('%', #{params.keyword}, '%') OR bm.contact_unit LIKE CONCAT('%', #{params.keyword}, '%')
OR type LIKE CONCAT('%', #{params.keyword}, '%') OR bm.type LIKE CONCAT('%', #{params.keyword}, '%')
) )
</if> </if>
<if test="params.state =='1' || params.state ==1"> <if test="params.state =='1' || params.state ==1">
AND current_balance>0 AND bm.current_balance>0
</if> </if>
<if test="params.state =='2' || params.state ==2"> <if test="params.state =='2' || params.state ==2">
AND current_balance=0 AND bm.current_balance=0
</if> </if>
ORDER BY updated_time DESC ORDER BY bm.updated_time DESC
</select> </select>
<select id="getListById" resultType="com.bonus.boot.manager.ca.bm.entity.PrepaymentBean"> <select id="getListById" resultType="com.bonus.boot.manager.ca.bm.entity.PrepaymentBean">
SELECT SELECT id,
id, project_code as projectCode,
project_code as projectCode, project_name as projectName,
project_name as projectName, business_unit as businessUnit,
business_unit as businessUnit, contact_unit as contactUnit,
contact_unit as contactUnit, type,
type, initial_amount as initialAmount,
initial_amount as initialAmount, first_payment_date as firstPaymentDate,
first_payment_date as firstPaymentDate, current_balance as currentBalance,
current_balance as currentBalance, remarks,
remarks, operator,
operator, created_time as createdTime,
created_time as createdTime, updated_time as updatedTime,
updated_time as updatedTime, GREATEST(PERIOD_DIFF(DATE_FORMAT(CURDATE(), '%Y%m'), DATE_FORMAT(first_payment_date, '%Y%m')),
GREATEST(PERIOD_DIFF(DATE_FORMAT(CURDATE(), '%Y%m'), DATE_FORMAT(first_payment_date, '%Y%m')), 0) AS agingMonths, 0) AS agingMonths,
CASE CASE
WHEN current_balance = 0 THEN 0 WHEN current_balance = 0 THEN 0
ELSE 1 ELSE 1
END AS state END AS state
FROM FROM `bm_project_prepayment`
`bm_project_prepayment` WHERE is_active = '1'
WHERE is_active = '1' and id= #{id} and id = #{id}
</select> </select>
<select id="getOperationsList" resultType="com.bonus.boot.manager.ca.bm.entity.OperationsBean"> <select id="getOperationsList" resultType="com.bonus.boot.manager.ca.bm.entity.OperationsBean">
SELECT SELECT bm.id,
id, bm.p_id as prepaymentId, bm.month, bm.operation_type as operationType,
p_id as prepaymentId, bm.amount, u2.username as executor, bm.remarks, bm.next_month as nextMonth,
month, bm.proposed_amount as proposedAmount, bm.handler, bm.next_remarks as nextRemarks,
operation_type as operationType, u.username as operator, bm.created_time as createdTime, bm.updated_time as updatedTime
amount, FROM `bm_monthly_operations` bm
executor, LEFT JOIN sys_user u ON u.id = bm.operator
remarks, LEFT JOIN sys_user u2 ON u2.id = bm.executor
next_month as nextMonth, WHERE bm.is_active = '1' AND bm.p_id = #{params.prepaymentId}
proposed_amount as proposedAmount, ORDER BY bm.updated_time DESC
handler,
next_remarks as nextRemarks,
operator,
created_time as createdTime,
updated_time as updatedTime
FROM `bm_monthly_operations`
WHERE is_active = '1' AND p_id = #{params.prepaymentId}
ORDER BY updated_time DESC
</select> </select>
<select id="getMath" resultType="java.lang.Integer"> <select id="getMath" resultType="java.lang.Integer">
SELECT COUNT(*) FROM `bm_monthly_operations` SELECT COUNT(*) FROM `bm_monthly_operations`
WHERE p_id = #{prepaymentId} and `month` = #{month} AND is_active = '1' WHERE p_id = #{prepaymentId} and `month` = #{month} AND is_active = '1'
<if test="id !=null "> <if test="id !=null ">
and id != #{id} and id != #{id}
</if> </if>
</select> </select>
<select id="getOperationsById" resultType="com.bonus.boot.manager.ca.bm.entity.OperationsBean"> <select id="getOperationsById" resultType="com.bonus.boot.manager.ca.bm.entity.OperationsBean">
SELECT SELECT bm.id,
bm.id, p_id as prepaymentId, month, operation_type as operationType, amount,
p_id as prepaymentId, u2.username as executor, remarks, next_month as nextMonth,
month, proposed_amount as proposedAmount, handler, next_remarks as nextRemarks,
operation_type as operationType, u.username as operator, created_time as createdTime, updated_time as updatedTime,
amount, u.id as userId, u.username as userName,bm.current_balance as currentBalance
executor,
remarks,
next_month as nextMonth,
proposed_amount as proposedAmount,
handler,
next_remarks as nextRemarks,
u.username as operator,
created_time as createdTime,
updated_time as updatedTime,
u.id as userId,
u.username as userName
FROM `bm_monthly_operations` bm FROM `bm_monthly_operations` bm
LEFT JOIN sys_user u ON u.id = bm.operator LEFT JOIN sys_user u ON u.id = bm.operator
LEFT JOIN sys_user u2 ON u2.id = bm.executor
WHERE bm.is_active = '1' AND bm.id= #{id} WHERE bm.is_active = '1' AND bm.id= #{id}
</select> </select>
</mapper> </mapper>

View File

@ -38,4 +38,14 @@ function getCurrentMonth() {
var year = now.getFullYear(); var year = now.getFullYear();
var month = now.getMonth() + 1; // 月份从 0 开始 var month = now.getMonth() + 1; // 月份从 0 开始
return year + '-' + (month < 10 ? '0' + month : month); return year + '-' + (month < 10 ? '0' + month : month);
}
function getToday() {
var now = new Date();
var year = now.getFullYear();
var month = now.getMonth() + 1; // 月份从 0 开始
var day = now.getDate();
return year + '-' +
(month < 10 ? '0' + month : month) + '-' +
(day < 10 ? '0' + day : day);
} }

View File

@ -104,6 +104,7 @@ function initData(){
$("#proposedAmount").val(info.proposedAmount); $("#proposedAmount").val(info.proposedAmount);
$("#handler").val(info.handler); $("#handler").val(info.handler);
$("#nextRemarks").val(info.nextRemarks); $("#nextRemarks").val(info.nextRemarks);
currentBalance = info.currentBalance;
} }
}, },
error: function (XMLHttpRequest, textStatus, e) { error: function (XMLHttpRequest, textStatus, e) {
@ -118,21 +119,29 @@ function initData(){
function calculateNewBalance() { function calculateNewBalance() {
var amount = parseFloat($('#amount').val()) || 0; var amount = parseFloat($('#amount').val()) || 0;
var operationType = $('#operationType').val(); var operationType = $('#operationType').val();
var num = currentBalance;
// 将 currentBalance 转换为数字
num = parseFloat(num) || 0;
if (operationType === '1') { if (operationType === '1') {
// 冲销是减少余额 // 冲销是减少余额
currentBalance = currentBalance - amount; num = num - amount;
} else { } else {
// 新增是增加余额 // 新增是增加余额
currentBalance = currentBalance + amount; num = num + amount;
} }
return currentBalance.toFixed(2); // 确保返回值是保留两位小数的字符串
console.log("最终余额:", num.toFixed(2));
return num.toFixed(2);
} }
function add(formData) { function add(formData) {
// 计算更新后的余额 //先保证未进行冲销或新增金额
var currentBalance = calculateNewBalance();
// 添加更新后的余额到表单数据
formData.field.currentBalance = currentBalance; formData.field.currentBalance = currentBalance;
// 计算更新后的余额
var currentBalanceNew = calculateNewBalance();
// 添加更新后的余额到表单数据
formData.field.currentBalanceNew = currentBalanceNew;
formData.field.prepaymentId = prepaymentId; formData.field.prepaymentId = prepaymentId;
formData.field.executor = $("#prepaymentUserId").val(); formData.field.executor = $("#prepaymentUserId").val();
@ -166,6 +175,7 @@ function add(formData) {
top.layer.close(addLoadingMsg); //再执行关闭 top.layer.close(addLoadingMsg); //再执行关闭
parent.layer.msg(tip + '成功', { icon: 1, time: 2000 }); parent.layer.msg(tip + '成功', { icon: 1, time: 2000 });
parent.table.reload('menuTable'); parent.table.reload('menuTable');
parent.initData()
} else { } else {
top.layer.close(addLoadingMsg); //再执行关闭 top.layer.close(addLoadingMsg); //再执行关闭
if(data.resMsg ==="当前月份已经存在"){ if(data.resMsg ==="当前月份已经存在"){

View File

@ -6,7 +6,8 @@ layui.use(['table', 'layer', 'laydate', 'jquery', 'form'], function(){
laydate = layui.laydate; laydate = layui.laydate;
// 渲染 // 渲染
laydate.render({ laydate.render({
elem: '#firstPaymentDate' elem: '#firstPaymentDate',
max: getToday(),
}); });
initData(); initData();
form.render(); form.render();

View File

@ -176,6 +176,7 @@ function del(id) {
url: ctxPath + '/prepayment/delOperations/' + id, url: ctxPath + '/prepayment/delOperations/' + id,
success: function (data) { success: function (data) {
table.reload('menuTable'); table.reload('menuTable');
initData()
layer.msg("删除成功"); layer.msg("删除成功");
} }
}); });

View File

@ -129,14 +129,14 @@
<div class="form-row"> <div class="form-row">
<div class="form-label required">经办人:</div> <div class="form-label required">经办人:</div>
<div class="form-input"> <div class="form-input">
<input type="text" class="layui-input" name="executor" id="executor" style="background-color: #eeeeee;" readonly> <input type="text" class="layui-input" name="executor" id="executor" style="background-color: #eeeeee;" readonly>
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<div class="form-label">备注:</div> <div class="form-label">备注:</div>
<div class="form-input"> <div class="form-input">
<textarea class="layui-input" name="remarks" id="remarks" ></textarea> <textarea class="layui-input" name="remarks" id="remarks" maxlength="200" ></textarea>
</div> </div>
</div> </div>
</div> </div>
@ -146,7 +146,7 @@
<div class="form-row"> <div class="form-row">
<div class="form-label">月度冲销计划及措施:</div> <div class="form-label">月度冲销计划及措施:</div>
<div class="form-input"> <div class="form-input">
<textarea class="layui-input" name="nextMonth" id="nextMonth" ></textarea> <textarea class="layui-input" name="nextMonth" id="nextMonth" maxlength="200" ></textarea>
</div> </div>
</div> </div>
@ -160,14 +160,14 @@
<div class="form-row"> <div class="form-row">
<div class="form-label ">责任人:</div> <div class="form-label ">责任人:</div>
<div class="form-input"> <div class="form-input">
<input type="text" class="layui-input" name="handler" id="handler" > <input type="text" class="layui-input" name="handler" id="handler" maxlength="30" >
</div> </div>
</div> </div>
<div class="form-row"> <div class="form-row">
<div class="form-label">备注:</div> <div class="form-label">备注:</div>
<div class="form-input"> <div class="form-input">
<textarea class="layui-input" name="nextRemarks" id="nextRemarks"></textarea> <textarea class="layui-input" name="nextRemarks" id="nextRemarks" maxlength="200"></textarea>
</div> </div>
</div> </div>
</div> </div>

View File

@ -150,9 +150,6 @@
<button class="layui-btn layui-btn-primary"> <button class="layui-btn layui-btn-primary">
导出 导出
</button> </button>
<button class="layui-btn layui-btn-primary">
删除
</button>
</div> </div>
</div> </div>