|
@@ -11,22 +11,29 @@ import com.dk.common.response.ResponseResultVO;
|
|
|
import com.dk.common.service.BaseService;
|
|
import com.dk.common.service.BaseService;
|
|
|
import com.dk.mdm.infrastructure.convert.ivt.InboundConvert;
|
|
import com.dk.mdm.infrastructure.convert.ivt.InboundConvert;
|
|
|
import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
|
|
import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
|
|
|
|
|
+import com.dk.mdm.mapper.common.CommonMapper;
|
|
|
import com.dk.mdm.mapper.ivt.InboundItemMapper;
|
|
import com.dk.mdm.mapper.ivt.InboundItemMapper;
|
|
|
import com.dk.mdm.mapper.ivt.InboundMapper;
|
|
import com.dk.mdm.mapper.ivt.InboundMapper;
|
|
|
import com.dk.mdm.mapper.pur.PurchaseItemMapper;
|
|
import com.dk.mdm.mapper.pur.PurchaseItemMapper;
|
|
|
import com.dk.mdm.mapper.pur.PurchaseMapper;
|
|
import com.dk.mdm.mapper.pur.PurchaseMapper;
|
|
|
import com.dk.mdm.model.pojo.ivt.Inbound;
|
|
import com.dk.mdm.model.pojo.ivt.Inbound;
|
|
|
import com.dk.mdm.model.pojo.ivt.InboundItem;
|
|
import com.dk.mdm.model.pojo.ivt.InboundItem;
|
|
|
|
|
+import com.dk.mdm.model.pojo.ivt.IntoReturn;
|
|
|
import com.dk.mdm.model.pojo.pur.Purchase;
|
|
import com.dk.mdm.model.pojo.pur.Purchase;
|
|
|
import com.dk.mdm.model.pojo.pur.PurchaseItem;
|
|
import com.dk.mdm.model.pojo.pur.PurchaseItem;
|
|
|
import com.dk.mdm.model.query.ivt.InboundItemQuery;
|
|
import com.dk.mdm.model.query.ivt.InboundItemQuery;
|
|
|
import com.dk.mdm.model.query.ivt.InboundQuery;
|
|
import com.dk.mdm.model.query.ivt.InboundQuery;
|
|
|
|
|
+import com.dk.mdm.model.query.ivt.IntoReturnItemQuery;
|
|
|
|
|
+import com.dk.mdm.model.query.ivt.IntoReturnQuery;
|
|
|
import com.dk.mdm.model.response.ivt.InboundItemResponse;
|
|
import com.dk.mdm.model.response.ivt.InboundItemResponse;
|
|
|
import com.dk.mdm.model.response.ivt.InboundResponse;
|
|
import com.dk.mdm.model.response.ivt.InboundResponse;
|
|
|
|
|
+import com.dk.mdm.model.response.ivt.IntoReturnItemResponse;
|
|
|
|
|
+import com.dk.mdm.model.response.ivt.IntoReturnResponse;
|
|
|
import com.dk.mdm.model.response.pur.PurchaseItemResponse;
|
|
import com.dk.mdm.model.response.pur.PurchaseItemResponse;
|
|
|
import com.dk.mdm.model.response.pur.PurchaseResponse;
|
|
import com.dk.mdm.model.response.pur.PurchaseResponse;
|
|
|
import com.dk.mdm.model.vo.ivt.InboundItemVO;
|
|
import com.dk.mdm.model.vo.ivt.InboundItemVO;
|
|
|
import com.dk.mdm.model.vo.ivt.InboundVO;
|
|
import com.dk.mdm.model.vo.ivt.InboundVO;
|
|
|
|
|
+import com.dk.mdm.model.vo.ivt.IntoReturnVO;
|
|
|
import com.dk.mdm.service.common.CommonService;
|
|
import com.dk.mdm.service.common.CommonService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -35,6 +42,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
@@ -68,7 +76,8 @@ public class InboundReturnService extends BaseService<Inbound> {
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private InboundItemConvert inboundItemConvert;
|
|
private InboundItemConvert inboundItemConvert;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CommonMapper commonMapper;
|
|
|
@Pagination
|
|
@Pagination
|
|
|
public ResponseResultVO<PageList<InboundResponse>> selectByCond(InboundQuery inboundQuery) {
|
|
public ResponseResultVO<PageList<InboundResponse>> selectByCond(InboundQuery inboundQuery) {
|
|
|
return super.mergeListWithCount(inboundQuery, inboundMapper.selectByInboundReturnCond(inboundQuery), inboundMapper.countByInboundReturnCond(inboundQuery));
|
|
return super.mergeListWithCount(inboundQuery, inboundMapper.selectByInboundReturnCond(inboundQuery), inboundMapper.countByInboundReturnCond(inboundQuery));
|
|
@@ -119,21 +128,19 @@ public class InboundReturnService extends BaseService<Inbound> {
|
|
|
.setReturnQty(purchaseResponse.getReturnQty().add(inboundVO.getReturnQty()))
|
|
.setReturnQty(purchaseResponse.getReturnQty().add(inboundVO.getReturnQty()))
|
|
|
.setReturnAmt(purchaseResponse.getReturnAmt().add(inboundVO.getReturnAmt()))
|
|
.setReturnAmt(purchaseResponse.getReturnAmt().add(inboundVO.getReturnAmt()))
|
|
|
);
|
|
);
|
|
|
- BigDecimal sumReturnQty = BigDecimal.ZERO;
|
|
|
|
|
- BigDecimal sumReturnAmt = BigDecimal.ZERO;
|
|
|
|
|
|
|
+
|
|
|
//反写入库订单明细、反写订单明细
|
|
//反写入库订单明细、反写订单明细
|
|
|
for (InboundItemVO inboundItemVO : itemList) {
|
|
for (InboundItemVO inboundItemVO : itemList) {
|
|
|
//根据退货明细中入库明细id查询入库明细数据
|
|
//根据退货明细中入库明细id查询入库明细数据
|
|
|
InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId()); //原入库单明细id
|
|
InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemVO.getItemId()); //原入库单明细id
|
|
|
BigDecimal returnQty = inboundItemResponse.getReturnQty().add(inboundItemVO.getReturnQty().setScale(6, BigDecimal.ROUND_HALF_UP));
|
|
BigDecimal returnQty = inboundItemResponse.getReturnQty().add(inboundItemVO.getReturnQty().setScale(6, BigDecimal.ROUND_HALF_UP));
|
|
|
BigDecimal returnAmt = inboundItemResponse.getReturnAmt().add(inboundItemVO.getReturnAmt().setScale(6, BigDecimal.ROUND_HALF_UP));
|
|
BigDecimal returnAmt = inboundItemResponse.getReturnAmt().add(inboundItemVO.getReturnAmt().setScale(6, BigDecimal.ROUND_HALF_UP));
|
|
|
- sumReturnQty = sumReturnQty.add(returnQty);
|
|
|
|
|
- sumReturnAmt = sumReturnAmt.add(returnAmt);
|
|
|
|
|
- //反写入库单退货数量金额 todo
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //反写入库单退货数量金额
|
|
|
InboundResponse inboundResponse = inboundMapper.selectById(inboundItemVO.getIntoId()); //原入库单id
|
|
InboundResponse inboundResponse = inboundMapper.selectById(inboundItemVO.getIntoId()); //原入库单id
|
|
|
inboundMapper.updateAmount(new Inbound().setIntoId(inboundItemVO.getIntoId())
|
|
inboundMapper.updateAmount(new Inbound().setIntoId(inboundItemVO.getIntoId())
|
|
|
- .setReturnQty(inboundResponse.getReturnQty().add(sumReturnQty))
|
|
|
|
|
- .setReturnAmt(inboundResponse.getReturnAmt().add(sumReturnAmt)));
|
|
|
|
|
|
|
+ .setReturnQty(inboundResponse.getReturnQty().add(returnQty))
|
|
|
|
|
+ .setReturnAmt(inboundResponse.getReturnAmt().add(returnAmt)));
|
|
|
inboundItemMapper.updateAmount(
|
|
inboundItemMapper.updateAmount(
|
|
|
new InboundItem()
|
|
new InboundItem()
|
|
|
.setItemId(inboundItemResponse.getItemId())
|
|
.setItemId(inboundItemResponse.getItemId())
|
|
@@ -152,8 +159,6 @@ public class InboundReturnService extends BaseService<Inbound> {
|
|
|
|
|
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
- inboundVO.setFromId(inboundVO.getIntoId());
|
|
|
|
|
- inboundVO.setFromNo(inboundVO.getIntoNo());
|
|
|
|
|
inboundVO.setIntoingQty(inboundVO.getReturnQty().multiply(new BigDecimal(-1)));
|
|
inboundVO.setIntoingQty(inboundVO.getReturnQty().multiply(new BigDecimal(-1)));
|
|
|
inboundVO.setIntoingAmt(inboundVO.getReturnAmt().multiply(new BigDecimal(-1)));
|
|
inboundVO.setIntoingAmt(inboundVO.getReturnAmt().multiply(new BigDecimal(-1)));
|
|
|
List<InboundItemVO> list = new ArrayList<>();
|
|
List<InboundItemVO> list = new ArrayList<>();
|
|
@@ -182,6 +187,16 @@ public class InboundReturnService extends BaseService<Inbound> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
inboundVO.setItemList(list);
|
|
inboundVO.setItemList(list);
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("cpId", inboundVO.getCpId());
|
|
|
|
|
+ map.put("code", "IVT_001");
|
|
|
|
|
+ //自动办理标识
|
|
|
|
|
+ String flgHandleSetting = commonMapper.getSettingValue(map);
|
|
|
|
|
+ //自动办理标识为1 自动办理入库
|
|
|
|
|
+ if(Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)){
|
|
|
|
|
+ inboundVO.setFlgHandleSetting(Constant.FlgHandleSetting.TRUE.getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ //region 总单
|
|
|
//获取 id/单号
|
|
//获取 id/单号
|
|
|
Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SALERETURN.getName(), false);
|
|
Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.SALERETURN.getName(), false);
|
|
|
inboundVO.setIntoId(codeMap.get("outId").toString()).
|
|
inboundVO.setIntoId(codeMap.get("outId").toString()).
|
|
@@ -189,7 +204,7 @@ public class InboundReturnService extends BaseService<Inbound> {
|
|
|
//入库类型
|
|
//入库类型
|
|
|
inboundVO.setIntoType(Constant.IntoType.PURRETURN_RETURN.getName());
|
|
inboundVO.setIntoType(Constant.IntoType.PURRETURN_RETURN.getName());
|
|
|
//自动入库标识
|
|
//自动入库标识
|
|
|
- if (inboundVO.getAutomaticFlg()) {
|
|
|
|
|
|
|
+ if (inboundVO.getFlgAutoHandle()) {
|
|
|
//已入库
|
|
//已入库
|
|
|
inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
|
|
inboundVO.setIntoStatus(Constant.IntoStatus.YIRUKU.getName());
|
|
|
} else {
|
|
} else {
|
|
@@ -251,7 +266,116 @@ public class InboundReturnService extends BaseService<Inbound> {
|
|
|
//实体转换
|
|
//实体转换
|
|
|
InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
|
|
|
inboundItemMapper.insert(inboundItem);
|
|
inboundItemMapper.insert(inboundItem);
|
|
|
|
|
+ //endregion
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResponseResultUtil.success();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @desc : 作废
|
|
|
|
|
+ * @date : 2022/6/28 16:58
|
|
|
|
|
+ * @author : 于继渤
|
|
|
|
|
+ */
|
|
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
|
|
+ public ResponseResultVO<String> cancel(InboundVO inboundVO) {
|
|
|
|
|
+ //查询当前 采退入库单 负
|
|
|
|
|
+ InboundResponse inboundResponse = inboundMapper.selectInboundReturnById(inboundVO.getIntoId());
|
|
|
|
|
+ if (inboundResponse.getIntoStatus().equals(Constant.IntoStatus.ZUOFEI.getName())) {
|
|
|
|
|
+ //当前单据已经作废,不能重复操
|
|
|
|
|
+ return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ISFLGVALID_FALSE.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ //校验单据是否可以作废
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //region 查询当前公司的系统参数 自动办理信息 并赋值
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
|
|
+ map.put("cpId", inboundResponse.getCpId());
|
|
|
|
|
+ map.put("code", "IVT_001");
|
|
|
|
|
+ //自动办理标识
|
|
|
|
|
+ String flgHandleSetting = commonMapper.getSettingValue(map);
|
|
|
|
|
+ //自动办理标识为1 自动办理入库
|
|
|
|
|
+ if(Constant.FlgAutoHandleStringType.ONE.getValue().equals(flgHandleSetting)){
|
|
|
|
|
+ inboundResponse.setFlgHandleSetting(Constant.FlgHandleSetting.TRUE.getValue());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ //TODO //系统参数自动出入库办理 已出库(未退款)可以作废,已出库(已退款)不可以作废
|
|
|
|
|
+ if(inboundResponse.getFlgHandleSetting() && inboundResponse.getIntoStatus().equals(Constant.IntoStatus.YIRUKU.getName())){
|
|
|
|
|
+ return ResponseResultUtil.error(ErrorCodeEnum.NO_WAIT_INTO_RETURN_CANCEL.getCode(),
|
|
|
|
|
+ ErrorCodeEnum.NO_WAIT_INTO_RETURN_CANCEL.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ //系统参数手动出入库办理 出库中,可以作废,已出库(未收款、已收款),不可以作废
|
|
|
|
|
+ if (!inboundResponse.getFlgHandleSetting() && inboundResponse.getIntoStatus().equals(Constant.IntoStatus.YIRUKU.getName())) {
|
|
|
|
|
+ return ResponseResultUtil.error(ErrorCodeEnum.NO_WAIT_INTO_RETURN_CANCEL.getCode(),
|
|
|
|
|
+ ErrorCodeEnum.NO_WAIT_INTO_RETURN_CANCEL.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ //查询采购单
|
|
|
|
|
+ PurchaseResponse purchaseResponse = purchaseMapper.selectById(inboundResponse.getFromId());
|
|
|
|
|
+ if (purchaseResponse == null) {
|
|
|
|
|
+ //返回 单据所对应的原始单据不存在,请重新操作
|
|
|
|
|
+ return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ORIGINAL_DOCUMENT_ABSENT.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ //修改采购单 已入库数量/金额
|
|
|
|
|
+ purchaseMapper.updateAmount(
|
|
|
|
|
+ new Purchase().setReturnQty(purchaseResponse.getReturnQty().subtract(inboundResponse.getReturnQty()))
|
|
|
|
|
+ .setReturnAmt(purchaseResponse.getReturnAmt().subtract(inboundResponse.getReturnAmt())).setPurId(purchaseResponse.getPurId())
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectByCond(new InboundItemQuery().setIntoId(inboundResponse.getIntoId()));
|
|
|
|
|
+ for (InboundItemResponse inboundItemRespons : inboundItemResponses) {
|
|
|
|
|
+
|
|
|
|
|
+ //查询源入库单明细
|
|
|
|
|
+ InboundItemResponse inboundItemResponse = inboundItemMapper.selectById(inboundItemRespons.getSIntoItemId());
|
|
|
|
|
+ if (inboundItemResponse == null) {
|
|
|
|
|
+ //返回 单据所对应的原始单据不存在,请重新操作
|
|
|
|
|
+ return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ORIGINAL_DOCUMENT_ABSENT.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ //修改入库单明细 已入库退货数量/金额
|
|
|
|
|
+ inboundItemMapper.updateAmount(new InboundItem()
|
|
|
|
|
+ .setItemId(inboundItemResponse.getSIntoItemId())
|
|
|
|
|
+ .setReturnQty(inboundItemResponse.getReturnQty().subtract(inboundItemResponse.getReturnQty()))
|
|
|
|
|
+ .setReturnAmt(inboundItemResponse.getReturnAmt().subtract(inboundItemResponse.getReturnAmt()))
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //查询源入库单 修改 已入库退货数量/金额
|
|
|
|
|
+ InboundResponse inboundRes = inboundMapper.selectById(inboundItemRespons.getSIntoId());
|
|
|
|
|
+ if (inboundRes == null) {
|
|
|
|
|
+ //返回 单据所对应的原始单据不存在,请重新操作
|
|
|
|
|
+ return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ORIGINAL_DOCUMENT_ABSENT.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ inboundMapper.updateAmount(new Inbound().setIntoId(inboundRes.getIntoId())
|
|
|
|
|
+ .setReturnQty(inboundResponse.getReturnQty().subtract(inboundItemRespons.getReturnQty()))
|
|
|
|
|
+ .setReturnAmt(inboundResponse.getReturnAmt().subtract(inboundItemRespons.getReturnAmt())));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //查询采购单明细
|
|
|
|
|
+ PurchaseItemResponse purchaseItemResponse = purchaseItemMapper.selectById(inboundItemRespons.getSPurItemId());
|
|
|
|
|
+ if (purchaseItemResponse == null) {
|
|
|
|
|
+ //返回 单据所对应的原始单据不存在,请重新操作
|
|
|
|
|
+ return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.ORIGINAL_DOCUMENT_ABSENT.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ //修改采购单明细 已入库退货数量/金额
|
|
|
|
|
+ purchaseItemMapper.updateAmount(
|
|
|
|
|
+ new PurchaseItem()
|
|
|
|
|
+ .setItemId(purchaseItemResponse.getItemId())
|
|
|
|
|
+ .setReturnQty(purchaseItemResponse.getReturnQty().subtract(inboundItemRespons.getReturnQty()))
|
|
|
|
|
+ .setReturnAmt(purchaseItemResponse.getReturnAmt().subtract(inboundItemRespons.getReturnAmt()))
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ //修改 负向入库单 状态为作废
|
|
|
|
|
+ inboundMapper.updateIntoStatus(new Inbound()
|
|
|
|
|
+ .setIntoId(inboundVO.getIntoId())
|
|
|
|
|
+ .setIntoStatus(Constant.IntoStatus.ZUOFEI.getName()));
|
|
|
|
|
+ //修改 负向入库单明细 状态为作废
|
|
|
|
|
+ if (inboundItemResponses != null && inboundItemResponses.size() > 0) {
|
|
|
|
|
+ for (InboundItemResponse inboundItemRespons : inboundItemResponses) {
|
|
|
|
|
+ inboundItemMapper.updateIntoStatus(new InboundItem().setItemId(inboundItemRespons.getItemId()).setIntoStatus(Constant.IntoStatus.ZUOFEI.getName()));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
return ResponseResultUtil.success();
|
|
return ResponseResultUtil.success();
|
|
|
}
|
|
}
|