using System; using System.Collections.Generic; using System.Linq; using CK.SCP.Models; using CK.SCP.Models.Enums; using CK.SCP.Models.ScpEntity; using CK.SCP.Models.UniApiEntity; namespace CK.SCP.Controller { public static class UniApiController { public static void RemoveList(ScpEntities db, List uniApiList) { db.TS_UNI_API.RemoveRange(uniApiList); } public static void AddHisList(ScpEntities db, List uniApiHisList) { db.TS_UNI_API_HIS.AddRange(uniApiHisList); } public static void AddApiData(ScpEntities wdb, TS_UNI_API apiData) { wdb.TS_UNI_API.Add(apiData); } public static void AddApiDataList(ScpEntities wdb, List apiDataList) { wdb.TS_UNI_API.AddRange(apiDataList); } public static WmsTableName GetTableName(UniApiType uniApiType) { WmsTableName tableName; switch (uniApiType) { case UniApiType.PO: tableName = WmsTableName.TS_UNI_API;//中间表的名字 break; case UniApiType.Receive: tableName = WmsTableName.TS_UNI_API; break; case UniApiType.BarCode: tableName = WmsTableName.TS_UNI_API; break; case UniApiType.Invoice: tableName = WmsTableName.TS_UNI_API; break; default: throw new ArgumentOutOfRangeException(nameof(uniApiType), uniApiType, null); } return tableName; } //创建采购订单 public static TS_UNI_API CreateBy(TB_PO bill, TB_PO_DETAIL detail, UniApiType uniApiType) { var tableName = GetTableName(uniApiType); var apiData = new TS_UNI_API { InterfaceType = uniApiType.ToString(), TableName = tableName.ToString(), BillNum = bill.PoBillNum, PartCode = detail.PartCode, Batch = "", Qty = detail.PlanQty, PoUnit = detail.PoUnit, LocUnit = detail.LocUnit, State = detail.State, CreateOper = bill.CreateUser, CreateTime = bill.CreateTime, PutTime = ScpCache.GetServerTime(), VendId = bill.VendId, BillType = (int)BillType.PuchaseOrder, SubBillType = 0, ValidDate = (DateTime)detail.EndTime, ErpBillNum = bill.ErpBillNum, ErpLineNum = int.Parse(detail.PoBillNum), VendBatch = "", SourceBillNum = "", Price = detail.Price, PackQty = detail.PackQty, Currency = detail.Currency, Attn = "",//TODO Buyer = bill.Buyer, BuyerPhone = bill.BuyerPhone, ModType = bill.ModType.ToString(), Receiver = "",//TODO UmConv = (decimal)detail.UnConv, }; return apiData; } private static ScpEntities db = EntitiesFactory.CreateScpInstance(); public static TS_UNI_API CreateBy(TB_PO bill, List detail, UniApiType uniApiType) { var tableName = GetTableName(uniApiType); TS_UNI_API asp = new TS_UNI_API(); foreach (var item in detail) { asp.InterfaceType = uniApiType.ToString(); asp.TableName = tableName.ToString(); asp.BillNum = bill.PoBillNum; asp.Batch = string.Empty; asp.CreateOper = bill.CreateUser; asp.CreateTime = bill.CreateTime; asp.PutTime = ScpCache.GetServerTime(); asp.VendId = bill.VendId; asp.BillType = (int)BillType.PO; asp.SubBillType = 0; asp.VendBatch = string.Empty; asp.SourceBillNum = string.Empty; asp.Attn = "";//TODO asp.Buyer = bill.Buyer; asp.BuyerPhone = bill.BuyerPhone; asp.ModType = bill.ModType.ToString(); asp.Receiver = "";//TODO asp.PartCode = item.PartCode; asp.Qty = item.PlanQty; asp.PoUnit = item.PoUnit; asp.LocUnit = item.LocUnit; asp.State = item.State; asp.ValidDate = (DateTime)item.EndTime; asp.ErpBillNum = bill.ErpBillNum;//暂时跟billnum 一样 后期可能会改 预留 asp.ErpLineNum = item.PoLine; asp.Price = item.Price; asp.PackQty = item.PackQty; asp.Currency = item.Currency; asp.UmConv = (decimal)item.UnConv; db.TS_UNI_API.Add(asp); db.SaveChanges(); } return asp; } //创建发货单 public static TS_UNI_API CreateBy(V_TB_ASN bill, V_TB_ASN_DETAIL detail, UniApiType uniApiType) { var tableName = GetTableName(uniApiType); var apiData = new TS_UNI_API(); apiData.InterfaceType = uniApiType.ToString(); apiData.TableName = tableName.ToString(); apiData.BillNum = bill.AsnBillNum; apiData.PartCode = detail.PartCode; apiData.Batch = detail.Batch; apiData.Qty = detail.Qty; apiData.PoUnit = detail.PoUnit; apiData.LocUnit = detail.LocUnit; apiData.State = (int)detail.State; apiData.CreateOper = bill.CreateUser; apiData.CreateTime = bill.CreateTime; apiData.PutTime = ScpCache.GetServerTime(); apiData.VendId = bill.VendId; apiData.BillType = (int)BillType.PuchaseOrder; apiData.SubBillType = 0; apiData.ValidDate = (DateTime)detail.ProduceDate; apiData.ErpBillNum = bill.PoBillNum; apiData.ErpLineNum = detail.PoLine; if (bill.Site == "BJCIAI") { apiData.VendBatch = detail.Batch; } else { apiData.VendBatch = detail.VendBatch; } apiData.Price = detail.Price; apiData.PackQty = detail.PackQty; apiData.Currency = detail.Currency; apiData.UmConv = (decimal) detail.UnConv; apiData.Buyer = bill.Buyer; apiData.BuyerPhone = bill.BuyerPhone; apiData.Domain = bill.Site; apiData.Site = !string.IsNullOrEmpty(bill.Remark)? bill.Remark:bill.Site; return apiData; } //创建条码 public static TS_UNI_API CreateBy(TB_ASN bill, TS_BARCODE detail, UniApiType uniApiType) { var tableName = GetTableName(uniApiType); var apiData = new TS_UNI_API(); apiData.Barcode = detail.BarCode; apiData.InterfaceType = uniApiType.ToString(); apiData.TableName = tableName.ToString(); apiData.BillNum = bill.AsnBillNum; apiData.PartCode = detail.PartCode; apiData.Batch = detail.Batch; apiData.Qty = detail.Qty; apiData.PoUnit = detail.PoUnit; apiData.LocUnit = detail.LocUnit; apiData.State = detail.State; apiData.CreateOper = bill.CreateUser; apiData.CreateTime = bill.CreateTime; apiData.PutTime = ScpCache.GetServerTime(); apiData.VendId = bill.VendId; apiData.BillType = (int)BillType.PuchaseOrder; apiData.SubBillType = 0; apiData.ValidDate = detail.ProduceDate; apiData.ErpBillNum = bill.PoBillNum; apiData.ErpLineNum = detail.PoBillLine; apiData.VendBatch = detail.VendBatch; apiData.SourceBillNum = bill.AsnBillNum; apiData.Domain = bill.Site; if(bill.Site=="") apiData.Site = bill.Remark; //detail.FullBarCode; apiData.PackQty = detail.PackQty; return apiData; } //创建发票 public static TS_UNI_API CreateBy(V_TB_INVOICE bill, V_TB_INVOICE_DETAIL detail, UniApiType uniApiType) { var tableName = GetTableName(uniApiType); var apiData = new TS_UNI_API { InterfaceType = uniApiType.ToString(), TableName = tableName.ToString(), BillNum = bill.InvcBillNum, PartCode = detail.PartCode, Batch = "", Qty = detail.Qty, PoUnit = detail.PoUnit, LocUnit = detail.PoUnit, State = (int)detail.State, CreateOper = bill.CreateUser, CreateTime = (DateTime)bill.CreateTime, PutTime = ScpCache.GetServerTime(), VendId = bill.VendId, BillType = (int)BillType.PuchaseOrder, SubBillType = 0, ValidDate = DateTime.Now,//暂时添上 ErpBillNum = detail.PoBillNum, ErpLineNum = detail.PoLineNum, VendBatch = detail.ProjectId, SourceBillNum = detail.AsnBillNum, Price = detail.Price, PackQty = (decimal)detail.PackQty, Currency = detail.Currency, Invoice = bill.InvoiceNum, Receiver = detail.ErpRecvBillNum, Tax = (decimal)bill.Tax, TaxAmt = (decimal)(detail.Price * bill.Tax), Domain = bill.Site, Site = bill.Site, Attn = Utils.JsonHelper.GetJson(bill) }; return apiData; } public static List GetNewInterfaceList(ScpEntities wdb) { return wdb.TS_UNI_API.Where(p => p.State == (int)BillState.New).OrderBy(p => p.UID).ToList(); } } }