Parcourir la source

分账逻辑优化

liuj il y a 6 mois
Parent
commit
955d1fdcdb

+ 25 - 24
src/main/java/com/sunxung/factoring/service/ledger/impl/LedgerManagementServiceImpl.java

@@ -1306,32 +1306,33 @@ public class LedgerManagementServiceImpl implements LedgerManagementService {
                                                 returnedAmount = returnedAmount.subtract(planFactoring.getAmount());
                                                 financePrincipal = financePrincipal.add(planFactoring.getAmount());
                                             } else {
-                                                //说明本金不够分了
-                                                //判断本金状态是否逾期,如果逾期,本金不能拆分
-                                                if (PaymentCollectionPlanStatusDict.ChildEnum.OVERDUE.getCode().equals(planFactoring.getStatus().getCode())) {
-                                                    //计划已逾期
-                                                    ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(ledgerDate, assignAmount,
-                                                            planFactoring, goodsAssignVo, 1));
-                                                } else {
-                                                    if (ledgerDate.before(planFactoring.getPlanDate())) {
-                                                        //分账日期早于计划日期
-                                                        planFactoring.setPlanDate(ledgerDate);
+                                                if (assignAmount.compareTo(BigDecimal.ZERO) > 0) {
+                                                    //说明本金不够分了
+                                                    //判断本金状态是否逾期,如果逾期,本金不能拆分
+                                                    if (PaymentCollectionPlanStatusDict.ChildEnum.OVERDUE.getCode().equals(planFactoring.getStatus().getCode())) {
+                                                        //计划已逾期
+                                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(ledgerDate, assignAmount,
+                                                                planFactoring, goodsAssignVo, 1));
+                                                    } else {
+                                                        if (ledgerDate.before(planFactoring.getPlanDate())) {
+                                                            //分账日期早于计划日期
+                                                            planFactoring.setPlanDate(ledgerDate);
+                                                        }
+                                                        planFactoring.setAmount(assignAmount);
+                                                        planFactoring.setActualCashFlow(assignAmount);
+                                                        //修改一笔本金收款记录
+                                                        ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(ledgerDate, assignAmount,
+                                                                planFactoring, goodsAssignVo, 1));
+                                                        Date lastPlanDate = goodsAssignVo.getLastPlanDate();
+                                                        //增加一笔剩余本金收款记录
+                                                        ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(lastPlanDate, returnedAmount.subtract(assignAmount), BigDecimal.ZERO,
+                                                                IncomeExpenditureTypeDict.ChildEnum.PRINCIPAL.getCode(), goodsAssignVo, 1));
+                                                        flag = true;
                                                     }
-                                                    planFactoring.setAmount(assignAmount);
-                                                    planFactoring.setActualCashFlow(assignAmount);
-                                                    //修改一笔本金收款记录
-                                                    ledgerPlanFactoringAssignList.add(addPlanFactoringUpdateAssign(ledgerDate, assignAmount,
-                                                            planFactoring, goodsAssignVo, 1));
-                                                    Date lastPlanDate = goodsAssignVo.getLastPlanDate();
-                                                    //增加一笔剩余本金收款记录
-                                                    ledgerPlanFactoringAssignList.add(addPlanFactoringInsertAssign(lastPlanDate, returnedAmount.subtract(assignAmount), BigDecimal.ZERO,
-                                                            IncomeExpenditureTypeDict.ChildEnum.PRINCIPAL.getCode(), goodsAssignVo, 1));
-                                                    flag = true;
+                                                    financePrincipal = financePrincipal.add(assignAmount);
+                                                    returnedAmount = returnedAmount.subtract(assignAmount);
+                                                    assignAmount = BigDecimal.ZERO;
                                                 }
-                                                financePrincipal = financePrincipal.add(assignAmount);
-                                                returnedAmount = returnedAmount.subtract(assignAmount);
-                                                assignAmount = BigDecimal.ZERO;
-
                                             }
                                         }
                                     }