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

982 lines
53 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 库内作业模块
  18. /// </summary>
  19. public class 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' AND a.TransferQuantity<a.TransferQuantity)
  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. /// <summary>
  115. /// 两步调出
  116. /// </summary>
  117. /// <param name="TransCode"></param>
  118. /// <param name="TransSequence"></param>
  119. /// <param name="Quantity"></param>
  120. /// <param name="WorkPoint"></param>
  121. /// <param name="cmd"></param>
  122. public static void TwoStepTransferDocOut(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  123. {
  124. try
  125. {
  126. string sql = @"DECLARE @Status VARCHAR(10)
  127. SELECT @Status=a.Status FROM ICSOtherOut a
  128. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  129. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  130. IF (@Status IS NULL)
  131. BEGIN
  132. RAISERROR('" + language.GetNameByCode("WMSAPIInfo146") + @"',16,1);
  133. RETURN
  134. END
  135. ELSE IF (@Status!='1')
  136. BEGIN
  137. RAISERROR('" + language.GetNameByCode("WMSAPIInfo147") + @"',16,1);
  138. RETURN
  139. END
  140. UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
  141. FROM ICSOtherOut a
  142. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  143. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  144. IF EXISTS(SELECT a.ID FROM ICSOtherOut a
  145. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  146. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.OutQuantity)
  147. BEGIN
  148. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  149. RETURN
  150. END";
  151. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  152. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  153. {
  154. throw new Exception(language.GetNameByCode("WMSAPIInfo148"));//"两步调出单更新失败!");
  155. }
  156. }
  157. catch (Exception)
  158. {
  159. throw;
  160. }
  161. }
  162. /// <summary>
  163. /// 两步调出接口
  164. /// </summary>
  165. /// <param name="TransType"></param>
  166. /// <param name="Identification"></param>
  167. /// <param name="cmd"></param>
  168. public static void TwoStepTransferDocOutERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  169. {
  170. try
  171. {
  172. #region ERP开立状态单据审核
  173. string sql = @"IF EXISTS(SELECT b.ID FROM ICSOtherOut b
  174. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  175. WHERE b.OutCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  176. AND b.Quantity!=b.OutQuantity)
  177. BEGIN
  178. RAISERROR('" + language.GetNameByCode("WMSAPIInfo098") + @"',16,1);
  179. RETURN
  180. END
  181. SELECT b.OutID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  182. FROM ICSWareHouseLotInfoLog a
  183. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  184. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  185. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  186. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  187. WHERE a.Identification='{0}' AND ERPUpload='0'
  188. GROUP BY b.OutID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  189. sql = string.Format(sql, Identification);
  190. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  191. string Inputstr = JsonConvert.SerializeObject(dt);
  192. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocOutURL, Inputstr);
  193. Result result = new Result();
  194. result = JsonConvert.DeserializeObject<Result>(resultStr);
  195. if (result.Success)
  196. {
  197. try
  198. {
  199. foreach (DataRow dr in dt.Rows)
  200. {
  201. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  202. }
  203. }
  204. catch (Exception ex)
  205. {
  206. log.Debug(ex.ToString());
  207. log.Debug(resultStr);
  208. }
  209. }
  210. else
  211. {
  212. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  213. }
  214. #endregion
  215. }
  216. catch (Exception)
  217. {
  218. throw;
  219. }
  220. }
  221. #endregion
  222. #region 两步调入
  223. /// <summary>
  224. /// 两步调入
  225. /// </summary>
  226. /// <param name="TransCode"></param>
  227. /// <param name="TransSequence"></param>
  228. /// <param name="Quantity"></param>
  229. /// <param name="WorkPoint"></param>
  230. /// <param name="cmd"></param>
  231. public static void TwoStepTransferDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  232. {
  233. //需要关联其他入库单
  234. try
  235. {
  236. string sql = @"DECLARE @Status VARCHAR(10)
  237. SELECT @Status=Otin.Status FROM ICSOtherIn Otin
  238. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  239. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  240. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  241. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  242. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}'
  243. IF (@Status IS NULL)
  244. BEGIN
  245. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  246. RETURN
  247. END
  248. ELSE IF (@Status!='1')
  249. BEGIN
  250. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  251. RETURN
  252. END
  253. UPDATE Otin SET InQuantity=ISNULL(InQuantity,0)+'{4}'
  254. FROM ICSOtherIn Otin
  255. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  256. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  257. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  258. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  259. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}'
  260. IF EXISTS(SELECT a.LotNo FROM ICSOtherIn Otin
  261. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  262. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  263. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  264. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  265. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}' AND Otin.Quantity<Otin.InQuantity)
  266. BEGIN
  267. RAISERROR('" + language.GetNameByCode("WMSAPIInfo149") + @"',16,1);
  268. END";
  269. sql = string.Format(sql, LotNo, WorkPoint,TransCode,TransSequence, Quantity);
  270. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  271. {
  272. throw new Exception(language.GetNameByCode("WMSAPIInfo150"));//"两步调入单更新失败!");
  273. }
  274. }
  275. catch (Exception)
  276. {
  277. throw;
  278. }
  279. }
  280. /// <summary>
  281. /// 两步调入接口
  282. /// </summary>
  283. /// <param name="TransType"></param>
  284. /// <param name="Identification"></param>
  285. /// <param name="cmd"></param>
  286. public static void TwoStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  287. {
  288. try
  289. {
  290. #region ERP开立状态单据审核
  291. string sql = @"IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  292. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  293. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  294. AND b.Quantity!=b.InQuantity)
  295. BEGIN
  296. RAISERROR('" + language.GetNameByCode("WMSAPIInfo099") + @"',16,1);
  297. RETURN
  298. END
  299. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  300. FROM ICSWareHouseLotInfoLog a
  301. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  302. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  303. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  304. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  305. WHERE a.Identification='{0}' AND ERPUpload='0'
  306. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  307. sql = string.Format(sql, Identification);
  308. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  309. string Inputstr = JsonConvert.SerializeObject(dt);
  310. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocInURL, Inputstr);
  311. Result result = new Result();
  312. result = JsonConvert.DeserializeObject<Result>(resultStr);
  313. if (result.Success)
  314. {
  315. try
  316. {
  317. foreach (DataRow dr in dt.Rows)
  318. {
  319. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  320. }
  321. }
  322. catch (Exception ex)
  323. {
  324. log.Debug(ex.ToString());
  325. log.Debug(resultStr);
  326. }
  327. }
  328. else
  329. {
  330. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  331. }
  332. #endregion
  333. }
  334. catch (Exception)
  335. {
  336. throw;
  337. }
  338. }
  339. #endregion
  340. #region 其他出库
  341. /// <summary>
  342. /// 其他出库
  343. /// </summary>
  344. /// <param name="TransCode"></param>
  345. /// <param name="TransSequence"></param>
  346. /// <param name="Quantity"></param>
  347. /// <param name="WorkPoint"></param>
  348. /// <param name="cmd"></param>
  349. public static void OtherOutDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  350. {
  351. try
  352. {
  353. string sql = @"DECLARE @Status VARCHAR(10)
  354. SELECT @Status=a.Status FROM ICSOtherOut a
  355. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  356. IF (@Status IS NULL)
  357. BEGIN
  358. RAISERROR('" + language.GetNameByCode("WMSAPIInfo151") + @"',16,1);
  359. RETURN
  360. END
  361. ELSE IF (@Status!='1')
  362. BEGIN
  363. RAISERROR('" + language.GetNameByCode("WMSAPIInfo152") + @"',16,1);
  364. RETURN
  365. END
  366. UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
  367. FROM ICSOtherOut a
  368. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  369. IF EXISTS(SELECT a.ID FROM ICSOtherOut a
  370. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.OutQuantity)
  371. BEGIN
  372. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  373. RETURN
  374. END";
  375. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  376. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  377. {
  378. throw new Exception(language.GetNameByCode("WMSAPIInfo153"));//"其他出库单更新失败!");
  379. }
  380. }
  381. catch (Exception)
  382. {
  383. throw;
  384. }
  385. }
  386. /// <summary>
  387. /// 其他出库接口
  388. /// </summary>
  389. /// <param name="TransType"></param>
  390. /// <param name="Identification"></param>
  391. /// <param name="cmd"></param>
  392. public static void OtherOutDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  393. {
  394. try
  395. {
  396. #region ERP开立状态单据审核
  397. string sql = @"IF EXISTS(SELECT b.ID FROM ICSOtherOut b
  398. WHERE b.OutCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  399. AND b.Quantity!=b.OutQuantity)
  400. BEGIN
  401. RAISERROR('" + language.GetNameByCode("WMSAPIInfo100") + @"',16,1);
  402. RETURN
  403. END
  404. SELECT b.OutID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  405. FROM ICSWareHouseLotInfoLog a
  406. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  407. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  408. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  409. WHERE a.Identification='{0}' AND ERPUpload='0'
  410. GROUP BY b.OutID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  411. sql = string.Format(sql, Identification);
  412. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  413. string Inputstr = JsonConvert.SerializeObject(dt);
  414. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OtherOutDocURL, Inputstr);
  415. Result result = new Result();
  416. result = JsonConvert.DeserializeObject<Result>(resultStr);
  417. if (result.Success)
  418. {
  419. try
  420. {
  421. foreach (DataRow dr in dt.Rows)
  422. {
  423. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  424. }
  425. }
  426. catch (Exception ex)
  427. {
  428. log.Debug(ex.ToString());
  429. log.Debug(resultStr);
  430. }
  431. }
  432. else
  433. {
  434. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  435. }
  436. #endregion
  437. }
  438. catch (Exception)
  439. {
  440. throw;
  441. }
  442. }
  443. #endregion
  444. #region 其他入库
  445. /// <summary>
  446. /// 其他入库
  447. /// </summary>
  448. /// <param name="TransCode"></param>
  449. /// <param name="TransSequence"></param>
  450. /// <param name="Quantity"></param>
  451. /// <param name="WorkPoint"></param>
  452. /// <param name="cmd"></param>
  453. public static void OtherInDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  454. {
  455. try
  456. {
  457. string sql = @"DECLARE @Status VARCHAR(10)
  458. SELECT @Status=c.Status FROM ICSInventoryLot a
  459. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  460. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  461. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  462. IF (@Status IS NULL)
  463. BEGIN
  464. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  465. RETURN
  466. END
  467. ELSE IF (@Status!='1')
  468. BEGIN
  469. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  470. RETURN
  471. END
  472. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  473. FROM ICSInventoryLot a
  474. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  475. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  476. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  477. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  478. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  479. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  480. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  481. BEGIN
  482. RAISERROR('" + language.GetNameByCode("WMSAPIInfo154") + @"',16,1);
  483. END";
  484. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  485. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  486. {
  487. throw new Exception(language.GetNameByCode("WMSAPIInfo155"));//"其他入库单更新失败!");
  488. }
  489. }
  490. catch (Exception)
  491. {
  492. throw;
  493. }
  494. }
  495. /// <summary>
  496. /// 其他入库接口
  497. /// </summary>
  498. /// <param name="TransType"></param>
  499. /// <param name="Identification"></param>
  500. /// <param name="cmd"></param>
  501. public static void OtherInDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  502. {
  503. try
  504. {
  505. #region ERP开立状态单据审核
  506. string sql = @"IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  507. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  508. AND b.Quantity!=b.InQuantity)
  509. BEGIN
  510. RAISERROR('" + language.GetNameByCode("WMSAPIInfo101") + @"',16,1);
  511. RETURN
  512. END
  513. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  514. FROM ICSWareHouseLotInfoLog a
  515. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  516. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  517. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  518. WHERE a.Identification='{0}' AND ERPUpload='0'
  519. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  520. sql = string.Format(sql, Identification);
  521. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  522. string Inputstr = JsonConvert.SerializeObject(dt);
  523. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OtherInDocURL, Inputstr);
  524. Result result = new Result();
  525. result = JsonConvert.DeserializeObject<Result>(resultStr);
  526. if (result.Success)
  527. {
  528. try
  529. {
  530. foreach (DataRow dr in dt.Rows)
  531. {
  532. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  533. }
  534. }
  535. catch (Exception ex)
  536. {
  537. log.Debug(ex.ToString());
  538. log.Debug(resultStr);
  539. }
  540. }
  541. else
  542. {
  543. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  544. }
  545. #endregion
  546. }
  547. catch (Exception)
  548. {
  549. throw;
  550. }
  551. }
  552. #endregion
  553. #region 拆卸单
  554. /// <summary>
  555. /// 拆卸单
  556. /// </summary>
  557. /// <param name="TransCode"></param>
  558. /// <param name="TransSequence"></param>
  559. /// <param name="Quantity"></param>
  560. /// <param name="WorkPoint"></param>
  561. /// <param name="cmd"></param>
  562. public static void DisassemblyDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  563. {
  564. try
  565. {
  566. string sql = @"DECLARE @Status VARCHAR(10)
  567. SELECT @Status=c.Status FROM ICSInventoryLot a
  568. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  569. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  570. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DABDOCType='2'
  571. IF (@Status IS NULL)
  572. BEGIN
  573. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  574. RETURN
  575. END
  576. ELSE IF (@Status!='1')
  577. BEGIN
  578. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  579. RETURN
  580. END
  581. UPDATE c SET DABDOCQuantity=ISNULL(DABDOCQuantity,0)+'{2}'
  582. FROM ICSInventoryLot a
  583. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  584. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  585. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  586. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  587. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  588. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  589. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.DABDOCQuantity)
  590. BEGIN
  591. RAISERROR('" + language.GetNameByCode("WMSAPIInfo156") + @"',16,1);
  592. END";
  593. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  594. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  595. {
  596. throw new Exception(language.GetNameByCode("WMSAPIInfo157"));//"拆卸单更新失败!");
  597. }
  598. }
  599. catch (Exception)
  600. {
  601. throw;
  602. }
  603. }
  604. /// <summary>
  605. /// 拆卸单更新套件锁定数量
  606. /// </summary>
  607. /// <param name="Identification"></param>
  608. /// <param name="cmd"></param>
  609. public static void DisassemblyDoc(string Identification, SqlCommand cmd, Dictionary<string, string> language)
  610. {
  611. try
  612. {
  613. string sql = @"UPDATE e SET e.Quantity=e.Quantity-e.LockQuantity,e.LockQuantity=0
  614. FROM ICSWareHouseLotInfoLog a
  615. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  616. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  617. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  618. INNER JOIN ICSWareHouseLotInfo e ON d.LotNo=e.LotNo AND d.WorkPoint=e.WorkPoint
  619. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1'";
  620. sql = string.Format(sql, Identification);
  621. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  622. {
  623. throw new Exception(language.GetNameByCode("WMSAPIInfo158"));//"拆卸单套件更新失败!");
  624. }
  625. }
  626. catch (Exception)
  627. {
  628. throw;
  629. }
  630. }
  631. /// <summary>
  632. /// 拆卸单接口
  633. /// </summary>
  634. /// <param name="TransType"></param>
  635. /// <param name="Identification"></param>
  636. /// <param name="cmd"></param>
  637. public static void DisassemblyDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  638. {
  639. try
  640. {
  641. #region ERP开立状态单据审核
  642. string sql = @"IF EXISTS(SELECT b.ID FROM ICSDisassemblyDoc b
  643. WHERE b.DABDOCCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  644. AND b.Quantity!=b.DABDOCQuantity)
  645. BEGIN
  646. RAISERROR('" + language.GetNameByCode("WMSAPIInfo102") + @"',16,1);
  647. RETURN
  648. END
  649. SELECT b.DABDOCID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  650. FROM ICSWareHouseLotInfoLog a
  651. INNER JOIN ICSDisassemblyDoc b ON a.TransCode=b.DABDOCCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  652. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  653. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  654. WHERE a.Identification='{0}' AND ERPUpload='0'
  655. GROUP BY b.DABDOCID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  656. sql = string.Format(sql, Identification);
  657. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  658. string Inputstr = JsonConvert.SerializeObject(dt);
  659. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DisassemblyDocURL, Inputstr);
  660. Result result = new Result();
  661. result = JsonConvert.DeserializeObject<Result>(resultStr);
  662. if (result.Success)
  663. {
  664. try
  665. {
  666. foreach (DataRow dr in dt.Rows)
  667. {
  668. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  669. }
  670. }
  671. catch (Exception ex)
  672. {
  673. log.Debug(ex.ToString());
  674. log.Debug(resultStr);
  675. }
  676. }
  677. else
  678. {
  679. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  680. }
  681. #endregion
  682. }
  683. catch (Exception)
  684. {
  685. throw;
  686. }
  687. }
  688. #endregion
  689. #region 借用
  690. /// <summary>
  691. /// 借用
  692. /// </summary>
  693. /// <param name="TransCode"></param>
  694. /// <param name="TransSequence"></param>
  695. /// <param name="Quantity"></param>
  696. /// <param name="WorkPoint"></param>
  697. /// <param name="cmd"></param>
  698. public static void BrrowDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  699. {
  700. try
  701. {
  702. string sql = @"DECLARE @Status VARCHAR(10)
  703. SELECT @Status=a.Status FROM ICSBrrow a
  704. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  705. IF (@Status IS NULL)
  706. BEGIN
  707. RAISERROR('" + language.GetNameByCode("WMSAPIInfo159") + @"',16,1);
  708. RETURN
  709. END
  710. ELSE IF (@Status!='2')
  711. BEGIN
  712. RAISERROR('" + language.GetNameByCode("WMSAPIInfo160") + @"',16,1);
  713. RETURN
  714. END
  715. UPDATE a SET BrrowQuantity=ISNULL(BrrowQuantity,0)+'{2}'
  716. FROM ICSBrrow a
  717. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  718. IF EXISTS(SELECT a.ID FROM ICSBrrow a
  719. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.BrrowQuantity)
  720. BEGIN
  721. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  722. RETURN
  723. END";
  724. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  725. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  726. {
  727. throw new Exception(language.GetNameByCode("WMSAPIInfo161"));//"借用单更新失败!");
  728. }
  729. }
  730. catch (Exception)
  731. {
  732. throw;
  733. }
  734. }
  735. /// <summary>
  736. /// 借用接口
  737. /// </summary>
  738. /// <param name="TransType"></param>
  739. /// <param name="Identification"></param>
  740. /// <param name="cmd"></param>
  741. public static void BrrowDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  742. {
  743. try
  744. {
  745. #region ERP
  746. 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,
  747. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,b.BrrowDetailID,Enable AS UpdateTodoQuantity
  748. ,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,
  749. 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
  750. INTO #TempERP
  751. FROM ICSWareHouseLotInfoLog a
  752. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  753. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  754. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  755. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  756. INNER JOIN ICSBrrow b ON a.TransCode=b.BrrowCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  757. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  758. WHERE a.Identification='{0}' AND ERPUpload='0'
  759. GROUP BY a.FromWarehouseCode,b.BrrowCode,a.MUSER,a.InvCode,b.BrrowDetailID,Enable
  760. ,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, ''),
  761. 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, '')
  762. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,BrrowCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  763. 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
  764. DROP TABLE #TempERP";
  765. sql = string.Format(sql, Identification);
  766. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  767. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  768. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.BrrowDocURL, Inputstr);
  769. Result result = new Result();
  770. result = JsonConvert.DeserializeObject<Result>(resultStr);
  771. if (result.Success)
  772. {
  773. try
  774. {
  775. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  776. foreach (var item in res)
  777. {
  778. JObject jo = (JObject)item;
  779. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  780. foreach (var detail in resdetail)
  781. {
  782. JObject det = (JObject)detail;
  783. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  784. det["DetailID"].ToString(), jo["OtherOutCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  785. }
  786. }
  787. }
  788. catch (Exception ex)
  789. {
  790. log.Debug(ex.ToString());
  791. log.Debug(resultStr);
  792. }
  793. }
  794. else
  795. {
  796. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  797. }
  798. #endregion
  799. }
  800. catch (Exception)
  801. {
  802. throw;
  803. }
  804. }
  805. #endregion
  806. #region 归还
  807. /// <summary>
  808. /// 归还
  809. /// </summary>
  810. /// <param name="TransCode"></param>
  811. /// <param name="TransSequence"></param>
  812. /// <param name="Quantity"></param>
  813. /// <param name="WorkPoint"></param>
  814. /// <param name="cmd"></param>
  815. public static void ReturnDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  816. {
  817. try
  818. {
  819. string sql = @"DECLARE @Status VARCHAR(10)
  820. SELECT @Status=c.Status FROM ICSInventoryLot a
  821. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  822. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  823. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  824. IF (@Status IS NULL)
  825. BEGIN
  826. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  827. RETURN
  828. END
  829. ELSE IF (@Status!='2')
  830. BEGIN
  831. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  832. RETURN
  833. END
  834. UPDATE c SET ReturnQuantity=ISNULL(ReturnQuantity,0)+'{2}'
  835. FROM ICSInventoryLot a
  836. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  837. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  838. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  839. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  840. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  841. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  842. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.ReturnQuantity)
  843. BEGIN
  844. RAISERROR('" + language.GetNameByCode("WMSAPIInfo162") + @"',16,1);
  845. END";
  846. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  847. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  848. {
  849. throw new Exception(language.GetNameByCode("WMSAPIInfo163"));//"归还单更新失败!");
  850. }
  851. }
  852. catch (Exception)
  853. {
  854. throw;
  855. }
  856. }
  857. /// <summary>
  858. /// 归还接口
  859. /// </summary>
  860. /// <param name="TransType"></param>
  861. /// <param name="Identification"></param>
  862. /// <param name="cmd"></param>
  863. public static void ReturnDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  864. {
  865. try
  866. {
  867. #region ERP
  868. 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,
  869. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,b.ReturnDetailID,Enable AS UpdateTodoQuantity
  870. ,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,
  871. 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
  872. INTO #TempERP
  873. FROM ICSWareHouseLotInfoLog a
  874. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  875. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  876. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  877. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  878. INNER JOIN ICSReturn b ON a.TransCode=b.ReturnCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  879. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  880. WHERE a.Identification='{0}' AND ERPUpload='0'
  881. GROUP BY a.ToWarehouseCode,b.ReturnCode,a.MUSER,a.InvCode,b.ReturnDetailID,Enable
  882. ,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, ''),
  883. 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, '')
  884. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ReturnCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  885. 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
  886. DROP TABLE #TempERP";
  887. sql = string.Format(sql, Identification);
  888. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  889. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  890. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ReturnDocURL, Inputstr);
  891. Result result = new Result();
  892. result = JsonConvert.DeserializeObject<Result>(resultStr);
  893. if (result.Success)
  894. {
  895. try
  896. {
  897. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  898. foreach (var item in res)
  899. {
  900. JObject jo = (JObject)item;
  901. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  902. foreach (var detail in resdetail)
  903. {
  904. JObject det = (JObject)detail;
  905. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  906. det["DetailID"].ToString(), jo["OtherInCode"].ToString(), det["Sequence"].ToString(), cmd,language);
  907. }
  908. }
  909. }
  910. catch (Exception ex)
  911. {
  912. log.Debug(ex.ToString());
  913. log.Debug(resultStr);
  914. }
  915. }
  916. else
  917. {
  918. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  919. }
  920. #endregion
  921. }
  922. catch (Exception)
  923. {
  924. throw;
  925. }
  926. }
  927. #endregion
  928. }
  929. }