diff --git a/jshERP-boot/src/main/java/com/jsh/erp/controller/SupplierController.java b/jshERP-boot/src/main/java/com/jsh/erp/controller/SupplierController.java index 2cb0c3a9..bde37933 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/controller/SupplierController.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/controller/SupplierController.java @@ -391,4 +391,25 @@ public class SupplierController { } } + /** + * 批量设置会员当前的预付款 + * @param jsonObject + * @param request + * @return + * @throws Exception + */ + @PostMapping(value = "/batchSetAdvanceIn") + @ApiOperation(value = "批量设置会员当前的预付款") + public String batchSetAdvanceIn(@RequestBody JSONObject jsonObject, + HttpServletRequest request)throws Exception { + String ids = jsonObject.getString("ids"); + Map objectMap = new HashMap<>(); + int res = supplierService.batchSetAdvanceIn(ids); + if(res > 0) { + return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code); + } else { + return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code); + } + } + } diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/AccountHeadMapperEx.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/AccountHeadMapperEx.java index 93294a00..de5106ec 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/AccountHeadMapperEx.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/AccountHeadMapperEx.java @@ -58,4 +58,7 @@ public interface AccountHeadMapperEx { List getFinancialBillNoByBillId( @Param("billId") Long billId); + + BigDecimal getFinancialAllPriceByOrganId( + @Param("organId") Long organId); } \ No newline at end of file diff --git a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapperEx.java b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapperEx.java index 93dcc1d9..2f49229e 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapperEx.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/datasource/mappers/DepotHeadMapperEx.java @@ -271,4 +271,7 @@ public interface DepotHeadMapperEx { @Param("endTime") String endTime, @Param("materialParam") String materialParam, @Param("depotArray") String[] depotArray); + + BigDecimal getBillAllPriceByOrganId( + @Param("organId") Long organId); } diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java index debab033..27012fd7 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java @@ -212,6 +212,12 @@ public class AccountHeadService { public int batchDeleteAccountHeadByIds(String ids)throws Exception { StringBuffer sb = new StringBuffer(); sb.append(BusinessConstants.LOG_OPERATION_TYPE_DELETE); + User userInfo=userService.getCurrentUser(); + String [] idArray=ids.split(","); + //删除主表 + accountItemMapperEx.batchDeleteAccountItemByHeadIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); + //删除子表 + accountHeadMapperEx.batchDeleteAccountHeadByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); List list = getAccountHeadListByIds(ids); for(AccountHead accountHead: list){ sb.append("[").append(accountHead.getBillNo()).append("]"); @@ -221,17 +227,11 @@ public class AccountHeadService { } if("收预付款".equals(accountHead.getType())){ if (accountHead.getOrganId() != null) { - //删除时需要从会员扣除预付款 - supplierService.updateAdvanceIn(accountHead.getOrganId(), BigDecimal.ZERO.subtract(accountHead.getTotalPrice())); + //更新会员预付款 + supplierService.updateAdvanceIn(accountHead.getOrganId()); } } } - User userInfo=userService.getCurrentUser(); - String [] idArray=ids.split(","); - //删除主表 - accountItemMapperEx.batchDeleteAccountItemByHeadIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); - //删除子表 - accountHeadMapperEx.batchDeleteAccountHeadByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); logService.insertLog("财务", sb.toString(), ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); return 1; @@ -314,7 +314,8 @@ public class AccountHeadService { accountItemService.saveDetials(rows, headId, type, request); } if("收预付款".equals(accountHead.getType())){ - supplierService.updateAdvanceIn(accountHead.getOrganId(), accountHead.getTotalPrice()); + //更新会员预付款 + supplierService.updateAdvanceIn(accountHead.getOrganId()); } logService.insertLog("财务单据", new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(accountHead.getBillNo()).toString(), request); @@ -328,8 +329,6 @@ public class AccountHeadService { throw new BusinessRunTimeException(ExceptionConstants.ACCOUNT_HEAD_BILL_NO_EXIST_CODE, String.format(ExceptionConstants.ACCOUNT_HEAD_BILL_NO_EXIST_MSG)); } - //获取之前的金额数据 - BigDecimal preTotalPrice = getAccountHead(accountHead.getId()).getTotalPrice().abs(); accountHeadMapper.updateByPrimaryKeySelective(accountHead); //根据单据编号查询单据id AccountHeadExample dhExample = new AccountHeadExample(); @@ -342,7 +341,8 @@ public class AccountHeadService { accountItemService.saveDetials(rows, headId, type, request); } if("收预付款".equals(accountHead.getType())){ - supplierService.updateAdvanceIn(accountHead.getOrganId(), accountHead.getTotalPrice().subtract(preTotalPrice)); + //更新会员预付款 + supplierService.updateAdvanceIn(accountHead.getOrganId()); } logService.insertLog("财务单据", new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(accountHead.getBillNo()).toString(), request); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java index ae1466a9..4e40aee5 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java @@ -459,15 +459,6 @@ public class DepotHeadService { } } } - //对于零售出库单据,更新会员的预收款信息 - if (BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType()) - && BusinessConstants.SUB_TYPE_RETAIL.equals(depotHead.getSubType())){ - if(BusinessConstants.PAY_TYPE_PREPAID.equals(depotHead.getPayType())) { - if (depotHead.getOrganId() != null) { - supplierService.updateAdvanceIn(depotHead.getOrganId(), depotHead.getTotalPrice().abs()); - } - } - } List list = depotItemService.getListByHeaderId(depotHead.getId()); //删除单据子表数据 depotItemMapperEx.batchDeleteDepotItemByDepotHeadIds(new Long[]{depotHead.getId()}); @@ -515,6 +506,16 @@ public class DepotHeadService { depotHeadMapper.updateByExampleSelective(dh, example); } } + //对于零售出库单据,更新会员的预收款信息 + if (BusinessConstants.DEPOTHEAD_TYPE_OUT.equals(depotHead.getType()) + && BusinessConstants.SUB_TYPE_RETAIL.equals(depotHead.getSubType())){ + if(BusinessConstants.PAY_TYPE_PREPAID.equals(depotHead.getPayType())) { + if (depotHead.getOrganId() != null) { + //更新会员预付款 + supplierService.updateAdvanceIn(depotHead.getOrganId()); + } + } + } //更新当前库存 for (DepotItem depotItem : list) { depotItemService.updateCurrentStock(depotItem); @@ -981,7 +982,8 @@ public class DepotHeadService { if(depotHead.getOrganId()!=null) { BigDecimal currentAdvanceIn = supplierService.getSupplier(depotHead.getOrganId()).getAdvanceIn(); if(currentAdvanceIn.compareTo(depotHead.getTotalPrice())>=0) { - supplierService.updateAdvanceIn(depotHead.getOrganId(), BigDecimal.ZERO.subtract(depotHead.getTotalPrice())); + //更新会员的预付款 + supplierService.updateAdvanceIn(depotHead.getOrganId()); } else { throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_MEMBER_PAY_LACK_CODE, String.format(ExceptionConstants.DEPOT_HEAD_MEMBER_PAY_LACK_MSG)); @@ -1023,8 +1025,8 @@ public class DepotHeadService { throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_CANNOT_EDIT_CODE, String.format(ExceptionConstants.DEPOT_HEAD_BILL_CANNOT_EDIT_MSG)); } - //获取之前的金额数据 - BigDecimal preTotalPrice = getDepotHead(depotHead.getId()).getTotalPrice().abs(); + //获取之前的会员id + Long preOrganId = getDepotHead(depotHead.getId()).getOrganId(); String subType = depotHead.getSubType(); //结算账户校验 if("采购".equals(subType) || "采购退货".equals(subType) || "销售".equals(subType) || "销售退货".equals(subType)) { @@ -1082,7 +1084,12 @@ public class DepotHeadService { if(depotHead.getOrganId()!=null){ BigDecimal currentAdvanceIn = supplierService.getSupplier(depotHead.getOrganId()).getAdvanceIn(); if(currentAdvanceIn.compareTo(depotHead.getTotalPrice())>=0) { - supplierService.updateAdvanceIn(depotHead.getOrganId(), BigDecimal.ZERO.subtract(depotHead.getTotalPrice().subtract(preTotalPrice))); + //更新会员的预付款 + supplierService.updateAdvanceIn(depotHead.getOrganId()); + if(null != preOrganId && !preOrganId.equals(depotHead.getOrganId())) { + //更新之前会员的预付款 + supplierService.updateAdvanceIn(preOrganId); + } } else { throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_MEMBER_PAY_LACK_CODE, String.format(ExceptionConstants.DEPOT_HEAD_MEMBER_PAY_LACK_MSG)); diff --git a/jshERP-boot/src/main/java/com/jsh/erp/service/supplier/SupplierService.java b/jshERP-boot/src/main/java/com/jsh/erp/service/supplier/SupplierService.java index f200ca72..4a314636 100644 --- a/jshERP-boot/src/main/java/com/jsh/erp/service/supplier/SupplierService.java +++ b/jshERP-boot/src/main/java/com/jsh/erp/service/supplier/SupplierService.java @@ -287,24 +287,24 @@ public class SupplierService { return list==null?0:list.size(); } + /** + * 更新会员的预付款 + * @param supplierId + */ @Transactional(value = "transactionManager", rollbackFor = Exception.class) - public int updateAdvanceIn(Long supplierId, BigDecimal advanceIn)throws Exception{ - Supplier supplier=null; + public void updateAdvanceIn(Long supplierId) { try{ - supplier = supplierMapper.selectByPrimaryKey(supplierId); - }catch(Exception e){ - JshException.readFail(logger, e); - } - int result=0; - try{ - if(supplier!=null){ - supplier.setAdvanceIn(supplier.getAdvanceIn().add(advanceIn)); //增加预收款的金额,可能增加的是负值 - result=supplierMapper.updateByPrimaryKeySelective(supplier); - } - }catch(Exception e){ + //查询会员在收预付款单据的总金额 + BigDecimal financialAllPrice = accountHeadMapperEx.getFinancialAllPriceByOrganId(supplierId); + //查询会员在零售出库单据的总金额 + BigDecimal billAllPrice = depotHeadMapperEx.getBillAllPriceByOrganId(supplierId); + Supplier supplier = new Supplier(); + supplier.setId(supplierId); + supplier.setAdvanceIn(financialAllPrice.subtract(billAllPrice)); + supplierMapper.updateByPrimaryKeySelective(supplier); + } catch (Exception e){ JshException.writeFail(logger, e); } - return result; } public List findBySelectCus()throws Exception { @@ -668,4 +668,15 @@ public class SupplierService { } } } + + @Transactional(value = "transactionManager", rollbackFor = Exception.class) + public int batchSetAdvanceIn(String ids) throws Exception { + int res = 0; + List idList = StringUtil.strToLongList(ids); + for(Long sId: idList) { + updateAdvanceIn(sId); + res = 1; + } + return res; + } } diff --git a/jshERP-boot/src/main/resources/mapper_xml/AccountHeadMapperEx.xml b/jshERP-boot/src/main/resources/mapper_xml/AccountHeadMapperEx.xml index 95df5b36..52b3378d 100644 --- a/jshERP-boot/src/main/resources/mapper_xml/AccountHeadMapperEx.xml +++ b/jshERP-boot/src/main/resources/mapper_xml/AccountHeadMapperEx.xml @@ -211,4 +211,11 @@ where ai.bill_id=#{billId} and ifnull(ah.delete_flag,'0') !='1' + + \ No newline at end of file diff --git a/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml b/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml index 50b68a2c..c89e6bf1 100644 --- a/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml +++ b/jshERP-boot/src/main/resources/mapper_xml/DepotHeadMapperEx.xml @@ -1235,4 +1235,13 @@ and ifnull(dh.delete_Flag,'0') !='1') tb + + \ No newline at end of file