You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
253 lines
9.1 KiB
253 lines
9.1 KiB
1 year ago
|
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<TS_UNI_API> uniApiList)
|
||
|
{
|
||
|
db.TS_UNI_API.RemoveRange(uniApiList);
|
||
|
}
|
||
|
public static void AddHisList(ScpEntities db, List<TS_UNI_API_HIS> 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<TS_UNI_API> 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(TF_PO bill, TF_PO_DETAIL detail, UniApiType uniApiType)
|
||
|
{
|
||
|
var tableName = GetTableName(uniApiType);
|
||
|
var apiData = new TS_UNI_API
|
||
|
{
|
||
|
InterfaceType = uniApiType.ToString(),
|
||
|
TableName = tableName.ToString(),
|
||
|
BillNum = bill.BillNum,
|
||
|
PartCode = detail.PartCode,
|
||
|
Batch = "",
|
||
|
Qty = detail.BillQty,
|
||
|
PoUnit = detail.PoUnit,
|
||
|
LocUnit = detail.LocUnit,
|
||
|
State = detail.State,
|
||
|
CreateOper = bill.OperName,
|
||
|
CreateTime = bill.BillTime,
|
||
|
PutTime = ScpCache.GetServerTime(),
|
||
|
VendId = bill.VendId,
|
||
|
BillType = (int)BillType.PuchaseOrder,
|
||
|
SubBillType = 0,
|
||
|
ValidDate = detail.DueDate,
|
||
|
ErpBillNum = bill.ErpBillNum,
|
||
|
ErpLineNum = detail.ErpLineNum,
|
||
|
VendBatch = "",
|
||
|
SourceBillNum = "",
|
||
|
Price = detail.Price,
|
||
|
PackQty = detail.PackQty,
|
||
|
Currency = detail.Currency,
|
||
|
Attn = "",//TODO
|
||
|
Buyer = bill.Buyer,
|
||
|
BuyerPhone = bill.BuyerPhone,
|
||
|
ModType = bill.ModType,
|
||
|
Receiver = "",//TODO
|
||
|
UmConv = (decimal)detail.UmConv,
|
||
|
};
|
||
|
return apiData;
|
||
|
}
|
||
|
|
||
|
private static ScpEntities db = EntitiesFactory.CreateScpInstance();
|
||
|
public static TS_UNI_API CreateBy(TF_PO bill, List<TF_PO_DETAIL> 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.BillNum;
|
||
|
asp.Batch = string.Empty;
|
||
|
asp.CreateOper = bill.OperName;
|
||
|
asp.CreateTime = bill.BillTime;
|
||
|
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;
|
||
|
asp.Receiver = "";//TODO
|
||
|
asp.PartCode = item.PartCode;
|
||
|
|
||
|
asp.Qty = item.BillQty;
|
||
|
asp.PoUnit = item.PoUnit;
|
||
|
asp.LocUnit = item.LocUnit;
|
||
|
asp.State = item.State;
|
||
|
|
||
|
asp.ValidDate = item.DueDate;
|
||
|
asp.ErpBillNum = bill.BillNum;//暂时跟billnum 一样 后期可能会改 预留
|
||
|
asp.ErpLineNum = item.ErpLineNum;
|
||
|
|
||
|
asp.Price = item.Price;
|
||
|
asp.PackQty = item.PackQty;
|
||
|
asp.Currency = item.Currency;
|
||
|
|
||
|
asp.UmConv = (decimal)item.UmConv;
|
||
|
|
||
|
db.TS_UNI_API.Add(asp);
|
||
|
db.SaveChanges();
|
||
|
}
|
||
|
|
||
|
return asp;
|
||
|
}
|
||
|
|
||
|
//创建发货单
|
||
|
public static TS_UNI_API CreateBy(TF_ASN bill, TF_ASN_DETAIL detail, UniApiType uniApiType)
|
||
|
{
|
||
|
var tableName = GetTableName(uniApiType);
|
||
|
var apiData = new TS_UNI_API
|
||
|
{
|
||
|
InterfaceType = uniApiType.ToString(),
|
||
|
TableName = tableName.ToString(),
|
||
|
BillNum = bill.BillNum,
|
||
|
PartCode = detail.PartCode,
|
||
|
Batch = detail.Batch,
|
||
|
Qty = detail.BillQty,
|
||
|
PoUnit = detail.PoUnit,
|
||
|
LocUnit = detail.LocUnit,
|
||
|
State = detail.State,
|
||
|
CreateOper = bill.OperName,
|
||
|
CreateTime = bill.BillTime,
|
||
|
PutTime = ScpCache.GetServerTime(),
|
||
|
VendId = bill.VendId,
|
||
|
BillType = (int)BillType.PuchaseOrder,
|
||
|
SubBillType = 0,
|
||
|
ValidDate = detail.ProduceDate,
|
||
|
ErpBillNum = bill.PoBillNum,
|
||
|
ErpLineNum = detail.PoLineNum,
|
||
|
VendBatch = detail.VendBatch,
|
||
|
Price = detail.Price,
|
||
|
PackQty = detail.PackQty,
|
||
|
Currency = detail.Currency,
|
||
|
UmConv = (decimal) detail.UmConv,
|
||
|
};
|
||
|
return apiData;
|
||
|
}
|
||
|
|
||
|
//创建条码
|
||
|
public static TS_UNI_API CreateBy(TF_ASN bill, TS_BARCODE detail, UniApiType uniApiType)
|
||
|
{
|
||
|
var tableName = GetTableName(uniApiType);
|
||
|
var apiData = new TS_UNI_API
|
||
|
{
|
||
|
Barcode = detail.BarCode,
|
||
|
InterfaceType = uniApiType.ToString(),
|
||
|
TableName = tableName.ToString(),
|
||
|
BillNum = bill.BillNum,
|
||
|
PartCode = detail.PartCode,
|
||
|
Batch = detail.Batch,
|
||
|
Qty = detail.Qty,
|
||
|
PoUnit = detail.PoUnit,
|
||
|
LocUnit = detail.LocUnit,
|
||
|
State = detail.State,
|
||
|
CreateOper = bill.OperName,
|
||
|
CreateTime = bill.BillTime,
|
||
|
PutTime = ScpCache.GetServerTime(),
|
||
|
VendId = bill.VendId,
|
||
|
BillType = (int)BillType.PuchaseOrder,
|
||
|
SubBillType = 0,
|
||
|
ValidDate = detail.ProduceDate,
|
||
|
ErpBillNum = bill.PoBillNum,
|
||
|
ErpLineNum = detail.PoBillLine,
|
||
|
VendBatch = detail.VendBatch,
|
||
|
SourceBillNum = detail.FullBarCode,
|
||
|
PackQty = detail.PackQty,
|
||
|
};
|
||
|
return apiData;
|
||
|
}
|
||
|
|
||
|
//创建发票
|
||
|
public static TS_UNI_API CreateBy(TB_INVOICE bill, TB_INVOICE_DETAIL detail, UniApiType uniApiType)
|
||
|
{
|
||
|
var tableName = GetTableName(uniApiType);
|
||
|
var apiData = new TS_UNI_API
|
||
|
{
|
||
|
InterfaceType = uniApiType.ToString(),
|
||
|
TableName = tableName.ToString(),
|
||
|
BillNum = bill.BillNum,
|
||
|
PartCode = detail.PartCode,
|
||
|
Batch = "",
|
||
|
Qty = detail.Qty,
|
||
|
PoUnit = detail.PoUnit,
|
||
|
LocUnit = detail.LocUnit,
|
||
|
State = detail.State,
|
||
|
CreateOper = bill.OperName,
|
||
|
CreateTime = bill.BillTime,
|
||
|
PutTime = ScpCache.GetServerTime(),
|
||
|
VendId = bill.VendId,
|
||
|
BillType = (int)BillType.PuchaseOrder,
|
||
|
SubBillType = 0,
|
||
|
ValidDate = detail.ProduceDate,
|
||
|
ErpBillNum = detail.PoBillNum,
|
||
|
ErpLineNum = detail.PoLineNum,
|
||
|
VendBatch = "",
|
||
|
SourceBillNum = "",
|
||
|
Price = detail.Price,
|
||
|
PackQty = detail.PackQty,
|
||
|
Currency = detail.Currency,
|
||
|
Invoice = bill.InvoiceNum,
|
||
|
Tax = detail.Tax,
|
||
|
TaxAmt = detail.TaxAmt,
|
||
|
};
|
||
|
return apiData;
|
||
|
}
|
||
|
|
||
|
public static List<TS_UNI_API> GetNewInterfaceList(ScpEntities wdb)
|
||
|
{
|
||
|
return wdb.TS_UNI_API.Where(p => p.State == (int)BillState.New).OrderBy(p => p.UID).ToList();
|
||
|
}
|
||
|
}
|
||
|
}
|