243 lines
7.1 KiB
C#
243 lines
7.1 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel.DataAnnotations.Schema;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using WMS.Web.Core;
|
||
using WMS.Web.Domain.Values;
|
||
|
||
namespace WMS.Web.Domain.Entitys
|
||
{
|
||
/// <summary>
|
||
/// erp入库任务表
|
||
/// </summary>
|
||
[Serializable]
|
||
[Table("t_erp_instock_task")]
|
||
public class InStockTask : EntityBase
|
||
{
|
||
/// <summary>
|
||
/// ID
|
||
/// </summary>
|
||
public override int Id { get; set; }
|
||
/// <summary>
|
||
/// 单据编号
|
||
/// </summary>
|
||
public string BillNo { get; set; }
|
||
/// <summary>
|
||
/// 来源单号
|
||
/// </summary>
|
||
public string SourceBillNo { get; set; }
|
||
|
||
///// <summary>
|
||
///// 销售订单号
|
||
///// </summary>
|
||
//public string SaleBillNo { get; set; }
|
||
|
||
/// <summary>
|
||
/// 入库状态
|
||
/// </summary>
|
||
public InstockStatus Status { get; set; }
|
||
/// <summary>
|
||
/// 入库类型
|
||
/// </summary>
|
||
public InstockType Type { get; set; }
|
||
/// <summary>
|
||
/// 收货人
|
||
/// </summary>
|
||
public int? ReceiverId { get; set; }
|
||
/// <summary>
|
||
/// 收货时间
|
||
/// </summary>
|
||
public DateTime? ReceiveTime { get; set; }
|
||
/// <summary>
|
||
/// 上架人
|
||
/// </summary>
|
||
public int? ShelferId { get; set; }
|
||
/// <summary>
|
||
/// 入库时间(上架时间)
|
||
/// </summary>
|
||
public DateTime? ShelfTime { get; set; }
|
||
|
||
|
||
/// <summary>
|
||
/// 创建时间(erp那边的创建时间)
|
||
/// </summary>
|
||
public DateTime CreateTime { get; set; }
|
||
/// <summary>
|
||
/// 在wms最新数据修改时间
|
||
/// </summary>
|
||
public DateTime? WmsUpdateTime { get; set; } = DateTime.Now;
|
||
|
||
/// <summary>
|
||
/// 作废人
|
||
/// </summary>
|
||
public int? RepealerId { get; set; }
|
||
|
||
/// <summary>
|
||
/// 作废时间
|
||
/// </summary>
|
||
public DateTime? RepealTime { get; set; }
|
||
|
||
/// <summary>
|
||
/// 供应商Id
|
||
/// </summary>
|
||
public int? SupplierId { get; set; }
|
||
|
||
/// <summary>
|
||
/// 组织编码
|
||
/// </summary>
|
||
public string OrgCode { get; set; }
|
||
|
||
/// <summary>
|
||
/// 明细
|
||
/// </summary>
|
||
public List<InStockTaskDetails> Details { get; set; }
|
||
|
||
/// <summary>
|
||
/// 创建
|
||
/// </summary>
|
||
/// <param name="type"></param>
|
||
/// <param name="sourceBillNo"></param>
|
||
/// <param name="createTime"></param>
|
||
public void Create(InstockType type, string sourceBillNo, DateTime createTime, int supplierId, string orgCode)
|
||
{
|
||
if (type == InstockType.Purchase)
|
||
this.Status = InstockStatus.Wait;
|
||
else
|
||
this.Status = InstockStatus.WaitInStock;
|
||
this.Type = type;
|
||
this.SourceBillNo = sourceBillNo;
|
||
this.SupplierId = supplierId;
|
||
this.OrgCode = orgCode;
|
||
this.CreateTime = createTime;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 作废
|
||
/// </summary>
|
||
public void Repeal(int repealerId, List<int> detailsIds)
|
||
{
|
||
this.RepealerId = repealerId;
|
||
this.RepealTime = DateTime.Now;
|
||
//明细行作废
|
||
this.Details.Where(x => detailsIds.Contains(x.Id)).ToList().ForEach(x => { x.IsRepeal = true; });
|
||
|
||
//如果明细全部作废,则单据状态作废
|
||
if (this.Details.All(x => x.IsRepeal == true))
|
||
this.Status = InstockStatus.Repeal;
|
||
else
|
||
this.ChangeInstockStatus();//重新计算单据的状态
|
||
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 反作废
|
||
/// </summary>
|
||
public void NoRepeal(int repealerId, List<int> detailsIds)
|
||
{
|
||
this.RepealerId = 0;
|
||
this.RepealTime = null;
|
||
//明细行作废
|
||
this.Details.Where(x => detailsIds.Contains(x.Id)).ToList().ForEach(x => { x.IsRepeal = false; });
|
||
|
||
this.ChangeInstockStatus();//重新计算单据的状态
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 创建订单号
|
||
/// </summary>
|
||
/// <param name="newId"></param>
|
||
public void MakeBillNo(int newId)
|
||
{
|
||
//生成订单号
|
||
var length = newId.ToString().Length;
|
||
if (length >= 8)
|
||
{
|
||
this.BillNo = $"RKRW{newId.ToString()}";
|
||
}
|
||
else
|
||
{
|
||
var needLength = 8 - length;
|
||
var needStr = "";
|
||
for (int i = 0; i < needLength; i++)
|
||
{
|
||
needStr += "0";
|
||
}
|
||
this.BillNo = "RKRW" + needStr + newId.ToString();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 收货
|
||
/// </summary>
|
||
/// <param name="creatorId"></param>
|
||
public void Receive(int creatorId)
|
||
{
|
||
this.Status = InstockStatus.WaitInStock;
|
||
this.ReceiverId = creatorId;
|
||
this.ReceiveTime = DateTime.Now;
|
||
}
|
||
|
||
//改变状态
|
||
public void ChangeInstockStatus()
|
||
{
|
||
//明细中:所有的应入数量之和
|
||
var totalAccruedQty = this.Details.Where(x => x.IsRepeal != true).Sum(x => x.AccruedQty);
|
||
|
||
//明细中:所有的入库数量之和
|
||
var totalRealityQty = this.Details.Where(x => x.IsRepeal != true && x.AccruedQty > 0).Sum(x => x.RealityQty);
|
||
|
||
//明细中:所有的收货数量之和
|
||
var totalReceiveQty = this.Details.Where(x => x.IsRepeal != true && x.AccruedQty > 0).Sum(x => x.ReceiveQty);
|
||
|
||
if (totalAccruedQty <= totalRealityQty)
|
||
this.Status = InstockStatus.Already;
|
||
else if (totalReceiveQty <= 0 && this.Type == InstockType.Purchase)
|
||
this.Status = InstockStatus.Wait;
|
||
else if (totalRealityQty <= 0)
|
||
this.Status = InstockStatus.WaitInStock;
|
||
else
|
||
this.Status = InstockStatus.Part;
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 上架
|
||
/// </summary>
|
||
/// <param name="creatorId"></param>
|
||
public void Shelf(int creatorId)
|
||
{
|
||
this.ChangeInstockStatus();
|
||
this.ShelferId = creatorId;
|
||
this.ShelfTime = DateTime.Now;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 非采购上架
|
||
/// </summary>
|
||
/// <param name="creatorId"></param>
|
||
public void NoPurchaseShelf(int creatorId)
|
||
{
|
||
this.ChangeInstockStatus();
|
||
this.ReceiverId = creatorId;
|
||
this.ReceiveTime = DateTime.Now;
|
||
this.ShelferId = creatorId;
|
||
this.ShelfTime = DateTime.Now;
|
||
}
|
||
/// <summary>
|
||
/// erp删单 作废处理
|
||
/// </summary>
|
||
public void ErpDel()
|
||
{
|
||
foreach (var d in this.Details)
|
||
{
|
||
d.AccruedQty = 0;
|
||
d.IsRepeal = true;
|
||
}
|
||
this.Status = InstockStatus.Repeal;
|
||
}
|
||
}
|
||
}
|