2024-03-19 11:08:28 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
using Infrastructure.Attribute;
|
|
|
|
|
|
using ZR.Model;
|
|
|
|
|
|
using ZR.Repository;
|
|
|
|
|
|
using ZR.Service.mes.wms.IService;
|
|
|
|
|
|
using ZR.Model.MES.wms;
|
|
|
|
|
|
using ZR.Model.MES.wms.Dto;
|
|
|
|
|
|
using Mapster;
|
|
|
|
|
|
using System.Collections.Generic;
|
2024-03-22 08:54:11 +08:00
|
|
|
|
using System.Data;
|
|
|
|
|
|
using JinianNet.JNTemplate.Dynamic;
|
2024-03-26 14:19:01 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Security.Cryptography.Xml;
|
|
|
|
|
|
using System.Collections;
|
2024-03-28 11:17:18 +08:00
|
|
|
|
using Infrastructure.Model;
|
|
|
|
|
|
using ZR.Service;
|
|
|
|
|
|
using ZR.Service.Utils;
|
2024-04-08 11:01:42 +08:00
|
|
|
|
using Aliyun.OSS;
|
2024-03-19 11:08:28 +08:00
|
|
|
|
|
|
|
|
|
|
namespace ZR.Service.mes.wms
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 出货单(物料+客户)Service业务层处理
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[AppService(ServiceType = typeof(IWmOutOrderService), ServiceLifetime = LifeTime.Transient)]
|
|
|
|
|
|
public class WmOutOrderService : BaseService<WmOutOrder>, IWmOutOrderService
|
|
|
|
|
|
{
|
2024-03-28 11:17:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-03-19 11:08:28 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询出货单(物料+客户)列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public PagedInfo<WmOutOrderDto> GetList(WmOutOrderQueryDto parm)
|
|
|
|
|
|
{
|
2024-03-26 15:21:21 +08:00
|
|
|
|
var predicate = Expressionable.Create<WmOutOrder>()
|
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.ShipmentNum), it => it.ShipmentNum.Contains(parm.ShipmentNum))
|
|
|
|
|
|
.AndIF(!string.IsNullOrEmpty(parm.CustomNo), it => it.CustomNo.Contains(parm.CustomNo))
|
|
|
|
|
|
.AndIF(parm.Year>0, it => it.Year == parm.Year)
|
|
|
|
|
|
.AndIF(parm.Week>0, it => it.Year == parm.Week)
|
|
|
|
|
|
.AndIF(parm.Date>0, it => it.Year == parm.Date)
|
|
|
|
|
|
;
|
2024-03-19 11:08:28 +08:00
|
|
|
|
var response = Queryable()
|
|
|
|
|
|
.Where(predicate.ToExpression())
|
|
|
|
|
|
.ToPage<WmOutOrder, WmOutOrderDto>(parm);
|
|
|
|
|
|
|
|
|
|
|
|
return response;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取详情
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="ShipmentNum"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public WmOutOrder_material_num GetInfo(string ShipmentNum)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
WmOutOrder WmOutOrderList = Context.Queryable<WmOutOrder>()
|
|
|
|
|
|
.Where(it => it.ShipmentNum == ShipmentNum)
|
|
|
|
|
|
.First();
|
|
|
|
|
|
|
|
|
|
|
|
WmOutOrder_material_num wmOutOrderItem = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (WmOutOrderList != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
wmOutOrderItem = WmOutOrderList.Adapt<WmOutOrder_material_num>();
|
|
|
|
|
|
|
|
|
|
|
|
List<WmMaterialOutorder> moList = Context.Queryable<WmMaterialOutorder>()
|
|
|
|
|
|
.Where(it => it.FkOutorderId == WmOutOrderList.ShipmentNum)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (moList != null && moList.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<WmMaterialQuery_stockQuantityDto2> Material_stock = new List<WmMaterialQuery_stockQuantityDto2>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var moItem in moList)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmMaterial material = Context.Queryable<WmMaterial>().Where(it => it.Id == moItem.FkMaterialId).First();
|
2024-03-26 14:19:01 +08:00
|
|
|
|
if (material != null)
|
2024-03-23 14:31:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
WmMaterialQuery_stockQuantityDto2 dto2 = material.Adapt<WmMaterialQuery_stockQuantityDto2>();
|
|
|
|
|
|
dto2.requireOutNum = moItem.OuthouseNum;
|
|
|
|
|
|
Material_stock.Add(dto2);
|
|
|
|
|
|
}
|
2024-03-26 14:19:01 +08:00
|
|
|
|
|
2024-03-19 11:08:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
wmOutOrderItem.MaterialList = Material_stock;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return wmOutOrderItem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 添加出货单(物料+客户)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public WmOutOrder AddWmOutOrder(WmOutOrder_materialDto model)
|
|
|
|
|
|
{
|
|
|
|
|
|
string today_id = "EG" + DateTime.Now.ToString("yyMMdd");
|
|
|
|
|
|
string last_outorder_ShipmentNum = Context.Queryable<WmOutOrder>().Where(it => it.ShipmentNum.StartsWith(today_id)).Max(it => it.ShipmentNum);
|
|
|
|
|
|
if (string.IsNullOrEmpty(last_outorder_ShipmentNum))
|
|
|
|
|
|
{
|
|
|
|
|
|
model.ShipmentNum = today_id + "001";
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
int flow = int.Parse(last_outorder_ShipmentNum.Substring(last_outorder_ShipmentNum.Length - 3, 3)) + 1;
|
|
|
|
|
|
model.ShipmentNum = today_id + flow.ToString("000");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
WmOutOrder wmOutOrder = model.Adapt<WmOutOrder>();
|
|
|
|
|
|
|
|
|
|
|
|
// 关联表也要新增
|
|
|
|
|
|
if (model.MaterialList != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (model.MaterialList.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
List<WmMaterialOutorder> materialOutorderList = new List<WmMaterialOutorder>();
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in model.MaterialList)
|
|
|
|
|
|
{
|
|
|
|
|
|
WmMaterialOutorder materialOutorder = new WmMaterialOutorder();
|
|
|
|
|
|
materialOutorder.FkMaterialId = item.Id;
|
|
|
|
|
|
materialOutorder.FkOutorderId = model.ShipmentNum;
|
|
|
|
|
|
materialOutorder.OuthouseNum = item.requireOutNum;
|
|
|
|
|
|
materialOutorder.CreatedBy = model.CreatedBy;
|
|
|
|
|
|
materialOutorder.CreatedTime = DateTime.Now;
|
|
|
|
|
|
materialOutorderList.Add(materialOutorder);
|
|
|
|
|
|
};
|
|
|
|
|
|
int result = Context.Insertable(materialOutorderList).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Context.Insertable(wmOutOrder).ExecuteReturnEntity();
|
|
|
|
|
|
}
|
2024-04-09 14:03:10 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除出货单关联的物料出货单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="primarys"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int Delete_fk_matrial(string[] primarys)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(primarys.Count()>0)
|
|
|
|
|
|
{
|
|
|
|
|
|
for(int i = 0; i < primarys.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Context.Deleteable<WmMaterialOutorder>().Where(it => it.FkOutorderId == primarys[i]).ExecuteCommand();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-03-19 11:08:28 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 修改出货单(物料+客户)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public int UpdateWmOutOrder(WmOutOrder model)
|
|
|
|
|
|
{
|
|
|
|
|
|
//var response = Update(w => w.ShipmentNum == model.ShipmentNum, it => new WmOutOrder()
|
|
|
|
|
|
//{
|
|
|
|
|
|
// CustomNo = model.CustomNo,
|
|
|
|
|
|
// CustomName = model.CustomName,
|
|
|
|
|
|
// CustomAddress = model.CustomAddress,
|
|
|
|
|
|
// Remarks = model.Remarks,
|
|
|
|
|
|
// Type = model.Type,
|
|
|
|
|
|
// Status = model.Status,
|
|
|
|
|
|
// Year = model.Year,
|
|
|
|
|
|
// Week = model.Week,
|
|
|
|
|
|
// Date = model.Date,
|
|
|
|
|
|
// CreatedBy = model.CreatedBy,
|
|
|
|
|
|
// CreatedTime = model.CreatedTime,
|
|
|
|
|
|
// UpdatedBy = model.UpdatedBy,
|
|
|
|
|
|
// UpdatedTime = model.UpdatedTime,
|
|
|
|
|
|
//});
|
|
|
|
|
|
//return response;
|
|
|
|
|
|
return Update(model, true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 获取用户信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public List<WmCustom> GetCustominfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
return Context.Queryable<WmCustom>().ToList();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询物料记录表列表
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public (List<WmMaterialQuery_stockQuantityDto>, int) GetmaterialList(WmMaterialQueryDto parm)
|
|
|
|
|
|
{
|
|
|
|
|
|
int total = 0;
|
|
|
|
|
|
var predicate = Expressionable.Create<WmMaterial>()
|
|
|
|
|
|
.AndIF(parm.Partnumber != null, it => it.Partnumber.Contains(parm.Partnumber))
|
|
|
|
|
|
.AndIF(parm.U8InventoryCode != null, it => it.U8InventoryCode.Contains(parm.U8InventoryCode))
|
|
|
|
|
|
.AndIF(parm.ProductName != null, it => it.ProductName.Contains(parm.ProductName))
|
|
|
|
|
|
.AndIF(parm.Color != null, it => it.Color.Contains(parm.Color))
|
|
|
|
|
|
.AndIF(parm.Specification != null, it => it.Specification.Contains(parm.Specification))
|
|
|
|
|
|
.AndIF(parm.Description != null, it => it.Description.Contains(parm.Description))
|
|
|
|
|
|
.AndIF(parm.Search1 != null, it => it.Search1.Contains(parm.Search1) || it.Search2.Contains(parm.Search1))
|
|
|
|
|
|
.AndIF(parm.Status > -1, it => it.Status == parm.Status);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<WmMaterial> materialList = Context.Queryable<WmMaterial>()
|
2024-04-09 14:03:10 +08:00
|
|
|
|
.Where(predicate.ToExpression())
|
|
|
|
|
|
|
|
|
|
|
|
.OrderByDescending(it => it.CreatedTime)
|
2024-03-19 11:08:28 +08:00
|
|
|
|
.ToPageList(parm.PageNum, parm.PageSize, ref total);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<WmMaterialQuery_stockQuantityDto> material_stockQuantity_list = new List<WmMaterialQuery_stockQuantityDto>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (materialList.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (WmMaterial item in materialList)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
WmMaterialQuery_stockQuantityDto wmMaterialQuery_Stock_item = item.Adapt<WmMaterialQuery_stockQuantityDto>();
|
|
|
|
|
|
|
|
|
|
|
|
int material_num = 0;
|
|
|
|
|
|
List<WmGoodsNowProduction> productioList = Context
|
|
|
|
|
|
.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.Partnumber == item.Partnumber)
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (productioList.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var product in productioList)
|
|
|
|
|
|
{
|
|
|
|
|
|
material_num = material_num + (int)product.GoodsNumLogic;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-09 14:03:10 +08:00
|
|
|
|
if(material_num>0)
|
|
|
|
|
|
{
|
|
|
|
|
|
wmMaterialQuery_Stock_item.stockQuantity = material_num;
|
|
|
|
|
|
material_stockQuantity_list.Add(wmMaterialQuery_Stock_item);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-19 11:08:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return (material_stockQuantity_list, total);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-22 08:54:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 查询出货单的物料信息
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="shipment_num"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public List<WmMaterialQuery_print> Queryoutoder_matrials(string shipment_num)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2024-03-28 08:52:44 +08:00
|
|
|
|
List<WmMaterialQuery_print> stockList = Context.Queryable<WmMaterialOutorder>()
|
2024-03-22 08:54:11 +08:00
|
|
|
|
.LeftJoin<WmMaterial>((mo, m) => mo.FkMaterialId == m.Id)
|
|
|
|
|
|
.Where(mo => mo.FkOutorderId == shipment_num)
|
|
|
|
|
|
.Select((mo, m) => new WmMaterialQuery_print()
|
|
|
|
|
|
{
|
|
|
|
|
|
//物料号
|
|
|
|
|
|
Partnumber = m.Partnumber,
|
|
|
|
|
|
// 描述
|
|
|
|
|
|
ProductName = m.ProductName,
|
|
|
|
|
|
//需求零件数
|
|
|
|
|
|
RequireOutNum = mo.OuthouseNum
|
|
|
|
|
|
}).ToList();
|
2024-03-28 08:52:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-03-22 08:54:11 +08:00
|
|
|
|
if (stockList != null && stockList.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var stock in stockList)
|
|
|
|
|
|
{
|
2024-04-08 11:01:42 +08:00
|
|
|
|
//库存箱数
|
2024-03-28 08:52:44 +08:00
|
|
|
|
stock.PackageNum = Context.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.Partnumber == stock.Partnumber).Count();
|
2024-03-22 08:54:11 +08:00
|
|
|
|
|
2024-04-08 11:01:42 +08:00
|
|
|
|
//库存零件数
|
2024-03-28 08:52:44 +08:00
|
|
|
|
int? num = Context.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.Partnumber == stock.Partnumber)
|
2024-03-28 15:36:38 +08:00
|
|
|
|
.Sum(it => it.GoodsNumAction);
|
2024-03-26 14:19:01 +08:00
|
|
|
|
stock.ItemNum = num ?? 0;
|
2024-04-08 11:01:42 +08:00
|
|
|
|
|
|
|
|
|
|
// 需求箱数
|
|
|
|
|
|
List<WmGoodsNowProduction> list= Context.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.Partnumber == stock.Partnumber).OrderByDescending(it=>it.PackageCodeClient).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
int sum = 0;
|
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
|
{
|
|
|
|
|
|
sum = sum + item.GoodsNumLogic??0;
|
|
|
|
|
|
if(sum>= stock.RequireOutNum)
|
|
|
|
|
|
{
|
|
|
|
|
|
stock.Require_pack_num=list.IndexOf(item)+1;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-22 08:54:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return stockList;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-03-28 11:17:18 +08:00
|
|
|
|
/// 生成出库单的出货计划
|
2024-03-22 08:54:11 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="shipment_num">出货单号</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public List<WmOutOrderPlan> Generate_outorderplan(string shipment_num)
|
|
|
|
|
|
{
|
2024-03-28 11:17:18 +08:00
|
|
|
|
// 最终结果
|
|
|
|
|
|
List<WmOutOrderPlan> planList = new List<WmOutOrderPlan>();
|
2024-03-22 08:54:11 +08:00
|
|
|
|
// 获取当前出货单下的物料信息
|
|
|
|
|
|
List<WmMaterialQuery_print> materialQuery_Prints = this.Queryoutoder_matrials(shipment_num);
|
|
|
|
|
|
if (materialQuery_Prints != null && materialQuery_Prints.Count > 0)
|
|
|
|
|
|
{
|
2024-03-28 11:17:18 +08:00
|
|
|
|
// 物料解析
|
2024-03-22 08:54:11 +08:00
|
|
|
|
foreach (var material in materialQuery_Prints)
|
|
|
|
|
|
{
|
2024-03-28 11:17:18 +08:00
|
|
|
|
//1. 物料需求量
|
2024-03-22 08:54:11 +08:00
|
|
|
|
int require_num = material.RequireOutNum;
|
|
|
|
|
|
// 物料号
|
|
|
|
|
|
string partnumber = material.Partnumber;
|
2024-03-28 11:17:18 +08:00
|
|
|
|
// 该物料下 ,现有货物列表,零件号相同,根据批次号从小到大排序
|
2024-03-26 14:19:01 +08:00
|
|
|
|
List<WmGoodsNowProduction> wmGoodsNowsList = Context.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.Partnumber == partnumber)
|
2024-03-28 15:36:38 +08:00
|
|
|
|
.OrderBy(it => it.PackageCodeClient)
|
2024-03-26 14:19:01 +08:00
|
|
|
|
.ToList();
|
2024-04-09 14:03:10 +08:00
|
|
|
|
|
2024-03-28 11:17:18 +08:00
|
|
|
|
// 判断要出多少批次的货
|
|
|
|
|
|
List<WmOutOrderPlan> wmOutOrderPlans = new List<WmOutOrderPlan>();
|
2024-03-28 15:36:38 +08:00
|
|
|
|
// 当前累计批次货物总数
|
|
|
|
|
|
int accumulation_num = 0;
|
2024-03-23 14:31:50 +08:00
|
|
|
|
foreach (var witem in wmGoodsNowsList)
|
2024-03-22 08:54:11 +08:00
|
|
|
|
{
|
2024-03-23 14:31:50 +08:00
|
|
|
|
if (require_num >= accumulation_num)
|
2024-03-22 08:54:11 +08:00
|
|
|
|
{
|
|
|
|
|
|
WmOutOrderPlan orderPlan = new WmOutOrderPlan();
|
|
|
|
|
|
orderPlan.FkOutOrderId = shipment_num;
|
|
|
|
|
|
orderPlan.Patchcode = witem.PackageCodeClient;
|
2024-03-28 11:17:18 +08:00
|
|
|
|
orderPlan.Patchcode_short = witem.PackageCodeClient.Split("_")[0];
|
2024-03-22 08:54:11 +08:00
|
|
|
|
orderPlan.MaterialCode = witem.Partnumber;
|
|
|
|
|
|
orderPlan.WarehouseCode = witem.LocationCode;
|
2024-03-28 11:17:18 +08:00
|
|
|
|
orderPlan.PackageNum = material.PackageNum;
|
2024-03-28 15:36:38 +08:00
|
|
|
|
// 获得批次的总零件数
|
2024-04-09 14:03:10 +08:00
|
|
|
|
orderPlan.PartnumberNum = witem.GoodsNumLogic;
|
2024-03-22 08:54:11 +08:00
|
|
|
|
orderPlan.RequireNum = require_num;
|
2024-03-28 11:17:18 +08:00
|
|
|
|
orderPlan.Patchtime = Resolution_bath(witem.PackageCodeOriginal);
|
2024-03-22 08:54:11 +08:00
|
|
|
|
wmOutOrderPlans.Add(orderPlan);
|
2024-03-26 14:19:01 +08:00
|
|
|
|
// 实际值计算
|
2024-04-09 14:03:10 +08:00
|
|
|
|
accumulation_num = accumulation_num + witem.GoodsNumLogic ?? 0;
|
2024-03-22 08:54:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-28 11:17:18 +08:00
|
|
|
|
// 进行聚合
|
2024-03-26 14:19:01 +08:00
|
|
|
|
if (wmOutOrderPlans.Count > 0)
|
2024-03-28 11:17:18 +08:00
|
|
|
|
{
|
|
|
|
|
|
// 根据批次号下划线前进行聚合
|
2024-04-09 14:03:10 +08:00
|
|
|
|
List < WmOutOrderPlan > material_plan_item = wmOutOrderPlans.GroupBy(it => it.Patchcode_short).Select(g => new
|
2024-03-28 11:17:18 +08:00
|
|
|
|
WmOutOrderPlan
|
|
|
|
|
|
{
|
|
|
|
|
|
FkOutOrderId = g.Max(p => p.FkOutOrderId),
|
2024-03-28 15:36:38 +08:00
|
|
|
|
Patchcode = g.Max(p => p.Patchcode_short),
|
2024-03-28 11:17:18 +08:00
|
|
|
|
Patchcode_short = g.Max(p => p.Patchcode_short),
|
|
|
|
|
|
WarehouseCode = g.Max(p => p.WarehouseCode),
|
|
|
|
|
|
MaterialCode = g.Max(p => p.MaterialCode),
|
|
|
|
|
|
PackageNum = g.Count(),
|
2024-03-28 15:36:38 +08:00
|
|
|
|
PartnumberNum = g.Sum(p=>p.PartnumberNum),
|
2024-03-28 11:17:18 +08:00
|
|
|
|
RequireNum = g.Max(p => p.RequireNum),
|
|
|
|
|
|
Patchtime = g.Max(p => p.Patchtime),
|
|
|
|
|
|
}).ToList();
|
2024-04-09 14:03:10 +08:00
|
|
|
|
|
|
|
|
|
|
planList=planList.Concat(material_plan_item).ToList();
|
2024-03-28 11:17:18 +08:00
|
|
|
|
}
|
2024-04-08 11:01:42 +08:00
|
|
|
|
|
2024-03-22 08:54:11 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-03-28 11:17:18 +08:00
|
|
|
|
// 添加序号
|
|
|
|
|
|
int count = 1;
|
|
|
|
|
|
foreach (var witem in planList)
|
2024-03-22 08:54:11 +08:00
|
|
|
|
{
|
2024-03-28 11:17:18 +08:00
|
|
|
|
witem.Id = count;
|
|
|
|
|
|
witem.Outorder = count;
|
2024-04-08 11:01:42 +08:00
|
|
|
|
|
2024-03-28 11:17:18 +08:00
|
|
|
|
count++;
|
2024-04-08 11:01:42 +08:00
|
|
|
|
witem.Inventory_pack_num = Context.Queryable<WmGoodsNowProduction>()
|
2024-04-09 14:03:10 +08:00
|
|
|
|
.Where(it=>it.PackageCodeClient.Contains(witem.Patchcode))
|
2024-04-08 11:01:42 +08:00
|
|
|
|
.Count();
|
|
|
|
|
|
witem.Inventory_num = Context.Queryable<WmGoodsNowProduction>()
|
2024-04-09 14:03:10 +08:00
|
|
|
|
.Where(it => it.PackageCodeClient.Contains( witem.Patchcode))
|
2024-04-08 11:01:42 +08:00
|
|
|
|
.Sum(it=>it.GoodsNumLogic)??0;
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-22 08:54:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-28 11:17:18 +08:00
|
|
|
|
return planList;
|
2024-03-22 08:54:11 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-23 14:31:50 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 根据出库单号与货物批次号,向出库记录添加数据,并且成品库表数据删除
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="doMaterialOut"></param>
|
|
|
|
|
|
/// <returns></returns>
|
2024-03-26 14:19:01 +08:00
|
|
|
|
public (int, int) DoMaterialOut(WmDoMaterialOut_Dto doMaterialOut, string Createby)
|
2024-03-23 14:31:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
int sum_delete = 0;
|
|
|
|
|
|
int sum_insert = 0;
|
|
|
|
|
|
string shipnumber = doMaterialOut.ShipmentNum;
|
2024-03-26 14:19:01 +08:00
|
|
|
|
if (doMaterialOut.PatchCode != null && doMaterialOut.PatchCode.Length > 0)
|
2024-03-23 14:31:50 +08:00
|
|
|
|
{
|
2024-03-26 14:19:01 +08:00
|
|
|
|
foreach (var item in doMaterialOut.PatchCode)
|
2024-03-23 14:31:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
UseTran2(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
WmGoodsOutRecord record = new WmGoodsOutRecord();
|
|
|
|
|
|
record.Id = SnowFlakeSingle.Instance.NextId().ToString();
|
|
|
|
|
|
WmGoodsNowProduction nowProduction = Context.Queryable<WmGoodsNowProduction>()
|
|
|
|
|
|
.Where(it => it.PackageCodeClient == item).First();
|
|
|
|
|
|
|
|
|
|
|
|
if (nowProduction != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
record.FkNowProductionId = nowProduction.Id;
|
2024-03-26 14:19:01 +08:00
|
|
|
|
record.PackageCodeClient = nowProduction.PackageCodeClient;
|
2024-03-23 14:31:50 +08:00
|
|
|
|
record.PackageCode = nowProduction.PackageCode;
|
|
|
|
|
|
record.PackageCodeOriginal = nowProduction.PackageCodeOriginal;
|
|
|
|
|
|
record.LocationCode = nowProduction.LocationCode;
|
|
|
|
|
|
record.Partnumber = nowProduction.Partnumber;
|
|
|
|
|
|
record.GoodsNumLogic = nowProduction.GoodsNumLogic;
|
|
|
|
|
|
record.GoodsNumAction = nowProduction.GoodsNumAction;
|
|
|
|
|
|
record.EntryWarehouseTime = nowProduction.EntryWarehouseTime;
|
|
|
|
|
|
record.OutTime = DateTime.Now;
|
|
|
|
|
|
record.CreatedTime = DateTime.Now;
|
|
|
|
|
|
record.CreatedBy = Createby;
|
|
|
|
|
|
record.FkOutOrderId = shipnumber;
|
2024-03-26 14:19:01 +08:00
|
|
|
|
sum_insert = Context.Insertable(record).ExecuteCommand();
|
|
|
|
|
|
sum_delete += Context.Deleteable<WmGoodsNowProduction>()
|
2024-03-23 14:31:50 +08:00
|
|
|
|
.Where(it => it.PackageCodeClient == item)
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
}
|
2024-03-26 14:19:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
2024-03-23 14:31:50 +08:00
|
|
|
|
});
|
2024-03-26 14:19:01 +08:00
|
|
|
|
|
2024-03-23 14:31:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return (sum_delete, sum_insert);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-26 14:19:01 +08:00
|
|
|
|
public bool OverOutorderplan(string shipment_num)
|
2024-03-23 14:31:50 +08:00
|
|
|
|
{
|
2024-03-26 14:19:01 +08:00
|
|
|
|
int reult = Context.Updateable<WmOutOrder>().Where(it => it.ShipmentNum == shipment_num)
|
|
|
|
|
|
.SetColumns(it => it.Type == 2)
|
|
|
|
|
|
.ExecuteCommand();
|
|
|
|
|
|
if (reult > 0)
|
2024-03-23 14:31:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-22 08:54:11 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 传入批次号 解析出时间 BNW240318007_105
|
|
|
|
|
|
/// </summary>
|
2024-03-28 11:17:18 +08:00
|
|
|
|
/// <param name="production_packcode">原始编码</param>
|
2024-03-22 08:54:11 +08:00
|
|
|
|
/// <returns></returns>
|
2024-03-28 11:17:18 +08:00
|
|
|
|
private string Resolution_bath(string production_packcode)
|
2024-03-22 08:54:11 +08:00
|
|
|
|
{
|
2024-03-28 11:17:18 +08:00
|
|
|
|
MaterialUtils materialToos = new MaterialUtils();
|
|
|
|
|
|
ResultionPackageCodeDto resultionPackage = materialToos.ResolutionPackage(production_packcode);
|
|
|
|
|
|
if (resultionPackage == null)
|
2024-03-22 08:54:11 +08:00
|
|
|
|
{
|
2024-03-28 11:17:18 +08:00
|
|
|
|
return "时间解析异常";
|
2024-03-22 08:54:11 +08:00
|
|
|
|
}
|
2024-03-28 11:17:18 +08:00
|
|
|
|
return resultionPackage.ProductionTime;
|
2024-03-22 08:54:11 +08:00
|
|
|
|
}
|
2024-03-28 09:12:17 +08:00
|
|
|
|
|
2024-03-28 11:17:18 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 检查是否可出库
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="production_packcode"></param>
|
|
|
|
|
|
/// <param name="shipment_num"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public string CheckProductionOut(string production_packcode, string shipment_num)
|
2024-03-28 09:12:17 +08:00
|
|
|
|
{
|
2024-03-28 12:29:39 +08:00
|
|
|
|
try
|
2024-03-28 11:17:18 +08:00
|
|
|
|
{
|
2024-03-28 12:29:39 +08:00
|
|
|
|
if (shipment_num == "" || production_packcode == "")
|
|
|
|
|
|
{
|
|
|
|
|
|
return "传入数据为空!请检查参数";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 1.判断工单是否处于已完成状态
|
|
|
|
|
|
bool isOutOrderCanUse = Context.Queryable<WmOutOrder>().Where(it => it.ShipmentNum == shipment_num).Where(it => it.Type == 1).Any();
|
|
|
|
|
|
if (!isOutOrderCanUse)
|
2024-03-28 11:17:18 +08:00
|
|
|
|
{
|
2024-03-28 12:29:39 +08:00
|
|
|
|
return "出库单已完成或已弃用!请检查出库单";
|
2024-03-28 11:17:18 +08:00
|
|
|
|
}
|
2024-03-28 12:29:39 +08:00
|
|
|
|
|
|
|
|
|
|
MaterialUtils materialToos = new MaterialUtils();
|
|
|
|
|
|
// 2.解析标签编码
|
|
|
|
|
|
ResultionPackageCodeDto resultionPackage = materialToos.ResolutionPackage(production_packcode);
|
|
|
|
|
|
if (resultionPackage == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "标签解析异常!请检查标签";
|
|
|
|
|
|
}
|
|
|
|
|
|
// 3.判断是否已入库
|
|
|
|
|
|
bool isExistedWarehouse = Context.Queryable<WmGoodsNowProduction>().Where(it => it.PackageCodeClient == resultionPackage.PatchCode).Any();
|
|
|
|
|
|
if (!isExistedWarehouse)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "该箱号未入库!请先入库";
|
|
|
|
|
|
}
|
2024-04-09 14:03:10 +08:00
|
|
|
|
|
2024-03-28 12:29:39 +08:00
|
|
|
|
// 4.获取出库单号对应的出库计划
|
|
|
|
|
|
List<WmOutOrderPlan> orderPlans = Generate_outorderplan(shipment_num);
|
|
|
|
|
|
// 5.配对是否符合出库条件
|
|
|
|
|
|
foreach (var orderPlan in orderPlans)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 存在匹配条件: 箱标签批次号包含计划短批次号
|
|
|
|
|
|
if (orderPlan != null && resultionPackage.PatchCode.Contains(orderPlan.Patchcode_short))
|
|
|
|
|
|
{
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-04-09 14:03:10 +08:00
|
|
|
|
// 6 .还差一个 数量超过要出库的箱子
|
2024-03-28 12:29:39 +08:00
|
|
|
|
return "此箱标签不可出库,批次号不在出库单计划内!请检查出库单计划!";
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "此箱标签存在异常不可出库!";
|
2024-03-28 11:17:18 +08:00
|
|
|
|
}
|
2024-03-28 12:29:39 +08:00
|
|
|
|
|
2024-03-28 09:12:17 +08:00
|
|
|
|
}
|
2024-04-11 16:23:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 持久化存储
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="shipment_num"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
|
|
|
public int PersistenceOutorderplan(string shipment_num)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-19 11:08:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|