Эх сурвалжийг харах

资金模块-新增核销单功能

huangx 7 жил өмнө
parent
commit
847d6eac67
18 өөрчлөгдсөн 791 нэмэгдсэн , 91 устгасан
  1. 3 2
      applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/exception/BizExceptionCode.java
  2. 1 1
      applications/money/money-dto/src/main/java/com/usoftchina/saas/money/dto/VerificationDTO.java
  3. 5 1
      applications/money/money-dto/src/main/java/com/usoftchina/saas/money/dto/VerificationdetDTO.java
  4. 5 1
      applications/money/money-dto/src/main/java/com/usoftchina/saas/money/dto/VerificationdetailDTO.java
  5. 2 0
      applications/money/money-server/src/main/java/com/usoftchina/saas/money/mapper/VerificationMapper.java
  6. 0 14
      applications/money/money-server/src/main/java/com/usoftchina/saas/money/po/Verification.java
  7. 20 0
      applications/money/money-server/src/main/java/com/usoftchina/saas/money/po/Verificationdet.java
  8. 20 0
      applications/money/money-server/src/main/java/com/usoftchina/saas/money/po/Verificationdetail.java
  9. 4 4
      applications/money/money-server/src/main/java/com/usoftchina/saas/money/service/impl/PaybalanceServiceImpl.java
  10. 4 4
      applications/money/money-server/src/main/java/com/usoftchina/saas/money/service/impl/RecbalanceServiceImpl.java
  11. 631 9
      applications/money/money-server/src/main/java/com/usoftchina/saas/money/service/impl/VerificationServiceImpl.java
  12. 3 2
      applications/money/money-server/src/main/resources/mapper/VerificationListMapper.xml
  13. 14 13
      applications/money/money-server/src/main/resources/mapper/VerificationMapper.xml
  14. 16 15
      applications/money/money-server/src/main/resources/mapper/VerificationdetMapper.xml
  15. 17 18
      applications/money/money-server/src/main/resources/mapper/VerificationdetailMapper.xml
  16. 12 2
      frontend/saas-web/app/view/money/verification/FormPanel.js
  17. 25 1
      frontend/saas-web/app/view/money/verification/FormPanelController.js
  18. 9 4
      frontend/saas-web/app/view/money/verification/QueryPanel.js

+ 3 - 2
applications/commons/commons-dto/src/main/java/com/usoftchina/saas/commons/exception/BizExceptionCode.java

