using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using WMS.Web.Domain.Values;
namespace WMS.Web.Domain.Entitys
{
///
/// wms入库单
///
[Serializable]
[Table("t_wms_instock")]
public class InStock
{
///
/// ID
///
public 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.Fail;
///
/// 操作人
///
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; }
///
/// 仓位ID
///
public int SubStockId { 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;
}
///
/// 同步金蝶
///
///
///
///
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).FirstOrDefault();
erpd.SuccessSync = SyncStatus.Success;
erpd.ErpSyncBillNo = erpBillNo;
//所有erp明细同步成功才是整个单据成功
if (this.ErpDetails.Where(w => w.SuccessSync == SyncStatus.Success).Count() == this.Details.Count())
{
this.SuccessSync = SyncStatus.Success;
this.Remark = "";
}
this.OperateId = operateId;
this.SyncTime = DateTime.Now;
}
///
/// 同步金蝶(失败)
///
///
///
///
///
public void SyncFail(string remark, int erpDetailId, int operateId, SyncStatus syncStatus)
{
var erpd = this.ErpDetails.FirstOrDefault(w => w.ErpDetailId == erpDetailId);
erpd.SuccessSync = syncStatus;
this.SuccessSync = SyncStatus.Fail;
this.Remark = remark;
this.OperateId = operateId;
this.SyncTime = DateTime.Now;
}
}
}