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.
 
 
 
 
 

985 lines
50 KiB

using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using CK.SCP.Models;
using CK.SCP.Models.Enums;
using CK.SCP.Models.ScpEntity;
using CK.SCP.Models.UniApiEntity;
using CK.SCP.Utils;
using System.Text;
using System.Data.Entity.Core;
using CK.SCP.Models.ScpEntity.ExcelExportEnttity;
namespace CK.SCP.GrupUniApi.Controller
{
public static class OdbcApiWmsController
{
public static void GetNewCtrlList()
{
UniApiEntities idb = EntitiesFactory.CreateUniApiInstance();
idb.Database.CommandTimeout = 60 * 20;
var tableNameList = EnumHelper.EnumToList<WmsTableName>();
List<string> _lst = new List<string>();
_lst.Add("xxwms_rc_det");
_lst.Add("xxwms_rt_det");
_lst.Add("xxwms_arv_det");
_lst.Add("xxwms_qua_det");
_lst.Add("xxwms_review_det");
var wmsCtrlList = idb.xxwms_ctrl.Where(p => p.xxwms_scm == "0" && _lst.Contains(p.xxwms_table)).ToList();
// var wmsCtrlList = idb.xxwms_ctrl.Where(p => p.xxwms_wms == "0").ToList();
//删除scp所有原料库存数据
if (GlobalVar.ApiConfig.Wms库存)
{
ScpEntities wdb = EntitiesFactory.CreateScpInstance();
var kucunlist = wmsCtrlList.Where(p => p.xxwms_table == "xxwms_ld_det").ToList();
//如果有库存数据
if (kucunlist.Count > 0)
{
var _stockList = wdb.TS_STOCK.ToList();
wdb.TS_STOCK.RemoveRange(_stockList);
//EntitiesFactory.SaveDb(wdb);
//取最近日期的流水号
xxwms_ctrl ctrl = idb.xxwms_ctrl.Where(p => p.xxwms_table == "xxwms_ld_det").OrderByDescending(p => p.xxwms_seq).FirstOrDefault();
if (ctrl != null && !string.IsNullOrEmpty(ctrl.xxwms_seq))
{
Console.WriteLine($"发现 WMS 接口数据:{ctrl.xxwms_table}:{ctrl.xxwms_table_qty}");
UpdateMaterialStocks(idb, wdb, ctrl.xxwms_seq);
EntitiesFactory.SaveDb(wdb);
}
}
}
Console.WriteLine($"调用WMS 接口数据:{wmsCtrlList.Count.ToString()}");
foreach (var wmsCtrl in wmsCtrlList)
{
if (tableNameList.All(p => p.Name != wmsCtrl.xxwms_table)) continue;
try
{
ScpEntities wdb = EntitiesFactory.CreateScpInstance();
//Console.WriteLine($"发现 WMS 接口数据:{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
WmsTableName wmsTableName;
Enum.TryParse(wmsCtrl.xxwms_table, false, out wmsTableName);
switch (wmsTableName)
{
case WmsTableName.xxwms_ld_det://原料库存
if (GlobalVar.ApiConfig.Wms库存)
{
//Console.WriteLine($"发现 WMS 接口数据:{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
//UpdateMaterialStocks(idb, wdb, wmsCtrl.xxwms_seq);
}
else
continue;
break;
case WmsTableName.xxwms_rc_det://接收收货单
//TODO
if (GlobalVar.ApiConfig.Wms收货单)
{
Console.WriteLine($"发现 WMS 接口数据:{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
AddMaterialReceive(idb, wdb, wmsCtrl.xxwms_seq, 0);//xxwms_seq:流水号
AddMaterialReturn_RC(idb, wdb, wmsCtrl.xxwms_seq, 1);//xxwms_seq:流水号
}
break;
case WmsTableName.xxwms_rt_det:
//TODO
if (GlobalVar.ApiConfig.Wms退货单)
{
Console.WriteLine($"发现 WMS 接口数据:{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
AddMaterialReturn(idb, wdb, wmsCtrl.xxwms_seq, 1);//xxwms_seq:流水号
}
break;
case WmsTableName.xxwms_arv_det:
//TODO
if (GlobalVar.ApiConfig.Wms到货单)
{
Console.WriteLine($"发现 WMS 接口数据:{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
AddMaterialArrive(idb, wdb, wmsCtrl.xxwms_seq);//xxwms_seq:流水号
}
break;
case WmsTableName.xxwms_qua_det:
//TODO
if (GlobalVar.ApiConfig.Wms库存质量)
{
Console.WriteLine($"发现 WMS 接口数据:{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
AddMaterialQuality(idb, wdb, wmsCtrl.xxwms_seq);
}
break;
case WmsTableName.xxwms_review_det:
//TODO
if (GlobalVar.ApiConfig.Wms评审单)
{
Console.WriteLine($"发现 WMS 接口数据:{wmsCtrl.xxwms_table}:{wmsCtrl.xxwms_table_qty}");
AddReview(idb, wdb, wmsCtrl.xxwms_seq);
}
break;
}
wmsCtrl.xxwms_scm = ((int)UniApiState.).ToString();
EntitiesFactory.SaveDb(wdb);
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
{
var sb = new StringBuilder();
foreach (var error in dbEx.EntityValidationErrors.ToList())
{
error.ValidationErrors.ToList().ForEach(i =>
{
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage);
});
}
wmsCtrl.xxwms_scm = ((int)UniApiState.).ToString();
wmsCtrl.xxwms_rmks += " SCM:" + sb.ToString();
}
catch (OptimisticConcurrencyException ex)//并发冲突异常
{
wmsCtrl.xxwms_scm = ((int)UniApiState.).ToString();
wmsCtrl.xxwms_rmks += " SCM:" + ex.Message;
}
catch (Exception ex)
{
wmsCtrl.xxwms_scm = ((int)UniApiState.).ToString();
wmsCtrl.xxwms_rmks += " SCM:" + ex.Message;
}
finally
{
EntitiesFactory.SaveDb(idb);
}
}
}
/// <summary>
/// 更新原料库存
/// </summary>
/// <param name="idb"></param>
/// <param name="wdb"></param>
/// <param name="seq"></param>
private static void UpdateMaterialStocks(UniApiEntities idb, ScpEntities wdb, string seq)
{
var wmsld_detList = idb.xxwms_ld_det.Where(p => p.xxwms_ld_seq == seq).ToList();
var scpRcvList = new List<TS_STOCK>();
foreach (var wmsld_detData in wmsld_detList)
{
var scpRcv = new TS_STOCK
{
BarCode = wmsld_detData.xxwms_ld_barcode,//标签号
Site = wmsld_detData.xxwms_ld_domain,//工厂
PartCode = wmsld_detData.xxwms_ld_part,//零件号
VendId = wmsld_detData.xxwms_ld_vend,//供应商编号
LocCode = wmsld_detData.xxwms_ld_loc,//库位
Batch = wmsld_detData.xxwms_ld_lot,//批次
VendBatch = wmsld_detData.xxwms_ld_vend_batch,//供应商批次
Qty = wmsld_detData.xxwms_ld_qty,//数量
ReceiveDate = wmsld_detData.xxwms_ld_date,//收货日期
ProduceDate = wmsld_detData.xxwms_ld_time,//生产时间
LocUnit = wmsld_detData.xxwms_ld_um,//单位
Remark = "",//备注
State = (int)FormState.,
CreateTime = wmsld_detData.xxwms_ld_createdt == null ? DateTime.Now : (DateTime)wmsld_detData.xxwms_ld_createdt,//创建日期
CreateUser = wmsld_detData.xxwms_ld_createur//创建用户
};
scpRcvList.Add(scpRcv);
}
wdb.TS_STOCK.AddOrUpdate(scpRcvList.ToArray());
Console.WriteLine($"更新 原料库存 数据:{wmsld_detList.Count}");
}
/// <summary>
///接收收货单
/// </summary>
/// <param name="idb"></param>
/// <param name="wdb"></param>
/// <param name="seq">流水号</param>
/// <param name="billtype">0:收货,1:退货</param>
private static void AddMaterialReceive(UniApiEntities idb, ScpEntities wdb, string seq, int billtype)
{
var qadRcvDetailList = idb.xxwms_rc_det.Where(p => p.xxwms_rc_seq == seq&&p.xxwms_rc_qty_total>=0).ToList();
var scpRcvList = new List<TB_RECEIVE>();
var scpRcveDetailList = new List<TB_RECEIVE_DETAIL>();
//根据xxwms_rc_po_nbr采购单字段去重
var qadReceiveNbrList = qadRcvDetailList.Select(p => p.xxwms_rc_nbr.ToUpper()).DistinctBy(p => p);
foreach (var qadRcvNbrList in qadReceiveNbrList)
{
//qadRcvDetailList同一xxqad_prh_receiver所有记录
var qadDataList = qadRcvDetailList.Where(p => p.xxwms_rc_nbr == qadRcvNbrList ).ToList();
if (qadDataList.Count == 0)
{
continue;
}
var firstqadData = qadDataList[0];
var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.RecvBillNum != null && p.RecvBillNum == qadRcvNbrList && p.Site==firstqadData.xxwms_rc_domain);
//判断0100工厂的收货自动审核是否为允许
bool isRerviceOk = false;
if (!string.IsNullOrEmpty(firstqadData.xxwms_rc_domain))
{
string site = firstqadData.xxwms_rc_domain;//0100
List<TA_FACTORY_CONFIG> configs = wdb.TA_FACTORY_CONFIG.Where(p => p.FactoryId == site).ToList();
foreach (TA_FACTORY_CONFIG cfg in configs)
{
TA_CONFIG tacfg = wdb.TA_CONFIG.Where(p => p.UID == cfg.ConfigId).SingleOrDefault();
if(tacfg != null && !string.IsNullOrEmpty(tacfg.ParamName) && tacfg.ParamName == "收货自动审核")
{
if ("允许" == tacfg.ParamValue)
{
isRerviceOk = true;
}
}
}
}
if (scpRcv == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.;
}
else
{
istate = (int)FormState.;
}
scpRcv = new TB_RECEIVE
{
RecvBillNum = qadRcvNbrList,//收货单号
State = istate,
Remark = "",
CreateTime = firstqadData.xxwms_rc_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxwms_rc_createdt,//创建日期
CreateUser = firstqadData.xxwms_rc_createur,//创建用户
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = billtype
};
scpRcvList.Add(scpRcv);
}
scpRcv.PoBillNum = firstqadData.xxwms_rc_po_nbr;//采购单
scpRcv.AsnBillNum = firstqadData.xxwms_rc_ps_nbr;//发货单号
scpRcv.Site = firstqadData.xxwms_rc_domain;//地点
scpRcv.VendId = firstqadData.xxwms_rc_vend;//供货商名称
scpRcv.ShipTime = firstqadData.xxwms_rc_date_ship;//收货日期
scpRcv.SubSite = !string.IsNullOrEmpty(firstqadData.xxwms_rc_site)? firstqadData.xxwms_rc_site: firstqadData.xxwms_rc_domain;
//var scpAsn = wdb.TF_ASN.FirstOrDefault(p => p.BillNum == scpRcv.AsnBillNum);
var scpAsn = wdb.TB_ASN.Where(p => p.AsnBillNum== scpRcv.AsnBillNum && p.IsDeleted==false).ToList();//发货单主表订单号==收货单主表发货单号
if (scpAsn != null && scpAsn.Count>0)
{
scpAsn.ForEach(p => {
p.State = (int)AsnState.Receive;
});
wdb.TB_ASN.AddOrUpdate(scpAsn.ToArray());
}
var scpAsnDetail = wdb.TB_ASN_DETAIL.Where(p => p.AsnBillNum == scpRcv.AsnBillNum && p.IsDeleted == false).ToList();
if (scpAsnDetail != null && scpAsnDetail.Count > 0)
{
scpAsnDetail.ForEach(p => {
p.State = (int)AsnState.Receive;
});
wdb.TB_ASN_DETAIL.AddOrUpdate(scpAsnDetail.ToArray());
}
foreach (var qadData in qadDataList)
{
try
{
var poLineNum = Convert.ToInt32(qadData.xxwms_rc_po_line);
var scpRcvDetail =
wdb.TB_RECEIVE_DETAIL.SingleOrDefault(
p => p.RecvBillNum == qadRcvNbrList &&
p.PoBillNum == qadData.xxwms_rc_po_nbr &&
p.PoLine == poLineNum &&
p.PartCode == qadData.xxwms_rc_part &&
p.Batch == qadData.xxwms_rc_lot
);
if (scpRcvDetail == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.;
}
else
{
istate = (int)FormState.;
}
scpRcvDetail = new TB_RECEIVE_DETAIL
{
RecvBillNum = qadRcvNbrList,//收货单号
PoBillNum = qadData.xxwms_rc_po_nbr,//采购单
PoLine = poLineNum,//订单行
PartCode = qadData.xxwms_rc_part,//零件号
Batch = qadData.xxwms_rc_lot,//批次
VendBatch = qadData.xxwms_rc_vend_batch,//供应商批号
PoUnit = qadData.xxwms_rc_po_um,//采购单位
LocUnit = qadData.xxwms_rc_loc_um,//基本单位
Qty = qadData.xxwms_rc_qty_total,//收货总量
DockCode = qadData.xxwms_rc_loc,//收货口
State = istate,// (int)FormState.关闭,
Site = firstqadData.xxwms_rc_domain,
SubSite = !string.IsNullOrEmpty(firstqadData.xxwms_rc_site) ? firstqadData.xxwms_rc_site : firstqadData.xxwms_rc_domain,
CreateTime = qadData.xxwms_rc_createdt == null ? DateTime.Now : (DateTime)qadData.xxwms_rc_createdt,//创建日期
CreateUser = qadData.xxwms_rc_createur,//创建用户
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = billtype
};
scpRcveDetailList.Add(scpRcvDetail);
}
//var scpPoDetail =
// wdb.TB_PO_DETAIL.FirstOrDefault(
// p => p.PoBillNum == qadData.xxwms_rc_po_nbr && p.PoLine == poLineNum);
//if (scpPoDetail != null)
//{
// //订单明细ReceivedQty已收数量 += 收货明细Qty已结束量
// scpPoDetail.ReceivedQty += scpRcvDetail.Qty;
//}
//var scpPo = wdb.TB_PO.FirstOrDefault(p => p.ErpBillNum == qadData.xxwms_rc_po_nbr);
//if (scpPo != null)
//{
// //订单明细
// var scpPoDetails = wdb.TB_PO_DETAIL.Where(p => p.PoBillNum == qadData.xxwms_rc_po_nbr);
// //if (scpPoDetails.All(p => p.BillQty == p.ReceivedQty))
// // scpPo.State = (int)PlanState.Complete;
// if (scpPoDetails.All(p => p.PlanQty == p.ReceivedQty))//订货数量==已收数量
// {
// scpPo.State = (int)PlanState.Complete;
// //var _detail = wdb.TB_ASK_DETAIL.Where(p => p.PoBillNum == qadData.xxwms_rc_po_nbr && p.PoLine == poLineNum );
// //if (_detail!=null && _detail.Count() > 0)
// //{
// // var _qty=_detail.Sum(p=>p.AskQty);
// // if(_qty== p.ReceivedQty)
// //}
// }
//}
qadData.xxwms_rc_wmsread = ((int)UniApiState.).ToString();
}
catch (Exception ex)
{
qadData.xxwms_rc_wmsread = ((int)UniApiState.).ToString();
qadData.xxwms_rc_rmks += " SCM:" + ex.Message;
}
qadData.xxwms_rc_updateur = ScpCache.Config.SCP用户名;
qadData.xxwms_rc_updatedt = DateTime.Now;
}
}
wdb.TB_RECEIVE.AddOrUpdate(scpRcvList.ToArray());
wdb.TB_RECEIVE_DETAIL.AddOrUpdate(scpRcveDetailList.ToArray());
Console.WriteLine($"更新 收货单 数据:{qadRcvDetailList.Count}");
}
/// <summary>
/// 接收退货单
/// </summary>
private static void AddMaterialReturn_RC(UniApiEntities idb, ScpEntities wdb, string seq, int billtype)
{
var qadRcvDetailList = idb.xxwms_rc_det.Where(p => p.xxwms_rc_seq == seq && p.xxwms_rc_qty_total < 0).ToList();
var scpRcvList = new List<TB_RECEIVE>();
var scpRcveDetailList = new List<TB_RECEIVE_DETAIL>();
//根据xxqad_prh_receiver字段去重
var qadReceiveNbrList = qadRcvDetailList.Select(p => p.xxwms_rc_nbr.ToUpper()).DistinctBy(p => p);
foreach (var qadRcvNbrList in qadReceiveNbrList)
{
//qadRcvDetailList同一xxqad_prh_receiver所有记录
var qadDataList = qadRcvDetailList.Where(p => p.xxwms_rc_nbr == qadRcvNbrList).ToList();
if (qadDataList.Count == 0)
{
continue;
}
var firstqadData = qadDataList[0];
var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.RecvBillNum == qadRcvNbrList && p.Site == firstqadData.xxwms_rc_domain);
//判断0100工厂的收货自动审核是否为允许
bool isRerviceOk = false;
if (!string.IsNullOrEmpty(firstqadData.xxwms_rc_domain))
{
string site = firstqadData.xxwms_rc_domain;//0100
List<TA_FACTORY_CONFIG> configs = wdb.TA_FACTORY_CONFIG.Where(p => p.FactoryId == site).ToList();
foreach (TA_FACTORY_CONFIG cfg in configs)
{
TA_CONFIG tacfg = wdb.TA_CONFIG.Where(p => p.UID == cfg.ConfigId).SingleOrDefault();
if (tacfg != null && !string.IsNullOrEmpty(tacfg.ParamName) && tacfg.ParamName == "收货自动审核")
{
if ("允许" == tacfg.ParamValue)
{
isRerviceOk = true;
}
}
}
}
if (scpRcv == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.;
}
else
{
istate = (int)FormState.;
}
scpRcv = new TB_RECEIVE
{
RecvBillNum = qadRcvNbrList,//退货单号
State = istate,
Remark = "",
Site = firstqadData.xxwms_rc_domain,
CreateTime = firstqadData.xxwms_rc_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxwms_rc_createdt,//创建日期
CreateUser = firstqadData.xxwms_rc_createur,//创建用户
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = billtype
};
scpRcvList.Add(scpRcv);
}
scpRcv.PoBillNum = firstqadData.xxwms_rc_po_nbr;//采购单
//scpRcv.AsnBillNum = firstqadData.xxqad_prh_psnbr;//发货单号
scpRcv.Site = firstqadData.xxwms_rc_domain;//地点
scpRcv.VendId = firstqadData.xxwms_rc_vend;//供货商名称
scpRcv.ShipTime = firstqadData.xxwms_rc_date_ship;//收货日期
scpRcv.SubSite = !string.IsNullOrEmpty(firstqadData.xxwms_rc_site) ? firstqadData.xxwms_rc_site : firstqadData.xxwms_rc_domain;
//var scpAsn = wdb.TF_ASN.FirstOrDefault(p => p.BillNum == scpRcv.AsnBillNum);
var scpAsn = wdb.TB_ASN.FirstOrDefault(p => p.PoBillNum == scpRcv.AsnBillNum);//发货单主表订单号==退货单主表发货单号
if (scpAsn != null)
scpAsn.State = (int)ShipState.Reject;
foreach (var qadData in qadDataList)
{
try
{
var poLineNum = Convert.ToInt32(qadData.xxwms_rc_po_line);
var scpRcvDetail =
wdb.TB_RECEIVE_DETAIL.SingleOrDefault(
p => p.RecvBillNum == qadRcvNbrList &&
p.PoBillNum == qadData.xxwms_rc_po_nbr &&
p.PoLine == poLineNum &&
p.PartCode == qadData.xxwms_rc_part &&
p.Batch == qadData.xxwms_rc_lot);
if (scpRcvDetail == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.;
}
else
{
istate = (int)FormState.;
}
scpRcvDetail = new TB_RECEIVE_DETAIL
{
RecvBillNum = qadRcvNbrList,//退货单号码
PoBillNum = qadData.xxwms_rc_po_nbr,//采购单
PoLine = poLineNum,//订单行
PartCode = qadData.xxwms_rc_part,//物料号
Batch = qadData.xxwms_rc_lot,//批次
VendBatch = qadData.xxwms_rc_vend_batch,//供应商批号
PoUnit = qadData.xxwms_rc_po_um,//采购单位
LocUnit = qadData.xxwms_rc_loc_um,//基本单位
Qty = qadData.xxwms_rc_qty_total,//退货总量
DockCode = qadData.xxwms_rc_loc,//收货口
State = istate,// (int)FormState.关闭,
Site = firstqadData.xxwms_rc_domain,
SubSite = firstqadData.xxwms_rc_site,
CreateTime = qadData.xxwms_rc_createdt == null ? DateTime.Now : (DateTime)qadData.xxwms_rc_createdt,//创建日期
CreateUser = qadData.xxwms_rc_createur,//创建用户
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = billtype
};
scpRcveDetailList.Add(scpRcvDetail);
}
//var scpPoDetail =
// wdb.TB_PO_DETAIL.FirstOrDefault(
// p => p.PoBillNum == qadData.xxwms_rt_po_nbr && p.PoLine == poLineNum);
//if (scpPoDetail != null)
//{
// //订单明细RejectQty已退数量 += 退货明细Qty已结束量
// scpPoDetail.RejectQty -= scpRcvDetail.Qty;
//}
//var scpPo = wdb.TB_PO.FirstOrDefault(p => p.ErpBillNum == qadData.xxwms_rt_po_nbr);
//if (scpPo != null)
//{
// //订单明细
// var scpPoDetails = wdb.TB_PO_DETAIL.Where(p => p.PoBillNum == qadData.xxwms_rt_po_nbr);
// //if (scpPoDetails.All(p => p.BillQty == p.ReceivedQty))
// // scpPo.State = (int)PlanState.Complete;
// if (scpPoDetails.All(p => p.PlanQty == p.ReceivedQty)) //订货数量==已收数量
// scpPo.State = (int)PlanState.Complete;
//}
qadData.xxwms_rc_wmsread = ((int)UniApiState.).ToString();
}
catch (Exception ex)
{
qadData.xxwms_rc_wmsread = ((int)UniApiState.).ToString();
qadData.xxwms_rc_rmks += " SCM:" + ex.Message;
}
qadData.xxwms_rc_updateur = ScpCache.Config.SCP用户名;
qadData.xxwms_rc_updatedt = DateTime.Now;
}
}
wdb.TB_RECEIVE.AddOrUpdate(scpRcvList.ToArray());
wdb.TB_RECEIVE_DETAIL.AddOrUpdate(scpRcveDetailList.ToArray());
Console.WriteLine($"更新 退货单 数据:{qadRcvDetailList.Count}");
}
#region WMS库存质量
private static void AddMaterialQuality(UniApiEntities idb, ScpEntities sdb, string seq)
{
var wms_qualList = idb.xxwms_qua_det.Where(p => p.xxwms_qua_seq == seq).ToList();
if (seq == "QUA_CNS_190219_13553074281")
{
string str = seq;
}
var _qualList = new List<TB_QUALITY>();
foreach (var itm in wms_qualList)
{
var scpQual = new TB_QUALITY();
scpQual.Type = itm.xxwms_qua_infotype;
scpQual.Barcode = itm.xxwms_qua_barcode;
scpQual.Loccode = itm.xxwms_qua_loccode;
scpQual.Pobillnum = itm.xxwms_qua_pobillnum;
scpQual.QualityNo = itm.xxwms_qua_nbr;
scpQual.Poline = (decimal)itm.xxwms_qua_poline;
scpQual.Inspecttype = itm.xxwms_qua_inspecttype;
scpQual.Partcode = itm.xxwms_qua_partcode;
scpQual.Batch = itm.xxwms_qua_batch;
scpQual.ReceiveQty = itm.xxwms_qua_receiveqty;
scpQual.SampleQty = itm.xxwms_qua_sampleqty;
scpQual.Inspqty = itm.xxwms_qua_inspqty;
scpQual.Passqty = itm.xxwms_qua_passqty;
scpQual.Failqty = itm.xxwms_qua_failqty;
scpQual.Crackqty = itm.xxwms_qua_crackqty;
scpQual.Inspresult = itm.xxwms_qua_inspresult;
scpQual.Failreason = itm.xxwms_qua_failreason;
scpQual.Vendid = itm.xxwms_qua_vendid;
scpQual.Vendbatch = itm.xxwms_qua_vendbatch;
scpQual.state = itm.xxwms_qua_state;
scpQual.Billtime = itm.xxwms_qua_billtime;
scpQual.Domain = itm.xxwms_qua_domain;
scpQual.Site = itm.xxwms_qua_domain;
scpQual.By1 = itm.xxwms_qua_by1;
scpQual.By2 = itm.xxwms_qua_by2;
scpQual.By3 = itm.xxwms_qua_by3;
scpQual.CreateTime = itm.xxwms_qua_createdt??DateTime.Now;
scpQual.CreateUser = itm.xxwms_qua_createur;
scpQual.UpdateTime = itm.xxwms_qua_updatedt;
scpQual.UpdateUser = itm.xxwms_qua_updateur;
scpQual.GUID = Guid.NewGuid();
_qualList.Add(scpQual);
sdb.TB_QUALITY.Add(scpQual);
}
//sdb.TB_QUALITY.Add(_qualList.ToArray());
Console.WriteLine($"更新质量库数据:{_qualList.Count}");
}
#endregion
#region pnigshen
private static void AddReview(UniApiEntities idb, ScpEntities sdb, string seq)
{
var wms_qualList = idb.xxwms_review_det.Where(p => p.xxwms_review_seq == seq).ToList();
var _qualList = new List<TM_HYANTOLIN_REVIEW>();
foreach (var itm in wms_qualList)
{
var _entity=sdb.TM_HYANTOLIN_REVIEW.Where(p => p.ReviewBillNum == itm.xxwms_review_nbr && p.Domain == itm.xxwms_review_domain).FirstOrDefault();
if (_entity == null)
{
_entity = new TM_HYANTOLIN_REVIEW();
if (!string.IsNullOrEmpty(itm.xxwms_review_reviewtype))
{
_entity.ReviewType = (EnumReviewType)int.Parse(itm.xxwms_review_reviewtype.ToString());
}
if (!string.IsNullOrEmpty(itm.xxwms_review_reviewsite))
{
_entity.ReviewSite = (EnumReviewSite)int.Parse(itm.xxwms_review_reviewsite.ToString());
}
}
_entity.ReviewBillNum = itm.xxwms_review_nbr;
_entity.RelationReviewNo = itm.xxwms_review_relationnbr;
_entity.BarCode = itm.xxwms_review_barcode;
_entity.PartCode = itm.xxwms_review_partcode;
_entity.Batch = itm.xxwms_review_batch;
_entity.ProjectId = itm.xxwms_review_projectid;
_entity.Qty = itm.xxwms_review_qty;
_entity.BadCouse = itm.xxwms_review_badcouse;
_entity.ReviewResult = itm.xxwms_review_reviewresult;
_entity.UltimateDepart = itm.xxwms_review_ultimatedepart;
_entity.UltimateName = itm.xxwms_review_ultimatename;
_entity.ClaimAmount =itm.xxwms_review_claimamount;
_entity.OperName = itm.xxwms_review_opername;
_entity.BillDate = itm.xxwms_review_billdate;
_entity.CreateTime = itm.xxwms_review_createtime;
_entity.ReviewTime = itm.xxwms_review_reviewtime;
_entity.Domain = itm.xxwms_review_domain;
//var partcode=sdb.V_TB_PO_DETAIL.Where(p => p.Site == _entity.Domain && p.PartCode == _entity.PartCode).FirstOrDefault();
//if (partcode != null)
//{
// _entity.UltimateName = partcode.VendId;
//}
_entity.Guid = Guid.NewGuid();
_qualList.Add(_entity);
//sdb.TB_QUALITY.Add(scpQual);
}
sdb.TM_HYANTOLIN_REVIEW.AddOrUpdate(_qualList.ToArray());
Console.WriteLine($"更新质量库数据:{_qualList.Count}");
}
#endregion
/// <summary>
/// 接收退货单
/// </summary>
private static void AddMaterialReturn(UniApiEntities idb, ScpEntities wdb, string seq, int billtype)
{
//var qadRcvDetailList = idb.xxqad_prh_det.Where(p => p.xxqad_prh_seq == seq).ToList();
var qadRcvDetailList = idb.xxwms_rt_det.Where(p => p.xxwms_rt_seq == seq).ToList();
var scpRcvList = new List<TB_RECEIVE>();
var scpRcveDetailList = new List<TB_RECEIVE_DETAIL>();
//根据xxqad_prh_receiver字段去重
var qadReceiveNbrList = qadRcvDetailList.Select(p => p.xxwms_rt_nbr.ToUpper()).DistinctBy(p => p);
foreach (var qadRcvNbrList in qadReceiveNbrList)
{
//qadRcvDetailList同一xxqad_prh_receiver所有记录
var qadDataList = qadRcvDetailList.Where(p => p.xxwms_rt_nbr == qadRcvNbrList ).ToList();
if (qadDataList.Count == 0)
{
continue;
}
var firstqadData = qadDataList[0];
var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.RecvBillNum == qadRcvNbrList && p.Site ==firstqadData.xxwms_rt_domain);
//判断0100工厂的收货自动审核是否为允许
bool isRerviceOk = false;
if (!string.IsNullOrEmpty(firstqadData.xxwms_rt_domain))
{
string site = firstqadData.xxwms_rt_domain;//0100
List<TA_FACTORY_CONFIG> configs = wdb.TA_FACTORY_CONFIG.Where(p => p.FactoryId == site).ToList();
foreach (TA_FACTORY_CONFIG cfg in configs)
{
TA_CONFIG tacfg = wdb.TA_CONFIG.Where(p => p.UID == cfg.ConfigId).SingleOrDefault();
if (tacfg != null && !string.IsNullOrEmpty(tacfg.ParamName) && tacfg.ParamName == "收货自动审核")
{
if ("允许" == tacfg.ParamValue)
{
isRerviceOk = true;
}
}
}
}
if (scpRcv == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.;
}
else
{
istate = (int)FormState.;
}
scpRcv = new TB_RECEIVE
{
RecvBillNum = qadRcvNbrList,//退货单号
State = istate,
Remark = "",
CreateTime = firstqadData.xxwms_rt_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxwms_rt_createdt,//创建日期
CreateUser = firstqadData.xxwms_rt_createur,//创建用户
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = billtype
};
scpRcvList.Add(scpRcv);
}
scpRcv.PoBillNum = firstqadData.xxwms_rt_po_nbr;//采购单
//scpRcv.AsnBillNum = firstqadData.xxqad_prh_psnbr;//发货单号
scpRcv.Site = firstqadData.xxwms_rt_domain;//地点
scpRcv.VendId = firstqadData.xxwms_rt_vend;//供货商名称
scpRcv.ShipTime = firstqadData.xxwms_rt_date_ship;//收货日期
scpRcv.SubSite = !string.IsNullOrEmpty(firstqadData.xxwms_rt_site)? firstqadData.xxwms_rt_site: firstqadData.xxwms_rt_domain;
//var scpAsn = wdb.TF_ASN.FirstOrDefault(p => p.BillNum == scpRcv.AsnBillNum);
var scpAsn = wdb.TB_ASN.FirstOrDefault(p => p.PoBillNum == scpRcv.AsnBillNum);//发货单主表订单号==退货单主表发货单号
if (scpAsn != null)
scpAsn.State = (int)ShipState.Reject;
foreach (var qadData in qadDataList)
{
try
{
var poLineNum = Convert.ToInt32(qadData.xxwms_rt_po_line);
var scpRcvDetail =
wdb.TB_RECEIVE_DETAIL.SingleOrDefault(
p => p.RecvBillNum == qadRcvNbrList &&
p.PoBillNum == qadData.xxwms_rt_po_nbr &&
p.PoLine == poLineNum &&
p.PartCode == qadData.xxwms_rt_part &&
p.Batch == qadData.xxwms_rt_lot);
if (scpRcvDetail == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.;
}
else
{
istate = (int)FormState.;
}
scpRcvDetail = new TB_RECEIVE_DETAIL
{
RecvBillNum = qadRcvNbrList,//退货单号码
PoBillNum = qadData.xxwms_rt_po_nbr,//采购单
PoLine = poLineNum,//订单行
PartCode = qadData.xxwms_rt_part,//物料号
Batch = qadData.xxwms_rt_lot,//批次
VendBatch = qadData.xxwms_rt_vend_batch,//供应商批号
PoUnit = qadData.xxwms_rt_po_um,//采购单位
LocUnit = qadData.xxwms_rt_loc_um,//基本单位
Qty = qadData.xxwms_rt_qty_total,//退货总量
State = istate,// (int)FormState.关闭,
Site = firstqadData.xxwms_rt_domain,
SubSite=firstqadData.xxwms_rt_site,
CreateTime = qadData.xxwms_rt_createdt == null ? DateTime.Now : (DateTime)qadData.xxwms_rt_createdt,//创建日期
CreateUser = qadData.xxwms_rt_createur,//创建用户
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = billtype
};
scpRcveDetailList.Add(scpRcvDetail);
}
//var scpPoDetail =
// wdb.TB_PO_DETAIL.FirstOrDefault(
// p => p.PoBillNum == qadData.xxwms_rt_po_nbr && p.PoLine == poLineNum);
//if (scpPoDetail != null)
//{
// //订单明细RejectQty已退数量 += 退货明细Qty已结束量
// scpPoDetail.RejectQty -= scpRcvDetail.Qty;
//}
//var scpPo = wdb.TB_PO.FirstOrDefault(p => p.ErpBillNum == qadData.xxwms_rt_po_nbr);
//if (scpPo != null)
//{
// //订单明细
// var scpPoDetails = wdb.TB_PO_DETAIL.Where(p => p.PoBillNum == qadData.xxwms_rt_po_nbr);
// //if (scpPoDetails.All(p => p.BillQty == p.ReceivedQty))
// // scpPo.State = (int)PlanState.Complete;
// if (scpPoDetails.All(p => p.PlanQty == p.ReceivedQty)) //订货数量==已收数量
// scpPo.State = (int)PlanState.Complete;
//}
qadData.xxwms_rt_wmsread = ((int)UniApiState.).ToString();
}
catch (Exception ex)
{
qadData.xxwms_rt_wmsread = ((int)UniApiState.).ToString();
qadData.xxwms_rt_rmks += " SCM:" + ex.Message;
}
qadData.xxwms_rt_updateur = ScpCache.Config.SCP用户名;
qadData.xxwms_rt_updatedt = DateTime.Now;
}
}
wdb.TB_RECEIVE.AddOrUpdate(scpRcvList.ToArray());
wdb.TB_RECEIVE_DETAIL.AddOrUpdate(scpRcveDetailList.ToArray());
Console.WriteLine($"更新 退货单 数据:{qadRcvDetailList.Count}");
}
/// <summary>
///接收到货单
/// </summary>
/// <param name="idb"></param>
/// <param name="wdb"></param>
/// <param name="seq">流水号</param>
private static void AddMaterialArrive(UniApiEntities idb, ScpEntities wdb, string seq)
{
//var qadRcvDetailList = idb.xxqad_prh_det.Where(p => p.xxqad_prh_seq == seq).ToList();
var qadRcvDetailList = idb.xxwms_arv_det.Where(p => p.xxwms_arv_seq == seq).ToList();
var scpRcvList = new List<TB_ARRIVE>();
var scpRcveDetailList = new List<TB_ARRIVE_DETAIL>();
//根据xxwms_rc_po_nbr采购单字段去重
var qadReceiveNbrList = qadRcvDetailList.Select(p => p.xxwms_arv_nbr.ToUpper()).DistinctBy(p => p);
foreach (var qadRcvNbrList in qadReceiveNbrList)
{
//qadRcvDetailList同一xxqad_prh_receiver所有记录
var qadDataList = qadRcvDetailList.Where(p => p.xxwms_arv_nbr == qadRcvNbrList).ToList();
if (qadDataList.Count == 0)
{
continue;
}
var firstqadData = qadDataList[0];
//var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.BillNum == qadRcvNbrList);
//var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.PoBillNum != null && p.PoBillNum == qadRcvNbrList);
var scpRcv = wdb.TB_ARRIVE.SingleOrDefault(p => p.ArrvBillNum != null && p.ArrvBillNum == qadRcvNbrList);
//判断0100工厂的收货自动审核是否为允许
bool isRerviceOk = false;
if (!string.IsNullOrEmpty(firstqadData.xxwms_arv_site))
{
string site = firstqadData.xxwms_arv_site;//0100
List<TA_FACTORY_CONFIG> configs = wdb.TA_FACTORY_CONFIG.Where(p => p.FactoryId == site).ToList();
foreach (TA_FACTORY_CONFIG cfg in configs)
{
TA_CONFIG tacfg = wdb.TA_CONFIG.Where(p => p.UID == cfg.ConfigId).SingleOrDefault();
if (tacfg != null && !string.IsNullOrEmpty(tacfg.ParamName) && tacfg.ParamName == "收货自动审核")
{
if ("允许" == tacfg.ParamValue)
{
isRerviceOk = true;
}
}
}
}
if (scpRcv == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.;
}
else
{
istate = (int)FormState.;
}
scpRcv = new TB_ARRIVE
{
ArrvBillNum = qadRcvNbrList,//到货单号
State = istate,
Remark = "",
CreateTime = firstqadData.xxwms_arv_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxwms_arv_createdt,//创建日期
CreateUser = firstqadData.xxwms_arv_createur,//创建用户
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = string.IsNullOrEmpty(firstqadData.xxwms_arv_trtype) ? 1 : int.Parse(firstqadData.xxwms_arv_trtype) //1-收货单 2-退货单
};
scpRcvList.Add(scpRcv);
}
scpRcv.PoBillNum = firstqadData.xxwms_arv_po_nbr;//采购单
scpRcv.AsnBillNum = firstqadData.xxwms_arv_ps_nbr;//发货单号
scpRcv.Site = firstqadData.xxwms_arv_site;//地点
scpRcv.VendId = firstqadData.xxwms_arv_vend;//供货商名称
scpRcv.ShipTime = firstqadData.xxwms_arv_date_ship;//收货日期
foreach (var qadData in qadDataList)
{
try
{
var poLineNum = Convert.ToInt32(qadData.xxwms_arv_po_line);
//var scpRcvDetail =
// wdb.TB_RECEIVE_DETAIL.SingleOrDefault(
// p => p.BillNum == qadRcvNbrList &&
// p.PoBillNum == qadData.xxqad_prh_po_nbr &&
// p.PoLineNum == poLineNum &&
// p.AsnBillNum == qadData.xxqad_prh_psnbr &&
// p.PartCode == qadData.xxqad_prh_part &&
// p.Batch == qadData.xxqad_prh_lot);
var scpRcvDetail =
wdb.TB_ARRIVE_DETAIL.SingleOrDefault(
p => p.ArrvBillNum == qadRcvNbrList &&
p.PoBillNum == qadData.xxwms_arv_po_nbr &&
p.PoLine == poLineNum &&
p.PartCode == qadData.xxwms_arv_part &&
p.Batch == qadData.xxwms_arv_lot);
if (scpRcvDetail == null)
{
int istate = 0;
if (isRerviceOk == false)
{
istate = (int)FormState.;
}
else
{
istate = (int)FormState.;
}
scpRcvDetail = new TB_ARRIVE_DETAIL
{
ArrvBillNum = qadRcvNbrList,//到货单号
PoBillNum = qadData.xxwms_arv_po_nbr,//采购单
PoLine = poLineNum,//订单行
PartCode = qadData.xxwms_arv_part,//零件号
Batch = qadData.xxwms_arv_lot,//批次
VendBatch = qadData.xxwms_arv_vend_batch,//供应商批号
PoUnit = qadData.xxwms_arv_po_um,//采购单位
LocUnit = qadData.xxwms_arv_loc_um,//基本单位
Qty = qadData.xxwms_arv_qty_total,//收货总量
//DockCode = ?,//收货口
State = istate,// (int)FormState.关闭,
Remark = "",
CreateTime = qadData.xxwms_arv_createdt == null ? DateTime.Now : (DateTime)qadData.xxwms_arv_createdt,//创建日期
CreateUser = qadData.xxwms_arv_createur,//创建用户
IsDeleted = false,
GUID = System.Guid.NewGuid(),
BillType = string.IsNullOrEmpty(firstqadData.xxwms_arv_trtype) ? 1 : int.Parse(firstqadData.xxwms_arv_trtype) //1-收货单 2-退货单
};
scpRcveDetailList.Add(scpRcvDetail);
}
//var scpPoDetail =
// wdb.TB_PO_DETAIL.FirstOrDefault(
// p => p.PoBillNum == qadData.xxwms_arv_po_nbr && p.PoLine == poLineNum);
//if (scpPoDetail != null)
//{
// //订单明细ReceivedQty已收数量 += 收货明细Qty已结束量
// scpPoDetail.ReceivedQty += scpRcvDetail.Qty;
//}
//var scpPo = wdb.TB_PO.FirstOrDefault(p => p.ErpBillNum == qadData.xxwms_arv_po_nbr);
//if (scpPo != null)
//{
// //订单明细
// var scpPoDetails = wdb.TB_PO_DETAIL.Where(p => p.PoBillNum == qadData.xxwms_arv_po_nbr);
// //if (scpPoDetails.All(p => p.BillQty == p.ReceivedQty))
// // scpPo.State = (int)PlanState.Complete;
// if (scpPoDetails.All(p => p.PlanQty == p.ReceivedQty)) //订货数量==已收数量
// scpPo.State = (int)PlanState.Complete;
//}
qadData.xxwms_arv_wmsread = ((int)UniApiState.).ToString();
}
catch (Exception ex)
{
qadData.xxwms_arv_wmsread = ((int)UniApiState.).ToString();
qadData.xxwms_arv_rmks += " SCM:" + ex.Message;
}
qadData.xxwms_arv_updateur = ScpCache.Config.SCP用户名;
qadData.xxwms_arv_updatedt = DateTime.Now;
}
}
wdb.TB_ARRIVE.AddOrUpdate(scpRcvList.ToArray());
wdb.TB_ARRIVE_DETAIL.AddOrUpdate(scpRcveDetailList.ToArray());
Console.WriteLine($"更新 到货单 数据:{qadRcvDetailList.Count}");
}
}
}