@@ -75,13 +75,14 @@ public enum BizExceptionCode implements BaseExceptionCode {
     //资金
     PAYBALANCE_OUTNOWBALANCE(74001,"本次核销金额不能大于未核销金额"),
     PAYBALANCE_UNIQUESOURCECODE(74002, "保存失败!不能选择重复的源单"),
-    PAYBALANCE_NOWAMOUNT_POSITIVE(74005, "单据类型为<u>%s</u>的单据,核销金额必须为正数"),
-    PAYBALANCE_NOWAMOUNT_NEGATIVE(74005, "单据类型为<u>%s</u>的单据,核销金额必须为负数"),
+    MONEY_NOWAMOUNT_POSITIVE(74005, "单据类型为<u>%s</u>的单据,核销金额必须为正数"),
+    MONEY_NOWAMOUNT_NEGATIVE(74005, "单据类型为<u>%s</u>的单据,核销金额必须为负数"),
     RECALANCE_OUTNOWBALANCE(74003,"本次核销金额不能大于未核销金额"),
     BEFORE_UNAUDIT(74006, "单据:<u>%s</u>未审核,无法反审核"),
     BANK_AMOUNT_NOTENOUGH(74004, "资金账号不足"),
     SUBLEDGER_NOT_EXIS(74005,"来源单据不存在"),
     CHECK_SETACOUNT_EXIS(74006, "不能删除单据日期小于等于结账期间<u>%s</u>的单据"),
+    VERIFICATION_CHECK_BALANCE(74007,"核销金额不能大于未核销金额"),
 
 
 

+ 1 - 1
applications/money/money-dto/src/main/java/com/usoftchina/saas/money/dto/VerificationDTO.java

@@ -15,7 +15,7 @@ import java.util.Date;
  */
 @Data
 @ApiModel(value = "Verification", description = "核销单")
-public class VerificationDTO implements Serializable {
+public class VerificationDTO extends  CommonBaseDTO implements Serializable {
     private Integer vc_id;
 
     private String vc_code;

+ 5 - 1
applications/money/money-dto/src/main/java/com/usoftchina/saas/money/dto/VerificationdetDTO.java

@@ -14,7 +14,7 @@ import java.util.Date;
  */
 @Data
 @ApiModel(value = "Verificationdet", description = "核销单明细一")
-public class VerificationdetDTO  implements Serializable {
+public class VerificationdetDTO  extends  CommonBaseDTO implements Serializable {
     private Integer vd_id;
 
     private Integer vd_vcid;
@@ -46,4 +46,8 @@ public class VerificationdetDTO  implements Serializable {
     private String vd_text4;
 
     private String vd_text5;
+
+    private Double sl_yamount;
+
+    private Double sl_namount;
 }

+ 5 - 1
applications/money/money-dto/src/main/java/com/usoftchina/saas/money/dto/VerificationdetailDTO.java

@@ -14,7 +14,7 @@ import java.util.Date;
  */
 @Data
 @ApiModel(value = "Verificationdetail", description = "核销单明细二")
-public class VerificationdetailDTO implements Serializable {
+public class VerificationdetailDTO extends  CommonBaseDTO implements Serializable {
     private Integer vcd_id;
 
     private Integer vcd_vcid;
@@ -47,4 +47,8 @@ public class VerificationdetailDTO implements Serializable {
 
     private String vcd_text5;
 
+    private Double sl_yamount;
+
+    private Double sl_namount;
+
 }

+ 2 - 0
applications/money/money-server/src/main/java/com/usoftchina/saas/money/mapper/VerificationMapper.java

@@ -38,4 +38,6 @@ public interface VerificationMapper extends CommonBaseMapper<Verification> {
     String selectCodeById(Long id);
 
     String validateResAudit(Long id);
+
+    int validateSetAcount(int detno);
 }

+ 0 - 14
applications/money/money-server/src/main/java/com/usoftchina/saas/money/po/Verification.java

@@ -303,19 +303,5 @@ public class Verification extends CommonBaseEntity implements Serializable {
         this.vc_text5 = vc_text5 == null ? null : vc_text5.trim();
     }
 
-    @Override
-    public void setCreatorId(long creatorId) {
 
-    }
-
-    @Override
-    public void setUpdaterId(long updaterId) {
-
-    }
-
-
-    @Override
-    public void setCompanyId(long companyId) {
-
-    }
 }

+ 20 - 0
applications/money/money-server/src/main/java/com/usoftchina/saas/money/po/Verificationdet.java

@@ -44,6 +44,10 @@ public class Verificationdet extends CommonBaseEntity implements Serializable {
 
     private String vd_text5;
 
+    private Double sl_yamount;
+
+    private Double sl_namount;
+
     public Integer getVd_id() {
         return vd_id;
     }
@@ -171,4 +175,20 @@ public class Verificationdet extends CommonBaseEntity implements Serializable {
     public void setVd_text5(String vd_text5) {
         this.vd_text5 = vd_text5 == null ? null : vd_text5.trim();
     }
+
+    public Double getSl_yamount() {
+        return sl_yamount;
+    }
+
+    public void setSl_yamount(Double sl_yamount) {
+        this.sl_yamount = sl_yamount;
+    }
+
+    public Double getSl_namount() {
+        return sl_namount;
+    }
+
+    public void setSl_namount(Double sl_namount) {
+        this.sl_namount = sl_namount;
+    }
 }

+ 20 - 0
applications/money/money-server/src/main/java/com/usoftchina/saas/money/po/Verificationdetail.java

@@ -44,6 +44,10 @@ public class Verificationdetail extends CommonBaseEntity implements Serializable
 
     private String vcd_text5;
 
+    private Double sl_yamount;
+
+    private Double sl_namount;
+
     public Integer getVcd_id() {
         return vcd_id;
     }
@@ -171,4 +175,20 @@ public class Verificationdetail extends CommonBaseEntity implements Serializable
     public void setVcd_text5(String vcd_text5) {
         this.vcd_text5 = vcd_text5 == null ? null : vcd_text5.trim();
     }
+
+    public Double getSl_yamount() {
+        return sl_yamount;
+    }
+
+    public void setSl_yamount(Double sl_yamount) {
+        this.sl_yamount = sl_yamount;
+    }
+
+    public Double getSl_namount() {
+        return sl_namount;
+    }
+
+    public void setSl_namount(Double sl_namount) {
+        this.sl_namount = sl_namount;
+    }
 }

+ 4 - 4
applications/money/money-server/src/main/java/com/usoftchina/saas/money/service/impl/PaybalanceServiceImpl.java

@@ -153,14 +153,14 @@ public class PaybalanceServiceImpl extends CommonBaseServiceImpl<PaybalanceMappe
             //单据金额
             Double amount = detail.getPbd_amount();
             if(amount>0 && nowbalance<0){
-                String msg = BizExceptionCode.PAYBALANCE_NOWAMOUNT_POSITIVE.getMessage();
-                int code = BizExceptionCode.PAYBALANCE_NOWAMOUNT_POSITIVE.getCode();
+                String msg = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getMessage();
+                int code = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getCode();
                 String error = String.format(msg, detail.getPbd_slkind());
                 throw new BizException(code, error);
             }
             if(amount<0 && nowbalance>0){
-                String msg = BizExceptionCode.PAYBALANCE_NOWAMOUNT_NEGATIVE.getMessage();
-                int code = BizExceptionCode.PAYBALANCE_NOWAMOUNT_NEGATIVE.getCode();
+                String msg = BizExceptionCode.MONEY_NOWAMOUNT_NEGATIVE.getMessage();
+                int code = BizExceptionCode.MONEY_NOWAMOUNT_NEGATIVE.getCode();
                 String error = String.format(msg, detail.getPbd_slkind());
                 throw new BizException(code, error);
             }

+ 4 - 4
applications/money/money-server/src/main/java/com/usoftchina/saas/money/service/impl/RecbalanceServiceImpl.java

@@ -151,14 +151,14 @@ public class RecbalanceServiceImpl extends CommonBaseServiceImpl<RecbalanceMappe
             //单据金额
             Double amount = detail.getRbd_amount();
             if(amount>0 && nowbalance<0){
-                String msg = BizExceptionCode.PAYBALANCE_NOWAMOUNT_POSITIVE.getMessage();
-                int code = BizExceptionCode.PAYBALANCE_NOWAMOUNT_POSITIVE.getCode();
+                String msg = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getMessage();
+                int code = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getCode();
                 String error = String.format(msg, detail.getRbd_slkind());
                 throw new BizException(500, error);
             }
             if(amount<0 && nowbalance>0){
-                String msg = BizExceptionCode.PAYBALANCE_NOWAMOUNT_POSITIVE.getMessage();
-                int code = BizExceptionCode.PAYBALANCE_NOWAMOUNT_POSITIVE.getCode();
+                String msg = BizExceptionCode.MONEY_NOWAMOUNT_NEGATIVE.getMessage();
+                int code = BizExceptionCode.MONEY_NOWAMOUNT_NEGATIVE.getCode();
                 String error = String.format(msg, detail.getRbd_slkind());
                 throw new BizException(code, error);
             }

+ 631 - 9
applications/money/money-server/src/main/java/com/usoftchina/saas/money/service/impl/VerificationServiceImpl.java

@@ -16,10 +16,7 @@ import com.usoftchina.saas.commons.po.Status;
 import com.usoftchina.saas.context.BaseContextHolder;
 import com.usoftchina.saas.exception.BizException;
 import com.usoftchina.saas.money.dto.*;
-import com.usoftchina.saas.money.mapper.VerificationListMapper;
-import com.usoftchina.saas.money.mapper.VerificationMapper;
-import com.usoftchina.saas.money.mapper.VerificationdetMapper;
-import com.usoftchina.saas.money.mapper.VerificationdetailMapper;
+import com.usoftchina.saas.money.mapper.*;
 import com.usoftchina.saas.money.po.*;
 import com.usoftchina.saas.money.service.VerificationService;
 import com.usoftchina.saas.page.PageRequest;
@@ -29,10 +26,12 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
 import javax.print.DocFlavor;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
+import java.util.logging.SimpleFormatter;
 
 @Service
 public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationMapper,Verification> implements VerificationService {
@@ -48,6 +47,12 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
     private VerificationListMapper verificationListMapper;
     @Autowired
     private MessageLogService messageLogService;
+    @Autowired
+    private SubledgerMapper subledgerMapper;
+    @Autowired
+    private RecbalanceMapper recbalanceMapper;
+    @Autowired
+    private PaybalanceMapper paybalanceMapper;
 
 
     @Override
@@ -93,6 +98,8 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
 
         List<Verificationdetail> verificationdetail = verificationdetailMapper.selectByFK(id);
         List<VerificationdetailDTO> items2 = BeanMapper.mapList(verificationdetail, VerificationdetailDTO.class);
+        String type = main.getVc_kind();
+        main.setVc_kind(transferKind(type));
         verificationFormDTO.setMain(main);
         verificationFormDTO.setItems1(items1);
         verificationFormDTO.setItems2(items2);
@@ -122,32 +129,40 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
         List<Verificationdet> updateDetails1 = new ArrayList<>();
         List<Verificationdetail> updateDetails2 = new ArrayList<>();
         DocSavedDTO saveDTO = new DocSavedDTO();
-        Long id = Long.valueOf(String.valueOf(main.getVc_id()));
+        Long id = main.getId();
         String code = main.getVc_code();
         Verification verification = BeanMapper.map(main,Verification.class);
         verification.setCompanyId(companyId);
         verification.setCreatorId(userId);
         verification.setCreateTime(new Date());
+        String kind = verification.getVc_kind();
+        verification.setVc_kind(transferKind(kind));
+
         //编号获取
         code = pushMaxnubmer(code,id);
-//        code = "1";
         verification.setVc_code(code);
         saveDTO.setCode(code);
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("YYYYMM");
+        String dateYM = simpleDateFormat.format(verification.getVc_date());
+        Integer numberYM = Integer.valueOf(dateYM);
         //判断更新与保存动作
         if (StringUtils.isEmpty(id) || "0".equals(id.toString())){
             //插入操作
             getMapper().insertSelective(verification);
             id = verification.getId();
+
             //添加从表传输对象
             for (VerificationdetDTO item : items1) {
                 Verificationdet detail = BeanMapper.map(item,Verificationdet.class);
                 detail.setVd_vcid(id);
                 detail.setCompanyId(companyId);
+                detail.setVd_ym(numberYM);
                 insertDetails1.add(detail);
             }
             for (VerificationdetailDTO item : items2) {
                 Verificationdetail detail = BeanMapper.map(item,Verificationdetail.class);
                 detail.setVcd_vcid(id);
+                detail.setVcd_ym(numberYM);
                 detail.setCompanyId(companyId);
                 insertDetails2.add(detail);
             }
@@ -158,8 +173,6 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
             if (insertDetails2.size()>0) {
                 verificationdetailMapper.batchInsert(insertDetails2);
             }
-            saveDTO.setId(id);
-            return saveDTO;
         }
         //更新操作
         getMapper().updateByPrimaryKeySelective(verification);
@@ -167,6 +180,7 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
         for (VerificationdetDTO item : items1) {
             Verificationdet detail = BeanMapper.map(item, Verificationdet.class);
             detail.setVd_vcid(id);
+            detail.setVd_ym(numberYM);
             detail.setCompanyId(companyId);
             if (StringUtils.isEmpty(detail.getId()) || "0".equals(detail.getId().toString())) {
                 insertDetails1.add(detail);
@@ -177,6 +191,7 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
         for (VerificationdetailDTO item : items2) {
             Verificationdetail detail = BeanMapper.map(item, Verificationdetail.class);
             detail.setVcd_vcid(id);
+            detail.setVcd_ym(numberYM);
             detail.setCompanyId(companyId);
             if (StringUtils.isEmpty(detail.getId()) || "0".equals(detail.getId().toString())) {
                 insertDetails2.add(detail);
@@ -198,19 +213,186 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
         if (updateDetails2.size()>0) {
             verificationdetailMapper.batchUpdate(updateDetails2);
         }
-
+        updateCorrespondingData(formdata);
         saveDTO.setId(id);
         return saveDTO;
     }
 
+    private void updateCorrespondingData(VerificationFormDTO formdata) {
+        //获取主表信息
+        VerificationDTO main = formdata.getMain();
+        //获取从表1
+        List<VerificationdetDTO> items1 = formdata.getItems1();
+        //获取从表2
+        List<VerificationdetailDTO> items2 = formdata.getItems2();
+
+        String type = main.getVc_kind();
+        if(type.equals("receipts_offset_receivable") || type.equals("prepaid_offset_payable") ||
+                type.equals("receivable_offset_payable")){
+            Double total1 = new Double(0);
+            for(VerificationdetDTO det : items1){
+                Double nowbalanceDet = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
+                total1 += nowbalanceDet;
+
+                //单据金额
+                Double amount = det.getVd_amount();
+                //核销金额
+                if(amount>0 && nowbalanceDet<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<0 && nowbalanceDet>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);
+                }
+            }
+            Double total2 = new Double(0);
+            for(VerificationdetailDTO detail : items2){
+                Double nowbalanceDet = detail.getVcd_nowbalance()==null?new Double(0):detail.getVcd_nowbalance();
+                total2 += nowbalanceDet;
+
+                //单据金额
+                Double amount = detail.getVcd_amount();
+                //核销金额
+                if(amount>0 && nowbalanceDet<0){
+                    String msg = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getMessage();
+                    int code = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getCode();
+                    String error = String.format(msg, detail.getVcd_slkind());
+                    throw new BizException(code, error);
+                }
+                if(amount<0 && nowbalanceDet>0){
+                    String msg = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getMessage();
+                    int code = BizExceptionCode.MONEY_NOWAMOUNT_POSITIVE.getCode();
+                    String error = String.format(msg, detail.getVcd_slkind());
+                    throw new BizException(code, error);
+                }
+            }
+            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(VerificationdetDTO 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<nowbalance){
+                    throw new BizException(500, BizExceptionCode.VERIFICATION_CHECK_BALANCE.getMessage());
+                }
+            }
+        }
+
+    }
+
+    //插入中间表
+    private Subledger changSubledgerUntil(VerificationDTO verification){
+        Subledger subledger = new Subledger();
+        String kind = verification.getVc_kind();
+        subledger.setCompanyId(BaseContextHolder.getCompanyId());
+        subledger.setSl_code(verification.getVc_code());
+        subledger.setSl_kind(kind);
+        if(kind.equals("receipts_offset_receivable") || kind.equals("prepaid_offset_payable") ||
+                kind.equals("receivable_offset_payable")){
+            subledger.setSl_custid(0);
+            subledger.setSl_vendid(verification.getVc_vendid());
+        }else{
+            subledger.setSl_custid(verification.getVc_custid());
+            subledger.setSl_vendid(0);
+        }
+
+        subledger.setSl_date(verification.getVc_date());
+        subledger.setSl_amount(-verification.getVc_amount2());
+        subledger.setSl_orderamount(new Double(0));
+        subledger.setSl_yamount(new Double(0));
+        subledger.setSl_remark(verification.getVc_remark());
+        subledger.setSl_discount(new Double(0));
+        if(kind.equals("receipts_offset_receivable") || kind.equals("prepaid_offset_payable")){
+            subledger.setSl_preamount(-verification.getVc_amount1());
+        }else{
+            subledger.setSl_preamount(new Double(0));
+        }
+        return subledger;
+    }
+    /**
+     * 审核更新来源单据的已核销,未核销
+     * @param id
+     * @param nowBalance
+     */
+    private void updateAuditSubledeger(int id , Double nowBalance){
+        Subledger subledger = subledgerMapper.selectByPrimaryKey(id);
+        Subledger newSubledeger = new Subledger();
+        newSubledeger.setId(Long.valueOf(String.valueOf(id)));
+        Double newNamout = subledger.getSl_namount()==null?new Double(0):subledger.getSl_namount()-nowBalance;
+        Double newYamout = subledger.getSl_yamount()==null?new Double(0):subledger.getSl_yamount()+nowBalance;
+        newSubledeger.setSl_yamount(newYamout);
+        newSubledeger.setSl_namount(newNamout);
+        newSubledeger.setCompanyId(BaseContextHolder.getCompanyId());
+        newSubledeger.setUpdaterName(BaseContextHolder.getUserName());
+        newSubledeger.setUpdaterId(BaseContextHolder.getUserId());
+        newSubledeger.setUpdateTime(new Date());
+        subledgerMapper.updateByPrimaryKey(newSubledeger);
+    }
+    /**
+     * 反审核更新来源单据的已核销,未核销
+     * @param id
+     * @param nowBalance
+     */
+    private void updateResAuditSubledeger(int id , Double nowBalance){
+        Subledger subledger = subledgerMapper.selectByPrimaryKey(id);
+        Subledger newSubledeger = new Subledger();
+        newSubledeger.setId(Long.valueOf(String.valueOf(id)));
+        Double newNamout = subledger.getSl_namount()==null?new Double(0):subledger.getSl_namount()+nowBalance;
+        Double newYamout = subledger.getSl_yamount()==null?new Double(0):subledger.getSl_yamount()-nowBalance;
+        newSubledeger.setSl_yamount(newYamout);
+        newSubledeger.setSl_namount(newNamout);
+        newSubledeger.setCompanyId(BaseContextHolder.getCompanyId());
+        newSubledeger.setUpdaterName(BaseContextHolder.getUserName());
+        newSubledeger.setUpdaterId(BaseContextHolder.getUserId());
+        newSubledeger.setUpdateTime(new Date());
+        subledgerMapper.updateByPrimaryKey(newSubledeger);
+    }
+    /**
+     * 转换核销单类型
+     * @param kind
+     * @return
+     */
+    private String transferKind(String kind) {
+        switch (kind) {
+            case  "receipts_offset_receivable" :
+                return "预收冲应收";
+            case "prepaid_offset_payable":
+                return "预付冲应付";
+            case "receivable_offset_payable":
+                return "应收冲应付";
+            case "receivable_to_receivable":
+                return "应收转应收";
+            case "payable_to_payable":
+                return "应付转应付";
+                default:return "";
+        }
+    }
+
     @Override
     public void delete(Long id) {
         if (null != id) {
+            Verification verification = verificationMapper.selectByPrimaryKey(Math.toIntExact(id));
+            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMM");
+            String ym = simpleDateFormat.format(verification.getVc_date());
+            int detno = Integer.valueOf(ym);
+            if(checkSetAcount(detno)){
+                throw new BizException(500, BizExceptionCode.CHECK_SETACOUNT_EXIS.getMessage());
+            }
+            //删除中间表
+            subledgerMapper.deleteByPrimaryKey(verification.getVc_code(),verification.getVc_kind());
+
             //从表删除
             verificationdetMapper.deleteByParentPrimaryKey(id);
             verificationdetailMapper.deleteByParentPrimaryKey(id);
             //主表删除
             verificationMapper.deleteByPrimaryKey(id);
+
             String code = verificationMapper.selectCodeById(id);
             DocBaseDTO baseDTO = new DocBaseDTO();
             baseDTO.setId(id);
@@ -221,6 +403,18 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
         }
     }
 
+    /**
+     *
+     * @param id
+     */
+    private boolean checkSetAcount(Integer detno){
+        boolean isSetAcount = false;
+        int count = verificationMapper.validateSetAcount(detno);
+        if(count>0){
+            isSetAcount = true;
+        }
+        return isSetAcount;
+    }
     @Override
     public void deleteDetail1(Long id) {
         if (null != id) {
@@ -266,11 +460,202 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
             verification.setVc_statuscode(Status.AUDITED.name());
             verification.setVc_id(Integer.valueOf(String.valueOf(id)));
             verificationMapper.updateByPrimaryKeySelective(verification);
+
+
+            VerificationDTO verificationDTO = formData.getMain();
+            Subledger subledger = changSubledgerUntil(verificationDTO);
+            subledgerMapper.insertSelective(subledger);
+
+            //更新客户或者供应商的金额
+            updateAuditCustomer(verificationDTO);
+            updateAuditVendor(verificationDTO);
+
+            //更新源单金额
+            //获取从表1
+            List<VerificationdetDTO> items1 = formData.getItems1();
+            //获取从表2
+            List<VerificationdetailDTO> items2 = formData.getItems2();
+            for(VerificationdetDTO det : items1){
+                Double nowbalanceDet = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
+                updateAuditSubledeger(det.getVd_slid(),nowbalanceDet);
+            }
+            for(VerificationdetailDTO detail : items2){
+                Double nowbalanceDet = detail.getVcd_nowbalance()==null?new Double(0):detail.getVcd_nowbalance();
+                updateAuditSubledeger(detail.getVcd_slid(),nowbalanceDet);
+            }
         }
         savedDTO.setId(id);
         return savedDTO;
     }
 
+    /**
+     * 审核更新客户金额
+     * @param verificationDTO
+     * @return
+     */
+    private void updateAuditCustomer(VerificationDTO verificationDTO){
+        String kind = verificationDTO.getVc_kind();
+        if(kind.equals("receipts_offset_receivable")){
+            Customer customerData = recbalanceMapper.selectCustomerByPrimaryKey(verificationDTO.getVc_custid());
+            Double preamount = customerData.getCu_preamount()==null?new Double(0):customerData.getCu_preamount();
+            Double beginapamount = customerData.getCu_beginaramount()==null?new Double(0):customerData.getCu_beginaramount();
+            Double beginprepayamount= customerData.getCu_beginprerecamount()==null?new Double(0):customerData.getCu_beginprerecamount();
+            Double recamount = customerData.getCu_recamount()==null?new Double(0):customerData.getCu_recamount();
+
+            Customer customer = new Customer();
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            customer.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_custid())));
+            customer.setCompanyId(BaseContextHolder.getCompanyId());
+            customer.setUpdaterId(BaseContextHolder.getUserId());
+            customer.setUpdaterName(BaseContextHolder.getUserName());
+            customer.setUpdateTime(new Date());
+            customer.setCu_preamount(preamount+amount1);
+            customer.setCu_recamount(recamount-amount2);
+            customer.setCu_leftamount(beginapamount-beginprepayamount+recamount-amount2-preamount-amount1);
+            recbalanceMapper.updateCustomerByPrimaryKeySelective(customer);
+        }else if(kind.equals("receivable_offset_payable")){
+            Customer customerData = recbalanceMapper.selectCustomerByPrimaryKey(verificationDTO.getVc_custid());
+            Double preamount = customerData.getCu_preamount()==null?new Double(0):customerData.getCu_preamount();
+            Double beginapamount = customerData.getCu_beginaramount()==null?new Double(0):customerData.getCu_beginaramount();
+            Double beginprepayamount= customerData.getCu_beginprerecamount()==null?new Double(0):customerData.getCu_beginprerecamount();
+            Double recamount = customerData.getCu_recamount()==null?new Double(0):customerData.getCu_recamount();
+
+            Customer customer = new Customer();
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            customer.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_custid())));
+            customer.setCompanyId(BaseContextHolder.getCompanyId());
+            customer.setUpdaterId(BaseContextHolder.getUserId());
+            customer.setUpdaterName(BaseContextHolder.getUserName());
+            customer.setUpdateTime(new Date());
+            customer.setCu_recamount(recamount-amount1);
+            customer.setCu_leftamount(beginapamount-beginprepayamount+recamount-amount1-preamount);
+            recbalanceMapper.updateCustomerByPrimaryKeySelective(customer);
+        }else if(kind.equals("receivable_to_receivable")){
+            //转入客户
+            Customer customerIn = recbalanceMapper.selectCustomerByPrimaryKey(verificationDTO.getVc_turncustid());
+            //转出客户
+            Customer customerOut = recbalanceMapper.selectCustomerByPrimaryKey(verificationDTO.getVc_custid());
+
+            Double preamountIn = customerIn.getCu_preamount()==null?new Double(0):customerIn.getCu_preamount();
+            Double beginapamountIn = customerIn.getCu_beginaramount()==null?new Double(0):customerIn.getCu_beginaramount();
+            Double beginprepayamountIn = customerIn.getCu_beginprerecamount()==null?new Double(0):customerIn.getCu_beginprerecamount();
+            Double recamountIn = customerIn.getCu_recamount()==null?new Double(0):customerIn.getCu_recamount();
+
+            Double preamountOut = customerOut.getCu_preamount()==null?new Double(0):customerOut.getCu_preamount();
+            Double beginapamountOut = customerOut.getCu_beginaramount()==null?new Double(0):customerOut.getCu_beginaramount();
+            Double beginprepayamountOut = customerOut.getCu_beginprerecamount()==null?new Double(0):customerOut.getCu_beginprerecamount();
+            Double recamountOut = customerOut.getCu_recamount()==null?new Double(0):customerOut.getCu_recamount();
+
+
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            Customer newCustomerIn = new Customer();
+            newCustomerIn.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_turncustid())));
+            newCustomerIn.setCompanyId(BaseContextHolder.getCompanyId());
+            newCustomerIn.setUpdaterId(BaseContextHolder.getUserId());
+            newCustomerIn.setUpdaterName(BaseContextHolder.getUserName());
+            newCustomerIn.setUpdateTime(new Date());
+            newCustomerIn.setCu_recamount(recamountIn-amount1);
+            newCustomerIn.setCu_leftamount(beginapamountIn-beginprepayamountIn+recamountIn-amount1-preamountIn);
+            recbalanceMapper.updateCustomerByPrimaryKeySelective(newCustomerIn);
+
+            Customer newCustomerOut = new Customer();
+            newCustomerOut.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_custid())));
+            newCustomerOut.setCompanyId(BaseContextHolder.getCompanyId());
+            newCustomerOut.setUpdaterId(BaseContextHolder.getUserId());
+            newCustomerOut.setUpdaterName(BaseContextHolder.getUserName());
+            newCustomerOut.setUpdateTime(new Date());
+            newCustomerOut.setCu_recamount(recamountOut-amount1);
+            newCustomerOut.setCu_leftamount(beginapamountOut-beginprepayamountOut+recamountOut-amount1-preamountOut);
+            recbalanceMapper.updateCustomerByPrimaryKeySelective(newCustomerOut);
+        }
+    }
+
+    /**
+     * 审核更新供应商金额
+     * @param verificationDTO
+     * @return
+     */
+    private void updateAuditVendor(VerificationDTO verificationDTO){
+        String kind = verificationDTO.getVc_kind();
+        if(kind.equals("prepaid_offset_payable")){
+            Vendor vendorData = paybalanceMapper.selectVendorByPrimaryKey(verificationDTO.getVc_vendid());
+            Double preamount = vendorData.getVe_preamount()==null?new Double(0):vendorData.getVe_preamount();
+            Double beginapamount = vendorData.getVe_beginapamount()==null?new Double(0):vendorData.getVe_beginapamount();
+            Double beginprepayamount= vendorData.getVe_beginprepayamount()==null?new Double(0):vendorData.getVe_beginprepayamount();
+            Double payamount = vendorData.getVe_payamount()==null?new Double(0):vendorData.getVe_payamount();
+
+            Vendor vendor = new Vendor();
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            vendor.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_vendid())));
+            vendor.setCompanyId(BaseContextHolder.getCompanyId());
+            vendor.setUpdaterId(BaseContextHolder.getUserId());
+            vendor.setUpdaterName(BaseContextHolder.getUserName());
+            vendor.setUpdateTime(new Date());
+            vendor.setVe_preamount(preamount-amount1);
+            vendor.setVe_payamount(payamount+amount2);
+            vendor.setVe_leftamount(beginapamount-beginprepayamount+payamount+amount2-preamount+amount1);
+            paybalanceMapper.updateVendorByPrimaryKeySelective(vendor);
+        }else if(kind.equals("receivable_offset_payable")){
+            Vendor vendorData = paybalanceMapper.selectVendorByPrimaryKey(verificationDTO.getVc_vendid());
+            Double preamount = vendorData.getVe_preamount()==null?new Double(0):vendorData.getVe_preamount();
+            Double beginapamount = vendorData.getVe_beginapamount()==null?new Double(0):vendorData.getVe_beginapamount();
+            Double beginprepayamount= vendorData.getVe_beginprepayamount()==null?new Double(0):vendorData.getVe_beginprepayamount();
+            Double payamount = vendorData.getVe_payamount()==null?new Double(0):vendorData.getVe_payamount();
+
+            Vendor vendor = new Vendor();
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            vendor.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_vendid())));
+            vendor.setVe_payamount(payamount+amount2);
+            vendor.setUpdaterId(BaseContextHolder.getUserId());
+            vendor.setUpdaterName(BaseContextHolder.getUserName());
+            vendor.setUpdateTime(new Date());
+            vendor.setVe_leftamount(beginapamount-beginprepayamount+payamount+amount2-preamount);
+            paybalanceMapper.updateVendorByPrimaryKeySelective(vendor);
+        }else if(kind.equals("payable_to_payable")){
+            //转入供应商
+            Vendor vendorIn = paybalanceMapper.selectVendorByPrimaryKey(verificationDTO.getVc_turnvendid());
+            //转出供应商
+            Vendor vendorOut = paybalanceMapper.selectVendorByPrimaryKey(verificationDTO.getVc_vendid());
+
+            Double preamountIn = vendorIn.getVe_preamount()==null?new Double(0):vendorIn.getVe_preamount();
+            Double beginapamountIn = vendorIn.getVe_beginapamount()==null?new Double(0):vendorIn.getVe_beginapamount();
+            Double beginprepayamountIn = vendorIn.getVe_beginprepayamount()==null?new Double(0):vendorIn.getVe_beginprepayamount();
+            Double payamountIn = vendorIn.getVe_payamount()==null?new Double(0):vendorIn.getVe_payamount();
+
+            Double preamountOut = vendorOut.getVe_preamount()==null?new Double(0):vendorOut.getVe_preamount();
+            Double beginapamountOut = vendorOut.getVe_beginapamount()==null?new Double(0):vendorOut.getVe_beginapamount();
+            Double beginprepayamountOut = vendorOut.getVe_beginprepayamount()==null?new Double(0):vendorOut.getVe_beginprepayamount();
+            Double payamountOut = vendorOut.getVe_payamount()==null?new Double(0):vendorOut.getVe_payamount();
+
+
+
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            Vendor newVendorIn = new Vendor();
+            newVendorIn.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_turnvendid())));
+            newVendorIn.setUpdaterId(BaseContextHolder.getUserId());
+            newVendorIn.setUpdaterName(BaseContextHolder.getUserName());
+            newVendorIn.setUpdateTime(new Date());
+            newVendorIn.setVe_payamount(payamountIn+amount1);
+            newVendorIn.setVe_leftamount(beginapamountIn-beginprepayamountIn+payamountIn+amount1-preamountIn);
+            paybalanceMapper.updateVendorByPrimaryKeySelective(newVendorIn);
+
+            Vendor newVendorOut = new Vendor();
+            newVendorOut.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_vendid())));
+            newVendorOut.setUpdaterId(BaseContextHolder.getUserId());
+            newVendorOut.setUpdaterName(BaseContextHolder.getUserName());
+            newVendorOut.setUpdateTime(new Date());
+            newVendorOut.setVe_payamount(payamountOut-amount1);
+            newVendorOut.setVe_leftamount(beginapamountOut-beginprepayamountOut+payamountOut-amount1-preamountOut);
+            paybalanceMapper.updateVendorByPrimaryKeySelective(newVendorOut);
+
+        }
+    }
     @Override
     public void resAudit(Long id) {
         if (null == id) {
@@ -282,6 +667,27 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
             int errCode = BizExceptionCode.BEFORE_UNAUDIT.getCode();
             throw new BizException(errCode, String.format(msg, code));
         }
+
+        //更新客户或者供应商的金额
+        Verification nowverification = verificationMapper.selectByPrimaryKey(id);
+        VerificationDTO verificationDTO = BeanMapper.map(nowverification,VerificationDTO.class);
+        updateResAuditCustomer(verificationDTO);
+        updateResAuditVendor(verificationDTO);
+
+        //更新源单金额
+        //获取从表1
+        List<Verificationdet> items1 = verificationdetMapper.selectByFK(id);
+        //获取从表2
+        List<Verificationdetail> items2 = verificationdetailMapper.selectByFK(id);
+        for(Verificationdet det : items1){
+            Double nowbalanceDet = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
+            updateAuditSubledeger(det.getVd_slid(),nowbalanceDet);
+        }
+        for(Verificationdetail detail : items2){
+            Double nowbalanceDet = detail.getVcd_nowbalance()==null?new Double(0):detail.getVcd_nowbalance();
+            updateAuditSubledeger(detail.getVcd_slid(),nowbalanceDet);
+        }
+
         Verification verification = new Verification();
         //生成更新对象
         verification.setVc_id(Integer.valueOf(String.valueOf(id)));
@@ -298,17 +704,209 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
         //日志
         messageLogService.unAudit(baseDTO);
     }
