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

1350 lines
79 KiB

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