圣珀
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

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using www.ufida.org.EntityData;
  4. using System.ServiceModel;
  5. using UFSoft.UBF.Service;
  6. using UFSoft.UBF.Util.Context;
  7. using System.Configuration;
  8. using ICS.WCF.Base;
  9. using System.Data;
  10. using System.Text;
  11. using System.Linq;
  12. using UFIDA.U9.ISV.CreatePriceList;
  13. //using UFIDA.U9.ISV.CreatePriceList;
  14. namespace UFIDA.ISV.CreatePoSrvSub
  15. {
  16. //采购订单
  17. public class CustCallUFIDAISVCreatePoSrvSub
  18. {
  19. //无来源采购
  20. DataTable dtPro;
  21. public string orgID = "";
  22. public OperationResult CustCreatePo(List<Pohead> poInfoList)//List<rtnPoinfo>
  23. {
  24. StringBuilder strlog1 = new StringBuilder();
  25. OperationResult RET = new OperationResult();
  26. #region 服务调用框架结构
  27. //实例化代理类 UFIDAU9ISVItemIBatchCreateItemByDTOSRVClient
  28. try
  29. {
  30. List<rtnPoinfo> rtnpos = new List<rtnPoinfo>();
  31. UFIDAU9ISVPOICreatePOSRVClient client = new UFIDAU9ISVPOICreatePOSRVClient();
  32. //服务返回结果
  33. UFIDAU9PMPOPurchaseOrderData[] returnItems;
  34. //返回异常信息,目前还没有使用此属性
  35. UFSoft.UBF.Exceptions1.MessageBase[] returnMsg;
  36. //上下文信息
  37. object context;
  38. //传入 参数
  39. UFIDAU9PMDTOsOBAPurchaseOrderDTOData[] pOList;
  40. //给上下文信息赋值
  41. //给传入参数赋值
  42. pOList = SetPoDtos(poInfoList);
  43. //服务调用
  44. context = CreateContextObj(orgID);
  45. (client.Endpoint.Binding as BasicHttpBinding).MaxReceivedMessageSize = int.MaxValue;
  46. (client.Endpoint.Binding as BasicHttpBinding).MaxBufferSize = int.MaxValue;
  47. returnItems = client.Do(out returnMsg, context, pOList);
  48. foreach (UFIDAU9PMPOPurchaseOrderData returnInfo in returnItems)
  49. {
  50. rtnPoinfo rtnpo = new rtnPoinfo();
  51. rtnpo.DocNo = returnInfo.m_docNo;
  52. rtnpo.DocID = returnInfo.m_iD;
  53. string[] str = GetOperatorByID(returnInfo.PurOper);
  54. if (str != null)
  55. {
  56. rtnpo.OperatorCode = str[0];
  57. rtnpo.OperatorName = str[1];
  58. }
  59. rtnpo.OrgCode = poInfoList[0].OrgCode;
  60. List<rtnPoLine> lines = new List<rtnPoLine>();
  61. foreach (UFIDAU9PMPOPOLineData poline in returnInfo.m_pOLines)
  62. {
  63. try
  64. {
  65. string pro = null;
  66. if (string.IsNullOrEmpty(poline.Project.ToString()) || poline.Project == -1)
  67. {
  68. if (Appconfig.getPRProject(poline.m_pRID, poline.m_pRLineID) != null)
  69. {
  70. pro = Appconfig.getPRProject(poline.m_pRID, poline.m_pRLineID).Rows[0][0].ToString();
  71. long num = 0;
  72. if (long.TryParse(pro, out num))
  73. {
  74. Appconfig.setPOProject(returnInfo.m_docNo, poline.m_docLineNo, num);//修改行和计划行项目号
  75. }
  76. }
  77. }
  78. bool IsToatl = Appconfig.setTotalMny(returnInfo.m_docNo, poline.m_docLineNo);//修改加工费合计
  79. rtnPoLine rtnpoline = new rtnPoLine();
  80. rtnpoline.SrcPOID = long.Parse(poline.m_descFlexSegments.m_privateDescSeg26);
  81. rtnpoline.lineID = poline.m_iD;
  82. rtnpoline.LineNo = poline.m_docLineNo;
  83. rtnpoline.srcDocNo = poline.m_srcDocInfo.m_srcDocNo;
  84. rtnpoline.srcLineNo = poline.m_srcDocInfo.m_srcDocLineNo;
  85. rtnpoline.reqQty = poline.m_reqQtyTU;
  86. //ReqUOMKey
  87. rtnpoline.proCode = Appconfig.GetProjectCode(poline.Project);
  88. rtnpoline.ProcessPrice = poline.m_descFlexSegments.m_privateDescSeg13;//加工费
  89. rtnpoline.TotalProcessPrice = poline.m_descFlexSegments.m_privateDescSeg16;//材料费
  90. lines.Add(rtnpoline);
  91. }
  92. catch { }
  93. }
  94. rtnpo.rtnLines = lines.ToArray();
  95. rtnpos.Add(rtnpo);
  96. }
  97. string m;
  98. ////创建厂商价目表和厂商价格调整单
  99. ////如果不是单一资源(供应商料品对应关系唯一),供应商不存在则创建厂商价目表,料品不存在则创建厂商价格调整单
  100. // CustCallUFIDAISVCreatePriceListSrvSub price = new CustCallUFIDAISVCreatePriceListSrvSub();
  101. // foreach (Pohead head in poInfoList)
  102. // {
  103. // List<UFIDAU9CustCustCreatePriceListSRVPriceDTOData> datas = new List<UFIDAU9CustCustCreatePriceListSRVPriceDTOData>();
  104. // foreach (PoLine line in head.lines)
  105. // {
  106. // //去重复
  107. // bool s = false;
  108. // foreach (UFIDAU9CustCustCreatePriceListSRVPriceDTOData b in datas)
  109. // {
  110. // if (b.m_itemCode == line.ItemCode)
  111. // {
  112. // s = true;
  113. // }
  114. // }
  115. // if (s)
  116. // {
  117. // continue;
  118. // }
  119. // #region 20190510修改 判断是否单一资源
  120. // string _sql_ = @"SELECT * FROM CBO_SupplierItem
  121. // WHERE ItemInfo_ItemCode = '{0}' AND Effective_IsEffective = 1";
  122. // _sql_ = string.Format(_sql_, line.ItemCode);
  123. // DataTable _dtCount = DBhlper.Query(_sql_, Appconfig.GetU9ConnStr());
  124. // if (_dtCount == null || _dtCount.Rows.Count == 0)
  125. // {
  126. // continue;
  127. // }
  128. // string _sql = @"SELECT DISTINCT a.Price,a.ItemInfo_ItemCode,c.SupplierInfo_Supplier FROM PPR_PurPriceLine a
  129. // LEFT JOIN PPR_PurPriceList b ON a.PurPriceList=b.ID
  130. // LEFT JOIN CBO_SupplierItem c ON c.SupplierInfo_Supplier=b.Supplier
  131. // WHERE a.ItemInfo_ItemCode='{0}'
  132. // AND a.Active=1
  133. // AND a.FromDate<getdate()
  134. // AND a.ToDate>getdate() ";
  135. // _sql = string.Format(_sql, line.ItemCode);
  136. // DataTable _dt = DBhlper.Query(_sql, Appconfig.GetU9ConnStr());
  137. // if (_dt != null && _dt.Rows.Count > 0)
  138. // {
  139. // if (_dt.Rows.Count == 1)
  140. // {
  141. // decimal _price = decimal.Parse(_dt.Rows[0][0].ToString());
  142. // if (_price > line.OrderPriceTC || _price < line.OrderPriceTC)
  143. // {
  144. // UFIDAU9CustCustCreatePriceListSRVPriceDTOData data = new UFIDAU9CustCustCreatePriceListSRVPriceDTOData();
  145. // data.m_itemCode = line.ItemCode;
  146. // data.m_price = line.OrderPriceTC.ToString();
  147. // data.m_suppCode = head.supplierCode;
  148. // data.m_tCCode = head.TCCode;
  149. // data.m_tUom = line.TradeUOM;
  150. // if (head.DocTypeCode == "PO12" || head.DocTypeCode == "PO14" || head.DocTypeCode == "PO16" || head.DocTypeCode == "PO20")
  151. // {
  152. // data.m_isWW = "B";
  153. // }
  154. // else
  155. // {
  156. // data.m_isWW = "A";
  157. // }
  158. // datas.Add(data);
  159. // }
  160. // }
  161. // }
  162. // else
  163. // {
  164. // UFIDAU9CustCustCreatePriceListSRVPriceDTOData data = new UFIDAU9CustCustCreatePriceListSRVPriceDTOData();
  165. // data.m_itemCode = line.ItemCode;
  166. // data.m_price = line.OrderPriceTC.ToString();
  167. // data.m_suppCode = head.supplierCode;
  168. // data.m_tCCode = head.TCCode;
  169. // data.m_tUom = line.TradeUOM;
  170. // if (head.DocTypeCode == "PO12" || head.DocTypeCode == "PO14" || head.DocTypeCode == "PO16" || head.DocTypeCode == "PO20")
  171. // {
  172. // data.m_isWW = "B";
  173. // }
  174. // else
  175. // {
  176. // data.m_isWW = "A";
  177. // }
  178. // datas.Add(data);
  179. // }
  180. // #endregion
  181. // }
  182. // if (datas.Count > 0)
  183. // {
  184. // #region 20190424新增 创建价目调整单
  185. // m = price.CustCreateRCV(datas);
  186. // StringBuilder str = new StringBuilder();
  187. // str.AppendLine("创建价表传输数据:");
  188. // foreach (var item in datas)
  189. // {
  190. // str.AppendLine("料号:" + item.m_itemCode);
  191. // str.AppendLine("价格:" + item.m_price);
  192. // str.AppendLine("供应商:" + item.m_suppCode);
  193. // str.AppendLine("交易币种:" + item.m_tCCode);
  194. // str.AppendLine("单位:" + item.m_tUom);
  195. // str.AppendLine("单据类型:" + item.m_isWW);
  196. // str.AppendLine("当前时间:" + DateTime.Now);
  197. // }
  198. // str.AppendLine("创建价表调接口返回:" + m.ToString());
  199. // Appconfig.WriteLogFile(str.ToString(), "logCreatePo");
  200. // #endregion
  201. // }
  202. // else
  203. // {
  204. // Appconfig.WriteLogFile("创建价表:传入数据所有料品都是非单一资源或未生效,传入数据不能为空!", "logCreatePo");
  205. // }
  206. // }
  207. return RET;
  208. }
  209. catch (Exception ex)
  210. {
  211. try
  212. {
  213. Appconfig.WriteLogFile("创建采购订单" + "\r\n异常:\r\n" + GetExceptionMessage(ex) + "\r\n" + ex.Source + ex.Message + ex.TargetSite + ex.StackTrace + ex.Data, "logCreatePo");
  214. }
  215. catch { }
  216. //异常信息捕获
  217. List<rtnPoinfo> rtnpos = new List<rtnPoinfo>();
  218. rtnPoinfo rtnpo = new rtnPoinfo();
  219. rtnpo.Message = GetExceptionMessage(ex);
  220. rtnpos.Add(rtnpo);
  221. return RET;
  222. }
  223. #endregion
  224. }
  225. #region 给传入参数赋值
  226. private UFIDAU9PMDTOsOBAPurchaseOrderDTOData[] SetPoDtos(List<Pohead> poInfoList)
  227. {
  228. List<UFIDAU9PMDTOsOBAPurchaseOrderDTOData> pOList = new List<UFIDAU9PMDTOsOBAPurchaseOrderDTOData>();
  229. foreach (Pohead poInfoHead in poInfoList)
  230. {
  231. string orgsql = @"select ID from Base_Organization
  232. where Code='{0}' ";
  233. orgsql = string.Format(orgsql, poInfoHead.OrgCode);
  234. DataTable orgdt = DBhlper.Query(orgsql, Appconfig.GetU9ConnStr());
  235. if (orgdt.Rows.Count == 0)
  236. {
  237. throw new Exception("组织编码不存在!");
  238. }
  239. else
  240. {
  241. orgID = orgdt.Rows[0]["ID"].ToString();
  242. }
  243. UFIDAU9PMDTOsOBAPurchaseOrderDTOData poHead = new UFIDAU9PMDTOsOBAPurchaseOrderDTOData();
  244. #region
  245. poHead.m_docNo = poInfoHead.PurchaseOrder;
  246. poHead.m_documentType = new UFIDAU9BaseDTOsIDCodeNameDTOData(); //单据类型
  247. poHead.m_documentType.m_code = poInfoHead.DocTypeCode;
  248. //poHead.pur = 2;
  249. poHead.m_businessDate = TimestampToDateTime(poInfoHead.DocDate);
  250. if (!string.IsNullOrEmpty(poInfoHead.TCCode))
  251. {
  252. poHead.m_tC = new UFIDAU9BaseDTOsIDCodeNameDTOData(); //交易币种
  253. poHead.m_tC.m_code = poInfoHead.TCCode;
  254. }
  255. poHead.m_aC = new UFIDAU9BaseDTOsIDCodeNameDTOData(); //核算币种
  256. poHead.m_aC.m_code = "C001";
  257. poHead.m_supplier = new UFIDAU9CBOSCMSupplierSupplierMISCInfoData();
  258. poHead.m_supplier.m_code = poInfoHead.supplierCode; //供应商
  259. poHead.m_bizType = poInfoHead.bizType;//标准采购 //业务类型
  260. //poHead.m_aAIStatus = 2; //poHead.m_priceList = new UFIDAU9BaseDTOsIDCodeNameDTOData();
  261. //CooperateStep //poHead.m_priceList.m_iD = -1;
  262. poHead.m_cooperateStep = -1;//抛转阶段
  263. poHead.m_isPriceIncludeTax = poInfoHead.isPriceIncludeTax; //价格是否含税
  264. poHead.m_createdOn = DateTime.Now;
  265. poHead.m_createdBy = ConfigurationManager.AppSettings["userCode"].ToString();
  266. poHead.m_accountOrg = new UFIDAU9BaseDTOsIDCodeNameDTOData();
  267. poHead.m_accountOrg.m_code = poInfoHead.OrgCode;// ConfigurationManager.AppSettings["orgCode"].ToString();
  268. poHead.m_isCentralizePO = false; //是否集中采购
  269. poHead.m_isDecompose = false; //是否分解
  270. poHead.m_isDecomposePO = false; //是否分解采购
  271. poHead.sysState = 0;//系统版本号
  272. poHead.m_sysVersion = 0;//系统版本号
  273. //poHead.m_prePayLine.ID=new UFSoft.UBF.Business.BusinessEntity.EntityKey(); = -1;
  274. poHead.m_cooperateType = -1;
  275. poHead.m_rtnType = -1;
  276. poHead.m_modifyOperType = -1;
  277. poHead.m_matchLayer = 3;
  278. //私有段
  279. poHead.m_descFlexField = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
  280. //poHead.m_descFlexField.m_privateDescSeg1 = poInfoHead.YPK;
  281. if (poInfoHead.DocTypeCode == "PO14" || poInfoHead.DocTypeCode == "PO20")
  282. {
  283. poHead.m_maxPrepayPercentEditable = true;
  284. poHead.m_prepayPolicyEditable = true;
  285. }
  286. #endregion
  287. int num = 0;
  288. Dictionary<string, decimal> dit = new Dictionary<string, decimal>();
  289. List<UFIDAU9PMDTOsOBAPOLineDTOData> poLines = new List<UFIDAU9PMDTOsOBAPOLineDTOData>();
  290. string log = "";
  291. for (int i = 0; i < poInfoHead.lines.Length; i++)
  292. {
  293. PoLine poInfoLine = poInfoHead.lines[i];//核准数量-转PO数量
  294. string srcCode = poInfoLine.srcDocPRNo + poInfoLine.srcDocPRLineNo.ToString();
  295. log += "来源信息:" + srcCode + " " + poInfoLine.PurchaseOrder + " " + poInfoLine.PurchaseOrderSeq + " " + poInfoLine.ReqQty;
  296. string sql = @"select TotalToPOQtyTU,ApprovedQtyTU
  297. from PR_PRLine as A inner join [PR_PR] as A1 on (A.[PR] = A1.[ID])
  298. inner JOIN Base_Organization c ON A1.Org=c.ID
  299. where A.[DocLineNo]='" + poInfoLine.srcDocPRLineNo + "' and A1.[DocNo]='" + poInfoLine.srcDocPRNo + "' and c.Code='" + poInfoHead.OrgCode + "'";
  300. //ApprovedQtyTU
  301. DataTable dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  302. if (dt == null || dt.Rows.Count == 0)
  303. {
  304. throw new Exception("该请购单在系统中已不存在!");
  305. }
  306. else
  307. {
  308. string toQty = string.IsNullOrEmpty(dt.Rows[0][0].ToString()) ? "0" : dt.Rows[0][0].ToString();
  309. string appQty = string.IsNullOrEmpty(dt.Rows[0][1].ToString()) ? "0" : dt.Rows[0][1].ToString();
  310. if (!dit.ContainsKey(srcCode))
  311. dit.Add(srcCode, decimal.Parse(toQty));
  312. dit[srcCode] += poInfoLine.ReqQty;
  313. if (dit[srcCode] > decimal.Parse(appQty))
  314. {
  315. throw new Exception("来源请购单:" + poInfoLine.srcDocPRNo + " 行:" + poInfoLine.srcDocPRLineNo.ToString()
  316. + " 已转数量:" + toQty + " +此次下单数量:" + (dit[srcCode] - decimal.Parse(toQty)).ToString() + " 不允许大于核准数量:"
  317. + appQty + " " + log);
  318. }
  319. }
  320. sql = @"select A.[Status] 状态1,
  321. A1.[Status] as 2
  322. from PR_PR as A
  323. inner join [PR_PRLine] as A1 on (A.[ID] = A1.[PR])
  324. inner JOIN Base_Organization c ON A.Org=c.ID
  325. where 1=1 and A.[DocNo] = '{0}' and A1.DocLineNo='{1}' and c.Code='" + poInfoHead.OrgCode + "'";
  326. sql = string.Format(sql, poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo);
  327. dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  328. if (dt.Rows[0]["状态1"].ToString() != "2" || dt.Rows[0]["状态2"].ToString() != "2")
  329. {
  330. throw new Exception("单号:" + poInfoLine.srcDocPRNo + "\n行号:" + poInfoLine.srcDocPRLineNo + "\n状态异常,U9中必须核准状态才准许转采购!请于 U9中确认。");
  331. }
  332. #region 行 poLine
  333. UFIDAU9PMDTOsOBAPOLineDTOData poLine = getPoLine(poInfoLine, i, orgID);
  334. poLines.Add(poLine);
  335. num = i;
  336. #endregion
  337. }
  338. poHead.m_pOLines = poLines.ToArray();
  339. pOList.Add(poHead);
  340. }
  341. return pOList.ToArray();
  342. }
  343. #endregion
  344. #region 提取异常信息
  345. /// <summary>
  346. /// 提取异常信息
  347. /// </summary>
  348. /// <param name="ex"></param>
  349. private string GetExceptionMessage(Exception ex)
  350. {
  351. string faultMessage = "未知错误,请查看ERP日志!";
  352. System.TimeoutException timeoutEx = ex as System.TimeoutException;
  353. if (timeoutEx != null)
  354. {
  355. faultMessage = "访问服务超时,请修改配置信息!";
  356. }
  357. else
  358. {
  359. FaultException<ServiceException> faultEx = ex as FaultException<ServiceException>;
  360. if (faultEx == null)
  361. {
  362. faultMessage = ex.Message;
  363. }
  364. else
  365. {
  366. ServiceException serviceEx = faultEx.Detail;
  367. if (serviceEx != null && !string.IsNullOrEmpty(serviceEx.Message)
  368. && !serviceEx.Message.Equals("fault", StringComparison.OrdinalIgnoreCase))
  369. {
  370. // 错误信息在faultEx.Message中,请提取,
  371. // 格式为"Fault:料品不能为空,请录入\n 在....."
  372. int startIndex = serviceEx.Message.IndexOf(":");
  373. int endIndex = serviceEx.Message.IndexOf("\n");
  374. if (endIndex == -1)
  375. endIndex = serviceEx.Message.Length;
  376. if (endIndex > 0 && endIndex > startIndex + 1)
  377. {
  378. faultMessage = serviceEx.Message.Substring(startIndex + 1, endIndex - startIndex - 1);
  379. }
  380. else
  381. {
  382. faultMessage = serviceEx.Message;
  383. }
  384. }
  385. }
  386. }
  387. return faultMessage;
  388. }
  389. #endregion
  390. #region 给上下文信息赋值
  391. /// <summary>
  392. /// 给上下文信息赋值
  393. /// </summary>
  394. /// <returns></returns>
  395. private ThreadContext CreateContextObj(string OrgID)
  396. {
  397. // 实例化应用上下文对象
  398. ThreadContext thContext = new ThreadContext();
  399. System.Collections.Generic.Dictionary<object, object> ns = new Dictionary<object, object>();
  400. //ns.Add("OrgID", ConfigurationManager.AppSettings["orgID"].ToString());
  401. ns.Add("OrgID", long.Parse(OrgID));
  402. ns.Add("UserID", ConfigurationManager.AppSettings["userID"].ToString());
  403. ns.Add("UserCode", ConfigurationManager.AppSettings["userCode"].ToString());
  404. ns.Add("Datetime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  405. ns.Add("CultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  406. ns.Add("EnterpriseID", ConfigurationManager.AppSettings["enterpriseID"].ToString());
  407. ns.Add("DefaultCultureName", ConfigurationManager.AppSettings["cultureName"].ToString());
  408. thContext.nameValueHas = ns;
  409. return thContext;
  410. }
  411. #endregion
  412. #region 时间戳方法
  413. private DateTime TimestampToDateTime(long timestamp)
  414. {
  415. DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  416. long lTime = timestamp * 10000000;
  417. TimeSpan nowTimeSpan = new TimeSpan(lTime);
  418. DateTime resultDateTime = dateTimeStart.Add(nowTimeSpan);
  419. return resultDateTime;
  420. }
  421. #endregion
  422. #region 通过ID查找采购员Code,Name
  423. public string[] GetOperatorByID(long id)
  424. {
  425. string[] str = new string[2];
  426. string sql = @"select A.Code,B.Name
  427. from CBO_Operators A left join CBO_Operators_Trl B on A.ID=B.ID where A.ID=" + id + "";
  428. DataTable dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  429. //string[] str = new string[2];
  430. if (dt == null || dt.Rows.Count == 0)
  431. { str = null; }
  432. else
  433. {
  434. str[0] = dt.Rows[0][0].ToString();
  435. str[1] = dt.Rows[0][1].ToString();
  436. }
  437. return str;
  438. }
  439. #endregion
  440. #region 赋值行
  441. public UFIDAU9PMDTOsOBAPOLineDTOData getPoLine(PoLine poInfoLine, int i, string orgid)
  442. {
  443. string project11 = null;
  444. string PubDescSeg18 = null;
  445. dtPro = Appconfig.getPRProject11(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo);
  446. if (dtPro != null && dtPro.Rows.Count > 0)
  447. {
  448. project11 = dtPro.Rows[0][0].ToString();
  449. PubDescSeg18 = dtPro.Rows[0][1].ToString();
  450. }
  451. UFIDAU9PMDTOsOBAPOLineDTOData poLine = new UFIDAU9PMDTOsOBAPOLineDTOData();
  452. //if (Appconfig.GetUOMCode(poInfoLine.TradeUOM).Rows.Count == 0 || Appconfig.GetUOMCode(poInfoLine.TradeUOM)==null)
  453. //{
  454. // throw new Exception("ERP中不存在该单位" + poInfoLine.TradeUOM);
  455. //}
  456. //string uom = Appconfig.GetUOMCode(poInfoLine.TradeUOM).Rows[0][0].ToString();
  457. //poLine.m_systemPriceTC = poInfoLine.Price;//系统价
  458. poLine.m_docLineNo = (i + 1) * 10; //行号
  459. poLine.m_srcDocType = 1; //来源单据类型 1表示请购单
  460. poLine.m_itemInfo = new UFIDAU9CBOSCMItemItemInfoData(); //料号信息
  461. poLine.m_itemInfo.m_itemCode = poInfoLine.ItemCode;
  462. poLine.m_itemInfo.m_itemGrade = -1;
  463. poLine.m_itemInfo.m_itemPotency = -1;//IsPUCanChange
  464. poLine.m_isPUCanChange = true;
  465. //poLine.m_isPresent = false; //是否赠品
  466. if (poInfoLine.OrderPriceTC == 0)
  467. {
  468. poLine.m_isPresent = true;
  469. }
  470. poLine.m_kITRcvMode = -1; //成套发货标志
  471. poLine.m_reqQtyTU = poInfoLine.ReqQty; //需求数量
  472. if (!string.IsNullOrEmpty(poInfoLine.TradeUOM))
  473. {
  474. poLine.m_reqUOM = new UFIDAU9BaseDTOsIDCodeNameDTOData(); //需求计量单位
  475. poLine.m_reqUOM.m_code = poInfoLine.TradeUOM;
  476. poLine.m_tradeUOM = new UFIDAU9BaseDTOsIDCodeNameDTOData(); //采购计量单位
  477. poLine.m_tradeUOM.m_code = poInfoLine.TradeUOM;
  478. }
  479. poLine.m_purQtyTU = poInfoLine.ReqQty; //采购数量
  480. if (!string.IsNullOrEmpty(poInfoLine.ValuationUnit))
  481. {
  482. poLine.m_priceUOM = new UFIDAU9BaseDTOsIDCodeNameDTOData();//计价单位
  483. poLine.m_priceUOM.m_code = poInfoLine.ValuationUnit;
  484. }
  485. poLine.m_pRNO = poInfoLine.srcDocPRNo;
  486. poLine.m_isPresent = poInfoLine.IsPersent;
  487. DataTable dt = Appconfig.GetPRDocID(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo);
  488. if (dt == null || dt.Rows.Count < 1)
  489. {
  490. throw new Exception("ERP中不存在该请购单行的数据,请检查是否被删除.单号:" + poInfoLine.srcDocPRNo + ",行号:" + poInfoLine.srcDocPRLineNo);
  491. }
  492. poLine.m_pRLineID = long.Parse(dt.Rows[0][1].ToString());
  493. poLine.m_pRID = long.Parse(dt.Rows[0][0].ToString());
  494. //poLine.m_supplierConfirmQtyTU = 2; //确认数量
  495. poLine.m_supplierConfirmQtyPU = poInfoLine.ValuationQty;//确认数量
  496. poLine.m_descFlexSegments = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
  497. poLine.m_descFlexSegments.m_privateDescSeg1 = TimestampToDateTime(poInfoLine.SupConfirmDate).ToString();//供应商确认日期
  498. if (!string.IsNullOrEmpty(project11))
  499. {
  500. poLine.m_descFlexSegments.m_pubDescSeg11 = project11;
  501. }
  502. //20200810 请购单行18传给采购单行18
  503. poLine.m_descFlexSegments.m_pubDescSeg18 = PubDescSeg18;
  504. //20200319新增行上存储物供传来的长整型
  505. poLine.m_descFlexSegments.m_privateDescSeg26 = poInfoLine.SrcPOID.ToString();
  506. if (!string.IsNullOrEmpty(poInfoLine.ProCode))
  507. {
  508. poLine.m_project = new UFIDAU9BaseDTOsIDCodeNameDTOData();
  509. long m = 0;
  510. if (long.TryParse(Appconfig.GetProjectID(poInfoLine.ProCode), out m))
  511. poLine.m_project.m_iD = m;
  512. //throw new Exception("ERP中不存在该项目号:" + poInfoLine.ProCode);
  513. }
  514. poLine.m_demondCode = -1; //需求分类
  515. poLine.m_isSpilted = false; //已分割
  516. poLine.m_isRefill = false; //替代件
  517. poLine.m_isPriceModify = true; //价格可改
  518. poLine.m_priceSource = 1; //价格来源
  519. #region 20190410注释
  520. //20190417
  521. //poLine.m_netFinallyPriceFC = poInfoLine.NetFinallyPriceAC;
  522. //poLine.m_netMnyAC = poInfoLine.NetMnyAC;
  523. if (poInfoLine.OrderPriceTC > 0)
  524. {
  525. poLine.m_orderPriceTC = poInfoLine.OrderPriceTC; //定价
  526. poLine.m_srcDocFinallyPriceTC = poInfoLine.OrderPriceTC;
  527. poLine.m_finallyPriceTC = poInfoLine.OrderPriceTC; //最终价 单价(含税)
  528. }
  529. //poLine.m_totalMnyTC = poInfoLine.OrderTotalTC;//价税合计
  530. if (poInfoLine.OrderTotalTC > 0)
  531. {
  532. poLine.m_netMnyTC = poInfoLine.OrderTotalTC;//价税合计
  533. }
  534. #endregion
  535. poLine.m_createdOn = DateTime.Now;
  536. poLine.m_createdBy = ConfigurationManager.AppSettings["userCode"].ToString();
  537. if (poInfoLine.TaxRate > 0)
  538. {
  539. poLine.m_taxRate = poInfoLine.TaxRate; //税率
  540. }
  541. poLine.m_srcDocInfo = new UFIDAU9CBOSCMPropertyTypesSrcDocInfoData();
  542. //poLine.m_srcDocInfo.m_srcDocBusiType = -1;
  543. poLine.m_srcDocInfo.SrcDocOrg_SKey = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
  544. poLine.m_srcDocInfo.SrcDocOrg_SKey.ID = long.Parse(orgid);// long.Parse(ConfigurationManager.AppSettings["orgID"].ToString());
  545. // = 1001604180010013;
  546. //poLine.m_srcDocInfo.m_srcDocVer = 1;
  547. poLine.m_srcDocInfo.m_srcDocNo = poInfoLine.srcDocPRNo; //来源单据号
  548. poLine.m_srcDocInfo.m_srcDoc = new UFIDAU9BasePropertyTypesBizEntityKeyData();
  549. //poLine.m_srcDocInfo.m_srcDocLineNo = poInfoLine.srcDocPRLineNo; //来源单据行号C:\Users\Administrator\Desktop\WCF\UFIDA.U9.ZHC\UFIDA.ISV.CreatePoSrvSub\CustCallUFIDAISVCreatePoSrvSub.cs
  550. poLine.m_srcDocInfo.m_srcDoc.m_entityID = long.Parse(Appconfig.GetPRDocID(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo).Rows[0][0].ToString());
  551. poLine.m_srcDocInfo.m_srcDoc.m_entityType = "UFIDA.U9.PR.PurchaseRequest.PR";
  552. poLine.m_srcDocInfo.m_srcDocLineNo = poInfoLine.srcDocPRLineNo; //来源单据行号
  553. poLine.m_srcDocInfo.m_srcDocLine = new UFIDAU9BasePropertyTypesBizEntityKeyData();
  554. poLine.m_srcDocInfo.m_srcDocLine.m_entityID = long.Parse(Appconfig.GetPRDocID(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo).Rows[0][1].ToString());
  555. poLine.m_srcDocInfo.m_srcDocLine.m_entityType = "UFIDA.U9.PR.PurchaseRequest.PRLine";
  556. poLine.m_demondCode = -1; //需求分类
  557. UFIDAU9PMDTOsOBAPOShipLineDTOData pOShipline = new www.ufida.org.EntityData.UFIDAU9PMDTOsOBAPOShipLineDTOData();
  558. #region 计划行
  559. pOShipline.m_srcDocType = 1;
  560. pOShipline.m_srcDocInfo = new UFIDAU9CBOSCMPropertyTypesSrcDocInfoData();
  561. pOShipline.m_srcDocInfo.m_srcDocBusiType = -1;
  562. pOShipline.m_srcDocInfo.SrcDocOrg_SKey = new UFSoft.UBF.Business.BusinessEntity.EntityKey();
  563. pOShipline.m_srcDocInfo.SrcDocOrg_SKey.ID = long.Parse(orgid);// long.Parse(ConfigurationManager.AppSettings["orgID"].ToString());
  564. // = 1001604180010013;
  565. pOShipline.m_srcDocInfo.m_srcDocVer = 1;
  566. pOShipline.m_srcDocInfo.m_srcDocNo = poInfoLine.srcDocPRNo; //来源单据号
  567. pOShipline.m_srcDocInfo.m_srcDoc = new UFIDAU9BasePropertyTypesBizEntityKeyData();
  568. pOShipline.m_srcDocInfo.m_srcDoc.m_entityID = long.Parse(Appconfig.GetPRDocID(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo).Rows[0][0].ToString());
  569. pOShipline.m_srcDocInfo.m_srcDoc.m_entityType = "UFIDA.U9.PR.PurchaseRequest.PR";
  570. pOShipline.m_srcDocInfo.m_srcDocLineNo = poInfoLine.srcDocPRLineNo; //来源单据行号
  571. pOShipline.m_srcDocInfo.m_srcDocLine = new UFIDAU9BasePropertyTypesBizEntityKeyData();
  572. pOShipline.m_srcDocInfo.m_srcDocLine.m_entityID = long.Parse(Appconfig.GetPRDocID(poInfoLine.srcDocPRNo, poInfoLine.srcDocPRLineNo).Rows[0][1].ToString());
  573. pOShipline.m_srcDocInfo.m_srcDocLine.m_entityType = "UFIDA.U9.PR.PurchaseRequest.PRLine";
  574. //pOShipline.m_srcDocInfo.m_srcDocTransType = new UFIDAU9BasePropertyTypesBizEntityKeyData(); //原单据类型
  575. //pOShipline.m_srcDocInfo.m_srcDocTransType.m_entityID = 1001604181460401;
  576. //pOShipline.m_srcDocInfo.m_srcDocTransType.m_entityType = "UFIDA.U9.PR.PurchaseRequest.PRDocType";
  577. //pOShipline.m_subLineNo = 10;
  578. pOShipline.m_rcvShipBy = 2; // 收发货依据
  579. pOShipline.m_demondCode = -1; //需求分类
  580. if (poInfoLine.RequireDate > 0)
  581. {
  582. pOShipline.m_deliveryDate = TimestampToDateTime(poInfoLine.RequireDate); // 要求交货日
  583. pOShipline.m_preMaturityDate = TimestampToDateTime(poInfoLine.RequireDate);
  584. pOShipline.m_planArriveDate = TimestampToDateTime(poInfoLine.RequireDate);
  585. pOShipline.m_needPODate = TimestampToDateTime(poInfoLine.RequireDate);
  586. }
  587. //else
  588. //{
  589. // pOShipline.m_deliveryDate = DateTime.Now.AddMonths(1); // 要求交货日
  590. // pOShipline.m_preMaturityDate = DateTime.Now.AddMonths(1);
  591. // pOShipline.m_planArriveDate = DateTime.Now.AddMonths(1);
  592. // pOShipline.m_needPODate = DateTime.Now.AddMonths(1);
  593. //}
  594. pOShipline.m_centralizedPurType = -1; //集中采购类型
  595. if (!string.IsNullOrEmpty(poInfoLine.ProCode))
  596. {
  597. pOShipline.m_project = new UFIDAU9BaseDTOsIDCodeNameDTOData();
  598. long m = 0;
  599. if (long.TryParse(Appconfig.GetProjectID(poInfoLine.ProCode), out m))
  600. pOShipline.m_project.m_iD = m;
  601. }
  602. pOShipline.m_descFlexSegments = new UFIDAU9BaseFlexFieldDescFlexFieldDescFlexSegmentsData();
  603. if (!string.IsNullOrEmpty(project11))
  604. {
  605. pOShipline.m_descFlexSegments.m_pubDescSeg11 = project11;
  606. }
  607. #endregion
  608. //poLine.m_pOShiplines = new UFIDAU9PMDTOsOBAPOShipLineDTOData[1];
  609. List<UFIDAU9PMDTOsOBAPOShipLineDTOData> ships = new List<UFIDAU9PMDTOsOBAPOShipLineDTOData>();
  610. ships.Add(pOShipline);
  611. poLine.m_pOShiplines = ships.ToArray();
  612. //poLine.m_pOShiplines[0].m_project = new UFIDAU9BaseDTOsIDCodeNameDTOData();
  613. //poLine.m_pOShiplines[0].m_project.m_code = poInfoLine.ProCode;
  614. return poLine;
  615. }
  616. #endregion
  617. #region 去重&叠加相同数量的料号
  618. public List<PoLine> selectItemCode(List<PoLine> pOLines)
  619. {
  620. for (int i = 0; i < pOLines.Count; i++)
  621. {
  622. for (int j = pOLines.Count - 1; j > i; j--)
  623. {
  624. if (pOLines[i].ItemCode.ToString() == pOLines[j].ItemCode.ToString())
  625. {
  626. pOLines[i].ReqQty += pOLines[j].ReqQty;
  627. pOLines.RemoveAt(j);
  628. }
  629. }
  630. }
  631. return pOLines;
  632. }
  633. #endregion
  634. #region 获取最小采购量
  635. public int getMinPR(string itemCode)
  636. {
  637. string sql = @"select A1.[DescFlexField_PrivateDescSeg12] as PurchaseBatchQty
  638. from [CBO_ItemMaster] as A1 where A1.Code='" + itemCode + "'";
  639. DataTable dt = DBhlper.Query(sql, Appconfig.GetU9ConnStr());
  640. if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0][0].ToString()))
  641. {
  642. return int.Parse(dt.Rows[0][0].ToString());
  643. }
  644. else
  645. {
  646. return -1;
  647. }
  648. }
  649. #endregion
  650. #region 汇总因最小采购量的拆行
  651. public List<PoLine> scatterLines(PoLine[] pOLines1)
  652. {
  653. List<PoLine> pOLines = new List<PoLine>(pOLines1);
  654. List<PoLine> lines = selectItemCode(pOLines);
  655. int j = lines.Count;
  656. for (int i = j - 1; i > -1; i--)
  657. {
  658. int min = getMinPR(lines[i].ItemCode);
  659. if (min == 0 || min == -1)
  660. {
  661. lines.Remove(lines[i]);
  662. continue;
  663. }
  664. int num = int.Parse(lines[i].ReqQty.ToString());
  665. int num1 = num / min;
  666. int num2 = (num1 + 1) * min - num;
  667. //if(num1==0)
  668. //{
  669. // continue;
  670. //}
  671. lines[i].ReqQty = num2;
  672. lines[i].ProCode = "";
  673. lines[i].ValuationQty = num2;
  674. }
  675. return lines;
  676. }
  677. #endregion
  678. }
  679. #region 上下文类信息
  680. public class contextInfo
  681. {
  682. private long _OrgID;
  683. private string _OrgCode;
  684. private long _UserID;
  685. private string _UserCode;
  686. private DateTime _Datetime;
  687. private string _CultureName;
  688. private string _EnterpriseID;
  689. /// <summary>
  690. /// 组织ID
  691. /// </summary>
  692. public long OrgID
  693. {
  694. get { return _OrgID; }
  695. set { _OrgID = value; }
  696. }
  697. /// <summary>
  698. /// 组织编码
  699. /// </summary>
  700. public string OrgCode
  701. {
  702. get { return _OrgCode; }
  703. set { _OrgCode = value; }
  704. }
  705. /// <summary>
  706. /// 操作员ID
  707. /// </summary>
  708. public long UserID
  709. {
  710. get { return _UserID; }
  711. set { _UserID = value; }
  712. }
  713. /// <summary>
  714. /// 操作员编码
  715. /// </summary>
  716. public string UserCode
  717. {
  718. get { return _UserCode; }
  719. set { _UserCode = value; }
  720. }
  721. /// <summary>
  722. /// 时间
  723. /// </summary>
  724. public DateTime Datetime
  725. {
  726. get { return _Datetime; }
  727. set { _Datetime = value; }
  728. }
  729. /// <summary>
  730. /// 语言
  731. /// </summary>
  732. public string CultureName
  733. {
  734. get { return _CultureName; }
  735. set { _CultureName = value; }
  736. }
  737. /// <summary>
  738. /// 企业ID号
  739. /// </summary>
  740. public string EnterpriseID
  741. {
  742. get { return _EnterpriseID; }
  743. set { _EnterpriseID = value; }
  744. }
  745. public contextInfo()
  746. {
  747. CultureName = "zh_CN";
  748. Datetime = DateTime.Now;
  749. }
  750. }
  751. #endregion
  752. #region 表头类
  753. public class Pohead
  754. {
  755. /// 单据类型
  756. public string DocTypeCode { get; set; }
  757. /// 单据日期
  758. public long DocDate { get; set; }
  759. /// 采购单单据号
  760. public string PurchaseOrder { get; set; }
  761. /// 交易币种
  762. public string TCCode { get; set; }
  763. /// 供应商
  764. public string supplierCode { get; set; }
  765. /// 价格是否含税
  766. public bool isPriceIncludeTax { get; set; }
  767. public PoLine[] lines { get; set; }
  768. /// 采购单单据类型
  769. public int bizType;
  770. //组织
  771. public string OrgCode { get; set; }
  772. }
  773. #endregion
  774. #region 表体类
  775. public class PoLine
  776. {
  777. public long SrcPOID { get; set; }
  778. // 采购订单号
  779. public string PurchaseOrder { get; set; }
  780. // 采购订单行号
  781. public int PurchaseOrderSeq { get; set; }
  782. /// 料号
  783. public string ItemCode { get; set; }
  784. /// 单位
  785. public string TradeUOM { get; set; }
  786. /// 数量
  787. public decimal ReqQty { get; set; }
  788. /// 价格
  789. public decimal OrderPriceTC { get; set; }
  790. /// 金额
  791. public decimal OrderTotalTC { get; set; }
  792. /// 税率
  793. public decimal TaxRate { get; set; }
  794. //来源请购单单号
  795. public string srcDocPRNo { get; set; }
  796. //来源请购单单行号
  797. public int srcDocPRLineNo { get; set; }
  798. /// 供应商交期
  799. public long RequireDate { get; set; }
  800. /// 供应商确认日期
  801. public long SupConfirmDate { get; set; }
  802. /// 计价单位
  803. public string ValuationUnit { get; set; }
  804. /// 计价数量
  805. public decimal ValuationQty { get; set; }
  806. // 项目号
  807. public string ProCode { get; set; }
  808. //是否分割
  809. public int IsSpilt { get; set; }
  810. //是否赠品
  811. public bool IsPersent { get; set; }
  812. }
  813. #endregion
  814. #region 返回信息类
  815. public class rtnPoinfo
  816. {
  817. public string DocNo { get; set; }
  818. public string Message { get; set; }
  819. public long DocID { get; set; }
  820. public string OperatorCode { get; set; }
  821. public string OperatorName { get; set; }
  822. public string OrgCode { get; set; }
  823. public rtnPoLine[] rtnLines { get; set; }
  824. }
  825. public class rtnPoLine
  826. {
  827. //20200319新增长整形字段最后再返回给物供
  828. public long SrcPOID { get; set; }
  829. public int LineNo { get; set; }
  830. public long lineID { get; set; }
  831. public string srcDocNo { get; set; }
  832. public int srcLineNo { get; set; }
  833. public decimal reqQty { get; set; }
  834. public string tc { get; set; }
  835. public string proCode { get; set; }
  836. public string ProcessPrice { get; set; }//加工费
  837. public string TotalProcessPrice { get; set; }//材料费
  838. }
  839. public class OperationResult
  840. {
  841. public bool IsSuccess { get; set; }
  842. public string MESSAGE { get; set; }
  843. public string SuppCode { get; set; }
  844. }
  845. #endregion
  846. }