+    /**
+     * 反审核更新客户金额
+     * @param verificationDTO
+     * @return
+     */
+    private void updateResAuditCustomer(VerificationDTO verificationDTO){
+        String kind = verificationDTO.getVc_kind();
+        if(kind.equals("receipts_offset_receivable")){
+            Customer customerData = recbalanceMapper.selectCustomerByPrimaryKey(verificationDTO.getVc_custid());
+            Double preamount = customerData.getCu_preamount()==null?new Double(0):customerData.getCu_preamount();
+            Double beginapamount = customerData.getCu_beginaramount()==null?new Double(0):customerData.getCu_beginaramount();
+            Double beginprepayamount= customerData.getCu_beginprerecamount()==null?new Double(0):customerData.getCu_beginprerecamount();
+            Double recamount = customerData.getCu_recamount()==null?new Double(0):customerData.getCu_recamount();
+
+            Customer customer = new Customer();
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            customer.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_custid())));
+            customer.setCompanyId(BaseContextHolder.getCompanyId());
+            customer.setUpdaterId(BaseContextHolder.getUserId());
+            customer.setUpdaterName(BaseContextHolder.getUserName());
+            customer.setUpdateTime(new Date());
+            customer.setCu_preamount(preamount-amount1);
+            customer.setCu_recamount(recamount+amount2);
+            customer.setCu_leftamount(beginapamount-beginprepayamount+recamount+amount2-preamount+amount1);
+            recbalanceMapper.updateCustomerByPrimaryKeySelective(customer);
+        }else if(kind.equals("receivable_offset_payable")){
+            Customer customerData = recbalanceMapper.selectCustomerByPrimaryKey(verificationDTO.getVc_custid());
+            Double preamount = customerData.getCu_preamount()==null?new Double(0):customerData.getCu_preamount();
+            Double beginapamount = customerData.getCu_beginaramount()==null?new Double(0):customerData.getCu_beginaramount();
+            Double beginprepayamount= customerData.getCu_beginprerecamount()==null?new Double(0):customerData.getCu_beginprerecamount();
+            Double recamount = customerData.getCu_recamount()==null?new Double(0):customerData.getCu_recamount();
+
+            Customer customer = new Customer();
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            customer.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_custid())));
+            customer.setCompanyId(BaseContextHolder.getCompanyId());
+            customer.setUpdaterId(BaseContextHolder.getUserId());
+            customer.setUpdaterName(BaseContextHolder.getUserName());
+            customer.setUpdateTime(new Date());
+            customer.setCu_recamount(recamount+amount1);
+            customer.setCu_leftamount(beginapamount-beginprepayamount+recamount+amount1-preamount);
+            recbalanceMapper.updateCustomerByPrimaryKeySelective(customer);
+        }else if(kind.equals("receivable_to_receivable")){
+            //转入客户
+            Customer customerIn = recbalanceMapper.selectCustomerByPrimaryKey(verificationDTO.getVc_turncustid());
+            //转出客户
+            Customer customerOut = recbalanceMapper.selectCustomerByPrimaryKey(verificationDTO.getVc_custid());
+
+            Double preamountIn = customerIn.getCu_preamount()==null?new Double(0):customerIn.getCu_preamount();
+            Double beginapamountIn = customerIn.getCu_beginaramount()==null?new Double(0):customerIn.getCu_beginaramount();
+            Double beginprepayamountIn = customerIn.getCu_beginprerecamount()==null?new Double(0):customerIn.getCu_beginprerecamount();
+            Double recamountIn = customerIn.getCu_recamount()==null?new Double(0):customerIn.getCu_recamount();
+
+            Double preamountOut = customerOut.getCu_preamount()==null?new Double(0):customerOut.getCu_preamount();
+            Double beginapamountOut = customerOut.getCu_beginaramount()==null?new Double(0):customerOut.getCu_beginaramount();
+            Double beginprepayamountOut = customerOut.getCu_beginprerecamount()==null?new Double(0):customerOut.getCu_beginprerecamount();
+            Double recamountOut = customerOut.getCu_recamount()==null?new Double(0):customerOut.getCu_recamount();
+
+
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            Customer newCustomerIn = new Customer();
+            newCustomerIn.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_turncustid())));
+            newCustomerIn.setCompanyId(BaseContextHolder.getCompanyId());
+            newCustomerIn.setUpdaterId(BaseContextHolder.getUserId());
+            newCustomerIn.setUpdaterName(BaseContextHolder.getUserName());
+            newCustomerIn.setUpdateTime(new Date());
+            newCustomerIn.setCu_recamount(recamountIn-amount1);
+            newCustomerIn.setCu_leftamount(beginapamountIn-beginprepayamountIn+recamountIn+amount1-preamountIn);
+            recbalanceMapper.updateCustomerByPrimaryKeySelective(newCustomerIn);
+
+            Customer newCustomerOut = new Customer();
+            newCustomerOut.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_custid())));
+            newCustomerOut.setCompanyId(BaseContextHolder.getCompanyId());
+            newCustomerOut.setUpdaterId(BaseContextHolder.getUserId());
+            newCustomerOut.setUpdaterName(BaseContextHolder.getUserName());
+            newCustomerOut.setUpdateTime(new Date());
+            newCustomerOut.setCu_recamount(recamountOut+amount1);
+            newCustomerOut.setCu_leftamount(beginapamountOut-beginprepayamountOut+recamountOut+amount1-preamountOut);
+            recbalanceMapper.updateCustomerByPrimaryKeySelective(newCustomerOut);
+        }
+    }
+
+    /**
+     * 审核更新供应商金额
+     * @param verificationDTO
+     * @return
+     */
+    private void updateResAuditVendor(VerificationDTO verificationDTO){
+        String kind = verificationDTO.getVc_kind();
+        if(kind.equals("prepaid_offset_payable")){
+            Vendor vendorData = paybalanceMapper.selectVendorByPrimaryKey(verificationDTO.getVc_vendid());
+            Double preamount = vendorData.getVe_preamount()==null?new Double(0):vendorData.getVe_preamount();
+            Double beginapamount = vendorData.getVe_beginapamount()==null?new Double(0):vendorData.getVe_beginapamount();
+            Double beginprepayamount= vendorData.getVe_beginprepayamount()==null?new Double(0):vendorData.getVe_beginprepayamount();
+            Double payamount = vendorData.getVe_payamount()==null?new Double(0):vendorData.getVe_payamount();
+
+            Vendor vendor = new Vendor();
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            vendor.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_vendid())));
+            vendor.setCompanyId(BaseContextHolder.getCompanyId());
+            vendor.setUpdaterId(BaseContextHolder.getUserId());
+            vendor.setUpdaterName(BaseContextHolder.getUserName());
+            vendor.setUpdateTime(new Date());
+            vendor.setVe_preamount(preamount+amount1);
+            vendor.setVe_payamount(payamount-amount2);
+            vendor.setVe_leftamount(beginapamount-beginprepayamount+payamount-amount2-preamount-amount1);
+            paybalanceMapper.updateVendorByPrimaryKeySelective(vendor);
+        }else if(kind.equals("receivable_offset_payable")){
+            Vendor vendorData = paybalanceMapper.selectVendorByPrimaryKey(verificationDTO.getVc_vendid());
+            Double preamount = vendorData.getVe_preamount()==null?new Double(0):vendorData.getVe_preamount();
+            Double beginapamount = vendorData.getVe_beginapamount()==null?new Double(0):vendorData.getVe_beginapamount();
+            Double beginprepayamount= vendorData.getVe_beginprepayamount()==null?new Double(0):vendorData.getVe_beginprepayamount();
+            Double payamount = vendorData.getVe_payamount()==null?new Double(0):vendorData.getVe_payamount();
+
+            Vendor vendor = new Vendor();
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            vendor.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_vendid())));
+            vendor.setVe_payamount(payamount+amount2);
+            vendor.setUpdaterId(BaseContextHolder.getUserId());
+            vendor.setUpdaterName(BaseContextHolder.getUserName());
+            vendor.setUpdateTime(new Date());
+            vendor.setVe_leftamount(beginapamount-beginprepayamount+payamount+amount2-preamount);
+            paybalanceMapper.updateVendorByPrimaryKeySelective(vendor);
+        }else if(kind.equals("payable_to_payable")){
+            //转入供应商
+            Vendor vendorIn = paybalanceMapper.selectVendorByPrimaryKey(verificationDTO.getVc_turnvendid());
+            //转出供应商
+            Vendor vendorOut = paybalanceMapper.selectVendorByPrimaryKey(verificationDTO.getVc_vendid());
+
+            Double preamountIn = vendorIn.getVe_preamount()==null?new Double(0):vendorIn.getVe_preamount();
+            Double beginapamountIn = vendorIn.getVe_beginapamount()==null?new Double(0):vendorIn.getVe_beginapamount();
+            Double beginprepayamountIn = vendorIn.getVe_beginprepayamount()==null?new Double(0):vendorIn.getVe_beginprepayamount();
+            Double payamountIn = vendorIn.getVe_payamount()==null?new Double(0):vendorIn.getVe_payamount();
+
+            Double preamountOut = vendorOut.getVe_preamount()==null?new Double(0):vendorOut.getVe_preamount();
+            Double beginapamountOut = vendorOut.getVe_beginapamount()==null?new Double(0):vendorOut.getVe_beginapamount();
+            Double beginprepayamountOut = vendorOut.getVe_beginprepayamount()==null?new Double(0):vendorOut.getVe_beginprepayamount();
+            Double payamountOut = vendorOut.getVe_payamount()==null?new Double(0):vendorOut.getVe_payamount();
+
 
+
+            Double amount1 = verificationDTO.getVc_amount1()==null?new Double(0):verificationDTO.getVc_amount1();
+            Double amount2 = verificationDTO.getVc_amount2()==null?new Double(0):verificationDTO.getVc_amount2();
+            Vendor newVendorIn = new Vendor();
+            newVendorIn.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_turnvendid())));
+            newVendorIn.setUpdaterId(BaseContextHolder.getUserId());
+            newVendorIn.setUpdaterName(BaseContextHolder.getUserName());
+            newVendorIn.setUpdateTime(new Date());
+            newVendorIn.setVe_payamount(payamountIn+amount1);
+            newVendorIn.setVe_leftamount(beginapamountIn-beginprepayamountIn+payamountIn+amount1-preamountIn);
+            paybalanceMapper.updateVendorByPrimaryKeySelective(newVendorIn);
+
+            Vendor newVendorOut = new Vendor();
+            newVendorOut.setId(Long.valueOf(String.valueOf(verificationDTO.getVc_vendid())));
+            newVendorOut.setUpdaterId(BaseContextHolder.getUserId());
+            newVendorOut.setUpdaterName(BaseContextHolder.getUserName());
+            newVendorOut.setUpdateTime(new Date());
+            newVendorOut.setVe_payamount(payamountOut+amount1);
+            newVendorOut.setVe_leftamount(beginapamountOut-beginprepayamountOut+payamountOut+amount1-preamountOut);
+            paybalanceMapper.updateVendorByPrimaryKeySelective(newVendorOut);
+
+        }
+    }
     @Override
     public void batchAudit(BatchDealBaseDTO baseDTO) {
         Iterator isList = baseDTO.getBaseDTOs().iterator();
         while (isList.hasNext()){
             DocBaseDTO docBaseDTO = (DocBaseDTO) isList.next();
             Long id = docBaseDTO.getId();
+
+            //更新客户或者供应商的金额
+            Verification nowverification = verificationMapper.selectByPrimaryKey(id);
+            VerificationDTO verificationDTO = BeanMapper.map(nowverification,VerificationDTO.class);
+            updateAuditCustomer(verificationDTO);
+            updateAuditVendor(verificationDTO);
+
+            //更新源单金额
+            //获取从表1
+            List<Verificationdet> items1 = verificationdetMapper.selectByFK(id);
+            //获取从表2
+            List<Verificationdetail> items2 = verificationdetailMapper.selectByFK(id);
+            for(Verificationdet det : items1){
+                Double nowbalanceDet = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
+                updateAuditSubledeger(det.getVd_slid(),nowbalanceDet);
+            }
+            for(Verificationdetail detail : items2){
+                Double nowbalanceDet = detail.getVcd_nowbalance()==null?new Double(0):detail.getVcd_nowbalance();
+                updateAuditSubledeger(detail.getVcd_slid(),nowbalanceDet);
+            }
+
             Verification verification = new Verification();
             verification.setVc_status(Status.AUDITED.getDisplay());
             verification.setVc_statuscode(Status.AUDITED.name());
             verification.setVc_id(Integer.valueOf(String.valueOf(id)));
+            verification.setCompanyId(BaseContextHolder.getCompanyId());
+            verification.setUpdaterId(BaseContextHolder.getUserId());
+            verification.setUpdaterName(BaseContextHolder.getUserName());
+            verification.setUpdateTime(new Date());
             verificationMapper.updateByPrimaryKeySelective(verification);
         }
     }
