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

1540 lines
108 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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,x.PickID,con.Enable AS UpdateTodoQuantity
  84. ,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,
  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,conv.Enable AS CompleteVerification
  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. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  91. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  92. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  93. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  94. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  95. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  96. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '5'
  97. GROUP BY y.DepCode,a.FromWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,x.OODetailID,con.Enable,conv.Enable
  98. ,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, ''),
  99. 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, '')
  100. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  101. 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
  102. DROP TABLE #TempERP";
  103. sql = string.Format(sql, Identification);
  104. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  105. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  106. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDocURL, Inputstr);
  107. Result result = new Result();
  108. result = JsonConvert.DeserializeObject<Result>(resultStr);
  109. if (result.Success)
  110. {
  111. try
  112. {
  113. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  114. foreach (var item in res)
  115. {
  116. JObject jo = (JObject)item;
  117. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  118. foreach (var detail in resdetail)
  119. {
  120. JObject det = (JObject)detail;
  121. string allcol = jo["cWhCode"].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()
  122. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  123. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  124. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language);
  125. }
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. log.Debug(ex.ToString());
  131. log.Debug(resultStr);
  132. }
  133. }
  134. else
  135. {
  136. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  137. }
  138. #endregion
  139. }
  140. catch (Exception)
  141. {
  142. throw;
  143. }
  144. }
  145. #endregion
  146. #region 委外领料申请单生产发料
  147. /// <summary>
  148. /// 委外领料申请单生产发料
  149. /// </summary>
  150. /// <param name="TransCode"></param>
  151. /// <param name="TransSequence"></param>
  152. /// <param name="Quantity"></param>
  153. /// <param name="WorkPoint"></param>
  154. /// <param name="cmd"></param>
  155. public static void OOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  156. {
  157. try
  158. {
  159. string sql = @"DECLARE @Status VARCHAR(10)
  160. SELECT @Status=a.Status FROM ICSOApply a
  161. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  162. IF (@Status IS NULL)
  163. BEGIN
  164. RAISERROR('" + language.GetNameByCode("WMSAPIInfo108") + @"',16,1);
  165. RETURN
  166. END
  167. ELSE IF (@Status!='2')
  168. BEGIN
  169. RAISERROR('" + language.GetNameByCode("WMSAPIInfo109") + @"',16,1);
  170. RETURN
  171. END
  172. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  173. FROM ICSOApply a
  174. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  175. IF EXISTS(SELECT a.ID FROM ICSOApply a
  176. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  177. BEGIN
  178. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  179. RETURN
  180. END";
  181. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  182. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  183. {
  184. throw new Exception(language.GetNameByCode("WMSAPIInfo110"));
  185. }
  186. }
  187. catch (Exception)
  188. {
  189. throw;
  190. }
  191. }
  192. /// <summary>
  193. /// 委外领料申请单生产发料接口
  194. /// </summary>
  195. /// <param name="TransType"></param>
  196. /// <param name="Identification"></param>
  197. /// <param name="cmd"></param>
  198. public static void OOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  199. {
  200. try
  201. {
  202. #region ERP
  203. 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,
  204. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,b.ApplyDetailID,con.Enable AS UpdateTodoQuantity
  205. ,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,
  206. 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,conv.Enable AS CompleteVerification
  207. INTO #TempERP
  208. FROM ICSWareHouseLotInfoLog a
  209. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  210. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  211. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  212. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  213. INNER JOIN ICSOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  214. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  215. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  216. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '6'
  217. GROUP BY a.FromWarehouseCode,b.ApplyCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable
  218. ,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, ''),
  219. 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, '')
  220. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  221. 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
  222. DROP TABLE #TempERP";
  223. sql = string.Format(sql, Identification);
  224. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  225. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  226. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOApplyURL, Inputstr);
  227. Result result = new Result();
  228. result = JsonConvert.DeserializeObject<Result>(resultStr);
  229. if (result.Success)
  230. {
  231. try
  232. {
  233. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  234. foreach (var item in res)
  235. {
  236. JObject jo = (JObject)item;
  237. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  238. foreach (var detail in resdetail)
  239. {
  240. JObject det = (JObject)detail;
  241. string allcol = jo["cWhCode"].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()
  242. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  243. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  244. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language);
  245. }
  246. }
  247. }
  248. catch (Exception ex)
  249. {
  250. log.Debug(ex.ToString());
  251. log.Debug(resultStr);
  252. }
  253. }
  254. else
  255. {
  256. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  257. }
  258. #endregion
  259. }
  260. catch (Exception)
  261. {
  262. throw;
  263. }
  264. }
  265. #endregion
  266. #region 委外材料出库单生产发料
  267. /// <summary>
  268. /// 委外材料出库单生产发料
  269. /// </summary>
  270. /// <param name="TransCode"></param>
  271. /// <param name="TransSequence"></param>
  272. /// <param name="Quantity"></param>
  273. /// <param name="WorkPoint"></param>
  274. /// <param name="cmd"></param>
  275. public static void OOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  276. {
  277. try
  278. {
  279. string sql = @"DECLARE @Status VARCHAR(10)
  280. SELECT @Status=a.Status FROM ICSOIssue a
  281. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  282. IF (@Status IS NULL)
  283. BEGIN
  284. RAISERROR('" + language.GetNameByCode("WMSAPIInfo111") + @"',16,1);
  285. RETURN
  286. END
  287. ELSE IF (@Status!='1')
  288. BEGIN
  289. RAISERROR('" + language.GetNameByCode("WMSAPIInfo112") + @"',16,1);
  290. RETURN
  291. END
  292. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  293. FROM ICSOIssue a
  294. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}'
  295. IF EXISTS(SELECT a.ID FROM ICSOIssue a
  296. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  297. BEGIN
  298. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  299. RETURN
  300. END";
  301. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  302. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  303. {
  304. throw new Exception(language.GetNameByCode("WMSAPIInfo113"));
  305. }
  306. }
  307. catch (Exception)
  308. {
  309. throw;
  310. }
  311. }
  312. /// <summary>
  313. /// 委外材料出库单生产发料接口
  314. /// </summary>
  315. /// <param name="TransType"></param>
  316. /// <param name="Identification"></param>
  317. /// <param name="cmd"></param>
  318. public static void OOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  319. {
  320. try
  321. {
  322. #region ERP开立状态单据审核
  323. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  324. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  325. WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity)
  326. BEGIN
  327. RAISERROR('" + language.GetNameByCode("WMSAPIInfo095") + @"',16,1);
  328. RETURN
  329. END
  330. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  331. FROM ICSWareHouseLotInfoLog a
  332. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  333. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  334. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  335. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '7'
  336. GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  337. sql = string.Format(sql, Identification);
  338. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  339. string Inputstr = JsonConvert.SerializeObject(dt);
  340. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOIssueURL, Inputstr);
  341. Result result = new Result();
  342. result = JsonConvert.DeserializeObject<Result>(resultStr);
  343. if (result.Success)
  344. {
  345. try
  346. {
  347. foreach (DataRow dr in dt.Rows)
  348. {
  349. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language);
  350. }
  351. }
  352. catch (Exception ex)
  353. {
  354. log.Debug(ex.ToString());
  355. log.Debug(resultStr);
  356. }
  357. }
  358. else
  359. {
  360. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  361. }
  362. #endregion
  363. }
  364. catch (Exception)
  365. {
  366. throw;
  367. }
  368. }
  369. #endregion
  370. #region 委外退料
  371. /// <summary>
  372. /// 委外退料
  373. /// </summary>
  374. /// <param name="TransCode"></param>
  375. /// <param name="TransSequence"></param>
  376. /// <param name="Quantity"></param>
  377. /// <param name="WorkPoint"></param>
  378. /// <param name="cmd"></param>
  379. public static void OutsourcingIssueDoNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  380. {
  381. try
  382. {
  383. string table = "";
  384. string sql = "";
  385. if (string.IsNullOrWhiteSpace(LogID))
  386. {
  387. string type = "";
  388. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  389. {
  390. table = "INNER JOIN ICSOOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  391. type = "1";
  392. }
  393. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  394. {
  395. table = "INNER JOIN ICSOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  396. type = "2";
  397. }
  398. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  399. {
  400. table = "INNER JOIN ICSOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  401. type = "3";
  402. }
  403. else
  404. {
  405. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  406. }
  407. #region 新条码
  408. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  409. FROM ICSInventoryLot a
  410. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  411. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  412. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  413. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  414. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  415. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  416. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  417. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  418. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND c.Quantity<c.IssueNegQuantity)
  419. BEGIN
  420. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  421. END
  422. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  423. FROM ICSInventoryLot a
  424. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  425. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  426. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  427. {3}
  428. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  429. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  430. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  431. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  432. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  433. {3}
  434. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  435. BEGIN
  436. RAISERROR('" + language.GetNameByCode("WMSAPIInfo193") + @"',16,1);
  437. END";
  438. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type);
  439. #endregion
  440. }
  441. else
  442. {
  443. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  444. {
  445. table = @"INNER JOIN ICSOutsourcingOrder b ON a.TransCode=b.OOCode AND a.WorkPoint=b.WorkPoint
  446. INNER JOIN ICSOOPick c ON b.OODetailID = c.OODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  447. }
  448. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  449. {
  450. table = "INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  451. }
  452. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  453. {
  454. table = "INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  455. }
  456. else
  457. {
  458. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  459. }
  460. #region 原条码
  461. sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  462. FROM ICSWareHouseLotInfoLog a
  463. {3}
  464. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  465. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  466. {3}
  467. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  468. BEGIN
  469. RAISERROR('" + language.GetNameByCode("WMSAPIInfo193") + @"',16,1);
  470. END";
  471. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID);
  472. #endregion
  473. }
  474. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  475. {
  476. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  477. }
  478. }
  479. catch (Exception)
  480. {
  481. throw;
  482. }
  483. }
  484. /// <summary>
  485. /// 委外退料接口
  486. /// </summary>
  487. /// <param name="TransType"></param>
  488. /// <param name="Identification"></param>
  489. /// <param name="cmd"></param>
  490. public static void OutsourcingIssueDoNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  491. {
  492. try
  493. {
  494. #region ERP
  495. string sql = string.Empty;
  496. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  497. {
  498. 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,x.PickID,a.InvCode) AS Sequence,
  499. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  500. ,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,
  501. 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
  502. INTO #TempERP
  503. FROM ICSWareHouseLotInfoLog a
  504. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  505. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  506. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  507. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  508. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  509. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  510. INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  511. INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  512. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  513. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  514. GROUP BY y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,con.Enable
  515. ,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, ''),
  516. 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, '')
  517. UNION ALL
  518. 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,x.PickID,a.InvCode) AS Sequence,
  519. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  520. ,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,
  521. 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
  522. FROM ICSWareHouseLotInfoLog a
  523. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  524. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  525. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  526. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  527. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  528. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  529. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  530. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  531. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  532. GROUP BY y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,con.Enable
  533. ,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, ''),
  534. 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, '')
  535. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  536. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  537. DROP TABLE #TempERP";
  538. }
  539. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  540. {
  541. 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,z.ApplyDetailID,a.InvCode) AS Sequence,
  542. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  543. ,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,
  544. 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
  545. INTO #TempERP
  546. FROM ICSWareHouseLotInfoLog a
  547. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  548. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  549. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  550. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  551. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  552. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  553. INNER JOIN ICSOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  554. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  555. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  556. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,con.Enable
  557. ,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, ''),
  558. 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, '')
  559. UNION ALL
  560. 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,z.ApplyDetailID,a.InvCode) AS Sequence,
  561. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  562. ,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,
  563. 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
  564. FROM ICSWareHouseLotInfoLog a
  565. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  566. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  567. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  568. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  569. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  570. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  571. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  572. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  573. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,con.Enable
  574. ,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, ''),
  575. 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, '')
  576. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  577. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  578. DROP TABLE #TempERP";
  579. }
  580. //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
  581. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  582. {
  583. sql = @"SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.ApplyDetailID IS NOT NULL THEN '委外领料申请单' WHEN m.PickID IS NOT NULL THEN '委外订单' ELSE '' END AS SourceType,ISNULL(z.ApplyCode, y.OOCode) AS OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.InvCode) AS Sequence,
  584. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  585. ,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,
  586. 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
  587. INTO #TempERP
  588. FROM ICSWareHouseLotInfoLog a
  589. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  590. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  591. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  592. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  593. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  594. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  595. INNER JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  596. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  597. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  598. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  599. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  600. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  601. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,lot.Amount,lot.Quantity
  602. ,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, ''),
  603. 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, '')
  604. UNION ALL
  605. SELECT ISNULL(y.DepCode, '')+a.ToWarehouseCode+a.MUSER AS Costre,ISNULL(y.DepCode, '') AS DepCode,a.ToWarehouseCode AS WarehouseCode,CASE WHEN m.ApplyDetailID IS NOT NULL THEN '' WHEN m.PickID IS NOT NULL THEN '' ELSE '' END AS SourceType,ISNULL(z.ApplyCode, y.OOCode) AS OOCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.InvCode) AS Sequence,
  606. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  607. ,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,
  608. 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
  609. FROM ICSWareHouseLotInfoLog a
  610. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  611. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  612. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  613. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  614. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  615. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  616. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  617. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  618. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  619. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  620. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  621. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,lot.Amount,lot.Quantity
  622. ,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, ''),
  623. 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, '')
  624. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  625. BEGIN
  626. RAISERROR('" + language.GetNameByCode("WMSAPIInfo116") + @"',16,1);
  627. END
  628. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity FROM #TempERP
  629. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  630. DROP TABLE #TempERP";
  631. }
  632. else
  633. {
  634. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  635. }
  636. sql = string.Format(sql, Identification);
  637. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  638. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  639. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDoNegativeURL, Inputstr);
  640. Result result = new Result();
  641. result = JsonConvert.DeserializeObject<Result>(resultStr);
  642. if (result.Success)
  643. {
  644. try
  645. {
  646. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  647. foreach (var item in res)
  648. {
  649. JObject jo = (JObject)item;
  650. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  651. foreach (var detail in resdetail)
  652. {
  653. JObject det = (JObject)detail;
  654. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  655. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), "",cmd, language);
  656. }
  657. }
  658. //List<ICSERPReturnIssueNEG> negList = JsonConvert.DeserializeObject<List<ICSERPReturnIssueNEG>>(result.Data.ToString());
  659. //foreach (var neg in negList)
  660. //{
  661. // foreach (var detail in neg.details)
  662. // {
  663. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, detail.SourceDetailID, Identification, neg.ID, detail.DetailID, neg.IssueNEGCode, detail.Sequence, cmd);
  664. // }
  665. //}
  666. }
  667. catch (Exception ex)
  668. {
  669. log.Debug(ex.ToString());
  670. log.Debug(resultStr);
  671. }
  672. }
  673. else
  674. {
  675. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  676. }
  677. #endregion
  678. }
  679. catch (Exception)
  680. {
  681. throw;
  682. }
  683. }
  684. #endregion
  685. #region 委外到货
  686. /// <summary>
  687. /// 委外到货接口
  688. /// </summary>
  689. /// <param name="TransType"></param>
  690. /// <param name="Identification"></param>
  691. /// <param name="cmd"></param>
  692. public static void OutsourcingDeliveryNoticeERP(string ODNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  693. {
  694. try
  695. {
  696. #region ERP
  697. string sql = @"SELECT a.VenCode+a.DepCode+y.OOCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.OOCode,a.MUSER,a.MTIME,
  698. a.Sequence,a.InvCode,a.Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.OODetailID
  699. ,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,
  700. 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
  701. INTO #TempERP
  702. FROM ICSODeliveryNotice a
  703. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  704. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  705. INNER JOIN ICSOutsourcingOrder y ON a.OODetailID=y.OODetailID AND a.WorkPoint=y.WorkPoint
  706. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  707. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  708. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,OODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  709. FROM #TempERP
  710. DROP TABLE #TempERP";
  711. sql = string.Format(sql, ODNCode, WorkPoint);
  712. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  713. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  714. string resultStr = HTTPHelper.HttpPost("委外到货", ERPUrl.ODeliveryNoticeURL, Inputstr);
  715. Result result = new Result();
  716. result = JsonConvert.DeserializeObject<Result>(resultStr);
  717. if (result.Success)
  718. {
  719. try
  720. {
  721. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  722. foreach (var item in res)
  723. {
  724. JObject jo = (JObject)item;
  725. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  726. foreach (var detail in resdetail)
  727. {
  728. JObject det = (JObject)detail;
  729. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  730. where OODetailID='{4}' AND ODNType='1' AND ODNCode='{5}' ";
  731. ERPupdate = string.Format(ERPupdate, jo["ODNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["OODetailID"], ODNCode);
  732. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  733. {
  734. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  735. }
  736. }
  737. }
  738. }
  739. catch (Exception ex)
  740. {
  741. log.Debug(ex.ToString());
  742. log.Debug(resultStr);
  743. }
  744. }
  745. else
  746. {
  747. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  748. }
  749. #endregion
  750. }
  751. catch (Exception)
  752. {
  753. throw;
  754. }
  755. }
  756. #endregion
  757. #region 委外入库
  758. /// <summary>
  759. /// 委外入库
  760. /// </summary>
  761. /// <param name="TransCode"></param>
  762. /// <param name="TransSequence"></param>
  763. /// <param name="Quantity"></param>
  764. /// <param name="WorkPoint"></param>
  765. /// <param name="cmd"></param>
  766. public static void OutsourcingReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  767. {
  768. try
  769. {
  770. string sql = @"DECLARE @Status VARCHAR(10)
  771. SELECT @Status=c.Status FROM ICSInventoryLot a
  772. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  773. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  774. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  775. IF (@Status IS NULL)
  776. BEGIN
  777. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  778. RETURN
  779. END
  780. ELSE IF (@Status='3')
  781. BEGIN
  782. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  783. RETURN
  784. END
  785. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  786. FROM ICSInventoryLot a
  787. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  788. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  789. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  790. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  791. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  792. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  793. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  794. BEGIN
  795. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  796. END";
  797. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  798. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  799. {
  800. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  801. }
  802. }
  803. catch (Exception)
  804. {
  805. throw;
  806. }
  807. }
  808. /// <summary>
  809. /// 委外入库接口
  810. /// </summary>
  811. /// <param name="TransType"></param>
  812. /// <param name="Identification"></param>
  813. /// <param name="cmd"></param>
  814. public static void OutsourcingReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  815. {
  816. try
  817. {
  818. #region ERP
  819. string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+f.ODNCode AS Costre,c.OODetailID AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,c.OOID,f.ODNCode,f.ODNDetailID,a.MUSER,f.Sequence AS ODNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode) AS Sequence,
  820. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.OODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable
  821. ,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,
  822. 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,conv.Enable AS CompleteVerification
  823. INTO #TempERP
  824. FROM ICSWareHouseLotInfoLog a
  825. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  826. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  827. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  828. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  829. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  830. INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  831. INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint
  832. INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode
  833. AND b.TransSequence = c.Sequence
  834. AND f.OODetailID = c.OODetailID
  835. AND b.WorkPoint = c.WorkPoint
  836. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  837. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  838. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  839. WHERE a.Identification='{0}' AND ERPUpload='0'
  840. GROUP BY c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,f.ODNCode,f.ODNDetailID,f.Sequence,a.InvCode,c.OOID,c.OODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conv.Enable
  841. ,a.WorkPoint,ISNULL(ext.ProjectCode, ''),CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  842. ISNULL(ext.cFree1, ''),ISNULL(ext.cFree2, ''),ISNULL(ext.cFree3, ''),ISNULL(ext.cFree4, ''),ISNULL(ext.cFree5, ''),ISNULL(ext.cFree6, ''),ISNULL(ext.cFree7, ''),ISNULL(ext.cFree8, ''),ISNULL(ext.cFree9, ''),ISNULL(ext.cFree10, '')
  843. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  844. SELECT Costre,Costre2,Sequence,ODNSequence,InvCode,Quantity,Amount,OODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  845. FROM #TempERP
  846. SELECT c.OODetailID AS Costre2,a.TransCode,a.TransSequence AS Sequence,a.InvCode,a.Quantity,c.Amount,c.PickID,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,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
  847. FROM ICSWareHouseLotInfoLog a
  848. INNER JOIN ICSOutsourcingOrder b ON b.OOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  849. INNER JOIN ICSOOPick c ON c.OODetailID=b.OODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  850. INNER JOIN ICSExtension ext ON ext.ID=c.ExtensionID AND ext.WorkPoint=c.WorkPoint
  851. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  852. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  853. WHERE a.Identification='{0}' AND a.TransType='12'
  854. DROP TABLE #TempERP";
  855. sql = string.Format(sql, Identification);
  856. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  857. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
  858. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocURL, Inputstr);
  859. Result result = new Result();
  860. result = JsonConvert.DeserializeObject<Result>(resultStr);
  861. if (result.Success)
  862. {
  863. try
  864. {
  865. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  866. foreach (var item in res)
  867. {
  868. JObject jo = (JObject)item;
  869. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  870. foreach (var detail in resdetail)
  871. {
  872. JObject det = (JObject)detail;
  873. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  874. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), "",cmd, language);
  875. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  876. foreach (var details in resdetails)
  877. {
  878. JObject dets = (JObject)details;
  879. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, det["ERPID"].ToString(),
  880. dets["ERPDetailID"].ToString(), dets["MRCVCode"].ToString(), dets["Sequence"].ToString(), "", cmd, language);
  881. }
  882. }
  883. }
  884. }
  885. catch (Exception ex)
  886. {
  887. log.Debug(ex.ToString());
  888. log.Debug(resultStr);
  889. }
  890. }
  891. else
  892. {
  893. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  894. }
  895. #endregion
  896. }
  897. catch (Exception)
  898. {
  899. throw;
  900. }
  901. }
  902. #endregion
  903. #region 审核的委外到货单
  904. /// <summary>
  905. /// 审核的委外到货单
  906. /// </summary>
  907. /// <param name="TransCode"></param>
  908. /// <param name="TransSequence"></param>
  909. /// <param name="Quantity"></param>
  910. /// <param name="WorkPoint"></param>
  911. /// <param name="cmd"></param>
  912. public static void ODeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  913. {
  914. try
  915. {
  916. string sql = @"DECLARE @Status VARCHAR(10)
  917. SELECT @Status=c.Status FROM ICSInventoryLot a
  918. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  919. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  920. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  921. IF (@Status IS NULL)
  922. BEGIN
  923. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  924. RETURN
  925. END
  926. ELSE IF (@Status='3')
  927. BEGIN
  928. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  929. RETURN
  930. END
  931. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  932. FROM ICSInventoryLot a
  933. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  934. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  935. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  936. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  937. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  938. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  939. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1' AND c.Quantity<c.RCVQuantity)
  940. BEGIN
  941. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  942. END";
  943. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  944. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  945. {
  946. throw new Exception(language.GetNameByCode("WMSAPIInfo117"));//"委外到货单更新失败!");
  947. }
  948. }
  949. catch (Exception)
  950. {
  951. throw;
  952. }
  953. }
  954. /// <summary>
  955. /// 审核的委外到货单接口
  956. /// </summary>
  957. /// <param name="TransType"></param>
  958. /// <param name="Identification"></param>
  959. /// <param name="cmd"></param>
  960. public static void ODeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  961. {
  962. try
  963. {
  964. #region ERP
  965. 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.ODNDetailID,a.InvCode) AS Sequence,
  966. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.ODNDetailID,con.Enable AS UpdateTodoQuantity,conn.Enable
  967. ,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,
  968. 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
  969. INTO #TempERP
  970. FROM ICSWareHouseLotInfoLog a
  971. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  972. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  973. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  974. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  975. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  976. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  977. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  978. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  979. WHERE a.Identification='{0}' AND ERPUpload='0'
  980. GROUP BY c.VenCode,a.ToWarehouseCode,c.ODNCode,a.MUSER,a.InvCode,c.ODNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable
  981. ,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, ''),
  982. 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, '')
  983. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity FROM #TempERP
  984. SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  985. FROM #TempERP
  986. DROP TABLE #TempERP";
  987. sql = string.Format(sql, Identification);
  988. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  989. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  990. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ODeliveryNoticeInURL, Inputstr);
  991. Result result = new Result();
  992. result = JsonConvert.DeserializeObject<Result>(resultStr);
  993. if (result.Success)
  994. {
  995. try
  996. {
  997. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  998. foreach (var item in res)
  999. {
  1000. JObject jo = (JObject)item;
  1001. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1002. foreach (var detail in resdetail)
  1003. {
  1004. JObject det = (JObject)detail;
  1005. string allcol = jo["cWhCode"].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()
  1006. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1007. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1008. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language);
  1009. }
  1010. }
  1011. }
  1012. catch (Exception ex)
  1013. {
  1014. log.Debug(ex.ToString());
  1015. log.Debug(resultStr);
  1016. }
  1017. }
  1018. else
  1019. {
  1020. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1021. }
  1022. #endregion
  1023. }
  1024. catch (Exception)
  1025. {
  1026. throw;
  1027. }
  1028. }
  1029. #endregion
  1030. #region 委外拒收
  1031. /// <summary>
  1032. /// 委外拒收
  1033. /// </summary>
  1034. /// <param name="TransCode"></param>
  1035. /// <param name="TransSequence"></param>
  1036. /// <param name="Quantity"></param>
  1037. /// <param name="WorkPoint"></param>
  1038. /// <param name="cmd"></param>
  1039. public static void OutsourcingRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1040. {
  1041. try
  1042. {
  1043. string sql = @"DECLARE @Status VARCHAR(10)
  1044. SELECT @Status=c.Status FROM ICSInventoryLot a
  1045. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1046. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1047. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  1048. IF (@Status IS NULL)
  1049. BEGIN
  1050. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1051. RETURN
  1052. END
  1053. ELSE IF (@Status='3')
  1054. BEGIN
  1055. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1056. RETURN
  1057. END
  1058. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1059. FROM ICSInventoryLot a
  1060. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1061. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1062. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  1063. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1064. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1065. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1066. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3' AND c.Quantity<c.RCVQuantity)
  1067. BEGIN
  1068. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1069. END";
  1070. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1071. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1072. {
  1073. throw new Exception(language.GetNameByCode("WMSAPIInfo118"));//"委外拒收单更新失败!");
  1074. }
  1075. }
  1076. catch (Exception)
  1077. {
  1078. throw;
  1079. }
  1080. }
  1081. /// <summary>
  1082. /// 委外拒收接口
  1083. /// </summary>
  1084. /// <param name="TransType"></param>
  1085. /// <param name="Identification"></param>
  1086. /// <param name="cmd"></param>
  1087. public static void OutsourcingRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1088. {
  1089. // try
  1090. // {
  1091. // #region ERP
  1092. // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.ODNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNCode,c.ODNDetailID,a.InvCode) AS Sequence,
  1093. // a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.ODNDetailID,Enable AS UpdateTodoQuantity
  1094. // ,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,
  1095. // 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
  1096. // INTO #TempERP
  1097. // FROM ICSWareHouseLotInfoLog a
  1098. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1099. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1100. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1101. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1102. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1103. // INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1104. // INNER JOIN ICSODeliveryNotice d ON c.OODetailID=d.ODNDetailID AND d.WorkPoint=c.WorkPoint
  1105. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1106. // WHERE a.Identification='{0}' AND ERPUpload='0'
  1107. // GROUP BY c.VenCode,a.ToWarehouseCode,c.ODNCode,d.ODNCode,a.MUSER,a.InvCode,d.ODNDetailID,c.ODNDetailID,isnull((c.UnitPrice),0),c.Currency,Enable
  1108. // ,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, ''),
  1109. // 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, '')
  1110. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,ODNCode AS DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint FROM #TempERP
  1111. //SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID AS DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1112. // FROM #TempERP
  1113. // DROP TABLE #TempERP";
  1114. // sql = string.Format(sql, Identification);
  1115. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1116. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  1117. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  1118. // Result result = new Result();
  1119. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  1120. // if (result.Success)
  1121. // {
  1122. // try
  1123. // {
  1124. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1125. // foreach (var item in res)
  1126. // {
  1127. // JObject jo = (JObject)item;
  1128. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1129. // foreach (var detail in resdetail)
  1130. // {
  1131. // JObject det = (JObject)detail;
  1132. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["OODetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1133. // }
  1134. // }
  1135. // }
  1136. // catch (Exception ex)
  1137. // {
  1138. // log.Debug(ex.ToString());
  1139. // log.Debug(resultStr);
  1140. // }
  1141. // }
  1142. // else
  1143. // {
  1144. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1145. // }
  1146. // #endregion
  1147. // }
  1148. // catch (Exception)
  1149. // {
  1150. // throw;
  1151. // }
  1152. }
  1153. /// <summary>
  1154. /// 委外拒收接口
  1155. /// </summary>
  1156. /// <param name="TransType"></param>
  1157. /// <param name="Identification"></param>
  1158. /// <param name="cmd"></param>
  1159. public static void OutsourcingRejectDocInNewERP(string ODNCode, string OJDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1160. {
  1161. try
  1162. {
  1163. #region ERP
  1164. string sql = @"SELECT a.VenCode+a.DepCode+a.ODNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,a.ODNCode,a.MUSER,a.MTIME,
  1165. a.Sequence,a.InvCode,Sum(x.Quantity) AS Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.ODNDetailID
  1166. ,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,
  1167. 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
  1168. INTO #TempERP
  1169. FROM ICSODeliveryNotice a
  1170. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1171. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  1172. INNER JOIN ICSODeliveryNotice x ON a.ODNDetailID=x.OODetailID AND a.WorkPoint=x.WorkPoint
  1173. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  1174. GROUP BY a.VenCode,a.DepCode,a.ODNCode,a.MUSER,a.MTIME,a.Sequence,a.InvCode,a.Amount,a.Quantity,a.UnitPrice,a.Currency,a.ODNDetailID,
  1175. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  1176. 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, '')
  1177. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  1178. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,ODNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1179. FROM #TempERP
  1180. DROP TABLE #TempERP";
  1181. sql = string.Format(sql, ODNCode, WorkPoint);
  1182. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1183. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  1184. string resultStr = HTTPHelper.HttpPost("委外拒收", ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  1185. Result result = new Result();
  1186. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1187. if (result.Success)
  1188. {
  1189. try
  1190. {
  1191. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1192. foreach (var item in res)
  1193. {
  1194. JObject jo = (JObject)item;
  1195. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1196. foreach (var detail in resdetail)
  1197. {
  1198. JObject det = (JObject)detail;
  1199. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1200. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  1201. where OODetailID='{4}' AND ODNType='3' AND ODNCode='{5}' ";
  1202. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], OJDNCode);
  1203. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1204. {
  1205. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  1206. }
  1207. }
  1208. }
  1209. }
  1210. catch (Exception ex)
  1211. {
  1212. log.Debug(ex.ToString());
  1213. log.Debug(resultStr);
  1214. }
  1215. }
  1216. else
  1217. {
  1218. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1219. }
  1220. #endregion
  1221. }
  1222. catch (Exception)
  1223. {
  1224. throw;
  1225. }
  1226. }
  1227. #endregion
  1228. #region 委外退货
  1229. /// <summary>
  1230. /// 委外退货
  1231. /// </summary>
  1232. /// <param name="TransCode"></param>
  1233. /// <param name="TransSequence"></param>
  1234. /// <param name="Quantity"></param>
  1235. /// <param name="WorkPoint"></param>
  1236. /// <param name="cmd"></param>
  1237. public static void OutsourcingReturnBack(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1238. {
  1239. try
  1240. {
  1241. string sql = @"DECLARE @Status VARCHAR(10)
  1242. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='2' and WorkPoint='{1}'
  1243. IF (@Status IS NULL)
  1244. BEGIN
  1245. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  1246. RETURN
  1247. END
  1248. ELSE IF (@Status!='2')
  1249. BEGIN
  1250. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  1251. RETURN
  1252. END
  1253. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1254. FROM ICSODeliveryNotice a
  1255. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND ODNType='2'
  1256. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  1257. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND ODNType='2')
  1258. BEGIN
  1259. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  1260. RETURN
  1261. END";
  1262. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1263. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1264. {
  1265. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  1266. }
  1267. }
  1268. catch (Exception)
  1269. {
  1270. throw;
  1271. }
  1272. }
  1273. /// <summary>
  1274. /// 委外退货接口
  1275. /// </summary>
  1276. /// <param name="TransType"></param>
  1277. /// <param name="Identification"></param>
  1278. /// <param name="cmd"></param>
  1279. public static void OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1280. {
  1281. try
  1282. {
  1283. #region ERP
  1284. 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,
  1285. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity
  1286. ,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,
  1287. 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,conv.Enable AS CompleteVerification
  1288. INTO #TempERP
  1289. FROM ICSWareHouseLotInfoLog a
  1290. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1291. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1292. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1293. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1294. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  1295. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1296. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  1297. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '11'
  1298. GROUP BY y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conv.Enable
  1299. ,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, ''),
  1300. 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, '')
  1301. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode AS ODNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  1302. 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
  1303. FROM #TempERP
  1304. DROP TABLE #TempERP";
  1305. sql = string.Format(sql, Identification);
  1306. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1307. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1308. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackURL, Inputstr);
  1309. Result result = new Result();
  1310. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1311. if (result.Success)
  1312. {
  1313. try
  1314. {
  1315. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1316. foreach (var item in res)
  1317. {
  1318. JObject jo = (JObject)item;
  1319. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1320. foreach (var detail in resdetail)
  1321. {
  1322. JObject det = (JObject)detail;
  1323. string allcol = jo["cWhCode"].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()
  1324. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1325. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1326. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language);
  1327. }
  1328. }
  1329. }
  1330. catch (Exception ex)
  1331. {
  1332. log.Debug(ex.ToString());
  1333. log.Debug(resultStr);
  1334. }
  1335. }
  1336. else
  1337. {
  1338. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1339. }
  1340. #endregion
  1341. }
  1342. catch (Exception)
  1343. {
  1344. throw;
  1345. }
  1346. }
  1347. #endregion
  1348. #region 开立委外红字入库
  1349. /// <summary>
  1350. /// 开立委外红字入库
  1351. /// </summary>
  1352. /// <param name="TransCode"></param>
  1353. /// <param name="TransSequence"></param>
  1354. /// <param name="Quantity"></param>
  1355. /// <param name="WorkPoint"></param>
  1356. /// <param name="cmd"></param>
  1357. public static void OutsourcingReceiveDocNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1358. {
  1359. try
  1360. {
  1361. string sql = @"DECLARE @Status VARCHAR(10)
  1362. SELECT @Status=a.Status FROM ICSOutsourcingReceive a
  1363. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1364. IF (@Status IS NULL)
  1365. BEGIN
  1366. RAISERROR('" + language.GetNameByCode("WMSAPIInfo122") + @"',16,1);
  1367. RETURN
  1368. END
  1369. ELSE IF (@Status!='1')
  1370. BEGIN
  1371. RAISERROR('" + language.GetNameByCode("WMSAPIInfo123") + @"',16,1);
  1372. RETURN
  1373. END
  1374. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1375. FROM ICSOutsourcingReceive a
  1376. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1377. IF EXISTS(SELECT a.ID FROM ICSOutsourcingReceive a
  1378. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  1379. BEGIN
  1380. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1381. RETURN
  1382. END";
  1383. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1384. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1385. {
  1386. throw new Exception(language.GetNameByCode("WMSAPIInfo124"));//"委外红字入库单更新失败!");
  1387. }
  1388. }
  1389. catch (Exception)
  1390. {
  1391. throw;
  1392. }
  1393. }
  1394. /// <summary>
  1395. /// 开立委外红字入库接口
  1396. /// </summary>
  1397. /// <param name="TransType"></param>
  1398. /// <param name="Identification"></param>
  1399. /// <param name="cmd"></param>
  1400. public static void OutsourcingReceiveDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1401. {
  1402. try
  1403. {
  1404. #region ERP开立状态单据审核
  1405. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  1406. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1407. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  1408. BEGIN
  1409. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  1410. RETURN
  1411. END
  1412. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1413. FROM ICSWareHouseLotInfoLog a
  1414. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1415. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1416. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1417. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '12'
  1418. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  1419. sql = string.Format(sql, Identification);
  1420. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1421. string Inputstr = JsonConvert.SerializeObject(dt);
  1422. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  1423. Result result = new Result();
  1424. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1425. if (result.Success)
  1426. {
  1427. try
  1428. {
  1429. foreach (DataRow dr in dt.Rows)
  1430. {
  1431. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language);
  1432. }
  1433. }
  1434. catch (Exception ex)
  1435. {
  1436. log.Debug(ex.ToString());
  1437. log.Debug(resultStr);
  1438. }
  1439. }
  1440. else
  1441. {
  1442. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1443. }
  1444. #endregion
  1445. }
  1446. catch (Exception)
  1447. {
  1448. throw;
  1449. }
  1450. }
  1451. #endregion
  1452. }
  1453. }