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

1 year ago
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}");
}
}
}