@@ -319,10 +917,34 @@ public class VerificationServiceImpl extends CommonBaseServiceImpl<VerificationM
         while (isList.hasNext()){
             DocBaseDTO docBaseDTO = (DocBaseDTO) isList.next();
             Long id = docBaseDTO.getId();
+
+            //更新客户或者供应商的金额
+            Verification nowverification = verificationMapper.selectByPrimaryKey(id);
+            VerificationDTO verificationDTO = BeanMapper.map(nowverification,VerificationDTO.class);
+            updateResAuditCustomer(verificationDTO);
+            updateResAuditVendor(verificationDTO);
+
+            //更新源单金额
+            //获取从表1
+            List<Verificationdet> items1 = verificationdetMapper.selectByFK(id);
+            //获取从表2
+            List<Verificationdetail> items2 = verificationdetailMapper.selectByFK(id);
+            for(Verificationdet det : items1){
+                Double nowbalanceDet = det.getVd_nowbalance()==null?new Double(0):det.getVd_nowbalance();
+                updateAuditSubledeger(det.getVd_slid(),nowbalanceDet);
+            }
+            for(Verificationdetail detail : items2){
+                Double nowbalanceDet = detail.getVcd_nowbalance()==null?new Double(0):detail.getVcd_nowbalance();
+                updateAuditSubledeger(detail.getVcd_slid(),nowbalanceDet);
+            }
+
             Verification verification = new Verification();
             verification.setVc_status(Status.UNAUDITED.getDisplay());
             verification.setVc_statuscode(Status.UNAUDITED.name());
             verification.setVc_id(Integer.valueOf(String.valueOf(id)));
+            verification.setUpdaterId(BaseContextHolder.getUserId());
+            verification.setUpdaterName(BaseContextHolder.getUserName());
+            verification.setUpdateTime(new Date());
             verificationMapper.updateByPrimaryKeySelective(verification);
         }
     }

