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 { /// /// erp入库任务表 /// [Serializable] [Table("t_erp_instock_task")] public class InStockTask : EntityBase { /// /// ID /// public override int Id { get; set; } /// /// 单据编号 /// public string BillNo { get; set; } /// /// 来源单号 /// public string SourceBillNo { get; set; } /// /// 销售订单号 /// public string SaleBillNo { get; set; } /// /// 入库状态 /// public InstockStatus Status { get; set; } /// /// 入库类型 /// public InstockType Type { get; set; } /// /// 收货人 /// public int? ReceiverId { get; set; } /// /// 收货时间 /// public DateTime? ReceiveTime { get; set; } /// /// 上架人 /// public int? ShelferId { get; set; } /// /// 入库时间(上架时间) /// public DateTime? ShelfTime { get; set; } /// /// 创建时间(erp那边的创建时间) /// public DateTime CreateTime { get; set; } /// /// 作废人 /// public int? RepealerId { get; set; } /// /// 作废时间 /// public DateTime? RepealTime { get; set; } /// /// 供应商Id /// public int SupplierId { get; set; } /// /// 组织编码 /// public string OrgCode { get; set; } /// /// 明细 /// public List Details { get; set; } /// /// 创建 /// /// /// /// public void Create(InstockType type,string sourceBillNo, DateTime createTime) { if (type == InstockType.Purchase) this.Status = InstockStatus.Wait; else this.Status = InstockStatus.WaitInStock; this.Type = type; this.SourceBillNo = sourceBillNo; this.CreateTime = createTime; } /// /// 作废 /// public void Repeal(int repealerId,List 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();//重新计算单据的状态 } /// /// 创建订单号 /// /// 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(); } } /// /// 收货 /// /// 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.Status = InstockStatus.Wait; else if(totalRealityQty<=0) this.Status = InstockStatus.WaitInStock; else this.Status = InstockStatus.Part; } /// /// 上架 /// /// public void Shelf(int creatorId) { this.ChangeInstockStatus(); this.ShelferId = creatorId; this.ShelfTime = DateTime.Now; } /// /// 非采购上架 /// /// public void NoPurchaseShelf(int creatorId) { this.ChangeInstockStatus(); this.ReceiverId = creatorId; this.ReceiveTime = DateTime.Now; this.ShelferId = creatorId; this.ShelfTime = DateTime.Now; } } }