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

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