纽威

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