+ 3 - 2
applications/money/money-server/src/main/resources/mapper/VerificationListMapper.xml

@@ -46,12 +46,13 @@
 
     </resultMap>
     <sql id="Base_Column_List">
-    vc_id, vc_code, vc_kind, vc_date, vc_vendid, vc_vendcode
+    vc_id, vc_code, vc_kind, vc_date, vc_vendid, vc_vendcode ,vc_custcode ,vc_custid ,vc_amount1
   </sql>
     <select id="selectVerificationListByCondition"  resultMap="BaseResultMap">
         select
         <include refid="Base_Column_List" />
         from verification left join verificationdet on vc_id=vd_vcid
+        and verification.companyid=verificationdet.companyid
         <where>
             <if test="con != null">
                 ${con}
@@ -59,7 +60,7 @@
             <if test="companyId!=null">
                 and verification.companyId=#{companyId}
             </if>
-            order by vc_id
+            order by vc_date desc,vc_id desc
         </where>
     </select>
 

+ 14 - 13
applications/money/money-server/src/main/resources/mapper/VerificationMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="com.usoftchina.saas.money.mapper.VerificationMapper" >
   <resultMap id="BaseResultMap" type="com.usoftchina.saas.money.po.Verification" >
-    <id column="vc_id" property="vc_id" jdbcType="INTEGER" />
+    <id column="vc_id" property="id" jdbcType="INTEGER" />
     <result column="vc_code" property="vc_code" jdbcType="VARCHAR" />
     <result column="vc_kind" property="vc_kind" jdbcType="VARCHAR" />
     <result column="vc_date" property="vc_date" jdbcType="TIMESTAMP" />
