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.
957 lines
50 KiB
957 lines
50 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;
|
||
|
using CK.SCP.Controller;
|
||
|
using System.Text;
|
||
|
using System.Data.Entity.Core;
|
||
|
using System.Text.RegularExpressions;
|
||
|
|
||
|
namespace CK.SCP.GrupUniApi.Controller
|
||
|
{
|
||
|
public static class OdbcApiQadController
|
||
|
{
|
||
|
public static void GetNewCtrlList()
|
||
|
{
|
||
|
UniApiEntities idb = EntitiesFactory.CreateUniApiInstance();
|
||
|
idb.Database.CommandTimeout = 60 * 20;
|
||
|
var tableNameList = EnumHelper.EnumToList<QadTableName>();
|
||
|
// var qadCtrlList = idb.xxqad_ctrl.Where(p => p.xxqad_domain == ScpCache.Config.QAD�� && p.xxqad_scm == "0").ToList();
|
||
|
var qadCtrlList = idb.xxqad_ctrl.Where(p => p.xxqad_scm == "0" ).ToList();
|
||
|
foreach (var qadCtrl in qadCtrlList)
|
||
|
{
|
||
|
if (tableNameList.All(p => p.Name != qadCtrl.xxqad_table)) continue;
|
||
|
try
|
||
|
{
|
||
|
ScpEntities wdb = EntitiesFactory.CreateScpInstance();
|
||
|
QadTableName qadTableName;
|
||
|
Enum.TryParse(qadCtrl.xxqad_table, false, out qadTableName);
|
||
|
switch (qadTableName)
|
||
|
{
|
||
|
case QadTableName.xxqad_pt_mstr: //����
|
||
|
if (GlobalVar.ApiConfig.Qad����)
|
||
|
{
|
||
|
Console.WriteLine($"���� QAD �ӿ����ݣ�{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
||
|
UpdateParts(idb, wdb, qadCtrl.xxqad_seq);
|
||
|
}
|
||
|
else
|
||
|
continue;
|
||
|
break;
|
||
|
case QadTableName.xxqad_vd_mstr: //��Ӧ��
|
||
|
if (GlobalVar.ApiConfig.Qad��Ӧ��)
|
||
|
{
|
||
|
Console.WriteLine($"���� QAD �ӿ����ݣ�{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
||
|
UpdateVender(idb, wdb, qadCtrl.xxqad_seq);
|
||
|
}
|
||
|
else
|
||
|
continue;
|
||
|
break;
|
||
|
|
||
|
case QadTableName.xxqad_vp_mstr: //��Ӧ������
|
||
|
if (GlobalVar.ApiConfig.Qad��Ӧ������)
|
||
|
{
|
||
|
Console.WriteLine($"���� QAD �ӿ����ݣ�{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
||
|
UpdateVendParts(idb, wdb, qadCtrl.xxqad_seq);
|
||
|
}
|
||
|
else
|
||
|
continue;
|
||
|
break;
|
||
|
case QadTableName.xxqad_pod_det: //�ɹ�����
|
||
|
if (GlobalVar.ApiConfig.Qad�ɹ�����)
|
||
|
{
|
||
|
Console.WriteLine($"���� QAD �ӿ����ݣ�{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
||
|
UpdatePurchaseOrders(idb, wdb, qadCtrl.xxqad_seq);
|
||
|
}
|
||
|
else
|
||
|
continue;
|
||
|
break;
|
||
|
case QadTableName.xxqad_pprice_det: //�ɹ��۸�
|
||
|
Console.WriteLine($"���� QAD �ӿ����ݣ�{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
||
|
UpdatePrice(idb, wdb, qadCtrl.xxqad_seq);
|
||
|
break;
|
||
|
case QadTableName.xxqad_ppod_det: //�ɹ��۸�
|
||
|
Console.WriteLine($"���� QAD �ӿ����ݣ�{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
||
|
UpdatePPod(idb, wdb, qadCtrl.xxqad_seq);
|
||
|
break;
|
||
|
case QadTableName.xxqad_prh_det:
|
||
|
Console.WriteLine($"���� QAD �ӿ����ݣ�{qadCtrl.xxqad_table}:{qadCtrl.xxqad_table_qty}");
|
||
|
AddReceive(idb, wdb, qadCtrl.xxqad_seq,0 );
|
||
|
AddReject(idb, wdb, qadCtrl.xxqad_seq, 0);
|
||
|
break;
|
||
|
}
|
||
|
qadCtrl.xxqad_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);
|
||
|
});
|
||
|
}
|
||
|
qadCtrl.xxqad_scm = ((int)UniApiState.ʧ��).ToString();
|
||
|
qadCtrl.xxqad_rmks += " SCM:" + sb.ToString();
|
||
|
|
||
|
}
|
||
|
catch (OptimisticConcurrencyException ex)//������ͻ�쳣
|
||
|
{
|
||
|
qadCtrl.xxqad_scm = ((int)UniApiState.ʧ��).ToString();
|
||
|
qadCtrl.xxqad_rmks += " SCM:" + ex.Message;
|
||
|
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
qadCtrl.xxqad_scm = ((int)UniApiState.ʧ��).ToString();
|
||
|
qadCtrl.xxqad_rmks += " SCM:" + ex.Message;
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
EntitiesFactory.SaveDb(idb);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
///�����ջ���
|
||
|
/// </summary>
|
||
|
/// <param name="idb"></param>
|
||
|
/// <param name="wdb"></param>
|
||
|
/// <param name="seq">��ˮ��</param>
|
||
|
/// <param name="billtype">0:�ջ�,1:�˻�</param>
|
||
|
private static void AddReceive(UniApiEntities idb, ScpEntities wdb, string seq, int billtype)
|
||
|
{
|
||
|
|
||
|
// var qadRcvDetailList = idb.xxqad_prh_det.Where(p => p.xxqad_prh_seq == seq).ToList();
|
||
|
|
||
|
string _rec = "SELECT * FROM [UniInterface].[dbo].[xxqad_prh_det] WHERE xxqad_prh_uid IN\n" +
|
||
|
"(\n" +
|
||
|
"SELECT\n" +
|
||
|
" MAX(xxqad_prh_uid)\n" +
|
||
|
" FROM [UniInterface].[dbo].[xxqad_prh_det] where xxqad_prh_seq='{0}' and xxqad_prh_psnbr like 'C.%' and xxqad_prh_qty_rcvd>=0\n" +
|
||
|
" GROUP BY\n" +
|
||
|
" [xxqad_prh_psnbr]\n" +
|
||
|
" ,[xxqad_prh_po_nbr]\n" +
|
||
|
" ,[xxqad_prh_po_line]\n" +
|
||
|
" ,[xxqad_prh_part]\n" +
|
||
|
" ,[xxqad_prh_domain]\n" +
|
||
|
")";
|
||
|
var qadRcvDetailList = idb.Database.SqlQuery<xxqad_prh_det>(string.Format(_rec, seq)).ToList();
|
||
|
var scpRcvList = new List<TB_RECEIVE_QAD>();
|
||
|
var scpRcveDetailList = new List<TB_RECEIVE_DETAIL_QAD>();
|
||
|
//����xxwms_rc_po_nbr�ɹ����ֶ�ȥ��
|
||
|
var qadReceiveNbrList = qadRcvDetailList.Where(p=> !string.IsNullOrEmpty(p.xxqad_prh_psnbr) && (p.xxqad_prh_psnbr.Contains("R.") || p.xxqad_prh_psnbr.Contains("C.")))
|
||
|
.Select(p => p.xxqad_prh_psnbr.ToUpper()).DistinctBy(p => p).ToList();
|
||
|
|
||
|
foreach (var qadRcvNbrList in qadReceiveNbrList)
|
||
|
{
|
||
|
|
||
|
//qadRcvDetailListͬһxxqad_prh_receiver���м�¼
|
||
|
var qadDataList = qadRcvDetailList.Where(p => p.xxqad_prh_psnbr== qadRcvNbrList).ToList();
|
||
|
if (qadDataList.Count == 0)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
var firstqadData = qadDataList[0];
|
||
|
var scpRcv = wdb.TB_RECEIVE_QAD.SingleOrDefault(p => p.RecvBillNum != null && p.RecvBillNum == qadRcvNbrList && p.Site == firstqadData.xxqad_prh_domain);
|
||
|
//�ж�0100�������ջ��Զ������Ƿ�Ϊ����
|
||
|
|
||
|
|
||
|
if (scpRcv == null)
|
||
|
{
|
||
|
|
||
|
scpRcv = new TB_RECEIVE_QAD
|
||
|
{
|
||
|
RecvBillNum = qadRcvNbrList,//�ջ�����
|
||
|
State = (int)FormState.����,
|
||
|
Remark = "",
|
||
|
CreateTime = firstqadData.xxqad_prh_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_prh_createdt,//��������
|
||
|
CreateUser = firstqadData.xxqad_prh_createur,//�����û�
|
||
|
IsDeleted = false,
|
||
|
GUID = System.Guid.NewGuid(),
|
||
|
BillType = billtype,
|
||
|
};
|
||
|
scpRcvList.Add(scpRcv);
|
||
|
}
|
||
|
scpRcv.PoBillNum = firstqadData.xxqad_prh_po_nbr;//�ɹ���
|
||
|
//��������
|
||
|
scpRcv.Site = firstqadData.xxqad_prh_domain;//�ص�
|
||
|
scpRcv.VendId = firstqadData.xxqad_prh_vend;//����������
|
||
|
scpRcv.ShipTime = firstqadData.xxqad_prh_date_ship;//�ջ�����
|
||
|
scpRcv.ErpRecvBillNum = firstqadData.xxqad_prh_receiver;
|
||
|
scpRcv.Tax = string.IsNullOrEmpty(firstqadData.xxqad_prh_taxc) ? 0: int.Parse(firstqadData.xxqad_prh_taxc)/100;
|
||
|
foreach (var qadData in qadDataList)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var poLineNum = Convert.ToInt32(qadData.xxqad_prh_po_line);
|
||
|
var scpRcvDetail =
|
||
|
wdb.TB_RECEIVE_DETAIL_QAD.SingleOrDefault(
|
||
|
p => p.RecvBillNum == qadRcvNbrList &&
|
||
|
p.PoBillNum == qadData.xxqad_prh_po_nbr &&
|
||
|
p.PoLine == poLineNum &&
|
||
|
p.PartCode == qadData.xxqad_prh_part
|
||
|
);
|
||
|
if (scpRcvDetail == null)
|
||
|
{
|
||
|
|
||
|
scpRcvDetail = new TB_RECEIVE_DETAIL_QAD
|
||
|
{
|
||
|
ErpRecvBillNum = qadData.xxqad_prh_receiver,
|
||
|
RecvBillNum = qadRcvNbrList,//�ջ�����
|
||
|
PoBillNum = qadData.xxqad_prh_po_nbr,//�ɹ���
|
||
|
PoLine = poLineNum,//������
|
||
|
PartCode = qadData.xxqad_prh_part,//������
|
||
|
Batch = qadData.xxqad_prh_vend_batch,//����
|
||
|
VendBatch = qadData.xxqad_prh_vend_batch,//��Ӧ������
|
||
|
PoUnit = qadData.xxqad_prh_po_um,//�ɹ���λ
|
||
|
LocUnit = qadData.xxqad_prh_loc_um,//������λ
|
||
|
Qty = qadData.xxqad_prh_qty_rcvd,//�ջ�����
|
||
|
CurAmt=qadData.xxqad_prh_curr_amt!=null?qadData.xxqad_prh_curr_amt.Value:0,
|
||
|
//DockCode = ?,//�ջ���
|
||
|
State = (int)FormState.����,// (int)FormState.�ر�,
|
||
|
CreateTime = qadData.xxqad_prh_createdt == null ? DateTime.Now : (DateTime)qadData.xxqad_prh_createdt,//��������
|
||
|
CreateUser = qadData.xxqad_prh_createur,//�����û�
|
||
|
IsDeleted = false,
|
||
|
GUID = System.Guid.NewGuid(),
|
||
|
BillType = billtype,
|
||
|
PurCost = qadData.xxqad_prh_pur_cost,
|
||
|
StdCost = qadData.xxqad_prh_std_cost != null? qadData.xxqad_prh_std_cost.Value:0,
|
||
|
Rate = qadData.xxqad_prh_curr_rate != null ?qadData.xxqad_prh_curr_rate.Value : 1,
|
||
|
Site=qadData.xxqad_prh_domain,
|
||
|
Tax = string.IsNullOrEmpty(firstqadData.xxqad_prh_taxc) ? 0 : int.Parse(firstqadData.xxqad_prh_taxc) / 100
|
||
|
|
||
|
|
||
|
};
|
||
|
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.xxqad_prh_scmread = ((int)UniApiState.�ɹ�).ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
qadData.xxqad_prh_scmread = ((int)UniApiState.ʧ��).ToString();
|
||
|
qadData.xxqad_prh_rmks += " SCM:" + ex.Message;
|
||
|
}
|
||
|
qadData.xxqad_prh_updateur = ScpCache.Config.SCP�û���;
|
||
|
qadData.xxqad_prh_updatedt = DateTime.Now;
|
||
|
}
|
||
|
}
|
||
|
wdb.TB_RECEIVE_QAD.AddOrUpdate(scpRcvList.ToArray());
|
||
|
wdb.TB_RECEIVE_DETAIL_QAD.AddOrUpdate(scpRcveDetailList.ToArray());
|
||
|
Console.WriteLine($"���� �ջ��� ���ݣ�{qadRcvDetailList.Count}");
|
||
|
}
|
||
|
|
||
|
|
||
|
private static void AddReject(UniApiEntities idb, ScpEntities wdb, string seq, int billtype)
|
||
|
{
|
||
|
|
||
|
// var qadRcvDetailList = idb.xxqad_prh_det.Where(p => p.xxqad_prh_seq == seq).ToList();
|
||
|
|
||
|
string _rec = "SELECT * FROM [UniInterface].[dbo].[xxqad_prh_det] WHERE xxqad_prh_uid IN\n" +
|
||
|
"(\n" +
|
||
|
"SELECT\n" +
|
||
|
" MAX(xxqad_prh_uid)\n" +
|
||
|
" FROM [UniInterface].[dbo].[xxqad_prh_det] where xxqad_prh_seq='{0}' and xxqad_prh_psnbr like 'R.%' \n" +
|
||
|
" GROUP BY\n" +
|
||
|
" [xxqad_prh_psnbr]\n" +
|
||
|
" ,[xxqad_prh_po_nbr]\n" +
|
||
|
" ,[xxqad_prh_po_line]\n" +
|
||
|
" ,[xxqad_prh_part]\n" +
|
||
|
" ,[xxqad_prh_domain]\n" +
|
||
|
")";
|
||
|
var qadRcvDetailList = idb.Database.SqlQuery<xxqad_prh_det>(string.Format(_rec, seq)).ToList();
|
||
|
var scpRcvList = new List<TB_RECEIVE_QAD>();
|
||
|
var scpRcveDetailList = new List<TB_RECEIVE_DETAIL_QAD>();
|
||
|
//����xxwms_rc_po_nbr�ɹ����ֶ�ȥ��
|
||
|
var qadReceiveNbrList = qadRcvDetailList.Where(p => !string.IsNullOrEmpty(p.xxqad_prh_psnbr) && (p.xxqad_prh_psnbr.Contains("R.") || p.xxqad_prh_psnbr.Contains("C.")))
|
||
|
.Select(p => p.xxqad_prh_psnbr.ToUpper()).DistinctBy(p => p).ToList();
|
||
|
|
||
|
foreach (var qadRcvNbrList in qadReceiveNbrList)
|
||
|
{
|
||
|
//qadRcvDetailListͬһxxqad_prh_receiver���м�¼
|
||
|
var qadDataList = qadRcvDetailList.Where(p => p.xxqad_prh_psnbr == qadRcvNbrList).ToList();
|
||
|
if (qadDataList.Count == 0)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
var firstqadData = qadDataList[0];
|
||
|
var scpRcv = wdb.TB_RECEIVE_QAD.SingleOrDefault(p => p.RecvBillNum != null && p.RecvBillNum == qadRcvNbrList && p.Site == firstqadData.xxqad_prh_domain);
|
||
|
//�ж�0100�������ջ��Զ������Ƿ�Ϊ����
|
||
|
|
||
|
if (scpRcv == null)
|
||
|
{
|
||
|
|
||
|
scpRcv = new TB_RECEIVE_QAD
|
||
|
{
|
||
|
RecvBillNum = qadRcvNbrList,//�ջ�����
|
||
|
State = (int)FormState.����,
|
||
|
Remark = "",
|
||
|
CreateTime = firstqadData.xxqad_prh_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_prh_createdt,//��������
|
||
|
CreateUser = firstqadData.xxqad_prh_createur,//�����û�
|
||
|
IsDeleted = false,
|
||
|
GUID = System.Guid.NewGuid(),
|
||
|
BillType = billtype,
|
||
|
|
||
|
};
|
||
|
scpRcvList.Add(scpRcv);
|
||
|
}
|
||
|
scpRcv.PoBillNum = firstqadData.xxqad_prh_po_nbr;//�ɹ���
|
||
|
//��������
|
||
|
scpRcv.Site = firstqadData.xxqad_prh_domain;//�ص�
|
||
|
scpRcv.VendId = firstqadData.xxqad_prh_vend;//����������
|
||
|
scpRcv.ShipTime = firstqadData.xxqad_prh_date_ship;//�ջ�����
|
||
|
scpRcv.ErpRecvBillNum = firstqadData.xxqad_prh_receiver;
|
||
|
|
||
|
scpRcv.Tax = string.IsNullOrEmpty(firstqadData.xxqad_prh_taxc) ? 0 : int.Parse(firstqadData.xxqad_prh_taxc) / 100;
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
foreach (var qadData in qadDataList)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var poLineNum = Convert.ToInt32(qadData.xxqad_prh_po_line);
|
||
|
var scpRcvDetail =
|
||
|
wdb.TB_RECEIVE_DETAIL_QAD.SingleOrDefault(
|
||
|
p => p.RecvBillNum == qadRcvNbrList &&
|
||
|
p.PoBillNum == qadData.xxqad_prh_po_nbr &&
|
||
|
p.PoLine == poLineNum &&
|
||
|
p.PartCode == qadData.xxqad_prh_part
|
||
|
);
|
||
|
if (scpRcvDetail == null)
|
||
|
{
|
||
|
|
||
|
scpRcvDetail = new TB_RECEIVE_DETAIL_QAD
|
||
|
{
|
||
|
ErpRecvBillNum = qadData.xxqad_prh_receiver,
|
||
|
RecvBillNum = qadRcvNbrList,//�ջ�����
|
||
|
PoBillNum = qadData.xxqad_prh_po_nbr,//�ɹ���
|
||
|
PoLine = poLineNum,//������
|
||
|
PartCode = qadData.xxqad_prh_part,//������
|
||
|
Batch = qadData.xxqad_prh_vend_batch,//����
|
||
|
VendBatch = qadData.xxqad_prh_vend_batch,//��Ӧ������
|
||
|
PoUnit = qadData.xxqad_prh_po_um,//�ɹ���λ
|
||
|
LocUnit = qadData.xxqad_prh_loc_um,//������λ
|
||
|
Qty = qadData.xxqad_prh_qty_rcvd,//�ջ�����
|
||
|
CurAmt = qadData.xxqad_prh_curr_amt != null ? qadData.xxqad_prh_curr_amt.Value : 0,
|
||
|
//DockCode = ?,//�ջ���
|
||
|
State = (int)FormState.����,// (int)FormState.�ر�,
|
||
|
|
||
|
CreateTime = qadData.xxqad_prh_createdt == null ? DateTime.Now : (DateTime)qadData.xxqad_prh_createdt,//��������
|
||
|
CreateUser = qadData.xxqad_prh_createur,//�����û�
|
||
|
IsDeleted = false,
|
||
|
GUID = System.Guid.NewGuid(),
|
||
|
BillType = billtype,
|
||
|
PurCost = qadData.xxqad_prh_pur_cost,
|
||
|
StdCost = qadData.xxqad_prh_std_cost != null ? qadData.xxqad_prh_std_cost.Value : 0,
|
||
|
Rate = qadData.xxqad_prh_curr_rate != null ? qadData.xxqad_prh_curr_rate.Value : 1,
|
||
|
Site = qadData.xxqad_prh_domain,
|
||
|
Tax = string.IsNullOrEmpty(firstqadData.xxqad_prh_taxc) ? 0 : int.Parse(firstqadData.xxqad_prh_taxc) / 100
|
||
|
|
||
|
|
||
|
};
|
||
|
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.xxqad_prh_scmread = ((int)UniApiState.�ɹ�).ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
qadData.xxqad_prh_scmread = ((int)UniApiState.ʧ��).ToString();
|
||
|
qadData.xxqad_prh_rmks += " SCM:" + ex.Message;
|
||
|
}
|
||
|
qadData.xxqad_prh_updateur = ScpCache.Config.SCP�û���;
|
||
|
qadData.xxqad_prh_updatedt = DateTime.Now;
|
||
|
}
|
||
|
}
|
||
|
wdb.TB_RECEIVE_QAD.AddOrUpdate(scpRcvList.ToArray());
|
||
|
wdb.TB_RECEIVE_DETAIL_QAD.AddOrUpdate(scpRcveDetailList.ToArray());
|
||
|
Console.WriteLine($"���� �ջ��� ���ݣ�{qadRcvDetailList.Count}");
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// ���²ɹ�����
|
||
|
/// </summary>
|
||
|
/// <param name="idb"></param>
|
||
|
/// <param name="wdb"></param>
|
||
|
/// <param name="seq"></param>
|
||
|
private static void UpdatePPod(UniApiEntities idb, ScpEntities wdb, string seq)
|
||
|
{
|
||
|
|
||
|
|
||
|
string _sql = "select * from\n" +
|
||
|
"(SELECT [xxqad_ppod_uid]\n" +
|
||
|
" ,[xxqad_ppod_seq]\n" +
|
||
|
" ,[xxqad_ppod_nbr]\n" +
|
||
|
" ,[xxqad_ppod_line]\n" +
|
||
|
" ,case\n" +
|
||
|
" LEN(replace([xxqad_ppod_rev],'-',''))\n" +
|
||
|
" when 8 then replace([xxqad_ppod_rev],'-','')+'000'\n" +
|
||
|
" when 11 then replace([xxqad_ppod_rev],'-','') end as xxqad_ppod_rev\n" +
|
||
|
" ,[xxqad_ppod_site]\n" +
|
||
|
" ,[xxqad_ppod_domain]\n" +
|
||
|
" ,[xxqad_ppod_part]\n" +
|
||
|
" ,[xxqad_ppod_desc]\n" +
|
||
|
" ,[xxqad_ppod_type]\n" +
|
||
|
" ,[xxqad_ppod_wolot]\n" +
|
||
|
" ,[xxqad_ppod_pricum]\n" +
|
||
|
" ,[xxqad_ppod_reccum]\n" +
|
||
|
" ,[xxqad_ppod_qty_ord]\n" +
|
||
|
" ,[xxqad_ppod_qty_std]\n" +
|
||
|
" ,[xxqad_ppod_due_date]\n" +
|
||
|
" ,[xxqad_ppod_loc_um]\n" +
|
||
|
" ,[xxqad_ppod_um]\n" +
|
||
|
" ,[xxqad_ppod_um_conv]\n" +
|
||
|
" ,[xxqad_ppod_vend]\n" +
|
||
|
" ,[xxqad_ppod_buyer]\n" +
|
||
|
" ,[xxqad_ppod_buyer_phone]\n" +
|
||
|
" ,[xxqad_ppod_status]\n" +
|
||
|
" ,[xxqad_ppod_qadread]\n" +
|
||
|
" ,[xxqad_ppod_wmsread]\n" +
|
||
|
" ,[xxqad_ppod_scmread]\n" +
|
||
|
" ,[xxqad_ppod_mesread]\n" +
|
||
|
" ,[xxqad_ppod_rmks]\n" +
|
||
|
" ,[xxqad_ppod_createdt]\n" +
|
||
|
" ,[xxqad_ppod_createur]\n" +
|
||
|
" ,[xxqad_ppod_updatedt]\n" +
|
||
|
" ,[xxqad_ppod_updateur] from xxqad_ppod_det\n" +
|
||
|
" where xxqad_ppod_seq = '{0}' and xxqad_ppod_scmread = '0'\n" +
|
||
|
" ) as a\n" +
|
||
|
"inner join\n" +
|
||
|
"(\n" +
|
||
|
"SELECT\n" +
|
||
|
" xxqad_ppod_seq\n" +
|
||
|
" ,[xxqad_ppod_nbr]\n" +
|
||
|
" ,[xxqad_ppod_line]\n" +
|
||
|
" ,[xxqad_ppod_domain]\n" +
|
||
|
" ,[xxqad_ppod_part]\n" +
|
||
|
" ,[xxqad_ppod_due_date]\n" +
|
||
|
" ,[xxqad_ppod_vend]\n" +
|
||
|
" ,max(\n" +
|
||
|
" case\n" +
|
||
|
" LEN(replace([xxqad_ppod_rev],'-',''))\n" +
|
||
|
" when 8 then replace([xxqad_ppod_rev],'-','')+'000'\n" +
|
||
|
" when 11 then replace([xxqad_ppod_rev],'-','') end\n" +
|
||
|
" ) as xxqad_ppod_rev\n" +
|
||
|
" FROM [xxqad_ppod_det]\n" +
|
||
|
" where xxqad_ppod_seq = '{0}' and xxqad_ppod_scmread = '0'\n" +
|
||
|
" group by\n" +
|
||
|
" xxqad_ppod_seq\n" +
|
||
|
" ,[xxqad_ppod_nbr]\n" +
|
||
|
" ,[xxqad_ppod_line]\n" +
|
||
|
" ,[xxqad_ppod_domain]\n" +
|
||
|
" ,[xxqad_ppod_part]\n" +
|
||
|
" ,[xxqad_ppod_due_date]\n" +
|
||
|
" ,[xxqad_ppod_vend]) as b\n" +
|
||
|
" on\n" +
|
||
|
" a.xxqad_ppod_seq=b.xxqad_ppod_seq\n" +
|
||
|
" and a.xxqad_ppod_domain=b.xxqad_ppod_domain\n" +
|
||
|
" and a.xxqad_ppod_due_date=b.xxqad_ppod_due_date\n" +
|
||
|
" and a.xxqad_ppod_line=b.xxqad_ppod_line\n" +
|
||
|
" and a.xxqad_ppod_nbr=b.xxqad_ppod_nbr\n" +
|
||
|
" and a.xxqad_ppod_vend=b.xxqad_ppod_vend\n" +
|
||
|
" and a.xxqad_ppod_part=b.xxqad_ppod_part\n" +
|
||
|
" and a.xxqad_ppod_rev=b.xxqad_ppod_rev";
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
_sql = string.Format(_sql, seq);
|
||
|
|
||
|
var _ppodList=idb.Database.SqlQuery<xxqad_ppod_det>(_sql).ToList();
|
||
|
|
||
|
// long max = _ppodList.Select(p => long.Parse(p.xxqad_ppod_rev)).Max();
|
||
|
|
||
|
//_ppodList =_ppodList.Where(p => p.xxqad_ppod_rev == max.ToString()).ToList();
|
||
|
ScpEntities sdb = EntitiesFactory.CreateScpInstance();
|
||
|
|
||
|
var _ask = sdb.TB_ASK.Where(p => p.AskBillNum.Contains("K_") && p.State<(int)AskState.Confirm);
|
||
|
|
||
|
var _askno = sdb.TB_ASK.Where(p => p.AskBillNum.Contains("K_") && p.State >= (int)AskState.Confirm);
|
||
|
var _ls=_askno.Select(p => p.AskBillNum).ToList();
|
||
|
var _detail = sdb.V_TB_ASK_DETAIL.Where(p => p.AskBillNum.Contains("K_") && p.State < (int)AskState.Confirm);
|
||
|
|
||
|
var ids=_detail.Select(p => p.UID).ToList();
|
||
|
var _d=sdb.TB_ASK_DETAIL.Where(p => ids.Contains(p.UID));
|
||
|
sdb.TB_ASK.RemoveRange(_ask);
|
||
|
sdb.TB_ASK_DETAIL.RemoveRange(_d);
|
||
|
sdb.SaveChanges();
|
||
|
var _billnumList = _ppodList.Select(p => p.xxqad_ppod_nbr.ToString()).Distinct().ToList();
|
||
|
var _dateList = _ppodList.Select(p => p.xxqad_ppod_due_date).Distinct().ToList();
|
||
|
_billnumList.ForEach(billnum =>{
|
||
|
_dateList.ForEach(date =>
|
||
|
{
|
||
|
var poList = _ppodList.Where(q => q.xxqad_ppod_nbr == billnum && q.xxqad_ppod_due_date == date && q.xxqad_ppod_qty_ord>0).ToList();
|
||
|
if (poList.Count > 0)
|
||
|
{
|
||
|
var po = poList.FirstOrDefault();
|
||
|
var _askBillNum = "K_" + po.xxqad_ppod_nbr + "_" + po.xxqad_ppod_due_date.ToString("yyMMdd");
|
||
|
var _entityList = wdb.V_TB_ASK.Where(itm =>
|
||
|
itm.PoBillNum == billnum
|
||
|
&& itm.EndTime == po.xxqad_ppod_due_date ).ToList();
|
||
|
if (_entityList.Count == 0)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (!_ls.Contains(_askBillNum))
|
||
|
{
|
||
|
TB_ASK _t = new TB_ASK();
|
||
|
_t.AskBillNum = _askBillNum;
|
||
|
_t.PoBillNum = po.xxqad_ppod_nbr;
|
||
|
_t.VendId = po.xxqad_ppod_vend;
|
||
|
_t.IsDeleted = false;//����Ա
|
||
|
_t.CreateTime = po.xxqad_ppod_createdt == null ? DateTime.Now : po.xxqad_ppod_createdt.Value;
|
||
|
_t.CreateUser = po.xxqad_ppod_createur;
|
||
|
_t.Site = po.xxqad_ppod_domain;
|
||
|
_t.Remark = po.xxqad_ppod_rev;
|
||
|
_t.State = (int)AskState.New;
|
||
|
_t.GUID = Guid.NewGuid();
|
||
|
_t.ModType = 1;
|
||
|
_t.ErpBillNum = po.xxqad_ppod_nbr;
|
||
|
_t.BeginTime = po.xxqad_ppod_createdt == null ? DateTime.Now : po.xxqad_ppod_createdt.Value;
|
||
|
_t.EndTime = po.xxqad_ppod_due_date;
|
||
|
_t.Buyer = po.xxqad_ppod_buyer;
|
||
|
_t.BuyerPhone = po.xxqad_ppod_buyer_phone;
|
||
|
wdb.TB_ASK.Add(_t);
|
||
|
}
|
||
|
}
|
||
|
catch (Exception e)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// string str= Utils.XmlHelper<xxqad_ppod_det>.EntityToXml(poList);
|
||
|
poList.ForEach(p =>
|
||
|
{
|
||
|
if (!_ls.Contains(_askBillNum))
|
||
|
{
|
||
|
var _list = wdb.V_TB_ASK_DETAIL.Where(itm =>
|
||
|
itm.PoBillNum == p.xxqad_ppod_nbr
|
||
|
&& itm.EndTime == p.xxqad_ppod_due_date
|
||
|
&& itm.VendId == p.xxqad_ppod_vend
|
||
|
&& itm.PoLine == p.xxqad_ppod_line
|
||
|
&& itm.PartCode == p.xxqad_ppod_part
|
||
|
&& itm.Site == p.xxqad_ppod_domain
|
||
|
|
||
|
).ToList();
|
||
|
var _askList = _list.Where(q => q.AskBillNum.Length > 11 && string.IsNullOrEmpty(Regex.Replace(q.Remark, @"\d+", string.Empty))).FirstOrDefault();
|
||
|
if (_askList == null)
|
||
|
{
|
||
|
if (p.xxqad_ppod_qty_ord > 0)
|
||
|
{
|
||
|
TB_ASK_DETAIL _tDetail = new TB_ASK_DETAIL();
|
||
|
_tDetail.Remark = p.xxqad_ppod_rev;
|
||
|
_tDetail.PoBillNum = p.xxqad_ppod_nbr;
|
||
|
_tDetail.AskBillNum = _askBillNum;
|
||
|
_tDetail.PoLine = p.xxqad_ppod_line;
|
||
|
_tDetail.PoUnit = p.xxqad_ppod_um;
|
||
|
_tDetail.CreateTime = p.xxqad_ppod_createdt == null ? DateTime.Now : p.xxqad_ppod_createdt.Value;
|
||
|
_tDetail.CreateUser = p.xxqad_ppod_createur;
|
||
|
_tDetail.PartCode = p.xxqad_ppod_part;
|
||
|
_tDetail.BeginTime = p.xxqad_ppod_createdt;
|
||
|
_tDetail.EndTime = p.xxqad_ppod_due_date;
|
||
|
_tDetail.AskQty = p.xxqad_ppod_qty_ord.Value;
|
||
|
_tDetail.IsDeleted = false;
|
||
|
_tDetail.LocUnit = p.xxqad_ppod_um;
|
||
|
_tDetail.UnConv = p.xxqad_ppod_um_conv;
|
||
|
_tDetail.State = (int)AskState.New;
|
||
|
_tDetail.GUID = Guid.NewGuid();
|
||
|
wdb.TB_ASK_DETAIL.Add(_tDetail);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
Console.WriteLine($"���¿������ݣ�{_ppodList.Count}");
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ���²ɹ�����
|
||
|
/// </summary>
|
||
|
/// <param name="idb"></param>
|
||
|
/// <param name="wdb"></param>
|
||
|
/// <param name="seq"></param>
|
||
|
private static void UpdatePurchaseOrders(UniApiEntities idb, ScpEntities wdb, string seq)
|
||
|
{
|
||
|
// var qadPoDetailList = idb.xxqad_pod_det.Where(p => p.xxqad_pod_seq == seq).ToList(); ԭ���� xxqad_pod_modtype 1Ϊ��
|
||
|
var qadPoDetailList = idb.xxqad_pod_det.Where(p => p.xxqad_pod_seq == seq && p.xxqad_pod_scmread == "0").ToList();
|
||
|
|
||
|
var wmsPoList = new List<TB_PO>();
|
||
|
var wmsPoDetailList = new List<TB_PO_DETAIL>();
|
||
|
|
||
|
var qadPoNbrList = qadPoDetailList.Select(p => p.xxqad_pod_nbr.ToUpper()).DistinctBy(p => p);
|
||
|
|
||
|
foreach (var qadPoNbr in qadPoNbrList)
|
||
|
{
|
||
|
var qadDataList = qadPoDetailList.Where(p => p.xxqad_pod_nbr == qadPoNbr).ToList();
|
||
|
if (qadDataList.Count == 0)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
var firstqadData = qadDataList[0];
|
||
|
//var wmsPo = wdb.TF_PO.SingleOrDefault(p => p.ErpBillNum == qadPoNbr);
|
||
|
var wmsPo = wdb.TB_PO.SingleOrDefault(p => p.ErpBillNum == qadPoNbr);
|
||
|
if (wmsPo == null)
|
||
|
{
|
||
|
|
||
|
int temp;
|
||
|
string strPoBillNum = SCP_BILLCODE_CONTROLLER.MakePOCode();
|
||
|
wmsPo = new TB_PO
|
||
|
{
|
||
|
PoBillNum = qadPoNbr,//������
|
||
|
ErpBillNum = qadPoNbr,//ERP������
|
||
|
VendId = firstqadData.xxqad_pod_vend.ToUpper(),//��Ӧ�̱���
|
||
|
ModType = Int32.TryParse(firstqadData.xxqad_pod_modtype, out temp) ? temp : (int?)null, //��������(1:�ճ̵�,2:��ɢ����)
|
||
|
Contacter = firstqadData.xxqad_pod_attn,//��ϵ��
|
||
|
Site = firstqadData.xxqad_pod_domain,//�ص�
|
||
|
State = (int)FormState.����,//״̬
|
||
|
|
||
|
CreateTime = firstqadData.xxqad_pod_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_pod_createdt,//��������
|
||
|
CreateUser = firstqadData.xxqad_pod_createur,//�����û�
|
||
|
|
||
|
IsDeleted = false,
|
||
|
GUID = System.Guid.NewGuid(),
|
||
|
BeginTime = firstqadData.xxqad_pod_createdt==null ? DateTime.Now: (DateTime)firstqadData.xxqad_pod_createdt,//��������
|
||
|
EndTime = firstqadData.xxqad_pod_due_date//�ջ�����ʱ��
|
||
|
};
|
||
|
wmsPoList.Add(wmsPo);
|
||
|
}
|
||
|
|
||
|
wmsPo.Contacter = firstqadData.xxqad_pod_attn;
|
||
|
wmsPo.Buyer = firstqadData.xxqad_pod_buyer;
|
||
|
wmsPo.BuyerPhone = firstqadData.xxqad_pod_buyer_phone;
|
||
|
|
||
|
wmsPo.UpdateTime = firstqadData.xxqad_pod_updatedt;//��������
|
||
|
wmsPo.UpdateUser = firstqadData.xxqad_pod_updateur;//�����û�
|
||
|
|
||
|
foreach (var qadData in qadDataList)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var lineNum = Convert.ToInt32(qadData.xxqad_pod_line);
|
||
|
|
||
|
var wmsPoDetail =
|
||
|
wdb.TB_PO_DETAIL.SingleOrDefault(
|
||
|
p => p.PoBillNum == qadPoNbr && p.PoLine == lineNum);
|
||
|
if (wmsPoDetail == null)
|
||
|
{
|
||
|
wmsPoDetail = new TB_PO_DETAIL
|
||
|
{
|
||
|
PoBillNum = qadPoNbr,//������
|
||
|
PoLine = lineNum,//������
|
||
|
IsDeleted = false,
|
||
|
GUID = System.Guid.NewGuid()
|
||
|
};
|
||
|
wmsPoDetailList.Add(wmsPoDetail);
|
||
|
}
|
||
|
|
||
|
wmsPoDetail.PartCode = qadData.xxqad_pod_part.ToUpper();//������-���Ϻ�
|
||
|
wmsPoDetail.PlanQty = qadData.xxqad_pod_qty_ord;//��������-�ɹ���
|
||
|
|
||
|
wmsPoDetail.BeginTime = firstqadData.xxqad_pod_createdt;//�ջ���ʼʱ��
|
||
|
wmsPoDetail.EndTime = qadData.xxqad_pod_due_date;//�ջ�����ʱ��
|
||
|
wmsPoDetail.PoUnit = qadData.xxqad_pod_um;//�ɹ���λ
|
||
|
wmsPoDetail.LocUnit = qadData.xxqad_pod_loc_um.ToUpper();//�洢��λ
|
||
|
wmsPoDetail.DockCode = qadData.xxqad_pod_loc;
|
||
|
wmsPoDetail.Price = ScpCache.Config.��Ŀ���� == ProjectName.���챱��ģ��.ToString()
|
||
|
? 0
|
||
|
: qadData.xxqad_pod_price;
|
||
|
wmsPoDetail.Currency = qadData.xxqad_pod_curr;//����
|
||
|
wmsPoDetail.PackQty = qadData.xxqad_pod_qty_std;//��������
|
||
|
wmsPoDetail.UnConv = qadData.xxqad_pod_um_conv;//ת����
|
||
|
|
||
|
wmsPoDetail.DockCode = qadData.xxqad_pod_loc;
|
||
|
|
||
|
wmsPoDetail.State = Convert.ToInt32(qadData.xxqad_pod_status);//״̬
|
||
|
wmsPoDetail.Remark = qadData.xxqad_pod_domain;//��ע
|
||
|
wmsPoDetail.CreateTime = firstqadData.xxqad_pod_createdt == null ? DateTime.Now : (DateTime)firstqadData.xxqad_pod_createdt;//��������
|
||
|
wmsPoDetail.CreateUser = firstqadData.xxqad_pod_createur;//�����û�
|
||
|
wmsPoDetail.UpdateTime = firstqadData.xxqad_pod_updatedt;//��������
|
||
|
wmsPoDetail.UpdateUser = firstqadData.xxqad_pod_updateur;//�����û�
|
||
|
|
||
|
//if (wmsPoDetail.BillQty != 0 && wmsPoDetail.BillQty <= wmsPoDetail.ReceivedQty)
|
||
|
// wmsPoDetail.State = (int)FormState.�ر�;
|
||
|
|
||
|
if (wmsPoDetail.PlanQty != 0 && wmsPoDetail.PlanQty <= wmsPoDetail.ReceivedQty)
|
||
|
wmsPoDetail.State = (int)FormState.�ر�;
|
||
|
|
||
|
qadData.xxqad_pod_scmread = ((int)UniApiState.�ɹ�).ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
qadData.xxqad_pod_scmread = ((int)UniApiState.ʧ��).ToString();
|
||
|
qadData.xxqad_pod_rmks += " SCM:" + ex.Message;
|
||
|
}
|
||
|
qadData.xxqad_pod_updateur = ScpCache.Config.SCP�û���;
|
||
|
qadData.xxqad_pod_updatedt = DateTime.Now;
|
||
|
|
||
|
}
|
||
|
wmsPo.State = qadDataList.All(p => p.xxqad_pod_status == ((int)FormState.�ر�).ToString())
|
||
|
? (int)FormState.�ر�
|
||
|
: (int)FormState.����;
|
||
|
}
|
||
|
wdb.TB_PO.AddOrUpdate(wmsPoList.ToArray());
|
||
|
wdb.TB_PO_DETAIL.AddOrUpdate(wmsPoDetailList.ToArray());
|
||
|
Console.WriteLine($"���� �ɹ����� ���ݣ�{qadPoDetailList.Count}");
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// ���²ɹ�����
|
||
|
/// </summary>
|
||
|
/// <param name="idb"></param>
|
||
|
/// <param name="wdb"></param>
|
||
|
/// <param name="seq"></param>
|
||
|
private static void UpdatePrice(UniApiEntities idb, ScpEntities scpdb, string seq)
|
||
|
{
|
||
|
var _list = idb.xxqad_pprice_det.Where(p => p.xxqad_pprice_seq == seq && p.xxqad_pprice_scmread == "0").ToList();
|
||
|
var PriceList = new List<TB_PRICE>();
|
||
|
foreach (var itm in _list)
|
||
|
{
|
||
|
var _price= new TB_PRICE
|
||
|
{
|
||
|
VendId = itm.xxqad_pprice_list,
|
||
|
Unit = itm.xxqad_pprice_um,
|
||
|
PartCode = itm.xxqad_pprice_part,
|
||
|
Site = itm.xxqad_pprice_domain,
|
||
|
Remarks = itm.xxqad_pprice_rmks,
|
||
|
StartTime = itm.xxqad_pprice_start,
|
||
|
EndTime = itm.xxqad_pprice_end,
|
||
|
Curr = itm.xxqad_pprice_curr
|
||
|
};
|
||
|
_price.Amt = itm.xxqad_pprice_amt;
|
||
|
PriceList.Add(_price);
|
||
|
}
|
||
|
scpdb.TB_PRICE.AddOrUpdate(PriceList.ToArray());
|
||
|
Console.WriteLine($"���²ɹ��۸����ݣ�{PriceList.Count}");
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// ���¹�Ӧ������
|
||
|
/// </summary>
|
||
|
/// <param name="idb"></param>
|
||
|
/// <param name="wdb"></param>
|
||
|
/// <param name="seq"></param>
|
||
|
private static void UpdateVendParts(UniApiEntities idb, ScpEntities wdb, string seq)
|
||
|
{
|
||
|
var qadDataList = idb.xxqad_vp_mstr.Where(p => p.xxqad_vp_seq == seq ).ToList();
|
||
|
var wmsDataList = new List<TA_VEND_PART>();
|
||
|
foreach (var qadData in qadDataList)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(qadData.xxqad_vp_vend_part))
|
||
|
qadData.xxqad_vp_vend_part = qadData.xxqad_vp_part;
|
||
|
var wmsData =
|
||
|
wdb.TA_VEND_PART.SingleOrDefault(
|
||
|
p => p.VendId == qadData.xxqad_vp_addr.ToUpper()
|
||
|
&& p.PartCode == qadData.xxqad_vp_part.ToUpper()
|
||
|
&& p.VendPartCode == qadData.xxqad_vp_vend_part.ToUpper() && p.Site==qadData.xxqad_vp_domain
|
||
|
) ??
|
||
|
new TA_VEND_PART
|
||
|
{
|
||
|
VendId = qadData.xxqad_vp_addr.ToUpper(),//��Ӧ�̱���
|
||
|
PartCode = qadData.xxqad_vp_part.ToUpper(),//��Ӧ���Ϻ�
|
||
|
VendPartCode = qadData.xxqad_vp_vend_part.ToUpper(),//��Ӧ�����Ϻ�
|
||
|
VendPackQty = qadData.xxqad_vp_comment,//��Ӧ�����Ϻ�
|
||
|
//PoUnit = qadData.,//�ɹ���λ
|
||
|
State = 1,//״̬��0��ʧЧ 1:��Ч��
|
||
|
Remark = "",
|
||
|
CreateTime = qadData.xxqad_vp_createdt == null ? DateTime.Now : (DateTime)qadData.xxqad_vp_createdt,//��������
|
||
|
CreateUser = qadData.xxqad_vp_createur,//�����û�
|
||
|
UpdateTime = qadData.xxqad_vp_updatedt,//��������
|
||
|
UpdateUser = qadData.xxqad_vp_updateur,//�����û�
|
||
|
TransportationTime=qadData.xxqad_vp_vend_lead,
|
||
|
IsDeleted = false,
|
||
|
GUID = new Guid()
|
||
|
};
|
||
|
wmsData.Site = string.IsNullOrEmpty(wmsData.Site) ? qadData.xxqad_vp_domain : wmsData.Site;
|
||
|
wmsData.VendPartCode = qadData.xxqad_vp_vend_part?.ToUpper() ?? qadData.xxqad_vp_part.ToUpper();
|
||
|
wmsData.VendPackQty = qadData.xxqad_vp_comment;
|
||
|
wmsData.TransportationTime = qadData.xxqad_vp_vend_lead;
|
||
|
wmsDataList.Add(wmsData);
|
||
|
qadData.xxqad_vp_scmread = ((int)UniApiState.�ɹ�).ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
qadData.xxqad_vp_scmread = ((int)UniApiState.ʧ��).ToString();
|
||
|
qadData.xxqad_vp_rmks += " SCM:" + ex.Message;
|
||
|
}
|
||
|
qadData.xxqad_vp_updateur = ScpCache.Config.SCP�û���;
|
||
|
qadData.xxqad_vp_updatedt = DateTime.Now;
|
||
|
|
||
|
}
|
||
|
wdb.TA_VEND_PART.AddOrUpdate(p=>new { p.PartCode,p.VendId, p.Site }, wmsDataList.ToArray());
|
||
|
Console.WriteLine($"���� ��Ӧ������ ���ݣ�{wmsDataList.Count}");
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ���¹�Ӧ��
|
||
|
/// </summary>
|
||
|
/// <param name="idb"></param>
|
||
|
/// <param name="wdb"></param>
|
||
|
/// <param name="seq"></param>
|
||
|
private static void UpdateVender(UniApiEntities idb, ScpEntities wdb, string seq)
|
||
|
{
|
||
|
var qadDataList = idb.xxqad_vd_mstr.Where(p => p.xxqad_vd_seq == seq ).ToList();
|
||
|
var wmsDataList = new List<TA_VENDER>();
|
||
|
|
||
|
foreach (var qadData in qadDataList)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var wmsData = wdb.TA_VENDER.SingleOrDefault(p => p.VendId == qadData.xxqad_vd_addr.ToUpper() && p.Site==qadData.xxqad_vd_domain) ??
|
||
|
new TA_VENDER { VendId = qadData.xxqad_vd_addr.ToUpper(), VendAbbCode = "0", State = 1 };
|
||
|
wmsData.VendName = string.IsNullOrEmpty(qadData.xxqad_vd_name)?qadData.xxqad_vd_addr:qadData.xxqad_vd_name;
|
||
|
wmsData.VendType = qadData.xxqad_vd_type.ToUpper().ToString();
|
||
|
wmsData.Country = qadData.xxqad_vd_country;
|
||
|
wmsData.City = qadData.xxqad_vd_city;
|
||
|
wmsData.Currency = qadData.xxqad_vd_curr.ToUpper();
|
||
|
wmsData.Address = qadData.xxqad_vd_line1 + qadData.xxqad_vd_line2 + qadData.xxqad_vd_line3;
|
||
|
wmsData.ZipCode = qadData.xxqad_vd_pst_id;
|
||
|
wmsData.Contacter = qadData.xxqad_vd_attn;
|
||
|
wmsData.Phone = qadData.xxqad_vd_phone;
|
||
|
wmsData.Fax = qadData.xxqad_vd_fax;
|
||
|
wmsData.Site = string.IsNullOrEmpty(wmsData.Site)? qadData.xxqad_vd_domain:wmsData.Site;
|
||
|
wmsData.Tax = qadData.xxqad_vd_tax;//˰��
|
||
|
wmsDataList.Add(wmsData);
|
||
|
qadData.xxqad_vd_scmread = ((int)UniApiState.�ɹ�).ToString();
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
qadData.xxqad_vd_scmread = ((int)UniApiState.ʧ��).ToString();
|
||
|
qadData.xxqad_vd_rmks += " SCM:" + ex.Message;
|
||
|
}
|
||
|
qadData.xxqad_vd_updateur = ScpCache.Config.SCP�û���;
|
||
|
qadData.xxqad_vd_updatedt = DateTime.Now;
|
||
|
}
|
||
|
if (wmsDataList.Count == 0)
|
||
|
{
|
||
|
Console.WriteLine("���� ��Ӧ�� ����:"+ seq+"������");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
wdb.TA_VENDER.AddOrUpdate(p=>new {p.VendId,p.Site } ,wmsDataList.ToArray());
|
||
|
Console.WriteLine($"���� ��Ӧ�� ���ݣ�{qadDataList.Count}");
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// ��������
|
||
|
/// </summary>
|
||
|
/// <param name="idb"></param>
|
||
|
/// <param name="wdb"></param>
|
||
|
/// <param name="seq"></param>
|
||
|
private static void UpdateParts(UniApiEntities idb, ScpEntities wdb, string seq)
|
||
|
{
|
||
|
var qadDataList = idb.xxqad_pt_mstr.Where(p => p.xxqad_pt_seq == seq ).ToList();
|
||
|
var wmsDataList = new List<TA_PART>();
|
||
|
foreach (var qadData in qadDataList)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
var wmsData = wdb.TA_PART.SingleOrDefault(p => p.ErpPartCode == qadData.xxqad_pt_part.ToUpper() && p.Site==qadData.xxqad_pt_domain) ??
|
||
|
new TA_PART
|
||
|
{
|
||
|
PartCode = qadData.xxqad_pt_part.ToUpper(),
|
||
|
ErpPartCode = qadData.xxqad_pt_part.ToUpper(),
|
||
|
};
|
||
|
wmsData.PartDesc1 = qadData.xxqad_pt_desc1;
|
||
|
wmsData.PartDesc2 = qadData.xxqad_pt_desc2;
|
||
|
wmsData.ProjectId = qadData.xxqad_pt_group.ToUpper();
|
||
|
wmsData.Unit = !string.IsNullOrEmpty(qadData.xxqad_pt_um)? qadData.xxqad_pt_um.ToUpper():"EA";
|
||
|
wmsData.PartGroup = qadData.xxqad_pt_dsgn_grp.ToUpper();
|
||
|
wmsData.State = qadData.xxqad_pt_status.ToUpper();
|
||
|
wmsData.Site = qadData.xxqad_pt_domain;
|
||
|
|
||
|
wmsDataList.Add(wmsData);
|
||
|
qadData.xxqad_pt_scmread = ((int)UniApiState.�ɹ�).ToString();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
qadData.xxqad_pt_scmread = ((int)UniApiState.ʧ��).ToString();
|
||
|
qadData.xxqad_pt_rmks += " SCM:" + ex.Message;
|
||
|
}
|
||
|
qadData.xxqad_pt_updateur = ScpCache.Config.SCP�û���;
|
||
|
qadData.xxqad_pt_updatedt = DateTime.Now;
|
||
|
}
|
||
|
wdb.TA_PART.AddOrUpdate(p =>new { p.PartCode, p.Site }, wmsDataList.ToArray());
|
||
|
Console.WriteLine($"���� ������Ϣ ���ݣ�{qadDataList.Count}");
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|