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

1275 lines
75 KiB

3 years ago
3 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
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
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
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
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
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
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
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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 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 ICSWareHouseService
  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="TransCode"></param>
  27. /// <param name="TransSequence"></param>
  28. /// <param name="Quantity"></param>
  29. /// <param name="WorkPoint"></param>
  30. /// <param name="cmd"></param>
  31. public static void OneStepTransferDocIn(string TransCode,string TransSequence, string WorkPoint,string Quantity, SqlCommand cmd, Dictionary<string, string> language)
  32. {
  33. try
  34. {
  35. string sql = @"UPDATE ICSTransfer SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
  36. WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'
  37. IF EXISTS(SELECT a.ID FROM ICSTransfer a
  38. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1'
  39. AND a.Quantity<a.TransferQuantity)
  40. BEGIN
  41. RAISERROR('" + language.GetNameByCode("WMSAPIInfo144") + @"',16,1);
  42. RETURN
  43. END";
  44. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  45. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  46. {
  47. throw new Exception(language.GetNameByCode("WMSAPIInfo145"));//"调拨单信息更新失败!");
  48. }
  49. }
  50. catch (Exception)
  51. {
  52. throw;
  53. }
  54. }
  55. #region 一步调拨(调拨申请单)
  56. /// <summary>
  57. /// 一步调拨(调拨申请单)
  58. /// </summary>
  59. /// <param name="TransCode"></param>
  60. /// <param name="TransSequence"></param>
  61. /// <param name="Quantity"></param>
  62. /// <param name="WorkPoint"></param>
  63. /// <param name="cmd"></param>
  64. public static void OneStepTransferApplicationIn(string TransCode, string TransSequence, string WorkPoint, string Quantity, SqlCommand cmd, Dictionary<string, string> language)
  65. {
  66. try
  67. {
  68. string sql = @"UPDATE ICSTransferApplication SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
  69. WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'
  70. IF EXISTS(SELECT a.ID FROM ICSTransferApplication a
  71. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.TransferQuantity<a.TransferQuantity)
  72. BEGIN
  73. RAISERROR('" + language.GetNameByCode("WMSAPIInfo144") + @"',16,1);
  74. RETURN
  75. END";
  76. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  77. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  78. {
  79. throw new Exception(language.GetNameByCode("WMSAPIInfo145"));//"调拨单信息更新失败!");
  80. }
  81. }
  82. catch (Exception)
  83. {
  84. throw;
  85. }
  86. }
  87. /// <summary>
  88. /// 一步调拨接口
  89. /// </summary>
  90. /// <param name="TransType"></param>
  91. /// <param name="Identification"></param>
  92. /// <param name="cmd"></param>
  93. public static void OneStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  94. {
  95. try
  96. {
  97. #region SAP
  98. string IsSuccess = "";
  99. string ErrorMessage = "";
  100. string sql = @" select Distinct A.TransferNO,A.WorkPoint from ICSTransfer A
  101. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.TransferNO AND B.WorkPoint=A.WorkPoint
  102. where B.Identification='{0}' AND BusinessCode='21'";
  103. sql = string.Format(sql, Identification);
  104. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  105. if (dt.Rows.Count > 1)
  106. {
  107. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  108. }
  109. for (int i = 0; i < dt.Rows.Count; i++)
  110. {
  111. string chksql = @"select SUM(Quantity) AS Quantity,SUM(TransferQuantity) AS TransferQuantity from ICSTransfer
  112. where TransferNO='{0}' and WorkPoint='{1}'
  113. GROUP BY TransferNO,WorkPoint";
  114. chksql = string.Format(chksql, dt.Rows[i]["TransferNO"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  115. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  116. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["TransferQuantity"]))
  117. {
  118. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo203"), chkdt.Rows[0]["Quantity"].ToString(), chkdt.Rows[0]["TransferQuantity"].ToString()));//单次提交数量卡控(必须整单提交)
  119. }
  120. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  121. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  122. Info.NEWID = Identification;
  123. Info.DANJU = dt.Rows[i]["TransferNO"].ToString();
  124. Info.STATE = "0";
  125. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  126. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  127. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  128. sql = @" select A.TransferNO,A.Sequence,A.Quantity,A.TransferQuantity,B.BatchCode from ICSTransfer A
  129. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  130. WHERE TransferNO='{0}' AND A.WorkPoint='{1}'";
  131. sql = string.Format(sql, dt.Rows[i]["TransferNO"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  132. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  133. foreach (DataRow dr in Sapdt.Rows)
  134. {
  135. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["TransferQuantity"].ToString()))
  136. {
  137. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  138. Item.DANJU = dr["TransferNO"].ToString();
  139. Item.POSNR = dr["Sequence"].ToString();
  140. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  141. Item.SERNP = dr["BatchCode"].ToString();
  142. ItemList.Add(Item);
  143. }
  144. }
  145. if (ItemList.Count > 0)
  146. {
  147. Info.Z_ITEM = ItemList.ToArray();
  148. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  149. result = Client.CallZWMS_SK_WS_PZ(Info);
  150. if (result.Z_NULL == "N")
  151. {
  152. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  153. {
  154. IsSuccess = "N";
  155. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  156. }
  157. }
  158. }
  159. }
  160. if (IsSuccess == "N")
  161. {
  162. throw new Exception(ErrorMessage);
  163. }
  164. #endregion
  165. }
  166. catch (Exception)
  167. {
  168. throw;
  169. }
  170. }
  171. #endregion
  172. #region 调拨
  173. /// <summary>
  174. /// 调拨接口
  175. /// </summary>
  176. /// <param name="TransType"></param>
  177. /// <param name="Identification"></param>
  178. /// <param name="cmd"></param>
  179. public static void StepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  180. {
  181. try
  182. {
  183. #region ERP开立状态单据审核
  184. //检验调拨单是否一次性发完
  185. string sql = @"SELECT a.ToWarehouseCode+a.MUSER+a.FromWarehouseCode AS Costre,a.ToWarehouseCode AS ToWHCode,a.FromWarehouseCode AS FromWHCode,a.MUSER,'' AS FromDepCode,'' AS ToDepCode,NULL AS TACode,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode) AS Sequence,NULL AS TADetailID,
  186. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  187. ,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,
  188. 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
  189. INTO #TempERP
  190. FROM ICSWareHouseLotInfoLog a
  191. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  192. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  193. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  194. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  195. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  196. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  197. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  198. WHERE a.Identification='{0}' AND ERPUpload='0'
  199. GROUP BY a.ToWarehouseCode,a.MUSER,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
  200. ,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, ''),
  201. 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, '')
  202. SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
  203. SELECT Costre,Sequence,InvCode,Quantity,Amount,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  204. FROM #TempERP
  205. DROP TABLE #TempERP";
  206. sql = string.Format(sql, Identification);
  207. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  208. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  209. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.StepTransferDocInURL, Inputstr);
  210. Result result = new Result();
  211. result = JsonConvert.DeserializeObject<Result>(resultStr);
  212. if (result.Success)
  213. {
  214. try
  215. {
  216. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  217. foreach (var item in res)
  218. {
  219. JObject jo = (JObject)item;
  220. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  221. foreach (var detail in resdetail)
  222. {
  223. JObject det = (JObject)detail;
  224. 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()
  225. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  226. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(),allcol, cmd, language, BusinessCode);
  227. }
  228. }
  229. }
  230. catch (Exception ex)
  231. {
  232. log.Debug(ex.ToString());
  233. log.Debug(resultStr);
  234. }
  235. }
  236. else
  237. {
  238. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  239. }
  240. #endregion
  241. }
  242. catch (Exception)
  243. {
  244. throw;
  245. }
  246. }
  247. #endregion
  248. #region 调拨申请单接口
  249. /// <summary>
  250. /// 调拨申请单接口
  251. /// </summary>
  252. /// <param name="TransType"></param>
  253. /// <param name="Identification"></param>
  254. /// <param name="cmd"></param>
  255. public static void StepTransferApplicationERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  256. {
  257. try
  258. {
  259. #region ERP开立状态单据审核
  260. //检验调拨单是否一次性发完
  261. string sql = @"SELECT c.TransferDetailID as TADetailID,a.ToWarehouseCode+a.MUSER+a.FromWarehouseCode AS Costre,a.ToWarehouseCode AS ToWHCode,a.FromWarehouseCode AS FromWHCode,a.MUSER,'' AS FromDepCode,'' AS ToDepCode,a.TransCode AS TACode,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode) AS Sequence,
  262. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  263. ,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,
  264. 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
  265. INTO #TempERP
  266. FROM ICSWareHouseLotInfoLog a
  267. INNER JOIN ICSTransfer c ON a.TransCode=c.TransferNO and a.TransSequence=c.Sequence and a.WorkPoint=c.WorkPoint
  268. --INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  269. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  270. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  271. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  272. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  273. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  274. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  275. WHERE a.Identification='{0}' AND ERPUpload='0'
  276. GROUP BY a.ToWarehouseCode,a.MUSER,c.TransferDetailID,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
  277. ,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, ''),
  278. 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, ''),a.TransCode
  279. SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
  280. SELECT Costre,Sequence,InvCode,Quantity,Amount,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  281. FROM #TempERP
  282. DROP TABLE #TempERP";
  283. sql = string.Format(sql, Identification);
  284. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  285. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  286. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.StepTransferApplicationURL, Inputstr);
  287. Result result = new Result();
  288. result = JsonConvert.DeserializeObject<Result>(resultStr);
  289. if (result.Success)
  290. {
  291. try
  292. {
  293. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  294. foreach (var item in res)
  295. {
  296. JObject jo = (JObject)item;
  297. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  298. foreach (var detail in resdetail)
  299. {
  300. JObject det = (JObject)detail;
  301. string allcol = "" + 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()
  302. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  303. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  304. }
  305. }
  306. }
  307. catch (Exception ex)
  308. {
  309. log.Debug(ex.ToString());
  310. log.Debug(resultStr);
  311. }
  312. }
  313. else
  314. {
  315. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  316. }
  317. #endregion
  318. }
  319. catch (Exception)
  320. {
  321. throw;
  322. }
  323. }
  324. #endregion
  325. #region 两步调出
  326. /// <summary>
  327. /// 两步调出
  328. /// </summary>
  329. /// <param name="TransCode"></param>
  330. /// <param name="TransSequence"></param>
  331. /// <param name="Quantity"></param>
  332. /// <param name="WorkPoint"></param>
  333. /// <param name="cmd"></param>
  334. public static void TwoStepTransferDocOut(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  335. {
  336. try
  337. {
  338. string sql = @"DECLARE @Status VARCHAR(10)
  339. SELECT @Status=a.Status FROM ICSOtherOut a
  340. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  341. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  342. IF (@Status IS NULL)
  343. BEGIN
  344. RAISERROR('" + language.GetNameByCode("WMSAPIInfo146") + @"',16,1);
  345. RETURN
  346. END
  347. ELSE IF (@Status!='1')
  348. BEGIN
  349. RAISERROR('" + language.GetNameByCode("WMSAPIInfo147") + @"',16,1);
  350. RETURN
  351. END
  352. UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
  353. FROM ICSOtherOut a
  354. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  355. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  356. IF EXISTS(SELECT a.ID FROM ICSOtherOut a
  357. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  358. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.OutQuantity)
  359. BEGIN
  360. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  361. RETURN
  362. END";
  363. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  364. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  365. {
  366. throw new Exception(language.GetNameByCode("WMSAPIInfo148"));//"两步调出单更新失败!");
  367. }
  368. }
  369. catch (Exception)
  370. {
  371. throw;
  372. }
  373. }
  374. /// <summary>
  375. /// 两步调出接口
  376. /// </summary>
  377. /// <param name="TransType"></param>
  378. /// <param name="Identification"></param>
  379. /// <param name="cmd"></param>
  380. public static void TwoStepTransferDocOutERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  381. {
  382. try
  383. {
  384. #region ERP开立状态单据审核
  385. string sql = @"IF EXISTS(SELECT b.ID FROM ICSOtherOut b
  386. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  387. WHERE b.OutCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  388. AND b.Quantity!=b.OutQuantity)
  389. BEGIN
  390. RAISERROR('" + language.GetNameByCode("WMSAPIInfo098") + @"',16,1);
  391. RETURN
  392. END
  393. SELECT b.OutID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  394. FROM ICSWareHouseLotInfoLog a
  395. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  396. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  397. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  398. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  399. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '22'
  400. GROUP BY b.OutID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  401. sql = string.Format(sql, Identification);
  402. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  403. string Inputstr = JsonConvert.SerializeObject(dt);
  404. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocOutURL, Inputstr);
  405. Result result = new Result();
  406. result = JsonConvert.DeserializeObject<Result>(resultStr);
  407. if (result.Success)
  408. {
  409. try
  410. {
  411. foreach (DataRow dr in dt.Rows)
  412. {
  413. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  414. }
  415. }
  416. catch (Exception ex)
  417. {
  418. log.Debug(ex.ToString());
  419. log.Debug(resultStr);
  420. }
  421. }
  422. else
  423. {
  424. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  425. }
  426. #endregion
  427. }
  428. catch (Exception)
  429. {
  430. throw;
  431. }
  432. }
  433. #endregion
  434. #region 两步调入
  435. /// <summary>
  436. /// 两步调入
  437. /// </summary>
  438. /// <param name="TransCode"></param>
  439. /// <param name="TransSequence"></param>
  440. /// <param name="Quantity"></param>
  441. /// <param name="WorkPoint"></param>
  442. /// <param name="cmd"></param>
  443. public static void TwoStepTransferDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  444. {
  445. //需要关联其他入库单
  446. try
  447. {
  448. string sql = @"DECLARE @Status VARCHAR(10)
  449. SELECT @Status=Otin.Status FROM ICSOtherIn Otin
  450. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  451. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  452. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  453. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  454. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}'
  455. IF (@Status IS NULL)
  456. BEGIN
  457. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  458. RETURN
  459. END
  460. ELSE IF (@Status!='1')
  461. BEGIN
  462. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  463. RETURN
  464. END
  465. UPDATE Otin SET InQuantity=ISNULL(InQuantity,0)+'{4}'
  466. FROM ICSOtherIn Otin
  467. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  468. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  469. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  470. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  471. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}'
  472. IF EXISTS(SELECT a.LotNo FROM ICSOtherIn Otin
  473. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  474. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  475. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  476. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  477. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}' AND Otin.Quantity<Otin.InQuantity)
  478. BEGIN
  479. RAISERROR('" + language.GetNameByCode("WMSAPIInfo149") + @"',16,1);
  480. END";
  481. sql = string.Format(sql, LotNo, WorkPoint,TransCode,TransSequence, Quantity);
  482. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  483. {
  484. throw new Exception(language.GetNameByCode("WMSAPIInfo150"));//"两步调入单更新失败!");
  485. }
  486. }
  487. catch (Exception)
  488. {
  489. throw;
  490. }
  491. }
  492. /// <summary>
  493. /// 两步调入接口
  494. /// </summary>
  495. /// <param name="TransType"></param>
  496. /// <param name="Identification"></param>
  497. /// <param name="cmd"></param>
  498. public static void TwoStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  499. {
  500. try
  501. {
  502. #region ERP开立状态单据审核
  503. string sql = @"IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  504. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  505. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  506. AND b.Quantity!=b.InQuantity)
  507. BEGIN
  508. RAISERROR('" + language.GetNameByCode("WMSAPIInfo099") + @"',16,1);
  509. RETURN
  510. END
  511. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  512. FROM ICSWareHouseLotInfoLog a
  513. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  514. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  515. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  516. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  517. WHERE a.Identification='{0}' AND ERPUpload='0'
  518. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  519. sql = string.Format(sql, Identification);
  520. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  521. string Inputstr = JsonConvert.SerializeObject(dt);
  522. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocInURL, Inputstr);
  523. Result result = new Result();
  524. result = JsonConvert.DeserializeObject<Result>(resultStr);
  525. if (result.Success)
  526. {
  527. try
  528. {
  529. foreach (DataRow dr in dt.Rows)
  530. {
  531. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "","", cmd, language, BusinessCode);
  532. }
  533. }
  534. catch (Exception ex)
  535. {
  536. log.Debug(ex.ToString());
  537. log.Debug(resultStr);
  538. }
  539. }
  540. else
  541. {
  542. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  543. }
  544. #endregion
  545. }
  546. catch (Exception)
  547. {
  548. throw;
  549. }
  550. }
  551. #endregion
  552. #region 其他出库
  553. /// <summary>
  554. /// 其他出库
  555. /// </summary>
  556. /// <param name="TransCode"></param>
  557. /// <param name="TransSequence"></param>
  558. /// <param name="Quantity"></param>
  559. /// <param name="WorkPoint"></param>
  560. /// <param name="cmd"></param>
  561. public static void OtherOutDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  562. {
  563. try
  564. {
  565. string sql = @"DECLARE @Status VARCHAR(10)
  566. SELECT @Status=a.Status FROM ICSOtherOut a
  567. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  568. IF (@Status IS NULL)
  569. BEGIN
  570. RAISERROR('" + language.GetNameByCode("WMSAPIInfo151") + @"',16,1);
  571. RETURN
  572. END
  573. ELSE IF (@Status!='1')
  574. BEGIN
  575. RAISERROR('" + language.GetNameByCode("WMSAPIInfo152") + @"',16,1);
  576. RETURN
  577. END
  578. UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
  579. FROM ICSOtherOut a
  580. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  581. IF EXISTS(SELECT a.ID FROM ICSOtherOut a
  582. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.OutQuantity)
  583. BEGIN
  584. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  585. RETURN
  586. END";
  587. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  588. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  589. {
  590. throw new Exception(language.GetNameByCode("WMSAPIInfo153"));//"其他出库单更新失败!");
  591. }
  592. }
  593. catch (Exception)
  594. {
  595. throw;
  596. }
  597. }
  598. /// <summary>
  599. /// 其他出库接口
  600. /// </summary>
  601. /// <param name="TransType"></param>
  602. /// <param name="Identification"></param>
  603. /// <param name="cmd"></param>
  604. public static void OtherOutDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  605. {
  606. try
  607. {
  608. #region SAP
  609. string IsSuccess = "";
  610. string ErrorMessage = "";
  611. string sql = @" select Distinct A.OutCode,A.WorkPoint from ICSOtherOut A
  612. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.OutCode AND B.WorkPoint=A.WorkPoint
  613. where B.Identification='{0}' AND BusinessCode='24'";
  614. sql = string.Format(sql, Identification);
  615. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  616. if (dt.Rows.Count > 1)
  617. {
  618. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  619. }
  620. for (int i = 0; i < dt.Rows.Count; i++)
  621. {
  622. string chksql = @"select SUM(Quantity) AS Quantity,SUM(OutQuantity) AS OutQuantity from ICSOtherOut
  623. where OutCode='{0}' and WorkPoint='{1}'
  624. GROUP BY OutCode,WorkPoint";
  625. chksql = string.Format(chksql, dt.Rows[i]["OutCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  626. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  627. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["OutQuantity"]))
  628. {
  629. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo203"), chkdt.Rows[0]["Quantity"].ToString(), chkdt.Rows[0]["OutQuantity"].ToString()));//单次提交数量卡控(必须整单提交)
  630. }
  631. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  632. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  633. Info.NEWID = Identification;
  634. Info.DANJU = dt.Rows[i]["OutCode"].ToString();
  635. Info.STATE = "0";
  636. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  637. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  638. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  639. sql = @"select A.OutCode,A.Sequence,A.Quantity,A.OutQuantity,B.BatchCode from ICSOtherOut A
  640. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  641. WHERE OutCode='{0}' AND A.WorkPoint='{1}'";
  642. sql = string.Format(sql, dt.Rows[i]["OutCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  643. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  644. foreach (DataRow dr in Sapdt.Rows)
  645. {
  646. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["OutQuantity"].ToString()))
  647. {
  648. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  649. Item.DANJU = dr["OutCode"].ToString();
  650. Item.POSNR = dr["Sequence"].ToString();
  651. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  652. Item.SERNP = dr["BatchCode"].ToString();
  653. ItemList.Add(Item);
  654. }
  655. }
  656. if (ItemList.Count > 0)
  657. {
  658. Info.Z_ITEM = ItemList.ToArray();
  659. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  660. result = Client.CallZWMS_SK_WS_PZ(Info);
  661. if (result.Z_NULL == "N")
  662. {
  663. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  664. {
  665. IsSuccess = "N";
  666. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  667. }
  668. }
  669. }
  670. }
  671. if (IsSuccess == "N")
  672. {
  673. throw new Exception(ErrorMessage);
  674. }
  675. #endregion
  676. }
  677. catch (Exception)
  678. {
  679. throw;
  680. }
  681. }
  682. #endregion
  683. #region 其他入库
  684. /// <summary>
  685. /// 其他入库
  686. /// </summary>
  687. /// <param name="TransCode"></param>
  688. /// <param name="TransSequence"></param>
  689. /// <param name="Quantity"></param>
  690. /// <param name="WorkPoint"></param>
  691. /// <param name="cmd"></param>
  692. public static void OtherInDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  693. {
  694. try
  695. {
  696. string sql = @"DECLARE @Status VARCHAR(10)
  697. SELECT @Status=c.Status FROM ICSInventoryLot a
  698. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  699. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  700. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  701. IF (@Status IS NULL)
  702. BEGIN
  703. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  704. RETURN
  705. END
  706. ELSE IF (@Status!='1')
  707. BEGIN
  708. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  709. RETURN
  710. END
  711. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  712. FROM ICSInventoryLot a
  713. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  714. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  715. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  716. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  717. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  718. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  719. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  720. BEGIN
  721. RAISERROR('" + language.GetNameByCode("WMSAPIInfo154") + @"',16,1);
  722. END";
  723. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  724. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  725. {
  726. throw new Exception(language.GetNameByCode("WMSAPIInfo155"));//"其他入库单更新失败!");
  727. }
  728. }
  729. catch (Exception)
  730. {
  731. throw;
  732. }
  733. }
  734. /// <summary>
  735. /// 其他入库接口
  736. /// </summary>
  737. /// <param name="TransType"></param>
  738. /// <param name="Identification"></param>
  739. /// <param name="cmd"></param>
  740. public static void OtherInDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  741. {
  742. try
  743. {
  744. #region SAP
  745. string IsSuccess = "";
  746. string ErrorMessage = "";
  747. string sql = @" select Distinct A.InCode,A.WorkPoint from ICSOtherIn A
  748. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.InCode AND B.WorkPoint=A.WorkPoint
  749. where B.Identification='{0}' AND BusinessCode='25'";
  750. sql = string.Format(sql, Identification);
  751. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  752. if (dt.Rows.Count > 1)
  753. {
  754. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  755. }
  756. for (int i = 0; i < dt.Rows.Count; i++)
  757. {
  758. string chksql = @"select SUM(Quantity) AS Quantity,SUM(InQuantity) AS InQuantity from ICSOtherIn
  759. where InCode='{0}' and WorkPoint='{1}'
  760. GROUP BY InCode,WorkPoint";
  761. chksql = string.Format(chksql, dt.Rows[i]["InCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  762. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  763. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["InQuantity"]))
  764. {
  765. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo203"), chkdt.Rows[0]["Quantity"].ToString(), chkdt.Rows[0]["InQuantity"].ToString()));//单次提交数量卡控(必须整单提交)
  766. }
  767. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  768. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  769. Info.NEWID = Identification;
  770. Info.DANJU = dt.Rows[i]["InCode"].ToString();
  771. Info.STATE = "0";
  772. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  773. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  774. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  775. sql = @"select A.InCode,A.Sequence,A.Quantity,A.InQuantity,B.BatchCode from ICSOtherIn A
  776. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  777. WHERE InCode='{0}' AND A.WorkPoint='{1}'";
  778. sql = string.Format(sql, dt.Rows[i]["InCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  779. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  780. foreach (DataRow dr in Sapdt.Rows)
  781. {
  782. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["InQuantity"].ToString()))
  783. {
  784. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  785. Item.DANJU = dr["InCode"].ToString();
  786. Item.POSNR = dr["Sequence"].ToString();
  787. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  788. Item.SERNP = dr["BatchCode"].ToString();
  789. ItemList.Add(Item);
  790. }
  791. }
  792. if (ItemList.Count > 0)
  793. {
  794. Info.Z_ITEM = ItemList.ToArray();
  795. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  796. result = Client.CallZWMS_SK_WS_PZ(Info);
  797. if (result.Z_NULL == "N")
  798. {
  799. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  800. {
  801. IsSuccess = "N";
  802. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  803. }
  804. }
  805. }
  806. }
  807. if (IsSuccess == "N")
  808. {
  809. throw new Exception(ErrorMessage);
  810. }
  811. #endregion
  812. }
  813. catch (Exception)
  814. {
  815. throw;
  816. }
  817. }
  818. #endregion
  819. #region 拆卸单
  820. /// <summary>
  821. /// 拆卸单
  822. /// </summary>
  823. /// <param name="TransCode"></param>
  824. /// <param name="TransSequence"></param>
  825. /// <param name="Quantity"></param>
  826. /// <param name="WorkPoint"></param>
  827. /// <param name="cmd"></param>
  828. public static void DisassemblyDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  829. {
  830. try
  831. {
  832. string sql = @"DECLARE @Status VARCHAR(10)
  833. SELECT @Status=c.Status FROM ICSInventoryLot a
  834. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  835. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  836. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DABDOCType='2'
  837. IF (@Status IS NULL)
  838. BEGIN
  839. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  840. RETURN
  841. END
  842. ELSE IF (@Status!='1')
  843. BEGIN
  844. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  845. RETURN
  846. END
  847. UPDATE c SET DABDOCQuantity=ISNULL(DABDOCQuantity,0)+'{2}'
  848. FROM ICSInventoryLot a
  849. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  850. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  851. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  852. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  853. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  854. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  855. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.DABDOCQuantity)
  856. BEGIN
  857. RAISERROR('" + language.GetNameByCode("WMSAPIInfo156") + @"',16,1);
  858. END";
  859. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  860. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  861. {
  862. throw new Exception(language.GetNameByCode("WMSAPIInfo157"));//"拆卸单更新失败!");
  863. }
  864. }
  865. catch (Exception)
  866. {
  867. throw;
  868. }
  869. }
  870. /// <summary>
  871. /// 拆卸单更新套件锁定数量
  872. /// </summary>
  873. /// <param name="Identification"></param>
  874. /// <param name="cmd"></param>
  875. public static void DisassemblyDoc(string Identification, SqlCommand cmd, Dictionary<string, string> language)
  876. {
  877. try
  878. {
  879. string sql = @"UPDATE ICSDisassemblyDoc SET DABDOCQuantity=Quantity
  880. WHERE DABDOCCode+Sequence+WorkPoint IN(SELECT DISTINCT d.TransCode+d.TransSequence+d.WorkPoint
  881. FROM ICSWareHouseLotInfoLog a
  882. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  883. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  884. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  885. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')
  886. UPDATE ICSWareHouseLotInfo SET Quantity=Quantity-LockQuantity,LockQuantity=0
  887. WHERE LotNo+WorkPoint IN(SELECT DISTINCT d.LotNo+d.WorkPoint
  888. FROM ICSWareHouseLotInfoLog a
  889. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  890. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  891. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  892. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')";
  893. sql = string.Format(sql, Identification);
  894. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  895. {
  896. throw new Exception(language.GetNameByCode("WMSAPIInfo158"));//"拆卸单套件更新失败!");
  897. }
  898. }
  899. catch (Exception)
  900. {
  901. throw;
  902. }
  903. }
  904. /// <summary>
  905. /// 拆卸单接口
  906. /// </summary>
  907. /// <param name="TransType"></param>
  908. /// <param name="Identification"></param>
  909. /// <param name="cmd"></param>
  910. public static void DisassemblyDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  911. {
  912. try
  913. {
  914. #region ERP开立状态单据审核
  915. string sql = @"IF EXISTS(SELECT b.ID FROM ICSDisassemblyDoc b
  916. WHERE b.DABDOCCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  917. AND b.Quantity!=b.DABDOCQuantity)
  918. BEGIN
  919. RAISERROR('" + language.GetNameByCode("WMSAPIInfo102") + @"',16,1);
  920. RETURN
  921. END
  922. SELECT b.DABDOCID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  923. FROM ICSWareHouseLotInfoLog a
  924. INNER JOIN ICSDisassemblyDoc b ON a.TransCode=b.DABDOCCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  925. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  926. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  927. WHERE a.Identification='{0}' AND ERPUpload='0'
  928. GROUP BY b.DABDOCID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  929. sql = string.Format(sql, Identification);
  930. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  931. string Inputstr = JsonConvert.SerializeObject(dt);
  932. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DisassemblyDocURL, Inputstr);
  933. Result result = new Result();
  934. result = JsonConvert.DeserializeObject<Result>(resultStr);
  935. if (result.Success)
  936. {
  937. try
  938. {
  939. foreach (DataRow dr in dt.Rows)
  940. {
  941. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "","", cmd, language, BusinessCode);
  942. }
  943. }
  944. catch (Exception ex)
  945. {
  946. log.Debug(ex.ToString());
  947. log.Debug(resultStr);
  948. }
  949. }
  950. else
  951. {
  952. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  953. }
  954. #endregion
  955. }
  956. catch (Exception)
  957. {
  958. throw;
  959. }
  960. }
  961. #endregion
  962. #region 借用
  963. /// <summary>
  964. /// 借用
  965. /// </summary>
  966. /// <param name="TransCode"></param>
  967. /// <param name="TransSequence"></param>
  968. /// <param name="Quantity"></param>
  969. /// <param name="WorkPoint"></param>
  970. /// <param name="cmd"></param>
  971. public static void BrrowDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  972. {
  973. try
  974. {
  975. string sql = @"DECLARE @Status VARCHAR(10)
  976. SELECT @Status=a.Status FROM ICSBrrow a
  977. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  978. IF (@Status IS NULL)
  979. BEGIN
  980. RAISERROR('" + language.GetNameByCode("WMSAPIInfo159") + @"',16,1);
  981. RETURN
  982. END
  983. ELSE IF (@Status!='2')
  984. BEGIN
  985. RAISERROR('" + language.GetNameByCode("WMSAPIInfo160") + @"',16,1);
  986. RETURN
  987. END
  988. UPDATE a SET BrrowQuantity=ISNULL(BrrowQuantity,0)+'{2}'
  989. FROM ICSBrrow a
  990. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  991. IF EXISTS(SELECT a.ID FROM ICSBrrow a
  992. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.BrrowQuantity)
  993. BEGIN
  994. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  995. RETURN
  996. END";
  997. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  998. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  999. {
  1000. throw new Exception(language.GetNameByCode("WMSAPIInfo161"));//"借用单更新失败!");
  1001. }
  1002. }
  1003. catch (Exception)
  1004. {
  1005. throw;
  1006. }
  1007. }
  1008. /// <summary>
  1009. /// 借用接口
  1010. /// </summary>
  1011. /// <param name="TransType"></param>
  1012. /// <param name="Identification"></param>
  1013. /// <param name="cmd"></param>
  1014. public static void BrrowDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1015. {
  1016. try
  1017. {
  1018. #region ERP
  1019. string sql = @"SELECT a.FromWarehouseCode+b.BrrowCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.BrrowCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.BrrowCode,b.BrrowDetailID,a.InvCode) AS Sequence,
  1020. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(b.Amount/b.Quantity)) AS Amount,b.BrrowDetailID,Enable AS UpdateTodoQuantity
  1021. ,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,
  1022. 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
  1023. INTO #TempERP
  1024. FROM ICSWareHouseLotInfoLog a
  1025. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1026. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1027. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1028. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1029. INNER JOIN ICSBrrow b ON a.TransCode=b.BrrowCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1030. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1031. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '26'
  1032. GROUP BY a.FromWarehouseCode,b.BrrowCode,a.MUSER,a.InvCode,b.BrrowDetailID,Enable
  1033. ,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, ''),
  1034. 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, '')
  1035. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,BrrowCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1036. SELECT Costre,Sequence,InvCode,Quantity,Amount,BrrowDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1037. DROP TABLE #TempERP";
  1038. sql = string.Format(sql, Identification);
  1039. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1040. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1041. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.BrrowDocURL, Inputstr);
  1042. Result result = new Result();
  1043. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1044. if (result.Success)
  1045. {
  1046. try
  1047. {
  1048. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1049. foreach (var item in res)
  1050. {
  1051. JObject jo = (JObject)item;
  1052. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1053. foreach (var detail in resdetail)
  1054. {
  1055. JObject det = (JObject)detail;
  1056. 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()
  1057. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1058. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1059. det["DetailID"].ToString(), jo["OtherOutCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1060. }
  1061. }
  1062. }
  1063. catch (Exception ex)
  1064. {
  1065. log.Debug(ex.ToString());
  1066. log.Debug(resultStr);
  1067. }
  1068. }
  1069. else
  1070. {
  1071. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1072. }
  1073. #endregion
  1074. }
  1075. catch (Exception)
  1076. {
  1077. throw;
  1078. }
  1079. }
  1080. #endregion
  1081. #region 归还
  1082. /// <summary>
  1083. /// 归还
  1084. /// </summary>
  1085. /// <param name="TransCode"></param>
  1086. /// <param name="TransSequence"></param>
  1087. /// <param name="Quantity"></param>
  1088. /// <param name="WorkPoint"></param>
  1089. /// <param name="cmd"></param>
  1090. public static void ReturnDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1091. {
  1092. try
  1093. {
  1094. string sql = @"DECLARE @Status VARCHAR(10)
  1095. SELECT @Status=c.Status FROM ICSInventoryLot a
  1096. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1097. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1098. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1099. IF (@Status IS NULL)
  1100. BEGIN
  1101. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1102. RETURN
  1103. END
  1104. ELSE IF (@Status!='2')
  1105. BEGIN
  1106. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  1107. RETURN
  1108. END
  1109. UPDATE c SET ReturnQuantity=ISNULL(ReturnQuantity,0)+'{2}'
  1110. FROM ICSInventoryLot a
  1111. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1112. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1113. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1114. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1115. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1116. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1117. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.ReturnQuantity)
  1118. BEGIN
  1119. RAISERROR('" + language.GetNameByCode("WMSAPIInfo162") + @"',16,1);
  1120. END";
  1121. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1122. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1123. {
  1124. throw new Exception(language.GetNameByCode("WMSAPIInfo163"));//"归还单更新失败!");
  1125. }
  1126. }
  1127. catch (Exception)
  1128. {
  1129. throw;
  1130. }
  1131. }
  1132. /// <summary>
  1133. /// 归还接口
  1134. /// </summary>
  1135. /// <param name="TransType"></param>
  1136. /// <param name="Identification"></param>
  1137. /// <param name="cmd"></param>
  1138. public static void ReturnDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1139. {
  1140. try
  1141. {
  1142. #region ERP
  1143. string sql = @"SELECT a.ToWarehouseCode+b.ReturnCode+a.MUSER AS Costre,a.ToWarehouseCode AS WarehouseCode,b.ReturnCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,b.ReturnCode,b.ReturnDetailID,a.InvCode) AS Sequence,
  1144. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,b.ReturnDetailID,Enable AS UpdateTodoQuantity
  1145. ,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,
  1146. 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
  1147. INTO #TempERP
  1148. FROM ICSWareHouseLotInfoLog a
  1149. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1150. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1151. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1152. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1153. INNER JOIN ICSReturn b ON a.TransCode=b.ReturnCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1154. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1155. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1156. GROUP BY a.ToWarehouseCode,b.ReturnCode,a.MUSER,a.InvCode,b.ReturnDetailID,Enable
  1157. ,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, ''),
  1158. 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, '')
  1159. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ReturnCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1160. SELECT Costre,Sequence,InvCode,Quantity,Amount,ReturnDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1161. DROP TABLE #TempERP";
  1162. sql = string.Format(sql, Identification,BusinessCode);
  1163. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1164. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1165. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ReturnDocURL, Inputstr);
  1166. Result result = new Result();
  1167. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1168. if (result.Success)
  1169. {
  1170. try
  1171. {
  1172. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1173. foreach (var item in res)
  1174. {
  1175. JObject jo = (JObject)item;
  1176. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1177. foreach (var detail in resdetail)
  1178. {
  1179. JObject det = (JObject)detail;
  1180. 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()
  1181. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1182. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1183. det["DetailID"].ToString(), jo["OtherInCode"].ToString(), det["Sequence"].ToString(),"", cmd,language, BusinessCode);
  1184. }
  1185. }
  1186. }
  1187. catch (Exception ex)
  1188. {
  1189. log.Debug(ex.ToString());
  1190. log.Debug(resultStr);
  1191. }
  1192. }
  1193. else
  1194. {
  1195. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1196. }
  1197. #endregion
  1198. }
  1199. catch (Exception)
  1200. {
  1201. throw;
  1202. }
  1203. }
  1204. #endregion
  1205. #endregion
  1206. }
  1207. }