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

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