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 收货 + 入库 + 生成付款单的更多相关文章

  1. SAP交货单过账自动生产采购订单、采购订单自动收货入库

    公司间需要买卖操作,由于发货和收货都是同一批人在操作,为了减少业务人员的工作量,提高工作效率,特实现以上功能 1.增强实现:增强点为交货单过账成功时触发,在提交前触发,如果遇到不可预知问题,可能造成数 ...

  2. ERP采购收货在标准成本和移动平均价下的差别

    欢迎关注微信公众号:iERPer (ERP咨询顾问之家) ERP系统在处理主要的采购流程有: 下采购合同->下采购订单->收货->发票校验->付款(财务) 其中 收货和发票校验 ...

  3. PP生产订单创建、下达、报工、收货、投料

    转自http://blog.sina.com.cn/s/blog_69fb8eb60102vpjd.html SAP 物料订单创建.下达.报工.收货与投料(ABAP代码) (2015-06-03 22 ...

  4. PDA移动POS终端系统,实现专柜或店铺的收货、零售、盘点通过无线网络直接连接总部中央数据库,实现高效安全的移动供应链管理

    利用PDA移动终端,实现专柜或店铺的收货.零售.盘点等一体化操作,通过无线网络直接连接总部中央数据库,实现高效安全的移动供应链管理. · PDA订货会应用解决方案利用PDA或电脑系统,在订货会现场直接 ...

  5. 微信支付开发(7) 收货地址共享接口V2

    关键字:微信公众平台 JSSDK 发送给朋友 收货地址共享接口 openAddress 作者:方倍工作室 原文:http://www.cnblogs.com/txw1958/p/weixin-open ...

  6. JDE报表开发笔记(R5537011 收货校验统计表)

    业务场景:根据批次收货,收货后对该批次产品进行检验,记录检验结果生成统计表. 涉及表:主表F37011,业务从表F43121/F4101/F4108 ------------------------- ...

  7. PO_PO系列 - 收货管理分析(案例)

    2014-07-01 Created By BaoXinjian

  8. 收货MIGO

    FUNCTION zrfc_mm003. *"---------------------------------------------------------------------- * ...

  9. java,url长链接生成短链接,短链接生成器,自定义字符串,对字符串md5混合KEY加密,根据短链接获得key值,不重复的随机数,不重复的随机字符串

    java,url长链接生成短链接,短链接生成器,自定义字符串,对字符串md5混合KEY加密,根据短链接获得key值,不重复的随机数,不重复的随机字符串 package com.zdz.test; im ...

随机推荐

  1. python 基本数据类型之字符串功能

    字符串常用功能: # name.upper() #全部大写变小写 # name.lower() #全部小写变大写 # name.split() #分割 # name.find() #找到指定子序列的索 ...

  2. Python绘制语谱图+时域波形

    """Python绘制语谱图""" """Python绘制时域波形""" # 导 ...

  3. Linux下无法执行tree命令问题

    Linux下不能使用tree命令,是因为没有安装命令, 执行下面代码就行了 yum install tree -y

  4. JavaScript面试核心考点(精华)

    引言 Javascript是前端面试的重点,本文重点梳理下 Javascript 中的常考基础知识点,然后就一些容易出现的题目进行解析.限于文章的篇幅,无法将知识点讲解的面面俱到,本文只罗列了一些重难 ...

  5. Codeforces Gym100502G:Outing(缩点+有依赖的树形背包)

    http://codeforces.com/gym/100502/attachments 题意:有n个点,容量为tol,接下来n个关系,表示选了第i个点,那么第xi个点就必须被选.问最多可以选多少个点 ...

  6. Larave使用composer安装无反应,提示“Changed current directory to C:/Users/Administrator/AppData/Roaming/Composer”

    按照Laravel文档的安装方式在windows上安装Laravel时,执行composer global require "laravel/installer". 然后命令行就显 ...

  7. Linux命令学习-tail命令

    Linux中,tail命令的全称就是tail,主要用于监控日志文件. 对于一个正在运行应用来说,其对应的log日志文件肯定是在不断的更新,此时,便可通过tail命令来动态显示日志文件的内容.假设当前目 ...

  8. 1.为什么会有Servlet?它解决了什么问题?

    1. 为什么会出现Servlet? 因为web服务器(tomcat.Weblogic.iis.apache)没有处理动态资源请求的能力(即该请求需要计算),只能处理静态资源的请求(如果浏览器请求某个h ...

  9. Android native进程间通信实例-socket本地通信篇之——基本通信功能

    导读: 网上看了很多篇有关socket本地通信的示例,很多都是调通服务端和客户端通信功能后就没有下文了,不太实用,真正开发中遇到的问题以及程序稳定性部分没有涉及,代码健壮性不够,本系列(socket本 ...

  10. Vue快速学习_第三节

    过滤器 局部过滤器(组件内部使用的过滤器,跟django的很像, filters: {过滤器的名字: {function(val, a,b){}}} 全局过滤器(全局过滤器,只要过滤器一创建,在任何组 ...