|
|
@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -58,6 +59,9 @@ public class PaybalanceServiceImpl implements PaybalanceService {
|
|
|
|
|
|
Long rbId = paybalance.getId();
|
|
|
|
|
|
+ //校验数据
|
|
|
+ checkPaybalance(pay);
|
|
|
+
|
|
|
if (paybalance.getId() > 0){
|
|
|
paybalanceMapper.updateByPrimaryKeySelective(paybalance);
|
|
|
}else {
|
|
|
@@ -93,6 +97,63 @@ public class PaybalanceServiceImpl implements PaybalanceService {
|
|
|
return new DocBaseDTO(rbId, pb_code, BillCodeSeq.PAYBALANCE.getCaller());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 校验数据
|
|
|
+ * @param pay
|
|
|
+ * @author hx
|
|
|
+ */
|
|
|
+ private void checkPaybalance(Pay pay){
|
|
|
+ Paybalance paybalance = pay.getMain();
|
|
|
+ List<Paybalancedet> paybalancedet = pay.getItems1();
|
|
|
+ List<Paybalancedetail> paybalancedetail = pay.getItems2();
|
|
|
+ //本次核销合计
|
|
|
+ Double nowbalanceTotal = new Double(0);
|
|
|
+ for(Paybalancedetail detail : paybalancedetail){
|
|
|
+ //本次核销金额
|
|
|
+ Double nowbalance = detail.getPbd_nowbalance();
|
|
|
+ nowbalanceTotal = nowbalanceTotal + nowbalance;
|
|
|
+ //来源单号
|
|
|
+ Integer sourceId = detail.getPbd_slid();
|
|
|
+ //未核销金额
|
|
|
+ Double namount = new Double(0);
|
|
|
+ if(sourceId!=0){
|
|
|
+ Subledger subledger = subledgerMapper.selectByPrimaryKey(sourceId);
|
|
|
+ namount = subledger.getSl_namount();
|
|
|
+ }
|
|
|
+ //本次核销金额不能大于未核销金额
|
|
|
+ if(nowbalance>namount){
|
|
|
+ throw new BizException(500, BizExceptionCode.PAYBALANCE_OUTNOWBALANCE.getMessage());
|
|
|
+ }
|
|
|
+ //单据金额
|
|
|
+ Double amount = detail.getPbd_amount();
|
|
|
+ if(amount>0 && nowbalance<0){
|
|
|
+ String error = "单据类型为" + detail.getPbd_slkind() + "的单据,核销金额必须为正数";
|
|
|
+ throw new BizException(500, error);
|
|
|
+ }
|
|
|
+ if(amount<0 && nowbalance>0){
|
|
|
+ String error = "单据类型为" + detail.getPbd_slkind() + "的单据,核销金额必须为负数";
|
|
|
+ throw new BizException(500, error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //不能选择重复的源单
|
|
|
+ for ( int i = 0 ; i < paybalancedetail.size() - 1 ; i ++ ) {
|
|
|
+ for ( int j = paybalancedetail.size() - 1 ; j > i; j -- ) {
|
|
|
+ if (paybalancedetail.get(j).getPbd_slcode().equals(paybalancedetail.get(i).getPbd_slcode())) {
|
|
|
+ throw new BizException(500, BizExceptionCode.PAYBALANCE_UNIQUESOURCECODE.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //付款金额合计
|
|
|
+ Double amountTotal = new Double(0);
|
|
|
+ for (Paybalancedet det: paybalancedet) {
|
|
|
+ amountTotal = amountTotal + det.getPd_amount();
|
|
|
+ }
|
|
|
+ //更新本次预付款金额
|
|
|
+ Paybalance updatePay = new Paybalance();
|
|
|
+ updatePay.setId(paybalance.getId());
|
|
|
+ updatePay.setPb_preamount(amountTotal+paybalance.getPb_discounts()-nowbalanceTotal);
|
|
|
+ paybalanceMapper.updateByPrimaryKeySelective(updatePay);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void audit(Pay pay) {
|
|
|
@@ -115,6 +176,19 @@ public class PaybalanceServiceImpl implements PaybalanceService {
|
|
|
}else {
|
|
|
paybalanceMapper.updateByPrimaryKeySelective(paybalance);
|
|
|
}
|
|
|
+
|
|
|
+ Paybalance updatePay = new Paybalance();
|
|
|
+ List<Paybalancedet> paybalancedet = pay.getItems1();
|
|
|
+ List<Paybalancedetail> paybalancedetail = pay.getItems2();
|
|
|
+ //更新主表付款金额:pb_pdamount=从表一金额合计
|
|
|
+ Double amountTotal = new Double(0);
|
|
|
+ for (Paybalancedet det: paybalancedet) {
|
|
|
+ amountTotal = amountTotal + det.getPd_amount();
|
|
|
+ }
|
|
|
+ updatePay.setId(pay.getMain().getId());
|
|
|
+ updatePay.setPb_pdamount(amountTotal);
|
|
|
+ //updateByPrimaryKeySelective
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -129,6 +203,13 @@ public class PaybalanceServiceImpl implements PaybalanceService {
|
|
|
paybalance = paybalanceMapper.selectByPrimaryKey(id);
|
|
|
subledgerMapper.deleteByPrimaryKey(paybalance.getPb_code(), paybalance.getPb_kind());
|
|
|
banksubledgerMapper.deleteByPrimaryKey(paybalance.getPb_code(), paybalance.getPb_kind());
|
|
|
+
|
|
|
+ //更新供应商资料
|
|
|
+ /**
|
|
|
+ * ve_preamount=nvl(ve_preamount,0)-pb_preamount,
|
|
|
+ * ve_payamount=nvl(ve_payamount,0)+pb_pbdamount,
|
|
|
+ * ve_leftamount=ve_beginapamount-e_beginprepayamount+ve_payamount-ve_preamount;
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
|