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.
724 lines
37 KiB
724 lines
37 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;
|
|
|
|
namespace CK.SCP.UniApi.Controller
|
|
{
|
|
public static class OdbcApiWmsController
|
|
{
|
|
public static void GetNewCtrlList()
|
|
{
|
|
|
|
UniApiEntities idb = EntitiesFactory.CreateUniApiInstance();
|
|
idb.Database.CommandTimeout = 60 * 20;
|
|
var tableNameList = EnumHelper.EnumToList<WmsTableName>();
|
|
//var scmCtrlList = idb.xxscm_ctrl.Where(p => p.xxscm_scm == "0").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:流水号
|
|
}
|
|
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;
|
|
}
|
|
|
|
wmsCtrl.xxwms_wms = ((int)UniApiState.成功).ToString();
|
|
EntitiesFactory.SaveDb(wdb);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
wmsCtrl.xxwms_wms = ((int)UniApiState.失败).ToString();
|
|
wmsCtrl.xxwms_rmks += ex.ToString();
|
|
|
|
}
|
|
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_site,//工厂
|
|
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.xxqad_prh_det.Where(p => p.xxqad_prh_seq == seq).ToList();
|
|
var qadRcvDetailList = idb.xxwms_rc_det.Where(p => p.xxwms_rc_seq == seq).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.BillNum == qadRcvNbrList);
|
|
//var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.PoBillNum != null && p.PoBillNum == qadRcvNbrList);
|
|
var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.RecvBillNum != null && p.RecvBillNum == qadRcvNbrList);
|
|
|
|
//判断0100工厂的收货自动审核是否为允许
|
|
bool isRerviceOk = false;
|
|
if (!string.IsNullOrEmpty(firstqadData.xxwms_rc_site))
|
|
{
|
|
string site = firstqadData.xxwms_rc_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)
|
|
{
|
|
|
|
//scpRcv = new TB_RECEIVE
|
|
//{
|
|
// BillNum = qadRcvNbrList,
|
|
// BillType = firstqadData.xxqad_prh_trtype == "RCT-PO" ? (int)ReceiveBillType.Receive : (int)ReceiveBillType.Reject,
|
|
// BillTime = firstqadData.xxqad_prh_createdt,
|
|
// OperName = firstqadData.xxqad_prh_createur,
|
|
// State = (int)FormState.关闭,
|
|
// Remark = "",
|
|
//};
|
|
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_site;//地点
|
|
scpRcv.VendId = firstqadData.xxwms_rc_vend;//供货商名称
|
|
scpRcv.ShipTime = firstqadData.xxwms_rc_date_ship;//收货日期
|
|
//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.Receive;
|
|
foreach (var qadData in qadDataList)
|
|
{
|
|
try
|
|
{
|
|
var poLineNum = Convert.ToInt32(qadData.xxwms_rc_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_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 = ?,//收货口
|
|
State = istate,// (int)FormState.关闭,
|
|
Remark = "",
|
|
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.TF_PO_DETAIL.FirstOrDefault(
|
|
// p => p.ErpBillNum == qadData.xxqad_prh_po_nbr && p.LineNum == poLineNum);
|
|
//if (scpPoDetail != null)
|
|
//{
|
|
// scpPoDetail.ReceivedQty += scpRcvDetail.ReceivedQty;
|
|
// if (scpRcv.BillType == (int)ReceiveBillType.Reject)
|
|
// scpPoDetail.RejectQty -= scpRcvDetail.ReceivedQty;
|
|
//}
|
|
|
|
|
|
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.TF_PO.FirstOrDefault(p => p.ErpBillNum == qadData.xxqad_prh_po_nbr);
|
|
//if (scpPo != null)
|
|
//{
|
|
|
|
// var scpPoDetails = wdb.TF_PO_DETAIL.Where(p => p.ErpBillNum == qadData.xxqad_prh_po_nbr);
|
|
// if (scpPoDetails.All(p => p.BillQty == p.ReceivedQty))
|
|
// scpPo.State = (int)PlanState.Complete;
|
|
//}
|
|
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(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.BillNum == qadRcvNbrList);
|
|
//var scpRcv = wdb.TB_REJECT.SingleOrDefault(p => p.PoBillNum == qadRcvNbrList);
|
|
var scpRcv = wdb.TB_RECEIVE.SingleOrDefault(p => p.RecvBillNum == qadRcvNbrList);
|
|
|
|
//判断0100工厂的收货自动审核是否为允许
|
|
bool isRerviceOk = false;
|
|
if (!string.IsNullOrEmpty(firstqadData.xxwms_rt_site))
|
|
{
|
|
string site = firstqadData.xxwms_rt_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_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_site;//地点
|
|
scpRcv.VendId = firstqadData.xxwms_rt_vend;//供货商名称
|
|
scpRcv.ShipTime = firstqadData.xxwms_rt_date_ship;//收货日期
|
|
//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.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_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.关闭,
|
|
Remark = "",
|
|
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.TF_PO_DETAIL.FirstOrDefault(
|
|
// p => p.ErpBillNum == qadData.xxqad_prh_po_nbr && p.LineNum == poLineNum);
|
|
//if (scpPoDetail != null)
|
|
//{
|
|
// scpPoDetail.ReceivedQty += scpRcvDetail.ReceivedQty;
|
|
// if (scpRcv.BillType == (int)ReceiveBillType.Reject)
|
|
// scpPoDetail.RejectQty -= scpRcvDetail.ReceivedQty;
|
|
//}
|
|
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.TF_PO.FirstOrDefault(p => p.ErpBillNum == qadData.xxqad_prh_po_nbr);
|
|
//if (scpPo != null)
|
|
//{
|
|
|
|
// var scpPoDetails = wdb.TF_PO_DETAIL.Where(p => p.ErpBillNum == qadData.xxqad_prh_po_nbr);
|
|
// if (scpPoDetails.All(p => p.BillQty == p.ReceivedQty))
|
|
// scpPo.State = (int)PlanState.Complete;
|
|
//}
|
|
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}");
|
|
}
|
|
|
|
}
|
|
}
|