using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;
using WMS.Web.Core;
using WMS.Web.Domain.Values;
namespace WMS.Web.Domain.Entitys
{
///
/// wms盘点单
///
[Serializable]
[Table("t_wms_takestock")]
public class TakeStock : EntityBase
{
public TakeStock() { }
///
/// 主键 订单编号
///
[Column("Id")]
public override int Id { get; set; }
///
/// 单据编号
///
[Column("BillNo")]
public string BillNo { get; set; }
///
/// 盘点日期
///
[Column("Date")]
public DateTime Date { get; set; } = DateTime.Now;
///
/// 盘点人员
///
[Column("CreatorId")]
public int CreatorId { get; set; }
///
/// 同步状态
///
[Column("SuccessSync")]
public SyncStatus SuccessSync { get; set; } = SyncStatus.Success;
///
/// 盘点结果类型:1为盘盈,2位盘亏
/// 盘点数量-系统库存 大于0为盘盈 小于0为盘亏
///
[Column("ResultType")]
public TakeStockType ResultType { get; set; } = TakeStockType.Profit;
///
/// 备注
///
[Column("FailRemark")]
public string FailRemark { get; set; }
///
/// 同步到金蝶后金蝶的单据Id
///
[Column("ErpSyncBillNo")]
public string ErpSyncBillNo { get; set; }
///
/// 明细
///
public List Details { get; set; } = new List();
///
/// 创建
///
///
public void Create(int creatorId, TakeStockType resultType)
{
this.ResultType = resultType;
this.CreatorId = creatorId;
this.Date = DateTime.Now;
}
///
/// 同步金蝶结果
///
///
///
public void Sync(bool isSuccess, string remark, SyncStatus syncStatus,string erpBillNo)
{
this.SuccessSync = syncStatus;
this.FailRemark = remark;
this.ErpSyncBillNo = erpBillNo;
}
///
/// 重传
///
public void RepeatSync()
{
//只有完全失败的情况下才能重传
if (this.SuccessSync != SyncStatus.Fail) return;
this.SuccessSync = SyncStatus.SyncIng;
this.FailRemark = "";
}
///
/// 生成单据号
///
public void GenerateNo()
{
//用户手动输入了 就不自动生成了
if (!string.IsNullOrEmpty(this.BillNo)) return;
if (this.Id.ToString().Length >= 8)
{
this.BillNo = "PD" + this.Id.ToString();
return;
}
string idStr = this.Id.ToString();
while (true)
{
idStr = "0" + idStr;
if (idStr.Length >= 8) break;
}
this.BillNo = "PD" + idStr;
}
}
}