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

1443 lines
100 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
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 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.ApplyDetailID 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,conv.Enable AS CompleteVerification
  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. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  510. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  511. GROUP BY y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,con.Enable,conv.Enable
  512. ,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, ''),
  513. 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, '')
  514. UNION ALL
  515. 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,
  516. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  517. ,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,
  518. 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
  519. FROM ICSWareHouseLotInfoLog a
  520. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  521. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  522. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  523. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  524. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  525. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  526. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  527. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  528. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  529. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  530. GROUP BY y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,con.Enable,conv.Enable
  531. ,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, ''),
  532. 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, '')
  533. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  534. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  535. DROP TABLE #TempERP";
  536. }
  537. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  538. {
  539. 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,
  540. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  541. ,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,
  542. 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
  543. INTO #TempERP
  544. FROM ICSWareHouseLotInfoLog a
  545. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  546. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  547. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  548. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  549. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  550. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  551. INNER JOIN ICSOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  552. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  553. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  554. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  555. GROUP BY a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,z.ApplyDetailID,con.Enable,conv.Enable
  556. ,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, ''),
  557. 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, '')
  558. UNION ALL
  559. 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,
  560. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  561. ,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,
  562. 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
  563. FROM ICSWareHouseLotInfoLog a
  564. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  565. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  566. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  567. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  568. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  569. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  570. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  571. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.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,z.ApplyDetailID,con.Enable,conv.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,CompleteVerification 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,0 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,conv.Enable AS CompleteVerification
  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. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=con.WorkPoint
  601. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')=''
  602. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,conv.Enable
  603. ,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, ''),
  604. 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, '')
  605. UNION ALL
  606. 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,
  607. a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity
  608. ,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,
  609. 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
  610. FROM ICSWareHouseLotInfoLog a
  611. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  612. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  613. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  614. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  615. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  616. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  617. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  618. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  619. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  620. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  621. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=con.WorkPoint
  622. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND ISNULL(a.LogID, '')<>''
  623. GROUP BY ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,conv.Enable
  624. ,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, ''),
  625. 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, '')
  626. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  627. BEGIN
  628. RAISERROR('" + language.GetNameByCode("WMSAPIInfo116") + @"',16,1);
  629. END
  630. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  631. SELECT Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  632. DROP TABLE #TempERP";
  633. }
  634. else
  635. {
  636. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  637. }
  638. sql = string.Format(sql, Identification);
  639. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  640. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  641. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDoNegativeURL, Inputstr);
  642. Result result = new Result();
  643. result = JsonConvert.DeserializeObject<Result>(resultStr);
  644. if (result.Success)
  645. {
  646. try
  647. {
  648. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  649. foreach (var item in res)
  650. {
  651. JObject jo = (JObject)item;
  652. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  653. foreach (var detail in resdetail)
  654. {
  655. JObject det = (JObject)detail;
  656. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  657. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  658. }
  659. }
  660. //List<ICSERPReturnIssueNEG> negList = JsonConvert.DeserializeObject<List<ICSERPReturnIssueNEG>>(result.Data.ToString());
  661. //foreach (var neg in negList)
  662. //{
  663. // foreach (var detail in neg.details)
  664. // {
  665. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, detail.SourceDetailID, Identification, neg.ID, detail.DetailID, neg.IssueNEGCode, detail.Sequence, cmd);
  666. // }
  667. //}
  668. }
  669. catch (Exception ex)
  670. {
  671. log.Debug(ex.ToString());
  672. log.Debug(resultStr);
  673. }
  674. }
  675. else
  676. {
  677. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  678. }
  679. #endregion
  680. }
  681. catch (Exception)
  682. {
  683. throw;
  684. }
  685. }
  686. #endregion
  687. #region 委外到货
  688. /// <summary>
  689. /// 委外到货接口
  690. /// </summary>
  691. /// <param name="TransType"></param>
  692. /// <param name="Identification"></param>
  693. /// <param name="cmd"></param>
  694. public static void OutsourcingDeliveryNoticeERP(string ODNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  695. {
  696. try
  697. {
  698. #region ERP
  699. string sql = @"SELECT a.VenCode+a.DepCode+y.OOCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.OOCode,a.MUSER,a.MTIME,
  700. a.Sequence,a.InvCode,a.Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.OODetailID
  701. ,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,
  702. 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
  703. INTO #TempERP
  704. FROM ICSODeliveryNotice a
  705. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  706. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  707. INNER JOIN ICSOutsourcingOrder y ON a.OODetailID=y.OODetailID AND a.WorkPoint=y.WorkPoint
  708. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  709. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  710. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,OODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  711. FROM #TempERP
  712. DROP TABLE #TempERP";
  713. sql = string.Format(sql, ODNCode, WorkPoint);
  714. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  715. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  716. string resultStr = HTTPHelper.HttpPost("委外到货", ERPUrl.ODeliveryNoticeURL, Inputstr);
  717. Result result = new Result();
  718. result = JsonConvert.DeserializeObject<Result>(resultStr);
  719. if (result.Success)
  720. {
  721. try
  722. {
  723. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  724. foreach (var item in res)
  725. {
  726. JObject jo = (JObject)item;
  727. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  728. foreach (var detail in resdetail)
  729. {
  730. JObject det = (JObject)detail;
  731. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  732. where OODetailID='{4}' AND ODNType='1' AND ODNCode='{5}' ";
  733. ERPupdate = string.Format(ERPupdate, jo["ODNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["OODetailID"], ODNCode);
  734. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  735. {
  736. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  737. }
  738. }
  739. }
  740. }
  741. catch (Exception ex)
  742. {
  743. log.Debug(ex.ToString());
  744. log.Debug(resultStr);
  745. }
  746. }
  747. else
  748. {
  749. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  750. }
  751. #endregion
  752. }
  753. catch (Exception)
  754. {
  755. throw;
  756. }
  757. }
  758. #endregion
  759. #region 委外入库
  760. /// <summary>
  761. /// 委外入库
  762. /// </summary>
  763. /// <param name="TransCode"></param>
  764. /// <param name="TransSequence"></param>
  765. /// <param name="Quantity"></param>
  766. /// <param name="WorkPoint"></param>
  767. /// <param name="cmd"></param>
  768. public static void OutsourcingReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  769. {
  770. try
  771. {
  772. string sql = @"DECLARE @Status VARCHAR(10)
  773. SELECT @Status=c.Status FROM ICSInventoryLot a
  774. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  775. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  776. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  777. IF (@Status IS NULL)
  778. BEGIN
  779. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  780. RETURN
  781. END
  782. ELSE IF (@Status='3')
  783. BEGIN
  784. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  785. RETURN
  786. END
  787. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  788. FROM ICSInventoryLot a
  789. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  790. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  791. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  792. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  793. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  794. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  795. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  796. BEGIN
  797. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  798. END";
  799. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  800. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  801. {
  802. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  803. }
  804. }
  805. catch (Exception)
  806. {
  807. throw;
  808. }
  809. }
  810. /// <summary>
  811. /// 委外入库接口
  812. /// </summary>
  813. /// <param name="TransType"></param>
  814. /// <param name="Identification"></param>
  815. /// <param name="cmd"></param>
  816. public static void OutsourcingReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  817. {
  818. try
  819. {
  820. #region ERP
  821. string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+f.ODNCode AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,f.ODNCode,a.MUSER,f.Sequence AS ODNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode) AS Sequence,
  822. 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
  823. ,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,
  824. 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
  825. INTO #TempERP
  826. FROM ICSWareHouseLotInfoLog a
  827. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  828. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  829. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  830. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  831. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  832. INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  833. INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint
  834. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND f.OODetailID=c.OODetailID AND b.WorkPoint=c.WorkPoint
  835. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  836. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  837. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  838. WHERE a.Identification='{0}' AND ERPUpload='0'
  839. GROUP BY c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,lot.Amount,lot.Quantity,f.ODNCode,f.Sequence,a.InvCode,c.OODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conv.Enable
  840. ,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, ''),
  841. 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, '')
  842. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  843. SELECT Costre,Sequence,ODNSequence,InvCode,Quantity,Amount,OODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  844. FROM #TempERP
  845. DROP TABLE #TempERP";
  846. sql = string.Format(sql, Identification);
  847. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  848. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  849. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocURL, Inputstr);
  850. Result result = new Result();
  851. result = JsonConvert.DeserializeObject<Result>(resultStr);
  852. if (result.Success)
  853. {
  854. try
  855. {
  856. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  857. foreach (var item in res)
  858. {
  859. JObject jo = (JObject)item;
  860. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  861. foreach (var detail in resdetail)
  862. {
  863. JObject det = (JObject)detail;
  864. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  865. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  866. }
  867. }
  868. }
  869. catch (Exception ex)
  870. {
  871. log.Debug(ex.ToString());
  872. log.Debug(resultStr);
  873. }
  874. }
  875. else
  876. {
  877. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  878. }
  879. #endregion
  880. }
  881. catch (Exception)
  882. {
  883. throw;
  884. }
  885. }
  886. #endregion
  887. #region 审核的委外到货单
  888. /// <summary>
  889. /// 审核的委外到货单
  890. /// </summary>
  891. /// <param name="TransCode"></param>
  892. /// <param name="TransSequence"></param>
  893. /// <param name="Quantity"></param>
  894. /// <param name="WorkPoint"></param>
  895. /// <param name="cmd"></param>
  896. public static void ODeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  897. {
  898. try
  899. {
  900. string sql = @"DECLARE @Status VARCHAR(10)
  901. SELECT @Status=c.Status FROM ICSInventoryLot a
  902. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  903. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  904. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  905. IF (@Status IS NULL)
  906. BEGIN
  907. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  908. RETURN
  909. END
  910. ELSE IF (@Status='3')
  911. BEGIN
  912. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  913. RETURN
  914. END
  915. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  916. FROM ICSInventoryLot a
  917. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  918. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  919. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  920. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  921. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  922. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  923. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1' AND c.Quantity<c.RCVQuantity)
  924. BEGIN
  925. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  926. END";
  927. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  928. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  929. {
  930. throw new Exception(language.GetNameByCode("WMSAPIInfo117"));//"委外到货单更新失败!");
  931. }
  932. }
  933. catch (Exception)
  934. {
  935. throw;
  936. }
  937. }
  938. /// <summary>
  939. /// 审核的委外到货单接口
  940. /// </summary>
  941. /// <param name="TransType"></param>
  942. /// <param name="Identification"></param>
  943. /// <param name="cmd"></param>
  944. public static void ODeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  945. {
  946. try
  947. {
  948. #region ERP
  949. 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,
  950. 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
  951. ,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,
  952. 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
  953. INTO #TempERP
  954. FROM ICSWareHouseLotInfoLog a
  955. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  956. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  957. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  958. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  959. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  960. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  961. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  962. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  963. INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  964. WHERE a.Identification='{0}' AND ERPUpload='0'
  965. 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,conv.Enable
  966. ,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, ''),
  967. 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, '')
  968. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  969. SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  970. FROM #TempERP
  971. DROP TABLE #TempERP";
  972. sql = string.Format(sql, Identification);
  973. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  974. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  975. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ODeliveryNoticeInURL, Inputstr);
  976. Result result = new Result();
  977. result = JsonConvert.DeserializeObject<Result>(resultStr);
  978. if (result.Success)
  979. {
  980. try
  981. {
  982. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  983. foreach (var item in res)
  984. {
  985. JObject jo = (JObject)item;
  986. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  987. foreach (var detail in resdetail)
  988. {
  989. JObject det = (JObject)detail;
  990. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  991. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  992. }
  993. }
  994. }
  995. catch (Exception ex)
  996. {
  997. log.Debug(ex.ToString());
  998. log.Debug(resultStr);
  999. }
  1000. }
  1001. else
  1002. {
  1003. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1004. }
  1005. #endregion
  1006. }
  1007. catch (Exception)
  1008. {
  1009. throw;
  1010. }
  1011. }
  1012. #endregion
  1013. #region 委外拒收
  1014. /// <summary>
  1015. /// 委外拒收
  1016. /// </summary>
  1017. /// <param name="TransCode"></param>
  1018. /// <param name="TransSequence"></param>
  1019. /// <param name="Quantity"></param>
  1020. /// <param name="WorkPoint"></param>
  1021. /// <param name="cmd"></param>
  1022. public static void OutsourcingRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1023. {
  1024. try
  1025. {
  1026. string sql = @"DECLARE @Status VARCHAR(10)
  1027. SELECT @Status=c.Status FROM ICSInventoryLot a
  1028. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1029. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1030. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  1031. IF (@Status IS NULL)
  1032. BEGIN
  1033. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1034. RETURN
  1035. END
  1036. ELSE IF (@Status='3')
  1037. BEGIN
  1038. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1039. RETURN
  1040. END
  1041. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1042. FROM ICSInventoryLot a
  1043. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1044. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1045. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  1046. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1047. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1048. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1049. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3' AND c.Quantity<c.RCVQuantity)
  1050. BEGIN
  1051. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1052. END";
  1053. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1054. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1055. {
  1056. throw new Exception(language.GetNameByCode("WMSAPIInfo118"));//"委外拒收单更新失败!");
  1057. }
  1058. }
  1059. catch (Exception)
  1060. {
  1061. throw;
  1062. }
  1063. }
  1064. /// <summary>
  1065. /// 委外拒收接口
  1066. /// </summary>
  1067. /// <param name="TransType"></param>
  1068. /// <param name="Identification"></param>
  1069. /// <param name="cmd"></param>
  1070. public static void OutsourcingRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1071. {
  1072. try
  1073. {
  1074. #region ERP
  1075. 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,
  1076. 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
  1077. ,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,
  1078. 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
  1079. INTO #TempERP
  1080. FROM ICSWareHouseLotInfoLog a
  1081. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1082. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1083. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1084. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1085. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1086. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1087. INNER JOIN ICSODeliveryNotice d ON c.OODetailID=d.ODNDetailID AND d.WorkPoint=c.WorkPoint
  1088. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1089. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  1090. WHERE a.Identification='{0}' AND ERPUpload='0'
  1091. 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,conv.Enable
  1092. ,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, ''),
  1093. 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, '')
  1094. SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,ODNCode AS DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint,CompleteVerification FROM #TempERP
  1095. 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
  1096. FROM #TempERP
  1097. DROP TABLE #TempERP";
  1098. sql = string.Format(sql, Identification);
  1099. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1100. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  1101. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  1102. Result result = new Result();
  1103. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1104. if (result.Success)
  1105. {
  1106. try
  1107. {
  1108. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1109. foreach (var item in res)
  1110. {
  1111. JObject jo = (JObject)item;
  1112. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1113. foreach (var detail in resdetail)
  1114. {
  1115. JObject det = (JObject)detail;
  1116. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["OODetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1117. }
  1118. }
  1119. }
  1120. catch (Exception ex)
  1121. {
  1122. log.Debug(ex.ToString());
  1123. log.Debug(resultStr);
  1124. }
  1125. }
  1126. else
  1127. {
  1128. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1129. }
  1130. #endregion
  1131. }
  1132. catch (Exception)
  1133. {
  1134. throw;
  1135. }
  1136. }
  1137. #endregion
  1138. #region 委外退货
  1139. /// <summary>
  1140. /// 委外退货
  1141. /// </summary>
  1142. /// <param name="TransCode"></param>
  1143. /// <param name="TransSequence"></param>
  1144. /// <param name="Quantity"></param>
  1145. /// <param name="WorkPoint"></param>
  1146. /// <param name="cmd"></param>
  1147. public static void OutsourcingReturnBack(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1148. {
  1149. try
  1150. {
  1151. string sql = @"DECLARE @Status VARCHAR(10)
  1152. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='2' and WorkPoint='{1}'
  1153. IF (@Status IS NULL)
  1154. BEGIN
  1155. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  1156. RETURN
  1157. END
  1158. ELSE IF (@Status!='2')
  1159. BEGIN
  1160. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  1161. RETURN
  1162. END
  1163. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1164. FROM ICSODeliveryNotice a
  1165. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND ODNType='2'
  1166. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  1167. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND ODNType='2')
  1168. BEGIN
  1169. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  1170. RETURN
  1171. END";
  1172. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1173. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1174. {
  1175. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  1176. }
  1177. }
  1178. catch (Exception)
  1179. {
  1180. throw;
  1181. }
  1182. }
  1183. /// <summary>
  1184. /// 委外退货接口
  1185. /// </summary>
  1186. /// <param name="TransType"></param>
  1187. /// <param name="Identification"></param>
  1188. /// <param name="cmd"></param>
  1189. public static void OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1190. {
  1191. try
  1192. {
  1193. #region ERP
  1194. 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,
  1195. 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
  1196. ,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,
  1197. 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
  1198. INTO #TempERP
  1199. FROM ICSWareHouseLotInfoLog a
  1200. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1201. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1202. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1203. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1204. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  1205. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1206. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  1207. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '11'
  1208. 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
  1209. ,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, ''),
  1210. 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, '')
  1211. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode AS ODNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification FROM #TempERP
  1212. 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
  1213. FROM #TempERP
  1214. DROP TABLE #TempERP";
  1215. sql = string.Format(sql, Identification);
  1216. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1217. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1218. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackURL, Inputstr);
  1219. Result result = new Result();
  1220. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1221. if (result.Success)
  1222. {
  1223. try
  1224. {
  1225. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1226. foreach (var item in res)
  1227. {
  1228. JObject jo = (JObject)item;
  1229. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1230. foreach (var detail in resdetail)
  1231. {
  1232. JObject det = (JObject)detail;
  1233. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1234. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1235. }
  1236. }
  1237. }
  1238. catch (Exception ex)
  1239. {
  1240. log.Debug(ex.ToString());
  1241. log.Debug(resultStr);
  1242. }
  1243. }
  1244. else
  1245. {
  1246. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1247. }
  1248. #endregion
  1249. }
  1250. catch (Exception)
  1251. {
  1252. throw;
  1253. }
  1254. }
  1255. #endregion
  1256. #region 开立委外红字入库
  1257. /// <summary>
  1258. /// 开立委外红字入库
  1259. /// </summary>
  1260. /// <param name="TransCode"></param>
  1261. /// <param name="TransSequence"></param>
  1262. /// <param name="Quantity"></param>
  1263. /// <param name="WorkPoint"></param>
  1264. /// <param name="cmd"></param>
  1265. public static void OutsourcingReceiveDocNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1266. {
  1267. try
  1268. {
  1269. string sql = @"DECLARE @Status VARCHAR(10)
  1270. SELECT @Status=a.Status FROM ICSOutsourcingReceive a
  1271. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1272. IF (@Status IS NULL)
  1273. BEGIN
  1274. RAISERROR('" + language.GetNameByCode("WMSAPIInfo122") + @"',16,1);
  1275. RETURN
  1276. END
  1277. ELSE IF (@Status!='1')
  1278. BEGIN
  1279. RAISERROR('" + language.GetNameByCode("WMSAPIInfo123") + @"',16,1);
  1280. RETURN
  1281. END
  1282. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1283. FROM ICSOutsourcingReceive a
  1284. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1285. IF EXISTS(SELECT a.ID FROM ICSOutsourcingReceive a
  1286. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  1287. BEGIN
  1288. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1289. RETURN
  1290. END";
  1291. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  1292. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1293. {
  1294. throw new Exception(language.GetNameByCode("WMSAPIInfo124"));//"委外红字入库单更新失败!");
  1295. }
  1296. }
  1297. catch (Exception)
  1298. {
  1299. throw;
  1300. }
  1301. }
  1302. /// <summary>
  1303. /// 开立委外红字入库接口
  1304. /// </summary>
  1305. /// <param name="TransType"></param>
  1306. /// <param name="Identification"></param>
  1307. /// <param name="cmd"></param>
  1308. public static void OutsourcingReceiveDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language)
  1309. {
  1310. try
  1311. {
  1312. #region ERP开立状态单据审核
  1313. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  1314. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1315. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  1316. BEGIN
  1317. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  1318. RETURN
  1319. END
  1320. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1321. FROM ICSWareHouseLotInfoLog a
  1322. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1323. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1324. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1325. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '12'
  1326. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  1327. sql = string.Format(sql, Identification);
  1328. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1329. string Inputstr = JsonConvert.SerializeObject(dt);
  1330. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  1331. Result result = new Result();
  1332. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1333. if (result.Success)
  1334. {
  1335. try
  1336. {
  1337. foreach (DataRow dr in dt.Rows)
  1338. {
  1339. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", cmd, language);
  1340. }
  1341. }
  1342. catch (Exception ex)
  1343. {
  1344. log.Debug(ex.ToString());
  1345. log.Debug(resultStr);
  1346. }
  1347. }
  1348. else
  1349. {
  1350. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1351. }
  1352. #endregion
  1353. }
  1354. catch (Exception)
  1355. {
  1356. throw;
  1357. }
  1358. }
  1359. #endregion
  1360. }
  1361. }