|
@@ -1,21 +1,30 @@
|
|
|
package com.fjhx.purchase.service.refund.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.account.entity.account.enums.PaymentStatusEnum;
|
|
|
+import com.fjhx.account.entity.account.enums.PaymentTypeEnum;
|
|
|
+import com.fjhx.account.entity.account.po.AccountDeptRunningWater;
|
|
|
import com.fjhx.account.entity.account.po.AccountPayment;
|
|
|
+import com.fjhx.account.entity.account.po.AccountRunningWater;
|
|
|
import com.fjhx.account.service.account.AccountPaymentService;
|
|
|
+import com.fjhx.account.service.account.AccountRunningWaterService;
|
|
|
import com.fjhx.purchase.entity.refund.dto.RefundDto;
|
|
|
import com.fjhx.purchase.entity.refund.dto.RefundSelectDto;
|
|
|
+import com.fjhx.purchase.entity.refund.enums.RefundEnum;
|
|
|
+import com.fjhx.purchase.entity.refund.enums.RefundStatusEnum;
|
|
|
import com.fjhx.purchase.entity.refund.po.Refund;
|
|
|
import com.fjhx.purchase.entity.refund.vo.RefundVo;
|
|
|
import com.fjhx.purchase.mapper.refund.RefundMapper;
|
|
|
import com.fjhx.purchase.service.refund.RefundService;
|
|
|
import com.fjhx.supply.entity.supplier.po.SupplierInfo;
|
|
|
import com.fjhx.supply.service.supplier.SupplierInfoService;
|
|
|
+import com.obs.services.internal.ServiceException;
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.common.utils.wrapper.SqlField;
|
|
@@ -46,6 +55,8 @@ public class RefundServiceImpl extends ServiceImpl<RefundMapper, Refund> impleme
|
|
|
@Autowired
|
|
|
private AccountPaymentService accountPaymentService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AccountRunningWaterService accountRunningWaterService;
|
|
|
|
|
|
@Override
|
|
|
public Page<RefundVo> getPage(RefundSelectDto dto) {
|
|
@@ -109,4 +120,46 @@ public class RefundServiceImpl extends ServiceImpl<RefundMapper, Refund> impleme
|
|
|
this.removeById(id);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 到款登记
|
|
|
+ * @param refundDto
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @DSTransactional
|
|
|
+ public void receiptRegistration(RefundDto refundDto) {
|
|
|
+ if(ObjectUtils.isEmpty(refundDto.getId())||
|
|
|
+ ObjectUtils.isEmpty(refundDto.getReceiptAmount())||
|
|
|
+ ObjectUtils.isEmpty(refundDto.getReceiptAccountManagementId())){
|
|
|
+ throw new ServiceException("参数异常");
|
|
|
+ }
|
|
|
+ Refund refund = this.getById(refundDto.getId());
|
|
|
+ if(ObjectUtils.isEmpty(refund)){
|
|
|
+ throw new ServiceException("退货单不存在");
|
|
|
+ }
|
|
|
+ //判断当前所收的金额修改退款状态
|
|
|
+ BigDecimal newAmount = refundDto.getReceiptAmount();
|
|
|
+ List<AccountRunningWater> accountRunningWaters = accountRunningWaterService.list(Wrappers.<AccountRunningWater>query().lambda().select(AccountRunningWater::getAmount).eq(AccountRunningWater::getBusinessId,refund.getId()));
|
|
|
+ BigDecimal sumAmount = accountRunningWaters.stream().map(AccountRunningWater::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if(ObjectUtils.isNotEmpty(sumAmount)){
|
|
|
+ if((sumAmount.add(newAmount)).compareTo(refund.getAmount())>-1){//已退款
|
|
|
+ refund.setRefundStatus(RefundEnum.RE_20.getKey());
|
|
|
+ }else{//部分退款
|
|
|
+ refund.setRefundStatus(RefundEnum.RE_10.getKey());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.updateById(refund);
|
|
|
+ //添加一条资金流水
|
|
|
+ AccountRunningWater accountRunningWater = new AccountRunningWater();
|
|
|
+ accountRunningWater.setAccountManagementId(refundDto.getReceiptAccountManagementId());
|
|
|
+ accountRunningWater.setStatus("10");
|
|
|
+ accountRunningWater.setBusinessId(refund.getId());
|
|
|
+ accountRunningWater.setAmount(refundDto.getReceiptAmount());
|
|
|
+ accountRunningWater.setCurrency(refund.getCurrency());
|
|
|
+ accountRunningWater.setReceived("20");
|
|
|
+ accountRunningWater.setName(refundDto.getReceiptName());
|
|
|
+ accountRunningWater.setOpeningBank(refundDto.getReceiptOpeningBank());
|
|
|
+ accountRunningWater.setAccountOpening(refundDto.getReceiptAccountOpening());
|
|
|
+ accountRunningWaterService.save(accountRunningWater);
|
|
|
+ }
|
|
|
+
|
|
|
}
|