商贸型企业 Java 收货 + 入库 + 生成付款单
package cn.hybn.erp.modular.system.service.impl; import cn.hybn.erp.core.common.page.LayuiPageFactory;
import cn.hybn.erp.core.common.page.LayuiPageInfo;
import cn.hybn.erp.modular.system.base.BaseStatus;
import cn.hybn.erp.modular.system.base.Order;
import cn.hybn.erp.modular.system.base.Status;
import cn.hybn.erp.modular.system.entity.*;
import cn.hybn.erp.modular.system.mapper.GrnOrderMapper;
import cn.hybn.erp.modular.system.model.params.GrnOrderParam;
import cn.hybn.erp.modular.system.model.params.PurchaseOrderParam;
import cn.hybn.erp.modular.system.model.result.GrnOrderResult;
import cn.hybn.erp.modular.system.service.*;
import cn.hybn.erp.modular.system.utility.Katrina_CJ_Utils;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.xml.internal.bind.v2.TODO;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import java.io.Serializable;
import java.math.BigDecimal;
import java.util.*; /**
* <p>
* 服务实现类
* </p>
*
* @author Katrina_CJ
* @since 2019-03-16
*/
@Service
public class GrnOrderServiceImpl extends ServiceImpl<GrnOrderMapper, GrnOrder> implements GrnOrderService { @Autowired
private PurchaseDetailService purchaseDetailService; @Autowired
private GrnOrderDetailService grnOrderDetailService; @Autowired
private InventoryService inventoryService; @Autowired
private InventoryTransactionService inventoryTransactionService; @Autowired
private PurchaseOrderService purchaseOrderService; @Autowired
private PaymentOrderService paymentOrderService; @Override
public void add(GrnOrderParam param) {
GrnOrder entity = getEntity(param);
this.save(entity);
} @Override
public void delete(GrnOrderParam param) {
this.removeById(getKey(param));
} @Override
public void update(GrnOrderParam param) {
GrnOrder oldEntity = getOldEntity(param);
GrnOrder newEntity = getEntity(param);
ToolUtil.copyProperties(newEntity, oldEntity);
this.updateById(newEntity);
} @Override
public GrnOrderResult findBySpec(GrnOrderParam param) {
return null;
} @Override
public List<GrnOrderResult> findListBySpec(GrnOrderParam param) {
return null;
} @Override
public LayuiPageInfo findPageBySpec(GrnOrderParam param) {
Page pageContext = getPageContext();
QueryWrapper<GrnOrder> objectQueryWrapper = new QueryWrapper<>();
IPage page = this.page(pageContext, objectQueryWrapper);
return LayuiPageFactory.createPageInfo(page);
} @Override
@Transactional(rollbackFor = {Exception.class})
public void createGrnOrder(PurchaseOrderParam param) {
GrnOrder grnOrder = new GrnOrder();
grnOrder.setGrnOrderStatus(Status.CREATE.getStatus());
grnOrder.setOrderId(param.getPoId());
grnOrder.setGrnOrderCreateTime(new Date());
QueryWrapper<GrnOrder> wrapper = new QueryWrapper<>();
wrapper.orderByDesc("grn_order_id").last("limit 1");
GrnOrder grnId = this.getOne(wrapper);
//如果当前数据库没有订单,手动赋值
if (Objects.isNull(grnId)) {
grnId = new GrnOrder();
grnId.setOrderId((long) 0);
}
//创建订单编号
LoggerFactory.getLogger(GrnOrderServiceImpl.class).info("DEBUG:->" + String.valueOf(grnId.getOrderId()));
String serial = Katrina_CJ_Utils.createOrderSerial(Order.RKD_, grnId.getOrderId());
grnOrder.setGrnOrderSerial(serial);
//填充入库单明细
// QueryWrapper<PurchaseDetail> queryWrapper = new QueryWrapper<>();
// queryWrapper.eq("order_po_id", param.getPoId());
//当前采购单明细
// List<PurchaseDetail> details = purchaseDetailService.list(queryWrapper); this.getBaseMapper().insert(grnOrder);
// details.forEach(pd -> {
// GrnOrderDetail grnOrderDetail = new GrnOrderDetail();
// grnOrderDetail.setGrnOrderId(grnOrder.getGrnOrderId());
// grnOrderDetail.setGrnDetailIsGift(pd.getOrderIsGifts());
// grnOrderDetail.setGrnDetailProductId(pd.getOrderProductId());
// grnOrderDetail.setGrnDetailUnit(pd.getOrderUnit());
// grnOrderDetail.setGrnDetailGoods(new BigDecimal(0));
// grnOrderDetailService.getBaseMapper().insert(grnOrderDetail);
// });
} @Override
@Transactional(rollbackFor = {Exception.class})
public void getGoods(GrnOrderParam grnOrderParam) {
GrnOrder grnOrder = new GrnOrder();
grnOrder.setGrnOrderId(grnOrderParam.getGrnOrderId());
grnOrder.setGrnOrderAgent(grnOrderParam.getGrnOrderAgent());
grnOrder.setGrnOrderAgentDept(grnOrderParam.getGrnOrderAgentDept());
grnOrder.setGrnOrderGetGoodsTime(new Date());
grnOrder.setGrnOrderRemark(grnOrderParam.getGrnOrderRemark());
grnOrder.setGrnOrderStatus(Status.FINISH.getStatus()); List<GrnOrderDetail> grnOrderDetails = JSONObject.parseArray(grnOrderParam.getGrnOrderDetail(), GrnOrderDetail.class); //更新入库单 this.getBaseMapper().updateById(grnOrder); //更新入库单详情
grnOrderDetails.forEach(g -> {
// grnOrderDetail.setGrnDetailIsGift(pd.getOrderIsGifts());
// grnOrderDetail.setGrnDetailProductId(pd.getOrderProductId());
// grnOrderDetail.setGrnDetailUnit(pd.getOrderUnit());
// grnOrderDetail.setGrnDetailGoods(new BigDecimal(0));
g.setGrnDetailProductId(g.getGrnDetailProductId());
g.setGrnDetailIsGift(g.getGrnDetailIsGift());
g.setGrnOrderId(grnOrder.getGrnOrderId()); grnOrderDetailService.getBaseMapper().insert(g);
}); //查询入库单详情
QueryWrapper<GrnOrderDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("grn_order_id", grnOrder.getGrnOrderId()); //更新库存和库存事务
List<GrnOrderDetail> details = grnOrderDetailService.list(queryWrapper); //获取采购单数据
GrnOrder grn = this.getById(grnOrder.getGrnOrderId());
PurchaseOrder purchaseOrder = purchaseOrderService.getById(grn.getOrderId());
//更新采购单数据
QueryWrapper<PurchaseDetail> purchaseDetailQueryWrapper = new QueryWrapper<>();
purchaseDetailQueryWrapper.eq("order_po_id", purchaseOrder.getPoId());
List<PurchaseDetail> purchaseDetails = purchaseDetailService.list(purchaseDetailQueryWrapper); //移除无入库的明细
details.removeIf(d -> Objects.isNull(d.getGrnDetailWarehouse())); details.forEach(d -> {
QueryWrapper<Inventory> inventoryQueryWrapper = new QueryWrapper<>();
inventoryQueryWrapper.eq("inventory_product_id", d.getGrnDetailProductId());
List<Inventory> inventories = inventoryService.list(inventoryQueryWrapper); //如果无当前产品,新增库存
if (inventories.size() == 0) {
//新库存
Inventory inventory = new Inventory();
inventory.setInventoryAmount(d.getGrnDetailGoods());
inventory.setInventoryAvailableLocation(d.getGrnDetailGoods());
inventory.setInventoryIn(d.getGrnDetailGoods());
inventory.setInventoryLow(new BigDecimal(0));
inventory.setInventoryProductId(d.getGrnDetailProductId());
inventory.setInventoryMax(new BigDecimal(0));
inventory.setInventoryWarehouseId(d.getGrnDetailWarehouse());
inventory.setInventoryUnit(d.getGrnDetailUnit());
inventory.setInventoryCreateTime(new Date());
inventory.setInventoryOnWay(new BigDecimal(0));
inventory.setInventoryBatch(d.getGrnDetailBatch());
inventory.setInventoryProductTime(d.getGrnDetailProductTime());
inventoryService.getBaseMapper().insert(inventory); //新库存事务
InventoryTransaction transaction = new InventoryTransaction();
transaction.setGrnTransactionInventoryId(inventory.getInventoryId());
transaction.setGrnTransactionIsGift(d.getGrnDetailIsGift());
transaction.setGrnTransactionOrderSerial(grnOrderParam.getGrnOrderSerial());
transaction.setGrnTransactionBatch(d.getGrnDetailBatch());
transaction.setGrnTransactionType(BaseStatus.RK.getDesc());
transaction.setGrnTransactionProductId(d.getGrnDetailProductId());
transaction.setGrnTransactionGrnOrderId(grnOrder.getGrnOrderId());
transaction.setGrnTransactionHappenNumber(d.getGrnDetailGoods());
transaction.setGrnTransactionProductionOfDate(d.getGrnDetailProductTime());
transaction.setGrnTransactionProductBarcode(d.getGrnDetailBarcode()); inventoryTransactionService.getBaseMapper().insert(transaction); } else {
inventories.forEach(inventory -> {
//库位一致
if (inventory.getInventoryWarehouseId().equals(d.getGrnDetailWarehouse())) {
//单位一致
if (inventory.getInventoryUnit().equals(d.getGrnDetailUnit())) {
//更新库存数量
inventory.setInventoryAmount(inventory.getInventoryAmount().add(d.getGrnDetailGoods())); inventoryService.getBaseMapper().updateById(inventory);
} else {
//新库存
Inventory newInventory = new Inventory();
newInventory.setInventoryAmount(d.getGrnDetailGoods());
newInventory.setInventoryAvailableLocation(d.getGrnDetailGoods());
newInventory.setInventoryIn(d.getGrnDetailGoods());
newInventory.setInventoryLow(new BigDecimal(0));
newInventory.setInventoryProductId(d.getGrnDetailProductId());
newInventory.setInventoryMax(new BigDecimal(0));
newInventory.setInventoryWarehouseId(d.getGrnDetailWarehouse());
newInventory.setInventoryUnit(d.getGrnDetailUnit());
newInventory.setInventoryCreateTime(new Date());
newInventory.setInventoryOnWay(new BigDecimal(0));
newInventory.setInventoryBatch(d.getGrnDetailBatch());
newInventory.setInventoryProductTime(d.getGrnDetailProductTime());
inventoryService.getBaseMapper().insert(newInventory); //新库存事务
InventoryTransaction transaction = new InventoryTransaction();
transaction.setGrnTransactionInventoryId(newInventory.getInventoryId());
transaction.setGrnTransactionIsGift(d.getGrnDetailIsGift());
transaction.setGrnTransactionOrderSerial(grnOrderParam.getGrnOrderSerial());
transaction.setGrnTransactionBatch(d.getGrnDetailBatch());
transaction.setGrnTransactionType(BaseStatus.RK.getDesc());
transaction.setGrnTransactionProductId(d.getGrnDetailProductId());
transaction.setGrnTransactionGrnOrderId(grnOrder.getGrnOrderId());
transaction.setGrnTransactionHappenNumber(d.getGrnDetailGoods());
transaction.setGrnTransactionProductionOfDate(d.getGrnDetailProductTime());
transaction.setGrnTransactionProductBarcode(d.getGrnDetailBarcode());
inventoryTransactionService.getBaseMapper().insert(transaction);
}
} else {
//新库存
Inventory newInventory = new Inventory();
newInventory.setInventoryAmount(d.getGrnDetailGoods());
newInventory.setInventoryAvailableLocation(d.getGrnDetailGoods());
newInventory.setInventoryIn(d.getGrnDetailGoods());
newInventory.setInventoryLow(new BigDecimal(0));
newInventory.setInventoryProductId(d.getGrnDetailProductId());
newInventory.setInventoryMax(new BigDecimal(0));
newInventory.setInventoryWarehouseId(d.getGrnDetailWarehouse());
newInventory.setInventoryUnit(d.getGrnDetailUnit());
newInventory.setInventoryCreateTime(new Date());
newInventory.setInventoryOnWay(new BigDecimal(0));
newInventory.setInventoryBatch(d.getGrnDetailBatch());
newInventory.setInventoryProductTime(d.getGrnDetailProductTime());
inventoryService.getBaseMapper().insert(newInventory); //新库存事务
InventoryTransaction transaction = new InventoryTransaction();
transaction.setGrnTransactionInventoryId(newInventory.getInventoryId());
transaction.setGrnTransactionIsGift(d.getGrnDetailIsGift());
transaction.setGrnTransactionOrderSerial(grnOrderParam.getGrnOrderSerial());
transaction.setGrnTransactionBatch(d.getGrnDetailBatch().longValue());
transaction.setGrnTransactionType(BaseStatus.RK.getDesc());
transaction.setGrnTransactionProductId(d.getGrnDetailProductId());
transaction.setGrnTransactionGrnOrderId(grnOrder.getGrnOrderId());
transaction.setGrnTransactionHappenNumber(d.getGrnDetailGoods());
transaction.setGrnTransactionProductionOfDate(d.getGrnDetailProductTime());
transaction.setGrnTransactionProductBarcode(d.getGrnDetailBarcode());
inventoryTransactionService.getBaseMapper().insert(transaction);
}
});
}
}); //TODO
//生成付款单
QueryWrapper<PaymentOrder> wrapper = new QueryWrapper<>();
wrapper.orderByDesc("payment_order_id").last("limit 1");
PaymentOrder serial = paymentOrderService.getOne(wrapper);
if (Objects.isNull(serial)) {
serial = new PaymentOrder();
serial.setPaymentOrderId((long) 0);
}
String paySerial = Katrina_CJ_Utils.createOrderSerial(Order.FKD_, serial.getPaymentOrderId());
PaymentOrder paymentOrder = new PaymentOrder();
paymentOrder.setPaymentOrderSerial(paySerial);
paymentOrder.setPaymentOrderCreateTime(new Date());
paymentOrder.setPaymentOrderStatus(Status.EXECUTION.getStatus()); //更新采购单
//当前采购单总数
purchaseOrder.setPoSumNumbers(new BigDecimal(0)); details.forEach(d -> {
if (purchaseOrder.getPoStatus().equals(Status.EXECUTION.getStatus()) || purchaseOrder.getPoStatus().equals(Status.TERMINATION.getStatus())) {
purchaseDetails.forEach(pd -> {
if (pd.getOrderProductId().equals(d.getGrnDetailProductId())) {
//更新已完成数量
pd.setOrderFinishNumber(pd.getOrderFinishNumber().add(d.getGrnDetailGoods()));
int flag = pd.getOrderNumbers().compareTo(pd.getOrderFinishNumber());
if (flag == 0) {
//已完成
pd.setOrderPendingNumber(new BigDecimal(0));
} else if (flag < 0) {
//超收
pd.setOrderPendingNumber(new BigDecimal(0));
} else {
//更新未完成数量
pd.setOrderPendingNumber(pd.getOrderNumbers().subtract(pd.getOrderFinishNumber()));
}
paymentOrder.setPaymentAmountsPayable(pd.getOrderPrice().multiply(d.getGrnDetailGoods()));
purchaseOrder.setPoSumNumbers(purchaseOrder.getPoSumNumbers().add(pd.getOrderFinishNumber()));
purchaseDetailService.getBaseMapper().updateById(pd);
}
});
} else {
throw new RuntimeException("订单状态异常!");
}
}); PurchaseOrder purchaseOrder_old = purchaseOrderService.getById(purchaseOrder.getPoId()); int flag = purchaseOrder.getPoSumNumbers().compareTo(purchaseOrder_old.getPoSumNumbers()); //订单完成
if (flag == 0 || flag > 0) {
//订单完成
purchaseOrder_old.setPoStatus(Status.FINISH.getStatus());
purchaseOrderService.getBaseMapper().updateById(purchaseOrder_old);
}
paymentOrder.setPaymentGrnOrder(grnOrder.getGrnOrderId());
//新增付款单
paymentOrderService.getBaseMapper().insert(paymentOrder);
} private Serializable getKey(GrnOrderParam param) {
return param.getGrnOrderId();
} private Page getPageContext() {
return LayuiPageFactory.defaultPage();
} private GrnOrder getOldEntity(GrnOrderParam param) {
return this.getById(getKey(param));
} private GrnOrder getEntity(GrnOrderParam param) {
GrnOrder entity = new GrnOrder();
ToolUtil.copyProperties(param, entity);
return entity;
} @Override
public Page<Map<String, Object>> list(String condition, String date_1, String date_2, String status) {
Page productPage = LayuiPageFactory.defaultPage();
return baseMapper.order_list(productPage, condition, date_1, date_2, status);
} }
商贸型企业 Java 收货 + 入库 + 生成付款单的更多相关文章
- SAP交货单过账自动生产采购订单、采购订单自动收货入库
公司间需要买卖操作,由于发货和收货都是同一批人在操作,为了减少业务人员的工作量,提高工作效率,特实现以上功能 1.增强实现:增强点为交货单过账成功时触发,在提交前触发,如果遇到不可预知问题,可能造成数 ...
- ERP采购收货在标准成本和移动平均价下的差别
欢迎关注微信公众号:iERPer (ERP咨询顾问之家) ERP系统在处理主要的采购流程有: 下采购合同->下采购订单->收货->发票校验->付款(财务) 其中 收货和发票校验 ...
- PP生产订单创建、下达、报工、收货、投料
转自http://blog.sina.com.cn/s/blog_69fb8eb60102vpjd.html SAP 物料订单创建.下达.报工.收货与投料(ABAP代码) (2015-06-03 22 ...
- PDA移动POS终端系统,实现专柜或店铺的收货、零售、盘点通过无线网络直接连接总部中央数据库,实现高效安全的移动供应链管理
利用PDA移动终端,实现专柜或店铺的收货.零售.盘点等一体化操作,通过无线网络直接连接总部中央数据库,实现高效安全的移动供应链管理. · PDA订货会应用解决方案利用PDA或电脑系统,在订货会现场直接 ...
- 微信支付开发(7) 收货地址共享接口V2
关键字:微信公众平台 JSSDK 发送给朋友 收货地址共享接口 openAddress 作者:方倍工作室 原文:http://www.cnblogs.com/txw1958/p/weixin-open ...
- JDE报表开发笔记(R5537011 收货校验统计表)
业务场景:根据批次收货,收货后对该批次产品进行检验,记录检验结果生成统计表. 涉及表:主表F37011,业务从表F43121/F4101/F4108 ------------------------- ...
- PO_PO系列 - 收货管理分析(案例)
2014-07-01 Created By BaoXinjian
- 收货MIGO
FUNCTION zrfc_mm003. *"---------------------------------------------------------------------- * ...
- java,url长链接生成短链接,短链接生成器,自定义字符串,对字符串md5混合KEY加密,根据短链接获得key值,不重复的随机数,不重复的随机字符串
java,url长链接生成短链接,短链接生成器,自定义字符串,对字符串md5混合KEY加密,根据短链接获得key值,不重复的随机数,不重复的随机字符串 package com.zdz.test; im ...
随机推荐
- JVM中的本机内存跟踪
1.概述 有没有想过为什么Java应用程序通过众所周知的-Xms和-Xmx调优标志消耗的内存比指定数量多得多?出于各种原因和可能的优化,JVM可以分配额外的本机内存.这些额外的分配最终会使消耗的内存超 ...
- 微服务-springcloud-注册中心
创建服务注册中心(eureka-server) 1.创建项目,选择 Eureka Server 别的都不要选择,next-finish 2.application.yml中写入如下信息:通过eurek ...
- SPOJ STC02 - Antisymmetry(Manacher算法求回文串数)
http://www.spoj.com/problems/STC02/en/ 题意:给出一个长度为n的字符串,问其中有多少个子串s可以使得s = s按位取反+翻转. 例如样例:11001011. 10 ...
- LSI 9211-8I阵列卡IR模式Update为IT模式操作步骤!
以下是DOS系统环境下操作(也可以在windows.linux环境下,只要找到对应的tool就可以)相对应的tool官网可以下载 链接:https://www.broadcom.com/support ...
- 【无线安全实践入门】网络扫描和ARP欺骗
文中可能存在错误操作或错误理解,望大家不吝指正. 同时也希望可以帮助到想要学习接触此方面.或兴趣使然的你,让你有个大概的印象. !阅前须知! 本文是基于我几年前的一本笔记本,上面记录了我学习网络基础时 ...
- java LineNumberReader的使用
前段时间需要读报表打印,需求是可以从第N行读到第N行,发现百度出来的LineNumberReader方法都不怎么理想 然后就找到一篇和众百度里脱颖而出的好文章,所以分享之: 从类 的命名来看,貌似 ...
- Modbus RTU 通信应用案例
如何打开项目归档文件 例程中的TIA博途项目文件与STEP 7项目文件均为归档文件,需要按如下方式打开: TIA博途项目文件 1. 打开TIA博途软件,通过软件左下方“项目视图”按钮切换至项目视图: ...
- JVM中有哪些内存区域,分别是用来干什么的
前言 之前我们探讨过一个.class文件是如何被加载到jvm中的.但是jvm内又是如何划分内存的呢?这个内被加载到了那一块内存中?jvm内存划分也是面试当中必被问到的一个面试题. 什么是jvm内存区域 ...
- android_viewFlipper(一)
需要注意的地方已在代码中表明 package cn.com.sxp; import android.app.Activity; import android.os.Bundle; import and ...
- EnjoyingSoft之Mule ESB开发教程系列第五篇:控制消息的流向-数据路由
目录 1. 使用场景 2. 基于消息头的路由 2.1 使用JSON提交订单的消息 2.2 使用XML提交订单的消息 2.3 使用Choice组件判断订单格式 3. 基于消息内容的路由 4. 其他控制流 ...