@@ -157,9 +157,6 @@
   <insert id="insertSelective" parameterType="com.usoftchina.saas.money.po.Verification" >
     insert into verification
     <trim prefix="(" suffix=")" suffixOverrides="," >
-      <if test="vc_id != null" >
-        vc_id,
-      </if>
       <if test="vc_code != null" >
         vc_code,
       </if>
@@ -255,9 +252,6 @@
       </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides="," >
-      <if test="vc_id != null" >
-        #{vc_id,jdbcType=INTEGER},
-      </if>
       <if test="vc_code != null" >
         #{vc_code,jdbcType=VARCHAR},
       </if>
@@ -352,6 +346,9 @@
         #{vc_text5,jdbcType=VARCHAR},
       </if>
     </trim>
+    <selectKey resultType="Long" keyProperty="id" order="AFTER">
+      SELECT LAST_INSERT_ID()
+    </selectKey>
   </insert>
   <select id="countByExample" parameterType="com.usoftchina.saas.money.po.VerificationExample" resultType="java.lang.Integer" >
     select count(*) from verification
@@ -362,8 +359,8 @@
   <update id="updateByExampleSelective" parameterType="map" >
     update verification
     <set >
-      <if test="record.vc_id != null" >
-        vc_id = #{record.vc_id,jdbcType=INTEGER},
+      <if test="record.id != null" >
+        vc_id = #{record.id,jdbcType=INTEGER},
       </if>
       <if test="record.vc_code != null" >
         vc_code = #{record.vc_code,jdbcType=VARCHAR},
@@ -465,7 +462,7 @@
   </update>
   <update id="updateByExample" parameterType="map" >
     update verification
-    set vc_id = #{record.vc_id,jdbcType=INTEGER},
+    set vc_id = #{record.id,jdbcType=INTEGER},
       vc_code = #{record.vc_code,jdbcType=VARCHAR},
       vc_kind = #{record.vc_kind,jdbcType=VARCHAR},
       vc_date = #{record.vc_date,jdbcType=TIMESTAMP},
@@ -598,7 +595,7 @@
         vc_text5 = #{vc_text5,jdbcType=VARCHAR},
       </if>
     </set>
-    where vc_id = #{vc_id,jdbcType=INTEGER}
+    where vc_id = #{id,jdbcType=INTEGER}
   </update>
   <update id="updateByPrimaryKey" parameterType="com.usoftchina.saas.money.po.Verification" >
     update verification
@@ -633,7 +630,7 @@
       vc_text3 = #{vc_text3,jdbcType=VARCHAR},
       vc_text4 = #{vc_text4,jdbcType=VARCHAR},
       vc_text5 = #{vc_text5,jdbcType=VARCHAR}
-    where vc_id = #{vc_id,jdbcType=INTEGER}
+    where vc_id = #{id,jdbcType=INTEGER}
   </update>
   <select id="validateCodeWhenInsert" resultType="int" parameterType="string" >
     select count(1) from Verification where vc_code = #{code}
@@ -645,6 +642,10 @@
     select vc_code from Verification where vc_id=#{id}
   </select>
   <select id="validateResAudit" parameterType="long" resultType="java.lang.String">
-    select vc_code from Verification where vc_id = #{vc_id} and IFNULL(vc_statuscode,'UNAUDITED')='UNAUDITED'
+    select vc_code from Verification where vc_id = #{id} and IFNULL(vc_statuscode,'UNAUDITED')='UNAUDITED'
+  </select>
+
+  <select id="validateSetAcount" parameterType="long" resultType="java.lang.String">
+    select count(1) from periodsdetail where pd_detno = #{detno} and IFNULL(pd_status,0)=0
   </select>
 </mapper>

