Administrator
2024-06-18 225cb66b7d1f86a56edad2eac37e9aff57106031
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using Model.InterFaceModel;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using WMS.DAL;
using WMS.Entity.BllAsnEntity;
using WMS.Entity.Context;
using WMS.IBLL.IBllTransServer;
 
namespace WMS.BLL.BllTransServer
{
    public class NoticeServer : DbHelper<BllArrivalNotice>, INoticeServer
    {
        private static readonly SqlSugarScope Db = DataContext.Db;
        public NoticeServer() : base(Db)
        {
        }
 
        public ErpModel CreateAsn(AsnInfo model)
        {
            try
            {
                var resultModel = new ErpModel() { Success = -1, Message = "" };
                if (string.IsNullOrEmpty(model.OrderCode))
                {
                    resultModel.Message = "上游系统单号不可为空!";
                    return resultModel;
                }
                if (model.AsnDetails.Count <= 0)
                {
                    resultModel.Message = "入库单明细不可为空!";
                    return resultModel;
                }
 
                // 入库总表信息
                string asnNo = new Common().GetMaxNo("ASN");
                var asnModel = new BllArrivalNotice()
                {
                    ASNNo = asnNo,
                    Status = "0",//等待执行
                    Type = "0",//原料入库
                    Origin = string.IsNullOrEmpty(model.Origin) ? "MES" : model.Origin,
                    CustomerNo = model.Customer,
                    CustomerName = "",
                    OrderCode = model.OrderCode,
                };
 
                // 入库明细表信息
                List<BllArrivalNoticeDetail> detailModels = new List<BllArrivalNoticeDetail>();
                foreach (AsnDetail asnDetailModel in model.AsnDetails)
                {
                    if (string.IsNullOrEmpty(asnDetailModel.SkuNo))
                    {
                        resultModel.Message = "物料编码不可为空!";
                        return resultModel;
                    }
                    if (string.IsNullOrEmpty(asnDetailModel.SkuName))
                    {
                        resultModel.Message = "物料名称不可为空!";
                        return resultModel;
                    }
                    if (asnDetailModel.Qty <= 0)
                    {
                        resultModel.Message = "数量应大于0!";
                        return resultModel;
                    }
                    if (string.IsNullOrEmpty(asnDetailModel.LotNo))
                    {
                        resultModel.Message = "批次号不可为空!";
                        return resultModel;
                    }
                    var detailModel = new BllArrivalNoticeDetail()
                    {
                        ASNNo = asnNo,
                        OrderDetailCode = asnDetailModel.OrderDetailCode,
                        SkuNo = asnDetailModel.SkuNo,
                        SkuName = asnDetailModel.SkuName,
                        LotNo = asnDetailModel.LotNo,
                        LotText = "",
                        Qty = (decimal)asnDetailModel.Qty,
                        FactQty = 0,
                        CompleteQty = 0,
                        SupplierLot = asnDetailModel.SupplierLot,
                        Status = "0",
                        IsSampling = "0",
                        InspectStatus = "0",
                        CreateUser = 0
                    };
                    detailModels.Add(detailModel);
                }
 
                Db.BeginTran();
                // 插入入库单总表
                Db.Insertable(asnModel).ExecuteCommand();
 
                // 插入入库单明细表
                Db.Insertable(detailModels).ExecuteCommand();
                Db.CommitTran();
 
                resultModel.Success = 0;
                resultModel.Message = "成功";
                return resultModel;
            }
            catch (Exception ex)
            {
                Db.RollbackTran();
                throw ex;
            }
        }
    }
}