192 lines
6.3 KiB
C#
192 lines
6.3 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>
|
|
/// wms出库单
|
|
/// </summary>
|
|
[Serializable]
|
|
[Table("t_wms_outstock")]
|
|
public class OutStock : EntityBase
|
|
{
|
|
public OutStock() { }
|
|
/// <summary>
|
|
/// 主键 订单编号
|
|
/// </summary>
|
|
[Column("Id")]
|
|
public override int Id { get; set; }
|
|
/// <summary>
|
|
/// 任务单ID
|
|
/// </summary>
|
|
[Column("TaskId")]
|
|
public int TaskId { get; set; }
|
|
/// <summary>
|
|
/// 单据编号
|
|
/// </summary>
|
|
[Column("BillNo")]
|
|
public string BillNo { get; set; }
|
|
/// <summary>
|
|
/// 出库方式 1 按箱 2 按产品
|
|
/// </summary>
|
|
[Column("Method")]
|
|
public InventoryInOutMethod Method { get; set; } = InventoryInOutMethod.Box;
|
|
/// <summary>
|
|
/// 单据类型
|
|
/// </summary>
|
|
[Column("Type")]
|
|
public OutStockType Type { get; set; } = OutStockType.Sal;
|
|
/// <summary>
|
|
/// 发货组织
|
|
///</summary>
|
|
[Column("DeliveryOrgId")]
|
|
public int DeliveryOrgId { get; set; }
|
|
/// <summary>
|
|
/// 组织编码
|
|
///</summary>
|
|
[Column("OrgCode")]
|
|
public string OrgCode { get; set; }
|
|
/// <summary>
|
|
/// 收货客户
|
|
///</summary>
|
|
[Column("ReceiptCustomerId")]
|
|
public int ReceiptCustomerId { get; set; }
|
|
/// <summary>
|
|
/// 仓库
|
|
///</summary>
|
|
[Column("StockCode")]
|
|
public string StockCode { get; set; }
|
|
/// <summary>
|
|
/// 创建人
|
|
/// </summary>
|
|
[Column("CreatorId")]
|
|
public int CreatorId { get; set; }
|
|
/// <summary>
|
|
/// 操作人
|
|
/// </summary>
|
|
[Column("OperateId")]
|
|
public int OperateId { get; set; }
|
|
/// <summary>
|
|
/// 创建时间(出库时间)
|
|
/// </summary>
|
|
[Column("CreateTime")]
|
|
public DateTime CreateTime { get; set; } = DateTime.Now;
|
|
/// <summary>
|
|
/// 同步成功或者失败 默认是失败状态
|
|
/// </summary>
|
|
[Column("SuccessSync")]
|
|
public SyncStatus SuccessSync { get; set; } = SyncStatus.Fail;
|
|
///// <summary>
|
|
///// 同步失败的源订单号(默认就包含所有来源单号)
|
|
///// </summary>
|
|
//[Column("SuccessSyncFail")]
|
|
//public List<int> SuccessSyncFail { get; set; } = new List<int>();
|
|
/// <summary>
|
|
/// 同步时间
|
|
/// </summary>
|
|
[Column("SyncTime")]
|
|
public DateTime? SyncTime { get; set; }
|
|
/// <summary>
|
|
/// 备注
|
|
/// </summary>
|
|
[Column("Remark")]
|
|
public string Remark { get; set; }
|
|
/// <summary>
|
|
/// 明细
|
|
/// </summary>
|
|
public List<OutStockDetails> Details { get; set; } = new List<OutStockDetails>();
|
|
/// <summary>
|
|
/// 创建(需要在明细都生成后最后调用)
|
|
/// </summary>
|
|
/// <param name="creatorId"></param>
|
|
public void Create(int creatorId, OutStockTask task, int method)
|
|
{
|
|
this.TaskId = task.Id;
|
|
this.Type = task.Type;
|
|
this.Method = (InventoryInOutMethod)method;
|
|
this.DeliveryOrgId = task.DeliveryOrgId;
|
|
this.ReceiptCustomerId = task.ReceiptCustomerId;
|
|
this.OrgCode = task.OrgCode;
|
|
this.StockCode = task.StockCode;
|
|
this.CreatorId = creatorId;
|
|
this.CreateTime = DateTime.Now;
|
|
if (task.Type == OutStockType.Sal)
|
|
{
|
|
//只有销售出库才需要同步金蝶
|
|
this.SuccessSync = SyncStatus.Fail;
|
|
var erpd = this.Details.SelectMany(s => s.ErpDetails).ToList();
|
|
erpd.ForEach(f => f.SuccessSync = SyncStatus.Fail);
|
|
}
|
|
else
|
|
{
|
|
this.SuccessSync = SyncStatus.Success;
|
|
var erpd = this.Details.SelectMany(s => s.ErpDetails).ToList();
|
|
erpd.ForEach(f => f.SuccessSync = SyncStatus.Success);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 同步金蝶(成功)
|
|
/// </summary>
|
|
/// <param name="operateId"></param>
|
|
public void SyncSuccess(string sourcBillNo, int operateId,string erpBillNo)
|
|
{
|
|
//foreach (var e in erpDetailIds)
|
|
// this.SuccessSyncFail.Remove(e);
|
|
var erpd = this.Details.SelectMany(s => s.ErpDetails).Where(w => w.SourceBillNo.Equals(sourcBillNo)).ToList();
|
|
foreach (var e in erpd)
|
|
{
|
|
e.SuccessSync = SyncStatus.Success;
|
|
e.ErpSyncBillNo = erpBillNo;
|
|
}
|
|
//所有erp明细同步成功才是整个单据成功
|
|
var erpDetails = this.Details.SelectMany(s => s.ErpDetails);
|
|
if (erpDetails.Where(w => w.SuccessSync == SyncStatus.Success).Count()== erpDetails.Count())
|
|
{
|
|
this.SuccessSync = SyncStatus.Success;
|
|
this.Remark = "";
|
|
}
|
|
this.OperateId = operateId;
|
|
this.SyncTime = DateTime.Now;
|
|
}
|
|
/// <summary>
|
|
/// 同步金蝶(失败)
|
|
/// </summary>
|
|
/// <param name="operateId"></param>
|
|
public void SyncFail(string remark, int operateId, SyncStatus syncStatus)
|
|
{
|
|
this.SuccessSync = syncStatus;
|
|
this.Remark = remark;
|
|
this.OperateId = operateId;
|
|
this.SyncTime = DateTime.Now;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 生成单据号
|
|
/// </summary>
|
|
public void GenerateNo()
|
|
{
|
|
//用户手动输入了 就不自动生成了
|
|
if (!string.IsNullOrEmpty(this.BillNo)) return;
|
|
|
|
if (this.Id.ToString().Length >= 8)
|
|
{
|
|
this.BillNo = "CK" + this.Id.ToString();
|
|
return;
|
|
}
|
|
|
|
string idStr = this.Id.ToString();
|
|
while (true)
|
|
{
|
|
idStr = "0" + idStr;
|
|
if (idStr.Length >= 8) break;
|
|
}
|
|
this.BillNo = "CK" + idStr;
|
|
}
|
|
}
|
|
}
|