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.

423 lines
20 KiB

  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. using Newtonsoft.Json.Linq;
  18. using NFine.Domain._03_Entity.WMS;
  19. using System.Net;
  20. using System.IO;
  21. namespace NFine.Application.WMS
  22. {
  23. public class FinishedProductWarehouseEntryApp : RepositoryFactory<ICSVendor>
  24. {
  25. public static DataTable PRInvmes = new DataTable();
  26. /// <summary>
  27. /// 退料
  28. /// </summary>
  29. /// <param name="jqgridparam"></param>
  30. /// <returns></returns>
  31. public DataTable GetICSMOApplyNeg(ref Pagination jqgridparam)
  32. {
  33. DataTable dt = new DataTable();
  34. List<DbParameter> parameter = new List<DbParameter>();
  35. string sql = @" SELECT DISTINCT a.ID,a.RCVCode AS ApplyNegCode,a.WHCode,b.WarehouseName,a.Type,a.Status,a.MUSERName,a.MTIME,a.CreateDateTime,a.CreatePerson,
  36. c.ProjectCode,c.BatchCode,c.Version,c.Brand,c.cFree1,c.cFree2,c.cFree3,cFree4,cFree5,c.cFree6,c.cFree7,c.cFree8,cFree9,cFree10
  37. FROM ICSWMSManufactureReceive a
  38. LEFT JOIN ICSWarehouse b ON b.WarehouseCode=a.WHCode AND b.WorkPoint=a.WorkPoint
  39. LEFT JOIN ICSExtension c ON c.ID=a.ExtensionID AND c.WorkPoint=a.WorkPoint
  40. WHERE 1=1";
  41. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  42. }
  43. public DataTable GetICSMOApplyNegDetail(string ApplyNegCode, ref Pagination jqgridparam)
  44. {
  45. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  46. DataTable dt = new DataTable();
  47. //var queryParam = queryJson.ToJObject();
  48. List<DbParameter> parameter = new List<DbParameter>();
  49. string sql = @"SELECT DISTINCT a.RCVCode AS ApplyNegCode,a.Sequence,a.LotNo,a.InvCode,inv.InvName,a.Quantity,a.RCVQuantity,a.MTIME,a.SourceCode,a.SourceSequence,
  50. c.ProjectCode,c.BatchCode,c.Version,c.Brand,c.cFree1,c.cFree2,c.cFree3,cFree4,cFree5,c.cFree6,c.cFree7,c.cFree8,cFree9,cFree10
  51. FROM ICSWMSManufactureReceiveDetail a
  52. LEFT JOIN ICSInventory inv ON inv.InvCode=a.invcode AND inv.WorkPoint=a.WorkPoint
  53. LEFT JOIN ICSExtension c ON c.ID=a.ExtensionID AND c.WorkPoint=a.WorkPoint
  54. LEFT JOIN ICSMO d ON d.MOCode=a.SourceCode AND d.Sequence=a.SourceSequence AND d.WorkPoint=a.WorkPoint and d.MOStatus<> '3'
  55. LEFT JOIN ICSInventoryLotDetail e ON e.TransCode=d.MOCode AND e.TransSequence=d.Sequence AND e.WorkPoint=d.WorkPoint
  56. WHERE a.RCVCode='" + ApplyNegCode + "' ";
  57. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  58. }
  59. public string DeleteICSMOApplyNeg(string keyValue)
  60. {
  61. //站点信息
  62. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  63. string msg = "";
  64. keyValue = keyValue.Substring(1, keyValue.Length - 2);
  65. string sql = string.Empty;
  66. sql += string.Format(@"DELETE FROM dbo.ICSWMSManufactureReceive WHERE RCVCode IN ({0}) and WorkPoint ='{1}' ", keyValue.TrimEnd(','), WorkPoint);
  67. sql += string.Format(@"DELETE FROM dbo.ICSWMSManufactureReceiveDetail WHERE RCVCode IN ({0}) and WorkPoint ='{1}' ", keyValue.TrimEnd(','), WorkPoint);
  68. try
  69. {
  70. if (SqlHelper.CmdExecuteNonQueryLi(sql) <= 0)
  71. {
  72. msg = "删除失败!";
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. return ex.Message;
  78. //throw new Exception(ex.Message);
  79. }
  80. return msg;
  81. }
  82. public DataTable GetICSReturnTemporary(string rfqno)
  83. {
  84. string sql = @"SELECT DISTINCT a.RCVCode AS ApplyNegCode,a.Sequence,a.LotNo,a.InvCode,a.Quantity,a.RCVQuantity,a.MTIME,
  85. c.ProjectCode,c.BatchCode,c.Version,c.Brand,c.cFree1,c.cFree2,c.cFree3,cFree4,cFree5,c.cFree6,c.cFree7,c.cFree8,cFree9,cFree10
  86. FROM ICSWMSManufactureReceiveDetail a
  87. LEFT JOIN ICSExtension c ON c.ID=a.ExtensionID AND c.WorkPoint=a.WorkPoint
  88. LEFT JOIN ICSMO d ON d.MOCode=a.SourceCode AND d.Sequence=a.SourceSequence AND d.WorkPoint=a.WorkPoint and d.MOStatus<>'3'
  89. LEFT JOIN ICSInventoryLotDetail e ON e.TransCode=d.MOCode AND e.TransSequence=d.Sequence AND e.WorkPoint=d.WorkPoint
  90. WHERE a.RCVCode='" + rfqno + "'";
  91. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  92. DataTable dtCloned = table.Clone();
  93. foreach (DataColumn col in dtCloned.Columns)
  94. {
  95. col.DataType = typeof(string);
  96. }
  97. foreach (DataRow row in table.Rows)
  98. {
  99. DataRow newrow = dtCloned.NewRow();
  100. foreach (DataColumn column in dtCloned.Columns)
  101. {
  102. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  103. }
  104. dtCloned.Rows.Add(newrow);
  105. }
  106. if (PRInvmes.Rows.Count > 0)
  107. {
  108. dtCloned.Merge(PRInvmes, false);
  109. }
  110. return dtCloned;
  111. }
  112. public DataTable GetINV(string invcode, string mocode, ref Pagination jqgridparam)
  113. {
  114. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  115. object Figure = GetDecimalDigits();
  116. List<DbParameter> parameter = new List<DbParameter>();
  117. DataTable table = new DataTable();
  118. string wherestr = "";
  119. if (!string.IsNullOrEmpty(invcode))
  120. {
  121. wherestr += " and a.InvCode like '%" + invcode + "%'";
  122. }
  123. if (!string.IsNullOrEmpty(mocode))
  124. {
  125. wherestr += " and a.MoCode like '%" + mocode + "%'";
  126. }
  127. string groupstr = " GROUP BY a.MODetailID,a.MOCode,a.Sequence,a.WHCode,a.RCVQuantity,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,a.Quantity,a.Amount,a.StartDate,a.DueDate,a.MOStatus,a.MUSERName,a.MTIME,a.MOMemo ";
  128. string sql = @"select distinct --c.ID,
  129. a.MODetailID,a.MOCode,a.Sequence,
  130. --c.LotNo,
  131. a.WHCode,CAST( a.Quantity AS DECIMAL(18,{0})) as Quantity, CAST(a.RCVQuantity AS DECIMAL(18,{0})) as RCVQuantity ,CAST( a.Quantity AS DECIMAL(18,{0})) -CAST(a.RCVQuantity AS DECIMAL(18,{0})) as ERPNum,
  132. SUM(CAST(c.LOTQTY AS DECIMAL(18,{0}))) as LOTQTY ,a.InvCode,b.InvName,b.InvDesc,b.InvStd,b.InvUnit,CAST( a.Amount as DECIMAL(18,{0})) as Amount,a.StartDate
  133. ,a.DueDate,a.MOStatus,
  134. -- c.ExtensionID,
  135. a.MUSERName,a.MTIME ,
  136. a.MOMemo
  137. -- ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  138. -- ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10,a.EATTRIBUTE1,a.EATTRIBUTE2,a.EATTRIBUTE3,a.EATTRIBUTE4,a.EATTRIBUTE5,a.EATTRIBUTE6,a.EATTRIBUTE7,a.EATTRIBUTE8,
  139. -- a.EATTRIBUTE9,a.EATTRIBUTE10
  140. from ICSMO a
  141. left join ICSInventory b on a.InvCode=b.InvCode and a.WorkPoint=b.WorkPoint
  142. left join (
  143. select ee.ID,mm.TransCode,mm.TransSequence,sum(isnull(ee.Quantity,0)) LOTQTY,ee.WorkPoint,ee.LotNo,ee.ExtensionID from ICSInventoryLot ee
  144. left join ICSInventoryLotDetail mm on ee.LotNo=mm.LotNo and ee.type='3'
  145. where isnull(ee.EATTRIBUTE1,'')=''
  146. group by mm.TransCode,mm.TransSequence,ee.WorkPoint,ee.LotNo,ee.ExtensionID,ee.ID
  147. )c
  148. on a.MOCode=c.TransCode and a.Sequence=c.TransSequence and a.WorkPoint=c.WorkPoint
  149. left join ICSExtension f on c.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  150. where 1=1 and a.Quantity-ISNULL(c.LOTQTY,0)<>0 and a.MOStatus<>'3' " + wherestr + groupstr;
  151. sql = string.Format(sql, Figure);
  152. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  153. }
  154. public void AddMOApplyNegTemp(string json)
  155. {
  156. var data = json.ToJObject();
  157. if (PRInvmes.Columns.Count <= 0)
  158. {
  159. PRInvmes.Columns.Add("ZJID", typeof(string));
  160. PRInvmes.Columns.Add("ApplyNegCode", typeof(string));
  161. PRInvmes.Columns.Add("Sequence", typeof(string));
  162. //PRInvmes.Columns.Add("LotNo", typeof(string));
  163. PRInvmes.Columns.Add("WHCode", typeof(string));
  164. PRInvmes.Columns.Add("InvCode", typeof(string));
  165. PRInvmes.Columns.Add("InvName", typeof(string));
  166. PRInvmes.Columns.Add("InvStd", typeof(string));
  167. PRInvmes.Columns.Add("InvUnit", typeof(string));
  168. PRInvmes.Columns.Add("OriginalQty", typeof(string));
  169. PRInvmes.Columns.Add("Quantity", typeof(string));
  170. PRInvmes.Columns.Add("RCVQuantity", typeof(string));
  171. PRInvmes.Columns.Add("LOTQTY", typeof(string));
  172. PRInvmes.Columns.Add("ERPNum", typeof(string));
  173. PRInvmes.Columns.Add("IssueNegQuantity", typeof(string));
  174. PRInvmes.Columns.Add("ExtensionID", typeof(string));
  175. PRInvmes.Columns.Add("Amount", typeof(string));
  176. PRInvmes.Columns.Add("ID", typeof(string));
  177. }
  178. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  179. DataRow newrow = PRInvmes.NewRow();
  180. newrow["ZJID"] = data["ZJID"];
  181. newrow["ApplyNegCode"] = data["ApplyNegCode"];
  182. newrow["Sequence"] = data["Sequence"];
  183. //newrow["LotNo"] = data["LotNo"];
  184. newrow["WHCode"] = data["WHCode"];
  185. newrow["InvName"] = data["InvName"];
  186. newrow["InvCode"] = data["InvCode"];
  187. newrow["InvStd"] = data["InvStd"];
  188. newrow["InvUnit"] = data["InvUnit"];
  189. newrow["OriginalQty"] = data["OriginalQty"];
  190. newrow["RCVQuantity"] = data["RCVQuantity"];
  191. newrow["LOTQTY"] = data["LOTQTY"];
  192. newrow["ERPNum"] = data["ERPNum"];
  193. newrow["Amount"] = data["Amount"];
  194. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  195. newrow["ExtensionID"] = data["ExtensionID"];
  196. newrow["Quantity"] = "";
  197. newrow["ID"] = data["ID"];
  198. PRInvmes.Rows.Add(newrow);
  199. }
  200. public string SaveICSMOApplyNeg(string ICSASN)
  201. {
  202. string msg = "";
  203. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "FinishedProductWarehouseEntry/Create";
  204. string result = HttpPost(APIURL, ICSASN);
  205. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  206. string MessAge = Obj["Message"].ToString();
  207. string Success = Obj["Success"].ToString();
  208. if (Success.ToUpper() == "FALSE")
  209. {
  210. msg = MessAge;
  211. }
  212. return msg;
  213. }
  214. public void ClearTemp()
  215. {
  216. PRInvmes.Rows.Clear();
  217. }
  218. public DataTable GetICSMOApplyNegDetailTemp(string ApplyNegCode)
  219. {
  220. string sql = @"SELECT
  221. a.ID,
  222. a.ID as TLZID,
  223. a.ApplyNegCode,
  224. a.InvCode,
  225. a.Quantity,
  226. a.Amount,
  227. a.SourceDetailID as ZJID,
  228. b.InvName,
  229. b.InvStd,
  230. b.InvUnit,
  231. a.IssueNegQuantity,
  232. a.ExtensionID
  233. ,f.Colspan ,f.ProjectCode ,f.BatchCode ,f.Version ,f.Brand ,f.cFree1 ,f.cFree2 ,f.cFree3 ,f.cFree4
  234. ,f.cFree5 ,f.cFree6 ,f.cFree7 ,f.cFree8 ,f.cFree9 ,f.cFree10
  235. FROM
  236. ICSMOApplyNegDetail a
  237. LEFT JOIN ICSInventory b ON a.InvCode = b.InvCode and a.WorkPoint=b.WorkPoint
  238. left join ICSExtension f on a.ExtensionID=f.ID and a.WorkPoint=f.WorkPoint
  239. where a.ApplyNegCode='" + ApplyNegCode + "'";
  240. DataTable table = Repository().FindDataSetBySql(sql).Tables[0];
  241. if (PRInvmes == null || PRInvmes.Columns.Count <= 0)
  242. PRInvmes = table.Clone();
  243. DataTable dtCloned = table.Clone();
  244. foreach (DataColumn col in dtCloned.Columns)
  245. {
  246. col.DataType = typeof(string);
  247. }
  248. foreach (DataRow row in table.Rows)
  249. {
  250. DataRow newrow = dtCloned.NewRow();
  251. foreach (DataColumn column in dtCloned.Columns)
  252. {
  253. newrow[column.ColumnName] = row[column.ColumnName].ToString();
  254. }
  255. dtCloned.Rows.Add(newrow);
  256. }
  257. if (PRInvmes.Rows.Count > 0)
  258. {
  259. //dtCloned.Merge(Invmes, false);
  260. foreach (DataRow data in PRInvmes.Rows)
  261. {
  262. var info = dtCloned.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  263. if (info != null && info.Length > 0)
  264. {
  265. info[0]["ZJID"] = data["ZJID"];
  266. info[0]["InvName"] = data["InvName"];
  267. info[0]["InvCode"] = data["InvCode"];
  268. info[0]["InvStd"] = data["InvStd"];
  269. info[0]["InvUnit"] = data["InvUnit"];
  270. info[0]["Amount"] = data["Amount"];
  271. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  272. info[0]["ExtensionID"] = data["ExtensionID"];
  273. info[0]["Quantity"] = 0;
  274. }
  275. else
  276. {
  277. DataRow newrow = dtCloned.NewRow();
  278. newrow["ZJID"] = data["ZJID"];
  279. newrow["InvName"] = data["InvName"];
  280. newrow["InvCode"] = data["InvCode"];
  281. newrow["InvStd"] = data["InvStd"];
  282. newrow["InvUnit"] = data["InvUnit"];
  283. newrow["Amount"] = data["Amount"];
  284. newrow["Quantity"] = 0;
  285. newrow["ID"] = data["ID"];
  286. newrow["TLZID"] = data["TLZID"];
  287. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  288. newrow["ExtensionID"] = data["ExtensionID"];
  289. dtCloned.Rows.Add(newrow);
  290. }
  291. }
  292. }
  293. return dtCloned;
  294. }
  295. public void UpdateMOApplyNegTemp(string json)
  296. {
  297. var data = json.ToJObject();
  298. string usercode = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode;
  299. var info = PRInvmes.Select(string.Format("TLZID='{0}'", data["TLZID"]));
  300. if (info != null && info.Length > 0)
  301. {
  302. info[0]["ZJID"] = data["ZJID"];
  303. info[0]["InvName"] = data["InvName"];
  304. info[0]["InvCode"] = data["InvCode"];
  305. info[0]["InvStd"] = data["InvStd"];
  306. info[0]["InvUnit"] = data["InvUnit"];
  307. info[0]["Amount"] = data["Amount"];
  308. info[0]["IssueNegQuantity"] = data["IssueNegQuantity"];
  309. info[0]["ExtensionID"] = data["ExtensionID"];
  310. info[0]["Quantity"] = 0;
  311. }
  312. else
  313. {
  314. DataRow newrow = PRInvmes.NewRow();
  315. newrow["ZJID"] = data["ZJID"];
  316. newrow["InvName"] = data["InvName"];
  317. newrow["InvCode"] = data["InvCode"];
  318. newrow["InvStd"] = data["InvStd"];
  319. newrow["InvUnit"] = data["InvUnit"];
  320. newrow["Amount"] = data["Amount"];
  321. newrow["IssueNegQuantity"] = data["IssueNegQuantity"];
  322. newrow["ExtensionID"] = data["ExtensionID"];
  323. newrow["Quantity"] = 0;
  324. newrow["ID"] = data["ID"];
  325. newrow["TLZID"] = data["TLZID"];
  326. PRInvmes.Rows.Add(newrow);
  327. }
  328. }
  329. public string AuditICSMOApplyNeg(string ICSASN)
  330. {
  331. string msg = "";
  332. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Approve";
  333. string result = HttpPost(APIURL, ICSASN);
  334. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  335. string MessAge = Obj["Message"].ToString();
  336. string Success = Obj["Success"].ToString();
  337. if (Success.ToUpper() == "FALSE")
  338. {
  339. msg = MessAge;
  340. }
  341. return msg;
  342. }
  343. public string UpdateICSMOApplyNeg(string ICSASN)
  344. {
  345. string msg = "";
  346. string APIURL = ConfigurationManager.ConnectionStrings["APIURL"].ConnectionString + "MOIssueDocNegativeApply/Update";
  347. string result = HttpPost(APIURL, ICSASN);
  348. JObject Obj = (JObject)JsonConvert.DeserializeObject(result);//或者JObject jo = JObject.Parse(jsonText);
  349. string MessAge = Obj["Message"].ToString();
  350. string Success = Obj["Success"].ToString();
  351. if (Success.ToUpper() == "FALSE")
  352. {
  353. msg = MessAge;
  354. }
  355. return msg;
  356. }
  357. //接口api解析
  358. public static string HttpPost(string url, string body)
  359. {
  360. try
  361. {
  362. Encoding encoding = Encoding.UTF8;
  363. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  364. request.Method = "POST";
  365. request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*";
  366. request.ContentType = "application/json; charset=utf-8";
  367. byte[] buffer = encoding.GetBytes(body);
  368. request.ContentLength = buffer.Length;
  369. request.GetRequestStream().Write(buffer, 0, buffer.Length);
  370. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  371. using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding))
  372. {
  373. return reader.ReadToEnd();
  374. }
  375. }
  376. catch (WebException ex)
  377. {
  378. throw new Exception(ex.Message);
  379. }
  380. }
  381. public object GetDecimalDigits()
  382. {
  383. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location.TrimEnd(',');
  384. try
  385. {
  386. string sql = string.Empty;
  387. sql = @"select Figure from ICSConfiguration where Code='Figure001' and Enable='1' and WorkPoint='" + WorkPoint + "'";
  388. object Figure = SqlHelper.ExecuteScalar(sql);
  389. return Figure;
  390. }
  391. catch (Exception ex)
  392. {
  393. throw new Exception(ex.Message.ToString());
  394. }
  395. }
  396. }
  397. }