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

1273 lines
79 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 委外模块
  18. /// </summary>
  19. public class ICSOutsourcingService
  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 OutsourcingIssueDoc(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  32. {
  33. try
  34. {
  35. string sql = @"DECLARE @Status VARCHAR(10)
  36. SELECT @Status=b.Status FROM ICSOOPick a
  37. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  38. WHERE b.OOCode='{0}' AND b.Sequence+'-'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  39. IF (@Status IS NULL)
  40. BEGIN
  41. RAISERROR('" + language.GetNameByCode("WMSAPIInfo104") + @"',16,1);
  42. RETURN
  43. END
  44. ELSE IF (@Status!='2')
  45. BEGIN
  46. RAISERROR('" + language.GetNameByCode("WMSAPIInfo105") + @"',16,1);
  47. RETURN
  48. END
  49. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  50. FROM ICSOOPick a
  51. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  52. WHERE b.OOCode='{0}' AND b.Sequence+'-'+a.Sequence='{3}' AND a.WorkPoint='{1}'
  53. IF EXISTS(SELECT a.ID FROM ICSOOPick a
  54. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  55. WHERE b.OOCode='{0}' AND b.Sequence+'-'+a.Sequence='{3}' and b.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  56. BEGIN
  57. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  58. RETURN
  59. END";
  60. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  61. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  62. {
  63. throw new Exception("" + language.GetNameByCode("WMSAPIInfo107") + @"");
  64. }
  65. }
  66. catch (Exception)
  67. {
  68. throw;
  69. }
  70. }
  71. /// <summary>
  72. /// 委外发料接口
  73. /// </summary>
  74. /// <param name="TransType"></param>
  75. /// <param name="Identification"></param>
  76. /// <param name="cmd"></param>
  77. public static void OutsourcingIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  78. {
  79. try
  80. {
  81. #region ERP
  82. string sql = @"SELECT y.DepCode+a.FromWarehouseCode+y.OOCode+a.MUSER AS Costre,y.DepCode,a.FromWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.FromWarehouseCode,y.OOCode,x.PickID,a.InvCode) AS Sequence,
  83. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,x.PickID,x.OODetailID,con.Enable AS UpdateTodoQuantity
  84. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  85. 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
  86. INTO #TempERP
  87. FROM ICSWareHouseLotInfoLog a
  88. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  89. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  90. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  91. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  92. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'-'+x.Sequence AND x.WorkPoint=y.WorkPoint
  93. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  94. WHERE a.Identification='{0}' AND ERPUpload='0'
  95. GROUP BY y.DepCode,a.FromWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,x.OODetailID,con.Enable
  96. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  97. 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, '')
  98. SELECT DISTINCT Costre,WorkPoint,DepCode,OODetailID,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  99. SELECT Costre,Sequence,InvCode,Quantity,Amount,PickID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  100. DROP TABLE #TempERP";
  101. sql = string.Format(sql, Identification);
  102. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  103. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  104. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDocURL, Inputstr);
  105. Result result = new Result();
  106. result = JsonConvert.DeserializeObject<Result>(resultStr);
  107. if (result.Success)
  108. {
  109. try
  110. {
  111. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  112. foreach (var item in res)
  113. {
  114. JObject jo = (JObject)item;
  115. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  116. foreach (var detail in resdetail)
  117. {
  118. JObject det = (JObject)detail;
  119. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  120. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  121. }
  122. }
  123. }
  124. catch (Exception ex)
  125. {
  126. log.Debug(ex.ToString());
  127. log.Debug(resultStr);
  128. }
  129. }
  130. else
  131. {
  132. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  133. }
  134. #endregion
  135. }
  136. catch (Exception)
  137. {
  138. throw;
  139. }
  140. }
  141. #endregion
  142. #region 委外领料申请单生产发料
  143. /// <summary>
  144. /// 委外领料申请单生产发料
  145. /// </summary>
  146. /// <param name="TransCode"></param>
  147. /// <param name="TransSequence"></param>
  148. /// <param name="Quantity"></param>
  149. /// <param name="WorkPoint"></param>
  150. /// <param name="cmd"></param>
  151. public static void OOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  152. {
  153. try
  154. {
  155. string sql = @"DECLARE @Status VARCHAR(10)
  156. SELECT @Status=a.Status FROM ICSOApply a
  157. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  158. IF (@Status IS NULL)
  159. BEGIN
  160. RAISERROR('" + language.GetNameByCode("WMSAPIInfo108") + @"',16,1);
  161. RETURN
  162. END
  163. ELSE IF (@Status!='2')
  164. BEGIN
  165. RAISERROR('" + language.GetNameByCode("WMSAPIInfo109") + @"',16,1);
  166. RETURN
  167. END
  168. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  169. FROM ICSOApply a
  170. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  171. IF EXISTS(SELECT a.ID FROM ICSOApply a
  172. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  173. BEGIN
  174. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  175. RETURN
  176. END";
  177. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  178. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  179. {
  180. throw new Exception("" + language.GetNameByCode("WMSAPIInfo110") + @"");
  181. }
  182. }
  183. catch (Exception)
  184. {
  185. throw;
  186. }
  187. }
  188. /// <summary>
  189. /// 委外领料申请单生产发料接口
  190. /// </summary>
  191. /// <param name="TransType"></param>
  192. /// <param name="Identification"></param>
  193. /// <param name="cmd"></param>
  194. public static void OOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  195. {
  196. try
  197. {
  198. #region ERP
  199. string sql = @"SELECT a.FromWarehouseCode+b.ApplyCode+a.MUSER AS Costre,a.FromWarehouseCode AS WarehouseCode,b.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.FromWarehouseCode,b.ApplyCode,b.ApplyDetailID,a.InvCode) AS Sequence,
  200. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,b.ApplyDetailID,Enable AS UpdateTodoQuantity
  201. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  202. 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
  203. INTO #TempERP
  204. FROM ICSWareHouseLotInfoLog a
  205. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  206. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  207. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  208. INNER JOIN ICSOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  209. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  210. WHERE a.Identification='{0}' AND ERPUpload='0'
  211. GROUP BY a.FromWarehouseCode,b.ApplyCode,a.MUSER,a.InvCode,b.ApplyDetailID,Enable
  212. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  213. 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, '')
  214. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  215. SELECT Costre,Sequence,InvCode,Quantity,Amount,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  216. DROP TABLE #TempERP";
  217. sql = string.Format(sql, Identification);
  218. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  219. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  220. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOApplyURL, Inputstr);
  221. Result result = new Result();
  222. result = JsonConvert.DeserializeObject<Result>(resultStr);
  223. if (result.Success)
  224. {
  225. try
  226. {
  227. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  228. foreach (var item in res)
  229. {
  230. JObject jo = (JObject)item;
  231. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  232. foreach (var detail in resdetail)
  233. {
  234. JObject det = (JObject)detail;
  235. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  236. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  237. }
  238. }
  239. }
  240. catch (Exception ex)
  241. {
  242. log.Debug(ex.ToString());
  243. log.Debug(resultStr);
  244. }
  245. }
  246. else
  247. {
  248. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  249. }
  250. #endregion
  251. }
  252. catch (Exception)
  253. {
  254. throw;
  255. }
  256. }
  257. #endregion
  258. #region 委外材料出库单生产发料
  259. /// <summary>
  260. /// 委外材料出库单生产发料
  261. /// </summary>
  262. /// <param name="TransCode"></param>
  263. /// <param name="TransSequence"></param>
  264. /// <param name="Quantity"></param>
  265. /// <param name="WorkPoint"></param>
  266. /// <param name="cmd"></param>
  267. public static void OOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  268. {
  269. try
  270. {
  271. string sql = @"DECLARE @Status VARCHAR(10)
  272. SELECT @Status=a.Status FROM ICSOIssue a
  273. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  274. IF (@Status IS NULL)
  275. BEGIN
  276. RAISERROR('" + language.GetNameByCode("WMSAPIInfo111") + @"',16,1);
  277. RETURN
  278. END
  279. ELSE IF (@Status!='1')
  280. BEGIN
  281. RAISERROR('" + language.GetNameByCode("WMSAPIInfo112") + @"',16,1);
  282. RETURN
  283. END
  284. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  285. FROM ICSOIssue a
  286. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  287. IF EXISTS(SELECT a.ID FROM ICSOIssue a
  288. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  289. BEGIN
  290. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  291. RETURN
  292. END";
  293. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  294. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  295. {
  296. throw new Exception("" + language.GetNameByCode("WMSAPIInfo113") + @"");
  297. }
  298. }
  299. catch (Exception)
  300. {
  301. throw;
  302. }
  303. }
  304. /// <summary>
  305. /// 委外材料出库单生产发料接口
  306. /// </summary>
  307. /// <param name="TransType"></param>
  308. /// <param name="Identification"></param>
  309. /// <param name="cmd"></param>
  310. public static void OOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  311. {
  312. try
  313. {
  314. #region ERP开立状态单据审核
  315. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  316. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  317. WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity)
  318. BEGIN
  319. RAISERROR('" + language.GetNameByCode("WMSAPIInfo095") + @"',16,1);
  320. RETURN
  321. END
  322. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  323. FROM ICSWareHouseLotInfoLog a
  324. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  325. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  326. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  327. WHERE a.Identification='{0}' AND ERPUpload='0'
  328. GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  329. sql = string.Format(sql, Identification);
  330. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  331. string Inputstr = JsonConvert.SerializeObject(dt);
  332. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOIssueURL, Inputstr);
  333. Result result = new Result();
  334. result = JsonConvert.DeserializeObject<Result>(resultStr);
  335. if (result.Success)
  336. {
  337. try
  338. {
  339. foreach (DataRow dr in dt.Rows)
  340. {
  341. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  342. }
  343. }
  344. catch (Exception ex)
  345. {
  346. log.Debug(ex.ToString());
  347. log.Debug(resultStr);
  348. }
  349. }
  350. else
  351. {
  352. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  353. }
  354. #endregion
  355. }
  356. catch (Exception)
  357. {
  358. throw;
  359. }
  360. }
  361. #endregion
  362. #region 委外退料
  363. /// <summary>
  364. /// 委外退料
  365. /// </summary>
  366. /// <param name="TransCode"></param>
  367. /// <param name="TransSequence"></param>
  368. /// <param name="Quantity"></param>
  369. /// <param name="WorkPoint"></param>
  370. /// <param name="cmd"></param>
  371. public static void OutsourcingIssueDoNegative(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  372. {
  373. try
  374. {
  375. string sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  376. FROM ICSInventoryLot a
  377. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  378. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  379. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  380. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  381. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  382. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  383. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.IssueNegQuantity)
  384. BEGIN
  385. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  386. END";
  387. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  388. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  389. {
  390. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  391. }
  392. }
  393. catch (Exception)
  394. {
  395. throw;
  396. }
  397. }
  398. /// <summary>
  399. /// 委外退料接口
  400. /// </summary>
  401. /// <param name="TransType"></param>
  402. /// <param name="Identification"></param>
  403. /// <param name="cmd"></param>
  404. public static void OutsourcingIssueDoNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  405. {
  406. try
  407. {
  408. #region ERP
  409. string sql = string.Empty;
  410. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  411. {
  412. sql = @"SELECT y.DepCode+a.ToWarehouseCode+y.OOCode+a.MUSER AS Costre,y.DepCode,a.ToWarehouseCode AS WarehouseCode,y.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.DepCode,a.ToWarehouseCode,y.OOCode,c.SourceDetailID,a.InvCode) AS Sequence,
  413. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,c.SourceDetailID,Enable AS UpdateTodoQuantity
  414. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  415. 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
  416. INTO #TempERP
  417. FROM ICSWareHouseLotInfoLog a
  418. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  419. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  420. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  421. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  422. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  423. INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  424. INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  425. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  426. WHERE a.Identification='{0}' AND ERPUpload='0'
  427. GROUP BY y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,c.SourceDetailID,Enable
  428. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  429. 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, '')
  430. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  431. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  432. DROP TABLE #TempERP";
  433. }
  434. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  435. {
  436. sql = @"SELECT a.ToWarehouseCode+z.ApplyCode+a.MUSER AS Costre,'' AS DepCode,a.ToWarehouseCode AS WarehouseCode,z.ApplyCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY a.ToWarehouseCode,z.ApplyCode,c.SourceDetailID,a.InvCode) AS Sequence,
  437. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,c.SourceDetailID,Enable AS UpdateTodoQuantity
  438. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  439. 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
  440. INTO #TempERP
  441. FROM ICSWareHouseLotInfoLog a
  442. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  443. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  444. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  445. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  446. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  447. INNER JOIN ICSOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  448. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  449. WHERE a.Identification='{0}' AND ERPUpload='0'
  450. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,c.SourceDetailID,Enable
  451. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  452. 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, '')
  453. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  454. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  455. DROP TABLE #TempERP";
  456. }
  457. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  458. {
  459. sql = @"SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+ISNULL(y.OOCode, z.ApplyCode)+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.PickID IS NOT NULL THEN '生产订单' WHEN m.ApplyDetailID IS NOT NULL THEN '领料申请单' ELSE '' END AS SourceType,ISNULL(y.OOCode, z.ApplyCode) AS OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(y.OOCode, z.ApplyCode),a.InvCode) AS Sequence,
  460. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(x.PickID, z.ApplyDetailID) AS SourceDetailID,Enable AS UpdateTodoQuantity
  461. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  462. 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
  463. INTO #TempERP
  464. FROM ICSWareHouseLotInfoLog a
  465. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  466. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  467. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  468. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  469. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  470. INNER JOIN ICSOIssue m ON c.SourceDetailID=m.ApplyDetailID AND c.WorkPoint=m.WorkPoint
  471. INNER JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  472. INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  473. INNER JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  474. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  475. WHERE a.Identification='{0}' AND ERPUpload='0'
  476. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(y.OOCode, z.ApplyCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,ISNULL(x.PickID, z.ApplyDetailID),Enable
  477. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  478. 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, '')
  479. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  480. BEGIN
  481. RAISERROR('" + language.GetNameByCode("WMSAPIInfo116") + @"',16,1);
  482. END
  483. SELECT DISTINCT Costre,WorkPoint,DepCode,SourceDetailID,WarehouseCode AS WHCode,SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  484. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  485. DROP TABLE #TempERP";
  486. }
  487. else
  488. {
  489. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  490. }
  491. sql = string.Format(sql, Identification);
  492. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  493. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  494. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDoNegativeURL, Inputstr);
  495. Result result = new Result();
  496. result = JsonConvert.DeserializeObject<Result>(resultStr);
  497. if (result.Success)
  498. {
  499. try
  500. {
  501. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  502. foreach (var item in res)
  503. {
  504. JObject jo = (JObject)item;
  505. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  506. foreach (var detail in resdetail)
  507. {
  508. JObject det = (JObject)detail;
  509. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  510. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  511. }
  512. }
  513. //List<ICSERPReturnIssueNEG> negList = JsonConvert.DeserializeObject<List<ICSERPReturnIssueNEG>>(result.Data.ToString());
  514. //foreach (var neg in negList)
  515. //{
  516. // foreach (var detail in neg.details)
  517. // {
  518. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, detail.SourceDetailID, Identification, neg.ID, detail.DetailID, neg.IssueNEGCode, detail.Sequence, cmd);
  519. // }
  520. //}
  521. }
  522. catch (Exception ex)
  523. {
  524. log.Debug(ex.ToString());
  525. log.Debug(resultStr);
  526. }
  527. }
  528. else
  529. {
  530. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  531. }
  532. #endregion
  533. }
  534. catch (Exception)
  535. {
  536. throw;
  537. }
  538. }
  539. #endregion
  540. #region 委外到货
  541. /// <summary>
  542. /// 委外到货接口
  543. /// </summary>
  544. /// <param name="TransType"></param>
  545. /// <param name="Identification"></param>
  546. /// <param name="cmd"></param>
  547. public static void OutsourcingDeliveryNoticeERP(string ODNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  548. {
  549. try
  550. {
  551. #region ERP
  552. string sql = @"SELECT a.VenCode+a.DepCode+y.OOCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.OOCode,a.MUSER,a.MTIME,
  553. a.Sequence,a.InvCode,a.Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.OODetailID
  554. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  555. 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
  556. INTO #TempERP
  557. FROM ICSODeliveryNotice a
  558. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  559. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  560. INNER JOIN ICSOutsourcingOrder y ON a.OODetailID=y.OODetailID AND a.WorkPoint=y.WorkPoint
  561. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  562. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  563. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,OODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  564. FROM #TempERP
  565. DROP TABLE #TempERP";
  566. sql = string.Format(sql, ODNCode, WorkPoint);
  567. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  568. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  569. string resultStr = HTTPHelper.HttpPost("委外到货", ERPUrl.ODeliveryNoticeURL, Inputstr);
  570. Result result = new Result();
  571. result = JsonConvert.DeserializeObject<Result>(resultStr);
  572. if (result.Success)
  573. {
  574. try
  575. {
  576. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  577. foreach (var item in res)
  578. {
  579. JObject jo = (JObject)item;
  580. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  581. foreach (var detail in resdetail)
  582. {
  583. JObject det = (JObject)detail;
  584. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  585. where OODetailID='{4}' AND ODNType='1' AND ODNCode='{5}' ";
  586. ERPupdate = string.Format(ERPupdate, jo["ODNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["OODetailID"],ODNCode);
  587. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  588. {
  589. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  590. }
  591. }
  592. }
  593. }
  594. catch (Exception ex)
  595. {
  596. log.Debug(ex.ToString());
  597. log.Debug(resultStr);
  598. }
  599. }
  600. else
  601. {
  602. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  603. }
  604. #endregion
  605. }
  606. catch (Exception)
  607. {
  608. throw;
  609. }
  610. }
  611. #endregion
  612. #region 委外入库
  613. /// <summary>
  614. /// 委外入库
  615. /// </summary>
  616. /// <param name="TransCode"></param>
  617. /// <param name="TransSequence"></param>
  618. /// <param name="Quantity"></param>
  619. /// <param name="WorkPoint"></param>
  620. /// <param name="cmd"></param>
  621. public static void OutsourcingReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  622. {
  623. try
  624. {
  625. string sql = @"DECLARE @Status VARCHAR(10)
  626. SELECT @Status=c.Status FROM ICSInventoryLot a
  627. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  628. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  629. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  630. IF (@Status IS NULL)
  631. BEGIN
  632. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  633. RETURN
  634. END
  635. ELSE IF (@Status='3')
  636. BEGIN
  637. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  638. RETURN
  639. END
  640. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  641. FROM ICSInventoryLot a
  642. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  643. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  644. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  645. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  646. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  647. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  648. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  649. BEGIN
  650. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  651. END";
  652. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  653. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  654. {
  655. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  656. }
  657. }
  658. catch (Exception)
  659. {
  660. throw;
  661. }
  662. }
  663. /// <summary>
  664. /// 委外入库接口
  665. /// </summary>
  666. /// <param name="TransType"></param>
  667. /// <param name="Identification"></param>
  668. /// <param name="cmd"></param>
  669. public static void OutsourcingReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  670. {
  671. try
  672. {
  673. #region ERP
  674. string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode) AS Sequence,
  675. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.OODetailID,Enable AS UpdateTodoQuantity
  676. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  677. 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
  678. INTO #TempERP
  679. FROM ICSWareHouseLotInfoLog a
  680. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  681. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  682. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  683. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  684. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  685. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  686. WHERE a.Identification='{0}' AND ERPUpload='0'
  687. GROUP BY c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,a.InvCode,c.OODetailID,isnull((c.UnitPrice),0),c.Currency,Enable
  688. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  689. 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, '')
  690. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  691. SELECT Costre,Sequence,InvCode,Quantity,Amount,OODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  692. FROM #TempERP
  693. DROP TABLE #TempERP";
  694. sql = string.Format(sql, Identification);
  695. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  696. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  697. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocURL, Inputstr);
  698. Result result = new Result();
  699. result = JsonConvert.DeserializeObject<Result>(resultStr);
  700. if (result.Success)
  701. {
  702. try
  703. {
  704. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  705. foreach (var item in res)
  706. {
  707. JObject jo = (JObject)item;
  708. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  709. foreach (var detail in resdetail)
  710. {
  711. JObject det = (JObject)detail;
  712. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  713. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  714. }
  715. }
  716. }
  717. catch (Exception ex)
  718. {
  719. log.Debug(ex.ToString());
  720. log.Debug(resultStr);
  721. }
  722. }
  723. else
  724. {
  725. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  726. }
  727. #endregion
  728. }
  729. catch (Exception)
  730. {
  731. throw;
  732. }
  733. }
  734. #endregion
  735. #region 审核的委外到货单
  736. /// <summary>
  737. /// 审核的委外到货单
  738. /// </summary>
  739. /// <param name="TransCode"></param>
  740. /// <param name="TransSequence"></param>
  741. /// <param name="Quantity"></param>
  742. /// <param name="WorkPoint"></param>
  743. /// <param name="cmd"></param>
  744. public static void ODeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  745. {
  746. try
  747. {
  748. string sql = @"DECLARE @Status VARCHAR(10)
  749. SELECT @Status=c.Status FROM ICSInventoryLot a
  750. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  751. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  752. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  753. IF (@Status IS NULL)
  754. BEGIN
  755. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  756. RETURN
  757. END
  758. ELSE IF (@Status='3')
  759. BEGIN
  760. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  761. RETURN
  762. END
  763. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  764. FROM ICSInventoryLot a
  765. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  766. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  767. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  768. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  769. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  770. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  771. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1' AND c.Quantity<c.RCVQuantity)
  772. BEGIN
  773. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  774. END";
  775. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  776. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  777. {
  778. throw new Exception(language.GetNameByCode("WMSAPIInfo117"));//"委外到货单更新失败!");
  779. }
  780. }
  781. catch (Exception)
  782. {
  783. throw;
  784. }
  785. }
  786. /// <summary>
  787. /// 审核的委外到货单接口
  788. /// </summary>
  789. /// <param name="TransType"></param>
  790. /// <param name="Identification"></param>
  791. /// <param name="cmd"></param>
  792. public static void ODeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  793. {
  794. try
  795. {
  796. #region ERP
  797. string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNCode,c.ODNDetailID,a.InvCode) AS Sequence,
  798. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.ODNDetailID,Enable AS UpdateTodoQuantity
  799. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  800. 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
  801. INTO #TempERP
  802. FROM ICSWareHouseLotInfoLog a
  803. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  804. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  805. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  806. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  807. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  808. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  809. WHERE a.Identification='{0}' AND ERPUpload='0'
  810. GROUP BY c.VenCode,a.ToWarehouseCode,c.ODNCode,a.MUSER,a.InvCode,c.ODNDetailID,isnull((c.UnitPrice),0),c.Currency,Enable
  811. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  812. 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, '')
  813. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  814. SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  815. FROM #TempERP
  816. DROP TABLE #TempERP";
  817. sql = string.Format(sql, Identification);
  818. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  819. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  820. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ODeliveryNoticeInURL, Inputstr);
  821. Result result = new Result();
  822. result = JsonConvert.DeserializeObject<Result>(resultStr);
  823. if (result.Success)
  824. {
  825. try
  826. {
  827. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  828. foreach (var item in res)
  829. {
  830. JObject jo = (JObject)item;
  831. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  832. foreach (var detail in resdetail)
  833. {
  834. JObject det = (JObject)detail;
  835. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  836. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  837. }
  838. }
  839. }
  840. catch (Exception ex)
  841. {
  842. log.Debug(ex.ToString());
  843. log.Debug(resultStr);
  844. }
  845. }
  846. else
  847. {
  848. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  849. }
  850. #endregion
  851. }
  852. catch (Exception)
  853. {
  854. throw;
  855. }
  856. }
  857. #endregion
  858. #region 委外拒收
  859. /// <summary>
  860. /// 委外拒收
  861. /// </summary>
  862. /// <param name="TransCode"></param>
  863. /// <param name="TransSequence"></param>
  864. /// <param name="Quantity"></param>
  865. /// <param name="WorkPoint"></param>
  866. /// <param name="cmd"></param>
  867. public static void OutsourcingRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  868. {
  869. try
  870. {
  871. string sql = @"DECLARE @Status VARCHAR(10)
  872. SELECT @Status=c.Status FROM ICSInventoryLot a
  873. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  874. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  875. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  876. IF (@Status IS NULL)
  877. BEGIN
  878. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  879. RETURN
  880. END
  881. ELSE IF (@Status='3')
  882. BEGIN
  883. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  884. RETURN
  885. END
  886. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  887. FROM ICSInventoryLot a
  888. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  889. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  890. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  891. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  892. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  893. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  894. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3' AND c.Quantity<c.RCVQuantity)
  895. BEGIN
  896. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  897. END";
  898. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  899. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  900. {
  901. throw new Exception(language.GetNameByCode("WMSAPIInfo118"));//"委外拒收单更新失败!");
  902. }
  903. }
  904. catch (Exception)
  905. {
  906. throw;
  907. }
  908. }
  909. /// <summary>
  910. /// 委外拒收接口
  911. /// </summary>
  912. /// <param name="TransType"></param>
  913. /// <param name="Identification"></param>
  914. /// <param name="cmd"></param>
  915. public static void OutsourcingRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  916. {
  917. //try
  918. //{
  919. // #region ERP
  920. // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNCode,c.ODNDetailID,a.InvCode) AS Sequence,
  921. // a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.ODNDetailID,Enable AS UpdateTodoQuantity
  922. // INTO #TempERP
  923. // FROM ICSWareHouseLotInfoLog a
  924. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  925. // INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  926. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  927. // WHERE a.Identification='{0}' AND ERPUpload='0'
  928. // GROUP BY c.VenCode,a.ToWarehouseCode,c.ODNCode,a.MUSER,a.InvCode,c.ODNDetailID,isnull((c.UnitPrice),0),c.Currency,Enable
  929. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  930. // SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID,Currency,UnitPrice
  931. // FROM #TempERP
  932. // DROP TABLE #TempERP";
  933. // sql = string.Format(sql, Identification);
  934. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  935. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  936. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ODeliveryNoticeInURL, Inputstr);
  937. // Result result = new Result();
  938. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  939. // if (result.Success)
  940. // {
  941. // try
  942. // {
  943. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  944. // foreach (var item in res)
  945. // {
  946. // JObject jo = (JObject)item;
  947. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  948. // foreach (var detail in resdetail)
  949. // {
  950. // JObject det = (JObject)detail;
  951. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd);
  952. // }
  953. // }
  954. // }
  955. // catch (Exception ex)
  956. // {
  957. // log.Debug(ex.ToString());
  958. // log.Debug(resultStr);
  959. // }
  960. // }
  961. // else
  962. // {
  963. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  964. // }
  965. // #endregion
  966. //}
  967. //catch (Exception)
  968. //{
  969. // throw;
  970. //}
  971. }
  972. #endregion
  973. #region 委外退货
  974. /// <summary>
  975. /// 委外退货
  976. /// </summary>
  977. /// <param name="TransCode"></param>
  978. /// <param name="TransSequence"></param>
  979. /// <param name="Quantity"></param>
  980. /// <param name="WorkPoint"></param>
  981. /// <param name="cmd"></param>
  982. public static void OutsourcingReturnBack(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  983. {
  984. try
  985. {
  986. string sql = @"DECLARE @Status VARCHAR(10)
  987. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='2' and WorkPoint='{1}'
  988. IF (@Status IS NULL)
  989. BEGIN
  990. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  991. RETURN
  992. END
  993. ELSE IF (@Status!='2')
  994. BEGIN
  995. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  996. RETURN
  997. END
  998. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  999. FROM ICSODeliveryNotice a
  1000. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND ODNType='2'
  1001. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  1002. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND ODNType='2')
  1003. BEGIN
  1004. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  1005. RETURN
  1006. END";
  1007. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1008. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1009. {
  1010. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  1011. }
  1012. }
  1013. catch (Exception)
  1014. {
  1015. throw;
  1016. }
  1017. }
  1018. /// <summary>
  1019. /// 委外退货接口
  1020. /// </summary>
  1021. /// <param name="TransType"></param>
  1022. /// <param name="Identification"></param>
  1023. /// <param name="cmd"></param>
  1024. public static void OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1025. {
  1026. try
  1027. {
  1028. #region ERP
  1029. string sql = @"SELECT y.VenCode+a.FromWarehouseCode+y.ODNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.ODNCode,y.ODNDetailID,a.InvCode) AS Sequence,
  1030. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,Enable AS UpdateTodoQuantity
  1031. ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  1032. 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
  1033. INTO #TempERP
  1034. FROM ICSWareHouseLotInfoLog a
  1035. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1036. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1037. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1038. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  1039. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1040. WHERE a.Identification='{0}' AND ERPUpload='0'
  1041. GROUP BY y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),Enable
  1042. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  1043. 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, '')
  1044. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode AS ODNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  1045. SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID AS ODNRTDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1046. FROM #TempERP
  1047. DROP TABLE #TempERP";
  1048. sql = string.Format(sql, Identification);
  1049. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1050. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1051. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackURL, Inputstr);
  1052. Result result = new Result();
  1053. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1054. if (result.Success)
  1055. {
  1056. try
  1057. {
  1058. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1059. foreach (var item in res)
  1060. {
  1061. JObject jo = (JObject)item;
  1062. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1063. foreach (var detail in resdetail)
  1064. {
  1065. JObject det = (JObject)detail;
  1066. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1067. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1068. }
  1069. }
  1070. }
  1071. catch (Exception ex)
  1072. {
  1073. log.Debug(ex.ToString());
  1074. log.Debug(resultStr);
  1075. }
  1076. }
  1077. else
  1078. {
  1079. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  1080. }
  1081. #endregion
  1082. }
  1083. catch (Exception)
  1084. {
  1085. throw;
  1086. }
  1087. }
  1088. #endregion
  1089. #region 开立委外红字入库
  1090. /// <summary>
  1091. /// 开立委外红字入库
  1092. /// </summary>
  1093. /// <param name="TransCode"></param>
  1094. /// <param name="TransSequence"></param>
  1095. /// <param name="Quantity"></param>
  1096. /// <param name="WorkPoint"></param>
  1097. /// <param name="cmd"></param>
  1098. public static void OutsourcingReceiveDocNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1099. {
  1100. try
  1101. {
  1102. string sql = @"DECLARE @Status VARCHAR(10)
  1103. SELECT @Status=a.Status FROM ICSOutsourcingReceive a
  1104. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1105. IF (@Status IS NULL)
  1106. BEGIN
  1107. RAISERROR('" + language.GetNameByCode("WMSAPIInfo122") + @"',16,1);
  1108. RETURN
  1109. END
  1110. ELSE IF (@Status!='1')
  1111. BEGIN
  1112. RAISERROR('" + language.GetNameByCode("WMSAPIInfo123") + @"',16,1);
  1113. RETURN
  1114. END
  1115. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1116. FROM ICSOutsourcingReceive a
  1117. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1118. IF EXISTS(SELECT a.ID FROM ICSOutsourcingReceive a
  1119. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  1120. BEGIN
  1121. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1122. RETURN
  1123. END";
  1124. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1125. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1126. {
  1127. throw new Exception(language.GetNameByCode("WMSAPIInfo124"));//"委外红字入库单更新失败!");
  1128. }
  1129. }
  1130. catch (Exception)
  1131. {
  1132. throw;
  1133. }
  1134. }
  1135. /// <summary>
  1136. /// 开立委外红字入库接口
  1137. /// </summary>
  1138. /// <param name="TransType"></param>
  1139. /// <param name="Identification"></param>
  1140. /// <param name="cmd"></param>
  1141. public static void OutsourcingReceiveDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1142. {
  1143. try
  1144. {
  1145. #region ERP开立状态单据审核
  1146. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  1147. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1148. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  1149. BEGIN
  1150. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  1151. RETURN
  1152. END
  1153. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1154. FROM ICSWareHouseLotInfoLog a
  1155. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1156. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1157. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1158. WHERE a.Identification='{0}' AND ERPUpload='0'
  1159. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  1160. sql = string.Format(sql, Identification);
  1161. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1162. string Inputstr = JsonConvert.SerializeObject(dt);
  1163. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  1164. Result result = new Result();
  1165. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1166. if (result.Success)
  1167. {
  1168. try
  1169. {
  1170. foreach (DataRow dr in dt.Rows)
  1171. {
  1172. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  1173. }
  1174. }
  1175. catch (Exception ex)
  1176. {
  1177. log.Debug(ex.ToString());
  1178. log.Debug(resultStr);
  1179. }
  1180. }
  1181. else
  1182. {
  1183. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1184. }
  1185. #endregion
  1186. }
  1187. catch (Exception)
  1188. {
  1189. throw;
  1190. }
  1191. }
  1192. #endregion
  1193. }
  1194. }