增加批量设置会员当前的预付款接口,完善单据中收预付款的更新逻辑
This commit is contained in:
parent
1daf602ecc
commit
0e87202d7c
@ -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<String, Object> 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -58,4 +58,7 @@ public interface AccountHeadMapperEx {
|
||||
|
||||
List<AccountHead> getFinancialBillNoByBillId(
|
||||
@Param("billId") Long billId);
|
||||
|
||||
BigDecimal getFinancialAllPriceByOrganId(
|
||||
@Param("organId") Long organId);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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<AccountHead> 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);
|
||||
|
||||
@ -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<DepotItem> 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));
|
||||
|
||||
@ -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<Supplier> 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<Long> idList = StringUtil.strToLongList(ids);
|
||||
for(Long sId: idList) {
|
||||
updateAdvanceIn(sId);
|
||||
res = 1;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,4 +211,11 @@
|
||||
where ai.bill_id=#{billId}
|
||||
and ifnull(ah.delete_flag,'0') !='1'
|
||||
</select>
|
||||
|
||||
<select id="getFinancialAllPriceByOrganId" resultType="java.math.BigDecimal">
|
||||
select ifnull(sum(ah.total_price),0) allPrice from jsh_account_head ah
|
||||
where ah.organ_id=#{organId}
|
||||
and ah.type = '收预付款'
|
||||
and ifnull(ah.delete_flag,'0') !='1'
|
||||
</select>
|
||||
</mapper>
|
||||
@ -1235,4 +1235,13 @@
|
||||
</if>
|
||||
and ifnull(dh.delete_Flag,'0') !='1') tb
|
||||
</select>
|
||||
|
||||
<select id="getBillAllPriceByOrganId" resultType="java.math.BigDecimal">
|
||||
select ifnull(sum(dh.total_price),0) allPrice from jsh_depot_head dh
|
||||
where dh.organ_id=#{organId}
|
||||
and dh.type = '出库'
|
||||
and dh.sub_type = '零售'
|
||||
and dh.pay_type = '预付款'
|
||||
and ifnull(dh.delete_flag,'0') !='1'
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue
Block a user