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

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