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.

3305 lines
198 KiB

  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,string IsPN, SqlCommand cmd, Dictionary<string, string> language)
  32. {
  33. try
  34. {
  35. string sql = string.Empty;
  36. if (IsPN=="1")
  37. {
  38. sql = @"UPDATE ICSTransfer SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
  39. WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='3'
  40. IF EXISTS(SELECT a.ID FROM ICSTransfer a
  41. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='3' AND a.TransferQuantity<a.TransferQuantity)
  42. BEGIN
  43. RAISERROR('" + language.GetNameByCode("WMSAPIInfo144") + @"',16,1);
  44. RETURN
  45. END";
  46. }
  47. else
  48. {
  49. sql = @"UPDATE ICSTransfer SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
  50. WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'
  51. IF EXISTS(SELECT a.ID FROM ICSTransfer a
  52. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.TransferQuantity<a.TransferQuantity)
  53. BEGIN
  54. RAISERROR('" + language.GetNameByCode("WMSAPIInfo144") + @"',16,1);
  55. RETURN
  56. END";
  57. }
  58. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  59. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  60. {
  61. throw new Exception(language.GetNameByCode("WMSAPIInfo145"));//"调拨单信息更新失败!");
  62. }
  63. }
  64. catch (Exception)
  65. {
  66. throw;
  67. }
  68. }
  69. /// <summary>
  70. /// 无源头调拨接口
  71. /// </summary>
  72. /// <param name="TransType"></param>
  73. /// <param name="Identification"></param>
  74. /// <param name="cmd"></param>
  75. public static void OneStepNoTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  76. {
  77. try
  78. {
  79. #region 生成调拨单
  80. string sql = @"SELECT a.FromWarehouseCode+a.ToWarehouseCode+a.MUSER AS Costre,'' AS FromDepCode,'' AS ToDepCode,a.FromWarehouseCode AS FromWHCode,a.ToWarehouseCode AS ToWHCode,'' AS TACode,CASE WHEN a.MUSER='2301' or a.MUSER='2305' THEN '039' ELSE a.MUSER END AS MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,a.ToWarehouseCode,a.InvCode) AS Sequence,
  81. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(lot.Amount) ELSE '0' END AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,'' AS TAetailID
  82. ,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,
  83. 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
  84. INTO #TempERP
  85. FROM ICSWareHouseLotInfoLog a
  86. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  87. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  88. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  89. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  90. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  91. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  92. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  93. WHERE a.Identification='{0}' AND ERPUpload='0' and a.BusinessCode='70'
  94. GROUP BY lot.Amount,inv.AmountEnable,a.FromWarehouseCode,a.ToWarehouseCode,a.MUSER,a.InvCode,con.Enable,conStock.Enable
  95. ,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, ''),
  96. 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, '')
  97. SELECT DISTINCT Costre,WorkPoint,FromDepCode,ToDepCode,FromWHCode,ToWHCode,TACode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,'TransIn002'as DocType,SYSDATETIME() as DocDate FROM #TempERP
  98. SELECT Costre,Sequence,InvCode,Quantity,Amount,TAetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,FromWHCode as OutWhCode,ToWHCode as INWhCode
  99. FROM #TempERP
  100. DROP TABLE #TempERP";
  101. sql = string.Format(sql, Identification);
  102. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  103. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  104. string resultStr = "";
  105. if (DBHelper.IsU9())
  106. {
  107. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OneStepNoTransferDocInURL, Inputstr);
  108. }
  109. else
  110. {
  111. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepNoTransferDocInURL, Inputstr);
  112. }
  113. Result result = new Result();
  114. result = JsonConvert.DeserializeObject<Result>(resultStr);
  115. if (result.Success)
  116. {
  117. try
  118. {
  119. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  120. foreach (var item in res)
  121. {
  122. JObject jo = (JObject)item;
  123. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  124. foreach (var detail in resdetail)
  125. {
  126. JObject det = (JObject)detail;
  127. string allcol = jo["FromWHCode"].ToString() + det["ProjectCode"].ToString() + det["BatchCode"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  128. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  129. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, "", Identification, jo["ID"].ToString(),
  130. det["DetailID"].ToString(), jo["TransCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  131. }
  132. }
  133. //foreach (DataRow dr in ds.Tables)
  134. //{
  135. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, "", Identification, "", "", "", "", "", cmd, language);
  136. //}
  137. }
  138. catch (Exception ex)
  139. {
  140. log.Debug(sql);
  141. log.Debug(ex.ToString());
  142. log.Debug(resultStr);
  143. }
  144. }
  145. else
  146. {
  147. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  148. }
  149. #endregion
  150. }
  151. catch (Exception)
  152. {
  153. throw;
  154. }
  155. }
  156. #region 一步调拨(调拨申请单)
  157. /// <summary>
  158. /// 一步调拨(调拨申请单)
  159. /// </summary>
  160. /// <param name="TransCode"></param>
  161. /// <param name="TransSequence"></param>
  162. /// <param name="Quantity"></param>
  163. /// <param name="WorkPoint"></param>
  164. /// <param name="cmd"></param>
  165. public static void OneStepTransferApplicationIn(string TransCode, string TransSequence, string WorkPoint, string Quantity, SqlCommand cmd, Dictionary<string, string> language)
  166. {
  167. try
  168. {
  169. string sql = "";
  170. if (DBHelper.IsPNU9())
  171. {
  172. sql = @"UPDATE ICSTransferApplication SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
  173. WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'";
  174. }
  175. else
  176. {
  177. sql = @"UPDATE ICSTransferApplication SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
  178. WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'
  179. IF EXISTS(SELECT a.ID FROM ICSTransferApplication a
  180. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.TransferQuantity<a.TransferQuantity)
  181. BEGIN
  182. RAISERROR('" + language.GetNameByCode("WMSAPIInfo144") + @"',16,1);
  183. RETURN
  184. END";
  185. }
  186. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  187. log.Debug(sql);
  188. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  189. {
  190. throw new Exception(language.GetNameByCode("WMSAPIInfo145"));//"调拨单信息更新失败!");
  191. }
  192. }
  193. catch (Exception)
  194. {
  195. throw;
  196. }
  197. }
  198. /// <summary>
  199. /// 一步调拨接口
  200. /// </summary>
  201. /// <param name="TransType"></param>
  202. /// <param name="Identification"></param>
  203. /// <param name="cmd"></param>
  204. public static void OneStepTransferDocInERP(string TransType, string Identification, string isPN, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode,string UserCode)
  205. {
  206. try
  207. {
  208. #region ERP开立状态单据审核
  209. string resultStr = "";
  210. string sql = "";
  211. //检验调拨单是否一次性发完
  212. if (isPN == "1")
  213. {
  214. sql = @"
  215. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  216. FROM ICSWareHouseLotInfoLog a
  217. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  218. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  219. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  220. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='3' and a.EATTRIBUTE1<>'1'
  221. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  222. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.TransferQuantity) AS ISSQty,a.transCode from ICSTransfer b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.TransferNO --AND a.WorkPoint=b.WorkPoint
  223. where a.Identification='{0}' GROUP BY a.transCode";
  224. checksql = string.Format(checksql, Identification);
  225. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  226. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  227. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  228. string trancode = chekdt.Rows[0]["transCode"].ToString();
  229. if (SUMQty - ISSQty == 0)
  230. {
  231. string pnsql = @"SELECT DISTINCT b.TransferID AS ID,'{1}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  232. FROM ICSWareHouseLotInfoLog a
  233. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  234. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  235. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  236. WHERE a.TransCode='{0}' AND ERPUpload='0' AND b.Type='3' and a.EATTRIBUTE1<>'1'
  237. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  238. ";
  239. pnsql = string.Format(pnsql, trancode, UserCode);
  240. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  241. string Inputstr = JsonConvert.SerializeObject(dt);
  242. if (isPN == "1")
  243. {//派纳调拨
  244. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNOneStepTransferDocInURL, Inputstr);
  245. Result result = new Result();
  246. result = JsonConvert.DeserializeObject<Result>(resultStr);
  247. if (result.Success)
  248. {
  249. try
  250. {
  251. foreach (DataRow dr in dt.Rows)
  252. {
  253. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  254. }
  255. }
  256. catch (Exception ex)
  257. {
  258. log.Debug(ex.ToString());
  259. log.Debug(resultStr);
  260. }
  261. }
  262. else
  263. {
  264. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  265. }
  266. }
  267. else
  268. {
  269. sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  270. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  271. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  272. BEGIN
  273. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  274. RETURN
  275. END
  276. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  277. FROM ICSWareHouseLotInfoLog a
  278. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  279. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  280. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  281. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  282. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  283. sql = string.Format(sql, Identification);
  284. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  285. string Inputstrr = JsonConvert.SerializeObject(dtt);
  286. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstrr);
  287. Result resultt = new Result();
  288. resultt = JsonConvert.DeserializeObject<Result>(resultStr);
  289. if (resultt.Success)
  290. {
  291. try
  292. {
  293. foreach (DataRow dr in dt.Rows)
  294. {
  295. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  296. }
  297. }
  298. catch (Exception ex)
  299. {
  300. log.Debug(ex.ToString());
  301. log.Debug(resultStr);
  302. }
  303. }
  304. else
  305. {
  306. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + resultt.Message);
  307. }
  308. }
  309. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  310. }
  311. }
  312. else
  313. {
  314. if (DBHelper.IsPNU9())
  315. {
  316. sql = @"
  317. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  318. FROM ICSWareHouseLotInfoLog a
  319. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  320. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  321. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  322. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' and a.EATTRIBUTE1<>'1'
  323. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  324. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.TransferQuantity) AS ISSQty,a.transCode from ICSTransfer b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.TransferNO --AND a.WorkPoint=b.WorkPoint
  325. where a.Identification='{0}' GROUP BY a.transCode";
  326. checksql = string.Format(checksql, Identification);
  327. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  328. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  329. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  330. string trancode = chekdt.Rows[0]["transCode"].ToString();
  331. if (SUMQty - ISSQty == 0)
  332. {
  333. string pnsql = @"SELECT DISTINCT b.TransferID AS ID,'{1}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  334. FROM ICSWareHouseLotInfoLog a
  335. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  336. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  337. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  338. WHERE a.TransCode='{0}' AND ERPUpload='0' AND b.Type='1' and a.EATTRIBUTE1<>'1'
  339. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  340. ";
  341. pnsql = string.Format(pnsql, trancode,UserCode);
  342. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  343. string Inputstr = JsonConvert.SerializeObject(dt);
  344. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  345. Result result = new Result();
  346. result = JsonConvert.DeserializeObject<Result>(resultStr);
  347. if (result.Success)
  348. {
  349. try
  350. {
  351. foreach (DataRow dr in dt.Rows)
  352. {
  353. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  354. }
  355. }
  356. catch (Exception ex)
  357. {
  358. log.Debug(ex.ToString());
  359. log.Debug(resultStr);
  360. }
  361. }
  362. else
  363. {
  364. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  365. }
  366. }
  367. }
  368. else
  369. {
  370. sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  371. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  372. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  373. BEGIN
  374. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  375. RETURN
  376. END
  377. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  378. FROM ICSWareHouseLotInfoLog a
  379. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  380. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  381. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  382. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  383. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  384. sql = string.Format(sql, Identification);
  385. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  386. string Inputstr = JsonConvert.SerializeObject(dt);
  387. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  388. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  389. Result result = new Result();
  390. result = JsonConvert.DeserializeObject<Result>(resultStr);
  391. if (result.Success)
  392. {
  393. try
  394. {
  395. foreach (DataRow dr in dt.Rows)
  396. {
  397. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  398. }
  399. }
  400. catch (Exception ex)
  401. {
  402. log.Debug(ex.ToString());
  403. log.Debug(resultStr);
  404. }
  405. }
  406. else
  407. {
  408. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  409. }
  410. }
  411. }
  412. #endregion
  413. }
  414. catch (Exception)
  415. {
  416. throw;
  417. }
  418. }
  419. /// <summary>
  420. /// 一步调拨接口
  421. /// </summary>
  422. /// <param name="TransType"></param>
  423. /// <param name="Identification"></param>
  424. /// <param name="cmd"></param>
  425. public static void NewOneStepTransferDocInERP(string TransType, string Identification, string isPN, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  426. {
  427. try
  428. {
  429. #region ERP开立状态单据审核
  430. string resultStr = "";
  431. string sql = "";
  432. //检验调拨单是否一次性发完
  433. if (isPN == "1")
  434. {
  435. sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  436. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  437. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  438. BEGIN
  439. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  440. RETURN
  441. END
  442. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  443. FROM ICSWareHouseLotInfoLog a
  444. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  445. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  446. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  447. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='3'
  448. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  449. sql = string.Format(sql, Identification);
  450. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  451. string Inputstr = JsonConvert.SerializeObject(dt);
  452. if (isPN == "1")
  453. {//派纳调拨
  454. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNOneStepTransferDocInURL, Inputstr);
  455. }
  456. else
  457. {
  458. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  459. }
  460. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  461. Result result = new Result();
  462. result = JsonConvert.DeserializeObject<Result>(resultStr);
  463. if (result.Success)
  464. {
  465. try
  466. {
  467. foreach (DataRow dr in dt.Rows)
  468. {
  469. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  470. }
  471. }
  472. catch (Exception ex)
  473. {
  474. log.Debug(ex.ToString());
  475. log.Debug(resultStr);
  476. }
  477. }
  478. else
  479. {
  480. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  481. }
  482. }
  483. else
  484. {
  485. if (DBHelper.IsPNU9())
  486. {
  487. sql = @"
  488. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  489. FROM ICSWareHouseLotInfoLog a
  490. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  491. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  492. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  493. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  494. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  495. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.TransferQuantity) AS ISSQty,a.transCode from ICSTransfer b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.TransferNO --AND a.WorkPoint=b.WorkPoint
  496. where a.Identification='{0}' GROUP BY a.transCode";
  497. checksql = string.Format(checksql, Identification);
  498. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  499. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  500. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  501. string trancode = chekdt.Rows[0]["transCode"].ToString();
  502. if (SUMQty - ISSQty == 0)
  503. {
  504. if (isPN=="2")
  505. {
  506. string pnsql = @"SELECT DISTINCT b.TransferDetailID AS DocLineID,SUM(a.Quantity) AS TransferQTY,ext.BatchCode AS TransferBatchCode,a.WorkPoint AS OrgCode
  507. FROM ICSWareHouseLotInfoLog a
  508. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo --AND a.WorkPoint=lot.WorkPoint
  509. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID --AND lot.WorkPoint=ext.WorkPoint
  510. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  511. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  512. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  513. WHERE a.TransCode='{0}' AND ERPUpload='0' AND b.Type='1'
  514. GROUP BY b.TransferDetailID,ext.BatchCode,a.WorkPoint
  515. ";
  516. pnsql = string.Format(pnsql, trancode);
  517. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  518. string Inputstr = JsonConvert.SerializeObject(dt);
  519. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.NewOneStepTransferDocInURL, Inputstr);
  520. Result result = new Result();
  521. result = JsonConvert.DeserializeObject<Result>(resultStr);
  522. if (result.Success)
  523. {
  524. try
  525. {
  526. foreach (DataRow dr in dt.Rows)
  527. {
  528. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  529. }
  530. }
  531. catch (Exception ex)
  532. {
  533. log.Debug(ex.ToString());
  534. log.Debug(resultStr);
  535. }
  536. }
  537. else
  538. {
  539. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  540. }
  541. }
  542. else
  543. {
  544. string pnsql = @"SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  545. FROM ICSWareHouseLotInfoLog a
  546. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  547. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  548. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  549. WHERE a.TransCode='{0}' AND ERPUpload='0' AND b.Type='1'
  550. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  551. ";
  552. pnsql = string.Format(pnsql, trancode);
  553. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  554. string Inputstr = JsonConvert.SerializeObject(dt);
  555. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  556. Result result = new Result();
  557. result = JsonConvert.DeserializeObject<Result>(resultStr);
  558. if (result.Success)
  559. {
  560. try
  561. {
  562. foreach (DataRow dr in dt.Rows)
  563. {
  564. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  565. }
  566. }
  567. catch (Exception ex)
  568. {
  569. log.Debug(ex.ToString());
  570. log.Debug(resultStr);
  571. }
  572. }
  573. else
  574. {
  575. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  576. }
  577. }
  578. }
  579. }
  580. else
  581. {
  582. sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  583. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  584. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  585. BEGIN
  586. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  587. RETURN
  588. END
  589. SELECT b.TransferID 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 ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  592. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  593. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  594. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  595. GROUP BY b.TransferID,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. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  600. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  601. Result result = new Result();
  602. result = JsonConvert.DeserializeObject<Result>(resultStr);
  603. if (result.Success)
  604. {
  605. try
  606. {
  607. foreach (DataRow dr in dt.Rows)
  608. {
  609. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  610. }
  611. }
  612. catch (Exception ex)
  613. {
  614. log.Debug(ex.ToString());
  615. log.Debug(resultStr);
  616. }
  617. }
  618. else
  619. {
  620. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  621. }
  622. }
  623. }
  624. #endregion
  625. }
  626. catch (Exception)
  627. {
  628. throw;
  629. }
  630. }
  631. #endregion
  632. #region 调拨
  633. /// <summary>
  634. /// 调拨接口
  635. /// </summary>
  636. /// <param name="TransType"></param>
  637. /// <param name="Identification"></param>
  638. /// <param name="cmd"></param>
  639. public static void StepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  640. {
  641. try
  642. {
  643. #region ERP开立状态单据审核
  644. //检验调拨单是否一次性发完
  645. 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,
  646. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  647. ,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,
  648. 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
  649. INTO #TempERP
  650. FROM ICSWareHouseLotInfoLog a
  651. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  652. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  653. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  654. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  655. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  656. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  657. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  658. WHERE a.Identification='{0}' AND ERPUpload='0'
  659. GROUP BY a.ToWarehouseCode,a.MUSER,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
  660. ,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, ''),
  661. 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, '')
  662. SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
  663. SELECT Costre,Sequence,InvCode,Quantity,Amount,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  664. FROM #TempERP
  665. DROP TABLE #TempERP";
  666. sql = string.Format(sql, Identification);
  667. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  668. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  669. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.StepTransferDocInURL, Inputstr);
  670. Result result = new Result();
  671. result = JsonConvert.DeserializeObject<Result>(resultStr);
  672. if (result.Success)
  673. {
  674. try
  675. {
  676. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  677. foreach (var item in res)
  678. {
  679. JObject jo = (JObject)item;
  680. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  681. foreach (var detail in resdetail)
  682. {
  683. JObject det = (JObject)detail;
  684. string allcol = jo["WHCode"].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()
  685. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  686. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(),allcol, cmd, language, BusinessCode);
  687. }
  688. }
  689. }
  690. catch (Exception ex)
  691. {
  692. log.Debug(ex.ToString());
  693. log.Debug(resultStr);
  694. }
  695. }
  696. else
  697. {
  698. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  699. }
  700. #endregion
  701. }
  702. catch (Exception)
  703. {
  704. throw;
  705. }
  706. }
  707. #endregion
  708. #region 调拨申请单接口
  709. /// <summary>
  710. /// 调拨申请单接口
  711. /// </summary>
  712. /// <param name="TransType"></param>
  713. /// <param name="Identification"></param>
  714. /// <param name="cmd"></param>
  715. public static void StepTransferApplicationERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  716. {
  717. try
  718. {
  719. #region ERP开立状态单据审核
  720. string sql = "";
  721. //检验调拨单是否一次性发完
  722. if (DBHelper.IsPNU9())//派纳
  723. {
  724. sql = @"SELECT c.TransferDetailID as TADetailID,a.TransCode+a.ToWarehouseCode+a.MUSER+a.FromWarehouseCode AS Costre,a.ToWarehouseCode AS ToWHCode,a.FromWarehouseCode AS FromWHCode,a.MUSER,'' AS FromDepCode,'' AS ToDepCode,a.TransCode AS TACode,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode) AS Sequence,
  725. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  726. ,c.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,
  727. 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
  728. INTO #TempERP
  729. FROM ICSWareHouseLotInfoLog a
  730. INNER JOIN ICSTransferApplication c ON a.TransCode=c.TransferNO and a.TransSequence=c.Sequence and a.WorkPoint=c.EATTRIBUTE30
  731. --INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  732. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  733. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  734. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  735. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  736. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  737. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  738. WHERE a.Identification='{0}' AND ERPUpload='0' and a.businesscode ='47'
  739. GROUP BY a.ToWarehouseCode,a.MUSER,c.TransferDetailID,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
  740. ,c.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, ''),
  741. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, ''),a.TransCode
  742. SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
  743. SELECT Costre,Sequence,InvCode,Quantity,Amount,ToWHCode AS INWhCode,FromWHCode AS OutWhCode,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  744. FROM #TempERP
  745. DROP TABLE #TempERP";
  746. }
  747. else
  748. {
  749. sql = @"SELECT c.TransferDetailID as TADetailID,a.TransCode+a.ToWarehouseCode+a.MUSER+a.FromWarehouseCode AS Costre,a.ToWarehouseCode AS ToWHCode,a.FromWarehouseCode AS FromWHCode,a.MUSER,'' AS FromDepCode,'' AS ToDepCode,a.TransCode AS TACode,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode) AS Sequence,
  750. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  751. ,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,
  752. 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
  753. INTO #TempERP
  754. FROM ICSWareHouseLotInfoLog a
  755. INNER JOIN ICSTransferApplication c ON a.TransCode=c.TransferNO and a.TransSequence=c.Sequence and a.WorkPoint=c.WorkPoint
  756. --INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  757. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  758. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  759. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  760. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  761. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  762. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  763. WHERE a.Identification='{0}' AND ERPUpload='0' and a.businesscode ='47'
  764. GROUP BY a.ToWarehouseCode,a.MUSER,c.TransferDetailID,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
  765. ,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, ''),
  766. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, ''),a.TransCode
  767. SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
  768. SELECT Costre,Sequence,InvCode,Quantity,Amount,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  769. FROM #TempERP
  770. DROP TABLE #TempERP";
  771. }
  772. sql = string.Format(sql, Identification);
  773. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  774. log.Debug(sql);
  775. log.Debug(ds.ToString());
  776. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  777. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.StepTransferApplicationURL, Inputstr);
  778. Result result = new Result();
  779. result = JsonConvert.DeserializeObject<Result>(resultStr);
  780. if (result.Success)
  781. {
  782. try
  783. {
  784. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  785. foreach (var item in res)
  786. {
  787. JObject jo = (JObject)item;
  788. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  789. foreach (var detail in resdetail)
  790. {
  791. JObject det = (JObject)detail;
  792. string allcol = "" + 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()
  793. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  794. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  795. }
  796. }
  797. }
  798. catch (Exception ex)
  799. {
  800. log.Debug(ex.ToString());
  801. log.Debug(resultStr);
  802. }
  803. }
  804. else
  805. {
  806. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  807. }
  808. #endregion
  809. }
  810. catch (Exception)
  811. {
  812. throw;
  813. }
  814. }
  815. #endregion
  816. #region 两步调出
  817. /// <summary>
  818. /// 两步调出
  819. /// </summary>
  820. /// <param name="TransCode"></param>
  821. /// <param name="TransSequence"></param>
  822. /// <param name="Quantity"></param>
  823. /// <param name="WorkPoint"></param>
  824. /// <param name="cmd"></param>
  825. public static void TwoStepTransferDocOut(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  826. {
  827. try
  828. {
  829. string sql = @"DECLARE @Status VARCHAR(10)
  830. SELECT @Status=a.Status FROM ICSOtherOut a
  831. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  832. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}'
  833. IF (@Status IS NULL)
  834. BEGIN
  835. RAISERROR('" + language.GetNameByCode("WMSAPIInfo146") + @"',16,1);
  836. RETURN
  837. END
  838. ELSE IF (@Status!='1')
  839. BEGIN
  840. RAISERROR('" + language.GetNameByCode("WMSAPIInfo147") + @"',16,1);
  841. RETURN
  842. END
  843. UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
  844. FROM ICSOtherOut a
  845. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  846. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}'
  847. IF EXISTS(SELECT a.ID FROM ICSOtherOut a
  848. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  849. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' and a.id='{4}' AND a.Quantity<a.OutQuantity)
  850. BEGIN
  851. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  852. RETURN
  853. END";
  854. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  855. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  856. {
  857. throw new Exception(language.GetNameByCode("WMSAPIInfo148"));//"两步调出单更新失败!");
  858. }
  859. }
  860. catch (Exception)
  861. {
  862. throw;
  863. }
  864. }
  865. /// <summary>
  866. /// 两步调出接口
  867. /// </summary>
  868. /// <param name="TransType"></param>
  869. /// <param name="Identification"></param>
  870. /// <param name="cmd"></param>
  871. public static void TwoStepTransferDocOutERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  872. {
  873. try
  874. {
  875. #region ERP开立状态单据审核
  876. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  877. INTO #NewTempERP
  878. from ICSWareHouseLotInfoLog
  879. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '22'
  880. IF EXISTS(SELECT b.ID FROM ICSOtherOut b
  881. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  882. WHERE b.OutCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  883. AND b.Quantity!=b.OutQuantity)
  884. BEGIN
  885. RAISERROR('" + language.GetNameByCode("WMSAPIInfo098") + @"',16,1);
  886. RETURN
  887. END
  888. SELECT b.OutID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  889. FROM #NewTempERP a
  890. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  891. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  892. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  893. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  894. GROUP BY b.OutID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  895. DROP TABLE #NewTempERP";
  896. sql = string.Format(sql, Identification);
  897. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  898. string Inputstr = JsonConvert.SerializeObject(dt);
  899. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocOutURL, Inputstr);
  900. Result result = new Result();
  901. result = JsonConvert.DeserializeObject<Result>(resultStr);
  902. if (result.Success)
  903. {
  904. try
  905. {
  906. foreach (DataRow dr in dt.Rows)
  907. {
  908. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  909. }
  910. }
  911. catch (Exception ex)
  912. {
  913. log.Debug(ex.ToString());
  914. log.Debug(resultStr);
  915. }
  916. }
  917. else
  918. {
  919. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  920. }
  921. #endregion
  922. }
  923. catch (Exception)
  924. {
  925. throw;
  926. }
  927. }
  928. #endregion
  929. #region 两步调入
  930. /// <summary>
  931. /// 两步调入
  932. /// </summary>
  933. /// <param name="TransCode"></param>
  934. /// <param name="TransSequence"></param>
  935. /// <param name="Quantity"></param>
  936. /// <param name="WorkPoint"></param>
  937. /// <param name="cmd"></param>
  938. public static void TwoStepTransferDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  939. {
  940. //需要关联其他入库单
  941. try
  942. {
  943. string sql = @"DECLARE @Status VARCHAR(10)
  944. SELECT @Status=Otin.Status FROM ICSOtherIn Otin
  945. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  946. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  947. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  948. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  949. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}'
  950. IF (@Status IS NULL)
  951. BEGIN
  952. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  953. RETURN
  954. END
  955. ELSE IF (@Status!='1')
  956. BEGIN
  957. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  958. RETURN
  959. END
  960. UPDATE Otin SET InQuantity=ISNULL(InQuantity,0)+'{4}'
  961. FROM ICSOtherIn Otin
  962. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  963. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  964. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  965. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  966. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}'
  967. IF EXISTS(SELECT a.LotNo FROM ICSOtherIn Otin
  968. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  969. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  970. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  971. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  972. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}' AND Otin.Quantity<Otin.InQuantity)
  973. BEGIN
  974. RAISERROR('" + language.GetNameByCode("WMSAPIInfo149") + @"',16,1);
  975. END";
  976. sql = string.Format(sql, LotNo, WorkPoint,TransCode,TransSequence, Quantity);
  977. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  978. {
  979. throw new Exception(language.GetNameByCode("WMSAPIInfo150"));//"两步调入单更新失败!");
  980. }
  981. }
  982. catch (Exception)
  983. {
  984. throw;
  985. }
  986. }
  987. /// <summary>
  988. /// 两步调入接口
  989. /// </summary>
  990. /// <param name="TransType"></param>
  991. /// <param name="Identification"></param>
  992. /// <param name="cmd"></param>
  993. public static void TwoStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  994. {
  995. try
  996. {
  997. #region ERP开立状态单据审核
  998. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  999. INTO #NewTempERP
  1000. from ICSWareHouseLotInfoLog
  1001. WHERE Identification='{0}' AND ERPUpload='0'
  1002. IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  1003. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1004. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1005. AND b.Quantity!=b.InQuantity)
  1006. BEGIN
  1007. RAISERROR('" + language.GetNameByCode("WMSAPIInfo099") + @"',16,1);
  1008. RETURN
  1009. END
  1010. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1011. FROM #NewTempERP a
  1012. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1013. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1014. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1015. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1016. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1017. DROP TABLE #NewTempERP";
  1018. sql = string.Format(sql, Identification);
  1019. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1020. string Inputstr = JsonConvert.SerializeObject(dt);
  1021. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocInURL, Inputstr);
  1022. Result result = new Result();
  1023. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1024. if (result.Success)
  1025. {
  1026. try
  1027. {
  1028. foreach (DataRow dr in dt.Rows)
  1029. {
  1030. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "","", cmd, language, BusinessCode);
  1031. }
  1032. }
  1033. catch (Exception ex)
  1034. {
  1035. log.Debug(ex.ToString());
  1036. log.Debug(resultStr);
  1037. }
  1038. }
  1039. else
  1040. {
  1041. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  1042. }
  1043. #endregion
  1044. }
  1045. catch (Exception)
  1046. {
  1047. throw;
  1048. }
  1049. }
  1050. #endregion
  1051. #region 锐腾两步调入
  1052. /// <summary>
  1053. /// 锐腾两步调入
  1054. /// </summary>
  1055. /// <param name="TransCode"></param>
  1056. /// <param name="TransSequence"></param>
  1057. /// <param name="Quantity"></param>
  1058. /// <param name="WorkPoint"></param>
  1059. /// <param name="cmd"></param>
  1060. public static void RTTwoStepTransferDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1061. {
  1062. //需要关联其他入库单
  1063. try
  1064. {
  1065. string sql = @"DECLARE @Status VARCHAR(10)
  1066. SELECT @Status=tra.Status FROM ICSTransfer tra
  1067. INNER JOIN ICSInventoryLotDetail lotd ON lotd.TransCode=tra.TransferNO AND lotd.TransSequence=tra.Sequence and lotd.WorkPoint=tra.WorkPoint
  1068. INNER JOIN ICSInventoryLot lot ON lotd.LotNo=lot.LotNo and lotd.WorkPoint=lot.WorkPoint
  1069. WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND tra.TransferNO='{2}' and tra.Sequence='{3}'
  1070. IF (@Status IS NULL)
  1071. BEGIN
  1072. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1073. RETURN
  1074. END
  1075. UPDATE tra SET TransferQuantity=ISNULL(TransferQuantity,0)+'{4}'
  1076. FROM ICSTransfer tra
  1077. INNER JOIN ICSInventoryLotDetail lotd ON lotd.TransCode=tra.TransferNO AND lotd.TransSequence=tra.Sequence and lotd.WorkPoint=tra.WorkPoint
  1078. INNER JOIN ICSInventoryLot lot ON lotd.LotNo=lot.LotNo and lotd.WorkPoint=lot.WorkPoint
  1079. WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND tra.TransferNO='{2}' and tra.Sequence='{3}'
  1080. IF EXISTS(SELECT lot.LotNo FROM ICSTransfer tra
  1081. INNER JOIN ICSInventoryLotDetail lotd ON lotd.TransCode=tra.TransferNO AND lotd.TransSequence=tra.Sequence and lotd.WorkPoint=tra.WorkPoint
  1082. INNER JOIN ICSInventoryLot lot ON lotd.LotNo=lot.LotNo and lotd.WorkPoint=lot.WorkPoint
  1083. WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND tra.TransferNO='{2}' and tra.Sequence='{3}' AND tra.Quantity<tra.TransferQuantity)
  1084. BEGIN
  1085. RAISERROR('" + language.GetNameByCode("WMSAPIInfo149") + @"',16,1);
  1086. END";
  1087. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  1088. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1089. {
  1090. throw new Exception(language.GetNameByCode("WMSAPIInfo150"));//"两步调入单更新失败!");
  1091. }
  1092. }
  1093. catch (Exception)
  1094. {
  1095. throw;
  1096. }
  1097. }
  1098. /// <summary>
  1099. /// 两步调入接口
  1100. /// </summary>
  1101. /// <param name="TransType"></param>
  1102. /// <param name="Identification"></param>
  1103. /// <param name="cmd"></param>
  1104. public static void RTTwoStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1105. {
  1106. try
  1107. {
  1108. #region ERP开立状态单据审核
  1109. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1110. INTO #NewTempERP
  1111. from ICSWareHouseLotInfoLog
  1112. WHERE Identification='{0}' AND ERPUpload='0'
  1113. IF EXISTS(SELECT b.ID FROM ICSTransfer b
  1114. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1115. AND b.Quantity!=b.TransferQuantity)
  1116. BEGIN
  1117. RAISERROR('" + language.GetNameByCode("WMSAPIInfo099") + @"',16,1);
  1118. RETURN
  1119. END
  1120. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1121. FROM #NewTempERP a
  1122. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1123. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1124. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1125. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1126. DROP TABLE #NewTempERP";
  1127. sql = string.Format(sql, Identification);
  1128. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1129. string Inputstr = JsonConvert.SerializeObject(dt);
  1130. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.RTTwoStepTransferDocInURL, Inputstr);
  1131. Result result = new Result();
  1132. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1133. if (result.Success)
  1134. {
  1135. try
  1136. {
  1137. foreach (DataRow dr in dt.Rows)
  1138. {
  1139. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1140. }
  1141. }
  1142. catch (Exception ex)
  1143. {
  1144. log.Debug(ex.ToString());
  1145. log.Debug(resultStr);
  1146. }
  1147. }
  1148. else
  1149. {
  1150. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1151. }
  1152. #endregion
  1153. }
  1154. catch (Exception)
  1155. {
  1156. throw;
  1157. }
  1158. }
  1159. #endregion
  1160. #region 其他出库
  1161. /// <summary>
  1162. /// 其他出库
  1163. /// </summary>
  1164. /// <param name="TransCode"></param>
  1165. /// <param name="TransSequence"></param>
  1166. /// <param name="Quantity"></param>
  1167. /// <param name="WorkPoint"></param>
  1168. /// <param name="cmd"></param>
  1169. public static void OtherOutDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  1170. {
  1171. try
  1172. {
  1173. string sql = @"DECLARE @Status VARCHAR(10)
  1174. SELECT @Status=a.Status FROM ICSOtherOut a
  1175. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}'
  1176. IF (@Status IS NULL)
  1177. BEGIN
  1178. RAISERROR('" + language.GetNameByCode("WMSAPIInfo151") + @"',16,1);
  1179. RETURN
  1180. END
  1181. ELSE IF (@Status!='1')
  1182. BEGIN
  1183. RAISERROR('" + language.GetNameByCode("WMSAPIInfo152") + @"',16,1);
  1184. RETURN
  1185. END
  1186. UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
  1187. FROM ICSOtherOut a
  1188. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}'
  1189. IF EXISTS(SELECT a.ID FROM ICSOtherOut a
  1190. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.id='{4}' and a.WorkPoint='{1}' AND a.Quantity<a.OutQuantity)
  1191. BEGIN
  1192. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1193. RETURN
  1194. END";
  1195. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  1196. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1197. {
  1198. throw new Exception(language.GetNameByCode("WMSAPIInfo153"));//"其他出库单更新失败!");
  1199. }
  1200. }
  1201. catch (Exception)
  1202. {
  1203. throw;
  1204. }
  1205. }
  1206. /// <summary>
  1207. /// 其他出库接口
  1208. /// </summary>
  1209. /// <param name="TransType"></param>
  1210. /// <param name="Identification"></param>
  1211. /// <param name="cmd"></param>
  1212. public static void OtherOutDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1213. {
  1214. try
  1215. {
  1216. string sql = string.Empty;
  1217. if (DBHelper.IsPNU9())
  1218. {
  1219. sql = @"SELECT a.ToWarehouseCode+b.OutCode+a.MUSER AS Costre
  1220. ,a.TransCode+a.TransSequence+a.ToWarehouseCode+b.OutCode+a.MUSER AS Costre2
  1221. ,a.ToWarehouseCode AS WarehouseCode,b.OutCode,b.Sequence,a.MUSER,
  1222. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount, b.OutDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  1223. ,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,
  1224. 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
  1225. INTO #TempERP
  1226. FROM ICSWareHouseLotInfoLog a
  1227. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1228. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1229. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1230. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1231. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1232. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1233. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  1234. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1235. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode = '24'
  1236. GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,a.ToWarehouseCode,b.OutCode,b.Sequence,a.MUSER,a.InvCode,b.OutDetailID,con.Enable,conStock.Enable
  1237. ,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, ''),
  1238. 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, '')
  1239. SELECT DISTINCT Costre,WorkPoint,OutCode AS DocNo,0 AS ID FROM #TempERP
  1240. SELECT Costre,Costre2,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS ShipQuantity,Amount,OutDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1241. DROP TABLE #TempERP";
  1242. sql = string.Format(sql, Identification);
  1243. //DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1244. //string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  1245. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.OutQuantity) AS ISSQty,a.transCode from ICSOtherOut b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.OutCode AND a.WorkPoint=b.WorkPoint
  1246. where a.Identification='{0}' GROUP BY a.transCode";
  1247. checksql = string.Format(checksql, Identification);
  1248. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  1249. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  1250. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  1251. string trancode = chekdt.Rows[0]["transCode"].ToString();
  1252. if (SUMQty - ISSQty == 0)
  1253. {
  1254. string pnsql = @"SELECT b.OutCode AS Costre
  1255. ,a.TransCode+a.TransSequence+a.FromWarehouseCode+b.OutCode+a.MUSER AS Costre2
  1256. ,a.FromWarehouseCode AS WarehouseCode,b.OutCode,b.Sequence,a.MUSER,
  1257. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount, b.OutDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  1258. ,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,
  1259. 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
  1260. INTO #TempERP
  1261. FROM ICSWareHouseLotInfoLog a
  1262. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1263. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1264. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1265. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1266. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1267. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1268. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  1269. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1270. WHERE a.TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '24' and a.EATTRIBUTE1<>'1'
  1271. GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,a.FromWarehouseCode,b.OutCode,b.Sequence,a.MUSER,a.InvCode,b.OutDetailID,con.Enable,conStock.Enable
  1272. ,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, ''),
  1273. 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, '')
  1274. SELECT DISTINCT Costre,WorkPoint,OutCode AS DocNo,0 AS ID FROM #TempERP
  1275. SELECT Costre,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS ShipQuantity,Amount,OutDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1276. DROP TABLE #TempERP";
  1277. pnsql = string.Format(pnsql, trancode);
  1278. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  1279. string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  1280. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MiscShipURL, Inputstr);
  1281. Result result = new Result();
  1282. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1283. if (result.Success)
  1284. {
  1285. try
  1286. {
  1287. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1288. foreach (var item in res)
  1289. {
  1290. JObject jo = (JObject)item;
  1291. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1292. foreach (var detail in resdetail)
  1293. {
  1294. JObject det = (JObject)detail;
  1295. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1',Quantity='{6}'
  1296. // FROM ICSWareHouseLotInfoLog a
  1297. // INNER JOIN ICSSSD c ON a.TransCode=c.SSDCOde AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1298. //INNER JOIN ICSInventoryLot lot on a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1299. //INNER JOIN ICSExtension d ON lot.ExtensionID=d.id and lot.WorkPoint=d.WorkPoint
  1300. // WHERE c.SSDCode='{0}' AND a.BusinessCode ='{7}' AND d.BatchCode='{8}' AND lot.InvCode='{1}'";
  1301. // ERPupdate = string.Format(ERPupdate);
  1302. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1303. // {
  1304. // throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  1305. // }
  1306. }
  1307. }
  1308. }
  1309. catch (Exception ex)
  1310. {
  1311. log.Debug(ex.ToString());
  1312. log.Debug(resultStr);
  1313. }
  1314. }
  1315. else
  1316. {
  1317. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1318. }
  1319. }
  1320. }
  1321. else
  1322. {
  1323. #region ERP开立状态单据审核
  1324. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  1325. INTO #NewTempERP
  1326. from ICSWareHouseLotInfoLog
  1327. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '24'
  1328. IF EXISTS(SELECT b.ID FROM ICSOtherOut b
  1329. WHERE b.OutCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1330. AND b.Quantity!=b.OutQuantity)
  1331. BEGIN
  1332. RAISERROR('" + language.GetNameByCode("WMSAPIInfo100") + @"',16,1);
  1333. RETURN
  1334. END
  1335. SELECT b.OutID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1336. FROM #NewTempERP a
  1337. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
  1338. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1339. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1340. GROUP BY b.OutID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1341. DROP TABLE #NewTempERP";
  1342. sql = string.Format(sql, Identification);
  1343. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1344. string Inputstr = JsonConvert.SerializeObject(dt);
  1345. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OtherOutDocURL, Inputstr);
  1346. Result result = new Result();
  1347. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1348. if (result.Success)
  1349. {
  1350. try
  1351. {
  1352. foreach (DataRow dr in dt.Rows)
  1353. {
  1354. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1355. }
  1356. }
  1357. catch (Exception ex)
  1358. {
  1359. log.Debug(ex.ToString());
  1360. log.Debug(resultStr);
  1361. }
  1362. }
  1363. else
  1364. {
  1365. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1366. }
  1367. #endregion
  1368. }
  1369. }
  1370. catch (Exception)
  1371. {
  1372. throw;
  1373. }
  1374. }
  1375. /// <summary>
  1376. /// 创建U9杂发单接口
  1377. /// </summary>
  1378. /// <param name="TransType"></param>
  1379. /// <param name="Identification"></param>
  1380. /// <param name="cmd"></param>
  1381. public static void CreateOtherOutDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1382. {
  1383. try
  1384. {
  1385. #region U9创建单据并审核
  1386. string sql = @"select LotNo,WorkPoint,InvCode,FromWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1387. INTO #NewTempERP
  1388. from ICSWareHouseLotInfoLog
  1389. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='24'
  1390. SELECT a.FromWarehouseCode+b.OutCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.OutCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.OutCode,a.InvCode) AS Sequence,
  1391. b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE7 as Project,b.EATTRIBUTE1 as Dep,
  1392. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1393. ,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,
  1394. 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
  1395. INTO #TempERP
  1396. FROM #NewTempERP a
  1397. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1398. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1399. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1400. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1401. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1402. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1403. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock009' AND a.WorkPoint=conStock.WorkPoint
  1404. GROUP BY inv.AmountEnable,a.FromWarehouseCode,b.OutCode,a.MUSER,a.InvCode,con.Enable,conStock.Enable,b.EATTRIBUTE4,b.EATTRIBUTE2,b.EATTRIBUTE7 ,b.EATTRIBUTE1
  1405. ,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, ''),
  1406. 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, '')
  1407. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,DocType,ClientCode,OutCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1408. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
  1409. DROP TABLE #TempERP
  1410. DROP TABLE #NewTempERP";
  1411. sql = string.Format(sql, Identification, BusinessCode);
  1412. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1413. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1414. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstr);
  1415. //sql = string.Format(sql, Identification);
  1416. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1417. //string Inputstr = JsonConvert.SerializeObject(dt);
  1418. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstr);
  1419. Result result = new Result();
  1420. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1421. if (result.Success)
  1422. {
  1423. try
  1424. {
  1425. //foreach (DataRow dr in dt.Rows)
  1426. //{
  1427. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1428. //}
  1429. }
  1430. catch (Exception ex)
  1431. {
  1432. log.Debug(ex.ToString());
  1433. log.Debug(resultStr);
  1434. }
  1435. }
  1436. else
  1437. {
  1438. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1439. }
  1440. #endregion
  1441. }
  1442. catch (Exception)
  1443. {
  1444. throw;
  1445. }
  1446. }
  1447. #endregion
  1448. #region 其他入库
  1449. /// <summary>
  1450. /// 其他入库
  1451. /// </summary>
  1452. /// <param name="TransCode"></param>
  1453. /// <param name="TransSequence"></param>
  1454. /// <param name="Quantity"></param>
  1455. /// <param name="WorkPoint"></param>
  1456. /// <param name="cmd"></param>
  1457. public static void OtherInDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1458. {
  1459. try
  1460. {
  1461. string sql = @"DECLARE @Status VARCHAR(10)
  1462. SELECT @Status=c.Status FROM ICSInventoryLot a
  1463. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1464. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1465. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND isnull(c.Type,'1')='1'
  1466. IF (@Status IS NULL)
  1467. BEGIN
  1468. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1469. RETURN
  1470. END
  1471. ELSE IF (@Status!='1')
  1472. BEGIN
  1473. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1474. RETURN
  1475. END
  1476. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  1477. FROM ICSInventoryLot a
  1478. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1479. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1480. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND isnull(c.Type,'1')='1'
  1481. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1482. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1483. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1484. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND isnull(c.Type,'1')='1'
  1485. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn021', c.Quantity,1,4,'')<c.InQuantity)
  1486. BEGIN
  1487. RAISERROR('" + language.GetNameByCode("WMSAPIInfo154") + @"',16,1);
  1488. END";
  1489. if (DBHelper.IsU9())
  1490. { sql = @"DECLARE @Status VARCHAR(10)
  1491. SELECT @Status=c.Status FROM ICSInventoryLot a
  1492. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1493. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1494. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1495. IF (@Status IS NULL)
  1496. BEGIN
  1497. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1498. RETURN
  1499. END
  1500. ELSE IF (@Status!='1')
  1501. BEGIN
  1502. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1503. RETURN
  1504. END
  1505. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  1506. FROM ICSInventoryLot a
  1507. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1508. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1509. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'-- AND c.EATTRIBUTE2='1'
  1510. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1511. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1512. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1513. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.EATTRIBUTE2='1'
  1514. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn021', c.Quantity,1,4,'')<c.InQuantity)
  1515. BEGIN
  1516. RAISERROR('" + language.GetNameByCode("WMSAPIInfo154") + @"',16,1);
  1517. END"; }
  1518. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1519. log.Debug("回写单据数量前"+sql);
  1520. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1521. {
  1522. throw new Exception(language.GetNameByCode("WMSAPIInfo155"));//"其他入库单更新失败!");
  1523. }
  1524. log.Debug("回写单据数量后");
  1525. }
  1526. catch (Exception)
  1527. {
  1528. throw;
  1529. }
  1530. }
  1531. public static void OtherInRedDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID)
  1532. {
  1533. try
  1534. {
  1535. string sql = @"DECLARE @Status VARCHAR(10)
  1536. SELECT @Status=a.Status FROM ICSOtherIn a
  1537. WHERE a.InCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' and a.type='2'
  1538. IF (@Status IS NULL)
  1539. BEGIN
  1540. RAISERROR('" + language.GetNameByCode("WMSAPIInfo151") + @"',16,1);
  1541. RETURN
  1542. END
  1543. ELSE IF (@Status!='1')
  1544. BEGIN
  1545. RAISERROR('" + language.GetNameByCode("WMSAPIInfo152") + @"',16,1);
  1546. RETURN
  1547. END
  1548. UPDATE a SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  1549. FROM ICSOtherIn a
  1550. WHERE a.InCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' and a.type='2'
  1551. IF EXISTS(SELECT a.ID FROM ICSOtherIn a
  1552. WHERE a.InCode='{0}' AND a.Sequence='{3}' and a.id='{4}' and a.WorkPoint='{1}' and a.type='2' AND a.Quantity<a.InQuantity)
  1553. BEGIN
  1554. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1555. RETURN
  1556. END";
  1557. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  1558. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1559. {
  1560. throw new Exception("红字其他入库单更新失败!");//"红字其他入库单更新失败!");
  1561. }
  1562. }
  1563. catch (Exception)
  1564. {
  1565. throw;
  1566. }
  1567. }
  1568. /// <summary>
  1569. /// 其他入库接口
  1570. /// </summary>
  1571. /// <param name="TransType"></param>
  1572. /// <param name="Identification"></param>
  1573. /// <param name="cmd"></param>
  1574. public static void OtherInDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1575. {
  1576. try
  1577. {
  1578. string sql = string.Empty;
  1579. log.Debug("ERP开立状态单据审核");
  1580. if (DBHelper.IsPNU9())
  1581. {
  1582. sql = @"SELECT a.ToWarehouseCode+b.InCode+a.MUSER AS Costre
  1583. ,a.TransCode+a.TransSequence+a.ToWarehouseCode+b.InCode+a.MUSER AS Costre2
  1584. ,a.ToWarehouseCode AS WarehouseCode,b.InCode,b.Sequence,a.MUSER,
  1585. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount, b.InDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  1586. ,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,
  1587. 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
  1588. INTO #TempERP
  1589. FROM ICSWareHouseLotInfoLog a
  1590. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1591. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1592. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1593. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1594. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1595. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1596. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  1597. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1598. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode = '25'
  1599. GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,a.ToWarehouseCode,b.InCode,b.Sequence,a.MUSER,a.InvCode,b.InDetailID,con.Enable,conStock.Enable
  1600. ,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, ''),
  1601. 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, '')
  1602. SELECT DISTINCT Costre,WorkPoint,InCode AS DocNo,0 AS ID FROM #TempERP
  1603. SELECT Costre,Costre2,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS RcvQuantity,Amount,InDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1604. DROP TABLE #TempERP";
  1605. sql = string.Format(sql, Identification);
  1606. //DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1607. //string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  1608. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.InQuantity) AS ISSQty,a.transCode from ICSOtherIn b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.InCode AND a.WorkPoint=b.WorkPoint
  1609. where a.Identification='{0}' GROUP BY a.transCode";
  1610. checksql = string.Format(checksql, Identification);
  1611. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  1612. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  1613. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  1614. string trancode = chekdt.Rows[0]["transCode"].ToString();
  1615. if (SUMQty - ISSQty == 0)
  1616. {
  1617. string pnsql = @"SELECT a.ToWarehouseCode+b.InCode+a.MUSER AS Costre
  1618. ,a.TransCode+a.TransSequence+a.ToWarehouseCode+b.InCode+a.MUSER AS Costre2
  1619. ,a.ToWarehouseCode AS WarehouseCode,b.InCode,b.Sequence,a.MUSER,
  1620. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount, b.InDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  1621. ,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,
  1622. 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
  1623. INTO #TempERP
  1624. FROM ICSWareHouseLotInfoLog a
  1625. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1626. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1627. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1628. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1629. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1630. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1631. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  1632. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1633. WHERE a.TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '25' and a.EATTRIBUTE1<>'1'
  1634. GROUP BY a.TransCode,a.TransSequence,conWhCode.Enable,inv.AmountEnable,a.ToWarehouseCode,b.InCode,b.Sequence,a.MUSER,a.InvCode,b.InDetailID,con.Enable,conStock.Enable
  1635. ,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, ''),
  1636. 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, '')
  1637. SELECT DISTINCT Costre,WorkPoint,InCode AS DocNo,0 AS ID FROM #TempERP
  1638. SELECT Costre,Costre2,Sequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,InvCode,Quantity,Quantity AS RcvQuantity,Amount,InDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  1639. DROP TABLE #TempERP";
  1640. pnsql = string.Format(pnsql, trancode);
  1641. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  1642. string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  1643. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MiscRcvURL, Inputstr);
  1644. Result result = new Result();
  1645. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1646. if (result.Success)
  1647. {
  1648. try
  1649. {
  1650. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1651. foreach (var item in res)
  1652. {
  1653. JObject jo = (JObject)item;
  1654. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1655. foreach (var detail in resdetail)
  1656. {
  1657. JObject det = (JObject)detail;
  1658. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1',Quantity='{6}'
  1659. // FROM ICSWareHouseLotInfoLog a
  1660. // INNER JOIN ICSSSD c ON a.TransCode=c.SSDCOde AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1661. //INNER JOIN ICSInventoryLot lot on a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1662. //INNER JOIN ICSExtension d ON lot.ExtensionID=d.id and lot.WorkPoint=d.WorkPoint
  1663. // WHERE c.SSDCode='{0}' AND a.BusinessCode ='{7}' AND d.BatchCode='{8}' AND lot.InvCode='{1}'";
  1664. // ERPupdate = string.Format(ERPupdate);
  1665. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1666. // {
  1667. // throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  1668. // }
  1669. }
  1670. }
  1671. }
  1672. catch (Exception ex)
  1673. {
  1674. log.Debug(ex.ToString());
  1675. log.Debug(resultStr);
  1676. }
  1677. }
  1678. else
  1679. {
  1680. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1681. }
  1682. }
  1683. }
  1684. else
  1685. {
  1686. #region ERP开立状态单据审核
  1687. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1688. INTO #NewTempERP
  1689. from ICSWareHouseLotInfoLog
  1690. WHERE Identification='{0}' AND ERPUpload='0'
  1691. IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  1692. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1693. AND b.Quantity!=ISNULL(b.InQuantity,0))
  1694. BEGIN
  1695. RAISERROR('" + language.GetNameByCode("WMSAPIInfo101") + @"',16,1);
  1696. RETURN
  1697. END
  1698. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1699. FROM #NewTempERP a
  1700. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint AND isnull(b.Type,'1')='1'
  1701. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1702. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1703. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1704. DROP TABLE #NewTempERP";
  1705. sql = string.Format(sql, Identification);
  1706. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1707. string Inputstr = JsonConvert.SerializeObject(dt);
  1708. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OtherInDocURL, Inputstr);
  1709. Result result = new Result();
  1710. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1711. if (result.Success)
  1712. {
  1713. try
  1714. {
  1715. foreach (DataRow dr in dt.Rows)
  1716. {
  1717. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1718. }
  1719. }
  1720. catch (Exception ex)
  1721. {
  1722. log.Debug(ex.ToString());
  1723. log.Debug(resultStr);
  1724. }
  1725. }
  1726. else
  1727. {
  1728. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1729. }
  1730. #endregion
  1731. }
  1732. }
  1733. catch (Exception)
  1734. {
  1735. throw;
  1736. }
  1737. }
  1738. public static void OtherInRedDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1739. {
  1740. try
  1741. {
  1742. #region ERP开立状态单据审核
  1743. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1744. INTO #NewTempERP
  1745. from ICSWareHouseLotInfoLog
  1746. WHERE Identification='{0}' AND ERPUpload='0'
  1747. IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  1748. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1749. AND b.Quantity!=b.InQuantity)
  1750. BEGIN
  1751. RAISERROR('" + language.GetNameByCode("WMSAPIInfo101") + @"',16,1);
  1752. RETURN
  1753. END
  1754. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1755. FROM #NewTempERP a
  1756. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint AND b.Type='2'
  1757. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1758. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1759. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1760. DROP TABLE #NewTempERP";
  1761. sql = string.Format(sql, Identification);
  1762. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1763. string Inputstr = JsonConvert.SerializeObject(dt);
  1764. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OtherInDocURL, Inputstr);
  1765. Result result = new Result();
  1766. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1767. if (result.Success)
  1768. {
  1769. try
  1770. {
  1771. foreach (DataRow dr in dt.Rows)
  1772. {
  1773. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1774. }
  1775. }
  1776. catch (Exception ex)
  1777. {
  1778. log.Debug(ex.ToString());
  1779. log.Debug(resultStr);
  1780. }
  1781. }
  1782. else
  1783. {
  1784. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1785. }
  1786. #endregion
  1787. }
  1788. catch (Exception)
  1789. {
  1790. throw;
  1791. }
  1792. }
  1793. /// <summary>
  1794. /// 创建U9杂收单接口
  1795. /// </summary>
  1796. /// <param name="TransType"></param>
  1797. /// <param name="Identification"></param>
  1798. /// <param name="cmd"></param>
  1799. public static void CreateOtherInDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1800. {
  1801. try
  1802. {
  1803. #region ERP开立状态单据审核
  1804. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1805. INTO #NewTempERP
  1806. from ICSWareHouseLotInfoLog
  1807. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='25'
  1808. SELECT a.ToWarehouseCode+b.InCode+a.MUSER AS Costre,a.ToWarehouseCode AS WarehouseCode,b.InCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,b.InCode,a.InvCode) AS Sequence,
  1809. b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,
  1810. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1811. ,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,
  1812. 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
  1813. ,b.EATTRIBUTE7 as Project,b.EATTRIBUTE1 as Dep
  1814. INTO #TempERP
  1815. FROM #NewTempERP a
  1816. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1817. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1818. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1819. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1820. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1821. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1822. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock009' AND a.WorkPoint=conStock.WorkPoint
  1823. GROUP BY inv.AmountEnable,a.ToWarehouseCode,b.InCode,a.MUSER,a.InvCode,con.Enable,conStock.Enable,b.EATTRIBUTE4,b.EATTRIBUTE2
  1824. ,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, ''),
  1825. 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, ''),b.EATTRIBUTE7,b.EATTRIBUTE1
  1826. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,DocType,ClientCode,InCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1827. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Project,Dep FROM #TempERP
  1828. DROP TABLE #TempERP
  1829. DROP TABLE #NewTempERP";
  1830. sql = string.Format(sql, Identification, BusinessCode);
  1831. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1832. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1833. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherInDocURL, Inputstr);
  1834. //sql = string.Format(sql, Identification);
  1835. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1836. //string Inputstr = JsonConvert.SerializeObject(dt);
  1837. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherInDocURL, Inputstr);
  1838. Result result = new Result();
  1839. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1840. if (result.Success)
  1841. {
  1842. try
  1843. {
  1844. //foreach (DataRow dr in dt.Rows)
  1845. //{
  1846. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1847. //}
  1848. }
  1849. catch (Exception ex)
  1850. {
  1851. log.Debug(ex.ToString());
  1852. log.Debug(resultStr);
  1853. }
  1854. }
  1855. else
  1856. {
  1857. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1858. }
  1859. #endregion
  1860. }
  1861. catch (Exception)
  1862. {
  1863. throw;
  1864. }
  1865. }
  1866. #endregion
  1867. #region 拆卸单
  1868. /// <summary>
  1869. /// 拆卸单
  1870. /// </summary>
  1871. /// <param name="TransCode"></param>
  1872. /// <param name="TransSequence"></param>
  1873. /// <param name="Quantity"></param>
  1874. /// <param name="WorkPoint"></param>
  1875. /// <param name="cmd"></param>
  1876. public static void DisassemblyDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1877. {
  1878. try
  1879. {
  1880. log.Debug("拆卸111");
  1881. string sql = @"DECLARE @Status VARCHAR(10)
  1882. SELECT @Status=c.Status FROM ICSInventoryLot a
  1883. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1884. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1885. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DABDOCType='2'
  1886. IF (@Status IS NULL)
  1887. BEGIN
  1888. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1889. RETURN
  1890. END
  1891. ELSE IF (@Status!='1')
  1892. BEGIN
  1893. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1894. RETURN
  1895. END
  1896. UPDATE c SET DABDOCQuantity=ISNULL(DABDOCQuantity,0)+'{2}'
  1897. FROM ICSInventoryLot a
  1898. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1899. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1900. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1901. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1902. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1903. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1904. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1905. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn024', c.Quantity,1,4,'')<c.DABDOCQuantity)
  1906. BEGIN
  1907. RAISERROR('" + language.GetNameByCode("WMSAPIInfo156") + @"',16,1);
  1908. END";
  1909. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1910. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1911. {
  1912. throw new Exception(language.GetNameByCode("WMSAPIInfo157"));//"拆卸单更新失败!");
  1913. }
  1914. log.Debug("拆卸222");
  1915. }
  1916. catch (Exception)
  1917. {
  1918. throw;
  1919. }
  1920. }
  1921. /// <summary>
  1922. /// 拆卸单更新套件锁定数量
  1923. /// </summary>
  1924. /// <param name="Identification"></param>
  1925. /// <param name="cmd"></param>
  1926. public static void DisassemblyDoc(string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1927. {
  1928. try
  1929. {
  1930. log.Debug("拆卸单sql前");
  1931. string sql = @"UPDATE ICSDisassemblyDoc SET DABDOCQuantity=Quantity
  1932. WHERE DABDOCCode+Sequence+WorkPoint IN(SELECT DISTINCT d.TransCode+d.TransSequence+d.WorkPoint
  1933. FROM ICSWareHouseLotInfoLog a
  1934. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1935. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1936. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  1937. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')
  1938. UPDATE ICSWareHouseLotInfo SET Quantity=Quantity-LockQuantity,LockQuantity=0
  1939. WHERE LotNo+WorkPoint IN(SELECT DISTINCT d.LotNo+d.WorkPoint
  1940. FROM ICSWareHouseLotInfoLog a
  1941. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1942. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1943. INNER JOIN ICSWareHouseLotInfoLog d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  1944. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')";
  1945. sql = string.Format(sql, Identification);
  1946. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1947. {
  1948. throw new Exception(language.GetNameByCode("WMSAPIInfo158"));//"拆卸单套件更新失败!");
  1949. }
  1950. log.Debug("拆卸单sql后");
  1951. }
  1952. catch (Exception)
  1953. {
  1954. throw;
  1955. }
  1956. }
  1957. /// <summary>
  1958. /// 拆卸单接口
  1959. /// </summary>
  1960. /// <param name="TransType"></param>
  1961. /// <param name="Identification"></param>
  1962. /// <param name="cmd"></param>
  1963. public static void DisassemblyDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1964. {
  1965. try
  1966. {
  1967. #region ERP开立状态单据审核
  1968. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1969. INTO #NewTempERP
  1970. from ICSWareHouseLotInfoLog
  1971. WHERE Identification='{0}' AND ERPUpload='0'
  1972. IF EXISTS(SELECT b.ID FROM ICSDisassemblyDoc b
  1973. WHERE b.DABDOCCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1974. AND b.Quantity!=b.DABDOCQuantity)
  1975. BEGIN
  1976. RAISERROR('" + language.GetNameByCode("WMSAPIInfo102") + @"',16,1);
  1977. RETURN
  1978. END
  1979. SELECT b.DABDOCID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1980. FROM #NewTempERP a
  1981. INNER JOIN ICSDisassemblyDoc b ON a.TransCode=b.DABDOCCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1982. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  1983. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  1984. GROUP BY b.DABDOCID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1985. DROP TABLE #NewTempERP";
  1986. sql = string.Format(sql, Identification);
  1987. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1988. string Inputstr = JsonConvert.SerializeObject(dt);
  1989. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DisassemblyDocURL, Inputstr);
  1990. Result result = new Result();
  1991. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1992. if (result.Success)
  1993. {
  1994. try
  1995. {
  1996. foreach (DataRow dr in dt.Rows)
  1997. {
  1998. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "","", cmd, language, BusinessCode);
  1999. }
  2000. }
  2001. catch (Exception ex)
  2002. {
  2003. log.Debug(ex.ToString());
  2004. log.Debug(resultStr);
  2005. }
  2006. }
  2007. else
  2008. {
  2009. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  2010. }
  2011. #endregion
  2012. }
  2013. catch (Exception)
  2014. {
  2015. throw;
  2016. }
  2017. }
  2018. #endregion
  2019. #region 借用
  2020. /// <summary>
  2021. /// 借用
  2022. /// </summary>
  2023. /// <param name="TransCode"></param>
  2024. /// <param name="TransSequence"></param>
  2025. /// <param name="Quantity"></param>
  2026. /// <param name="WorkPoint"></param>
  2027. /// <param name="cmd"></param>
  2028. public static void BrrowDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2029. {
  2030. try
  2031. {
  2032. string sql = @"DECLARE @Status VARCHAR(10)
  2033. SELECT @Status=a.Status FROM ICSBrrow a
  2034. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  2035. IF (@Status IS NULL)
  2036. BEGIN
  2037. RAISERROR('" + language.GetNameByCode("WMSAPIInfo159") + @"',16,1);
  2038. RETURN
  2039. END
  2040. ELSE IF (@Status!='2')
  2041. BEGIN
  2042. RAISERROR('" + language.GetNameByCode("WMSAPIInfo160") + @"',16,1);
  2043. RETURN
  2044. END
  2045. UPDATE a SET BrrowQuantity=ISNULL(BrrowQuantity,0)+'{2}'
  2046. FROM ICSBrrow a
  2047. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  2048. IF EXISTS(SELECT a.ID FROM ICSBrrow a
  2049. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.BrrowQuantity)
  2050. BEGIN
  2051. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  2052. RETURN
  2053. END";
  2054. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  2055. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2056. {
  2057. throw new Exception(language.GetNameByCode("WMSAPIInfo161"));//"借用单更新失败!");
  2058. }
  2059. }
  2060. catch (Exception)
  2061. {
  2062. throw;
  2063. }
  2064. }
  2065. /// <summary>
  2066. /// 借用接口
  2067. /// </summary>
  2068. /// <param name="TransType"></param>
  2069. /// <param name="Identification"></param>
  2070. /// <param name="cmd"></param>
  2071. public static void BrrowDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2072. {
  2073. try
  2074. {
  2075. #region ERP
  2076. string sql = string.Empty;
  2077. if (!DBHelper.IsBBU9())
  2078. {
  2079. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2080. INTO #NewTempERP
  2081. from ICSWareHouseLotInfoLog
  2082. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '26'
  2083. 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,
  2084. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.BrrowDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  2085. ,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,
  2086. 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
  2087. INTO #TempERP
  2088. FROM #NewTempERP a
  2089. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2090. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2091. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2092. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2093. INNER JOIN ICSBrrow b ON a.TransCode=b.BrrowCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2094. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2095. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock008' AND a.WorkPoint=conStock.WorkPoint
  2096. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2097. GROUP BY conWhCode.Enable,inv.AmountEnable,a.FromWarehouseCode,b.BrrowCode,a.MUSER,a.InvCode,b.BrrowDetailID,con.Enable,conStock.Enable
  2098. ,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, ''),
  2099. 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, '')
  2100. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,BrrowCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  2101. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,BrrowDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  2102. DROP TABLE #TempERP
  2103. DROP TABLE #NewTempERP";
  2104. sql = string.Format(sql, Identification);
  2105. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2106. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2107. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.BrrowDocURL, Inputstr);
  2108. Result result = new Result();
  2109. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2110. if (result.Success)
  2111. {
  2112. try
  2113. {
  2114. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2115. foreach (var item in res)
  2116. {
  2117. JObject jo = (JObject)item;
  2118. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2119. foreach (var detail in resdetail)
  2120. {
  2121. JObject det = (JObject)detail;
  2122. string allcol = jo["WHCode"].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()
  2123. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2124. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2125. det["DetailID"].ToString(), jo["OtherOutCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2126. }
  2127. }
  2128. }
  2129. catch (Exception ex)
  2130. {
  2131. log.Debug(ex.ToString());
  2132. log.Debug(resultStr);
  2133. }
  2134. }
  2135. else
  2136. {
  2137. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2138. }
  2139. }
  2140. else
  2141. {
  2142. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2143. INTO #NewTempERP
  2144. from ICSWareHouseLotInfoLog
  2145. WHERE Identification='{0}' AND ERPUpload='0'
  2146. IF EXISTS(SELECT b.ID FROM ICSBrrow b
  2147. WHERE b.BrrowCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  2148. AND b.Quantity!=ISNULL(b.BrrowQuantity,0))
  2149. BEGIN
  2150. RAISERROR('',16,1);
  2151. RETURN
  2152. END
  2153. SELECT b.BrrowCode AS DocNO,a.MUSER AS [User],SYSDATETIME() AS MTime,a.WorkPoint
  2154. FROM #NewTempERP a
  2155. INNER JOIN ICSBrrow b ON a.TransCode=b.BrrowCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2156. GROUP BY b.BrrowCode,a.MUSER,a.WorkPoint
  2157. DROP TABLE #NewTempERP";
  2158. sql = string.Format(sql, Identification);
  2159. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2160. string Inputstr = JsonConvert.SerializeObject(dt);
  2161. Inputstr = Inputstr.Replace("[", "");
  2162. Inputstr = Inputstr.Replace("]", "");
  2163. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.BrrowDocApproveURL, Inputstr);
  2164. Result result = new Result();
  2165. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2166. if (result.Success)
  2167. {
  2168. try
  2169. {
  2170. foreach (DataRow dr in dt.Rows)
  2171. {
  2172. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2173. }
  2174. }
  2175. catch (Exception ex)
  2176. {
  2177. log.Debug(ex.ToString());
  2178. log.Debug(resultStr);
  2179. }
  2180. }
  2181. else
  2182. {
  2183. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2184. }
  2185. }
  2186. #endregion
  2187. }
  2188. catch (Exception)
  2189. {
  2190. throw;
  2191. }
  2192. }
  2193. #endregion
  2194. #region 归还
  2195. /// <summary>
  2196. /// 归还
  2197. /// </summary>
  2198. /// <param name="TransCode"></param>
  2199. /// <param name="TransSequence"></param>
  2200. /// <param name="Quantity"></param>
  2201. /// <param name="WorkPoint"></param>
  2202. /// <param name="cmd"></param>
  2203. public static void ReturnDoc(string TransCode, string TransSequence, string LotNo,string LogID, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2204. {
  2205. try
  2206. {
  2207. string sql = string.Empty;
  2208. if (string.IsNullOrEmpty(LogID))
  2209. {
  2210. sql = @"DECLARE @Status VARCHAR(10)
  2211. SELECT @Status=c.Status FROM ICSInventoryLot a
  2212. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2213. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2214. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2215. IF (@Status IS NULL)
  2216. BEGIN
  2217. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2218. RETURN
  2219. END
  2220. ELSE IF (@Status!='2')
  2221. BEGIN
  2222. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  2223. RETURN
  2224. END
  2225. UPDATE c SET ReturnQuantity=ISNULL(ReturnQuantity,0)+'{2}'
  2226. FROM ICSInventoryLot a
  2227. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2228. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2229. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2230. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2231. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2232. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2233. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2234. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn023', c.Quantity,1,4,'')<c.ReturnQuantity)
  2235. BEGIN
  2236. RAISERROR('" + language.GetNameByCode("WMSAPIInfo162") + @"',16,1);
  2237. END";
  2238. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2239. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2240. {
  2241. throw new Exception(language.GetNameByCode("WMSAPIInfo163"));//"归还单更新失败!");
  2242. }
  2243. }
  2244. else
  2245. {
  2246. sql = @"DECLARE @Status VARCHAR(10)
  2247. SELECT @Status=a.Status FROM ICSReturn a
  2248. WHERE a.ReturnCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  2249. IF (@Status IS NULL)
  2250. BEGIN
  2251. RAISERROR('" + language.GetNameByCode("WMSAPIInfo151") + @"',16,1);
  2252. RETURN
  2253. END
  2254. ELSE IF (@Status!='2')
  2255. BEGIN
  2256. RAISERROR('" + language.GetNameByCode("WMSAPIInfo152") + @"',16,1);
  2257. RETURN
  2258. END
  2259. UPDATE a SET ReturnQuantity=ISNULL(ReturnQuantity,0)+'{2}'
  2260. FROM ICSReturn a
  2261. WHERE a.ReturnCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  2262. IF EXISTS(SELECT a.ID FROM ICSReturn a
  2263. WHERE a.ReturnCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.ReturnQuantity)
  2264. BEGIN
  2265. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  2266. RETURN
  2267. END";
  2268. sql = string.Format(sql, TransCode, WorkPoint, Quantity,TransSequence);
  2269. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2270. {
  2271. throw new Exception(language.GetNameByCode("WMSAPIInfo163"));//"归还单更新失败!");
  2272. }
  2273. }
  2274. }
  2275. catch (Exception)
  2276. {
  2277. throw;
  2278. }
  2279. }
  2280. /// <summary>
  2281. /// 归还接口
  2282. /// </summary>
  2283. /// <param name="TransType"></param>
  2284. /// <param name="Identification"></param>
  2285. /// <param name="cmd"></param>
  2286. public static void ReturnDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2287. {
  2288. try
  2289. {
  2290. #region ERP
  2291. string sql = string.Empty;
  2292. if (!DBHelper.IsBBU9())
  2293. {
  2294. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2295. INTO #NewTempERP
  2296. from ICSWareHouseLotInfoLog
  2297. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  2298. 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,
  2299. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,b.ReturnDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  2300. ,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,
  2301. 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
  2302. INTO #TempERP
  2303. FROM #NewTempERP a
  2304. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2305. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2306. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2307. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2308. INNER JOIN ICSReturn b ON a.TransCode=b.ReturnCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2309. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2310. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock009' AND a.WorkPoint=conStock.WorkPoint
  2311. GROUP BY inv.AmountEnable,a.ToWarehouseCode,b.ReturnCode,a.MUSER,a.InvCode,b.ReturnDetailID,con.Enable,conStock.Enable
  2312. ,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, ''),
  2313. 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, '')
  2314. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ReturnCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  2315. 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
  2316. DROP TABLE #TempERP
  2317. DROP TABLE #NewTempERP";
  2318. sql = string.Format(sql, Identification, BusinessCode);
  2319. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2320. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2321. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ReturnDocURL, Inputstr);
  2322. Result result = new Result();
  2323. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2324. if (result.Success)
  2325. {
  2326. try
  2327. {
  2328. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2329. foreach (var item in res)
  2330. {
  2331. JObject jo = (JObject)item;
  2332. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2333. foreach (var detail in resdetail)
  2334. {
  2335. JObject det = (JObject)detail;
  2336. string allcol = jo["WHCode"].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()
  2337. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2338. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2339. det["DetailID"].ToString(), jo["OtherInCode"].ToString(), det["Sequence"].ToString(), "", cmd, language, BusinessCode);
  2340. }
  2341. }
  2342. }
  2343. catch (Exception ex)
  2344. {
  2345. log.Debug(ex.ToString());
  2346. log.Debug(resultStr);
  2347. }
  2348. }
  2349. else
  2350. {
  2351. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2352. }
  2353. }
  2354. else
  2355. {
  2356. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2357. INTO #NewTempERP
  2358. from ICSWareHouseLotInfoLog
  2359. WHERE Identification='{0}' AND ERPUpload='0'
  2360. IF EXISTS(SELECT b.ID FROM ICSReturn b
  2361. WHERE b.ReturnCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  2362. AND b.Quantity!=ISNULL(b.ReturnQuantity,0))
  2363. BEGIN
  2364. RAISERROR('',16,1);
  2365. RETURN
  2366. END
  2367. SELECT b.ReturnCode AS DocNO,a.MUSER AS [User],SYSDATETIME() AS MTime,a.WorkPoint
  2368. FROM #NewTempERP a
  2369. INNER JOIN ICSReturn b ON a.TransCode=b.ReturnCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2370. GROUP BY b.ReturnCode,a.MUSER,a.WorkPoint
  2371. DROP TABLE #NewTempERP";
  2372. sql = string.Format(sql, Identification);
  2373. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2374. string Inputstr = JsonConvert.SerializeObject(dt);
  2375. Inputstr = Inputstr.Replace("[", "");
  2376. Inputstr = Inputstr.Replace("]", "");
  2377. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ReturnDocApproveURL, Inputstr);
  2378. Result result = new Result();
  2379. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2380. if (result.Success)
  2381. {
  2382. try
  2383. {
  2384. foreach (DataRow dr in dt.Rows)
  2385. {
  2386. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2387. }
  2388. }
  2389. catch (Exception ex)
  2390. {
  2391. log.Debug(ex.ToString());
  2392. log.Debug(resultStr);
  2393. }
  2394. }
  2395. else
  2396. {
  2397. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2398. }
  2399. }
  2400. #endregion
  2401. }
  2402. catch (Exception)
  2403. {
  2404. throw;
  2405. }
  2406. }
  2407. #endregion
  2408. #endregion
  2409. #region 工单关联
  2410. /// <summary>
  2411. /// 工单关联
  2412. /// </summary>
  2413. /// <param name="TransCode"></param>
  2414. /// <param name="TransSequence"></param>
  2415. /// <param name="Quantity"></param>
  2416. /// <param name="WorkPoint"></param>
  2417. /// <param name="cmd"></param>
  2418. public static void ICSMOReceive(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string SRMLotGroup,
  2419. string ProjectCode, string BatchCode, string Version, string Brand, string cFree1, string cFree2, string cFree3, string cFree4, string cFree5,
  2420. string cFree6, string cFree7, string cFree8, string cFree9, string cFree10, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  2421. {
  2422. try
  2423. {
  2424. decimal LOTQTY = 0;
  2425. decimal MOQTY = 0;
  2426. String EffectiveEnable = "";
  2427. String Colspan = "";
  2428. String IDD = "";
  2429. int EffectiveDays = 0;
  2430. String Time = "";
  2431. int EffectiveDayss = 0;
  2432. DateTime dtt;
  2433. DateTime now = DateTime.Now;
  2434. string sql = @"select * from ICSInventoryLotDetail
  2435. where LotNo='{0}' and WorkPoint='{1}'
  2436. ";
  2437. sql = string.Format(sql, LotNo, WorkPoint);
  2438. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  2439. if (dttte.Rows.Count > 0)
  2440. {
  2441. sql = @"IF NOT EXISTS(select * from ICSMO b
  2442. where b.MOCODE='{2}' and b.WorkPoint='{1}' and b.EATTRIBUTE1='1')
  2443. BEGIN
  2444. select * from ICSInventoryLotDetail a
  2445. left join ICSMO b ON a.transcode=b.mocode and a.WorkPoint=b.WorkPoint
  2446. where a.LotNo='{0}' and a.WorkPoint='{1}' and a.TransCode = ''
  2447. END
  2448. ELSE
  2449. BEGIN
  2450. select * from ICSInventoryLotDetail
  2451. where LotNo='{0}' and WorkPoint='{1}'
  2452. END";
  2453. sql = string.Format(sql, LotNo, WorkPoint, TransCode);
  2454. DataTable tt = DBHelper.SQlReturnData(sql, cmd);
  2455. if (tt.Rows.Count > 0)
  2456. {
  2457. ///修改条码关联表
  2458. sql = @"update ICSInventoryLotDetail set TransCode='{0}',TransSequence='{1}'
  2459. where lotno='{3}' and WorkPoint='{2}'
  2460. ";
  2461. sql = string.Format(sql, TransCode, TransSequence, WorkPoint, LotNo);
  2462. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2463. {
  2464. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  2465. }
  2466. ///修改条码表
  2467. sql = @"update ICSInventoryLot set InvCode=(select a.InvCode from ICSMO a where a.MOCode='{0}' and a.Sequence='{1}')
  2468. where lotno='{3}' and WorkPoint='{2}'
  2469. ";
  2470. sql = string.Format(sql, TransCode, TransSequence, WorkPoint, LotNo);
  2471. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2472. {
  2473. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  2474. }
  2475. }
  2476. else
  2477. {
  2478. throw new Exception(language.GetNameByCode("WMSAPIInfo374"));
  2479. }
  2480. }
  2481. else
  2482. {
  2483. sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
  2484. Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
  2485. where b.MoCode='{0}' and b.WorkPoint='{1}'";
  2486. sql = string.Format(sql, TransCode, WorkPoint);
  2487. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2488. if (dt.Rows.Count == 0)
  2489. {
  2490. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2491. }
  2492. else
  2493. {
  2494. EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
  2495. EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
  2496. }
  2497. //EffectiveDayss = Convert.ToInt32(EffectiveDays);
  2498. if (!EffectiveEnable.Equals("False"))
  2499. {
  2500. Time = DBHelper.ReTime(now, EffectiveDays);
  2501. }
  2502. else
  2503. {
  2504. Time = "2999-12-31 00:00:00.000";
  2505. }
  2506. dtt = Convert.ToDateTime(Time);
  2507. sql = @"DECLARE @aa VARCHAR(10)
  2508. DECLARE @bb VARCHAR(10)
  2509. SELECT @aa=a.EATTRIBUTE1 FROM ICSMO a
  2510. WHERE a.MOCode='{0}' and a.WorkPoint='{1}'
  2511. print @aa
  2512. IF(@aa='1')
  2513. BEGIN
  2514. select Count(c.lotno) AS LOTQTY,a.Quantity+ISNULL((select SUM(b.Quantity) from ICSMO a
  2515. left join ICSMOPick b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  2516. where a.MOCode='{0}' and a.EATTRIBUTE1='1' and b.EATTRIBUTE1='1' and a.WorkPoint='{1}'),0) AS MOQTY
  2517. from ICSMO a
  2518. left join ICSInventoryLotDetail bb on a.MOCode=bb.TransCode and a.WorkPoint=bb.WorkPoint
  2519. left join ICSInventoryLot c on bb.LotNo=c.LotNo and c.WorkPoint=bb.WorkPoint
  2520. where a.MOCode='{0}' and a.WorkPoint='{1}'
  2521. group by a.Quantity
  2522. END
  2523. ELSE
  2524. BEGIN
  2525. select Count(bb.lotno) AS LOTQTY,a.Quantity AS MOQTY
  2526. from ICSMO a
  2527. left join ICSInventoryLotDetail bb on a.MOCode=bb.TransCode and a.Sequence=bb.transSequence and a.WorkPoint=bb.WorkPoint
  2528. left join ICSInventoryLot c on bb.LotNo=c.LotNo and c.WorkPoint=bb.WorkPoint
  2529. where a.MOCode='{0}' and a.WorkPoint='{1}'
  2530. group by a.Quantity
  2531. END
  2532. ";
  2533. sql = string.Format(sql, TransCode, WorkPoint);
  2534. DataTable dtttt = DBHelper.SQlReturnData(sql, cmd);
  2535. LOTQTY = Convert.ToDecimal(dtttt.Rows[0]["LOTQTY"]);
  2536. MOQTY = Convert.ToDecimal(dtttt.Rows[0]["MOQTY"]);
  2537. sql = @"select * from ICSInventoryLot
  2538. where LotNo='{0}' and WorkPoint='{1}'
  2539. ";
  2540. sql = string.Format(sql, LotNo, WorkPoint);
  2541. DataTable dttaa = DBHelper.SQlReturnData(sql, cmd);
  2542. if (LOTQTY < MOQTY)
  2543. {
  2544. //检验自由项
  2545. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  2546. + "~" + Brand + "~" + cFree1
  2547. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  2548. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  2549. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  2550. sql = @"select ID,Colspan from ICSExtension a
  2551. where Colspan='{0}' and WorkPoint='{1}'";
  2552. sql = string.Format(sql, Colspan, WorkPoint);
  2553. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  2554. if (dttt.Rows.Count == 0)
  2555. {
  2556. IDD = Guid.NewGuid().ToString();
  2557. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  2558. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  2559. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  2560. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2561. {
  2562. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2563. }
  2564. }
  2565. else
  2566. {
  2567. IDD = dttt.Rows[0]["ID"].ToString();
  2568. }
  2569. if (dttaa.Rows.Count == 0)
  2570. {
  2571. //存入条码表
  2572. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  2573. BEGIN
  2574. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2575. RETURN
  2576. END
  2577. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  2578. Quantity,Amount,ExtensionID,Type,PrintTimes,
  2579. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  2580. WorkPoint,EATTRIBUTE1)
  2581. SELECT TOP 1 NEWID(),'{0}',a.InvCode,GETDATE(),'{6}',
  2582. 1,'0','{7}','90',null,
  2583. null,null,'{2}' ,f.F_RealName ,GETDATE(),
  2584. '{4}' ,''
  2585. FROM ICSMO a
  2586. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2587. INNER JOIN ICSExtension b ON a.ExtensionID=b.ID AND a.WorkPoint=b.WorkPoint
  2588. INNER JOIN ICSInventory c ON a.InvCode=c.InvCode AND a.WorkPoint=c.WorkPoint
  2589. where a.MOCode='{3}' and a.Sequence='{5}' and a.WorkPoint='{4}'
  2590. ";
  2591. sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD);
  2592. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2593. {
  2594. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2595. }
  2596. }
  2597. ///存入条码关联表
  2598. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
  2599. BEGIN
  2600. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2601. RETURN
  2602. END
  2603. INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
  2604. WorkPoint,EATTRIBUTE1)
  2605. SELECT a.LotNo,'{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
  2606. a.WorkPoint,''
  2607. FROM ICSInventoryLot a
  2608. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  2609. WHERE a.LotNo='{4}' AND a.WorkPoint='{3}'
  2610. ";
  2611. sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo);
  2612. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2613. {
  2614. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  2615. }
  2616. }
  2617. else
  2618. {
  2619. throw new Exception(language.GetNameByCode("WMSAPIInfo373"));//條碼綁定工單失敗!數量已滿!
  2620. }
  2621. }
  2622. }
  2623. catch (Exception)
  2624. {
  2625. throw;
  2626. }
  2627. }
  2628. public static void ICSMOReceiveUntie(string LotNo, string WorkPoint, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  2629. {
  2630. try
  2631. {
  2632. DateTime now = DateTime.Now;
  2633. string sql = @"select * from ICSInventoryLotDetail
  2634. where LotNo='{0}' and WorkPoint='{1}'
  2635. ";
  2636. sql = string.Format(sql, LotNo, WorkPoint);
  2637. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  2638. if (dttte.Rows.Count > 0)
  2639. {
  2640. ///删除条码关联表数据
  2641. sql = @"DELETE FROM [dbo].[ICSInventoryLotDetail] WHERE LotNo='{0}' AND WorkPoint='{1}'
  2642. ";
  2643. sql = string.Format(sql, LotNo, WorkPoint);
  2644. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2645. {
  2646. throw new Exception(language.GetNameByCode("WMSAPIInfo464"));
  2647. }
  2648. sql = @"DELETE FROM [dbo].[ICSInventoryLot] WHERE LotNo = '{0}' AND WorkPoint = '{1}'
  2649. ";
  2650. sql = string.Format(sql, LotNo, WorkPoint);
  2651. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2652. {
  2653. throw new Exception(language.GetNameByCode("WMSAPIInfo464"));
  2654. }
  2655. }
  2656. else
  2657. {
  2658. throw new Exception(language.GetNameByCode("WMSAPIInfo465"));
  2659. }
  2660. }
  2661. catch (Exception)
  2662. {
  2663. throw;
  2664. }
  2665. }
  2666. #endregion
  2667. #region 容器条码绑定
  2668. public static bool ICSContainerLot(string LotNo, string containerCode, string WorkPoint, string Identification, string User,
  2669. string ProjectCode, string BatchCode, string Version, string Brand, string cFree1, string cFree2, string cFree3, string cFree4, string cFree5,
  2670. string cFree6, string cFree7, string cFree8, string cFree9, string cFree10, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  2671. {
  2672. try
  2673. {
  2674. bool flag = false;
  2675. string Colspan = "";
  2676. string IDD = "";
  2677. string Time = "";
  2678. DateTime dtt;
  2679. DateTime now = DateTime.Now;
  2680. string sql = @"select * FROM ICSContainerLot WHERE LotNo='{0}' AND WorkPoint='{1}'
  2681. ";
  2682. sql = string.Format(sql, LotNo, WorkPoint);
  2683. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  2684. if (dttte.Rows.Count > 0)
  2685. {
  2686. ///修改容器关联表
  2687. sql = @"UPDATE ICSContainerLot SET ContainerID=(SELECT ID FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}' )
  2688. where lotno='{2}' and WorkPoint='{1}'
  2689. ";
  2690. sql = string.Format(sql, containerCode, WorkPoint, LotNo);
  2691. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2692. {
  2693. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo525"), containerCode, LotNo));
  2694. }
  2695. flag = true;
  2696. }
  2697. else
  2698. {
  2699. sql = @"select 1 from ICSInventoryLot
  2700. where LotNo='{0}' and WorkPoint='{1}'
  2701. ";
  2702. sql = string.Format(sql, LotNo, WorkPoint);
  2703. DataTable dttaa = DBHelper.SQlReturnData(sql, cmd);
  2704. if (dttaa.Rows.Count > 0)
  2705. {
  2706. //检验自由项
  2707. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  2708. + "~" + Brand + "~" + cFree1
  2709. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  2710. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  2711. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  2712. sql = @"select ID,Colspan from ICSExtension a
  2713. where Colspan='{0}' and WorkPoint='{1}'";
  2714. sql = string.Format(sql, Colspan, WorkPoint);
  2715. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  2716. if (dttt.Rows.Count == 0)
  2717. {
  2718. IDD = Guid.NewGuid().ToString();
  2719. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  2720. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  2721. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  2722. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2723. {
  2724. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  2725. }
  2726. }
  2727. else
  2728. {
  2729. IDD = dttt.Rows[0]["ID"].ToString();
  2730. }
  2731. Time = "2999-12-31 00:00:00.000";
  2732. dtt = Convert.ToDateTime(Time);
  2733. ///存入容器关联表
  2734. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  2735. BEGIN
  2736. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  2737. RETURN
  2738. END
  2739. INSERT INTO ICSContainerLot(ID,ContainerID,LotNo,MUSER,MUSERName,WorkPoint,MTIME)
  2740. SELECT NEWID(),a.ID,'{3}','{1}',f.F_RealName,'{2}',GETDATE()
  2741. FROM ICSContainer a
  2742. INNER JOIN Sys_SRM_User f ON f.F_Account='{1}' AND a.WorkPoint=f.F_Location
  2743. WHERE a.ContainerCode='{0}' AND WorkPoint='{2}'
  2744. ";
  2745. sql = string.Format(sql, containerCode, User, WorkPoint, LotNo);
  2746. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2747. {
  2748. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo525"), containerCode, LotNo));
  2749. }
  2750. ///记录日志
  2751. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  2752. VALUES(NEWID(), (SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}'), '{1}', 2, '{2}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}'), '{3}', GETDATE())";
  2753. sql = string.Format(sql, containerCode, LotNo, User, WorkPoint);
  2754. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2755. {
  2756. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo526"), containerCode, LotNo));
  2757. }
  2758. flag = true;
  2759. }
  2760. }
  2761. return flag;
  2762. }
  2763. catch (Exception ex)
  2764. {
  2765. log.Error(ex.Message);
  2766. //return false;
  2767. throw;
  2768. }
  2769. }
  2770. /// <summary>
  2771. /// 容器条码解绑
  2772. /// </summary>
  2773. /// <param name="LotNo"></param>
  2774. /// <param name="WorkPoint"></param>
  2775. /// <param name="User"></param>
  2776. /// <param name="cmd"></param>
  2777. /// <param name="language"></param>
  2778. public static bool ICSContainerLotUntie(string ContainerCode, string LotNo, string WorkPoint, string User, string Type, SqlCommand cmd, Dictionary<string, string> language)
  2779. {
  2780. try
  2781. {
  2782. DateTime now = DateTime.Now;
  2783. string sql = @"select 1 from ICSContainerLot
  2784. where ContainerID=(SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{2}') AND LotNo='{0}' and WorkPoint='{1}'
  2785. ";
  2786. sql = string.Format(sql, LotNo, WorkPoint, ContainerCode);
  2787. log.Debug("查询容器条码关联表是否存在sql:" + sql);
  2788. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  2789. if (dttte.Rows.Count > 0)
  2790. {
  2791. ///删除条码关联表数据
  2792. sql = @"DELETE FROM ICSContainerLot
  2793. where ContainerID=(SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{2}') AND LotNo='{0}' and WorkPoint='{1}'
  2794. ";
  2795. sql = string.Format(sql, LotNo, WorkPoint, ContainerCode);
  2796. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2797. {
  2798. throw new Exception("容器条码关联表数据删除失败");
  2799. }
  2800. ///记录日志
  2801. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  2802. VALUES(NEWID(), (SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}'), '{1}', '{4}', '{2}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}'), '{3}', GETDATE())";
  2803. sql = string.Format(sql, ContainerCode, LotNo, User, WorkPoint, Type);
  2804. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2805. {
  2806. throw new Exception("条码解绑容器记录日志表失败");
  2807. }
  2808. return true;
  2809. }
  2810. else
  2811. {
  2812. throw new Exception(language.GetNameByCode("容器条码关联表不存在容器" + ContainerCode + "与条码" + LotNo + "的绑定关系"));
  2813. }
  2814. }
  2815. catch (Exception)
  2816. {
  2817. throw;
  2818. }
  2819. }
  2820. /// <summary>
  2821. /// 容器绑定父容器
  2822. /// </summary>
  2823. /// <param name="superiorContainerCode"></param>
  2824. /// <param name="containerCode"></param>
  2825. /// <param name="WorkPoint"></param>
  2826. /// <param name="User"></param>
  2827. /// <param name="Type"></param>
  2828. /// <param name="cmd"></param>
  2829. /// <param name="language"></param>
  2830. /// <returns></returns>
  2831. public static bool ICSContainerCon(string superiorContainerCode, string containerCode, string WorkPoint, string User, string MTIME, string Type, SqlCommand cmd, Dictionary<string, string> language)
  2832. {
  2833. try
  2834. {
  2835. Boolean flag = false;
  2836. DateTime now = DateTime.Now;
  2837. string superiorContainerID = "";
  2838. string sql = @"SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}'";
  2839. sql = string.Format(sql, superiorContainerCode, WorkPoint);
  2840. DataTable dataTable = DBHelper.SQlReturnData(sql, cmd);
  2841. if (dataTable.Rows.Count == 0)
  2842. {
  2843. throw new Exception("父容器不存在");
  2844. }
  2845. else
  2846. {
  2847. //绑定父容器
  2848. superiorContainerID = dataTable.Rows[0]["ID"].ToString();
  2849. sql = @"UPDATE ICSContainer SET ContainerID='{0}',MUSER='{1}',MUSERName=(SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}'),MTIME='{2}' WHERE ContainerCode='{3}' AND WorkPoint='{4}'";
  2850. sql = string.Format(sql, superiorContainerID, User, MTIME, containerCode, WorkPoint);
  2851. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2852. {
  2853. throw new Exception("绑定父容器失败");
  2854. }
  2855. //添加日志
  2856. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  2857. VALUES(NEWID(), (SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}'), '{1}', '{4}', '{2}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}'), '{3}', GETDATE())";
  2858. sql = string.Format(sql, superiorContainerCode, containerCode, User, WorkPoint, Type);
  2859. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2860. {
  2861. throw new Exception("日志记录失败");
  2862. }
  2863. flag = true;
  2864. }
  2865. return flag;
  2866. }
  2867. catch (Exception ex)
  2868. {
  2869. log.Error(ex.Message);
  2870. //return false;
  2871. throw;
  2872. }
  2873. }
  2874. /// <summary>
  2875. /// 容器解绑父容器
  2876. /// </summary>
  2877. /// <param name="ContainerCode"></param>
  2878. /// <param name="WorkPoint"></param>
  2879. /// <param name="User"></param>
  2880. /// <param name="Type"></param>
  2881. /// <param name="MTIME"></param>
  2882. /// <param name="cmd"></param>
  2883. /// <param name="language"></param>
  2884. /// <returns></returns>
  2885. public static bool ICSContainerConUntie(string ContainerCode, string WorkPoint, string User, string Type, SqlCommand cmd, Dictionary<string, string> language)
  2886. {
  2887. try
  2888. {
  2889. //添加日志
  2890. string sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  2891. VALUES(NEWID(), '', '{0}', '{3}', '{1}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}'), '{2}', GETDATE())";
  2892. sql = string.Format(sql, ContainerCode, User, WorkPoint, Type);
  2893. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2894. {
  2895. throw new Exception("日志记录失败");
  2896. }
  2897. //容器表父容器ID清空
  2898. sql = string.Format(@"UPDATE ICSContainer SET ContainerID='',MUSER='{2}',
  2899. MUSERName=(SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  2900. ,MTIME=GETDATE()
  2901. WHERE ContainerCode='{0}' AND WorkPoint='{1}'",
  2902. ContainerCode, WorkPoint, User);
  2903. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2904. {
  2905. throw new Exception("容器解绑父容器失败");
  2906. }
  2907. return true;
  2908. }
  2909. catch (Exception)
  2910. {
  2911. throw;
  2912. }
  2913. }
  2914. #endregion
  2915. #region 车次条码清单
  2916. public static bool ICSCartScheduleCreate(string LotNo ,string Quantity, string CartNo, string User, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2917. {
  2918. try
  2919. {
  2920. bool flag = false;
  2921. string sql = @"INSERT INTO dbo.ICSCartLotNoCheckList (id,CartNo,LotNo,MUSER,MUSERName,MTIME,WorkPoint,Quantity)
  2922. VALUES(NEWID(),'{0}','{1}','{2}','{2}',CONVERT(VARCHAR,GETDATE(),120),'{3}','{4}')";
  2923. sql = string.Format(sql, CartNo,LotNo,User,WorkPoint,"" == Quantity ? null : Quantity);
  2924. log.Debug("生成车次条码清单:" + sql);
  2925. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2926. {
  2927. throw new Exception("生成车次条码清单失败!");
  2928. }
  2929. flag = true;
  2930. return flag;
  2931. }
  2932. catch (Exception ex)
  2933. {
  2934. log.Error(ex.Message);
  2935. //return false;
  2936. throw;
  2937. }
  2938. }
  2939. #endregion
  2940. /// <summary>
  2941. /// 入库时解绑条码与容器
  2942. /// </summary>
  2943. /// <param name="ContainerCode"></param>
  2944. /// <param name="LotNo"></param>
  2945. /// <param name="WorkPoint"></param>
  2946. /// <param name="User"></param>
  2947. /// <param name="Type"></param>
  2948. /// <param name="cmd"></param>
  2949. /// <param name="language"></param>
  2950. /// <returns></returns>
  2951. public static bool ICSContainerLotUntieWhenIn(string ContainerCode, string LotNo, string WorkPoint, string User, string Type, SqlCommand cmd, Dictionary<string, string> language)
  2952. {
  2953. try
  2954. {
  2955. DateTime now = DateTime.Now;
  2956. string sql = @"select 1 from ICSContainerLot
  2957. where ContainerID=(SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{2}') AND LotNo='{0}' and WorkPoint='{1}'
  2958. ";
  2959. sql = string.Format(sql, LotNo, WorkPoint, ContainerCode);
  2960. log.Debug("查询容器条码关联表是否存在sql:" + sql);
  2961. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  2962. if (dttte.Rows.Count > 0)
  2963. {
  2964. ///删除条码关联表数据
  2965. sql = @"DELETE FROM ICSContainerLot
  2966. where ContainerID=(SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{2}') AND LotNo='{0}' and WorkPoint='{1}'
  2967. ";
  2968. sql = string.Format(sql, LotNo, WorkPoint, ContainerCode);
  2969. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2970. {
  2971. throw new Exception("容器条码关联表数据删除失败");
  2972. }
  2973. ///记录日志
  2974. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  2975. VALUES(NEWID(), (SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}'), '{1}', '{4}', '{2}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}'), '{3}', GETDATE())";
  2976. sql = string.Format(sql, ContainerCode, LotNo, User, WorkPoint, Type);
  2977. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2978. {
  2979. throw new Exception("条码解绑容器记录日志表失败");
  2980. }
  2981. return true;
  2982. }
  2983. else
  2984. {
  2985. log.Debug(language.GetNameByCode("容器条码关联表不存在容器" + ContainerCode + "与条码" + LotNo + "的绑定关系,或已解除绑定"));
  2986. return false;
  2987. }
  2988. }
  2989. catch (Exception)
  2990. {
  2991. throw;
  2992. }
  2993. }
  2994. /// <summary>
  2995. /// 入库时解绑父容器与容器
  2996. /// </summary>
  2997. /// <param name="ContainerCode"></param>
  2998. /// <param name="WorkPoint"></param>
  2999. /// <param name="User"></param>
  3000. /// <param name="Type"></param>
  3001. /// <param name="cmd"></param>
  3002. /// <param name="language"></param>
  3003. /// <returns></returns>
  3004. public static bool ICSContainerConUntieWhenIn(string ContainerCode, string WorkPoint, string User, string Type, SqlCommand cmd, Dictionary<string, string> language)
  3005. {
  3006. try
  3007. {
  3008. string sql = @"IF EXISTS(SELECT 1 FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{2}' AND ContainerID IS NOT NULL AND ContainerID<>'')
  3009. BEGIN
  3010. INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  3011. VALUES(NEWID(), '', '{0}', '{3}', '{1}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}'), '{2}', GETDATE())
  3012. UPDATE ICSContainer SET ContainerID='',MUSER='{1}',
  3013. MUSERName=(SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  3014. ,MTIME=GETDATE()
  3015. WHERE ContainerCode='{0}' AND WorkPoint='{2}'
  3016. END";
  3017. sql = string.Format(sql, ContainerCode, User, WorkPoint, Type);
  3018. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3019. {
  3020. log.Debug("容器 " + ContainerCode + " 无父容器关联关系或已解绑");
  3021. return false;
  3022. }
  3023. return true;
  3024. }
  3025. catch (Exception)
  3026. {
  3027. throw;
  3028. }
  3029. }
  3030. }
  3031. }