|
|
@ -21,6 +21,8 @@ import com.qs.serve.modules.goods.service.GoodsSpuService; |
|
|
|
import com.qs.serve.modules.pay.common.PaymentType; |
|
|
|
import com.qs.serve.modules.pay.entity.PayPayment; |
|
|
|
import com.qs.serve.modules.pay.entity.PayPaymentItem; |
|
|
|
import com.qs.serve.modules.pay.service.PayPaymentItemService; |
|
|
|
import com.qs.serve.modules.pay.service.PayPaymentService; |
|
|
|
import com.qs.serve.modules.sys.entity.SysUser; |
|
|
|
import com.qs.serve.modules.sys.service.SysUserService; |
|
|
|
import com.qs.serve.modules.tbs.common.TbsActivityState; |
|
|
@ -38,6 +40,7 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.math.RoundingMode; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
@ -67,6 +70,7 @@ public class PortalOfCostApplication { |
|
|
|
|
|
|
|
private SysUserService userService; |
|
|
|
|
|
|
|
private TbsCostUnItemService costUnItemService; |
|
|
|
private TbsBudgetLogService budgetLogService; |
|
|
|
private TbsBudgetApplicationService budgetApplicationService; |
|
|
|
private TbsCostApplyService costApplyService; |
|
|
@ -75,6 +79,9 @@ public class PortalOfCostApplication { |
|
|
|
private GoodsSpuService goodsSpuService; |
|
|
|
private GoodsCategoryService goodsCategoryService; |
|
|
|
|
|
|
|
private PayPaymentService paymentService; |
|
|
|
private PayPaymentItemService paymentItemService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@ -86,6 +93,7 @@ public class PortalOfCostApplication { |
|
|
|
BmsSubject subject = subjectService.getByCode(createBo.getSubjectCode()); |
|
|
|
if(subject==null){Assert.throwEx("科目不存在,请重新编辑");} |
|
|
|
//初始化sku列表
|
|
|
|
List<ProcessGoodsItem> processGoodsItems = createBo.getGoodsList(); |
|
|
|
List<GoodsSku> skuList = this.initSkuListOfProcess(createBo); |
|
|
|
//常用参数
|
|
|
|
final String GOODS_TYPE = "sku"; |
|
|
@ -93,6 +101,8 @@ public class PortalOfCostApplication { |
|
|
|
final BigDecimal OneHundred = new BigDecimal("100"); |
|
|
|
LocalDateTime nowTime = LocalDateTime.now(); |
|
|
|
LocalDate nowDate = LocalDate.now(); |
|
|
|
String billNumber = createBo.getBillNumber(); |
|
|
|
String erpCode = createBo.getErpCode(); |
|
|
|
Long supplierId = Long.parseLong(supplier.getId()); |
|
|
|
BigDecimal totalAmount = createBo.getTotalAmount(); |
|
|
|
String costCode = createBo.getCostCode(); |
|
|
@ -193,10 +203,6 @@ public class PortalOfCostApplication { |
|
|
|
centerGoods.setSubjectId(subject.getId()); |
|
|
|
centerGoods.setSubjectCode(subject.getSubjectCode()); |
|
|
|
centerGoods.setSubjectName(subject.getSubjectName()); |
|
|
|
//TODO 分配
|
|
|
|
centerGoods.setCenterGoodsAmount(BigDecimal.ZERO); |
|
|
|
centerGoods.setCenterGoodsRate(BigDecimal.ZERO); |
|
|
|
centerGoods.setUsedAmount(BigDecimal.ZERO); |
|
|
|
//设置活动时间
|
|
|
|
centerGoods.setActEndDate(nowDate); |
|
|
|
centerGoods.setActStartDate(nowDate); |
|
|
@ -209,6 +215,16 @@ public class PortalOfCostApplication { |
|
|
|
centerGoods.setTargetName(activityGoods.getTargetName()); |
|
|
|
centerGoods.setTargetLevelPathIds(activityGoods.getTargetLevelPathIds()); |
|
|
|
centerGoods.setTargetLevelPathNames(activityGoods.getTargetLevelPathNames()); |
|
|
|
// 分配金额
|
|
|
|
for (ProcessGoodsItem goodsItem : processGoodsItems) { |
|
|
|
if(goodsItem.getInventoryCode().equals(activityGoods.getTargetCode())){ |
|
|
|
BigDecimal rate = goodsItem.getAmount().divide(totalAmount, RoundingMode.UP); |
|
|
|
centerGoods.setCenterGoodsAmount(goodsItem.getAmount()); |
|
|
|
centerGoods.setCenterGoodsRate(rate); |
|
|
|
centerGoods.setUsedAmount(goodsItem.getAmount()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
activityCenterGoodsList.add(centerGoods); |
|
|
|
} |
|
|
|
|
|
|
@ -240,6 +256,7 @@ public class PortalOfCostApplication { |
|
|
|
Arrays.asList(activitySubject), |
|
|
|
activityCenterGoodsList, |
|
|
|
Arrays.asList(activityCenter),true,false,false); |
|
|
|
|
|
|
|
//不匹配的商品,保存到无预算表
|
|
|
|
List<TbsBudgetCostItem> unMatchBudgetItem = budgetCostResult.getBudgetUnMatchList(); |
|
|
|
List<TbsCostUnItem> costUnItemList = new ArrayList<>(); |
|
|
@ -249,6 +266,8 @@ public class PortalOfCostApplication { |
|
|
|
costUnItemList.add(costUnItem); |
|
|
|
} |
|
|
|
} |
|
|
|
costUnItemService.saveBatch(costUnItemList); |
|
|
|
|
|
|
|
//不匹配的商品,生成预算日志
|
|
|
|
List<TbsBudgetCostItem> matchBudgetItem = budgetCostResult.getBudgetMatchList(); |
|
|
|
List<TbsBudgetLog> budgetLogList = new ArrayList<>(); |
|
|
@ -265,7 +284,9 @@ public class PortalOfCostApplication { |
|
|
|
budgetLogList.add(budgetLog); |
|
|
|
} |
|
|
|
} |
|
|
|
budgetLogService.saveBatch(budgetLogList); |
|
|
|
|
|
|
|
//保存核销申请
|
|
|
|
VtbVerification verification = new VtbVerification(); |
|
|
|
verification.setVerificationCode("HX"+ IdUtil.timeStampId()); |
|
|
|
verification.setFinishedTime(nowTime); |
|
|
@ -281,8 +302,7 @@ public class PortalOfCostApplication { |
|
|
|
verification.setAmountRecord(totalAmount); |
|
|
|
verification.setPaymentState(ResultFlag.OK); |
|
|
|
|
|
|
|
|
|
|
|
//保存费用结果
|
|
|
|
//保存核销费用结果
|
|
|
|
VtbVerificationSubject verificationSubject = new VtbVerificationSubject(); |
|
|
|
verificationSubject.setVerificationSubCode(verification.getVerificationCode()+"_1"); |
|
|
|
verificationSubject.setCostApplyId(costApply.getId()); |
|
|
@ -299,6 +319,7 @@ public class PortalOfCostApplication { |
|
|
|
verificationSubject.setCountPerson(0); |
|
|
|
verificationSubject.setCountSession(0); |
|
|
|
|
|
|
|
//保存支付
|
|
|
|
PayPayment payPayment = new PayPayment(); |
|
|
|
payPayment.setPayType(PaymentType.PAYMENT); |
|
|
|
payPayment.setPayCode("PM"+ StringUtils.genShortId()); |
|
|
@ -310,8 +331,9 @@ public class PortalOfCostApplication { |
|
|
|
payPayment.setUserCode(user.getCode()); |
|
|
|
payPayment.setUserName(user.getName()); |
|
|
|
payPayment.setPayTime(nowTime); |
|
|
|
payPayment.setErpCode(""); |
|
|
|
payPayment.setBillNumber(""); |
|
|
|
payPayment.setErpCode(erpCode); |
|
|
|
payPayment.setBillNumber(billNumber); |
|
|
|
paymentService.save(payPayment); |
|
|
|
|
|
|
|
PayPaymentItem paymentItem = new PayPaymentItem(); |
|
|
|
paymentItem.setPaymentId(payPayment.getId()); |
|
|
@ -319,7 +341,14 @@ public class PortalOfCostApplication { |
|
|
|
paymentItem.setSupplierId(supplierId); |
|
|
|
paymentItem.setItemPayAmount(totalAmount); |
|
|
|
paymentItem.setVerificationId(verification.getId()); |
|
|
|
|
|
|
|
paymentItem.setVerificationSubjectId(verificationSubject.getId()); |
|
|
|
paymentItem.setCostApplyId(costApply.getId()); |
|
|
|
paymentItem.setActivityId(activity.getId()); |
|
|
|
paymentItem.setActivityCode(activity.getActivityCode()); |
|
|
|
paymentItem.setSubjectId(subject.getId()); |
|
|
|
paymentItem.setSubjectCode(subject.getSubjectCode()); |
|
|
|
paymentItem.setSubjectName(subject.getSubjectName()); |
|
|
|
paymentItemService.save(paymentItem); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|