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.
982 lines
42 KiB
982 lines
42 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using www.ufida.org.EntityData;
|
|
using System.ServiceModel;
|
|
using UFSoft.UBF.Service;
|
|
using UFSoft.UBF.Util.Context;
|
|
using System.Configuration;
|
|
using ICS.WCF.Base;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Linq;
|
|
using UFIDA.U9.ISV.CreatePriceList;
|
|
//using UFIDA.U9.ISV.CreatePriceList;
|
|
|
|
namespace UFIDA.ISV.CreatePoSrvSub
|
|
{
|
|
//采购订单
|
|
public class CustCallUFIDAISVCreatePoSrvSub
|
|
{
|
|
//无来源采购
|
|
DataTable dtPro;
|
|
public string orgID = "";
|
|
public OperationResult CustCreatePo(List<Pohead> poInfoList)//List<rtnPoinfo>
|
|
{
|
|
StringBuilder strlog1 = new StringBuilder();
|
|
OperationResult RET = new OperationResult();
|
|
#region 服务调用框架结构
|
|
//实例化代理类 UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient
|
|
try
|
|
{
|
|
List<rtnPoinfo> rtnpos = new List<rtnPoinfo>();
|
|
|
|
UFIDAU9ISVPOICreatePOSRVClient client = new UFIDAU9ISVPOICreatePOSRVClient();
|
|
//服务返回结果
|
|
UFIDAU9PMPOPurchaseOrderData[] returnItems;
|
|
//返回异常信息,目前还没有使用此属性
|
|
UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
|
|
//上下文信息
|
|
object context;
|
|
//传入 参数
|
|
UFIDAU9PMDTOsOBAPurchaseOrderDTOData[] pOList;
|
|
//给上下文信息赋值
|
|
//给传入参数赋值
|
|
pOList = SetPoDtos(poInfoList);
|
|
//服务调用
|
|
context = CreateContextObj(orgID);
|
|
|
|
(client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
|
|
(client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
|
|
returnItems = client.Do(out returnMsg, context, pOList);
|
|
|
|
foreach (UFIDAU9PMPOPurchaseOrderData returnInfo in returnItems)
|
|
{
|
|
rtnPoinfo rtnpo = new rtnPoinfo();
|
|
rtnpo.DocNo = returnInfo.m_docNo;
|
|
rtnpo.DocID = returnInfo.m_iD;
|
|
string[] str = GetOperatorByID(returnInfo.PurOper);
|
|
if (str != null)
|
|
{
|
|
rtnpo.OperatorCode = str[0];
|
|
rtnpo.OperatorName = str[1];
|
|
}
|
|
rtnpo.OrgCode = poInfoList[0].OrgCode;
|
|
|
|
List<rtnPoLine> lines = new List<rtnPoLine>();
|
|
foreach (UFIDAU9PMPOPOLineData poline in returnInfo.m_pOLines)
|
|
{
|
|
try
|
|
{
|
|
string pro = null;
|
|
if (string.IsNullOrEmpty(poline.Project.ToString()) || poline.Project == -1)
|
|
{
|
|
if (Appconfig.getPRProject(poline.m_pRID, poline.m_pRLineID) != null)
|
|
{
|
|
pro = Appconfig.getPRProject(poline.m_pRID, poline.m_pRLineID).Rows[0][0].ToString();
|
|
long num = 0;
|
|
if (long.TryParse(pro, out num))
|
|
{
|
|
Appconfig.setPOProject(returnInfo.m_docNo, poline.m_docLineNo, num);//修改行和计划行项目号
|
|
}
|
|
}
|
|
}
|
|
|
|
bool IsToatl = Appconfig.setTotalMny(returnInfo.m_docNo, poline.m_docLineNo);//修改加工费合计
|
|
|
|
rtnPoLine rtnpoline = new rtnPoLine();
|
|
|
|
|
|
rtnpoline.SrcPOID = long.Parse(poline.m_descFlexSegments.m_privateDescSeg26);
|
|
|
|
rtnpoline.lineID = poline.m_iD;
|
|
rtnpoline.LineNo = poline.m_docLineNo;
|
|
rtnpoline.srcDocNo = poline.m_srcDocInfo.m_srcDocNo;
|
|
rtnpoline.srcLineNo = poline.m_srcDocInfo.m_srcDocLineNo;
|
|
rtnpoline.reqQty = poline.m_reqQtyTU;
|
|
|
|
|
|
|
|
//ReqUOMKey
|
|
rtnpoline.proCode = Appconfig.GetProjectCode(poline.Project);
|
|
rtnpoline.ProcessPrice = poline.m_descFlexSegments.m_privateDescSeg13;//加工费
|
|
rtnpoline.TotalProcessPrice = poline.m_descFlexSegments.m_privateDescSeg16;//材料费
|
|
|
|
lines.Add(rtnpoline);
|
|
|
|
}
|
|
catch { }
|
|
|
|
}
|
|
rtnpo.rtnLines = lines.ToArray();
|
|
|
|
rtnpos.Add(rtnpo);
|
|
}
|
|
string m;
|
|
|
|
////创建厂商价目表和厂商价格调整单
|
|
////如果不是单一资源(供应商料品对应关系唯一),供应商不存在则创建厂商价目表,料品不存在则创建厂商价格调整单
|
|
|
|
// CustCallUFIDAISVCreatePriceListSrvSub price = new CustCallUFIDAISVCreatePriceListSrvSub();
|
|
// foreach (Pohead head in poInfoList)
|
|
// {
|
|
// List<UFIDAU9CustCustCreatePriceListSRVPriceDTOData> datas = new List<UFIDAU9CustCustCreatePriceListSRVPriceDTOData>();
|
|
// foreach (PoLine line in head.lines)
|
|
// {
|
|
// //去重复
|
|
// bool s = false;
|
|
// foreach (UFIDAU9CustCustCreatePriceListSRVPriceDTOData b in datas)
|
|
// {
|
|
// if (b.m_itemCode == line.ItemCode)
|
|
// {
|
|
// s = true;
|
|
// }
|
|
// }
|
|
// if (s)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// #region 20190510修改 判断是否单一资源
|
|
|
|
// string _sql_ = @"SELECT * FROM CBO_SupplierItem
|
|
// WHERE ItemInfo_ItemCode = '{0}' AND Effective_IsEffective = 1";
|
|
// _sql_ = string.Format(_sql_, line.ItemCode);
|
|
// DataTable _dtCount = DBhlper.Query(_sql_, Appconfig.GetU9ConnStr());
|
|
// if (_dtCount == null || _dtCount.Rows.Count == 0)
|
|
// {
|
|
// continue;
|
|
// }
|
|
|
|
// string _sql = @"SELECT DISTINCT a.Price,a.ItemInfo_ItemCode,c.SupplierInfo_Supplier FROM PPR_PurPriceLine a
|
|
// LEFT JOIN PPR_PurPriceList b ON a.PurPriceList=b.ID
|
|
// LEFT JOIN CBO_SupplierItem c ON c.SupplierInfo_Supplier=b.Supplier
|
|
// WHERE a.ItemInfo_ItemCode='{0}'
|
|
// AND a.Active=1
|
|
// AND a.FromDate<getdate()
|
|
// AND a.ToDate>getdate() ";
|
|
// _sql = string.Format(_sql, line.ItemCode);
|
|
// DataTable _dt = DBhlper.Query(_sql, Appconfig.GetU9ConnStr());
|
|
|
|
// if (_dt != null && _dt.Rows.Count > 0)
|
|
// {
|
|
// if (_dt.Rows.Count == 1)
|
|
// {
|
|
// decimal _price = decimal.Parse(_dt.Rows[0][0].ToString());
|
|
// if (_price > line.OrderPriceTC || _price < line.OrderPriceTC)
|
|
// {
|
|
// UFIDAU9CustCustCreatePriceListSRVPriceDTOData data = new UFIDAU9CustCustCreatePriceListSRVPriceDTOData();
|
|
// data.m_itemCode = line.ItemCode;
|
|
// data.m_price = line.OrderPriceTC.ToString();
|
|
// data.m_suppCode = head.supplierCode;
|
|
// data.m_tCCode = head.TCCode;
|
|
// data.m_tUom = line.TradeUOM;
|
|
// if (head.DocTypeCode == "PO12" || head.DocTypeCode == "PO14" || head.DocTypeCode == "PO16" || head.DocTypeCode == "PO20")
|
|
// {
|
|
// data.m_isWW = "B";
|
|
// }
|
|
// else
|
|
// {
|
|
// data.m_isWW = "A";
|
|
// }
|
|
// datas.Add(data);
|
|
// }
|
|
// }
|
|
// }
|
|
// else
|
|
// {
|
|
// UFIDAU9CustCustCreatePriceListSRVPriceDTOData data = new UFIDAU9CustCustCreatePriceListSRVPriceDTOData();
|
|
// data.m_itemCode = line.ItemCode;
|
|
// data.m_price = line.OrderPriceTC.ToString();
|
|
// data.m_suppCode = head.supplierCode;
|
|
// data.m_tCCode = head.TCCode;
|
|
// data.m_tUom = line.TradeUOM;
|
|
// if (head.DocTypeCode == "PO12" || head.DocTypeCode == "PO14" || head.DocTypeCode == "PO16" || head.DocTypeCode == "PO20")
|
|
// {
|
|
// data.m_isWW = "B";
|
|
// }
|
|
// else
|
|
// {
|
|
// data.m_isWW = "A";
|
|
// }
|
|
// datas.Add(data);
|
|
// }
|
|
// #endregion
|
|
|
|
// }
|
|
// if (datas.Count > 0)
|
|
// {
|
|
// #region 20190424新增 创建价目调整单
|
|
|
|
// m = price.CustCreateRCV(datas);
|
|
|
|
// StringBuilder str = new StringBuilder();
|
|
// str.AppendLine("创建价表传输数据:");
|
|
// foreach (var item in datas)
|
|
// {
|
|
// str.AppendLine("料号:" + item.m_itemCode);
|
|
// str.AppendLine("价格:" + item.m_price);
|
|
// str.AppendLine("供应商:" + item.m_suppCode);
|
|
// str.AppendLine("交易币种:" + item.m_tCCode);
|
|
// str.AppendLine("单位:" + item.m_tUom);
|
|
// str.AppendLine("单据类型:" + item.m_isWW);
|
|
// str.AppendLine("当前时间:" + DateTime.Now);
|
|
// }
|
|
// str.AppendLine("创建价表调接口返回:" + m.ToString());
|
|
// Appconfig.WriteLogFile(str.ToString(), "logCreatePo");
|
|
|
|
// #endregion
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// Appconfig.WriteLogFile("创建价表:传入数据所有料品都是非单一资源或未生效,传入数据不能为空!", "logCreatePo");
|
|
// }
|
|
|
|
// }
|
|
|
|
return RET;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
try
|
|
{
|
|
Appconfig.WriteLogFile("创建采购订单" + "\r\n异常:\r\n" + GetExceptionMessage(ex) + "\r\n" + ex.Source + ex.Message + ex.TargetSite + ex.StackTrace + ex.Data, "logCreatePo");
|
|
}
|
|
catch { }
|
|
//异常信息捕获
|
|
List<rtnPoinfo> rtnpos = new List<rtnPoinfo>();
|
|
rtnPoinfo rtnpo = new rtnPoinfo();
|
|
rtnpo.Message = GetExceptionMessage(ex);
|
|
rtnpos.Add(rtnpo);
|
|
return RET;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
|
|
#region 给传入参数赋值
|
|
|
|
private UFIDAU9PMDTOsOBAPurchaseOrderDTOData[] SetPoDtos(List<Pohead> poInfoList)
|
|
{
|
|
List<UFIDAU9PMDTOsOBAPurchaseOrderDTOData> pOList = new List<UFIDAU9PMDTOsOBAPurchaseOrderDTOData>();
|
|
|
|
foreach (Pohead poInfoHead in poInfoList)
|
|
{
|
|
|
|
string orgsql = @"select ID from Base_Organization
|
|
where Code='{0}' ";
|
|
orgsql = string.Format(orgsql, poInfoHead.OrgCode);
|
|
DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
|
|
if (orgdt.Rows.Count == 0)
|
|
{
|
|
throw new Exception("组织编码不存在!");
|
|
}
|
|
else
|
|
{
|
|
orgID = orgdt.Rows[0]["ID"].ToString();
|
|
}
|
|
|
|
|
|
UFIDAU9PMDTOsOBAPurchaseOrderDTOData poHead = new UFIDAU9PMDTOsOBAPurchaseOrderDTOData();
|
|
#region
|
|
poHead.m_docNo = poInfoHead.PurchaseOrder;
|
|
|
|
poHead.m_documentType = new UFIDAU9BaseDTOsIDCodeNameDTOData(); //单据类型
|
|
poHead.m_documentType.m_code = poInfoHead.DocTypeCode;
|
|
//poHead.pur = 2;
|
|
poHead.m_businessDate = TimestampToDateTime(poInfoHead.DocDate);
|
|
if (!string.IsNullOrEmpty(poInfoHead.TCCode))
|
|
{
|
|
poHead.m_tC = new UFIDAU9BaseDTOsIDCodeNameDTOData(); //交易币种
|
|
poHead.m_tC.m_code = poInfoHead.TCCode;
|
|
}
|
|
poHead.m_aC = new UFIDAU9BaseDTOsIDCodeNameDTOData(); //核算币种
|
|
poHead.m_aC.m_code = "C001";
|
|
poHead.m_supplier = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
|
|
poHead.m_supplier.m_code = poInfoHead.supplierCode; //供应商
|
|
poHead.m_bizType = poInfoHead.bizType;//标准采购 //业务类型
|
|
//poHead.m_aAIStatus = 2; //poHead.m_priceList = new UFIDAU9BaseDTOsIDCodeNameDTOData();
|
|
//CooperateStep //poHead.m_priceList.m_iD = -1;
|
|
poHead.m_cooperateStep = -1;//抛转阶段
|
|
poHead.m_isPriceIncludeTax = poInfoHead.isPriceIncludeTax; //价格是否含税
|
|
poHead.m_createdOn = DateTime.Now;
|
|
poHead.m_createdBy = ConfigurationManager.AppSettings["userCode"].ToString();
|
|
poHead.m_accountOrg = new UFIDAU9BaseDTOsIDCodeNameDTOData();
|
|
poHead.m_accountOrg.m_code = poInfoHead.OrgCode;// ConfigurationManager.AppSettings["orgCode"].ToString();
|
|
poHead.m_isCentralizePO = false; //是否集中采购
|
|
poHead.m_isDecompose = false; //是否分解
|
|
poHead.m_isDecomposePO = false; //是否分解采购
|
|
poHead.sysState = 0;//系统版本号
|
|
poHead.m_sysVersion = 0;//系统版本号
|
|
//poHead.m_prePayLine.ID=new UFSoft.UBF.Business.BusinessEntity.EntityKey(); = -1;
|
|
poHead.m_cooperateType = -1;
|
|
poHead.m_rtnType = -1;
|
|
poHead.m_modifyOperType = -1;
|
|
poHead.m_matchLayer = 3;
|
|
|
|
//私有段
|
|
poHead.m_descFlexField = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
|
|
//poHead.m_descFlexField.m_privateDescSeg1 = poInfoHead.YPK;
|
|
if (poInfoHead.DocTypeCode == "PO14" || poInfoHead.DocTypeCode == "PO20")
|
|
{
|
|
poHead.m_maxPrepayPercentEditable = true;
|
|
poHead.m_prepayPolicyEditable = true;
|
|
}
|
|
#endregion
|
|
|
|
int num = 0;
|
|
Dictionary<string, decimal> dit = new Dictionary<string, decimal>();
|
|
List<UFIDAU9PMDTOsOBAPOLineDTOData> poLines = new List<UFIDAU9PMDTOsOBAPOLineDTOData>();
|
|
string log = "";
|
|
for (int i = 0; i < poInfoHead.lines.Length; i++)
|
|
{
|
|
|
|
PoLine poInfoLine = poInfoHead.lines[i];//核准数量-转PO数量
|
|
|
|
string srcCode = poInfoLine.srcDocPRNo + poInfoLine.srcDocPRLineNo.ToString();
|
|
|
|
log += "来源信息:" + srcCode + " " + poInfoLine.PurchaseOrder + " " + poInfoLine.PurchaseOrderSeq + " " + poInfoLine.ReqQty;
|
|
|
|
string sql = @"select TotalToPOQtyTU,ApprovedQtyTU
|
|
from PR_PRLine as A inner join [PR_PR] as A1 on (A.[PR] = A1.[ID])
|
|
inner JOIN Base_Organization c ON A1.Org=c.ID
|
|
where A.[DocLineNo]='" + poInfoLine.srcDocPRLineNo + "' and A1.[DocNo]='" + poInfoLine.srcDocPRNo + "' and c.Code='" + poInfoHead.OrgCode + "'";
|
|
//ApprovedQtyTU
|
|
DataTable dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
|
|
if (dt == null || dt.Rows.Count == 0)
|
|
{
|
|
throw new Exception("该请购单在系统中已不存在!");
|
|
}
|
|
else
|
|
{
|
|
string toQty = string.IsNullOrEmpty(dt.Rows[0][0].ToString()) ? "0" : dt.Rows[0][0].ToString();
|
|
string appQty = string.IsNullOrEmpty(dt.Rows[0][1].ToString()) ? "0" : dt.Rows[0][1].ToString();
|
|
|
|
if (!dit.ContainsKey(srcCode))
|
|
dit.Add(srcCode, decimal.Parse(toQty));
|
|
|
|
dit[srcCode] += poInfoLine.ReqQty;
|
|
|
|
if (dit[srcCode] > decimal.Parse(appQty))
|
|
{
|
|
throw new Exception("来源请购单:" + poInfoLine.srcDocPRNo + " 行:" + poInfoLine.srcDocPRLineNo.ToString()
|
|
+ " 已转数量:" + toQty + " +此次下单数量:" + (dit[srcCode] - decimal.Parse(toQty)).ToString() + " 不允许大于核准数量:"
|
|
+ appQty + " " + log);
|
|
}
|
|
}
|
|
|
|
sql = @"select A.[Status] 状态1,
|
|
A1.[Status] as 状态2
|
|
from PR_PR as A
|
|
inner join [PR_PRLine] as A1 on (A.[ID] = A1.[PR])
|
|
inner JOIN Base_Organization c ON A.Org=c.ID
|
|
where 1=1 and A.[DocNo] = '{0}' and A1.DocLineNo='{1}' and c.Code='" + poInfoHead.OrgCode + "'";
|
|
sql = string.Format(sql, poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo);
|
|
dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
|
|
if (dt.Rows[0]["状态1"].ToString() != "2" || dt.Rows[0]["状态2"].ToString() != "2")
|
|
{
|
|
throw new Exception("单号:" + poInfoLine.srcDocPRNo + "\n行号:" + poInfoLine.srcDocPRLineNo + "\n状态异常,U9中必须核准状态才准许转采购!请于 U9中确认。");
|
|
}
|
|
|
|
#region 行 poLine
|
|
UFIDAU9PMDTOsOBAPOLineDTOData poLine = getPoLine(poInfoLine, i, orgID);
|
|
poLines.Add(poLine);
|
|
num = i;
|
|
#endregion
|
|
|
|
}
|
|
|
|
poHead.m_pOLines = poLines.ToArray();
|
|
pOList.Add(poHead);
|
|
}
|
|
return pOList.ToArray();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 提取异常信息
|
|
/// <summary>
|
|
/// 提取异常信息
|
|
/// </summary>
|
|
/// <param name="ex"></param>
|
|
private string GetExceptionMessage(Exception ex)
|
|
{
|
|
string faultMessage = "未知错误,请查看ERP日志!";
|
|
|
|
System.TimeoutException timeoutEx = ex as System.TimeoutException;
|
|
if (timeoutEx != null)
|
|
{
|
|
faultMessage = "访问服务超时,请修改配置信息!";
|
|
}
|
|
else
|
|
{
|
|
FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
|
|
if (faultEx == null)
|
|
{
|
|
faultMessage = ex.Message;
|
|
}
|
|
else
|
|
{
|
|
ServiceException serviceEx = faultEx.Detail;
|
|
if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
|
|
&& !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
// 错误信息在faultEx.Message中,请提取,
|
|
// 格式为"Fault:料品不能为空,请录入\n 在....."
|
|
int startIndex = serviceEx.Message.IndexOf(":");
|
|
int endIndex = serviceEx.Message.IndexOf("\n");
|
|
if (endIndex == -1)
|
|
endIndex = serviceEx.Message.Length;
|
|
if (endIndex > 0 && endIndex > startIndex + 1)
|
|
{
|
|
faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
|
|
}
|
|
else
|
|
{
|
|
faultMessage = serviceEx.Message;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return faultMessage;
|
|
}
|
|
#endregion
|
|
|
|
#region 给上下文信息赋值
|
|
/// <summary>
|
|
/// 给上下文信息赋值
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private ThreadContext CreateContextObj(string OrgID)
|
|
{
|
|
// 实例化应用上下文对象
|
|
ThreadContext thContext = new ThreadContext();
|
|
|
|
System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
|
|
//ns.Add("OrgID", ConfigurationManager.AppSettings["orgID"].ToString());
|
|
ns.Add("OrgID", long.Parse(OrgID));
|
|
|
|
ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
|
|
ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
|
|
ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
|
|
ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
|
|
ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
|
|
thContext.nameValueHas = ns;
|
|
|
|
return thContext;
|
|
}
|
|
#endregion
|
|
|
|
#region 时间戳方法
|
|
private DateTime TimestampToDateTime(long timestamp)
|
|
{
|
|
DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
|
long lTime = timestamp * 10000000;
|
|
TimeSpan nowTimeSpan = new TimeSpan(lTime);
|
|
DateTime resultDateTime = dateTimeStart.Add(nowTimeSpan);
|
|
return resultDateTime;
|
|
}
|
|
#endregion
|
|
|
|
#region 通过ID查找采购员Code,Name
|
|
public string[] GetOperatorByID(long id)
|
|
{
|
|
string[] str = new string[2];
|
|
string sql = @"select A.Code,B.Name
|
|
from CBO_Operators A left join CBO_Operators_Trl B on A.ID=B.ID where A.ID=" + id + "";
|
|
DataTable dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
|
|
//string[] str = new string[2];
|
|
if (dt == null || dt.Rows.Count == 0)
|
|
{ str = null; }
|
|
else
|
|
{
|
|
str[0] = dt.Rows[0][0].ToString();
|
|
str[1] = dt.Rows[0][1].ToString();
|
|
}
|
|
return str;
|
|
}
|
|
#endregion
|
|
|
|
#region 赋值行
|
|
public UFIDAU9PMDTOsOBAPOLineDTOData getPoLine(PoLine poInfoLine, int i, string orgid)
|
|
{
|
|
string project11 = null;
|
|
string PubDescSeg18 = null;
|
|
|
|
|
|
dtPro = Appconfig.getPRProject11(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo);
|
|
if (dtPro != null && dtPro.Rows.Count > 0)
|
|
{
|
|
project11 = dtPro.Rows[0][0].ToString();
|
|
PubDescSeg18 = dtPro.Rows[0][1].ToString();
|
|
}
|
|
UFIDAU9PMDTOsOBAPOLineDTOData poLine = new UFIDAU9PMDTOsOBAPOLineDTOData();
|
|
//if (Appconfig.GetUOMCode(poInfoLine.TradeUOM).Rows.Count == 0 || Appconfig.GetUOMCode(poInfoLine.TradeUOM)==null)
|
|
//{
|
|
// throw new Exception("ERP中不存在该单位" + poInfoLine.TradeUOM);
|
|
//}
|
|
//string uom = Appconfig.GetUOMCode(poInfoLine.TradeUOM).Rows[0][0].ToString();
|
|
//poLine.m_systemPriceTC = poInfoLine.Price;//系统价
|
|
poLine.m_docLineNo = (i + 1) * 10; //行号
|
|
poLine.m_srcDocType = 1; //来源单据类型 1表示请购单
|
|
poLine.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData(); //料号信息
|
|
poLine.m_itemInfo.m_itemCode = poInfoLine.ItemCode;
|
|
poLine.m_itemInfo.m_itemGrade = -1;
|
|
poLine.m_itemInfo.m_itemPotency = -1;//IsPUCanChange
|
|
poLine.m_isPUCanChange = true;
|
|
//poLine.m_isPresent = false; //是否赠品
|
|
if (poInfoLine.OrderPriceTC == 0)
|
|
{
|
|
poLine.m_isPresent = true;
|
|
}
|
|
|
|
poLine.m_kITRcvMode = -1; //成套发货标志
|
|
poLine.m_reqQtyTU = poInfoLine.ReqQty; //需求数量
|
|
if (!string.IsNullOrEmpty(poInfoLine.TradeUOM))
|
|
{
|
|
poLine.m_reqUOM = new UFIDAU9BaseDTOsIDCodeNameDTOData(); //需求计量单位
|
|
poLine.m_reqUOM.m_code = poInfoLine.TradeUOM;
|
|
poLine.m_tradeUOM = new UFIDAU9BaseDTOsIDCodeNameDTOData(); //采购计量单位
|
|
poLine.m_tradeUOM.m_code = poInfoLine.TradeUOM;
|
|
}
|
|
poLine.m_purQtyTU = poInfoLine.ReqQty; //采购数量
|
|
if (!string.IsNullOrEmpty(poInfoLine.ValuationUnit))
|
|
{
|
|
poLine.m_priceUOM = new UFIDAU9BaseDTOsIDCodeNameDTOData();//计价单位
|
|
poLine.m_priceUOM.m_code = poInfoLine.ValuationUnit;
|
|
}
|
|
poLine.m_pRNO = poInfoLine.srcDocPRNo;
|
|
poLine.m_isPresent = poInfoLine.IsPersent;
|
|
|
|
DataTable dt = Appconfig.GetPRDocID(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo);
|
|
if (dt == null || dt.Rows.Count < 1)
|
|
{
|
|
throw new Exception("ERP中不存在该请购单行的数据,请检查是否被删除.单号:" + poInfoLine.srcDocPRNo + ",行号:" + poInfoLine.srcDocPRLineNo);
|
|
}
|
|
poLine.m_pRLineID = long.Parse(dt.Rows[0][1].ToString());
|
|
poLine.m_pRID = long.Parse(dt.Rows[0][0].ToString());
|
|
//poLine.m_supplierConfirmQtyTU = 2; //确认数量
|
|
poLine.m_supplierConfirmQtyPU = poInfoLine.ValuationQty;//确认数量
|
|
poLine.m_descFlexSegments = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
|
|
poLine.m_descFlexSegments.m_privateDescSeg1 = TimestampToDateTime(poInfoLine.SupConfirmDate).ToString();//供应商确认日期
|
|
if (!string.IsNullOrEmpty(project11))
|
|
{
|
|
poLine.m_descFlexSegments.m_pubDescSeg11 = project11;
|
|
}
|
|
|
|
|
|
|
|
//20200810 请购单行18传给采购单行18
|
|
poLine.m_descFlexSegments.m_pubDescSeg18 = PubDescSeg18;
|
|
|
|
//20200319新增行上存储物供传来的长整型
|
|
poLine.m_descFlexSegments.m_privateDescSeg26 = poInfoLine.SrcPOID.ToString();
|
|
|
|
|
|
if (!string.IsNullOrEmpty(poInfoLine.ProCode))
|
|
{
|
|
poLine.m_project = new UFIDAU9BaseDTOsIDCodeNameDTOData();
|
|
long m = 0;
|
|
if (long.TryParse(Appconfig.GetProjectID(poInfoLine.ProCode), out m))
|
|
poLine.m_project.m_iD = m;
|
|
//throw new Exception("ERP中不存在该项目号:" + poInfoLine.ProCode);
|
|
}
|
|
poLine.m_demondCode = -1; //需求分类
|
|
|
|
poLine.m_isSpilted = false; //已分割
|
|
poLine.m_isRefill = false; //替代件
|
|
|
|
|
|
poLine.m_isPriceModify = true; //价格可改
|
|
poLine.m_priceSource = 1; //价格来源
|
|
|
|
|
|
#region 20190410注释
|
|
|
|
//20190417
|
|
//poLine.m_netFinallyPriceFC = poInfoLine.NetFinallyPriceAC;
|
|
//poLine.m_netMnyAC = poInfoLine.NetMnyAC;
|
|
|
|
if (poInfoLine.OrderPriceTC > 0)
|
|
{
|
|
poLine.m_orderPriceTC = poInfoLine.OrderPriceTC; //定价
|
|
poLine.m_srcDocFinallyPriceTC = poInfoLine.OrderPriceTC;
|
|
poLine.m_finallyPriceTC = poInfoLine.OrderPriceTC; //最终价 单价(含税)
|
|
}
|
|
|
|
//poLine.m_totalMnyTC = poInfoLine.OrderTotalTC;//价税合计
|
|
if (poInfoLine.OrderTotalTC > 0)
|
|
{
|
|
poLine.m_netMnyTC = poInfoLine.OrderTotalTC;//价税合计
|
|
}
|
|
#endregion
|
|
|
|
poLine.m_createdOn = DateTime.Now;
|
|
poLine.m_createdBy = ConfigurationManager.AppSettings["userCode"].ToString();
|
|
|
|
if (poInfoLine.TaxRate > 0)
|
|
{
|
|
poLine.m_taxRate = poInfoLine.TaxRate; //税率
|
|
}
|
|
|
|
poLine.m_srcDocInfo = new UFIDAU9CBOSCMPropertyTypesSrcDocInfoData();
|
|
//poLine.m_srcDocInfo.m_srcDocBusiType = -1;
|
|
poLine.m_srcDocInfo.SrcDocOrg_SKey = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
|
|
poLine.m_srcDocInfo.SrcDocOrg_SKey.ID = long.Parse(orgid);// long.Parse(ConfigurationManager.AppSettings["orgID"].ToString());
|
|
// = 1001604180010013;
|
|
//poLine.m_srcDocInfo.m_srcDocVer = 1;
|
|
poLine.m_srcDocInfo.m_srcDocNo = poInfoLine.srcDocPRNo; //来源单据号
|
|
poLine.m_srcDocInfo.m_srcDoc = new UFIDAU9BasePropertyTypesBizEntityKeyData();
|
|
//poLine.m_srcDocInfo.m_srcDocLineNo = poInfoLine.srcDocPRLineNo; //来源单据行号C:\Users\Administrator\Desktop\WCF\UFIDA.U9.ZHC\UFIDA.ISV.CreatePoSrvSub\CustCallUFIDAISVCreatePoSrvSub.cs
|
|
poLine.m_srcDocInfo.m_srcDoc.m_entityID = long.Parse(Appconfig.GetPRDocID(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo).Rows[0][0].ToString());
|
|
poLine.m_srcDocInfo.m_srcDoc.m_entityType = "UFIDA.U9.PR.PurchaseRequest.PR";
|
|
|
|
poLine.m_srcDocInfo.m_srcDocLineNo = poInfoLine.srcDocPRLineNo; //来源单据行号
|
|
poLine.m_srcDocInfo.m_srcDocLine = new UFIDAU9BasePropertyTypesBizEntityKeyData();
|
|
poLine.m_srcDocInfo.m_srcDocLine.m_entityID = long.Parse(Appconfig.GetPRDocID(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo).Rows[0][1].ToString());
|
|
poLine.m_srcDocInfo.m_srcDocLine.m_entityType = "UFIDA.U9.PR.PurchaseRequest.PRLine";
|
|
|
|
poLine.m_demondCode = -1; //需求分类
|
|
|
|
UFIDAU9PMDTOsOBAPOShipLineDTOData pOShipline = new www.ufida.org.EntityData.UFIDAU9PMDTOsOBAPOShipLineDTOData();
|
|
#region 计划行
|
|
|
|
pOShipline.m_srcDocType = 1;
|
|
pOShipline.m_srcDocInfo = new UFIDAU9CBOSCMPropertyTypesSrcDocInfoData();
|
|
pOShipline.m_srcDocInfo.m_srcDocBusiType = -1;
|
|
pOShipline.m_srcDocInfo.SrcDocOrg_SKey = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
|
|
pOShipline.m_srcDocInfo.SrcDocOrg_SKey.ID = long.Parse(orgid);// long.Parse(ConfigurationManager.AppSettings["orgID"].ToString());
|
|
// = 1001604180010013;
|
|
pOShipline.m_srcDocInfo.m_srcDocVer = 1;
|
|
pOShipline.m_srcDocInfo.m_srcDocNo = poInfoLine.srcDocPRNo; //来源单据号
|
|
pOShipline.m_srcDocInfo.m_srcDoc = new UFIDAU9BasePropertyTypesBizEntityKeyData();
|
|
pOShipline.m_srcDocInfo.m_srcDoc.m_entityID = long.Parse(Appconfig.GetPRDocID(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo).Rows[0][0].ToString());
|
|
pOShipline.m_srcDocInfo.m_srcDoc.m_entityType = "UFIDA.U9.PR.PurchaseRequest.PR";
|
|
|
|
pOShipline.m_srcDocInfo.m_srcDocLineNo = poInfoLine.srcDocPRLineNo; //来源单据行号
|
|
pOShipline.m_srcDocInfo.m_srcDocLine = new UFIDAU9BasePropertyTypesBizEntityKeyData();
|
|
pOShipline.m_srcDocInfo.m_srcDocLine.m_entityID = long.Parse(Appconfig.GetPRDocID(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo).Rows[0][1].ToString());
|
|
pOShipline.m_srcDocInfo.m_srcDocLine.m_entityType = "UFIDA.U9.PR.PurchaseRequest.PRLine";
|
|
|
|
//pOShipline.m_srcDocInfo.m_srcDocTransType = new UFIDAU9BasePropertyTypesBizEntityKeyData(); //原单据类型
|
|
//pOShipline.m_srcDocInfo.m_srcDocTransType.m_entityID = 1001604181460401;
|
|
//pOShipline.m_srcDocInfo.m_srcDocTransType.m_entityType = "UFIDA.U9.PR.PurchaseRequest.PRDocType";
|
|
|
|
//pOShipline.m_subLineNo = 10;
|
|
|
|
pOShipline.m_rcvShipBy = 2; // 收发货依据
|
|
pOShipline.m_demondCode = -1; //需求分类
|
|
if (poInfoLine.RequireDate > 0)
|
|
{
|
|
pOShipline.m_deliveryDate = TimestampToDateTime(poInfoLine.RequireDate); // 要求交货日
|
|
|
|
pOShipline.m_preMaturityDate = TimestampToDateTime(poInfoLine.RequireDate);
|
|
pOShipline.m_planArriveDate = TimestampToDateTime(poInfoLine.RequireDate);
|
|
pOShipline.m_needPODate = TimestampToDateTime(poInfoLine.RequireDate);
|
|
}
|
|
//else
|
|
//{
|
|
// pOShipline.m_deliveryDate = DateTime.Now.AddMonths(1); // 要求交货日
|
|
// pOShipline.m_preMaturityDate = DateTime.Now.AddMonths(1);
|
|
// pOShipline.m_planArriveDate = DateTime.Now.AddMonths(1);
|
|
// pOShipline.m_needPODate = DateTime.Now.AddMonths(1);
|
|
//}
|
|
pOShipline.m_centralizedPurType = -1; //集中采购类型
|
|
if (!string.IsNullOrEmpty(poInfoLine.ProCode))
|
|
{
|
|
pOShipline.m_project = new UFIDAU9BaseDTOsIDCodeNameDTOData();
|
|
long m = 0;
|
|
if (long.TryParse(Appconfig.GetProjectID(poInfoLine.ProCode), out m))
|
|
pOShipline.m_project.m_iD = m;
|
|
}
|
|
pOShipline.m_descFlexSegments = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
|
|
if (!string.IsNullOrEmpty(project11))
|
|
{
|
|
pOShipline.m_descFlexSegments.m_pubDescSeg11 = project11;
|
|
}
|
|
#endregion
|
|
//poLine.m_pOShiplines = new UFIDAU9PMDTOsOBAPOShipLineDTOData[1];
|
|
List<UFIDAU9PMDTOsOBAPOShipLineDTOData> ships = new List<UFIDAU9PMDTOsOBAPOShipLineDTOData>();
|
|
ships.Add(pOShipline);
|
|
|
|
poLine.m_pOShiplines = ships.ToArray();
|
|
//poLine.m_pOShiplines[0].m_project = new UFIDAU9BaseDTOsIDCodeNameDTOData();
|
|
//poLine.m_pOShiplines[0].m_project.m_code = poInfoLine.ProCode;
|
|
return poLine;
|
|
}
|
|
#endregion
|
|
|
|
#region 去重&叠加相同数量的料号
|
|
public List<PoLine> selectItemCode(List<PoLine> pOLines)
|
|
{
|
|
for (int i = 0; i < pOLines.Count; i++)
|
|
{
|
|
for (int j = pOLines.Count - 1; j > i; j--)
|
|
{
|
|
if (pOLines[i].ItemCode.ToString() == pOLines[j].ItemCode.ToString())
|
|
{
|
|
pOLines[i].ReqQty += pOLines[j].ReqQty;
|
|
pOLines.RemoveAt(j);
|
|
}
|
|
}
|
|
}
|
|
return pOLines;
|
|
}
|
|
#endregion
|
|
|
|
#region 获取最小采购量
|
|
public int getMinPR(string itemCode)
|
|
{
|
|
string sql = @"select A1.[DescFlexField_PrivateDescSeg12] as PurchaseBatchQty
|
|
from [CBO_ItemMaster] as A1 where A1.Code='" + itemCode + "'";
|
|
DataTable dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
|
|
if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0][0].ToString()))
|
|
{
|
|
return int.Parse(dt.Rows[0][0].ToString());
|
|
}
|
|
else
|
|
{
|
|
return -1;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 汇总因最小采购量的拆行
|
|
public List<PoLine> scatterLines(PoLine[] pOLines1)
|
|
{
|
|
List<PoLine> pOLines = new List<PoLine>(pOLines1);
|
|
List<PoLine> lines = selectItemCode(pOLines);
|
|
int j = lines.Count;
|
|
for (int i = j - 1; i > -1; i--)
|
|
{
|
|
int min = getMinPR(lines[i].ItemCode);
|
|
if (min == 0 || min == -1)
|
|
{
|
|
lines.Remove(lines[i]);
|
|
continue;
|
|
}
|
|
int num = int.Parse(lines[i].ReqQty.ToString());
|
|
int num1 = num / min;
|
|
int num2 = (num1 + 1) * min - num;
|
|
//if(num1==0)
|
|
//{
|
|
// continue;
|
|
//}
|
|
lines[i].ReqQty = num2;
|
|
lines[i].ProCode = "";
|
|
lines[i].ValuationQty = num2;
|
|
}
|
|
return lines;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
#region 上下文类信息
|
|
public class contextInfo
|
|
{
|
|
private long _OrgID;
|
|
private string _OrgCode;
|
|
private long _UserID;
|
|
private string _UserCode;
|
|
private DateTime _Datetime;
|
|
private string _CultureName;
|
|
private string _EnterpriseID;
|
|
|
|
|
|
/// <summary>
|
|
/// 组织ID
|
|
/// </summary>
|
|
public long OrgID
|
|
{
|
|
get { return _OrgID; }
|
|
set { _OrgID = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 组织编码
|
|
/// </summary>
|
|
public string OrgCode
|
|
{
|
|
get { return _OrgCode; }
|
|
set { _OrgCode = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 操作员ID
|
|
/// </summary>
|
|
public long UserID
|
|
{
|
|
get { return _UserID; }
|
|
set { _UserID = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 操作员编码
|
|
/// </summary>
|
|
public string UserCode
|
|
{
|
|
get { return _UserCode; }
|
|
set { _UserCode = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 时间
|
|
/// </summary>
|
|
public DateTime Datetime
|
|
{
|
|
get { return _Datetime; }
|
|
set { _Datetime = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 语言
|
|
/// </summary>
|
|
public string CultureName
|
|
{
|
|
get { return _CultureName; }
|
|
set { _CultureName = value; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 企业ID号
|
|
/// </summary>
|
|
public string EnterpriseID
|
|
{
|
|
get { return _EnterpriseID; }
|
|
set { _EnterpriseID = value; }
|
|
}
|
|
|
|
public contextInfo()
|
|
{
|
|
CultureName = "zh_CN";
|
|
Datetime = DateTime.Now;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 表头类
|
|
public class Pohead
|
|
{
|
|
|
|
/// 单据类型
|
|
public string DocTypeCode { get; set; }
|
|
/// 单据日期
|
|
public long DocDate { get; set; }
|
|
/// 采购单单据号
|
|
public string PurchaseOrder { get; set; }
|
|
/// 交易币种
|
|
public string TCCode { get; set; }
|
|
/// 供应商
|
|
public string supplierCode { get; set; }
|
|
/// 价格是否含税
|
|
public bool isPriceIncludeTax { get; set; }
|
|
public PoLine[] lines { get; set; }
|
|
/// 采购单单据类型
|
|
public int bizType;
|
|
//组织
|
|
public string OrgCode { get; set; }
|
|
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 表体类
|
|
public class PoLine
|
|
{
|
|
|
|
public long SrcPOID { get; set; }
|
|
// 采购订单号
|
|
public string PurchaseOrder { get; set; }
|
|
// 采购订单行号
|
|
public int PurchaseOrderSeq { get; set; }
|
|
/// 料号
|
|
public string ItemCode { get; set; }
|
|
/// 单位
|
|
public string TradeUOM { get; set; }
|
|
/// 数量
|
|
public decimal ReqQty { get; set; }
|
|
/// 价格
|
|
public decimal OrderPriceTC { get; set; }
|
|
/// 金额
|
|
public decimal OrderTotalTC { get; set; }
|
|
/// 税率
|
|
public decimal TaxRate { get; set; }
|
|
//来源请购单单号
|
|
public string srcDocPRNo { get; set; }
|
|
//来源请购单单行号
|
|
public int srcDocPRLineNo { get; set; }
|
|
/// 供应商交期
|
|
public long RequireDate { get; set; }
|
|
/// 供应商确认日期
|
|
public long SupConfirmDate { get; set; }
|
|
/// 计价单位
|
|
public string ValuationUnit { get; set; }
|
|
/// 计价数量
|
|
public decimal ValuationQty { get; set; }
|
|
// 项目号
|
|
public string ProCode { get; set; }
|
|
|
|
//是否分割
|
|
public int IsSpilt { get; set; }
|
|
|
|
//是否赠品
|
|
public bool IsPersent { get; set; }
|
|
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 返回信息类
|
|
public class rtnPoinfo
|
|
{
|
|
public string DocNo { get; set; }
|
|
public string Message { get; set; }
|
|
public long DocID { get; set; }
|
|
public string OperatorCode { get; set; }
|
|
public string OperatorName { get; set; }
|
|
|
|
public string OrgCode { get; set; }
|
|
|
|
|
|
public rtnPoLine[] rtnLines { get; set; }
|
|
}
|
|
|
|
public class rtnPoLine
|
|
{
|
|
//20200319新增长整形字段最后再返回给物供
|
|
public long SrcPOID { get; set; }
|
|
|
|
|
|
public int LineNo { get; set; }
|
|
|
|
public long lineID { get; set; }
|
|
|
|
public string srcDocNo { get; set; }
|
|
|
|
public int srcLineNo { get; set; }
|
|
|
|
public decimal reqQty { get; set; }
|
|
|
|
public string tc { get; set; }
|
|
|
|
public string proCode { get; set; }
|
|
|
|
public string ProcessPrice { get; set; }//加工费
|
|
|
|
public string TotalProcessPrice { get; set; }//材料费
|
|
}
|
|
|
|
|
|
public class OperationResult
|
|
{
|
|
public bool IsSuccess { get; set; }
|
|
public string MESSAGE { get; set; }
|
|
public string SuppCode { get; set; }
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
|