+ 16 - 15
applications/money/money-server/src/main/resources/mapper/VerificationdetMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="com.usoftchina.saas.money.mapper.VerificationdetMapper" >
   <resultMap id="BaseResultMap" type="com.usoftchina.saas.money.po.Verificationdet" >
-    <id column="vd_id" property="vd_id" jdbcType="INTEGER" />
+    <id column="vd_id" property="id" jdbcType="INTEGER" />
     <result column="vd_vcid" property="vd_vcid" jdbcType="INTEGER" />
     <result column="vd_detno" property="vd_detno" jdbcType="INTEGER" />
     <result column="vd_ym" property="vd_ym" jdbcType="INTEGER" />
@@ -82,7 +82,8 @@
   </sql>
   <sql id="Base_Column_List" >
     vd_id, vd_vcid, vd_detno, vd_ym, vd_slid, vd_slcode, vd_slkind, vd_sldate, vd_amount, 
-    vd_nowbalance, vd_remark, companyId, updaterId, updateTime, vd_text1, vd_text2, vd_text3, 
+    vd_nowbalance, vd_remark, verificationdet.companyId, verificationdet.updaterId,
+    verificationdet.updateTime, vd_text1, vd_text2, vd_text3,
     vd_text4, vd_text5
   </sql>
   <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.usoftchina.saas.money.po.VerificationdetExample" >
@@ -116,14 +117,14 @@
     </if>
   </delete>
   <insert id="insert" parameterType="com.usoftchina.saas.money.po.Verificationdet" >
