using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using WMS.Web.Core; using WMS.Web.Core.Internal.Results; using WMS.Web.Domain.Values; namespace WMS.Web.Domain.Entitys { /// /// wms入库单 /// [Serializable] [Table("t_wms_instock")] public class InStock : EntityBase { public InStock() { } /// /// ID /// public override int Id { get; set; } /// /// 单据编号 /// public string BillNo { get; set; } /// /// 入库类型 /// public InstockType Type { get; set; } /// /// 出入库方式:1按箱,2按产品 /// public InventoryInOutMethod Method { get; set; } /// /// 创建人 /// public int CreatorId { get; set; } /// /// 创建时间(入库时间) /// public DateTime CreateTime { get; set; } /// /// 同步成功或者失败 /// public SyncStatus SuccessSync { get; set; } = SyncStatus.SyncIng; /// /// 操作人 /// public int OperateId { get; set; } /// /// 同步时间 /// public DateTime? SyncTime { get; set; } /// /// 备注 /// public string Remark { get; set; } /// /// 组织ID /// public int OrgId { get; set; } /// /// 组织编码 /// public string OrgCode { get; set; } /// /// 仓库编码 /// public string StockCode { get; set; } /// /// 仓位编码 /// public string SubStockCode { get; set; } /// /// ERP明细 /// public List ErpDetails { get; set; } = new List(); /// /// 明细 /// public List Details { get; set; } = new List(); /// /// 创建 /// /// public void Create(int creatorId) { this.CreatorId = creatorId; this.CreateTime = DateTime.Now; if (this.Type == InstockType.Purchase) { this.SuccessSync = SyncStatus.SyncIng; this.ErpDetails.ForEach(f => f.SuccessSync = SyncStatus.SyncIng); } else if (this.Type == InstockType.ProduceSotck) { this.SuccessSync = SyncStatus.SyncIng; this.ErpDetails.ForEach(f => f.SuccessSync = SyncStatus.SyncIng); } else//非采购订单,这里就没有记录erpdetails的数据了 { this.SuccessSync = SyncStatus.Success; } } /// /// 同步金蝶 /// /// /// /// public void Sync(SyncStatus syncStatus, int operateId, string remark) { this.SuccessSync = syncStatus; this.Remark = remark; this.OperateId = operateId; this.SyncTime = DateTime.Now; } /// /// 生成单据号 /// public void GenerateNo() { //用户手动输入了 就不自动生成了 if (!string.IsNullOrEmpty(this.BillNo)) return; if (this.Id.ToString().Length >= 8) { this.BillNo = "RK" + this.Id.ToString(); return; } string idStr = this.Id.ToString(); while (true) { idStr = "0" + idStr; if (idStr.Length >= 8) break; } this.BillNo = "RK" + idStr; } /// /// 同步金蝶(成功) /// /// /// /// public void SyncSuccess(int erpDetailId, int operateId, string erpBillNo) { var erpd = this.ErpDetails.Where(s => s.ErpDetailId == erpDetailId).ToList(); erpd.ForEach(det => { det.SuccessSync = SyncStatus.Success; det.ErpSyncBillNo = erpBillNo; }); //所有erp明细同步成功才是整个单据成功 if (this.ErpDetails.Where(w => w.SuccessSync == SyncStatus.Success).Count() == this.ErpDetails.Count()) { this.SuccessSync = SyncStatus.Success; this.Remark = ""; } else this.SuccessSync = SyncStatus.Fail; this.OperateId = operateId; this.SyncTime = DateTime.Now; } /// /// 同步金蝶(失败) /// /// /// /// /// public void SyncFail(string remark, int erpDetailId, int operateId, SyncStatus syncStatus) { var erpd = this.ErpDetails.Where(w => w.ErpDetailId == erpDetailId).ToList(); erpd.ForEach(det => { det.SuccessSync = syncStatus; }); this.SuccessSync = SyncStatus.Fail; this.Remark = remark; this.OperateId = operateId; this.SyncTime = DateTime.Now; } /// /// 全部失败 /// /// /// public void SyncFailAll(string remark, int operateId) { this.SuccessSync = SyncStatus.Fail; this.Remark = remark; this.OperateId = operateId; this.SyncTime = DateTime.Now; } /// /// 重传 /// public void RepeatSync() { //只有完全失败的情况下才能重传 if (this.SuccessSync != SyncStatus.Fail) return; this.SuccessSync = SyncStatus.SyncIng; var erpDetails = this.ErpDetails .Where(w => w.SuccessSync == SyncStatus.Fail || w.SuccessSync == SyncStatus.SubmitFail || w.SuccessSync == SyncStatus.CheckFail) .ToList(); foreach (var e in erpDetails) { e.SuccessSync = SyncStatus.SyncIng; } this.Remark = ""; } /// /// 同步成功 /// /// /// /// /// public Result OperationSyncSuccess(string sourceBillNo, string materialNumber, string erpBillNo) { var erpDetail = this.ErpDetails.FirstOrDefault(f => f.SourceBillNo.Equals(sourceBillNo) && f.MaterialNumber.Equals(materialNumber)); if (erpDetail == null) return Result.ReFailure(ResultCodes.NoDateError); if (erpDetail.SuccessSync == SyncStatus.Success) return Result.ReSuccess(); if (this.SuccessSync == SyncStatus.Success) return Result.ReFailure(ResultCodes.SyncSuccessError); erpDetail.ErpSyncBillNo = erpBillNo; erpDetail.SuccessSync = SyncStatus.Success; if (this.ErpDetails.Where(w => w.SuccessSync == SyncStatus.Success).Count() == this.ErpDetails.Count()) this.SuccessSync = SyncStatus.Success; return Result.ReSuccess(); } } }