From 2c66e03ba8ac6e1cea9882f54b4f7f2ef449e4c4 Mon Sep 17 00:00:00 2001 From: winter <664946893@qq.com> Date: Thu, 28 Nov 2024 20:08:18 +0800 Subject: [PATCH] fix --- .../market/WxFinanceController.java | 27 ++- .../domain/dto/FinanceReceiveCalcuteDTO.java | 1 + .../com/iformall/domain/po/WxAllBill.java | 7 +- .../com/iformall/mapper/WxAllBillMapper.java | 4 + .../iformall/service/WxAllBillService.java | 3 + .../iformall/service/WxFinanceService.java | 7 +- .../service/helper/WxBillAllHelper.java | 4 - .../service/impl/WxAllBillServiceImpl.java | 12 + .../service/impl/WxFinanceServiceImpl.java | 219 ++++++++++++++---- .../java/com/iformall/utils/Constant.java | 3 + .../main/resources/mapper/WxAllBillMapper.xml | 14 ++ 11 files changed, 252 insertions(+), 49 deletions(-) diff --git a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxFinanceController.java b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxFinanceController.java index c02857125..429c77e1b 100644 --- a/mallinkAdmin/src/main/java/com/iformall/controller/market/WxFinanceController.java +++ b/mallinkAdmin/src/main/java/com/iformall/controller/market/WxFinanceController.java @@ -22,6 +22,7 @@ import com.iformall.domain.po.WxFlowModel; import com.iformall.domain.po.WxShop; import com.iformall.domain.po.base.BaseEntity; import com.iformall.domain.po.base.TenantEntity; +import com.iformall.domain.vo.FinanceAdvanceBillVo; import com.iformall.domain.vo.FinanceBillSetoffSum; import com.iformall.domain.vo.WxFinanceReceiveBillSum; import com.iformall.domain.vo.WxFinanceReceiveCountVo; @@ -281,14 +282,36 @@ public class WxFinanceController extends BaseController { return new ResultData(); } - //查询铺位预收总计 + //押金总计 + @GetMapping("getMerchantDeposit") + public ResultData getMerchantDeposit(@ModelAttribute WxShop record) { + record.updateTenantInfo(getTenantInfo()); + if (null == record.getId()) { + return new ResultData(Result.ERROR,"请选择房源"); + } + BigDecimal sum = wxFinanceService.getBillDepositSum(record); + return new ResultData(sum); + } + + //预收总计 @GetMapping("getMerchantAdvance") public ResultData getMerchantAdvance(@ModelAttribute WxShop record) { record.updateTenantInfo(getTenantInfo()); if (null == record.getId()) { return new ResultData(Result.ERROR,"请选择房源"); } - FinanceBillSetoffSum sum = wxFinanceService.getBillSetoffSum(record); + BigDecimal sum = wxFinanceService.getBillSetoffSum(record); + return new ResultData(sum); + } + + @GetMapping("getMerchantAdvanceDepositList") + public ResultData getMerchantAdvanceDepositList(@ModelAttribute WxShop record) { + record.updateTenantInfo(getTenantInfo()); + if (null == record.getId()) { + return new ResultData(Result.ERROR,"请选择房源"); + } + //FinanceBillSetoffSum sum + List sum = wxFinanceService.getMerchantAdvanceDepositList(record); return new ResultData(sum); } diff --git a/mallinkService/src/main/java/com/iformall/domain/dto/FinanceReceiveCalcuteDTO.java b/mallinkService/src/main/java/com/iformall/domain/dto/FinanceReceiveCalcuteDTO.java index ca0bc9251..f149b2ea2 100644 --- a/mallinkService/src/main/java/com/iformall/domain/dto/FinanceReceiveCalcuteDTO.java +++ b/mallinkService/src/main/java/com/iformall/domain/dto/FinanceReceiveCalcuteDTO.java @@ -17,4 +17,5 @@ public class FinanceReceiveCalcuteDTO extends TenantEntity{ private BigDecimal totalSetoff; private BigDecimal totalRemainPay; private BigDecimal totalCut; + private BigDecimal totalNeedPay; } diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxAllBill.java b/mallinkService/src/main/java/com/iformall/domain/po/WxAllBill.java index f631fb34d..59b1e57fc 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxAllBill.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxAllBill.java @@ -245,7 +245,10 @@ public class WxAllBill extends TenantEntity { if (StringUtils.isBlank(returnPay)) { returnPay = "0"; } - return new BigDecimal(pay).subtract(new BigDecimal(returnPay)).toPlainString(); + if (StringUtils.isBlank(useMoney)) { + useMoney = "0"; + } + return new BigDecimal(pay).subtract(new BigDecimal(returnPay)).subtract(new BigDecimal(useMoney)).toPlainString(); } @Excel(name = "备注", width = 20, orderNum = "9") @@ -423,6 +426,8 @@ public class WxAllBill extends TenantEntity { @TableField(exist = false) public Integer advanceHasMoney; @TableField(exist = false) + private Integer depositHasMoney; + @TableField(exist = false) private String energyFeesIdStr; @TableField(exist = false) private String cusLinkPerson; diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxAllBillMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxAllBillMapper.java index 49a19228f..c0e7af222 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxAllBillMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxAllBillMapper.java @@ -8,6 +8,8 @@ import com.iformall.domain.vo.WxBillHotNotify; import com.iformall.domain.vo.WxBillNotify; import com.iformall.domain.vo.WxBillSum; import org.apache.ibatis.annotations.Param; + +import java.math.BigDecimal; import java.util.List; /** @@ -21,6 +23,8 @@ public interface WxAllBillMapper extends CommonMapper { List getShopIdList(WxAllBill record); + BigDecimal getMerchantAdvanceGroupSum(WxAllBill wxBillRent); + BigDecimal getMerchantDepositGroupSum(WxAllBill wxBillRent); List getMerchantAdvanceGroupSumList(WxAllBill wxBillRent); List getBillNotifyList(WxAllBill record); diff --git a/mallinkService/src/main/java/com/iformall/service/WxAllBillService.java b/mallinkService/src/main/java/com/iformall/service/WxAllBillService.java index 744a1a1f9..24c923ce8 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxAllBillService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxAllBillService.java @@ -18,6 +18,7 @@ import com.iformall.domain.vo.WxBillSum; import com.iformall.enums.EnumBillAction; import com.iformall.enums.EnumBillStatus; +import java.math.BigDecimal; import java.util.List; import javax.servlet.http.HttpServletRequest; @@ -56,6 +57,8 @@ public interface WxAllBillService { void completeBill(EnumBillStatus status,WxShop wxShop,MallUserInfo user); + BigDecimal getBillSetoffSum(WxAllBill wxBillRent); + BigDecimal getBillDepositSum(WxAllBill wxBillRent); List getMerchantAdvanceGroupSumList(WxAllBill wxBillRent); List list(WxAllBill record); diff --git a/mallinkService/src/main/java/com/iformall/service/WxFinanceService.java b/mallinkService/src/main/java/com/iformall/service/WxFinanceService.java index 35ff8d5d5..06891315e 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxFinanceService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxFinanceService.java @@ -1,5 +1,6 @@ package com.iformall.service; +import java.math.BigDecimal; import java.util.Date; import java.util.List; import java.util.Map; @@ -25,6 +26,7 @@ import com.iformall.domain.po.WxFinanceReceivePayway; import com.iformall.domain.po.WxFinanceReceiveSetoff; import com.iformall.domain.po.WxShop; import com.iformall.domain.po.base.TenantEntity; +import com.iformall.domain.vo.FinanceAdvanceBillVo; import com.iformall.domain.vo.FinanceBillSetoffSum; import com.iformall.domain.vo.WxFinanceReceiveBillSum; import com.iformall.domain.vo.WxFinanceReceiveCountVo; @@ -62,10 +64,13 @@ public interface WxFinanceService { void updateReceiveStatus(WxFinanceReceive record); //预收款 List calcuetSetOff(FinanceSetOffDTO dto,MallUserInfo user); - FinanceBillSetoffSum getBillSetoffSum(WxShop wxShop); //List getSetOffList(FinanceSetOffDTO dto,boolean isMerge); PageInfo receiveSetoffListAsPage(WxFinanceReceive record, Integer pageIndex, Integer pageSize); + BigDecimal getBillSetoffSum(WxShop wxShop); + BigDecimal getBillDepositSum(WxShop wxShop); + List getMerchantAdvanceDepositList(WxShop wxShop); + //增加临时费用 void createTempFees(WxAllBill record,MallUserInfo user); void createTempToPay(WxAllBill record,MallUserInfo user); diff --git a/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java b/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java index 4de77f279..d671a9615 100644 --- a/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java +++ b/mallinkService/src/main/java/com/iformall/service/helper/WxBillAllHelper.java @@ -380,10 +380,6 @@ public class WxBillAllHelper { wxAllBillService.completeBill(status,wxShop, user); } - public List getMerchantAdvanceGroupSumList(WxAllBill bill) { - return wxAllBillService.getMerchantAdvanceGroupSumList(bill); - } - /** * 退租: * 账单开始时间>= 今天,并且账单是 WAIT_PAY,NOT_PAID,NOT_EXPIRED,BAD 变为INVALID,如果已付了款,需要退回 diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxAllBillServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxAllBillServiceImpl.java index a8d63c970..27cd732ac 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxAllBillServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxAllBillServiceImpl.java @@ -544,6 +544,18 @@ public class WxAllBillServiceImpl extends WxBillBaseService implements WxAllBill } + @Override + public BigDecimal getBillSetoffSum(WxAllBill record) { + updateQueryParam(record); + return wxAllBillMapper.getMerchantAdvanceGroupSum(record); + } + + @Override + public BigDecimal getBillDepositSum(WxAllBill record) { + updateQueryParam(record); + return wxAllBillMapper.getMerchantDepositGroupSum(record); + } + @Override public List getMerchantAdvanceGroupSumList(WxAllBill record) { updateQueryParam(record); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxFinanceServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxFinanceServiceImpl.java index 4d87c72bb..174e9dd4b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxFinanceServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxFinanceServiceImpl.java @@ -241,10 +241,35 @@ public class WxFinanceServiceImpl implements WxFinanceService { payway4.setCreateTime(new Date()); payway4.setUpdateTime(new Date()); wxBillPayWayMapper.insert(payway4); + + WxBillPayWay payway5 = new WxBillPayWay(); + payway5.updateTenantInfo(tenantInfo); + payway5.setId(Constant.bill_pay_way_deposit_setoff); + payway5.setName("押金抵扣"); + payway5.setIsDel(EnumYesOrNo.NO.getCode()); + payway5.setIsSystem(EnumYesOrNo.YES.getCode()); + payway5.setCreateTime(new Date()); + payway5.setUpdateTime(new Date()); + wxBillPayWayMapper.insert(payway5); } @Override - public FinanceBillSetoffSum getBillSetoffSum(WxShop record) { + public BigDecimal getBillDepositSum(WxShop record) { + //取账单里面的 + //查询预存账单 + WxAllBill abq = new WxAllBill(); + abq.updateTenantInfo(record); + abq.setShopId(record.getId()); + abq.setDepositHasMoney(EnumYesOrNo.YES.getCode()); + BigDecimal total = wxAllBillService.getBillDepositSum(abq); + if (null == total) { + total = new BigDecimal(0); + } + return total; + } + + @Override + public BigDecimal getBillSetoffSum(WxShop record) { //取账单里面的 //查询预存账单 WxAllBill abq = new WxAllBill(); @@ -252,10 +277,34 @@ public class WxFinanceServiceImpl implements WxFinanceService { abq.setBillType(EnumBillAllType.ADVANCE.getCode()); abq.setShopId(record.getId()); abq.setAdvanceHasMoney(EnumYesOrNo.YES.getCode()); - List advanceList = wxBillAllHelper.getMerchantAdvanceGroupSumList(abq); - BigDecimal total = new BigDecimal(0); - FinanceBillSetoffSum retMap = new FinanceBillSetoffSum(); - List bvolist = new ArrayList(); + BigDecimal total = wxAllBillService.getBillSetoffSum(abq); + if (null == total) { + total = new BigDecimal(0); + } + return total; + } + + @Override + public List getMerchantAdvanceDepositList(WxShop record) { + //取账单里面的 + List bvolist = new ArrayList(); + //查询所有押金 + BigDecimal deposit = getBillDepositSum(record); + if (null != deposit && deposit.compareTo(new BigDecimal(0)) > 0 ) { + FinanceAdvanceBillVo v0 = new FinanceAdvanceBillVo(); + v0.setFeesId(Constant.bill_all_deposit_id); + v0.setFeesName("押金总计"); + v0.setRemain(deposit.toPlainString()); + bvolist.add(v0); + } + + //查询预存账单 + WxAllBill abq = new WxAllBill(); + abq.updateTenantInfo(record); + abq.setBillType(EnumBillAllType.ADVANCE.getCode()); + abq.setShopId(record.getId()); + abq.setAdvanceHasMoney(EnumYesOrNo.YES.getCode()); + List advanceList = wxAllBillService.getMerchantAdvanceGroupSumList(abq); if (null != advanceList && advanceList.size() > 0 ) { WxEnergyFees fat = new WxEnergyFees(); fat.updateTenantInfo(record); @@ -271,13 +320,10 @@ public class WxFinanceServiceImpl implements WxFinanceService { vo.setFeesName(wfat.getName()); } } - total = total.add(new BigDecimal(at.getRemain())); bvolist.add(vo); } } - retMap.setTotal(total); - retMap.setAdvanceList(bvolist); - return retMap; + return bvolist; } //根据预充值收款单来冲抵账单 @@ -347,17 +393,10 @@ public class WxFinanceServiceImpl implements WxFinanceService { if (null == dto.getBills() || dto.getBills().size() <= 0 || null == dto.getFeesId()) { throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请选择账单和抵扣科目"); } - //查询预收科目可冲抵的科目 - WxEnergyFeesSetoff fsq = new WxEnergyFeesSetoff(); - fsq.updateTenantInfo(dto); - fsq.setAdvanceFeesId(dto.getFeesId()); - List setOffFeesIds = wxEnergyService.getAdvanceSetoffFeesids(fsq); - if (null == setOffFeesIds || setOffFeesIds.size() <= 0 ) { - throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"该科目未设置可冲抵科目"); - } - //查询出账单可以抵扣的科目预收项 + //如果是多个店铺的则不能冲抵 Long shopId = null; + List billIdList = new ArrayList(); for (int i = 0 ; i < dto.getBills().size() ; i ++) { WxAllBill be = dto.getBills().get(i); if (null == shopId) { @@ -366,18 +405,57 @@ public class WxFinanceServiceImpl implements WxFinanceService { if (shopId.longValue() != be.getShopId().longValue()) { throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"多个房源合并收款不能冲抵"); } + billIdList.add(be.getId()); } - WxAllBill abq = new WxAllBill(); - abq.updateTenantInfo(dto); - abq.setEnergyFeesId(dto.getFeesId()); - abq.setBillType(EnumBillAllType.ADVANCE.getCode()); - abq.setAdvanceHasMoney(EnumYesOrNo.YES.getCode()); - abq.setSortColumns(SortField.Createtime_ASC); - //如果是多个店铺的则不能冲抵 - abq.setShopId(shopId);; - List advanceList = wxAllBillService.list(abq); - if (null == advanceList || advanceList.size() <= 0 ) { - return null; + + List setOffFeesIds = null; + List advanceList = null; + //如果是押金 + if (dto.getFeesId().longValue() == Constant.bill_all_deposit_id.longValue()){ + WxEnergyFees fq = new WxEnergyFees(); + fq.updateTenantInfo(dto); + List depositTypes = new ArrayList(); + depositTypes.add(EnumBillAllType.RENT_DEPOSIT.getCode()); + depositTypes.add(EnumBillAllType.PROPERTY_DEPOSIT.getCode()); + depositTypes.add(EnumBillAllType.OTHER_DEPOSIT.getCode()); + fq.setBillTypeList(depositTypes); + setOffFeesIds = wxEnergyService.getFeesIdList(fq); + if (null == setOffFeesIds || setOffFeesIds.size() <= 0 ) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"未查询到押金科目"); + } + //查询出账单可以抵扣的押金项 + WxAllBill abq = new WxAllBill(); + abq.updateTenantInfo(dto); + abq.setNotInIds(billIdList); + abq.setDepositHasMoney(EnumYesOrNo.YES.getCode()); + abq.setSortColumns(SortField.Createtime_ASC); + abq.setShopId(shopId);; + advanceList = wxAllBillService.list(abq); + if (null == advanceList || advanceList.size() <= 0 ) { + return null; + } + }else { + //查询预收科目可冲抵的科目 + WxEnergyFeesSetoff fsq = new WxEnergyFeesSetoff(); + fsq.updateTenantInfo(dto); + fsq.setAdvanceFeesId(dto.getFeesId()); + setOffFeesIds = wxEnergyService.getAdvanceSetoffFeesids(fsq); + if (null == setOffFeesIds || setOffFeesIds.size() <= 0 ) { + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"该科目未设置可冲抵科目"); + } + + //查询出账单可以抵扣的科目预收项 + WxAllBill abq = new WxAllBill(); + abq.updateTenantInfo(dto); + abq.setEnergyFeesId(dto.getFeesId()); + abq.setBillType(EnumBillAllType.ADVANCE.getCode()); + abq.setAdvanceHasMoney(EnumYesOrNo.YES.getCode()); + abq.setSortColumns(SortField.Createtime_ASC); + abq.setShopId(shopId);; + advanceList = wxAllBillService.list(abq); + if (null == advanceList || advanceList.size() <= 0 ) { + return null; + } } //账单排序 List bills = dto.getBills(); @@ -407,6 +485,7 @@ public class WxFinanceServiceImpl implements WxFinanceService { retList.add(retb); } } + return retList; } @@ -681,11 +760,7 @@ public class WxFinanceServiceImpl implements WxFinanceService { } } - //TODO 校验金额+减免是不是超过了应收费用 - - - - //冲抵总金额 + //已冲抵总金额 BigDecimal setOffTotal = new BigDecimal(0); List bills = record.getBills(); sortBills(bills); @@ -702,6 +777,7 @@ public class WxFinanceServiceImpl implements WxFinanceService { calcuteDto.setTotalRemainReceive(receiveTotal); calcuteDto.setTotalSetoff(setOffTotal); calcuteDto.setTotalCut(new BigDecimal(0)); + calcuteDto.setTotalNeedPay(new BigDecimal(0)); //建立子账单关联单 List shopIdList = new ArrayList(); StringBuffer shopnumberSb = new StringBuffer(); @@ -723,9 +799,17 @@ public class WxFinanceServiceImpl implements WxFinanceService { throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请收款或者冲抵"); } + BigDecimal allHandleMoney = receiveTotal.add(new BigDecimal(0)); if (null != calcuteDto.getTotalSetoff()) { addreceive.setSetOffMoney(calcuteDto.getTotalSetoff().toPlainString()); + allHandleMoney.add(calcuteDto.getTotalSetoff()); + } + + //校验金额+冲抵是不是超过了应收费用 + if (calcuteDto.getTotalNeedPay().compareTo(allHandleMoney) < 0 ){ + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"实际收款和冲抵之和不能超过应收总金额"); } + addreceive.setBillCusName(billCusSb.toString()); addreceive.setBillShopNumber(shopnumberSb.toString()); addreceive.setRemark(record.getRemark()); @@ -771,7 +855,10 @@ public class WxFinanceServiceImpl implements WxFinanceService { //计算账单收款费用,更新账单收款 BigDecimal b0 = new BigDecimal(0); WxAllBill bill = wxBillAllHelper.getBillDetail(addreceive, be.getId()); + boolean billIsHandled = false; + BigDecimal billOldOweDecimal = new BigDecimal(bill.getOwe()); if (calcuteDto.getTotalRemainReceive().compareTo(b0) > 0) { + billIsHandled = true; noNeedCreate = false; //有收款,就要更新账单的收款 //更新账单收款信息 @@ -815,9 +902,7 @@ public class WxFinanceServiceImpl implements WxFinanceService { if(StringUtils.isNotBlank(be.getCurrentSetOff())) { calcuteDto.setTotalSetoff(calcuteDto.getTotalSetoff().add(new BigDecimal(be.getCurrentSetOff()))); payDto.setSetOff(be.getCurrentSetOff()); - //创建一个冲抵收款单 - createFinanceReceiveBill(addreceive,bill,be.getCurrentSetOff(),null,Constant.bill_pay_way_setoff); - //处理关联抵扣的预收单 + //押金冲抵和预收冲抵要分开建收款单 createFinanceReceiveSetoff(addreceive,be,bill); } //有减免 @@ -829,11 +914,10 @@ public class WxFinanceServiceImpl implements WxFinanceService { wxBillAllHelper.updatePay(payDto, user); }else if (StringUtils.isNotBlank(be.getCurrentSetOff())) { + billIsHandled = true; noNeedCreate = false; calcuteDto.setTotalSetoff(calcuteDto.getTotalSetoff().add(new BigDecimal(be.getCurrentSetOff()))); //没收款,有冲抵,就要更新账单的冲抵,然后把对应的预充值使用金额更新,并进行关联 - //创建一个冲抵收款单 - createFinanceReceiveBill(addreceive,bill,be.getCurrentSetOff(),null,Constant.bill_pay_way_setoff); //处理预充关联 createFinanceReceiveSetoff(addreceive,be,bill); @@ -856,6 +940,9 @@ public class WxFinanceServiceImpl implements WxFinanceService { payDto.setRemark("收款单收款["+addreceive.getId()+"]冲抵"+addreceive.getRemark()); wxBillAllHelper.updatePay(payDto, user); } + if (billIsHandled) { + calcuteDto.setTotalNeedPay(calcuteDto.getTotalNeedPay().add(billOldOweDecimal)); + } return noNeedCreate; } @@ -904,9 +991,30 @@ public class WxFinanceServiceImpl implements WxFinanceService { } public void createFinanceReceiveSetoff(WxFinanceReceive addreceive,WxAllBill be,WxAllBill bill) { + BigDecimal advanceMoney = new BigDecimal(0); + BigDecimal depositMoney = new BigDecimal(0); for (int j = 0 ; j < be.getSetOffDetailList().size(); j ++ ) { FinanceSetOffDetailVo setoffdetail = be.getSetOffDetailList().get(j); WxAllBill advance = wxAllBillService.getById(addreceive, setoffdetail.getAdvanceId()); + EnumBillAllType billType = EnumBillAllType.getEnum(advance.getBillType()); + + //如果是预冲 + if (billType == EnumBillAllType.ADVANCE){ + advanceMoney = advanceMoney.add(new BigDecimal(setoffdetail.getSetoff())); + }else { + //如果是押金 + boolean isDeposit = false; + for (EnumBillAllType bt : EnumBillAllType.getDepositTypes()) { + if (bt == billType) { + isDeposit = true; + break; + } + } + if (isDeposit) { + depositMoney = depositMoney.add(new BigDecimal(setoffdetail.getSetoff())); + } + } + advance.setUseMoney(new BigDecimal(advance.getUseMoney()).add(new BigDecimal(setoffdetail.getSetoff())).toPlainString()); advance.setUpdatetime(new Date()); wxAllBillService.saveOrUpdate(advance, null); @@ -926,6 +1034,14 @@ public class WxFinanceServiceImpl implements WxFinanceService { rb.setCreateTime(new Date()); rb.setUpdateTime(new Date()); wxFinanceReceiveSetoffMapper.insert(rb); + + //创建一个冲抵收款单 + if (advanceMoney.compareTo(new BigDecimal(0)) > 0 ) { + createFinanceReceiveBill(addreceive,bill,be.getCurrentSetOff(),null,Constant.bill_pay_way_setoff); + } + if (depositMoney.compareTo(new BigDecimal(0)) > 0 ) { + createFinanceReceiveBill(addreceive,bill,be.getCurrentSetOff(),null,Constant.bill_pay_way_deposit_setoff); + } } } @@ -1002,6 +1118,7 @@ public class WxFinanceServiceImpl implements WxFinanceService { FinanceReceiveCalcuteDTO calcuteDto = new FinanceReceiveCalcuteDTO(); calcuteDto.setTotalCut(new BigDecimal(0)); + calcuteDto.setTotalNeedPay(new BigDecimal(0)); //建立子账单关联单 List shopIdList = new ArrayList(); StringBuffer shopnumberSb = new StringBuffer(); @@ -1009,6 +1126,8 @@ public class WxFinanceServiceImpl implements WxFinanceService { for (int i = 0 ; i < record.getBills().size(); i++) { WxAllBill be = record.getBills().get(i); if(StringUtils.isNotBlank(be.getCurrentCut())) { + WxAllBill bill = wxBillAllHelper.getBillDetail(record, be.getId()); + calcuteDto.setTotalNeedPay(calcuteDto.getTotalNeedPay().add(new BigDecimal(bill.getOwe()))); WxBillPayDTO payDto = new WxBillPayDTO(); payDto.updateTenantInfo(addreceive); payDto.setId(be.getId()); @@ -1031,6 +1150,11 @@ public class WxFinanceServiceImpl implements WxFinanceService { if (isAllEmpity) { throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请收款或者冲抵"); } + + //校验减免是不是超过了应收费用 + if (calcuteDto.getTotalNeedPay().compareTo(calcuteDto.getTotalCut()) < 0 ){ + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"减免金额之和不能超过应收总金额"); + } addreceive.setBillCusName(billCusSb.toString()); addreceive.setBillShopNumber(shopnumberSb.toString()); addreceive.setRemark(record.getRemark()); @@ -1089,6 +1213,7 @@ public class WxFinanceServiceImpl implements WxFinanceService { FinanceReceiveCalcuteDTO calcuteDto = new FinanceReceiveCalcuteDTO(); calcuteDto.setTotalRemainPay(payTotal); + calcuteDto.setTotalNeedPay(new BigDecimal(0)); //建立子账单关联单 List shopIdList = new ArrayList(); StringBuffer shopnumberSb = new StringBuffer(); @@ -1110,6 +1235,12 @@ public class WxFinanceServiceImpl implements WxFinanceService { if (isAllEmpity) { throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"请付款"); } + + //校验金额+冲抵是不是超过了应收费用 + if (calcuteDto.getTotalNeedPay().compareTo(payTotal) < 0 ){ + throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"实际付款之和不能超过应付总金额"); + } + addreceive.setBillCusName(billCusSb.toString()); addreceive.setBillShopNumber(shopnumberSb.toString()); addreceive.setRemark(record.getRemark()); @@ -1155,8 +1286,11 @@ public class WxFinanceServiceImpl implements WxFinanceService { //计算账单收款费用,更新账单收款 BigDecimal b0 = new BigDecimal(0); WxAllBill bill = wxBillAllHelper.getBillDetail(addreceive, be.getId()); + boolean billIsHandled = false; + BigDecimal billOldOweDecimal = new BigDecimal(bill.getRemainReturnPrice()); if (calcuteDto.getTotalRemainPay().compareTo(b0) > 0) { noNeedCreate = false; + billIsHandled = true; //有收款,就要更新账单的收款 //更新账单收款信息 String money = ""; @@ -1195,8 +1329,11 @@ public class WxFinanceServiceImpl implements WxFinanceService { bill.setCurrentReceive(money); wxBillAllHelper.updatePayToMerchant(payDto, user); - } + if (billIsHandled) { + calcuteDto.setTotalNeedPay(calcuteDto.getTotalNeedPay().add(billOldOweDecimal)); + } + return noNeedCreate; } @@ -1279,7 +1416,7 @@ public class WxFinanceServiceImpl implements WxFinanceService { @Override public void delteTemp(WxAllBill record,MallUserInfo user) { WxAllBill bill = wxAllBillService.getById(record,record.getId()); - if (bill.getCreateBy() != user.getId()) { + if (bill.getCreateBy().longValue() != user.getId().longValue()) { throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"只能删除自己创建的账单"); } if (bill.getCanEdit() == EnumYesOrNo.YES.getCode()) { diff --git a/mallinkService/src/main/java/com/iformall/utils/Constant.java b/mallinkService/src/main/java/com/iformall/utils/Constant.java index de0c892c0..f6259ac3a 100644 --- a/mallinkService/src/main/java/com/iformall/utils/Constant.java +++ b/mallinkService/src/main/java/com/iformall/utils/Constant.java @@ -149,6 +149,9 @@ public class Constant { public static final Long bill_pay_way_system = 2L; public static final Long bill_pay_way_setoff = 3L; public static final Long bill_pay_way_cut = 4L; + public static final Long bill_pay_way_deposit_setoff = 5L; + + public static final Long bill_all_deposit_id = 99999999L; } diff --git a/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml b/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml index 3e5ded6fc..1d7280dd1 100644 --- a/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxAllBillMapper.xml @@ -84,6 +84,7 @@ and `extra_create_from` = #{extraCreateFrom} and `extra_create_from` is null and bill_type = 6 and IFNULL(`pay`,'0') -IFNULL(`return_pay`,'0') - IFNULL(`use_money`,'0') > 0 + and IFNULL(`pay`,'0') - IFNULL(`return_pay`,'0') - IFNULL(`use_money`,'0') > 0 and bill_type in (13,21,5) and `can_edit` = #{canEdit} and date_format(starttime,'%Y-%m') <= #{month} and date_format(endtime,'%Y-%m') >= #{month} @@ -217,6 +218,19 @@ + + + + +