校验同一个清账单下面的明细单分录中本次核销金额合计是否会超出剩余核销金额
This commit is contained in:
		
							parent
							
								
									df0dc5116c
								
							
						
					
					
						commit
						bf5ecf5324
					
				|  | @ -16,10 +16,7 @@ import kd.sdk.plugin.Plugin; | |||
| import shjh.jhzj7.fi.fi.utils.JhzjUtils; | ||||
| 
 | ||||
| import java.math.BigDecimal; | ||||
| import java.util.ArrayList; | ||||
| import java.util.HashSet; | ||||
| import java.util.List; | ||||
| import java.util.Set; | ||||
| import java.util.*; | ||||
| 
 | ||||
| /** | ||||
|  * 清账明细单据操作插件 | ||||
|  | @ -33,6 +30,8 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp | |||
|     private static final String clearBillName = "shjh_clear_account";//清账单 | ||||
|     private static final String userName = "bos_user";//用户 | ||||
| 
 | ||||
|     private static final String amountSql = "select t1.fk_shjh_pzh,t1.fk_shjh_pzlx,t1.fk_shjh_pzhh,sum(t1.fk_shjh_cursettle) from tk_shjh_acctdetail_entry t1 left join tk_shjh_clear_acctdetail t2 on t1.fid=t2.fid where t2.fk_shjh_clearbillid=? and t2.fid!=? group by t1.fk_shjh_pzh,t1.fk_shjh_pzlx,t1.fk_shjh_pzhh"; | ||||
| 
 | ||||
|     /** | ||||
|      * 操作校验通过之后,开启事务之前,触发此事件; | ||||
|      * 插件可以在此事件,对通过校验的数据,进行整理 | ||||
|  | @ -82,6 +81,12 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp | |||
|                     e.setCancelMessage(billno+"金额校验结果:"+amountCheckResult); | ||||
|                     e.setCancel(true); | ||||
|                 } | ||||
|                 //校验同一个清账单下面的明细单分录中本次核销金额合计是否会超出剩余核销金额 | ||||
|                 amountCheckResult = checkEntryHXAmount(prinfo); | ||||
|                 if(!"ok".equals(amountCheckResult)){ | ||||
|                     e.setCancelMessage(billno+"分录本次核销金额校验结果:"+amountCheckResult); | ||||
|                     e.setCancel(true); | ||||
|                 } | ||||
|             }else if("revoke".equals(eok)){ | ||||
|                 //撤销校验 | ||||
|                 if(!"B".equals(prinfo.getString("billstatus"))){ | ||||
|  | @ -131,6 +136,45 @@ public class ClearDetailBillOperation extends AbstractOperationServicePlugIn imp | |||
|         return false; | ||||
|     } | ||||
| 
 | ||||
|     private String checkEntryHXAmount(DynamicObject prinfo){ | ||||
|         //获取当前明细单上的清账单id,根据包含此清账单id和剔除当前明细单id,查找分录凭证号 凭证类型 凭证行号 统计本次核销金额 | ||||
|         //改成写sql 表名 tk_shjh_clear_acctdetail | ||||
|         //shjh_details 待清账明细 | ||||
|         //shjh_e_pzh 凭证号 fk_shjh_pzh | ||||
|         //shjh_e_pzlx 凭证类型 fk_shjh_pzlx | ||||
|         //shjh_e_pzhh 凭证行号 fk_shjh_pzhh | ||||
|         //shjh_e_cursettle 本次核销金额 fk_shjh_cursettle | ||||
|         //shjh_e_unsettle 未核销金额 | ||||
|         Map<String,BigDecimal> entryAmounts = DB.query(DBRoute.of("fi"),amountSql, | ||||
|                 new Object[]{prinfo.getString("shjh_clearbillid"),prinfo.getPkValue()},(rs) -> { | ||||
|             Map<String,BigDecimal> amounts = new HashMap<>(); | ||||
|             while(rs.next()) { | ||||
|                 amounts.put(rs.getString(1)+rs.getString(2)+rs.getString(3),rs.getBigDecimal(4)); | ||||
|             } | ||||
|             return amounts; | ||||
|         }); | ||||
|         if(entryAmounts.isEmpty()){ | ||||
|             //说明除了当前明细单外,清账单下没有其他的明细单了 | ||||
|             return "ok"; | ||||
|         } | ||||
|         //循环当前明细单的分录行,根据凭证号+凭证类型+凭证行号一起判断本次核销金额加上map中的金额是否会超过分录上的未核销金额 | ||||
|         DynamicObjectCollection docs = prinfo.getDynamicObjectCollection("shjh_details"); | ||||
|         String key;//map中的key | ||||
|         BigDecimal entryAmount;//map中的金额 | ||||
|         for (DynamicObject docinfo : docs) { | ||||
|             key = docinfo.getString("shjh_e_pzh")+docinfo.getString("shjh_e_pzlx")+docinfo.getString("shjh_e_pzhh"); | ||||
|             if(entryAmounts.containsKey(key)){ | ||||
|                 entryAmount = entryAmounts.get(key); | ||||
|                 //map中的金额+当前分录行本次核销金额 | ||||
|                 entryAmount = entryAmount.add(docinfo.getBigDecimal("shjh_e_cursettle")); | ||||
|                 if(entryAmount.abs().compareTo(docinfo.getBigDecimal("shjh_e_unsettle").abs()) > 0){ | ||||
|                     return key+"本次核销金额合计不能超过未核销金额"; | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         return "ok"; | ||||
|     } | ||||
| 
 | ||||
|     private String checkEntryAmount(DynamicObject prinfo){ | ||||
|         //校验分录本次核销金额的合计等于0 负数金额相加部分的绝对值不能大于未清金额 | ||||
|         BigDecimal entrytotal = BigDecimal.ZERO;//本次核销金额合计 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue