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

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