-    insert into verificationdet (vd_id, vd_vcid, vd_detno, 
+    insert into verificationdet ( vd_vcid, vd_detno,
       vd_ym, vd_slid, vd_slcode, 
       vd_slkind, vd_sldate, vd_amount, 
       vd_nowbalance, vd_remark, companyId, 
       updaterId, updateTime, vd_text1, 
       vd_text2, vd_text3, vd_text4, 
       vd_text5)
-    values (#{vd_id,jdbcType=INTEGER}, #{vd_vcid,jdbcType=INTEGER}, #{vd_detno,jdbcType=INTEGER}, 
+    values (#{vd_vcid,jdbcType=INTEGER}, #{vd_detno,jdbcType=INTEGER},
       #{vd_ym,jdbcType=INTEGER}, #{vd_slid,jdbcType=INTEGER}, #{vd_slcode,jdbcType=VARCHAR}, 
       #{vd_slkind,jdbcType=VARCHAR}, #{vd_sldate,jdbcType=TIMESTAMP}, #{vd_amount,jdbcType=DOUBLE}, 
       #{vd_nowbalance,jdbcType=DOUBLE}, #{vd_remark,jdbcType=VARCHAR}, #{companyId,jdbcType=INTEGER}, 
@@ -134,9 +135,6 @@
   <insert id="insertSelective" parameterType="com.usoftchina.saas.money.po.Verificationdet" >
     insert into verificationdet
     <trim prefix="(" suffix=")" suffixOverrides="," >
-      <if test="vd_id != null" >
-        vd_id,
-      </if>
       <if test="vd_vcid != null" >
         vd_vcid,
       </if>
@@ -193,9 +191,6 @@
       </if>
     </trim>
     <trim prefix="values (" suffix=")" suffixOverrides="," >
-      <if test="vd_id != null" >
-        #{vd_id,jdbcType=INTEGER},
-      </if>
       <if test="vd_vcid != null" >
         #{vd_vcid,jdbcType=INTEGER},
       </if>
@@ -433,14 +428,13 @@
   <insert id="batchInsert" parameterType="java.util.List" >
     insert into verificationdet
     (
-    vd_id,vd_vcid,vd_detno,vd_ym,vd_slid,vd_slcode,vd_slkind,vd_sldate,
+    vd_vcid,vd_detno,vd_ym,vd_slid,vd_slcode,vd_slkind,vd_sldate,
     vd_amount,vd_nowbalance,vd_remark,companyId,updaterId,updateTime,
     vd_text1,vd_text2,vd_text3,vd_text4,vd_text5
     )
     values
     <foreach collection="list" item="items1" index="index" open="" close="" separator=",">
-      (
-      #{items1.vd_id,jdbcType=INTEGER},#{items1.vd_vcid,jdbcType=INTEGER},#{items1.vd_detno,jdbcType=INTEGER},#{items1.vd_ym,jdbcType=INTEGER},#{items1.vd_slid,jdbcType=INTEGER},
+      (#{items1.vd_vcid,jdbcType=INTEGER},#{items1.vd_detno,jdbcType=INTEGER},#{items1.vd_ym,jdbcType=INTEGER},#{items1.vd_slid,jdbcType=INTEGER},
       #{items1.vd_slcode,jdbcType=VARCHAR},#{items1.vd_slkind,jdbcType=VARCHAR},#{items1.vd_sldate,jdbcType=DATE},#{items1.vd_amount,jdbcType=DOUBLE},
       #{items1.vd_nowbalance,jdbcType=DOUBLE},#{items1.vd_remark,jdbcType=VARCHAR},#{items1.companyId,jdbcType=INTEGER},#{items1.updaterId,jdbcType=INTEGER},#{items1.updateTime,jdbcType=DATE},
       #{items1.vd_text1,jdbcType=VARCHAR},#{items1.vd_text2,jdbcType=VARCHAR},#{items1.vd_text3,jdbcType=VARCHAR},#{items1.vd_text4,jdbcType=VARCHAR},
@@ -451,7 +445,7 @@
   <update id="batchUpdate" parameterType="com.usoftchina.saas.money.po.Verificationdet" >
     <foreach collection="list" item="items1" index="index" open="" close="" separator=";">
       update Verificationdet <set>
-      vd_id = #{items1.vd_id},
+      vd_id = #{items1.id},
       vd_vcid = #{items1.vd_vcid},
       vd_detno = #{items1.vd_detno},
       vd_ym = #{items1.vd_ym},
@@ -478,8 +472,15 @@
     delete from verificationdet
     where vd_id = #{vd_vcid,jdbcType=INTEGER}
   </delete>
+  <sql id="subledger_Column_List" >
+    sl_yamount,sl_namount
+  </sql>
   <select id="selectByFK" parameterType="long" resultMap="BaseResultMap">
-    select * from verificationdet
+    select
+    <include refid="Base_Column_List" />,
+    <include refid="subledger_Column_List" />
+    from verificationdet left join subledger on sl_id=vd_slid and subledger.companyid=verificationdet.companyId
       where vd_vcid=#{vc_id} order by vd_id
   </select>
+
 </mapper>

+ 17 - 18
applications/money/money-server/src/main/resources/mapper/VerificationdetailMapper.xml

@@ -2,7 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
 <mapper namespace="com.usoftchina.saas.money.mapper.VerificationdetailMapper" >
   <resultMap id="BaseResultMap" type="com.usoftchina.saas.money.po.Verificationdetail" >
-    <id column="vcd_id" property="vcd_id" jdbcType="INTEGER" />
+    <id column="vcd_id" property="id" jdbcType="INTEGER" />
     <result column="vcd_vcid" property="vcd_vcid" jdbcType="INTEGER" />
     <result column="vcd_detno" property="vcd_detno" jdbcType="INTEGER" />
     <result column="vcd_ym" property="vcd_ym" jdbcType="INTEGER" />
@@ -82,7 +82,8 @@
   </sql>
   <sql id="Base_Column_List" >
     vcd_id, vcd_vcid, vcd_detno, vcd_ym, vcd_slid, vcd_slcode, vcd_slkind, vcd_sldate,
-    vcd_amount, vcd_nowbalance, vcd_remark, companyId, updaterId, updateTime, vcd_text1,
+    vcd_amount, vcd_nowbalance, vcd_remark, Verificationdetail.companyId,
+    Verificationdetail.updaterId, Verificationdetail.updateTime, vcd_text1,
     vcd_text2, vcd_text3, vcd_text4, vcd_text5
   </sql>
   <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.usoftchina.saas.money.po.VerificationdetailExample" >
@@ -116,14 +117,14 @@
     </if>
   </delete>
   <insert id="insert" parameterType="com.usoftchina.saas.money.po.Verificationdetail" >
-    insert into verificationdetail (vcd_id, vcd_vcid, vcd_detno,
+    insert into verificationdetail ( vcd_vcid, vcd_detno,
       vcd_ym, vcd_slid, vcd_slcode,
       vcd_slkind, vcd_sldate, vcd_amount,
       vcd_nowbalance, vcd_remark, companyId,
       updaterId, updateTime, vcd_text1,
       vcd_text2, vcd_text3, vcd_text4,
       vcd_text5)
-    values (#{vcd_id,jdbcType=INTEGER}, #{vcd_vcid,jdbcType=INTEGER}, #{vcd_detno,jdbcType=INTEGER},
+    values ( #{vcd_vcid,jdbcType=INTEGER}, #{vcd_detno,jdbcType=INTEGER},
       #{vcd_ym,jdbcType=INTEGER}, #{vcd_slid,jdbcType=INTEGER}, #{vcd_slcode,jdbcType=VARCHAR},
       #{vcd_slkind,jdbcType=VARCHAR}, #{vcd_sldate,jdbcType=TIMESTAMP}, #{vcd_amount,jdbcType=DOUBLE},
       #{vcd_nowbalance,jdbcType=DOUBLE}, #{vcd_remark,jdbcType=VARCHAR}, #{companyId,jdbcType=INTEGER},
@@ -134,9 +135,6 @@
   <insert id="insertSelective" parameterType="com.usoftchina.saas.money.po.Verificationdetail" >
     insert into verificationdetail
     <trim prefix="(" suffix=")" suffixOverrides="," >
-      <if test="vcd_id != null" >
-        vcd_id,
-      </if>
       <if test="vcd_vcid != null" >
         vcd_vcid,
       </if>
@@ -192,10 +190,7 @@
         vcd_text5,
       </if>
     </trim>
-    <trim prefix="values (" suffix=")" suffixOverrides="," >
-      <if test="vcd_id != null" >
-        #{vcd_id,jdbcType=INTEGER},
-      </if>
+    <trim prefix="values (" suffix=")" suffixOverrides="," >-0--0
       <if test="vcd_vcid != null" >
         #{vcd_vcid,jdbcType=INTEGER},
       </if>
@@ -432,15 +427,13 @@
   </update>
   <insert id="batchInsert" parameterType="java.util.List" >
     insert into verificationdetail
-    (
-    vcd_id,vcd_vcid,vcd_detno,vcd_ym,vcd_slid,vcd_slcode,vcd_slkind,vcd_sldate,
+    (vcd_vcid,vcd_detno,vcd_ym,vcd_slid,vcd_slcode,vcd_slkind,vcd_sldate,
     vcd_amount,vcd_nowbalance,vcd_remark,companyId,updaterId,updateTime,vcd_text1,
     vcd_text2,vcd_text3,vcd_text4,vcd_text5
     )
     values
     <foreach collection="list" item="items2" index="index" open="" close="" separator=",">
-      (
-      #{items2.vcd_id,jdbcType=INTEGER},#{items2.vcd_vcid,jdbcType=INTEGER},#{items2.vcd_detno,jdbcType=INTEGER},#{items2.vcd_ym,jdbcType=INTEGER},#{items2.vcd_slid,jdbcType=INTEGER},
+      (#{items2.vcd_vcid,jdbcType=INTEGER},#{items2.vcd_detno,jdbcType=INTEGER},#{items2.vcd_ym,jdbcType=INTEGER},#{items2.vcd_slid,jdbcType=INTEGER},
       #{items2.vcd_slcode,jdbcType=VARCHAR},#{items2.vcd_slkind,jdbcType=VARCHAR},#{items2.vcd_sldate,jdbcType=DATE},#{items2.vcd_amount,jdbcType=DOUBLE},
       #{items2.vcd_nowbalance,jdbcType=DOUBLE},#{items2.vcd_remark,jdbcType=VARCHAR},#{items2.companyId,jdbcType=INTEGER},#{items2.updaterId,jdbcType=INTEGER},#{items2.updateTime,jdbcType=DATE},
       #{items2.vcd_text1,jdbcType=VARCHAR},#{items2.vcd_text2,jdbcType=VARCHAR},#{items2.vcd_text3,jdbcType=VARCHAR},#{items2.vcd_text4,jdbcType=VARCHAR},
@@ -478,8 +471,14 @@
     delete from verificationdetail
     where vcd_id = #{vcd_vcid,jdbcType=INTEGER}
   </delete>
+  <sql id="subledger_Column_List" >
+    sl_yamount,sl_namount
+  </sql>
   <select id="selectByFK" parameterType="long" resultMap="BaseResultMap">
-    select * from verificationdetail
-      where vcd_vcid=#{vc_id} order by vcd_id
-  </select>
+  select
+  <include refid="Base_Column_List" />,
+  <include refid="subledger_Column_List" />
+  from verificationdetail left join subledger on sl_id=vcd_slid and subledger.companyid=verificationdetail.companyId
+  where vcd_vcid=#{vc_id} order by vcd_id
+</select>
 </mapper>

+ 12 - 2
frontend/saas-web/app/view/money/verification/FormPanel.js

@@ -12,7 +12,7 @@ Ext.define('saas.view.money.verification.FormPanel', {
 
     //字段属性
     _title: '核销单',
-    _idField: 'vc_id',
+    _idField: 'id',
     _codeField: 'vc_code',
     _statusField: 'vc_status',
     _statusCodeField: 'vc_statuscode',
@@ -318,6 +318,8 @@ Ext.define('saas.view.money.verification.FormPanel', {
             }, {
                 fieldLabel: '日期',
                 xtype: 'datefield',
+                defaultValue: new Date(),
+                allowBlank : false,
                 name: 'vc_date'
             }],
             details: ['detail1', 'detail2']
@@ -344,6 +346,8 @@ Ext.define('saas.view.money.verification.FormPanel', {
             }, {
                 fieldLabel: '日期',
                 xtype: 'datefield',
+                defaultValue: new Date(),
+                allowBlank : false,
                 name: 'vc_date'
             }],
             details: ['detail1', 'detail2']
@@ -387,6 +391,8 @@ Ext.define('saas.view.money.verification.FormPanel', {
             }, {
                 fieldLabel: '日期',
                 xtype: 'datefield',
+                defaultValue: new Date(),
+                allowBlank : false,
                 name: 'vc_date'
             }],
             details: ['detail1', 'detail2']
@@ -428,6 +434,8 @@ Ext.define('saas.view.money.verification.FormPanel', {
             }, {
                 fieldLabel: '日期',
                 xtype: 'datefield',
+                defaultValue: new Date(),
+                allowBlank : false,
                 name: 'vc_date'
             }],
             details: ['detail1']
@@ -469,6 +477,8 @@ Ext.define('saas.view.money.verification.FormPanel', {
             }, {
                 fieldLabel: '日期',
                 xtype: 'datefield',
+                defaultValue: new Date(),
+                allowBlank : false,
                 name: 'vc_date'
             }],
             details: ['detail1']
@@ -476,7 +486,7 @@ Ext.define('saas.view.money.verification.FormPanel', {
 
         defaultConditions: {
             receipts_offset_receivable: ['ifnull(sl_custid,0)={vc_custid} and ifnull(sl_preamount,0)<>0 and ifnull(sl_namount,0)<>0',
-                'ifnull(sl_custid,0)={vc_custid} and ifnull(sl_preamount,0)=0 and ifnull(sl_namount,0)<>0'],
+                'ifnull(sl_custid,0)={vc_custid} and ifnull(sl_preamount,0)=0 and ifnull(sl_namount,0)<>0 and sl_kind in (\'期初余额\',\'出货单\',\'销售退货单\')'],
             prepaid_offset_payable: ['ifnull(sl_vendid,0)={vc_vendid} and ifnull(sl_preamount,0)<>0 and ifnull(sl_namount,0)<>0',
                 'ifnull(sl_vendid,0)={vc_vendid} and ifnull(sl_preamount,0)=0 and ifnull(sl_namount,0)<>0'],
             receivable_offset_payable: ['ifnull(sl_custid,0)={vc_custid} and ifnull(sl_preamount,0)=0 and ifnull(sl_namount,0)<>0',

+ 25 - 1
frontend/saas-web/app/view/money/verification/FormPanelController.js

@@ -127,6 +127,9 @@ Ext.define('saas.view.money.verification.FormPanelController', {
                         },{
                             from: 'sl_yamount',
                             to: 'sl_yamount'
+                        },{
+                            from: 'sl_namount',
+                            to: 'sl_namount'
                         },{
                             from:'sl_date',
                             to:'vd_sldate'
@@ -175,7 +178,7 @@ Ext.define('saas.view.money.verification.FormPanelController', {
                         },{
                             from: 'sl_yamount',
                             to: 'sl_yamount'
-                        },,{
+                        },{
                             from: 'sl_namount',
                             to: 'sl_namount'
                         },{
@@ -286,4 +289,25 @@ Ext.define('saas.view.money.verification.FormPanelController', {
         store.removeAll();
         store.add(datas);
     },
+    onSave: function() {
+        var me = this,
+            form = me.getView(),
+            viewModel = me.getViewModel(),
+            store1 = viewModel.get('detail0').detailStore,
+            store2 = viewModel.get('detail1').detailStore;
+
+        var valid = form.isValid();
+        if(!valid) {
+            saas.util.BaseUtil.showErrorToast(form.invalidText);
+            return false;
+        }
+
+        var sum_detail1 = store1.sum('vd_nowbalance'); // 从表1核销合计
+        var sum_detail2 = store2.sum('vcd_nowbalance'); // 从表2核销合计
+
+        viewModel.set("vc_amount1",sum_detail1);
+        viewModel.set("vc_amount2",sum_detail2);
+
+        me.save();
+    },
 });

+ 9 - 4
frontend/saas-web/app/view/money/verification/QueryPanel.js

@@ -10,7 +10,7 @@ Ext.define('saas.view.money.verification.QueryPanel', {
     queryFormItems: [{
         xtype: 'textfield',
         name: 'vc_code',
-        fieldLabel: '单号/供应商名/客户名',
+        fieldLabel: '',
         emptyText :'请输入单号或者供应商名或者客户名',
         getCondition: function(value) {
             if(value == 'ALL') {
@@ -81,7 +81,7 @@ Ext.define('saas.view.money.verification.QueryPanel', {
     }],
     moreQueryFormItems: [],
     queryGridConfig: {
-        idField: 'id',
+        idField: 'vc_id',
         codeField: 'vc_code',
         addTitle: '核销单',
         addXtype: 'money-verification-formpanel',
@@ -97,11 +97,16 @@ Ext.define('saas.view.money.verification.QueryPanel', {
             text: '单据编号',
             dataIndex: 'vc_code',
             width: 200
-        }, {
+        },  {
+            text: '单据日期',
+            dataIndex: 'vc_date',
+            xtype: 'datecolumn',
+            width: 120
+        },{
             text: '审核状态',
             dataIndex: 'vc_status',
             width: 120
-        }, {
+        },{
             text: '业务类型',
             dataIndex: 'vc_kind',
             width: 200