|
|
@@ -137,6 +137,14 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
|
|
|
|
|
|
Verification verification = BeanMapper.map(main,Verification.class);
|
|
|
if(id.longValue() > 0 ){
|
|
|
+
|
|
|
+ //更新前判断数据库中的币别是否和当前币别一致
|
|
|
+ Verification oldVerification = getMapper().selectByPrimaryKey(id.intValue());
|
|
|
+ if(!oldVerification.getVc_currency().equals(main.getVc_currency())){
|
|
|
+ verificationdetailMapper.deleteByParentPrimaryKey(id);
|
|
|
+ verificationdetMapper.deleteByParentPrimaryKey(id);
|
|
|
+ }
|
|
|
+
|
|
|
String kind = verification.getVc_kind();
|
|
|
verification.setVc_kind(transferKind(kind));
|
|
|
verification.setCompanyId(companyId);
|
|
|
@@ -212,36 +220,47 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
|
|
|
|
|
|
String type = main.getVc_kind();
|
|
|
type = transferKind(type);
|
|
|
+
|
|
|
+ for(Verificationdet det : items1){
|
|
|
+ //本次核销金额
|
|
|
+ Double nowbalanceDet = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
|
|
|
+ //单据金额
|
|
|
+ Double amount = det.getSl_namount();
|
|
|
+ //已核销金额
|
|
|
+ Double namount = det.getSl_namount()==null?new Double(0):det.getSl_namount();
|
|
|
+ //核销金额
|
|
|
+ if(amount.doubleValue()>0 && nowbalanceDet.doubleValue()<0){
|
|
|
+ String msg = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getMessage();
|
|
|
+ int code = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getCode();
|
|
|
+ String error = String.format(msg, det.getVd_slkind());
|
|
|
+ throw new BizException(code, error);
|
|
|
+ }
|
|
|
+ if(amount.doubleValue()<0 && nowbalanceDet.doubleValue()>0){
|
|
|
+ String msg = BizExceptionCode.MONEY_NOWAMOUNT_NEGATIVE.getMessage();
|
|
|
+ int code = BizExceptionCode.MONEY_NOWAMOUNT_NEGATIVE.getCode();
|
|
|
+ String error = String.format(msg, det.getVd_slkind());
|
|
|
+ throw new BizException(code, error);
|
|
|
+ }
|
|
|
+ Double nowbalance = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
|
|
|
+ if( Math.abs(namount.doubleValue()) < Math.abs(nowbalanceDet.doubleValue()) ){
|
|
|
+ throw new BizException(500, BizExceptionCode.RECALANCE_OUTNOWBALANCE.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
if(type.equals("receipts_offset_receivable") || type.equals("prepaid_offset_payable") ||
|
|
|
- type.equals("receivable_offset_payable")){
|
|
|
+ type.equals("receivable_offset_payable")){//预收冲应收、预付冲应付、应收冲应付
|
|
|
Double total1 = new Double(0);
|
|
|
for(Verificationdet det : items1){
|
|
|
Double nowbalanceDet = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
|
|
|
total1 += nowbalanceDet;
|
|
|
-
|
|
|
- //单据金额
|
|
|
- Double amount = det.getSl_namount();
|
|
|
- //核销金额
|
|
|
- if(amount.doubleValue()>0 && nowbalanceDet.doubleValue()<0){
|
|
|
- String msg = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getMessage();
|
|
|
- int code = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getCode();
|
|
|
- String error = String.format(msg, det.getVd_slkind());
|
|
|
- throw new BizException(code, error);
|
|
|
- }
|
|
|
- if(amount.doubleValue()<0 && nowbalanceDet.doubleValue()>0){
|
|
|
- String msg = BizExceptionCode.MONEY_NOWAMOUNT_NEGATIVE.getMessage();
|
|
|
- int code = BizExceptionCode.MONEY_NOWAMOUNT_NEGATIVE.getCode();
|
|
|
- String error = String.format(msg, det.getVd_slkind());
|
|
|
- throw new BizException(code, error);
|
|
|
- }
|
|
|
}
|
|
|
Double total2 = new Double(0);
|
|
|
for(Verificationdetail detail : items2){
|
|
|
Double nowbalanceDet = detail.getVcd_nowbalance()==null?new Double(0):detail.getVcd_nowbalance();
|
|
|
total2 += nowbalanceDet;
|
|
|
-
|
|
|
//单据金额
|
|
|
Double amount = detail.getVcd_amount();
|
|
|
+ //已核销金额
|
|
|
+ Double namount = detail.getSl_namount()==null?new Double(0):detail.getSl_namount();
|
|
|
//核销金额
|
|
|
if(amount.doubleValue()>0 && nowbalanceDet.doubleValue()<0){
|
|
|
String msg = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getMessage();
|
|
|
@@ -255,20 +274,14 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
|
|
|
String error = String.format(msg, detail.getVcd_slkind());
|
|
|
throw new BizException(code, error);
|
|
|
}
|
|
|
+ if( Math.abs(namount.doubleValue()) < Math.abs(nowbalanceDet.doubleValue()) ){
|
|
|
+ throw new BizException(500, BizExceptionCode.RECALANCE_OUTNOWBALANCE.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
if(total1.doubleValue()!=total2.doubleValue()){
|
|
|
throw new BizException(500, BizExceptionCode.VERIFICATION_CHECK_BALANCE.getMessage());
|
|
|
}
|
|
|
- }else if(type.equals("receivable_to_receivable") || type.equals("payable_to_payable")){
|
|
|
- for(Verificationdet det : items1){
|
|
|
- Double namount = det.getSl_namount()==null?new Double(0):det.getSl_namount();
|
|
|
- Double nowbalance = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
|
|
|
- if(namount.doubleValue()<nowbalance.doubleValue()){
|
|
|
- throw new BizException(500, BizExceptionCode.RECALANCE_OUTNOWBALANCE.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
//插入中间表
|
|
|
@@ -590,6 +603,11 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
|
|
|
if(items1!=null){
|
|
|
for(VerificationdetDTO det : items1){
|
|
|
Double nowbalanceDet = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
|
|
|
+ Subledger sub = subledgerMapper.selectByPrimaryKey(Math.toIntExact(det.getVd_slid()));
|
|
|
+ if (sub != null && sub.getSl_preamount() != 0 &&
|
|
|
+ ("receivable_to_receivable".equals(verificationDTO.getVc_kind()) || "payable_to_payable".equals(verificationDTO.getVc_kind()))) {
|
|
|
+ nowbalanceDet=-1*nowbalanceDet;
|
|
|
+ }
|
|
|
updateAuditSubledeger(det.getVd_slid(),nowbalanceDet);
|
|
|
}
|
|
|
}
|
|
|
@@ -879,6 +897,12 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
|
|
|
List<Verificationdetail> items2 = verificationdetailMapper.selectByFK(id);
|
|
|
for(Verificationdet det : items1){
|
|
|
Double nowbalanceDet = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
|
|
|
+ Subledger sub = subledgerMapper.selectByPrimaryKey(Math.toIntExact(det.getVd_slid()));
|
|
|
+ if (sub != null && sub.getSl_preamount() != 0 &&
|
|
|
+ ("receivable_to_receivable".equals(verificationDTO.getVc_kind()) || "payable_to_payable".equals(verificationDTO.getVc_kind())
|
|
|
+ || "应收转应收".equals(verificationDTO.getVc_kind()) || "应付转应付".equals(verificationDTO.getVc_kind()))) {
|
|
|
+ nowbalanceDet=-1*nowbalanceDet;
|
|
|
+ }
|
|
|
updateResAuditSubledeger(det.getVd_slid(),nowbalanceDet);
|
|
|
}
|
|
|
for(Verificationdetail detail : items2){
|