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.

4032 lines
242 KiB

3 weeks ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 库内作业模块
  18. /// </summary>
  19. public class ICSWareHouseService
  20. {
  21. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  22. #region 一步调拨
  23. /// <summary>
  24. /// 一步调拨
  25. /// </summary>
  26. /// <param name="TransCode"></param>
  27. /// <param name="TransSequence"></param>
  28. /// <param name="Quantity"></param>
  29. /// <param name="WorkPoint"></param>
  30. /// <param name="cmd"></param>
  31. public static void OneStepTransferDocIn(string TransCode, string TransSequence, string WorkPoint, string Quantity, 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="TransCode"></param>
  73. /// <param name="TransSequence"></param>
  74. /// <param name="Quantity"></param>
  75. /// <param name="WorkPoint"></param>
  76. /// <param name="cmd"></param>
  77. public static void JHOneStepTransferDocIn(string TransCode, string TransSequence, string WorkPoint, string Quantity, string IsPN, SqlCommand cmd, Dictionary<string, string> language)
  78. {
  79. try
  80. {
  81. string sql = string.Empty;
  82. sql = @"UPDATE ICSTransfer SET Quantity=TransferQuantity
  83. WHERE TransferNO='{0}' AND WorkPoint='{1}' AND Type='1'";
  84. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  85. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  86. {
  87. throw new Exception(language.GetNameByCode("WMSAPIInfo145"));//"调拨单信息更新失败!");
  88. }
  89. }
  90. catch (Exception)
  91. {
  92. throw;
  93. }
  94. }
  95. /// <summary>
  96. /// 无源头调拨接口
  97. /// </summary>
  98. /// <param name="TransType"></param>
  99. /// <param name="Identification"></param>
  100. /// <param name="cmd"></param>
  101. public static void OneStepNoTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string PalletCode)
  102. {
  103. try
  104. {
  105. #region 生成调拨单
  106. 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,
  107. 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
  108. ,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,
  109. 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
  110. INTO #TempERP
  111. FROM ICSWareHouseLotInfoLog a
  112. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  113. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  114. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  115. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  116. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  117. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  118. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  119. WHERE a.Identification='{0}' AND ERPUpload='0' and a.BusinessCode='70'
  120. GROUP BY lot.Amount,inv.AmountEnable,a.FromWarehouseCode,a.ToWarehouseCode,a.MUSER,a.InvCode,con.Enable,conStock.Enable
  121. ,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, ''),
  122. 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, '')
  123. 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
  124. SELECT Costre,Sequence,InvCode,Quantity,Amount,TAetailID,'{1}' AS PalletCode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,FromWHCode as OutWhCode,ToWHCode as INWhCode
  125. FROM #TempERP
  126. DROP TABLE #TempERP";
  127. sql = string.Format(sql, Identification, PalletCode);
  128. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  129. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  130. string resultStr = "";
  131. if (DBHelper.IsU9())
  132. {
  133. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OneStepNoTransferDocInURL, Inputstr);
  134. }
  135. else
  136. {
  137. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepNoTransferDocInURL, Inputstr);
  138. }
  139. Result result = new Result();
  140. result = JsonConvert.DeserializeObject<Result>(resultStr);
  141. if (result.Success)
  142. {
  143. try
  144. {
  145. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  146. foreach (var item in res)
  147. {
  148. JObject jo = (JObject)item;
  149. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  150. foreach (var detail in resdetail)
  151. {
  152. JObject det = (JObject)detail;
  153. 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()
  154. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  155. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, "", Identification, jo["ID"].ToString(),
  156. det["DetailID"].ToString(), jo["TransCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  157. }
  158. }
  159. //foreach (DataRow dr in ds.Tables)
  160. //{
  161. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, "", Identification, "", "", "", "", "", cmd, language);
  162. //}
  163. }
  164. catch (Exception ex)
  165. {
  166. log.Debug(sql);
  167. log.Debug(ex.ToString());
  168. log.Debug(resultStr);
  169. }
  170. }
  171. else
  172. {
  173. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  174. }
  175. #endregion
  176. }
  177. catch (Exception)
  178. {
  179. throw;
  180. }
  181. }
  182. /// <summary>
  183. /// 晶华无源头调拨接口
  184. /// </summary>
  185. /// <param name="TransType"></param>
  186. /// <param name="Identification"></param>
  187. /// <param name="cmd"></param>
  188. public static void JHOneStepNoTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string PalletCode)
  189. {
  190. try
  191. {
  192. #region 生成调拨单
  193. string sql = @"SELECT 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,
  194. ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,a.ToWarehouseCode,a.InvCode) AS Sequence,
  195. 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
  196. ,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,
  197. 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
  198. INTO #TempERP
  199. FROM ICSWareHouseLotInfoLog a
  200. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  201. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  202. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  203. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  204. --INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  205. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  206. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  207. WHERE a.Identification='{0}' AND ERPUpload='0' and a.BusinessCode='70-1'
  208. GROUP BY a.workpoint,a.MUSER,a.FromWarehouseCode,a.ToWarehouseCode,a.InvCode,con.Enable,conStock.Enable,inv.AmountEnable,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, ''),
  209. 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, '')
  210. SELECT DISTINCT Costre,WorkPoint,FromDepCode,ToDepCode,TACode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,'TransIn002'as DocType,SYSDATETIME() as DocDate FROM #TempERP
  211. SELECT Costre,Sequence,InvCode,Quantity,Amount,TAetailID,'' AS PalletCode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,FromWHCode as OutWhCode,ToWHCode as INWhCode
  212. FROM #TempERP
  213. DROP TABLE #TempERP";
  214. sql = string.Format(sql, Identification, PalletCode);
  215. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  216. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  217. string resultStr = "";
  218. if (DBHelper.IsU9())
  219. {
  220. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OneStepNoTransferDocInURL, Inputstr);
  221. }
  222. else
  223. {
  224. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.JHOneStepNoTransferDocInURL, Inputstr);
  225. }
  226. Result result = new Result();
  227. result = JsonConvert.DeserializeObject<Result>(resultStr);
  228. if (result.Success)
  229. {
  230. try
  231. {
  232. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  233. string updatesql = @"UPDATE ICSWareHouseLotInfoLog set TransCode='{0}'
  234. where Identification='{1}'";
  235. updatesql = string.Format(updatesql, res[0]["TransCode"].ToString(), Identification);
  236. DBHelper.ExecuteNonQuery(updatesql, cmd);
  237. foreach (var item in res)
  238. {
  239. JObject jo = (JObject)item;
  240. //JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  241. //foreach (var detail in resdetail)
  242. //{
  243. // JObject det = (JObject)detail;
  244. // 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()
  245. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  246. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, "", Identification, jo["ID"].ToString(),
  247. // det["DetailID"].ToString(), jo["TransCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  248. //}
  249. }
  250. //foreach (DataRow dr in ds.Tables)
  251. //{
  252. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, "", Identification, "", "", "", "", "", cmd, language);
  253. //}
  254. }
  255. catch (Exception ex)
  256. {
  257. log.Debug(sql);
  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. #endregion
  267. }
  268. catch (Exception)
  269. {
  270. throw;
  271. }
  272. }
  273. #region 一步调拨(调拨申请单)
  274. /// <summary>
  275. /// 一步调拨(调拨申请单)
  276. /// </summary>
  277. /// <param name="TransCode"></param>
  278. /// <param name="TransSequence"></param>
  279. /// <param name="Quantity"></param>
  280. /// <param name="WorkPoint"></param>
  281. /// <param name="cmd"></param>
  282. public static void OneStepTransferApplicationIn(string TransCode, string TransSequence, string WorkPoint, string Quantity, SqlCommand cmd, Dictionary<string, string> language)
  283. {
  284. try
  285. {
  286. string sql = "";
  287. if (DBHelper.IsPNU9())
  288. {
  289. sql = @"UPDATE ICSTransferApplication SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
  290. WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'";
  291. }
  292. else
  293. {
  294. sql = @"UPDATE ICSTransferApplication SET TransferQuantity=ISNULL(TransferQuantity,0)+'{2}'
  295. WHERE TransferNO='{0}' AND Sequence='{3}' AND WorkPoint='{1}' AND Type='1'
  296. IF EXISTS(SELECT a.ID FROM ICSTransferApplication a
  297. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='1' AND a.TransferQuantity<a.TransferQuantity)
  298. BEGIN
  299. RAISERROR('" + language.GetNameByCode("WMSAPIInfo144") + @"',16,1);
  300. RETURN
  301. END";
  302. }
  303. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  304. log.Debug(sql);
  305. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  306. {
  307. throw new Exception(language.GetNameByCode("WMSAPIInfo145"));//"调拨单信息更新失败!");
  308. }
  309. }
  310. catch (Exception)
  311. {
  312. throw;
  313. }
  314. }
  315. /// <summary>
  316. /// 一步调拨接口
  317. /// </summary>
  318. /// <param name="TransType"></param>
  319. /// <param name="Identification"></param>
  320. /// <param name="cmd"></param>
  321. public static void OneStepTransferDocInERP(string TransType, string Identification, string isPN, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode, string UserCode)
  322. {
  323. string Inputstr2 = "";
  324. string resultStr = "";
  325. Result result = new Result();
  326. try
  327. {
  328. #region ERP开立状态单据审核
  329. string sql = "";
  330. //检验调拨单是否一次性发完
  331. if (isPN == "1")
  332. {
  333. sql = @"
  334. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  335. FROM ICSWareHouseLotInfoLog a
  336. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  337. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  338. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  339. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='3' and a.EATTRIBUTE1<>'1'
  340. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  341. 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
  342. where a.Identification='{0}' GROUP BY a.transCode";
  343. checksql = string.Format(checksql, Identification);
  344. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  345. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  346. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  347. string trancode = chekdt.Rows[0]["transCode"].ToString();
  348. if (SUMQty - ISSQty == 0)
  349. {
  350. string pnsql = @"SELECT DISTINCT b.TransferID AS ID,'{1}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  351. FROM ICSWareHouseLotInfoLog a
  352. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  353. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  354. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  355. WHERE a.TransCode='{0}' AND ERPUpload='0' AND b.Type='3' and a.EATTRIBUTE1<>'1'
  356. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  357. ";
  358. pnsql = string.Format(pnsql, trancode, UserCode);
  359. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  360. string Inputstr = JsonConvert.SerializeObject(dt);
  361. if (isPN == "1")
  362. {//派纳调拨
  363. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNOneStepTransferDocInURL, Inputstr);
  364. //Result result = new Result();
  365. result = JsonConvert.DeserializeObject<Result>(resultStr);
  366. if (result.Success)
  367. {
  368. try
  369. {
  370. foreach (DataRow dr in dt.Rows)
  371. {
  372. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  373. }
  374. }
  375. catch (Exception ex)
  376. {
  377. log.Debug(ex.ToString());
  378. log.Debug(resultStr);
  379. }
  380. }
  381. else
  382. {
  383. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  384. }
  385. }
  386. else
  387. {
  388. sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  389. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  390. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  391. BEGIN
  392. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  393. RETURN
  394. END
  395. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  396. FROM ICSWareHouseLotInfoLog a
  397. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  398. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  399. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  400. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  401. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  402. sql = string.Format(sql, Identification);
  403. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  404. string Inputstrr = JsonConvert.SerializeObject(dtt);
  405. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstrr);
  406. Result resultt = new Result();
  407. resultt = JsonConvert.DeserializeObject<Result>(resultStr);
  408. if (resultt.Success)
  409. {
  410. try
  411. {
  412. foreach (DataRow dr in dt.Rows)
  413. {
  414. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  415. }
  416. }
  417. catch (Exception ex)
  418. {
  419. log.Debug(ex.ToString());
  420. log.Debug(resultStr);
  421. }
  422. }
  423. else
  424. {
  425. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + resultt.Message);
  426. }
  427. }
  428. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  429. }
  430. }
  431. else
  432. {
  433. if (DBHelper.IsPNU9())
  434. {
  435. sql = @"
  436. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  437. FROM ICSWareHouseLotInfoLog a
  438. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  439. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  440. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  441. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' and a.EATTRIBUTE1<>'1'
  442. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  443. 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
  444. where a.Identification='{0}' GROUP BY a.transCode";
  445. checksql = string.Format(checksql, Identification);
  446. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  447. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  448. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  449. string trancode = chekdt.Rows[0]["transCode"].ToString();
  450. if (SUMQty - ISSQty == 0)
  451. {
  452. string pnsql = @"SELECT DISTINCT b.TransferID AS ID,'{1}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  453. FROM ICSWareHouseLotInfoLog a
  454. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  455. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  456. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  457. WHERE a.TransCode='{0}' AND ERPUpload='0' AND b.Type='1' and a.EATTRIBUTE1<>'1'
  458. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  459. ";
  460. pnsql = string.Format(pnsql, trancode, UserCode);
  461. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  462. string Inputstr = JsonConvert.SerializeObject(dt);
  463. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  464. //Result result = new Result();
  465. result = JsonConvert.DeserializeObject<Result>(resultStr);
  466. if (result.Success)
  467. {
  468. try
  469. {
  470. foreach (DataRow dr in dt.Rows)
  471. {
  472. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  473. }
  474. }
  475. catch (Exception ex)
  476. {
  477. log.Debug(ex.ToString());
  478. log.Debug(resultStr);
  479. }
  480. }
  481. else
  482. {
  483. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  484. }
  485. }
  486. }
  487. else
  488. {
  489. sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  490. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  491. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  492. BEGIN
  493. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  494. RETURN
  495. END
  496. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  497. FROM ICSWareHouseLotInfoLog a
  498. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  499. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  500. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  501. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  502. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  503. sql = string.Format(sql, Identification);
  504. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  505. string Inputstr = JsonConvert.SerializeObject(dt);
  506. Inputstr2 = Inputstr;
  507. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  508. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  509. //Result result = new Result();
  510. result = JsonConvert.DeserializeObject<Result>(resultStr);
  511. if (result.Success)
  512. {
  513. try
  514. {
  515. foreach (DataRow dr in dt.Rows)
  516. {
  517. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  518. }
  519. }
  520. catch (Exception ex)
  521. {
  522. log.Debug(ex.ToString());
  523. log.Debug(resultStr);
  524. }
  525. }
  526. else
  527. {
  528. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  529. }
  530. }
  531. }
  532. #endregion
  533. }
  534. catch (Exception)
  535. {
  536. //DataTable WHtable = ICSControlModeService.GetJHWHCode();
  537. //if (WHtable == null)
  538. //{
  539. throw;
  540. //}
  541. //else
  542. //{
  543. // ICSControlModeService.InsertErrLog(ERPUrl.OneStepTransferDocInURL, Inputstr2, result.Message, JArray.Parse(Inputstr2)[0]["User"]?.ToString(), JArray.Parse(Inputstr2)[0]["WorkPoint"]?.ToString(), cmd);
  544. // // ICSControlModeService.InsertErrLog(ERPUrl.OneStepTransferDocInURL, Inputstr2, result.Message, JObject.Parse(Inputstr2)["UserCode"]?.ToString(), JObject.Parse(Inputstr2)["OrgCode"]?.ToString(), cmd);
  545. //}
  546. }
  547. }
  548. public static void JHOneStepTransferDocInERP(string TransType, string Identification, string isPN, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode, string UserCode)
  549. {
  550. try
  551. {
  552. #region ERP开立状态单据审核
  553. string resultStr = "";
  554. string sql = "";
  555. //检验调拨单是否一次性发完
  556. if (isPN == "1")
  557. {
  558. sql = @"
  559. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  560. FROM ICSWareHouseLotInfoLog a
  561. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  562. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  563. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  564. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='3' and a.EATTRIBUTE1<>'1'
  565. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  566. 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
  567. where a.Identification='{0}' GROUP BY a.transCode";
  568. checksql = string.Format(checksql, Identification);
  569. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  570. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  571. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  572. string trancode = chekdt.Rows[0]["transCode"].ToString();
  573. if (SUMQty - ISSQty == 0)
  574. {
  575. string pnsql = @"SELECT DISTINCT b.TransferID AS ID,'{1}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  576. FROM ICSWareHouseLotInfoLog a
  577. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  578. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  579. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  580. WHERE a.TransCode='{0}' AND ERPUpload='0' AND b.Type='3' and a.EATTRIBUTE1<>'1'
  581. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  582. ";
  583. pnsql = string.Format(pnsql, trancode, UserCode);
  584. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  585. string Inputstr = JsonConvert.SerializeObject(dt);
  586. if (isPN == "1")
  587. {//派纳调拨
  588. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNOneStepTransferDocInURL, Inputstr);
  589. Result result = new Result();
  590. result = JsonConvert.DeserializeObject<Result>(resultStr);
  591. if (result.Success)
  592. {
  593. try
  594. {
  595. foreach (DataRow dr in dt.Rows)
  596. {
  597. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  598. }
  599. }
  600. catch (Exception ex)
  601. {
  602. log.Debug(ex.ToString());
  603. log.Debug(resultStr);
  604. }
  605. }
  606. else
  607. {
  608. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  609. }
  610. }
  611. else
  612. {
  613. sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  614. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  615. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  616. BEGIN
  617. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  618. RETURN
  619. END
  620. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  621. FROM ICSWareHouseLotInfoLog a
  622. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  623. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  624. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  625. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  626. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  627. sql = string.Format(sql, Identification);
  628. DataTable dtt = DBHelper.SQlReturnData(sql, cmd);
  629. string Inputstrr = JsonConvert.SerializeObject(dtt);
  630. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstrr);
  631. Result resultt = new Result();
  632. resultt = JsonConvert.DeserializeObject<Result>(resultStr);
  633. if (resultt.Success)
  634. {
  635. try
  636. {
  637. foreach (DataRow dr in dt.Rows)
  638. {
  639. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  640. }
  641. }
  642. catch (Exception ex)
  643. {
  644. log.Debug(ex.ToString());
  645. log.Debug(resultStr);
  646. }
  647. }
  648. else
  649. {
  650. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + resultt.Message);
  651. }
  652. }
  653. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  654. }
  655. }
  656. else
  657. {
  658. if (DBHelper.IsPNU9())
  659. {
  660. sql = @"
  661. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  662. FROM ICSWareHouseLotInfoLog a
  663. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  664. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  665. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  666. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1' and a.EATTRIBUTE1<>'1'
  667. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  668. 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
  669. where a.Identification='{0}' GROUP BY a.transCode";
  670. checksql = string.Format(checksql, Identification);
  671. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  672. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  673. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  674. string trancode = chekdt.Rows[0]["transCode"].ToString();
  675. if (SUMQty - ISSQty == 0)
  676. {
  677. string pnsql = @"SELECT DISTINCT b.TransferID AS ID,'{1}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  678. FROM ICSWareHouseLotInfoLog a
  679. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  680. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  681. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  682. WHERE a.TransCode='{0}' AND ERPUpload='0' AND b.Type='1' and a.EATTRIBUTE1<>'1'
  683. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  684. ";
  685. pnsql = string.Format(pnsql, trancode, UserCode);
  686. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  687. string Inputstr = JsonConvert.SerializeObject(dt);
  688. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  689. Result result = new Result();
  690. result = JsonConvert.DeserializeObject<Result>(resultStr);
  691. if (result.Success)
  692. {
  693. try
  694. {
  695. foreach (DataRow dr in dt.Rows)
  696. {
  697. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  698. }
  699. }
  700. catch (Exception ex)
  701. {
  702. log.Debug(ex.ToString());
  703. log.Debug(resultStr);
  704. }
  705. }
  706. else
  707. {
  708. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  709. }
  710. }
  711. }
  712. else
  713. {
  714. sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  715. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  716. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  717. BEGIN
  718. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  719. RETURN
  720. END
  721. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  722. FROM ICSWareHouseLotInfoLog a
  723. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.WorkPoint=b.WorkPoint
  724. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  725. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  726. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  727. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  728. sql = string.Format(sql, Identification);
  729. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  730. string Inputstr = JsonConvert.SerializeObject(dt);
  731. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  732. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  733. Result result = new Result();
  734. result = JsonConvert.DeserializeObject<Result>(resultStr);
  735. if (result.Success)
  736. {
  737. try
  738. {
  739. foreach (DataRow dr in dt.Rows)
  740. {
  741. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  742. }
  743. }
  744. catch (Exception ex)
  745. {
  746. log.Debug(ex.ToString());
  747. log.Debug(resultStr);
  748. }
  749. }
  750. else
  751. {
  752. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  753. }
  754. }
  755. }
  756. #endregion
  757. }
  758. catch (Exception)
  759. {
  760. throw;
  761. }
  762. }
  763. /// <summary>
  764. /// 一步调拨接口
  765. /// </summary>
  766. /// <param name="TransType"></param>
  767. /// <param name="Identification"></param>
  768. /// <param name="cmd"></param>
  769. public static void NewOneStepTransferDocInERP(string TransType, string Identification, string isPN, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  770. {
  771. try
  772. {
  773. #region ERP开立状态单据审核
  774. string resultStr = "";
  775. string sql = "";
  776. //检验调拨单是否一次性发完
  777. if (isPN == "1")
  778. {
  779. sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  780. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  781. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  782. BEGIN
  783. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  784. RETURN
  785. END
  786. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  787. FROM ICSWareHouseLotInfoLog a
  788. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  789. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  790. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  791. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='3'
  792. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  793. sql = string.Format(sql, Identification);
  794. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  795. string Inputstr = JsonConvert.SerializeObject(dt);
  796. if (isPN == "1")
  797. {//派纳调拨
  798. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PNOneStepTransferDocInURL, Inputstr);
  799. }
  800. else
  801. {
  802. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  803. }
  804. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  805. Result result = new Result();
  806. result = JsonConvert.DeserializeObject<Result>(resultStr);
  807. if (result.Success)
  808. {
  809. try
  810. {
  811. foreach (DataRow dr in dt.Rows)
  812. {
  813. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  814. }
  815. }
  816. catch (Exception ex)
  817. {
  818. log.Debug(ex.ToString());
  819. log.Debug(resultStr);
  820. }
  821. }
  822. else
  823. {
  824. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  825. }
  826. }
  827. else
  828. {
  829. if (DBHelper.IsPNU9())
  830. {
  831. sql = @"
  832. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  833. FROM ICSWareHouseLotInfoLog a
  834. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  835. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  836. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  837. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  838. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  839. 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
  840. where a.Identification='{0}' GROUP BY a.transCode";
  841. checksql = string.Format(checksql, Identification);
  842. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  843. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  844. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  845. string trancode = chekdt.Rows[0]["transCode"].ToString();
  846. if (SUMQty - ISSQty == 0)
  847. {
  848. if (isPN == "2")
  849. {
  850. string pnsql = @"SELECT DISTINCT b.TransferDetailID AS DocLineID,SUM(a.Quantity) AS TransferQTY,ext.BatchCode AS TransferBatchCode,a.WorkPoint AS OrgCode
  851. FROM ICSWareHouseLotInfoLog a
  852. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo --AND a.WorkPoint=lot.WorkPoint
  853. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID --AND lot.WorkPoint=ext.WorkPoint
  854. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  855. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  856. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  857. WHERE a.TransCode='{0}' AND ERPUpload='0' AND b.Type='1'
  858. GROUP BY b.TransferDetailID,ext.BatchCode,a.WorkPoint
  859. ";
  860. pnsql = string.Format(pnsql, trancode);
  861. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  862. string Inputstr = JsonConvert.SerializeObject(dt);
  863. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.NewOneStepTransferDocInURL, Inputstr);
  864. Result result = new Result();
  865. result = JsonConvert.DeserializeObject<Result>(resultStr);
  866. if (result.Success)
  867. {
  868. try
  869. {
  870. foreach (DataRow dr in dt.Rows)
  871. {
  872. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  873. }
  874. }
  875. catch (Exception ex)
  876. {
  877. log.Debug(ex.ToString());
  878. log.Debug(resultStr);
  879. }
  880. }
  881. else
  882. {
  883. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  884. }
  885. }
  886. else
  887. {
  888. string pnsql = @"SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  889. FROM ICSWareHouseLotInfoLog a
  890. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  891. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  892. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  893. WHERE a.TransCode='{0}' AND ERPUpload='0' AND b.Type='1'
  894. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  895. ";
  896. pnsql = string.Format(pnsql, trancode);
  897. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  898. string Inputstr = JsonConvert.SerializeObject(dt);
  899. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, 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. }
  922. }
  923. }
  924. else
  925. {
  926. sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  927. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  928. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  929. BEGIN
  930. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  931. RETURN
  932. END
  933. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  934. FROM ICSWareHouseLotInfoLog a
  935. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  936. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  937. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  938. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  939. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  940. sql = string.Format(sql, Identification);
  941. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  942. string Inputstr = JsonConvert.SerializeObject(dt);
  943. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  944. // resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OneStepTransferDocInURL, Inputstr);
  945. Result result = new Result();
  946. result = JsonConvert.DeserializeObject<Result>(resultStr);
  947. if (result.Success)
  948. {
  949. try
  950. {
  951. foreach (DataRow dr in dt.Rows)
  952. {
  953. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  954. }
  955. }
  956. catch (Exception ex)
  957. {
  958. log.Debug(ex.ToString());
  959. log.Debug(resultStr);
  960. }
  961. }
  962. else
  963. {
  964. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  965. }
  966. }
  967. }
  968. #endregion
  969. }
  970. catch (Exception)
  971. {
  972. throw;
  973. }
  974. }
  975. #endregion
  976. #region 调拨
  977. /// <summary>
  978. /// 调拨接口
  979. /// </summary>
  980. /// <param name="TransType"></param>
  981. /// <param name="Identification"></param>
  982. /// <param name="cmd"></param>
  983. public static void StepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  984. {
  985. try
  986. {
  987. #region ERP开立状态单据审核
  988. //检验调拨单是否一次性发完
  989. 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,
  990. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  991. ,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,
  992. 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
  993. INTO #TempERP
  994. FROM ICSWareHouseLotInfoLog a
  995. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  996. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  997. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  998. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  999. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1000. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  1001. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  1002. WHERE a.Identification='{0}' AND ERPUpload='0'
  1003. GROUP BY a.ToWarehouseCode,a.MUSER,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
  1004. ,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, ''),
  1005. 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, '')
  1006. SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
  1007. SELECT Costre,Sequence,InvCode,Quantity,Amount,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1008. FROM #TempERP
  1009. DROP TABLE #TempERP";
  1010. sql = string.Format(sql, Identification);
  1011. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1012. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1013. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.StepTransferDocInURL, Inputstr);
  1014. Result result = new Result();
  1015. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1016. if (result.Success)
  1017. {
  1018. try
  1019. {
  1020. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1021. foreach (var item in res)
  1022. {
  1023. JObject jo = (JObject)item;
  1024. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1025. foreach (var detail in resdetail)
  1026. {
  1027. JObject det = (JObject)detail;
  1028. 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()
  1029. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1030. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1031. }
  1032. }
  1033. }
  1034. catch (Exception ex)
  1035. {
  1036. log.Debug(ex.ToString());
  1037. log.Debug(resultStr);
  1038. }
  1039. }
  1040. else
  1041. {
  1042. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1043. }
  1044. #endregion
  1045. }
  1046. catch (Exception)
  1047. {
  1048. throw;
  1049. }
  1050. }
  1051. #endregion
  1052. #region 调拨申请单接口
  1053. /// <summary>
  1054. /// 调拨申请单接口
  1055. /// </summary>
  1056. /// <param name="TransType"></param>
  1057. /// <param name="Identification"></param>
  1058. /// <param name="cmd"></param>
  1059. public static void StepTransferApplicationERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1060. {
  1061. try
  1062. {
  1063. #region ERP开立状态单据审核
  1064. string sql = "";
  1065. //检验调拨单是否一次性发完
  1066. if (DBHelper.IsPNU9())//派纳
  1067. {
  1068. 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,
  1069. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1070. ,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,
  1071. 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
  1072. INTO #TempERP
  1073. FROM ICSWareHouseLotInfoLog a
  1074. INNER JOIN ICSTransferApplication c ON a.TransCode=c.TransferNO and a.TransSequence=c.Sequence and a.WorkPoint=c.EATTRIBUTE30
  1075. --INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1076. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1077. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1078. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1079. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1080. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  1081. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  1082. WHERE a.Identification='{0}' AND ERPUpload='0' and a.businesscode ='47'
  1083. GROUP BY a.ToWarehouseCode,a.MUSER,c.TransferDetailID,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
  1084. ,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, ''),
  1085. 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
  1086. SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
  1087. 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
  1088. FROM #TempERP
  1089. DROP TABLE #TempERP";
  1090. }
  1091. else
  1092. {
  1093. 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,
  1094. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1095. ,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,
  1096. 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
  1097. INTO #TempERP
  1098. FROM ICSWareHouseLotInfoLog a
  1099. INNER JOIN ICSTransferApplication c ON a.TransCode=c.TransferNO and a.TransSequence=c.Sequence and a.WorkPoint=c.WorkPoint
  1100. --INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1101. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1102. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1103. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1104. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1105. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  1106. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  1107. WHERE a.Identification='{0}' AND ERPUpload='0' and a.businesscode ='47'
  1108. GROUP BY a.ToWarehouseCode,a.MUSER,c.TransferDetailID,a.InvCode,conStock.Enable,con.Enable,a.FromWarehouseCode
  1109. ,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, ''),
  1110. 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
  1111. SELECT DISTINCT Costre,ToWHCode,FromWHCode,FromDepCode ,ToDepCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,TACode,UpdateStock FROM #TempERP
  1112. SELECT Costre,Sequence,InvCode,Quantity,Amount,TADetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1113. FROM #TempERP
  1114. DROP TABLE #TempERP";
  1115. }
  1116. sql = string.Format(sql, Identification);
  1117. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1118. log.Debug(sql);
  1119. log.Debug(ds.ToString());
  1120. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1121. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.StepTransferApplicationURL, Inputstr);
  1122. Result result = new Result();
  1123. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1124. if (result.Success)
  1125. {
  1126. try
  1127. {
  1128. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1129. foreach (var item in res)
  1130. {
  1131. JObject jo = (JObject)item;
  1132. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1133. foreach (var detail in resdetail)
  1134. {
  1135. JObject det = (JObject)detail;
  1136. 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()
  1137. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1138. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1139. }
  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 TwoStepTransferDocOut(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. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  1176. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}'
  1177. IF (@Status IS NULL)
  1178. BEGIN
  1179. RAISERROR('" + language.GetNameByCode("WMSAPIInfo146") + @"',16,1);
  1180. RETURN
  1181. END
  1182. ELSE IF (@Status!='1')
  1183. BEGIN
  1184. RAISERROR('" + language.GetNameByCode("WMSAPIInfo147") + @"',16,1);
  1185. RETURN
  1186. END
  1187. UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
  1188. FROM ICSOtherOut a
  1189. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  1190. WHERE a.OutCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}'
  1191. IF EXISTS(SELECT a.ID FROM ICSOtherOut a
  1192. INNER JOIN ICSTransfer b ON a.TransferDetailID=b.TransferDetailID AND a.WorkPoint=b.WorkPoint
  1193. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' and a.id='{4}' AND a.Quantity<a.OutQuantity)
  1194. BEGIN
  1195. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1196. RETURN
  1197. END";
  1198. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  1199. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1200. {
  1201. throw new Exception(language.GetNameByCode("WMSAPIInfo148"));//"两步调出单更新失败!");
  1202. }
  1203. }
  1204. catch (Exception)
  1205. {
  1206. throw;
  1207. }
  1208. }
  1209. /// <summary>
  1210. /// 两步调出接口
  1211. /// </summary>
  1212. /// <param name="TransType"></param>
  1213. /// <param name="Identification"></param>
  1214. /// <param name="cmd"></param>
  1215. public static void TwoStepTransferDocOutERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1216. {
  1217. try
  1218. {
  1219. #region ERP开立状态单据审核
  1220. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1221. INTO #NewTempERP
  1222. from ICSWareHouseLotInfoLog
  1223. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '22'
  1224. IF EXISTS(SELECT b.ID FROM ICSOtherOut b
  1225. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1226. WHERE b.OutCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1227. AND b.Quantity!=b.OutQuantity)
  1228. BEGIN
  1229. RAISERROR('" + language.GetNameByCode("WMSAPIInfo098") + @"',16,1);
  1230. RETURN
  1231. END
  1232. SELECT b.OutID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1233. FROM #NewTempERP a
  1234. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1235. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1236. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1237. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1238. GROUP BY b.OutID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1239. DROP TABLE #NewTempERP";
  1240. sql = string.Format(sql, Identification);
  1241. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1242. string Inputstr = JsonConvert.SerializeObject(dt);
  1243. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocOutURL, Inputstr);
  1244. Result result = new Result();
  1245. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1246. if (result.Success)
  1247. {
  1248. try
  1249. {
  1250. foreach (DataRow dr in dt.Rows)
  1251. {
  1252. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1253. }
  1254. }
  1255. catch (Exception ex)
  1256. {
  1257. log.Debug(ex.ToString());
  1258. log.Debug(resultStr);
  1259. }
  1260. }
  1261. else
  1262. {
  1263. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1264. }
  1265. #endregion
  1266. }
  1267. catch (Exception)
  1268. {
  1269. throw;
  1270. }
  1271. }
  1272. #endregion
  1273. #region 晶华两步调出
  1274. /// <summary>
  1275. /// 晶华两步调出
  1276. /// </summary>
  1277. /// <param name="TransCode"></param>
  1278. /// <param name="TransSequence"></param>
  1279. /// <param name="Quantity"></param>
  1280. /// <param name="WorkPoint"></param>
  1281. /// <param name="cmd"></param>
  1282. public static void JHTwoStepTransferDocOut(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID)
  1283. {
  1284. try
  1285. {
  1286. string sql = @"DECLARE @Status VARCHAR(10)
  1287. SELECT @Status=a.Status FROM ICSTransfer a
  1288. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}'
  1289. IF (@Status IS NULL)
  1290. BEGIN
  1291. RAISERROR('" + language.GetNameByCode("WMSAPIInfo146") + @"',16,1);
  1292. RETURN
  1293. END
  1294. ELSE IF (@Status!='1')
  1295. BEGIN
  1296. RAISERROR('" + language.GetNameByCode("WMSAPIInfo147") + @"',16,1);
  1297. RETURN
  1298. END
  1299. UPDATE a SET EATTRIBUTE1=ISNULL(EATTRIBUTE1,0)+{2}
  1300. FROM ICSTransfer a
  1301. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}'
  1302. IF EXISTS(SELECT a.ID FROM ICSTransfer a
  1303. WHERE a.TransferNO='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' and a.id='{4}' AND a.Quantity<ISNULL(a.EATTRIBUTE1,0))
  1304. BEGIN
  1305. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1306. RETURN
  1307. END";
  1308. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  1309. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1310. {
  1311. throw new Exception(language.GetNameByCode("WMSAPIInfo148"));//"两步调出单更新失败!");
  1312. }
  1313. }
  1314. catch (Exception)
  1315. {
  1316. throw;
  1317. }
  1318. }
  1319. /// <summary>
  1320. /// 两步调出接口
  1321. /// </summary>
  1322. /// <param name="TransType"></param>
  1323. /// <param name="Identification"></param>
  1324. /// <param name="cmd"></param>
  1325. /// <summary>
  1326. /// 两步调出接口
  1327. /// </summary>
  1328. /// <param name="TransType"></param>
  1329. /// <param name="Identification"></param>
  1330. /// <param name="cmd"></param>
  1331. public static void JHTwoStepTransferDocOutERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1332. {
  1333. try
  1334. {
  1335. #region ERP开立状态单据审核
  1336. string sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  1337. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1338. AND b.Type = '3' AND b.Quantity!=ISNULL(b.EATTRIBUTE1,0))
  1339. BEGIN
  1340. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  1341. RETURN
  1342. END
  1343. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1344. FROM ICSWareHouseLotInfoLog a
  1345. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1346. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  1347. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  1348. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='3'
  1349. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  1350. sql = string.Format(sql, Identification);
  1351. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1352. string Inputstr = JsonConvert.SerializeObject(dt);
  1353. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.JHTwoStepTransferDocOutURL, Inputstr);
  1354. Result result = new Result();
  1355. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1356. if (result.Success)
  1357. {
  1358. try
  1359. {
  1360. foreach (DataRow dr in dt.Rows)
  1361. {
  1362. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1363. }
  1364. }
  1365. catch (Exception ex)
  1366. {
  1367. log.Debug(ex.ToString());
  1368. log.Debug(resultStr);
  1369. }
  1370. }
  1371. else
  1372. {
  1373. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1374. }
  1375. #endregion
  1376. }
  1377. catch (Exception)
  1378. {
  1379. throw;
  1380. }
  1381. }
  1382. #endregion
  1383. #region 两步调入
  1384. /// <summary>
  1385. /// 两步调入
  1386. /// </summary>
  1387. /// <param name="TransCode"></param>
  1388. /// <param name="TransSequence"></param>
  1389. /// <param name="Quantity"></param>
  1390. /// <param name="WorkPoint"></param>
  1391. /// <param name="cmd"></param>
  1392. public static void TwoStepTransferDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1393. {
  1394. //需要关联其他入库单
  1395. try
  1396. {
  1397. string sql = @"DECLARE @Status VARCHAR(10)
  1398. SELECT @Status=Otin.Status FROM ICSOtherIn Otin
  1399. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  1400. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  1401. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  1402. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1403. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}'
  1404. IF (@Status IS NULL)
  1405. BEGIN
  1406. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1407. RETURN
  1408. END
  1409. ELSE IF (@Status!='1')
  1410. BEGIN
  1411. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1412. RETURN
  1413. END
  1414. UPDATE Otin SET InQuantity=ISNULL(InQuantity,0)+'{4}'
  1415. FROM ICSOtherIn Otin
  1416. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  1417. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  1418. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  1419. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1420. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}'
  1421. IF EXISTS(SELECT a.LotNo FROM ICSOtherIn Otin
  1422. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  1423. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  1424. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  1425. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1426. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND Otin.InCode='{2}' AND Otin.Sequence='{3}' AND Otin.Quantity<Otin.InQuantity)
  1427. BEGIN
  1428. RAISERROR('" + language.GetNameByCode("WMSAPIInfo149") + @"',16,1);
  1429. END";
  1430. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  1431. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1432. {
  1433. throw new Exception(language.GetNameByCode("WMSAPIInfo150"));//"两步调入单更新失败!");
  1434. }
  1435. }
  1436. catch (Exception)
  1437. {
  1438. throw;
  1439. }
  1440. }
  1441. /// <summary>
  1442. /// 两步调入接口
  1443. /// </summary>
  1444. /// <param name="TransType"></param>
  1445. /// <param name="Identification"></param>
  1446. /// <param name="cmd"></param>
  1447. public static void TwoStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1448. {
  1449. try
  1450. {
  1451. #region ERP开立状态单据审核
  1452. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1453. INTO #NewTempERP
  1454. from ICSWareHouseLotInfoLog
  1455. WHERE Identification='{0}' AND ERPUpload='0'
  1456. IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  1457. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1458. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1459. AND b.Quantity!=b.InQuantity)
  1460. BEGIN
  1461. RAISERROR('" + language.GetNameByCode("WMSAPIInfo099") + @"',16,1);
  1462. RETURN
  1463. END
  1464. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1465. FROM #NewTempERP a
  1466. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1467. INNER JOIN ICSTransfer c ON b.TransferDetailID=c.TransferDetailID AND b.WorkPoint=c.WorkPoint
  1468. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1469. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1470. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1471. DROP TABLE #NewTempERP";
  1472. sql = string.Format(sql, Identification);
  1473. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1474. string Inputstr = JsonConvert.SerializeObject(dt);
  1475. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.TwoStepTransferDocInURL, Inputstr);
  1476. Result result = new Result();
  1477. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1478. if (result.Success)
  1479. {
  1480. try
  1481. {
  1482. foreach (DataRow dr in dt.Rows)
  1483. {
  1484. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1485. }
  1486. }
  1487. catch (Exception ex)
  1488. {
  1489. log.Debug(ex.ToString());
  1490. log.Debug(resultStr);
  1491. }
  1492. }
  1493. else
  1494. {
  1495. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1496. }
  1497. #endregion
  1498. }
  1499. catch (Exception)
  1500. {
  1501. throw;
  1502. }
  1503. }
  1504. #endregion
  1505. #region 晶华两步调入
  1506. /// <summary>
  1507. /// 晶华两步调入
  1508. /// </summary>
  1509. /// <param name="TransCode"></param>
  1510. /// <param name="TransSequence"></param>
  1511. /// <param name="Quantity"></param>
  1512. /// <param name="WorkPoint"></param>
  1513. /// <param name="cmd"></param>
  1514. public static void JHTwoStepTransferDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1515. {
  1516. try
  1517. {
  1518. string sql = @"
  1519. UPDATE tra SET TransferQuantity=ISNULL(TransferQuantity,0)+{4}
  1520. FROM ICSTransfer tra
  1521. INNER JOIN ICSWareHouseLotInfoLog log ON tra.TransferNO=log.TransCode AND tra.Sequence=log.TransSequence AND tra.ID=log.transID AND tra.WorkPoint=log.WorkPoint
  1522. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1523. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1524. IF EXISTS(SELECT a.LotNo FROM ICSTransfer tra
  1525. INNER JOIN ICSWareHouseLotInfoLog log ON tra.TransferNO=log.TransCode AND tra.Sequence=log.TransSequence AND tra.ID=log.transID AND tra.WorkPoint=log.WorkPoint
  1526. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1527. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND tra.Quantity<tra.TransferQuantity)
  1528. BEGIN
  1529. RAISERROR('" + language.GetNameByCode("WMSAPIInfo149") + @"',16,1);
  1530. END";
  1531. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  1532. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1533. {
  1534. throw new Exception(language.GetNameByCode("WMSAPIInfo150"));//"两步调入单更新失败!");
  1535. }
  1536. string checksql = @"UPDATE tra SET TransferQuantity=ISNULL(TransferQuantity,0)+{2}
  1537. FROM ICSTransfer tra
  1538. WHERE tra.TransferNO='{0}' AND tra.Sequence='{1}'
  1539. IF EXISTS(SELECT a.LotNo FROM ICSTransfer tra
  1540. INNER JOIN ICSWareHouseLotInfoLog log ON tra.TransferNO=log.TransCode AND tra.Sequence=log.TransSequence AND tra.ID=log.transID AND tra.WorkPoint=log.WorkPoint
  1541. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1542. WHERE tra.TransferNO='{0}' AND tra.Sequence='{1}' AND tra.Quantity<tra.TransferQuantity)
  1543. BEGIN
  1544. RAISERROR('" + language.GetNameByCode("WMSAPIInfo149") + @"',16,1);
  1545. END";
  1546. checksql = string.Format(checksql, TransCode, TransSequence, Quantity);
  1547. if (!DBHelper.ExecuteNonQuery(checksql, cmd))
  1548. {
  1549. throw new Exception(language.GetNameByCode("WMSAPIInfo150"));//"两步调入单更新失败!");
  1550. }
  1551. }
  1552. catch (Exception)
  1553. {
  1554. throw;
  1555. }
  1556. }
  1557. /// <summary>
  1558. /// 晶华两步调入接口
  1559. /// </summary>
  1560. /// <param name="TransType"></param>
  1561. /// <param name="Identification"></param>
  1562. /// <param name="cmd"></param>
  1563. public static void JHTwoStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1564. {
  1565. try
  1566. {
  1567. log.Debug("晶华两步调入erp接口开发中;");
  1568. #region ERP开立状态单据审核
  1569. string sql = @"IF EXISTS(SELECT b.ID FROM ICSTransfer b
  1570. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1571. AND b.Type = '1' AND b.Quantity!=b.TransferQuantity)
  1572. BEGIN
  1573. RAISERROR('" + language.GetNameByCode("WMSAPIInfo097") + @"',16,1);
  1574. RETURN
  1575. END
  1576. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1577. FROM ICSWareHouseLotInfoLog a
  1578. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1579. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  1580. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  1581. WHERE a.Identification='{0}' AND ERPUpload='0' AND b.Type='1'
  1582. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  1583. sql = string.Format(sql, Identification);
  1584. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1585. string Inputstr = JsonConvert.SerializeObject(dt);
  1586. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.JHTwoStepTransferDocInURL, Inputstr);
  1587. Result result = new Result();
  1588. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1589. if (result.Success)
  1590. {
  1591. try
  1592. {
  1593. foreach (DataRow dr in dt.Rows)
  1594. {
  1595. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1596. }
  1597. }
  1598. catch (Exception ex)
  1599. {
  1600. log.Debug(ex.ToString());
  1601. log.Debug(resultStr);
  1602. }
  1603. }
  1604. else
  1605. {
  1606. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1607. }
  1608. #endregion
  1609. }
  1610. catch (Exception)
  1611. {
  1612. throw;
  1613. }
  1614. }
  1615. #endregion
  1616. #region 锐腾两步调入
  1617. /// <summary>
  1618. /// 锐腾两步调入
  1619. /// </summary>
  1620. /// <param name="TransCode"></param>
  1621. /// <param name="TransSequence"></param>
  1622. /// <param name="Quantity"></param>
  1623. /// <param name="WorkPoint"></param>
  1624. /// <param name="cmd"></param>
  1625. public static void RTTwoStepTransferDocIn(string TransCode, string TransSequence, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1626. {
  1627. //需要关联其他入库单
  1628. try
  1629. {
  1630. string sql = @"DECLARE @Status VARCHAR(10)
  1631. SELECT @Status=tra.Status FROM ICSTransfer tra
  1632. INNER JOIN ICSInventoryLotDetail lotd ON lotd.TransCode=tra.TransferNO AND lotd.TransSequence=tra.Sequence and lotd.WorkPoint=tra.WorkPoint
  1633. INNER JOIN ICSInventoryLot lot ON lotd.LotNo=lot.LotNo and lotd.WorkPoint=lot.WorkPoint
  1634. WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND tra.TransferNO='{2}' and tra.Sequence='{3}'
  1635. IF (@Status IS NULL)
  1636. BEGIN
  1637. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1638. RETURN
  1639. END
  1640. UPDATE tra SET TransferQuantity=ISNULL(TransferQuantity,0)+'{4}'
  1641. FROM ICSTransfer tra
  1642. INNER JOIN ICSInventoryLotDetail lotd ON lotd.TransCode=tra.TransferNO AND lotd.TransSequence=tra.Sequence and lotd.WorkPoint=tra.WorkPoint
  1643. INNER JOIN ICSInventoryLot lot ON lotd.LotNo=lot.LotNo and lotd.WorkPoint=lot.WorkPoint
  1644. WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND tra.TransferNO='{2}' and tra.Sequence='{3}'
  1645. IF EXISTS(SELECT lot.LotNo FROM ICSTransfer tra
  1646. INNER JOIN ICSInventoryLotDetail lotd ON lotd.TransCode=tra.TransferNO AND lotd.TransSequence=tra.Sequence and lotd.WorkPoint=tra.WorkPoint
  1647. INNER JOIN ICSInventoryLot lot ON lotd.LotNo=lot.LotNo and lotd.WorkPoint=lot.WorkPoint
  1648. WHERE lot.LotNo='{0}' AND lot.WorkPoint='{1}' AND tra.TransferNO='{2}' and tra.Sequence='{3}' AND tra.Quantity<tra.TransferQuantity)
  1649. BEGIN
  1650. RAISERROR('" + language.GetNameByCode("WMSAPIInfo149") + @"',16,1);
  1651. END";
  1652. sql = string.Format(sql, LotNo, WorkPoint, TransCode, TransSequence, Quantity);
  1653. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1654. {
  1655. throw new Exception(language.GetNameByCode("WMSAPIInfo150"));//"两步调入单更新失败!");
  1656. }
  1657. }
  1658. catch (Exception)
  1659. {
  1660. throw;
  1661. }
  1662. }
  1663. /// <summary>
  1664. /// 两步调入接口
  1665. /// </summary>
  1666. /// <param name="TransType"></param>
  1667. /// <param name="Identification"></param>
  1668. /// <param name="cmd"></param>
  1669. public static void RTTwoStepTransferDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1670. {
  1671. try
  1672. {
  1673. #region ERP开立状态单据审核
  1674. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1675. INTO #NewTempERP
  1676. from ICSWareHouseLotInfoLog
  1677. WHERE Identification='{0}' AND ERPUpload='0'
  1678. IF EXISTS(SELECT b.ID FROM ICSTransfer b
  1679. WHERE b.TransferNO+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1680. AND b.Quantity!=b.TransferQuantity)
  1681. BEGIN
  1682. RAISERROR('" + language.GetNameByCode("WMSAPIInfo099") + @"',16,1);
  1683. RETURN
  1684. END
  1685. SELECT b.TransferID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1686. FROM #NewTempERP a
  1687. INNER JOIN ICSTransfer b ON a.TransCode=b.TransferNO AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1688. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1689. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1690. GROUP BY b.TransferID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1691. DROP TABLE #NewTempERP";
  1692. sql = string.Format(sql, Identification);
  1693. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1694. string Inputstr = JsonConvert.SerializeObject(dt);
  1695. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.RTTwoStepTransferDocInURL, Inputstr);
  1696. Result result = new Result();
  1697. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1698. if (result.Success)
  1699. {
  1700. try
  1701. {
  1702. foreach (DataRow dr in dt.Rows)
  1703. {
  1704. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1705. }
  1706. }
  1707. catch (Exception ex)
  1708. {
  1709. log.Debug(ex.ToString());
  1710. log.Debug(resultStr);
  1711. }
  1712. }
  1713. else
  1714. {
  1715. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1716. }
  1717. #endregion
  1718. }
  1719. catch (Exception)
  1720. {
  1721. throw;
  1722. }
  1723. }
  1724. #endregion
  1725. #region 其他出库
  1726. /// <summary>
  1727. /// 其他出库
  1728. /// </summary>
  1729. /// <param name="TransCode"></param>
  1730. /// <param name="TransSequence"></param>
  1731. /// <param name="Quantity"></param>
  1732. /// <param name="WorkPoint"></param>
  1733. /// <param name="cmd"></param>
  1734. public static void OtherOutDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID)
  1735. {
  1736. try
  1737. {
  1738. string sql = @"DECLARE @Status VARCHAR(10)
  1739. SELECT @Status=a.Status FROM ICSOtherOut a
  1740. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}'
  1741. IF (@Status IS NULL)
  1742. BEGIN
  1743. RAISERROR('" + language.GetNameByCode("WMSAPIInfo151") + @"',16,1);
  1744. RETURN
  1745. END
  1746. ELSE IF (@Status!='1')
  1747. BEGIN
  1748. RAISERROR('" + language.GetNameByCode("WMSAPIInfo152") + @"',16,1);
  1749. RETURN
  1750. END
  1751. UPDATE a SET OutQuantity=ISNULL(OutQuantity,0)+'{2}'
  1752. FROM ICSOtherOut a
  1753. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}'
  1754. IF EXISTS(SELECT a.ID FROM ICSOtherOut a
  1755. WHERE a.OutCode='{0}' AND a.Sequence='{3}' and a.id='{4}' and a.WorkPoint='{1}' AND a.Quantity<a.OutQuantity)
  1756. BEGIN
  1757. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1758. RETURN
  1759. END";
  1760. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  1761. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1762. {
  1763. throw new Exception(language.GetNameByCode("WMSAPIInfo153"));//"其他出库单更新失败!");
  1764. }
  1765. }
  1766. catch (Exception)
  1767. {
  1768. throw;
  1769. }
  1770. }
  1771. /// <summary>
  1772. /// 其他出库接口
  1773. /// </summary>
  1774. /// <param name="TransType"></param>
  1775. /// <param name="Identification"></param>
  1776. /// <param name="cmd"></param>
  1777. public static void OtherOutDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1778. {
  1779. try
  1780. {
  1781. string sql = string.Empty;
  1782. if (DBHelper.IsPNU9())
  1783. {
  1784. sql = @"SELECT a.ToWarehouseCode+b.OutCode+a.MUSER AS Costre
  1785. ,a.TransCode+a.TransSequence+a.ToWarehouseCode+b.OutCode+a.MUSER AS Costre2
  1786. ,a.ToWarehouseCode AS WarehouseCode,b.OutCode,b.Sequence,a.MUSER,
  1787. 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
  1788. ,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,
  1789. 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
  1790. INTO #TempERP
  1791. FROM ICSWareHouseLotInfoLog a
  1792. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1793. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1794. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1795. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1796. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1797. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1798. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  1799. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1800. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode = '24'
  1801. 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
  1802. ,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, ''),
  1803. 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, '')
  1804. SELECT DISTINCT Costre,WorkPoint,OutCode AS DocNo,0 AS ID FROM #TempERP
  1805. 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
  1806. DROP TABLE #TempERP";
  1807. sql = string.Format(sql, Identification);
  1808. //DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1809. //string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  1810. 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
  1811. where a.Identification='{0}' GROUP BY a.transCode";
  1812. checksql = string.Format(checksql, Identification);
  1813. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  1814. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  1815. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  1816. string trancode = chekdt.Rows[0]["transCode"].ToString();
  1817. if (SUMQty - ISSQty == 0)
  1818. {
  1819. string pnsql = @"SELECT b.OutCode AS Costre
  1820. ,a.TransCode+a.TransSequence+a.FromWarehouseCode+b.OutCode+a.MUSER AS Costre2
  1821. ,a.FromWarehouseCode AS WarehouseCode,b.OutCode,b.Sequence,a.MUSER,
  1822. 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
  1823. ,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,
  1824. 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
  1825. INTO #TempERP
  1826. FROM ICSWareHouseLotInfoLog a
  1827. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1828. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1829. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1830. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1831. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1832. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1833. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  1834. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1835. WHERE a.TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '24' and a.EATTRIBUTE1<>'1'
  1836. 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
  1837. ,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, ''),
  1838. 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, '')
  1839. SELECT DISTINCT Costre,WorkPoint,OutCode AS DocNo,0 AS ID FROM #TempERP
  1840. 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
  1841. DROP TABLE #TempERP";
  1842. pnsql = string.Format(pnsql, trancode);
  1843. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  1844. string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  1845. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MiscShipURL, Inputstr);
  1846. Result result = new Result();
  1847. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1848. if (result.Success)
  1849. {
  1850. try
  1851. {
  1852. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1853. foreach (var item in res)
  1854. {
  1855. JObject jo = (JObject)item;
  1856. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1857. foreach (var detail in resdetail)
  1858. {
  1859. JObject det = (JObject)detail;
  1860. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1',Quantity='{6}'
  1861. // FROM ICSWareHouseLotInfoLog a
  1862. // INNER JOIN ICSSSD c ON a.TransCode=c.SSDCOde AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  1863. //INNER JOIN ICSInventoryLot lot on a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1864. //INNER JOIN ICSExtension d ON lot.ExtensionID=d.id and lot.WorkPoint=d.WorkPoint
  1865. // WHERE c.SSDCode='{0}' AND a.BusinessCode ='{7}' AND d.BatchCode='{8}' AND lot.InvCode='{1}'";
  1866. // ERPupdate = string.Format(ERPupdate);
  1867. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1868. // {
  1869. // throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  1870. // }
  1871. }
  1872. }
  1873. }
  1874. catch (Exception ex)
  1875. {
  1876. log.Debug(ex.ToString());
  1877. log.Debug(resultStr);
  1878. }
  1879. }
  1880. else
  1881. {
  1882. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1883. }
  1884. }
  1885. }
  1886. else
  1887. {
  1888. #region ERP开立状态单据审核
  1889. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  1890. INTO #NewTempERP
  1891. from ICSWareHouseLotInfoLog
  1892. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '24'
  1893. IF EXISTS(SELECT b.ID FROM ICSOtherOut b
  1894. WHERE b.OutCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  1895. AND b.Quantity!=b.OutQuantity)
  1896. BEGIN
  1897. RAISERROR('" + language.GetNameByCode("WMSAPIInfo100") + @"',16,1);
  1898. RETURN
  1899. END
  1900. SELECT b.OutID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1901. FROM #NewTempERP a
  1902. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
  1903. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1904. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1905. GROUP BY b.OutID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1906. DROP TABLE #NewTempERP";
  1907. sql = string.Format(sql, Identification);
  1908. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1909. string Inputstr = JsonConvert.SerializeObject(dt);
  1910. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OtherOutDocURL, Inputstr);
  1911. Result result = new Result();
  1912. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1913. if (result.Success)
  1914. {
  1915. try
  1916. {
  1917. foreach (DataRow dr in dt.Rows)
  1918. {
  1919. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1920. }
  1921. }
  1922. catch (Exception ex)
  1923. {
  1924. log.Debug(ex.ToString());
  1925. log.Debug(resultStr);
  1926. }
  1927. }
  1928. else
  1929. {
  1930. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1931. }
  1932. #endregion
  1933. }
  1934. }
  1935. catch (Exception)
  1936. {
  1937. throw;
  1938. }
  1939. }
  1940. /// <summary>
  1941. /// 创建U9杂发单接口
  1942. /// </summary>
  1943. /// <param name="TransType"></param>
  1944. /// <param name="Identification"></param>
  1945. /// <param name="cmd"></param>
  1946. public static void CreateOtherOutDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1947. {
  1948. try
  1949. {
  1950. #region U9创建单据并审核
  1951. string sql = @"select LotNo,WorkPoint,InvCode,FromWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1952. INTO #NewTempERP
  1953. from ICSWareHouseLotInfoLog
  1954. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='24'
  1955. 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,
  1956. b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,b.EATTRIBUTE7 as Project,b.EATTRIBUTE1 as Dep,
  1957. 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
  1958. ,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,
  1959. 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
  1960. INTO #TempERP
  1961. FROM #NewTempERP a
  1962. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1963. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1964. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1965. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1966. INNER JOIN ICSOtherOut b ON a.TransCode=b.OutCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1967. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1968. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock009' AND a.WorkPoint=conStock.WorkPoint
  1969. GROUP BY inv.AmountEnable,a.FromWarehouseCode,b.OutCode,a.MUSER,a.InvCode,con.Enable,conStock.Enable,b.EATTRIBUTE4,b.EATTRIBUTE2,b.EATTRIBUTE7 ,b.EATTRIBUTE1
  1970. ,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, ''),
  1971. 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, '')
  1972. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,DocType,ClientCode,OutCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1973. 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
  1974. DROP TABLE #TempERP
  1975. DROP TABLE #NewTempERP";
  1976. sql = string.Format(sql, Identification, BusinessCode);
  1977. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1978. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1979. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstr);
  1980. //sql = string.Format(sql, Identification);
  1981. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1982. //string Inputstr = JsonConvert.SerializeObject(dt);
  1983. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstr);
  1984. Result result = new Result();
  1985. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1986. if (result.Success)
  1987. {
  1988. try
  1989. {
  1990. //foreach (DataRow dr in dt.Rows)
  1991. //{
  1992. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1993. //}
  1994. }
  1995. catch (Exception ex)
  1996. {
  1997. log.Debug(ex.ToString());
  1998. log.Debug(resultStr);
  1999. }
  2000. }
  2001. else
  2002. {
  2003. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2004. }
  2005. #endregion
  2006. }
  2007. catch (Exception)
  2008. {
  2009. throw;
  2010. }
  2011. }
  2012. public static void CreateOtherOutDocNoSourceERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2013. {
  2014. try
  2015. {
  2016. #region U9创建无源头单据并审核
  2017. string sql = @"select LotNo,WorkPoint,InvCode,FromWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2018. INTO #NewTempERP
  2019. from ICSWareHouseLotInfoLog
  2020. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  2021. SELECT a.FromWarehouseCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,a.InvCode) AS Sequence,
  2022. 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
  2023. ,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,
  2024. 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
  2025. INTO #TempERP
  2026. FROM #NewTempERP a
  2027. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2028. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2029. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2030. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2031. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2032. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock009' AND a.WorkPoint=conStock.WorkPoint
  2033. GROUP BY inv.AmountEnable,a.FromWarehouseCode,a.MUSER,a.InvCode,con.Enable,conStock.Enable
  2034. ,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, ''),
  2035. 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, '')
  2036. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'MiscShip004' AS DocType,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  2037. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,'10403' AS Dep FROM #TempERP
  2038. DROP TABLE #TempERP
  2039. DROP TABLE #NewTempERP";
  2040. sql = string.Format(sql, Identification, BusinessCode);
  2041. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2042. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2043. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherOutDocURL, Inputstr);
  2044. Result result = new Result();
  2045. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2046. if (result.Success)
  2047. {
  2048. try
  2049. {
  2050. //foreach (DataRow dr in dt.Rows)
  2051. //{
  2052. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2053. //}
  2054. }
  2055. catch (Exception ex)
  2056. {
  2057. log.Debug(ex.ToString());
  2058. log.Debug(resultStr);
  2059. }
  2060. }
  2061. else
  2062. {
  2063. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2064. }
  2065. #endregion
  2066. }
  2067. catch (Exception)
  2068. {
  2069. throw;
  2070. }
  2071. }
  2072. #endregion
  2073. #region 其他入库
  2074. /// <summary>
  2075. /// 其他入库
  2076. /// </summary>
  2077. /// <param name="TransCode"></param>
  2078. /// <param name="TransSequence"></param>
  2079. /// <param name="Quantity"></param>
  2080. /// <param name="WorkPoint"></param>
  2081. /// <param name="cmd"></param>
  2082. public static void OtherInDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2083. {
  2084. try
  2085. {
  2086. string sql = @"DECLARE @Status VARCHAR(10)
  2087. SELECT @Status=c.Status FROM ICSInventoryLot a
  2088. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2089. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2090. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND isnull(c.Type,'1')='1'
  2091. IF (@Status IS NULL)
  2092. BEGIN
  2093. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2094. RETURN
  2095. END
  2096. ELSE IF (@Status!='1')
  2097. BEGIN
  2098. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  2099. RETURN
  2100. END
  2101. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  2102. FROM ICSInventoryLot a
  2103. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2104. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2105. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND isnull(c.Type,'1')='1'
  2106. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2107. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2108. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2109. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND isnull(c.Type,'1')='1'
  2110. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn021', c.Quantity,1,4,'')<c.InQuantity)
  2111. BEGIN
  2112. RAISERROR('" + language.GetNameByCode("WMSAPIInfo154") + @"',16,1);
  2113. END";
  2114. if (DBHelper.IsU9())
  2115. { sql = @"DECLARE @Status VARCHAR(10)
  2116. SELECT @Status=c.Status FROM ICSInventoryLot a
  2117. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2118. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2119. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2120. IF (@Status IS NULL)
  2121. BEGIN
  2122. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2123. RETURN
  2124. END
  2125. ELSE IF (@Status!='1')
  2126. BEGIN
  2127. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  2128. RETURN
  2129. END
  2130. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  2131. FROM ICSInventoryLot a
  2132. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2133. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2134. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'-- AND c.EATTRIBUTE2='1'
  2135. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2136. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2137. INNER JOIN ICSOtherIn c ON b.TransCode=c.InCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2138. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.EATTRIBUTE2='1'
  2139. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn021', c.Quantity,1,4,'')<c.InQuantity)
  2140. BEGIN
  2141. RAISERROR('" + language.GetNameByCode("WMSAPIInfo154") + @"',16,1);
  2142. END"; }
  2143. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2144. log.Debug("回写单据数量前" + sql);
  2145. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2146. {
  2147. throw new Exception(language.GetNameByCode("WMSAPIInfo155"));//"其他入库单更新失败!");
  2148. }
  2149. log.Debug("回写单据数量后");
  2150. }
  2151. catch (Exception)
  2152. {
  2153. throw;
  2154. }
  2155. }
  2156. public static void OtherInRedDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID)
  2157. {
  2158. try
  2159. {
  2160. string sql = @"DECLARE @Status VARCHAR(10)
  2161. SELECT @Status=a.Status FROM ICSOtherIn a
  2162. WHERE a.InCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' and a.type='2'
  2163. IF (@Status IS NULL)
  2164. BEGIN
  2165. RAISERROR('" + language.GetNameByCode("WMSAPIInfo151") + @"',16,1);
  2166. RETURN
  2167. END
  2168. ELSE IF (@Status!='1')
  2169. BEGIN
  2170. RAISERROR('" + language.GetNameByCode("WMSAPIInfo152") + @"',16,1);
  2171. RETURN
  2172. END
  2173. UPDATE a SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  2174. FROM ICSOtherIn a
  2175. WHERE a.InCode='{0}' AND a.Sequence='{3}' and a.id='{4}' AND a.WorkPoint='{1}' and a.type='2'
  2176. IF EXISTS(SELECT a.ID FROM ICSOtherIn a
  2177. 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)
  2178. BEGIN
  2179. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  2180. RETURN
  2181. END";
  2182. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  2183. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2184. {
  2185. throw new Exception("红字其他入库单更新失败!");//"红字其他入库单更新失败!");
  2186. }
  2187. }
  2188. catch (Exception)
  2189. {
  2190. throw;
  2191. }
  2192. }
  2193. /// <summary>
  2194. /// 其他入库接口
  2195. /// </summary>
  2196. /// <param name="TransType"></param>
  2197. /// <param name="Identification"></param>
  2198. /// <param name="cmd"></param>
  2199. public static void OtherInDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2200. {
  2201. try
  2202. {
  2203. string sql = string.Empty;
  2204. log.Debug("ERP开立状态单据审核");
  2205. if (DBHelper.IsPNU9())
  2206. {
  2207. sql = @"SELECT a.ToWarehouseCode+b.InCode+a.MUSER AS Costre
  2208. ,a.TransCode+a.TransSequence+a.ToWarehouseCode+b.InCode+a.MUSER AS Costre2
  2209. ,a.ToWarehouseCode AS WarehouseCode,b.InCode,b.Sequence,a.MUSER,
  2210. 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
  2211. ,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,
  2212. 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
  2213. INTO #TempERP
  2214. FROM ICSWareHouseLotInfoLog a
  2215. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2216. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2217. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2218. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2219. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2220. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2221. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  2222. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2223. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode = '25'
  2224. 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
  2225. ,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, ''),
  2226. 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, '')
  2227. SELECT DISTINCT Costre,WorkPoint,InCode AS DocNo,0 AS ID FROM #TempERP
  2228. 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
  2229. DROP TABLE #TempERP";
  2230. sql = string.Format(sql, Identification);
  2231. //DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2232. //string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  2233. 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
  2234. where a.Identification='{0}' GROUP BY a.transCode";
  2235. checksql = string.Format(checksql, Identification);
  2236. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  2237. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  2238. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  2239. string trancode = chekdt.Rows[0]["transCode"].ToString();
  2240. if (SUMQty - ISSQty == 0)
  2241. {
  2242. string pnsql = @"SELECT a.ToWarehouseCode+b.InCode+a.MUSER AS Costre
  2243. ,a.TransCode+a.TransSequence+a.ToWarehouseCode+b.InCode+a.MUSER AS Costre2
  2244. ,a.ToWarehouseCode AS WarehouseCode,b.InCode,b.Sequence,a.MUSER,
  2245. 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
  2246. ,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,
  2247. 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
  2248. INTO #TempERP
  2249. FROM ICSWareHouseLotInfoLog a
  2250. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2251. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2252. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2253. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2254. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2255. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2256. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock005' AND a.WorkPoint=conStock.WorkPoint
  2257. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2258. WHERE a.TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '25' and a.EATTRIBUTE1<>'1'
  2259. 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
  2260. ,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, ''),
  2261. 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, '')
  2262. SELECT DISTINCT Costre,WorkPoint,InCode AS DocNo,0 AS ID FROM #TempERP
  2263. 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
  2264. DROP TABLE #TempERP";
  2265. pnsql = string.Format(pnsql, trancode);
  2266. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  2267. string Inputstr = DataToJsonHelper.DataSetToJson2(ds, "details", "Costre");
  2268. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.MiscRcvURL, Inputstr);
  2269. Result result = new Result();
  2270. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2271. if (result.Success)
  2272. {
  2273. try
  2274. {
  2275. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2276. foreach (var item in res)
  2277. {
  2278. JObject jo = (JObject)item;
  2279. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2280. foreach (var detail in resdetail)
  2281. {
  2282. JObject det = (JObject)detail;
  2283. // string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1',Quantity='{6}'
  2284. // FROM ICSWareHouseLotInfoLog a
  2285. // INNER JOIN ICSSSD c ON a.TransCode=c.SSDCOde AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint
  2286. //INNER JOIN ICSInventoryLot lot on a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2287. //INNER JOIN ICSExtension d ON lot.ExtensionID=d.id and lot.WorkPoint=d.WorkPoint
  2288. // WHERE c.SSDCode='{0}' AND a.BusinessCode ='{7}' AND d.BatchCode='{8}' AND lot.InvCode='{1}'";
  2289. // ERPupdate = string.Format(ERPupdate);
  2290. // if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2291. // {
  2292. // throw new Exception(TransType + language.GetNameByCode("WMSAPIInfo175"));//"回写日志失败!");
  2293. // }
  2294. }
  2295. }
  2296. }
  2297. catch (Exception ex)
  2298. {
  2299. log.Debug(ex.ToString());
  2300. log.Debug(resultStr);
  2301. }
  2302. }
  2303. else
  2304. {
  2305. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2306. }
  2307. }
  2308. }
  2309. else
  2310. {
  2311. #region ERP开立状态单据审核
  2312. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2313. INTO #NewTempERP
  2314. from ICSWareHouseLotInfoLog
  2315. WHERE Identification='{0}' AND ERPUpload='0'
  2316. IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  2317. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  2318. AND b.Quantity!=ISNULL(b.InQuantity,0))
  2319. BEGIN
  2320. RAISERROR('" + language.GetNameByCode("WMSAPIInfo101") + @"',16,1);
  2321. RETURN
  2322. END
  2323. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2324. FROM #NewTempERP a
  2325. 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'
  2326. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2327. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  2328. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2329. DROP TABLE #NewTempERP";
  2330. sql = string.Format(sql, Identification);
  2331. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2332. string Inputstr = JsonConvert.SerializeObject(dt);
  2333. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OtherInDocURL, Inputstr);
  2334. Result result = new Result();
  2335. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2336. if (result.Success)
  2337. {
  2338. try
  2339. {
  2340. foreach (DataRow dr in dt.Rows)
  2341. {
  2342. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2343. }
  2344. }
  2345. catch (Exception ex)
  2346. {
  2347. log.Debug(ex.ToString());
  2348. log.Debug(resultStr);
  2349. }
  2350. }
  2351. else
  2352. {
  2353. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2354. }
  2355. #endregion
  2356. }
  2357. }
  2358. catch (Exception)
  2359. {
  2360. throw;
  2361. }
  2362. }
  2363. public static void OtherInRedDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2364. {
  2365. try
  2366. {
  2367. #region ERP开立状态单据审核
  2368. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2369. INTO #NewTempERP
  2370. from ICSWareHouseLotInfoLog
  2371. WHERE Identification='{0}' AND ERPUpload='0'
  2372. IF EXISTS(SELECT b.ID FROM ICSOtherIn b
  2373. WHERE b.InCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  2374. AND b.Quantity!=b.InQuantity)
  2375. BEGIN
  2376. RAISERROR('" + language.GetNameByCode("WMSAPIInfo101") + @"',16,1);
  2377. RETURN
  2378. END
  2379. SELECT b.InID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2380. FROM #NewTempERP a
  2381. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint AND b.Type='2'
  2382. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2383. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  2384. GROUP BY b.InID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2385. DROP TABLE #NewTempERP";
  2386. sql = string.Format(sql, Identification);
  2387. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2388. string Inputstr = JsonConvert.SerializeObject(dt);
  2389. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OtherInDocURL, Inputstr);
  2390. Result result = new Result();
  2391. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2392. if (result.Success)
  2393. {
  2394. try
  2395. {
  2396. foreach (DataRow dr in dt.Rows)
  2397. {
  2398. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2399. }
  2400. }
  2401. catch (Exception ex)
  2402. {
  2403. log.Debug(ex.ToString());
  2404. log.Debug(resultStr);
  2405. }
  2406. }
  2407. else
  2408. {
  2409. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2410. }
  2411. #endregion
  2412. }
  2413. catch (Exception)
  2414. {
  2415. throw;
  2416. }
  2417. }
  2418. /// <summary>
  2419. /// 创建U9杂收单接口
  2420. /// </summary>
  2421. /// <param name="TransType"></param>
  2422. /// <param name="Identification"></param>
  2423. /// <param name="cmd"></param>
  2424. public static void CreateOtherInDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2425. {
  2426. try
  2427. {
  2428. #region ERP开立状态单据审核
  2429. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2430. INTO #NewTempERP
  2431. from ICSWareHouseLotInfoLog
  2432. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='25'
  2433. 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,
  2434. b.EATTRIBUTE2 as DocType,b.EATTRIBUTE4 as ClientCode,
  2435. 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
  2436. ,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,
  2437. 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
  2438. ,b.EATTRIBUTE7 as Project,b.EATTRIBUTE1 as Dep
  2439. INTO #TempERP
  2440. FROM #NewTempERP a
  2441. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2442. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2443. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2444. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2445. INNER JOIN ICSOtherIn b ON a.TransCode=b.InCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2446. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2447. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock009' AND a.WorkPoint=conStock.WorkPoint
  2448. GROUP BY inv.AmountEnable,a.ToWarehouseCode,b.InCode,a.MUSER,a.InvCode,con.Enable,conStock.Enable,b.EATTRIBUTE4,b.EATTRIBUTE2
  2449. ,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, ''),
  2450. 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
  2451. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,DocType,ClientCode,InCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  2452. 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
  2453. DROP TABLE #TempERP
  2454. DROP TABLE #NewTempERP";
  2455. sql = string.Format(sql, Identification, BusinessCode);
  2456. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2457. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2458. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherInDocURL, Inputstr);
  2459. //sql = string.Format(sql, Identification);
  2460. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2461. //string Inputstr = JsonConvert.SerializeObject(dt);
  2462. //string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateOtherInDocURL, Inputstr);
  2463. Result result = new Result();
  2464. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2465. if (result.Success)
  2466. {
  2467. try
  2468. {
  2469. //foreach (DataRow dr in dt.Rows)
  2470. //{
  2471. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2472. //}
  2473. }
  2474. catch (Exception ex)
  2475. {
  2476. log.Debug(ex.ToString());
  2477. log.Debug(resultStr);
  2478. }
  2479. }
  2480. else
  2481. {
  2482. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2483. }
  2484. #endregion
  2485. }
  2486. catch (Exception)
  2487. {
  2488. throw;
  2489. }
  2490. }
  2491. #endregion
  2492. #region 拆卸单
  2493. /// <summary>
  2494. /// 拆卸单
  2495. /// </summary>
  2496. /// <param name="TransCode"></param>
  2497. /// <param name="TransSequence"></param>
  2498. /// <param name="Quantity"></param>
  2499. /// <param name="WorkPoint"></param>
  2500. /// <param name="cmd"></param>
  2501. public static void DisassemblyDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2502. {
  2503. try
  2504. {
  2505. log.Debug("拆卸111");
  2506. string sql = @"DECLARE @Status VARCHAR(10)
  2507. SELECT @Status=c.Status FROM ICSInventoryLot a
  2508. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2509. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2510. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DABDOCType='2'
  2511. IF (@Status IS NULL)
  2512. BEGIN
  2513. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2514. RETURN
  2515. END
  2516. ELSE IF (@Status!='1')
  2517. BEGIN
  2518. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  2519. RETURN
  2520. END
  2521. UPDATE c SET DABDOCQuantity=ISNULL(DABDOCQuantity,0)+'{2}'
  2522. FROM ICSInventoryLot a
  2523. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2524. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2525. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2526. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2527. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2528. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2529. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2530. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn024', c.Quantity,1,4,'')<c.DABDOCQuantity)
  2531. BEGIN
  2532. RAISERROR('" + language.GetNameByCode("WMSAPIInfo156") + @"',16,1);
  2533. END";
  2534. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2535. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2536. {
  2537. throw new Exception(language.GetNameByCode("WMSAPIInfo157"));//"拆卸单更新失败!");
  2538. }
  2539. log.Debug("拆卸222");
  2540. }
  2541. catch (Exception)
  2542. {
  2543. throw;
  2544. }
  2545. }
  2546. /// <summary>
  2547. /// 拆卸单更新套件锁定数量
  2548. /// </summary>
  2549. /// <param name="Identification"></param>
  2550. /// <param name="cmd"></param>
  2551. public static void DisassemblyDoc(string Identification, SqlCommand cmd, Dictionary<string, string> language)
  2552. {
  2553. try
  2554. {
  2555. log.Debug("拆卸单sql前");
  2556. string sql = @"select * into #table2 from ICSWareHouseLotInfoLog where transcode in(
  2557. select transcode from ICSWareHouseLotInfoLog where Identification='{0}')
  2558. UPDATE ICSDisassemblyDoc SET DABDOCQuantity=Quantity
  2559. WHERE DABDOCCode+Sequence+WorkPoint IN(SELECT DISTINCT d.TransCode+d.TransSequence+d.WorkPoint
  2560. FROM #table2 a
  2561. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2562. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2563. INNER JOIN #table2 d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  2564. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')
  2565. UPDATE ICSWareHouseLotInfo SET Quantity=Quantity-LockQuantity,LockQuantity=0
  2566. WHERE LotNo+WorkPoint IN(SELECT DISTINCT d.LotNo+d.WorkPoint
  2567. FROM #table2 a
  2568. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2569. INNER JOIN ICSDisassemblyDoc c ON b.TransCode=c.DABDOCCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2570. INNER JOIN #table2 d ON b.TransCode=d.TransCode AND d.TransSequence='1' AND b.WorkPoint=d.WorkPoint
  2571. WHERE a.Identification='{0}' AND d.ERPUpload='0' AND d.Lock='1')
  2572. DROP TABLE #table2
  2573. ";
  2574. sql = string.Format(sql, Identification);
  2575. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2576. {
  2577. throw new Exception(language.GetNameByCode("WMSAPIInfo158"));//"拆卸单套件更新失败!");
  2578. }
  2579. log.Debug("拆卸单sql后");
  2580. }
  2581. catch (Exception)
  2582. {
  2583. throw;
  2584. }
  2585. }
  2586. /// <summary>
  2587. /// 拆卸单接口
  2588. /// </summary>
  2589. /// <param name="TransType"></param>
  2590. /// <param name="Identification"></param>
  2591. /// <param name="cmd"></param>
  2592. public static void DisassemblyDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2593. {
  2594. try
  2595. {
  2596. #region ERP开立状态单据审核
  2597. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2598. INTO #NewTempERP
  2599. from ICSWareHouseLotInfoLog
  2600. WHERE Identification='{0}' AND ERPUpload='0'
  2601. IF EXISTS(SELECT b.ID FROM ICSDisassemblyDoc b
  2602. WHERE b.DABDOCCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  2603. AND b.Quantity!=b.DABDOCQuantity)
  2604. BEGIN
  2605. RAISERROR('" + language.GetNameByCode("WMSAPIInfo102") + @"',16,1);
  2606. RETURN
  2607. END
  2608. SELECT b.DABDOCID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2609. FROM #NewTempERP a
  2610. INNER JOIN ICSDisassemblyDoc b ON a.TransCode=b.DABDOCCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2611. INNER JOIN ICSConfiguration con ON con.Code='Stock003' AND a.WorkPoint=con.WorkPoint
  2612. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock006' AND a.WorkPoint=conStock.WorkPoint
  2613. GROUP BY b.DABDOCID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2614. DROP TABLE #NewTempERP";
  2615. sql = string.Format(sql, Identification);
  2616. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2617. string Inputstr = JsonConvert.SerializeObject(dt);
  2618. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DisassemblyDocURL, Inputstr);
  2619. Result result = new Result();
  2620. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2621. if (result.Success)
  2622. {
  2623. try
  2624. {
  2625. foreach (DataRow dr in dt.Rows)
  2626. {
  2627. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2628. }
  2629. }
  2630. catch (Exception ex)
  2631. {
  2632. log.Debug(ex.ToString());
  2633. log.Debug(resultStr);
  2634. }
  2635. }
  2636. else
  2637. {
  2638. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2639. }
  2640. #endregion
  2641. }
  2642. catch (Exception)
  2643. {
  2644. throw;
  2645. }
  2646. }
  2647. #endregion
  2648. #region 借用
  2649. /// <summary>
  2650. /// 借用
  2651. /// </summary>
  2652. /// <param name="TransCode"></param>
  2653. /// <param name="TransSequence"></param>
  2654. /// <param name="Quantity"></param>
  2655. /// <param name="WorkPoint"></param>
  2656. /// <param name="cmd"></param>
  2657. public static void BrrowDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2658. {
  2659. try
  2660. {
  2661. string sql = @"DECLARE @Status VARCHAR(10)
  2662. SELECT @Status=a.Status FROM ICSBrrow a
  2663. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  2664. IF (@Status IS NULL)
  2665. BEGIN
  2666. RAISERROR('" + language.GetNameByCode("WMSAPIInfo159") + @"',16,1);
  2667. RETURN
  2668. END
  2669. ELSE IF (@Status!='2')
  2670. BEGIN
  2671. RAISERROR('" + language.GetNameByCode("WMSAPIInfo160") + @"',16,1);
  2672. RETURN
  2673. END
  2674. UPDATE a SET BrrowQuantity=ISNULL(BrrowQuantity,0)+'{2}'
  2675. FROM ICSBrrow a
  2676. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  2677. IF EXISTS(SELECT a.ID FROM ICSBrrow a
  2678. WHERE a.BrrowCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.BrrowQuantity)
  2679. BEGIN
  2680. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  2681. RETURN
  2682. END";
  2683. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  2684. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2685. {
  2686. throw new Exception(language.GetNameByCode("WMSAPIInfo161"));//"借用单更新失败!");
  2687. }
  2688. }
  2689. catch (Exception)
  2690. {
  2691. throw;
  2692. }
  2693. }
  2694. /// <summary>
  2695. /// 借用接口
  2696. /// </summary>
  2697. /// <param name="TransType"></param>
  2698. /// <param name="Identification"></param>
  2699. /// <param name="cmd"></param>
  2700. public static void BrrowDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2701. {
  2702. try
  2703. {
  2704. #region ERP
  2705. string sql = string.Empty;
  2706. if (!DBHelper.IsBBU9())
  2707. {
  2708. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2709. INTO #NewTempERP
  2710. from ICSWareHouseLotInfoLog
  2711. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '26'
  2712. 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,
  2713. 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
  2714. ,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,
  2715. 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
  2716. INTO #TempERP
  2717. FROM #NewTempERP a
  2718. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2719. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2720. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2721. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2722. INNER JOIN ICSBrrow b ON a.TransCode=b.BrrowCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2723. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2724. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock008' AND a.WorkPoint=conStock.WorkPoint
  2725. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2726. GROUP BY conWhCode.Enable,inv.AmountEnable,a.FromWarehouseCode,b.BrrowCode,a.MUSER,a.InvCode,b.BrrowDetailID,con.Enable,conStock.Enable
  2727. ,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, ''),
  2728. 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, '')
  2729. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,BrrowCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  2730. 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
  2731. DROP TABLE #TempERP
  2732. DROP TABLE #NewTempERP";
  2733. sql = string.Format(sql, Identification);
  2734. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2735. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2736. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.BrrowDocURL, Inputstr);
  2737. Result result = new Result();
  2738. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2739. if (result.Success)
  2740. {
  2741. try
  2742. {
  2743. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2744. foreach (var item in res)
  2745. {
  2746. JObject jo = (JObject)item;
  2747. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2748. foreach (var detail in resdetail)
  2749. {
  2750. JObject det = (JObject)detail;
  2751. 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()
  2752. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2753. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2754. det["DetailID"].ToString(), jo["OtherOutCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2755. }
  2756. }
  2757. }
  2758. catch (Exception ex)
  2759. {
  2760. log.Debug(ex.ToString());
  2761. log.Debug(resultStr);
  2762. }
  2763. }
  2764. else
  2765. {
  2766. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2767. }
  2768. }
  2769. else
  2770. {
  2771. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2772. INTO #NewTempERP
  2773. from ICSWareHouseLotInfoLog
  2774. WHERE Identification='{0}' AND ERPUpload='0'
  2775. IF EXISTS(SELECT b.ID FROM ICSBrrow b
  2776. WHERE b.BrrowCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  2777. AND b.Quantity!=ISNULL(b.BrrowQuantity,0))
  2778. BEGIN
  2779. RAISERROR('',16,1);
  2780. RETURN
  2781. END
  2782. SELECT b.BrrowCode AS DocNO,a.MUSER AS [User],SYSDATETIME() AS MTime,a.WorkPoint
  2783. FROM #NewTempERP a
  2784. INNER JOIN ICSBrrow b ON a.TransCode=b.BrrowCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2785. GROUP BY b.BrrowCode,a.MUSER,a.WorkPoint
  2786. DROP TABLE #NewTempERP";
  2787. sql = string.Format(sql, Identification);
  2788. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2789. string Inputstr = JsonConvert.SerializeObject(dt);
  2790. Inputstr = Inputstr.Replace("[", "");
  2791. Inputstr = Inputstr.Replace("]", "");
  2792. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.BrrowDocApproveURL, Inputstr);
  2793. Result result = new Result();
  2794. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2795. if (result.Success)
  2796. {
  2797. try
  2798. {
  2799. foreach (DataRow dr in dt.Rows)
  2800. {
  2801. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2802. }
  2803. }
  2804. catch (Exception ex)
  2805. {
  2806. log.Debug(ex.ToString());
  2807. log.Debug(resultStr);
  2808. }
  2809. }
  2810. else
  2811. {
  2812. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2813. }
  2814. }
  2815. #endregion
  2816. }
  2817. catch (Exception)
  2818. {
  2819. throw;
  2820. }
  2821. }
  2822. #endregion
  2823. #region 归还
  2824. /// <summary>
  2825. /// 归还
  2826. /// </summary>
  2827. /// <param name="TransCode"></param>
  2828. /// <param name="TransSequence"></param>
  2829. /// <param name="Quantity"></param>
  2830. /// <param name="WorkPoint"></param>
  2831. /// <param name="cmd"></param>
  2832. public static void ReturnDoc(string TransCode, string TransSequence, string LotNo, string LogID, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2833. {
  2834. try
  2835. {
  2836. string sql = string.Empty;
  2837. if (string.IsNullOrEmpty(LogID))
  2838. {
  2839. sql = @"DECLARE @Status VARCHAR(10)
  2840. SELECT @Status=c.Status FROM ICSInventoryLot a
  2841. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2842. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2843. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2844. IF (@Status IS NULL)
  2845. BEGIN
  2846. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2847. RETURN
  2848. END
  2849. ELSE IF (@Status!='2')
  2850. BEGIN
  2851. RAISERROR('" + language.GetNameByCode("WMSAPIInfo142") + @"',16,1);
  2852. RETURN
  2853. END
  2854. UPDATE c SET ReturnQuantity=ISNULL(ReturnQuantity,0)+'{2}'
  2855. FROM ICSInventoryLot a
  2856. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2857. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2858. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2859. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2860. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2861. INNER JOIN ICSReturn c ON b.TransCode=c.ReturnCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2862. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  2863. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn023', c.Quantity,1,4,'')<c.ReturnQuantity)
  2864. BEGIN
  2865. RAISERROR('" + language.GetNameByCode("WMSAPIInfo162") + @"',16,1);
  2866. END";
  2867. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2868. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2869. {
  2870. throw new Exception(language.GetNameByCode("WMSAPIInfo163"));//"归还单更新失败!");
  2871. }
  2872. }
  2873. else
  2874. {
  2875. sql = @"DECLARE @Status VARCHAR(10)
  2876. SELECT @Status=a.Status FROM ICSReturn a
  2877. WHERE a.ReturnCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  2878. IF (@Status IS NULL)
  2879. BEGIN
  2880. RAISERROR('" + language.GetNameByCode("WMSAPIInfo151") + @"',16,1);
  2881. RETURN
  2882. END
  2883. ELSE IF (@Status!='2')
  2884. BEGIN
  2885. RAISERROR('" + language.GetNameByCode("WMSAPIInfo152") + @"',16,1);
  2886. RETURN
  2887. END
  2888. UPDATE a SET ReturnQuantity=ISNULL(ReturnQuantity,0)+'{2}'
  2889. FROM ICSReturn a
  2890. WHERE a.ReturnCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  2891. IF EXISTS(SELECT a.ID FROM ICSReturn a
  2892. WHERE a.ReturnCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.ReturnQuantity)
  2893. BEGIN
  2894. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  2895. RETURN
  2896. END";
  2897. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  2898. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2899. {
  2900. throw new Exception(language.GetNameByCode("WMSAPIInfo163"));//"归还单更新失败!");
  2901. }
  2902. }
  2903. }
  2904. catch (Exception)
  2905. {
  2906. throw;
  2907. }
  2908. }
  2909. /// <summary>
  2910. /// 归还接口
  2911. /// </summary>
  2912. /// <param name="TransType"></param>
  2913. /// <param name="Identification"></param>
  2914. /// <param name="cmd"></param>
  2915. public static void ReturnDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2916. {
  2917. try
  2918. {
  2919. #region ERP
  2920. string sql = string.Empty;
  2921. if (!DBHelper.IsBBU9())
  2922. {
  2923. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2924. INTO #NewTempERP
  2925. from ICSWareHouseLotInfoLog
  2926. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  2927. 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,
  2928. 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
  2929. ,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,
  2930. 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
  2931. INTO #TempERP
  2932. FROM #NewTempERP a
  2933. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2934. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2935. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2936. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2937. INNER JOIN ICSReturn b ON a.TransCode=b.ReturnCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2938. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2939. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock009' AND a.WorkPoint=conStock.WorkPoint
  2940. GROUP BY inv.AmountEnable,a.ToWarehouseCode,b.ReturnCode,a.MUSER,a.InvCode,b.ReturnDetailID,con.Enable,conStock.Enable
  2941. ,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, ''),
  2942. 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, '')
  2943. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ReturnCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  2944. 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
  2945. DROP TABLE #TempERP
  2946. DROP TABLE #NewTempERP";
  2947. sql = string.Format(sql, Identification, BusinessCode);
  2948. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2949. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2950. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ReturnDocURL, Inputstr);
  2951. Result result = new Result();
  2952. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2953. if (result.Success)
  2954. {
  2955. try
  2956. {
  2957. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2958. foreach (var item in res)
  2959. {
  2960. JObject jo = (JObject)item;
  2961. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2962. foreach (var detail in resdetail)
  2963. {
  2964. JObject det = (JObject)detail;
  2965. 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()
  2966. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2967. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2968. det["DetailID"].ToString(), jo["OtherInCode"].ToString(), det["Sequence"].ToString(), "", cmd, language, BusinessCode);
  2969. }
  2970. }
  2971. }
  2972. catch (Exception ex)
  2973. {
  2974. log.Debug(ex.ToString());
  2975. log.Debug(resultStr);
  2976. }
  2977. }
  2978. else
  2979. {
  2980. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2981. }
  2982. }
  2983. else
  2984. {
  2985. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  2986. INTO #NewTempERP
  2987. from ICSWareHouseLotInfoLog
  2988. WHERE Identification='{0}' AND ERPUpload='0'
  2989. IF EXISTS(SELECT b.ID FROM ICSReturn b
  2990. WHERE b.ReturnCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  2991. AND b.Quantity!=ISNULL(b.ReturnQuantity,0))
  2992. BEGIN
  2993. RAISERROR('',16,1);
  2994. RETURN
  2995. END
  2996. SELECT b.ReturnCode AS DocNO,a.MUSER AS [User],SYSDATETIME() AS MTime,a.WorkPoint
  2997. FROM #NewTempERP a
  2998. INNER JOIN ICSReturn b ON a.TransCode=b.ReturnCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2999. GROUP BY b.ReturnCode,a.MUSER,a.WorkPoint
  3000. DROP TABLE #NewTempERP";
  3001. sql = string.Format(sql, Identification);
  3002. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3003. string Inputstr = JsonConvert.SerializeObject(dt);
  3004. Inputstr = Inputstr.Replace("[", "");
  3005. Inputstr = Inputstr.Replace("]", "");
  3006. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ReturnDocApproveURL, Inputstr);
  3007. Result result = new Result();
  3008. result = JsonConvert.DeserializeObject<Result>(resultStr);
  3009. if (result.Success)
  3010. {
  3011. try
  3012. {
  3013. foreach (DataRow dr in dt.Rows)
  3014. {
  3015. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  3016. }
  3017. }
  3018. catch (Exception ex)
  3019. {
  3020. log.Debug(ex.ToString());
  3021. log.Debug(resultStr);
  3022. }
  3023. }
  3024. else
  3025. {
  3026. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  3027. }
  3028. }
  3029. #endregion
  3030. }
  3031. catch (Exception)
  3032. {
  3033. throw;
  3034. }
  3035. }
  3036. #endregion
  3037. #endregion
  3038. #region 工单关联
  3039. /// <summary>
  3040. /// 工单关联
  3041. /// </summary>
  3042. /// <param name="TransCode"></param>
  3043. /// <param name="TransSequence"></param>
  3044. /// <param name="Quantity"></param>
  3045. /// <param name="WorkPoint"></param>
  3046. /// <param name="cmd"></param>
  3047. public static void ICSMOReceive(string LotNo, string Quantity, string TransCode, string TransSequence, string WorkPoint, string Identification, string User, string SRMLotGroup,
  3048. string ProjectCode, string BatchCode, string Version, string Brand, string cFree1, string cFree2, string cFree3, string cFree4, string cFree5,
  3049. string cFree6, string cFree7, string cFree8, string cFree9, string cFree10, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3050. {
  3051. try
  3052. {
  3053. decimal LOTQTY = 0;
  3054. decimal MOQTY = 0;
  3055. String EffectiveEnable = "";
  3056. String Colspan = "";
  3057. String IDD = "";
  3058. int EffectiveDays = 0;
  3059. String Time = "";
  3060. int EffectiveDayss = 0;
  3061. DateTime dtt;
  3062. DateTime now = DateTime.Now;
  3063. string sql = @"select * from ICSInventoryLotDetail
  3064. where LotNo='{0}' and WorkPoint='{1}'
  3065. ";
  3066. sql = string.Format(sql, LotNo, WorkPoint);
  3067. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  3068. if (dttte.Rows.Count > 0)
  3069. {
  3070. sql = @"IF NOT EXISTS(select * from ICSMO b
  3071. where b.MOCODE='{2}' and b.WorkPoint='{1}' and b.EATTRIBUTE1='1')
  3072. BEGIN
  3073. select * from ICSInventoryLotDetail a
  3074. left join ICSMO b ON a.transcode=b.mocode and a.WorkPoint=b.WorkPoint
  3075. where a.LotNo='{0}' and a.WorkPoint='{1}' and a.TransCode = ''
  3076. END
  3077. ELSE
  3078. BEGIN
  3079. select * from ICSInventoryLotDetail
  3080. where LotNo='{0}' and WorkPoint='{1}'
  3081. END";
  3082. sql = string.Format(sql, LotNo, WorkPoint, TransCode);
  3083. DataTable tt = DBHelper.SQlReturnData(sql, cmd);
  3084. if (tt.Rows.Count > 0)
  3085. {
  3086. ///修改条码关联表
  3087. sql = @"update ICSInventoryLotDetail set TransCode='{0}',TransSequence='{1}'
  3088. where lotno='{3}' and WorkPoint='{2}'
  3089. ";
  3090. sql = string.Format(sql, TransCode, TransSequence, WorkPoint, LotNo);
  3091. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3092. {
  3093. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  3094. }
  3095. ///修改条码表
  3096. sql = @"update ICSInventoryLot set InvCode=(select a.InvCode from ICSMO a where a.MOCode='{0}' and a.Sequence='{1}')
  3097. where lotno='{3}' and WorkPoint='{2}'
  3098. ";
  3099. sql = string.Format(sql, TransCode, TransSequence, WorkPoint, LotNo);
  3100. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3101. {
  3102. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  3103. }
  3104. }
  3105. else
  3106. {
  3107. throw new Exception(language.GetNameByCode("WMSAPIInfo374"));
  3108. }
  3109. }
  3110. else
  3111. {
  3112. sql = @"select EffectiveEnable,EffectiveDays from ICSInventory a
  3113. Left Join ICSMO b ON a.InvCode=b.InvCode and a.WorkPoint = b.WorkPoint
  3114. where b.MoCode='{0}' and b.WorkPoint='{1}'";
  3115. sql = string.Format(sql, TransCode, WorkPoint);
  3116. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3117. if (dt.Rows.Count == 0)
  3118. {
  3119. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  3120. }
  3121. else
  3122. {
  3123. EffectiveEnable = dt.Rows[0]["EffectiveEnable"].ToString();
  3124. EffectiveDays = Convert.ToInt32(dt.Rows[0]["EffectiveDays"]);
  3125. }
  3126. //EffectiveDayss = Convert.ToInt32(EffectiveDays);
  3127. if (!EffectiveEnable.Equals("False"))
  3128. {
  3129. Time = DBHelper.ReTime(now, EffectiveDays);
  3130. }
  3131. else
  3132. {
  3133. Time = "2999-12-31 00:00:00.000";
  3134. }
  3135. dtt = Convert.ToDateTime(Time);
  3136. sql = @"DECLARE @aa VARCHAR(10)
  3137. DECLARE @bb VARCHAR(10)
  3138. SELECT @aa=a.EATTRIBUTE1 FROM ICSMO a
  3139. WHERE a.MOCode='{0}' and a.WorkPoint='{1}'
  3140. print @aa
  3141. IF(@aa='1')
  3142. BEGIN
  3143. select Count(c.lotno) AS LOTQTY,a.Quantity+ISNULL((select SUM(b.Quantity) from ICSMO a
  3144. left join ICSMOPick b on a.MODetailID=b.MODetailID and a.WorkPoint=b.WorkPoint
  3145. where a.MOCode='{0}' and a.EATTRIBUTE1='1' and b.EATTRIBUTE1='1' and a.WorkPoint='{1}'),0) AS MOQTY
  3146. from ICSMO a
  3147. left join ICSInventoryLotDetail bb on a.MOCode=bb.TransCode and a.WorkPoint=bb.WorkPoint
  3148. left join ICSInventoryLot c on bb.LotNo=c.LotNo and c.WorkPoint=bb.WorkPoint
  3149. where a.MOCode='{0}' and a.WorkPoint='{1}'
  3150. group by a.Quantity
  3151. END
  3152. ELSE
  3153. BEGIN
  3154. select Count(bb.lotno) AS LOTQTY,a.Quantity AS MOQTY
  3155. from ICSMO a
  3156. left join ICSInventoryLotDetail bb on a.MOCode=bb.TransCode and a.Sequence=bb.transSequence and a.WorkPoint=bb.WorkPoint
  3157. left join ICSInventoryLot c on bb.LotNo=c.LotNo and c.WorkPoint=bb.WorkPoint
  3158. where a.MOCode='{0}' and a.WorkPoint='{1}'
  3159. group by a.Quantity
  3160. END
  3161. ";
  3162. sql = string.Format(sql, TransCode, WorkPoint);
  3163. DataTable dtttt = DBHelper.SQlReturnData(sql, cmd);
  3164. LOTQTY = Convert.ToDecimal(dtttt.Rows[0]["LOTQTY"]);
  3165. MOQTY = Convert.ToDecimal(dtttt.Rows[0]["MOQTY"]);
  3166. sql = @"select * from ICSInventoryLot
  3167. where LotNo='{0}' and WorkPoint='{1}'
  3168. ";
  3169. sql = string.Format(sql, LotNo, WorkPoint);
  3170. DataTable dttaa = DBHelper.SQlReturnData(sql, cmd);
  3171. if (LOTQTY < MOQTY)
  3172. {
  3173. //检验自由项
  3174. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  3175. + "~" + Brand + "~" + cFree1
  3176. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  3177. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  3178. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  3179. sql = @"select ID,Colspan from ICSExtension a
  3180. where Colspan='{0}' and WorkPoint='{1}'";
  3181. sql = string.Format(sql, Colspan, WorkPoint);
  3182. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  3183. if (dttt.Rows.Count == 0)
  3184. {
  3185. IDD = Guid.NewGuid().ToString();
  3186. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  3187. 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}'";
  3188. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  3189. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3190. {
  3191. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  3192. }
  3193. }
  3194. else
  3195. {
  3196. IDD = dttt.Rows[0]["ID"].ToString();
  3197. }
  3198. if (dttaa.Rows.Count == 0)
  3199. {
  3200. //存入条码表
  3201. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  3202. BEGIN
  3203. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3204. RETURN
  3205. END
  3206. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,
  3207. Quantity,Amount,ExtensionID,Type,PrintTimes,
  3208. LastPrintUser,LastPrintTime,MUSER,MUSERName,MTIME,
  3209. WorkPoint,EATTRIBUTE1)
  3210. SELECT TOP 1 NEWID(),'{0}',a.InvCode,GETDATE(),'{6}',
  3211. 1,'0','{7}','90',null,
  3212. null,null,'{2}' ,f.F_RealName ,GETDATE(),
  3213. '{4}' ,''
  3214. FROM ICSMO a
  3215. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3216. INNER JOIN ICSExtension b ON a.ExtensionID=b.ID AND a.WorkPoint=b.WorkPoint
  3217. INNER JOIN ICSInventory c ON a.InvCode=c.InvCode AND a.WorkPoint=c.WorkPoint
  3218. where a.MOCode='{3}' and a.Sequence='{5}' and a.WorkPoint='{4}'
  3219. ";
  3220. sql = string.Format(sql, LotNo, Quantity, User, TransCode, WorkPoint, TransSequence, dtt, IDD);
  3221. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3222. {
  3223. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  3224. }
  3225. }
  3226. ///存入条码关联表
  3227. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{3}')
  3228. BEGIN
  3229. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3230. RETURN
  3231. END
  3232. INSERT INTO ICSInventoryLotDetail(LotNo,TransCode,TransSequence,MUSER,MUSERName,MTIME,
  3233. WorkPoint,EATTRIBUTE1)
  3234. SELECT a.LotNo,'{0}','{1}',f.F_Account ,f.F_RealName,GETDATE(),
  3235. a.WorkPoint,''
  3236. FROM ICSInventoryLot a
  3237. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  3238. WHERE a.LotNo='{4}' AND a.WorkPoint='{3}'
  3239. ";
  3240. sql = string.Format(sql, TransCode, TransSequence, User, WorkPoint, LotNo);
  3241. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3242. {
  3243. throw new Exception(language.GetNameByCode("WMSAPIInfo367"));
  3244. }
  3245. }
  3246. else
  3247. {
  3248. throw new Exception(language.GetNameByCode("WMSAPIInfo373"));//條碼綁定工單失敗!數量已滿!
  3249. }
  3250. }
  3251. }
  3252. catch (Exception)
  3253. {
  3254. throw;
  3255. }
  3256. }
  3257. public static void ICSMOReceiveUntie(string LotNo, string WorkPoint, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3258. {
  3259. try
  3260. {
  3261. DateTime now = DateTime.Now;
  3262. string sql = @"select * from ICSInventoryLotDetail
  3263. where LotNo='{0}' and WorkPoint='{1}'
  3264. ";
  3265. sql = string.Format(sql, LotNo, WorkPoint);
  3266. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  3267. if (dttte.Rows.Count > 0)
  3268. {
  3269. ///删除条码关联表数据
  3270. sql = @"DELETE FROM [dbo].[ICSInventoryLotDetail] WHERE LotNo='{0}' AND WorkPoint='{1}'
  3271. ";
  3272. sql = string.Format(sql, LotNo, WorkPoint);
  3273. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3274. {
  3275. throw new Exception(language.GetNameByCode("WMSAPIInfo464"));
  3276. }
  3277. sql = @"DELETE FROM [dbo].[ICSInventoryLot] WHERE LotNo = '{0}' AND WorkPoint = '{1}'
  3278. ";
  3279. sql = string.Format(sql, LotNo, WorkPoint);
  3280. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3281. {
  3282. throw new Exception(language.GetNameByCode("WMSAPIInfo464"));
  3283. }
  3284. }
  3285. else
  3286. {
  3287. throw new Exception(language.GetNameByCode("WMSAPIInfo465"));
  3288. }
  3289. }
  3290. catch (Exception)
  3291. {
  3292. throw;
  3293. }
  3294. }
  3295. #endregion
  3296. #region 容器条码绑定
  3297. public static bool ICSContainerLot(string LotNo, string containerCode, string WorkPoint, string Identification, string User,
  3298. string ProjectCode, string BatchCode, string Version, string Brand, string cFree1, string cFree2, string cFree3, string cFree4, string cFree5,
  3299. string cFree6, string cFree7, string cFree8, string cFree9, string cFree10, string BusinessCode, SqlCommand cmd, Dictionary<string, string> language)
  3300. {
  3301. try
  3302. {
  3303. bool flag = false;
  3304. string Colspan = "";
  3305. string IDD = "";
  3306. string Time = "";
  3307. DateTime dtt;
  3308. DateTime now = DateTime.Now;
  3309. string sql = @"select * FROM ICSContainerLot WHERE LotNo='{0}' AND WorkPoint='{1}'
  3310. ";
  3311. sql = string.Format(sql, LotNo, WorkPoint);
  3312. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  3313. if (dttte.Rows.Count > 0)
  3314. {
  3315. ///修改容器关联表
  3316. sql = @"UPDATE ICSContainerLot SET ContainerID=(SELECT ID FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}' )
  3317. where lotno='{2}' and WorkPoint='{1}'
  3318. ";
  3319. sql = string.Format(sql, containerCode, WorkPoint, LotNo);
  3320. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3321. {
  3322. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo525"), containerCode, LotNo));
  3323. }
  3324. flag = true;
  3325. }
  3326. else
  3327. {
  3328. sql = @"select 1 from ICSInventoryLot
  3329. where LotNo='{0}' and WorkPoint='{1}'
  3330. ";
  3331. sql = string.Format(sql, LotNo, WorkPoint);
  3332. DataTable dttaa = DBHelper.SQlReturnData(sql, cmd);
  3333. if (dttaa.Rows.Count > 0)
  3334. {
  3335. //检验自由项
  3336. Colspan = ProjectCode + "~" + BatchCode + "~" + Version
  3337. + "~" + Brand + "~" + cFree1
  3338. + "~" + cFree2 + "~" + cFree3 + "~" + cFree4
  3339. + "~" + cFree5 + "~" + cFree6 + "~" + cFree7
  3340. + "~" + cFree8 + "~" + cFree9 + "~" + cFree10;
  3341. sql = @"select ID,Colspan from ICSExtension a
  3342. where Colspan='{0}' and WorkPoint='{1}'";
  3343. sql = string.Format(sql, Colspan, WorkPoint);
  3344. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  3345. if (dttt.Rows.Count == 0)
  3346. {
  3347. IDD = Guid.NewGuid().ToString();
  3348. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  3349. 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}'";
  3350. sql = string.Format(sql, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, User, WorkPoint, IDD);
  3351. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3352. {
  3353. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  3354. }
  3355. }
  3356. else
  3357. {
  3358. IDD = dttt.Rows[0]["ID"].ToString();
  3359. }
  3360. Time = "2999-12-31 00:00:00.000";
  3361. dtt = Convert.ToDateTime(Time);
  3362. ///存入容器关联表
  3363. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  3364. BEGIN
  3365. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  3366. RETURN
  3367. END
  3368. INSERT INTO ICSContainerLot(ID,ContainerID,LotNo,MUSER,MUSERName,WorkPoint,MTIME)
  3369. SELECT NEWID(),a.ID,'{3}','{1}',f.F_RealName,'{2}',GETDATE()
  3370. FROM ICSContainer a
  3371. INNER JOIN Sys_SRM_User f ON f.F_Account='{1}' AND a.WorkPoint=f.F_Location
  3372. WHERE a.ContainerCode='{0}' AND WorkPoint='{2}'
  3373. ";
  3374. sql = string.Format(sql, containerCode, User, WorkPoint, LotNo);
  3375. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3376. {
  3377. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo525"), containerCode, LotNo));
  3378. }
  3379. ///记录日志
  3380. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  3381. 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}' and F_Location ='{3}'), '{3}', GETDATE())";
  3382. sql = string.Format(sql, containerCode, LotNo, User, WorkPoint);
  3383. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3384. {
  3385. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo526"), containerCode, LotNo));
  3386. }
  3387. flag = true;
  3388. }
  3389. }
  3390. return flag;
  3391. }
  3392. catch (Exception ex)
  3393. {
  3394. log.Error(ex.Message);
  3395. //return false;
  3396. throw;
  3397. }
  3398. }
  3399. /// <summary>
  3400. /// 容器条码解绑
  3401. /// </summary>
  3402. /// <param name="LotNo"></param>
  3403. /// <param name="WorkPoint"></param>
  3404. /// <param name="User"></param>
  3405. /// <param name="cmd"></param>
  3406. /// <param name="language"></param>
  3407. public static bool ICSContainerLotUntie(string ContainerCode, string LotNo, string WorkPoint, string User, string Type, SqlCommand cmd, Dictionary<string, string> language)
  3408. {
  3409. try
  3410. {
  3411. DateTime now = DateTime.Now;
  3412. string sql = @"select 1 from ICSContainerLot
  3413. where ContainerID=(SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{2}') AND LotNo='{0}' and WorkPoint='{1}'
  3414. ";
  3415. sql = string.Format(sql, LotNo, WorkPoint, ContainerCode);
  3416. log.Debug("查询容器条码关联表是否存在sql:" + sql);
  3417. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  3418. if (dttte.Rows.Count > 0)
  3419. {
  3420. ///删除条码关联表数据
  3421. sql = @"DELETE FROM ICSContainerLot
  3422. where ContainerID=(SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{2}') AND LotNo='{0}' and WorkPoint='{1}'
  3423. ";
  3424. sql = string.Format(sql, LotNo, WorkPoint, ContainerCode);
  3425. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3426. {
  3427. throw new Exception("容器条码关联表数据删除失败");
  3428. }
  3429. ///记录日志
  3430. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  3431. 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}' and F_Location ='{3}' ), '{3}', GETDATE())";
  3432. sql = string.Format(sql, ContainerCode, LotNo, User, WorkPoint, Type);
  3433. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3434. {
  3435. throw new Exception("条码解绑容器记录日志表失败");
  3436. }
  3437. return true;
  3438. }
  3439. else
  3440. {
  3441. throw new Exception(language.GetNameByCode("容器条码关联表不存在容器" + ContainerCode + "与条码" + LotNo + "的绑定关系"));
  3442. }
  3443. }
  3444. catch (Exception)
  3445. {
  3446. throw;
  3447. }
  3448. }
  3449. /// <summary>
  3450. /// 容器绑定父容器
  3451. /// </summary>
  3452. /// <param name="superiorContainerCode"></param>
  3453. /// <param name="containerCode"></param>
  3454. /// <param name="WorkPoint"></param>
  3455. /// <param name="User"></param>
  3456. /// <param name="Type"></param>
  3457. /// <param name="cmd"></param>
  3458. /// <param name="language"></param>
  3459. /// <returns></returns>
  3460. public static bool ICSContainerCon(string superiorContainerCode, string containerCode, string WorkPoint, string User, string MTIME, string Type, SqlCommand cmd, Dictionary<string, string> language)
  3461. {
  3462. try
  3463. {
  3464. Boolean flag = false;
  3465. DateTime now = DateTime.Now;
  3466. string superiorContainerID = "";
  3467. string sql = @"SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}'";
  3468. sql = string.Format(sql, superiorContainerCode, WorkPoint);
  3469. DataTable dataTable = DBHelper.SQlReturnData(sql, cmd);
  3470. if (dataTable.Rows.Count == 0)
  3471. {
  3472. throw new Exception("父容器不存在");
  3473. }
  3474. else
  3475. {
  3476. //绑定父容器
  3477. superiorContainerID = dataTable.Rows[0]["ID"].ToString();
  3478. 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}'";
  3479. sql = string.Format(sql, superiorContainerID, User, MTIME, containerCode, WorkPoint);
  3480. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3481. {
  3482. throw new Exception("绑定父容器失败");
  3483. }
  3484. //添加日志
  3485. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  3486. 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}' and F_Location ='{3}'), '{3}', GETDATE())";
  3487. sql = string.Format(sql, superiorContainerCode, containerCode, User, WorkPoint, Type);
  3488. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3489. {
  3490. throw new Exception("日志记录失败");
  3491. }
  3492. flag = true;
  3493. }
  3494. return flag;
  3495. }
  3496. catch (Exception ex)
  3497. {
  3498. log.Error(ex.Message);
  3499. //return false;
  3500. throw;
  3501. }
  3502. }
  3503. /// <summary>
  3504. /// 容器解绑父容器
  3505. /// </summary>
  3506. /// <param name="ContainerCode"></param>
  3507. /// <param name="WorkPoint"></param>
  3508. /// <param name="User"></param>
  3509. /// <param name="Type"></param>
  3510. /// <param name="MTIME"></param>
  3511. /// <param name="cmd"></param>
  3512. /// <param name="language"></param>
  3513. /// <returns></returns>
  3514. public static bool ICSContainerConUntie(string ContainerCode, string WorkPoint, string User, string Type, SqlCommand cmd, Dictionary<string, string> language)
  3515. {
  3516. try
  3517. {
  3518. //添加日志
  3519. string sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  3520. VALUES(NEWID(), '', '{0}', '{3}', '{1}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}'), '{2}', GETDATE())";
  3521. sql = string.Format(sql, ContainerCode, User, WorkPoint, Type);
  3522. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3523. {
  3524. throw new Exception("日志记录失败");
  3525. }
  3526. //容器表父容器ID清空
  3527. sql = string.Format(@"UPDATE ICSContainer SET ContainerID='',MUSER='{2}',
  3528. MUSERName=(SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')
  3529. ,MTIME=GETDATE()
  3530. WHERE ContainerCode='{0}' AND WorkPoint='{1}'",
  3531. ContainerCode, WorkPoint, User);
  3532. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3533. {
  3534. throw new Exception("容器解绑父容器失败");
  3535. }
  3536. return true;
  3537. }
  3538. catch (Exception)
  3539. {
  3540. throw;
  3541. }
  3542. }
  3543. #endregion
  3544. #region 车次条码清单
  3545. public static bool ICSCartScheduleCreate(string LotNo, string Quantity, string CartNo, string User, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  3546. {
  3547. try
  3548. {
  3549. bool flag = false;
  3550. string sql = @"INSERT INTO dbo.ICSCartLotNoCheckList (id,CartNo,LotNo,MUSER,MUSERName,MTIME,WorkPoint,Quantity)
  3551. VALUES(NEWID(),'{0}','{1}','{2}','{2}',CONVERT(VARCHAR,GETDATE(),120),'{3}','{4}')";
  3552. sql = string.Format(sql, CartNo, LotNo, User, WorkPoint, "" == Quantity ? null : Quantity);
  3553. log.Debug("生成车次条码清单:" + sql);
  3554. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3555. {
  3556. throw new Exception("生成车次条码清单失败!");
  3557. }
  3558. flag = true;
  3559. return flag;
  3560. }
  3561. catch (Exception ex)
  3562. {
  3563. log.Error(ex.Message);
  3564. //return false;
  3565. throw;
  3566. }
  3567. }
  3568. #endregion
  3569. /// <summary>
  3570. /// 入库时解绑条码与容器
  3571. /// </summary>
  3572. /// <param name="ContainerCode"></param>
  3573. /// <param name="LotNo"></param>
  3574. /// <param name="WorkPoint"></param>
  3575. /// <param name="User"></param>
  3576. /// <param name="Type"></param>
  3577. /// <param name="cmd"></param>
  3578. /// <param name="language"></param>
  3579. /// <returns></returns>
  3580. public static bool ICSContainerLotUntieWhenIn(string ContainerCode, string LotNo, string WorkPoint, string User, string Type, SqlCommand cmd, Dictionary<string, string> language)
  3581. {
  3582. try
  3583. {
  3584. DateTime now = DateTime.Now;
  3585. string sql = @"select 1 from ICSContainerLot
  3586. where ContainerID=(SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{2}') AND LotNo='{0}' and WorkPoint='{1}'
  3587. ";
  3588. sql = string.Format(sql, LotNo, WorkPoint, ContainerCode);
  3589. log.Debug("查询容器条码关联表是否存在sql:" + sql);
  3590. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  3591. if (dttte.Rows.Count > 0)
  3592. {
  3593. ///删除条码关联表数据
  3594. sql = @"DELETE FROM ICSContainerLot
  3595. where ContainerID=(SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{2}') AND LotNo='{0}' and WorkPoint='{1}'
  3596. ";
  3597. sql = string.Format(sql, LotNo, WorkPoint, ContainerCode);
  3598. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3599. {
  3600. throw new Exception("容器条码关联表数据删除失败");
  3601. }
  3602. ///记录日志
  3603. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  3604. 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}' and F_Location ='{3}'), '{3}', GETDATE())";
  3605. sql = string.Format(sql, ContainerCode, LotNo, User, WorkPoint, Type);
  3606. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3607. {
  3608. throw new Exception("条码解绑容器记录日志表失败");
  3609. }
  3610. log.Debug(language.GetNameByCode("容器" + ContainerCode + "与条码" + LotNo + "已解除绑定"));
  3611. return true;
  3612. }
  3613. else
  3614. {
  3615. return false;
  3616. }
  3617. }
  3618. catch (Exception)
  3619. {
  3620. throw;
  3621. }
  3622. }
  3623. /// <summary>
  3624. /// 入库时解绑父容器与容器
  3625. /// </summary>
  3626. /// <param name="ContainerCode"></param>
  3627. /// <param name="WorkPoint"></param>
  3628. /// <param name="User"></param>
  3629. /// <param name="Type"></param>
  3630. /// <param name="cmd"></param>
  3631. /// <param name="language"></param>
  3632. /// <returns></returns>
  3633. public static bool ICSContainerConUntieWhenIn(string ContainerCode, string WorkPoint, string User, string Type, SqlCommand cmd, Dictionary<string, string> language)
  3634. {
  3635. try
  3636. {
  3637. string sql = @"IF EXISTS(SELECT 1 FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{2}' AND ContainerID IS NOT NULL AND ContainerID<>'')
  3638. BEGIN
  3639. INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  3640. VALUES(NEWID(), '', '{0}', '{3}', '{1}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}'), '{2}', GETDATE())
  3641. UPDATE ICSContainer SET ContainerID='',MUSER='{1}',
  3642. MUSERName=(SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  3643. ,MTIME=GETDATE()
  3644. WHERE ContainerCode='{0}' AND WorkPoint='{2}'
  3645. END";
  3646. sql = string.Format(sql, ContainerCode, User, WorkPoint, Type);
  3647. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3648. {
  3649. return false;
  3650. }
  3651. log.Debug("容器 " + ContainerCode + " 与父容器已解绑");
  3652. return true;
  3653. }
  3654. catch (Exception)
  3655. {
  3656. throw;
  3657. }
  3658. }
  3659. /// <summary>
  3660. /// U9盘点差异单接口
  3661. /// </summary>
  3662. /// <param name="TransType"></param>
  3663. /// <param name="Identification"></param>
  3664. /// <param name="cmd"></param>
  3665. public static void CheckDiffInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  3666. {
  3667. try
  3668. {
  3669. #region 查询盘点数据
  3670. string sql = @" select FromWarehouseCode AS WHCode,A.InvCode,C.BatchCode into #tempWh from ICSWareHouseLotInfoLog A
  3671. LEFT JOIN ICSInventoryLot B ON B.LotNo=A.LotNo AND B.WorkPoint=A.WorkPoint
  3672. LEFT JOIN ICSExtension C ON C.ID=B.ExtensionID
  3673. where Identification='{0}'
  3674. GROUP BY FromWarehouseCode,A.InvCode,C.BatchCode
  3675. select A.WorkPoint AS Costre,A.WorkPoint AS WorkPoint,A.InvCode AS InvCode
  3676. ,A.WarehouseCode AS WHCode,SUM(A.Quantity) AS Quantity,D.BatchCode AS BatchCode
  3677. into #TempERP from ICSWareHouseLotInfo A
  3678. INNER JOIN ICSInventoryLot B ON B.LotNo=A.LotNo AND B.WorkPoint=A.WorkPoint
  3679. INNER JOIN ICSExtension D ON D.ID=B.ExtensionID
  3680. INNER JOIN #tempWh C ON C.WHCode=A.WarehouseCode AND C.InvCode=A.InvCode AND C.BatchCode=D.BatchCode
  3681. GROUP BY A.WorkPoint,A.InvCode,A.WarehouseCode,D.BatchCode
  3682. SELECT DISTINCT Costre,WorkPoint FROM #TempERP
  3683. SELECT Costre,InvCode,WHCode,Quantity,0 AS Amount,BatchCode
  3684. FROM #TempERP
  3685. DROP TABLE #tempWh
  3686. DROP TABLE #TempERP";
  3687. sql = string.Format(sql, Identification);
  3688. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  3689. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  3690. string resultStr = "";
  3691. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateCheckDiffJinHURL, Inputstr);
  3692. Result result = new Result();
  3693. result = JsonConvert.DeserializeObject<Result>(resultStr);
  3694. if (!result.Success)
  3695. {
  3696. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  3697. }
  3698. #endregion
  3699. }
  3700. catch (Exception)
  3701. {
  3702. throw;
  3703. }
  3704. }
  3705. }
  3706. }