纽威
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.

1006 lines
61 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 采购模块
  18. /// </summary>
  19. public class ICSPurchaseService
  20. {
  21. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  22. #region 采购到货
  23. /// <summary>
  24. /// 采购到货接口
  25. /// </summary>
  26. /// <param name="TransType"></param>
  27. /// <param name="Identification"></param>
  28. /// <param name="cmd"></param>
  29. public static void DeliveryNoticeERP(string DNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  30. {
  31. try
  32. {
  33. #region ERP
  34. string sql = @"SELECT a.VenCode+a.DepCode+y.POCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.POCode,a.MUSER,a.MTIME,
  35. a.Sequence,a.InvCode,a.Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.PODetailID
  36. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  37. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  38. INTO #TempERP
  39. FROM ICSDeliveryNotice a
  40. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  41. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  42. INNER JOIN ICSPurchaseOrder y ON a.PODetailID=y.PODetailID AND a.WorkPoint=y.WorkPoint
  43. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  44. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  45. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,PODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  46. FROM #TempERP
  47. DROP TABLE #TempERP";
  48. sql = string.Format(sql, DNCode, WorkPoint);
  49. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  50. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  51. string resultStr = HTTPHelper.HttpPost("采购到货", ERPUrl.CreatePOArrivURL, Inputstr);
  52. Result result = new Result();
  53. result = JsonConvert.DeserializeObject<Result>(resultStr);
  54. if (result.Success)
  55. {
  56. try
  57. {
  58. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  59. foreach (var item in res)
  60. {
  61. JObject jo = (JObject)item;
  62. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  63. foreach (var detail in resdetail)
  64. {
  65. JObject det = (JObject)detail;
  66. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  67. where PODetailID='{4}' AND DNType='1' AND DNCode='{5}' ";
  68. ERPupdate = string.Format(ERPupdate, jo["DNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["PODetailID"], DNCode);
  69. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  70. {
  71. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  72. }
  73. }
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. log.Debug(ex.ToString());
  79. log.Debug(resultStr);
  80. }
  81. }
  82. else
  83. {
  84. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  85. }
  86. #endregion
  87. }
  88. catch (Exception)
  89. {
  90. throw;
  91. }
  92. }
  93. #endregion
  94. #region 采购入库
  95. /// <summary>
  96. /// 采购入库
  97. /// </summary>
  98. /// <param name="TransCode"></param>
  99. /// <param name="TransSequence"></param>
  100. /// <param name="Quantity"></param>
  101. /// <param name="WorkPoint"></param>
  102. /// <param name="cmd"></param>
  103. public static void PurchaseReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  104. {
  105. try
  106. {
  107. string sql = @"DECLARE @Status VARCHAR(10)
  108. SELECT @Status=c.Status FROM ICSInventoryLot a
  109. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  110. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  111. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  112. IF (@Status IS NULL)
  113. BEGIN
  114. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  115. RETURN
  116. END
  117. ELSE IF (@Status='3')
  118. BEGIN
  119. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  120. RETURN
  121. END
  122. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  123. FROM ICSInventoryLot a
  124. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  125. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  126. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  127. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  128. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  129. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  130. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  131. BEGIN
  132. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  133. END";
  134. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  135. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  136. {
  137. throw new Exception(language.GetNameByCode("WMSAPIInfo104"));//"采购入库单更新失败!");
  138. }
  139. }
  140. catch (Exception)
  141. {
  142. throw;
  143. }
  144. }
  145. /// <summary>
  146. /// 采购入库接口
  147. /// </summary>
  148. /// <param name="TransType"></param>
  149. /// <param name="Identification"></param>
  150. /// <param name="cmd"></param>
  151. public static void PurchaseReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  152. {
  153. try
  154. {
  155. #region ERP
  156. string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS DNCode,CASE WHEN(LEN(f.DNID)>=20) THEN '1' ELSE '0' END AS HasDN,a.MUSER,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END AS DNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,a.InvCode) AS Sequence,
  157. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable
  158. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  159. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  160. INTO #TempERP
  161. FROM ICSWareHouseLotInfoLog a
  162. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  163. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  164. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  165. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  166. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  167. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  168. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint
  169. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  170. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  171. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  172. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  173. GROUP BY c.VenCode,a.ToWarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END,f.DNID,a.MUSER,a.InvCode,CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.Sequence END,c.PODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable
  174. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  175. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  176. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity FROM #TempERP
  177. SELECT Costre,Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  178. FROM #TempERP
  179. SELECT HasDN FROM #TempERP
  180. DROP TABLE #TempERP";
  181. sql = string.Format(sql, Identification, BusinessCode);
  182. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  183. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  184. var IsDNCode = ds.Tables[2];
  185. if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  186. {
  187. throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  188. }
  189. string dncode = Convert.ToString(IsDNCode.Rows[0]["HasDN"]);
  190. if (dncode.Equals(""))
  191. {
  192. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  193. Result result = new Result();
  194. result = JsonConvert.DeserializeObject<Result>(resultStr);
  195. if (result.Success)
  196. {
  197. try
  198. {
  199. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  200. foreach (var item in res)
  201. {
  202. JObject jo = (JObject)item;
  203. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  204. foreach (var detail in resdetail)
  205. {
  206. JObject det = (JObject)detail;
  207. string allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  208. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  209. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  210. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  211. }
  212. }
  213. }
  214. catch (Exception ex)
  215. {
  216. log.Debug(ex.ToString());
  217. log.Debug(resultStr);
  218. }
  219. }
  220. else
  221. {
  222. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  223. }
  224. }
  225. else
  226. {
  227. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr);
  228. Result result = new Result();
  229. result = JsonConvert.DeserializeObject<Result>(resultStr);
  230. if (result.Success)
  231. {
  232. try
  233. {
  234. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  235. foreach (var item in res)
  236. {
  237. JObject jo = (JObject)item;
  238. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  239. foreach (var detail in resdetail)
  240. {
  241. JObject det = (JObject)detail;
  242. string allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  243. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  244. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  245. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  246. }
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. log.Debug(ex.ToString());
  252. log.Debug(resultStr);
  253. }
  254. }
  255. else
  256. {
  257. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  258. }
  259. }
  260. #endregion
  261. }
  262. catch (Exception)
  263. {
  264. throw;
  265. }
  266. }
  267. #endregion
  268. #region 审核的到货单
  269. /// <summary>
  270. /// 审核的到货单
  271. /// </summary>
  272. /// <param name="TransCode"></param>
  273. /// <param name="TransSequence"></param>
  274. /// <param name="Quantity"></param>
  275. /// <param name="WorkPoint"></param>
  276. /// <param name="cmd"></param>
  277. public static void DeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  278. {
  279. try
  280. {
  281. string sql = @"DECLARE @Status VARCHAR(10)
  282. SELECT @Status=c.Status FROM ICSInventoryLot a
  283. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  284. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  285. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  286. IF (@Status IS NULL)
  287. BEGIN
  288. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  289. RETURN
  290. END
  291. ELSE IF (@Status='3')
  292. BEGIN
  293. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  294. RETURN
  295. END
  296. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  297. FROM ICSInventoryLot a
  298. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  299. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  300. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  301. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  302. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  303. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  304. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND c.Quantity<c.RCVQuantity)
  305. BEGIN
  306. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  307. END";
  308. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  309. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  310. {
  311. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  312. }
  313. }
  314. catch (Exception)
  315. {
  316. throw;
  317. }
  318. }
  319. /// <summary>
  320. /// 审核的到货单接口
  321. /// </summary>
  322. /// <param name="TransType"></param>
  323. /// <param name="Identification"></param>
  324. /// <param name="cmd"></param>
  325. public static void DeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  326. {
  327. try
  328. {
  329. #region SAP(检验合格单为两层结构 一行对应一个序列号)
  330. string IsSuccess = "";
  331. string ErrorMessage = "";
  332. string sql = @" select Distinct A.DNCode,A.WorkPoint from ICSDeliveryNotice A
  333. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.DNCode AND B.WorkPoint=A.WorkPoint
  334. where B.Identification='{0}' AND BusinessCode='2'";
  335. sql = string.Format(sql, Identification);
  336. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  337. if (dt.Rows.Count > 1)
  338. {
  339. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  340. }
  341. for (int i = 0; i < dt.Rows.Count; i++)
  342. {
  343. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  344. where DNCode='{0}' and WorkPoint='{1}'
  345. GROUP BY DNCode,WorkPoint";
  346. chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  347. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  348. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  349. {
  350. return;
  351. }
  352. sql = @"select A.DNCode,SUM(A.RCVQuantity) AS RCVQuantity,B.BatchCode from ICSDeliveryNotice A
  353. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  354. WHERE DNCode='{0}' AND A.WorkPoint='{1}'
  355. GROUP BY A.DNCode,B.BatchCode";
  356. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  357. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  358. if (Sapdt.Rows.Count == 0)
  359. {
  360. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo205"), dt.Rows[i]["DNCode"].ToString()));//单据查询失败
  361. }
  362. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU Client = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU();
  363. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1 Info = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1();
  364. Info.NEWID = Identification;
  365. Info.PRUEFLOS = Sapdt.Rows[0]["DNCode"].ToString();
  366. Info.L_LME = System.Decimal.Round(Convert.ToDecimal(Sapdt.Rows[0]["RCVQuantity"].ToString()), 3);
  367. Info.SERNP = Sapdt.Rows[0]["BatchCode"].ToString();
  368. Info.Z_GERNR = new SAPCallBackJYHGDVPN.ZWEBS_GERNR[0];
  369. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse result = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse();
  370. result = Client.CallZWMS_SK_WS_RUKU(Info);
  371. if (result.Z_NULL == "N")
  372. {
  373. ErrorMessage += result.L_MESSAGE;
  374. }
  375. }
  376. if (IsSuccess == "N")
  377. {
  378. throw new Exception(ErrorMessage);
  379. }
  380. #endregion
  381. }
  382. catch (Exception)
  383. {
  384. throw;
  385. }
  386. }
  387. #endregion
  388. #region 叉车采购入库
  389. /// <summary>
  390. /// 叉车采购入库
  391. /// </summary>
  392. /// <param name="TransCode"></param>
  393. /// <param name="TransSequence"></param>
  394. /// <param name="Quantity"></param>
  395. /// <param name="WorkPoint"></param>
  396. /// <param name="cmd"></param>
  397. public static void DeliveryNoticeForkLift(string ContainerCode, SqlCommand cmd, Dictionary<string, string> language)
  398. {
  399. try
  400. {
  401. string lotsql = @" select A.LotNo,C.Quantity,B.WorkPoint from ICSContainerLot A
  402. LEFT JOIN ICSContainer B ON B.ID=A.ContainerID AND B.WorkPoint=A.WorkPoint
  403. LEFT JOIN ICSInventoryLot C ON C.LotNo=A.LotNo AND C.WorkPoint=A.WorkPoint
  404. where B.ContainerCode='{0}'";
  405. lotsql = string.Format(lotsql, ContainerCode);
  406. DataTable lotdt = DBHelper.SQlReturnData(lotsql, cmd);
  407. if (lotdt.Rows.Count == 0)
  408. {
  409. throw new Exception("托盘号不存在或者尚未绑定条码!");
  410. }
  411. foreach (DataRow dr in lotdt.Rows)
  412. {
  413. string sql = @" UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  414. FROM ICSInventoryLot a
  415. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  416. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  417. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  418. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  419. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  420. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  421. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND c.Quantity<c.RCVQuantity)
  422. BEGIN
  423. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  424. END";
  425. sql = string.Format(sql, dr["LotNo"].ToString(), dr["WorkPoint"].ToString(), dr["Quantity"].ToString());
  426. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  427. {
  428. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  429. }
  430. }
  431. }
  432. catch (Exception)
  433. {
  434. throw;
  435. }
  436. }
  437. #endregion
  438. #region 采购拒收
  439. /// <summary>
  440. /// 采购拒收
  441. /// </summary>
  442. /// <param name="TransCode"></param>
  443. /// <param name="TransSequence"></param>
  444. /// <param name="Quantity"></param>
  445. /// <param name="WorkPoint"></param>
  446. /// <param name="cmd"></param>
  447. public static void PurchaseRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  448. {
  449. try
  450. {
  451. string sql = @"DECLARE @Status VARCHAR(10)
  452. SELECT @Status=c.Status FROM ICSInventoryLot a
  453. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  454. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  455. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  456. IF (@Status IS NULL)
  457. BEGIN
  458. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  459. RETURN
  460. END
  461. ELSE IF (@Status='3')
  462. BEGIN
  463. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  464. RETURN
  465. END
  466. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  467. FROM ICSInventoryLot a
  468. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  469. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  470. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  471. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  472. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  473. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  474. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3' AND c.Quantity<c.RCVQuantity)
  475. BEGIN
  476. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  477. END";
  478. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  479. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  480. {
  481. throw new Exception(language.GetNameByCode("WMSAPIInfo084"));//"拒收单更新失败!");
  482. }
  483. }
  484. catch (Exception)
  485. {
  486. throw;
  487. }
  488. }
  489. /// <summary>
  490. /// 采购拒收接口
  491. /// </summary>
  492. /// <param name="TransType"></param>
  493. /// <param name="Identification"></param>
  494. /// <param name="cmd"></param>
  495. public static void PurchaseRejectDocInNewERP(string DNCode, string JDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  496. {
  497. //try
  498. //{
  499. // #region ERP
  500. // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNDetailID,a.InvCode) AS Sequence,
  501. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.DNDetailID,con.Enable AS UpdateTodoQuantity
  502. // ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  503. // ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10,conv.Enable AS VerificationEnable
  504. // INTO #TempERP
  505. // FROM ICSWareHouseLotInfoLog a
  506. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  507. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  508. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  509. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  510. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  511. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  512. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  513. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  514. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  515. // WHERE a.Identification='{0}' AND ERPUpload='0'
  516. // GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conv.Enable
  517. // ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  518. // ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  519. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  520. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  521. // FROM #TempERP
  522. // DROP TABLE #TempERP";
  523. // sql = string.Format(sql, Identification);
  524. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  525. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  526. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  527. // Result result = new Result();
  528. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  529. // if (result.Success)
  530. // {
  531. // try
  532. // {
  533. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  534. // foreach (var item in res)
  535. // {
  536. // JObject jo = (JObject)item;
  537. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  538. // foreach (var detail in resdetail)
  539. // {
  540. // JObject det = (JObject)detail;
  541. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  542. // }
  543. // }
  544. // }
  545. // catch (Exception ex)
  546. // {
  547. // log.Debug(ex.ToString());
  548. // log.Debug(resultStr);
  549. // }
  550. // }
  551. // else
  552. // {
  553. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  554. // }
  555. // #endregion
  556. //}
  557. //catch (Exception)
  558. //{
  559. // throw;
  560. //}
  561. try
  562. {
  563. #region ERP
  564. string sql = @"SELECT a.VenCode+a.DepCode+a.DNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,a.DNCode,a.MUSER,a.MTIME,
  565. a.Sequence,a.InvCode,Sum(x.Quantity) AS Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.DNDetailID
  566. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  567. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  568. INTO #TempERP
  569. FROM ICSDeliveryNotice a
  570. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  571. INNER JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  572. INNER JOIN ICSDeliveryNotice x ON a.DNDetailID=x.PODetailID AND a.WorkPoint=x.WorkPoint
  573. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  574. GROUP BY a.VenCode,a.DepCode,a.DNCode,a.MUSER,a.MTIME,a.Sequence,a.InvCode,a.Amount,a.Quantity,a.UnitPrice,a.Currency,a.DNDetailID,
  575. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  576. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  577. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  578. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  579. FROM #TempERP
  580. DROP TABLE #TempERP";
  581. sql = string.Format(sql, DNCode, WorkPoint);
  582. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  583. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  584. string resultStr = HTTPHelper.HttpPost("采购拒收", ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  585. Result result = new Result();
  586. result = JsonConvert.DeserializeObject<Result>(resultStr);
  587. if (result.Success)
  588. {
  589. try
  590. {
  591. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  592. foreach (var item in res)
  593. {
  594. JObject jo = (JObject)item;
  595. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  596. foreach (var detail in resdetail)
  597. {
  598. JObject det = (JObject)detail;
  599. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  600. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  601. where PODetailID='{4}' AND DNType='3' AND DNCode='{5}' ";
  602. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], JDNCode);
  603. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  604. {
  605. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  606. }
  607. }
  608. }
  609. }
  610. catch (Exception ex)
  611. {
  612. log.Debug(ex.ToString());
  613. log.Debug(resultStr);
  614. }
  615. }
  616. else
  617. {
  618. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  619. }
  620. #endregion
  621. }
  622. catch (Exception)
  623. {
  624. throw;
  625. }
  626. }
  627. /// <summary>
  628. /// 采购拒收接口
  629. /// </summary>
  630. /// <param name="TransType"></param>
  631. /// <param name="Identification"></param>
  632. /// <param name="cmd"></param>
  633. public static void PurchaseRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  634. {
  635. //try
  636. //{
  637. // #region ERP
  638. // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNDetailID,a.InvCode) AS Sequence,
  639. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.DNDetailID,con.Enable AS UpdateTodoQuantity
  640. // ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  641. // ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10,conv.Enable AS VerificationEnable
  642. // INTO #TempERP
  643. // FROM ICSWareHouseLotInfoLog a
  644. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  645. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  646. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  647. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  648. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  649. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  650. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  651. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  652. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  653. // WHERE a.Identification='{0}' AND ERPUpload='0'
  654. // GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conv.Enable
  655. // ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  656. // ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  657. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  658. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  659. // FROM #TempERP
  660. // DROP TABLE #TempERP";
  661. // sql = string.Format(sql, Identification);
  662. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  663. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  664. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  665. // Result result = new Result();
  666. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  667. // if (result.Success)
  668. // {
  669. // try
  670. // {
  671. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  672. // foreach (var item in res)
  673. // {
  674. // JObject jo = (JObject)item;
  675. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  676. // foreach (var detail in resdetail)
  677. // {
  678. // JObject det = (JObject)detail;
  679. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  680. // }
  681. // }
  682. // }
  683. // catch (Exception ex)
  684. // {
  685. // log.Debug(ex.ToString());
  686. // log.Debug(resultStr);
  687. // }
  688. // }
  689. // else
  690. // {
  691. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  692. // }
  693. // #endregion
  694. //}
  695. //catch (Exception)
  696. //{
  697. // throw;
  698. //}
  699. }
  700. #endregion
  701. #region 采购退货
  702. /// <summary>
  703. /// 采购退货
  704. /// </summary>
  705. /// <param name="TransCode"></param>
  706. /// <param name="TransSequence"></param>
  707. /// <param name="Quantity"></param>
  708. /// <param name="WorkPoint"></param>
  709. /// <param name="cmd"></param>
  710. public static void PurchaseReceiveDoctNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  711. {
  712. try
  713. {
  714. string sql = @"DECLARE @Status VARCHAR(10)
  715. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}'
  716. IF (@Status IS NULL)
  717. BEGIN
  718. RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
  719. RETURN
  720. END
  721. ELSE IF (@Status!='2')
  722. BEGIN
  723. RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
  724. RETURN
  725. END
  726. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  727. FROM ICSDeliveryNotice a
  728. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  729. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
  730. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND DNType='2')
  731. BEGIN
  732. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  733. RETURN
  734. END";
  735. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  736. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  737. {
  738. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  739. }
  740. }
  741. catch (Exception)
  742. {
  743. throw;
  744. }
  745. }
  746. /// <summary>
  747. /// 采购退货接口
  748. /// </summary>
  749. /// <param name="TransType"></param>
  750. /// <param name="Identification"></param>
  751. /// <param name="cmd"></param>
  752. public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  753. {
  754. try
  755. {
  756. #region SAP(三层结构)
  757. string IsSuccess = "";
  758. string ErrorMessage = "";
  759. string sql = @" select Distinct A.DNCode,A.WorkPoint from ICSDeliveryNotice A
  760. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.DNCode AND B.WorkPoint=A.WorkPoint
  761. where B.Identification='{0}' AND BusinessCode='3'";
  762. sql = string.Format(sql, Identification);
  763. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  764. if (dt.Rows.Count > 1)
  765. {
  766. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  767. }
  768. for (int i = 0; i < dt.Rows.Count; i++)
  769. {
  770. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  771. where DNCode='{0}' and WorkPoint='{1}'
  772. GROUP BY DNCode,WorkPoint";
  773. chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  774. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  775. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  776. {
  777. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  778. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  779. Info.NEWID = Identification;
  780. Info.DANJU = dt.Rows[i]["DNCode"].ToString();
  781. Info.STATE = "0";
  782. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  783. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  784. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  785. sql = @"select A.DNCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.RCVQuantity
  786. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSDeliveryNotice A
  787. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  788. WHERE DNCode='{0}' AND A.WorkPoint='{1}'";
  789. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  790. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  791. foreach (DataRow dr in Sapdt.Rows)
  792. {
  793. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["RCVQuantity"].ToString()))
  794. {
  795. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  796. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  797. Item.DANJU = dr["DNCode"].ToString();
  798. Item.POSNR = dr["SAPSequence"].ToString();
  799. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  800. ItemList.Add(Item);
  801. if (dr["BatchCode"].ToString() != "")
  802. {
  803. ItemLine.DANJU= dr["DNCode"].ToString();
  804. ItemLine.POSNR= dr["SAPSequence"].ToString();
  805. ItemLine.MATNR = dr["InvCode"].ToString();
  806. ItemLine.GERNR = dr["BatchCode"].ToString();
  807. ItemLineList.Add(ItemLine);
  808. }
  809. }
  810. }
  811. if (ItemList.Count > 0)
  812. {
  813. Info.Z_ITEM = ItemList.ToArray();
  814. if (ItemLineList.Count > 0)
  815. {
  816. Info.Z_GERNR = ItemLineList.ToArray();
  817. }
  818. else
  819. {
  820. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  821. }
  822. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  823. result = Client.CallZWMS_SK_WS_PZ(Info);
  824. if (result.Z_NULL == "N")
  825. {
  826. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  827. {
  828. IsSuccess = "N";
  829. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  830. }
  831. }
  832. }
  833. }
  834. }
  835. if (IsSuccess == "N")
  836. {
  837. throw new Exception(ErrorMessage);
  838. }
  839. #endregion
  840. }
  841. catch (Exception)
  842. {
  843. throw;
  844. }
  845. }
  846. #endregion
  847. #region 开立红字入库
  848. /// <summary>
  849. /// 开立红字入库
  850. /// </summary>
  851. /// <param name="TransCode"></param>
  852. /// <param name="TransSequence"></param>
  853. /// <param name="Quantity"></param>
  854. /// <param name="WorkPoint"></param>
  855. /// <param name="cmd"></param>
  856. public static void PurchaseReceive(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  857. {
  858. try
  859. {
  860. string sql = @"DECLARE @Status VARCHAR(10)
  861. SELECT @Status=a.Status FROM ICSPurchaseReceive a
  862. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  863. IF (@Status IS NULL)
  864. BEGIN
  865. RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1);
  866. RETURN
  867. END
  868. ELSE IF (@Status!='1')
  869. BEGIN
  870. RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
  871. RETURN
  872. END
  873. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  874. FROM ICSPurchaseReceive a
  875. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  876. IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a
  877. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  878. BEGIN
  879. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  880. RETURN
  881. END";
  882. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  883. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  884. {
  885. throw new Exception(language.GetNameByCode("WMSAPIInfo092"));//"红字入库单更新失败!");
  886. }
  887. }
  888. catch (Exception)
  889. {
  890. throw;
  891. }
  892. }
  893. /// <summary>
  894. /// 开立红字入库接口
  895. /// </summary>
  896. /// <param name="TransType"></param>
  897. /// <param name="Identification"></param>
  898. /// <param name="cmd"></param>
  899. public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  900. {
  901. try
  902. {
  903. #region ERP开立状态单据审核
  904. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  905. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  906. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  907. BEGIN
  908. RAISERROR('" + language.GetNameByCode("WMSAPIInfo093") + @"',16,1);
  909. RETURN
  910. END
  911. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  912. FROM ICSWareHouseLotInfoLog a
  913. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  914. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  915. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  916. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '4'
  917. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  918. sql = string.Format(sql, Identification);
  919. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  920. string Inputstr = JsonConvert.SerializeObject(dt);
  921. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr);
  922. Result result = new Result();
  923. result = JsonConvert.DeserializeObject<Result>(resultStr);
  924. if (result.Success)
  925. {
  926. try
  927. {
  928. foreach (DataRow dr in dt.Rows)
  929. {
  930. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  931. }
  932. }
  933. catch (Exception ex)
  934. {
  935. log.Debug(ex.ToString());
  936. log.Debug(resultStr);
  937. }
  938. }
  939. else
  940. {
  941. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  942. }
  943. #endregion
  944. }
  945. catch (Exception)
  946. {
  947. throw;
  948. }
  949. }
  950. #endregion
  951. }
  952. }