爱思开
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.

1156 lines
66 KiB

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