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

990 lines
54 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
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 ICSDisassemblyDoc SET DABDOCQuantity=Quantity
  614. WHERE DABDOCCode+Sequence+WorkPoint IN(SELECT DISTINCT d.TransCode+d.TransSequence+d.WorkPoint
  615. FROM ICSWareHouseLotInfoLog a
  616. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  617. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  618. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  619. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')
  620. UPDATE ICSWareHouseLotInfo SET Quantity=Quantity-LockQuantity,LockQuantity=0
  621. WHERE LotNo+WorkPoint IN(SELECT DISTINCT d.LotNo+d.WorkPoint
  622. FROM ICSWareHouseLotInfoLog a
  623. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  624. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  625. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  626. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')";
  627. sql = string.Format(sql, Identification);
  628. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  629. {
  630. throw new Exception(language.GetNameByCode("WMSAPIInfo158"));//"拆卸单套件更新失败!");
  631. }
  632. }
  633. catch (Exception)
  634. {
  635. throw;
  636. }
  637. }
  638. /// <summary>
  639. /// 拆卸单接口
  640. /// </summary>
  641. /// <param name="TransType"></param>
  642. /// <param name="Identification"></param>
  643. /// <param name="cmd"></param>
  644. public static void DisassemblyDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  645. {
  646. try
  647. {
  648. #region ERP开立状态单据审核
  649. string sql = @"IF EXISTS(SELECT b.ID FROM ICSDisassemblyDoc b
  650. WHERE b.DABDOCCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  651. AND b.Quantity!=b.DABDOCQuantity)
  652. BEGIN
  653. RAISERROR('" + language.GetNameByCode("WMSAPIInfo102") + @"',16,1);
  654. RETURN
  655. END
  656. SELECT b.DABDOCID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  657. FROM ICSWareHouseLotInfoLog a
  658. INNER JOIN ICSDisassemblyDoc b ON a.TransCode=b.DABDOCCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  659. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  660. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  661. WHERE a.Identification='{0}' AND ERPUpload='0'
  662. GROUP BY b.DABDOCID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  663. sql = string.Format(sql, Identification);
  664. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  665. string Inputstr = JsonConvert.SerializeObject(dt);
  666. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DisassemblyDocURL, Inputstr);
  667. Result result = new Result();
  668. result = JsonConvert.DeserializeObject<Result>(resultStr);
  669. if (result.Success)
  670. {
  671. try
  672. {
  673. foreach (DataRow dr in dt.Rows)
  674. {
  675. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  676. }
  677. }
  678. catch (Exception ex)
  679. {
  680. log.Debug(ex.ToString());
  681. log.Debug(resultStr);
  682. }
  683. }
  684. else
  685. {
  686. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  687. }
  688. #endregion
  689. }
  690. catch (Exception)
  691. {
  692. throw;
  693. }
  694. }
  695. #endregion
  696. #region 借用
  697. /// <summary>
  698. /// 借用
  699. /// </summary>
  700. /// <param name="TransCode"></param>
  701. /// <param name="TransSequence"></param>
  702. /// <param name="Quantity"></param>
  703. /// <param name="WorkPoint"></param>
  704. /// <param name="cmd"></param>
  705. public static void BrrowDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  706. {
  707. try
  708. {
  709. string sql = @"DECLARE @Status VARCHAR(10)
  710. SELECT @Status=a.Status FROM ICSBrrow a
  711. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  712. IF (@Status IS NULL)
  713. BEGIN
  714. RAISERROR('" + language.GetNameByCode("WMSAPIInfo159") + @"',16,1);
  715. RETURN
  716. END
  717. ELSE IF (@Status!='2')
  718. BEGIN
  719. RAISERROR('" + language.GetNameByCode("WMSAPIInfo160") + @"',16,1);
  720. RETURN
  721. END
  722. UPDATE a SET BrrowQuantity=ISNULL(BrrowQuantity,0)+'{2}'
  723. FROM ICSBrrow a
  724. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  725. IF EXISTS(SELECT a.ID FROM ICSBrrow a
  726. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.BrrowQuantity)
  727. BEGIN
  728. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  729. RETURN
  730. END";
  731. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  732. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  733. {
  734. throw new Exception(language.GetNameByCode("WMSAPIInfo161"));//"借用单更新失败!");
  735. }
  736. }
  737. catch (Exception)
  738. {
  739. throw;
  740. }
  741. }
  742. /// <summary>
  743. /// 借用接口
  744. /// </summary>
  745. /// <param name="TransType"></param>
  746. /// <param name="Identification"></param>
  747. /// <param name="cmd"></param>
  748. public static void BrrowDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  749. {
  750. try
  751. {
  752. #region ERP
  753. 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,
  754. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,b.BrrowDetailID,Enable AS UpdateTodoQuantity
  755. ,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,
  756. 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
  757. INTO #TempERP
  758. FROM ICSWareHouseLotInfoLog a
  759. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  760. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  761. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  762. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  763. INNER JOIN ICSBrrow b ON a.TransCode=b.BrrowCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  764. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  765. WHERE a.Identification='{0}' AND ERPUpload='0'
  766. GROUP BY a.FromWarehouseCode,b.BrrowCode,a.MUSER,a.InvCode,b.BrrowDetailID,Enable
  767. ,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, ''),
  768. 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, '')
  769. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,BrrowCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  770. 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
  771. DROP TABLE #TempERP";
  772. sql = string.Format(sql, Identification);
  773. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  774. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  775. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.BrrowDocURL, Inputstr);
  776. Result result = new Result();
  777. result = JsonConvert.DeserializeObject<Result>(resultStr);
  778. if (result.Success)
  779. {
  780. try
  781. {
  782. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  783. foreach (var item in res)
  784. {
  785. JObject jo = (JObject)item;
  786. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  787. foreach (var detail in resdetail)
  788. {
  789. JObject det = (JObject)detail;
  790. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  791. det["DetailID"].ToString(), jo["OtherOutCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  792. }
  793. }
  794. }
  795. catch (Exception ex)
  796. {
  797. log.Debug(ex.ToString());
  798. log.Debug(resultStr);
  799. }
  800. }
  801. else
  802. {
  803. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  804. }
  805. #endregion
  806. }
  807. catch (Exception)
  808. {
  809. throw;
  810. }
  811. }
  812. #endregion
  813. #region 归还
  814. /// <summary>
  815. /// 归还
  816. /// </summary>
  817. /// <param name="TransCode"></param>
  818. /// <param name="TransSequence"></param>
  819. /// <param name="Quantity"></param>
  820. /// <param name="WorkPoint"></param>
  821. /// <param name="cmd"></param>
  822. public static void ReturnDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  823. {
  824. try
  825. {
  826. string sql = @"DECLARE @Status VARCHAR(10)
  827. SELECT @Status=c.Status FROM ICSInventoryLot a
  828. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  829. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  830. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  831. IF (@Status IS NULL)
  832. BEGIN
  833. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  834. RETURN
  835. END
  836. ELSE IF (@Status!='2')
  837. BEGIN
  838. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  839. RETURN
  840. END
  841. UPDATE c SET ReturnQuantity=ISNULL(ReturnQuantity,0)+'{2}'
  842. FROM ICSInventoryLot a
  843. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  844. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  845. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  846. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  847. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  848. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  849. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.ReturnQuantity)
  850. BEGIN
  851. RAISERROR('" + language.GetNameByCode("WMSAPIInfo162") + @"',16,1);
  852. END";
  853. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  854. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  855. {
  856. throw new Exception(language.GetNameByCode("WMSAPIInfo163"));//"归还单更新失败!");
  857. }
  858. }
  859. catch (Exception)
  860. {
  861. throw;
  862. }
  863. }
  864. /// <summary>
  865. /// 归还接口
  866. /// </summary>
  867. /// <param name="TransType"></param>
  868. /// <param name="Identification"></param>
  869. /// <param name="cmd"></param>
  870. public static void ReturnDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  871. {
  872. try
  873. {
  874. #region ERP
  875. 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,
  876. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,b.ReturnDetailID,Enable AS UpdateTodoQuantity
  877. ,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,
  878. 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
  879. INTO #TempERP
  880. FROM ICSWareHouseLotInfoLog a
  881. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  882. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  883. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  884. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  885. INNER JOIN ICSReturn b ON a.TransCode=b.ReturnCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  886. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  887. WHERE a.Identification='{0}' AND ERPUpload='0'
  888. GROUP BY a.ToWarehouseCode,b.ReturnCode,a.MUSER,a.InvCode,b.ReturnDetailID,Enable
  889. ,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, ''),
  890. 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, '')
  891. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ReturnCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  892. 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
  893. DROP TABLE #TempERP";
  894. sql = string.Format(sql, Identification);
  895. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  896. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  897. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ReturnDocURL, Inputstr);
  898. Result result = new Result();
  899. result = JsonConvert.DeserializeObject<Result>(resultStr);
  900. if (result.Success)
  901. {
  902. try
  903. {
  904. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  905. foreach (var item in res)
  906. {
  907. JObject jo = (JObject)item;
  908. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  909. foreach (var detail in resdetail)
  910. {
  911. JObject det = (JObject)detail;
  912. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  913. det["DetailID"].ToString(), jo["OtherInCode"].ToString(), det["Sequence"].ToString(), cmd,language);
  914. }
  915. }
  916. }
  917. catch (Exception ex)
  918. {
  919. log.Debug(ex.ToString());
  920. log.Debug(resultStr);
  921. }
  922. }
  923. else
  924. {
  925. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  926. }
  927. #endregion
  928. }
  929. catch (Exception)
  930. {
  931. throw;
  932. }
  933. }
  934. #endregion
  935. }
  936. }