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.

3118 lines
232 KiB

2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks ago
2 weeks 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,string enableCode,string TransID)
  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}' and a.id='{5}'
  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.id='{5}' 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 a.id='{5}' and b.WorkPoint='{1}' AND
  56. (dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{4}',2,2,''))<a.IssueQuantity)
  57. BEGIN
  58. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  59. RETURN
  60. END";
  61. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,enableCode, TransID);
  62. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  63. {
  64. throw new Exception(language.GetNameByCode("WMSAPIInfo107"));
  65. }
  66. }
  67. catch (Exception)
  68. {
  69. throw;
  70. }
  71. }
  72. /// <summary>
  73. /// 委外发料接口
  74. /// </summary>
  75. /// <param name="TransType"></param>
  76. /// <param name="Identification"></param>
  77. /// <param name="cmd"></param>
  78. public static void OutsourcingIssueDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  79. {
  80. try
  81. {
  82. #region ERP
  83. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  84. INTO #NewTempERP
  85. from ICSWareHouseLotInfoLog
  86. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '5'
  87. SELECT isnull(y.DepCode,'') + a.FromWarehouseCode + y.OOCode + a.MUSER AS Costre,
  88. 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,
  89. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(x.Amount/x.Quantity)) ELSE '0' END AS Amount,x.PickID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  90. ,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,
  91. 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
  92. , x.OODetailID
  93. INTO #TempERP
  94. FROM #NewTempERP a
  95. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  96. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  97. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  98. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  99. INNER JOIN ICSOutsourcingOrder y ON a.TransCode=y.OOCode AND a.WorkPoint=y.WorkPoint
  100. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND a.TransSequence=y.Sequence+'~'+x.Sequence AND x.WorkPoint=y.WorkPoint
  101. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  102. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  103. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  104. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  105. GROUP BY conWhCode.Enable,inv.AmountEnable,y.DepCode,a.FromWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,x.OODetailID,con.Enable,conv.Enable,conStock.Enable
  106. ,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, ''),
  107. 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, '')
  108. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
  109. SELECT Costre,WarehouseCode AS WHCode,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,PickID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,OODetailID as SourceLineID FROM #TempERP
  110. DROP TABLE #TempERP
  111. DROP TABLE #NewTempERP";
  112. sql = string.Format(sql, Identification);
  113. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  114. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  115. string resultStr = "";
  116. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["IsU9Api"]))
  117. { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingIssueDocURL, Inputstr); }
  118. else { resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDocURL, Inputstr); }
  119. Result result = new Result();
  120. result = JsonConvert.DeserializeObject<Result>(resultStr);
  121. if (result.Success)
  122. {
  123. try
  124. {
  125. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  126. foreach (var item in res)
  127. {
  128. JObject jo = (JObject)item;
  129. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  130. foreach (var detail in resdetail)
  131. {
  132. JObject det = (JObject)detail;
  133. string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  134. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  135. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  136. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language, BusinessCode);
  137. }
  138. }
  139. }
  140. catch (Exception ex)
  141. {
  142. log.Debug(ex.ToString());
  143. log.Debug(resultStr);
  144. }
  145. }
  146. else
  147. {
  148. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  149. }
  150. #endregion
  151. }
  152. catch (Exception)
  153. {
  154. throw;
  155. }
  156. }
  157. #endregion
  158. #region 委外领料申请单生产发料
  159. /// <summary>
  160. /// 委外领料申请单生产发料
  161. /// </summary>
  162. /// <param name="TransCode"></param>
  163. /// <param name="TransSequence"></param>
  164. /// <param name="Quantity"></param>
  165. /// <param name="WorkPoint"></param>
  166. /// <param name="cmd"></param>
  167. public static void OOApply(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string enableCode,string TransID)
  168. {
  169. try
  170. {
  171. string sql = @"DECLARE @Status VARCHAR(10)
  172. SELECT @Status=a.Status FROM ICSOApply a
  173. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' AND a.WorkPoint='{1}'
  174. IF (@Status IS NULL)
  175. BEGIN
  176. RAISERROR('" + language.GetNameByCode("WMSAPIInfo108") + @"',16,1);
  177. RETURN
  178. END
  179. ELSE IF (@Status!='2')
  180. BEGIN
  181. RAISERROR('" + language.GetNameByCode("WMSAPIInfo109") + @"',16,1);
  182. RETURN
  183. END
  184. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  185. FROM ICSOApply a
  186. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' AND a.WorkPoint='{1}'
  187. IF EXISTS(SELECT a.ID FROM ICSOApply a
  188. WHERE a.ApplyCode='{0}' AND a.Sequence='{3}' and a.id='{5}' and a.WorkPoint='{1}' AND
  189. (dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{4}',2,2,''))<a.IssueQuantity)
  190. BEGIN
  191. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  192. RETURN
  193. END";
  194. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,enableCode, TransID);
  195. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  196. {
  197. throw new Exception(language.GetNameByCode("WMSAPIInfo110"));
  198. }
  199. }
  200. catch (Exception)
  201. {
  202. throw;
  203. }
  204. }
  205. /// <summary>
  206. /// 委外领料申请单生产发料接口
  207. /// </summary>
  208. /// <param name="TransType"></param>
  209. /// <param name="Identification"></param>
  210. /// <param name="cmd"></param>
  211. public static void OOApplyERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  212. {
  213. try
  214. {
  215. #region ERP
  216. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode,transid
  217. INTO #NewTempERP
  218. from ICSWareHouseLotInfoLog
  219. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '6'
  220. 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,
  221. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(b.Amount/b.Quantity)) ELSE '0' END AS Amount,b.ApplyDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  222. ,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,
  223. 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
  224. INTO #TempERP
  225. FROM #NewTempERP a
  226. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  227. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  228. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  229. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  230. INNER JOIN ICSOApply b ON a.TransCode=b.ApplyCode AND a.TransSequence=b.Sequence and a.transid=b.id AND a.WorkPoint=b.WorkPoint
  231. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  232. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  233. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  234. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  235. GROUP BY conWhCode.Enable,inv.AmountEnable,a.FromWarehouseCode,b.ApplyCode,a.MUSER,a.InvCode,b.ApplyDetailID,con.Enable,conv.Enable,conStock.Enable
  236. ,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, ''),
  237. 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, '')
  238. SELECT DISTINCT Costre,WorkPoint,'' AS DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock FROM #TempERP
  239. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ApplyDetailID AS SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  240. DROP TABLE #TempERP
  241. DROP TABLE #NewTempERP";
  242. sql = string.Format(sql, Identification);
  243. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  244. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  245. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOApplyURL, Inputstr);
  246. Result result = new Result();
  247. result = JsonConvert.DeserializeObject<Result>(resultStr);
  248. if (result.Success)
  249. {
  250. try
  251. {
  252. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  253. foreach (var item in res)
  254. {
  255. JObject jo = (JObject)item;
  256. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  257. foreach (var detail in resdetail)
  258. {
  259. JObject det = (JObject)detail;
  260. string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  261. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  262. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  263. det["DetailID"].ToString(), jo["IssueCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  264. }
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. log.Debug(ex.ToString());
  270. log.Debug(resultStr);
  271. }
  272. }
  273. else
  274. {
  275. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  276. }
  277. #endregion
  278. }
  279. catch (Exception)
  280. {
  281. throw;
  282. }
  283. }
  284. #endregion
  285. #region 委外材料出库单生产发料
  286. /// <summary>
  287. /// 委外材料出库单生产发料
  288. /// </summary>
  289. /// <param name="TransCode"></param>
  290. /// <param name="TransSequence"></param>
  291. /// <param name="Quantity"></param>
  292. /// <param name="WorkPoint"></param>
  293. /// <param name="cmd"></param>
  294. public static void OOIssue(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  295. {
  296. try
  297. {
  298. string sql = @"DECLARE @Status VARCHAR(10)
  299. SELECT @Status=a.Status FROM ICSOIssue a
  300. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}'
  301. IF (@Status IS NULL)
  302. BEGIN
  303. RAISERROR('" + language.GetNameByCode("WMSAPIInfo111") + @"',16,1);
  304. RETURN
  305. END
  306. ELSE IF (@Status!='1')
  307. BEGIN
  308. RAISERROR('" + language.GetNameByCode("WMSAPIInfo112") + @"',16,1);
  309. RETURN
  310. END
  311. UPDATE a SET IssueQuantity=ISNULL(IssueQuantity,0)+'{2}'
  312. FROM ICSOIssue a
  313. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}'
  314. IF EXISTS(SELECT a.ID FROM ICSOIssue a
  315. WHERE a.IssueCode='{0}' AND a.Sequence='{3}' and a.id='{4}' and a.WorkPoint='{1}' AND a.Quantity<a.IssueQuantity)
  316. BEGIN
  317. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  318. RETURN
  319. END";
  320. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  321. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  322. {
  323. throw new Exception(language.GetNameByCode("WMSAPIInfo113"));
  324. }
  325. }
  326. catch (Exception)
  327. {
  328. throw;
  329. }
  330. }
  331. /// <summary>
  332. /// 委外材料出库单生产发料接口
  333. /// </summary>
  334. /// <param name="TransType"></param>
  335. /// <param name="Identification"></param>
  336. /// <param name="cmd"></param>
  337. public static void OOIssueERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  338. {
  339. try
  340. {
  341. #region ERP开立状态单据审核
  342. string sql = "";
  343. if (DBHelper.IsPNU9())
  344. {
  345. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  346. INTO #NewTempERP
  347. from ICSWareHouseLotInfoLog
  348. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '7'
  349. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  350. FROM #NewTempERP a
  351. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  352. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  353. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  354. GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  355. DROP TABLE #NewTempERP";
  356. sql = string.Format(sql, Identification);
  357. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.IssueQuantity) AS ISSQty,a.transCode from ICSOIssue b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.IssueCode AND a.WorkPoint=b.WorkPoint
  358. where a.Identification='{0}' GROUP BY a.transCode";
  359. checksql = string.Format(checksql, Identification);
  360. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  361. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  362. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  363. string trancode = chekdt.Rows[0]["transCode"].ToString();
  364. if (SUMQty - ISSQty == 0)
  365. {
  366. string pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  367. INTO #NewTempERP
  368. from ICSWareHouseLotInfoLog
  369. WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '7' and EATTRIBUTE1<>'1'
  370. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  371. FROM #NewTempERP a
  372. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  373. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  374. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  375. GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  376. DROP TABLE #NewTempERP";
  377. pnsql = string.Format(pnsql, trancode);
  378. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  379. string Inputstr = JsonConvert.SerializeObject(dt);
  380. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOIssueURL, Inputstr);
  381. Result result = new Result();
  382. result = JsonConvert.DeserializeObject<Result>(resultStr);
  383. if (result.Success)
  384. {
  385. try
  386. {
  387. foreach (DataRow dr in dt.Rows)
  388. {
  389. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  390. }
  391. }
  392. catch (Exception ex)
  393. {
  394. log.Debug(ex.ToString());
  395. log.Debug(resultStr);
  396. }
  397. }
  398. else
  399. {
  400. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  401. }
  402. }
  403. }
  404. else
  405. {
  406. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  407. INTO #NewTempERP
  408. from ICSWareHouseLotInfoLog
  409. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '7'
  410. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  411. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  412. WHERE a.Identification='{0}' AND b.Quantity!=b.IssueQuantity)
  413. BEGIN
  414. RAISERROR('" + language.GetNameByCode("WMSAPIInfo095") + @"',16,1);
  415. RETURN
  416. END
  417. SELECT b.IssueID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  418. FROM #NewTempERP a
  419. INNER JOIN ICSOIssue b ON a.TransCode=b.IssueCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  420. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  421. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  422. GROUP BY b.IssueID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  423. DROP TABLE #NewTempERP";
  424. sql = string.Format(sql, Identification);
  425. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  426. string Inputstr = JsonConvert.SerializeObject(dt);
  427. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OOIssueURL, Inputstr);
  428. Result result = new Result();
  429. result = JsonConvert.DeserializeObject<Result>(resultStr);
  430. if (result.Success)
  431. {
  432. try
  433. {
  434. foreach (DataRow dr in dt.Rows)
  435. {
  436. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  437. }
  438. }
  439. catch (Exception ex)
  440. {
  441. log.Debug(ex.ToString());
  442. log.Debug(resultStr);
  443. }
  444. }
  445. else
  446. {
  447. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  448. }
  449. }
  450. #endregion
  451. }
  452. catch (Exception)
  453. {
  454. throw;
  455. }
  456. }
  457. #endregion
  458. #region 委外退料
  459. /// <summary>
  460. /// 委外退料
  461. /// </summary>
  462. /// <param name="TransCode"></param>
  463. /// <param name="TransSequence"></param>
  464. /// <param name="Quantity"></param>
  465. /// <param name="WorkPoint"></param>
  466. /// <param name="cmd"></param>
  467. public static void OutsourcingIssueDoNegative(string TransType, string LogID, string LotNo, string Quantity, string WorkPoint, string TransCode, string TransSequence, SqlCommand cmd, Dictionary<string, string> language)
  468. {
  469. try
  470. {
  471. string table = "";
  472. string sql = "";
  473. if (string.IsNullOrWhiteSpace(LogID))
  474. {
  475. string type = "";
  476. string quantitySql = "c.Quantity";
  477. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  478. {
  479. table = "INNER JOIN ICSOOPick e ON c.SourceDetailID=e.PickID AND c.WorkPoint=e.WorkPoint";
  480. type = "1";
  481. quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn008', c.Quantity,1,1,'')";
  482. }
  483. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  484. {
  485. table = "INNER JOIN ICSOApply e ON c.SourceDetailID=e.ApplyDetailID AND c.WorkPoint=e.WorkPoint";
  486. type = "2";
  487. quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn009', c.Quantity,1,1,'')";
  488. }
  489. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  490. {
  491. table = "INNER JOIN ICSOIssue e ON c.SourceDetailID=e.IssueDetailID AND c.WorkPoint=e.WorkPoint";
  492. type = "3";
  493. quantitySql = "dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn010', c.Quantity,1,1,'')";
  494. }
  495. else
  496. {
  497. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  498. }
  499. #region 新条码
  500. sql = @"UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  501. FROM ICSInventoryLot a
  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 ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  505. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  506. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  507. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  508. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  509. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  510. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND {5}<c.IssueNegQuantity)
  511. BEGIN
  512. RAISERROR('" + language.GetNameByCode("WMSAPIInfo114") + @"',16,1);
  513. END
  514. UPDATE e SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  515. FROM ICSInventoryLot a
  516. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  517. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  518. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  519. {3}
  520. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}'
  521. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  522. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  523. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  524. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  525. {3}
  526. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND d.Type='{4}' AND e.IssueQuantity<0)
  527. BEGIN
  528. RAISERROR('" + language.GetNameByCode("WMSAPIInfo193") + @"',16,1);
  529. END";
  530. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, type, quantitySql);
  531. #endregion
  532. }
  533. else
  534. {
  535. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  536. {
  537. table = @"INNER JOIN ICSOutsourcingOrder b ON a.TransCode=b.OOCode AND a.WorkPoint=b.WorkPoint
  538. INNER JOIN ICSOOPick c ON b.OODetailID = c.OODetailID AND b.WorkPoint = c.WorkPoint AND a.TransSequence = b.Sequence + '~' + c.Sequence";
  539. }
  540. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  541. {
  542. table = "INNER JOIN ICSOApply c ON a.TransCode=c.ApplyCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  543. }
  544. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  545. {
  546. table = "INNER JOIN ICSOIssue c ON a.TransCode=c.IssueCode AND a.TransSequence=c.Sequence AND a.WorkPoint=c.WorkPoint";
  547. }
  548. else
  549. {
  550. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  551. }
  552. #region 原条码
  553. //sql = @"UPDATE c SET IssueQuantity=ISNULL(IssueQuantity,0)-'{2}'
  554. // FROM ICSWareHouseLotInfoLog a
  555. // {3}
  556. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}'
  557. // IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfoLog a
  558. // {3}
  559. // WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND a.ID='{4}' AND c.IssueQuantity<0)
  560. // BEGIN
  561. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo193") + @"',16,1);
  562. // END";
  563. sql = @"IF EXISTS(select * from ICSOApplyNegDetail where Quantity>'{2}' and OApplyNegCode='{5}' and Sequence='{6}')
  564. BEGIN
  565. UPDATE c SET IssueNegQuantity=ISNULL(IssueNegQuantity,0)+'{2}'
  566. FROM ICSOApplyNegDetail c
  567. INNER JOIN ICSOApplyNeg d ON c.OApplyNegCode=d.OApplyNegCode AND c.WorkPoint=d.WorkPoint
  568. WHERE c.WorkPoint='{1}' and c.OApplyNegCode='{5}' and c.Sequence='{6}'
  569. END";
  570. sql = string.Format(sql, LotNo, WorkPoint, Quantity, table, LogID, TransCode, TransSequence);
  571. #endregion
  572. }
  573. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  574. {
  575. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  576. }
  577. }
  578. catch (Exception)
  579. {
  580. throw;
  581. }
  582. }
  583. /// <summary>
  584. /// 委外退料接口
  585. /// </summary>
  586. /// <param name="TransType"></param>
  587. /// <param name="Identification"></param>
  588. /// <param name="cmd"></param>
  589. public static void OutsourcingIssueDoNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  590. {
  591. try
  592. {
  593. #region ERP
  594. string sql = string.Empty;
  595. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  596. {
  597. if (DBHelper.IsU9()) {
  598. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  599. INTO #NewTempERP
  600. from ICSWareHouseLotInfoLog
  601. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  602. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  603. INTO #NewDouTempERP
  604. from ICSWareHouseLotInfoLog
  605. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  606. 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 Sequence1,
  607. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  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,y.Sequence
  610. INTO #TempERP
  611. FROM #NewTempERP a
  612. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  613. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  614. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  615. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  616. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  617. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  618. INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  619. INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  620. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  621. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  622. GROUP BY inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,con.Enable,conStock.Enable
  623. ,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, ''),
  624. 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, ''),y.Sequence
  625. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  626. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  627. DROP TABLE #TempERP
  628. DROP TABLE #NewTempERP
  629. DROP TABLE #NewDouTempERP"; }
  630. else { sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  631. INTO #NewTempERP
  632. from ICSWareHouseLotInfoLog
  633. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  634. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  635. INTO #NewDouTempERP
  636. from ICSWareHouseLotInfoLog
  637. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  638. SELECT isnull(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,
  639. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  640. ,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,
  641. 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
  642. INTO #TempERP
  643. FROM #NewTempERP a
  644. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  645. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  646. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  647. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  648. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  649. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  650. INNER JOIN ICSOOPick x ON c.SourceDetailID=x.PickID AND c.WorkPoint=x.WorkPoint
  651. INNER JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  652. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  653. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  654. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  655. GROUP BY conWhCode.Enable,inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,x.PickID,con.Enable,conStock.Enable
  656. ,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, ''),
  657. 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, ''),y.Sequence
  658. UNION ALL
  659. SELECT isnull(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,
  660. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,x.PickID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  661. ,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,
  662. 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
  663. FROM #NewDouTempERP a
  664. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  665. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  666. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  667. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  668. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  669. INNER JOIN ICSOutsourcingOrder y ON b.TransCode=y.OOCode AND b.WorkPoint=y.WorkPoint
  670. INNER JOIN ICSOOPick x ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint AND b.TransSequence = y.Sequence + '~' + x.Sequence
  671. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  672. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  673. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  674. GROUP BY conWhCode.Enable,inv.AmountEnable,y.DepCode,a.ToWarehouseCode,y.OOCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,x.PickID,con.Enable,conStock.Enable
  675. ,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, ''),
  676. 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, '')
  677. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  678. SELECT WarehouseCode AS WHCode,Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  679. DROP TABLE #TempERP
  680. DROP TABLE #NewTempERP
  681. DROP TABLE #NewDouTempERP"; }
  682. }
  683. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  684. {
  685. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  686. INTO #NewTempERP
  687. from ICSWareHouseLotInfoLog
  688. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  689. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  690. INTO #NewDouTempERP
  691. from ICSWareHouseLotInfoLog
  692. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  693. 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,
  694. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  695. ,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,
  696. ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  697. INTO #TempERP
  698. FROM #NewTempERP a
  699. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  700. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  701. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  702. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  703. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  704. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  705. INNER JOIN ICSOApply z ON c.SourceDetailID=z.ApplyDetailID AND c.WorkPoint=z.WorkPoint
  706. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  707. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  708. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  709. GROUP BY conWhCode.Enable,inv.AmountEnable,a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,con.Enable,conStock.Enable
  710. ,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, ''),
  711. 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, '')
  712. UNION ALL
  713. 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,
  714. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,z.ApplyDetailID AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  715. ,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,
  716. 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
  717. FROM #NewDouTempERP a
  718. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  719. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  720. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  721. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  722. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  723. INNER JOIN ICSOApply z ON b.TransCode=z.ApplyCode AND b.TransSequence=z.Sequence AND b.WorkPoint=z.WorkPoint
  724. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  725. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  726. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  727. GROUP BY conWhCode.Enable,inv.AmountEnable,a.ToWarehouseCode,z.ApplyCode,a.MUSER,a.InvCode,lot.Amount,lot.Quantity,z.ApplyDetailID,con.Enable,conStock.Enable
  728. ,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, ''),
  729. 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, '')
  730. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,'' AS SourceType,ApplyCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  731. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  732. DROP TABLE #TempERP
  733. DROP TABLE #NewTempERP
  734. DROP TABLE #NewDouTempERP";
  735. }
  736. //根据材料出库单查询上游单据,根据上游单据生成红字材料出库
  737. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  738. {
  739. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  740. INTO #NewTempERP
  741. from ICSWareHouseLotInfoLog
  742. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')=''
  743. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID
  744. INTO #NewDouTempERP
  745. from ICSWareHouseLotInfoLog
  746. WHERE Identification='{0}' AND ERPUpload='0' AND ISNULL(LogID, '')<>''
  747. IF EXISTS(select * FROM #NewTempERP a
  748. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  749. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  750. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  751. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  752. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  753. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  754. INNER JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  755. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  756. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  757. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  758. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  759. BEGIN
  760. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  761. RETURN
  762. END
  763. IF EXISTS(select * FROM #NewDouTempERP a
  764. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  765. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  766. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  767. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  768. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  769. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  770. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  771. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  772. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  773. where m.ApplyDetailID<>null and z.ApplyDetailID=null)
  774. BEGIN
  775. RAISERROR('" + language.GetNameByCode("WMSAPIInfo480") + @"',16,1);
  776. RETURN
  777. END
  778. 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,
  779. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  780. ,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,
  781. 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
  782. INTO #TempERP
  783. FROM #NewTempERP a
  784. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  785. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  786. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  787. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  788. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  789. INNER JOIN ICSOApplyNegDetail c ON b.TransCode=c.OApplyNegCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  790. INNER JOIN ICSOIssue m ON c.SourceDetailID=m.IssueDetailID AND c.WorkPoint=m.WorkPoint
  791. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  792. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  793. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  794. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  795. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  796. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  797. GROUP BY conWhCode.Enable,inv.AmountEnable,ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,lot.Amount,lot.Quantity,conStock.Enable
  798. ,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, ''),
  799. 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, '')
  800. UNION ALL
  801. 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,
  802. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,ISNULL(m.ApplyDetailID, m.PickID) AS SourceDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  803. ,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,
  804. 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
  805. FROM #NewDouTempERP a
  806. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  807. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  808. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  809. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  810. INNER JOIN ICSWareHouseLotInfoLog b ON a.LogID=b.ID AND a.WorkPoint=b.WorkPoint
  811. INNER JOIN ICSOIssue m ON b.TransCode=m.IssueCode AND b.TransSequence=m.Sequence AND b.WorkPoint=m.WorkPoint
  812. LEFT JOIN ICSOOPick x ON m.PickID=x.PickID AND m.WorkPoint=x.WorkPoint
  813. LEFT JOIN ICSOutsourcingOrder y ON x.OODetailID=y.OODetailID AND x.WorkPoint=y.WorkPoint
  814. LEFT JOIN ICSOApply z ON m.ApplyDetailID=z.ApplyDetailID AND m.WorkPoint=z.WorkPoint
  815. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  816. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  817. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  818. GROUP BY conWhCode.Enable,inv.AmountEnable,ISNULL(y.DepCode, ''),a.ToWarehouseCode,ISNULL(z.ApplyCode, y.OOCode),a.MUSER,a.InvCode,m.PickID,m.ApplyDetailID,con.Enable,lot.Amount,lot.Quantity,conStock.Enable
  819. ,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, ''),
  820. 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, '')
  821. IF EXISTS(SELECT Costre FROM #TempERP WHERE SourceType='{0}')
  822. BEGIN
  823. RAISERROR('" + language.GetNameByCode("WMSAPIInfo116") + @"',16,1);
  824. END
  825. SELECT DISTINCT Costre,WorkPoint,DepCode,WarehouseCode AS WHCode,SourceType,OOCode AS SourceCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  826. SELECT Costre,Sequence,InvCode,Quantity,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,Amount,SourceDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  827. DROP TABLE #TempERP
  828. DROP TABLE #NewTempERP
  829. DROP TABLE #NewDouTempERP";
  830. }
  831. else
  832. {
  833. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  834. }
  835. sql = string.Format(sql, Identification);
  836. log.Debug("退料erpsql:"+sql);
  837. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  838. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  839. string resultStr = "";
  840. if (DBHelper.IsU9())
  841. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingIssueDoNegativeURL, Inputstr);
  842. else
  843. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingIssueDoNegativeURL, Inputstr);
  844. Result result = new Result();
  845. result = JsonConvert.DeserializeObject<Result>(resultStr);
  846. if (result.Success)
  847. {
  848. try
  849. {
  850. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  851. foreach (var item in res)
  852. {
  853. JObject jo = (JObject)item;
  854. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  855. foreach (var detail in resdetail)
  856. {
  857. JObject det = (JObject)detail;
  858. string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  859. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  860. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["SourceDetailID"].ToString(), Identification, jo["ID"].ToString(),
  861. det["DetailID"].ToString(), jo["IssueNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  862. }
  863. }
  864. //List<ICSERPReturnIssueNEG> negList = JsonConvert.DeserializeObject<List<ICSERPReturnIssueNEG>>(result.Data.ToString());
  865. //foreach (var neg in negList)
  866. //{
  867. // foreach (var detail in neg.details)
  868. // {
  869. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, detail.SourceDetailID, Identification, neg.ID, detail.DetailID, neg.IssueNEGCode, detail.Sequence, cmd);
  870. // }
  871. //}
  872. }
  873. catch (Exception ex)
  874. {
  875. log.Debug(ex.ToString());
  876. log.Debug(resultStr);
  877. }
  878. }
  879. else
  880. {
  881. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  882. }
  883. #endregion
  884. }
  885. catch (Exception)
  886. {
  887. throw;
  888. }
  889. }
  890. #endregion
  891. #region 委外到货
  892. /// <summary>
  893. /// 委外到货接口
  894. /// </summary>
  895. /// <param name="TransType"></param>
  896. /// <param name="Identification"></param>
  897. /// <param name="cmd"></param>
  898. public static void OutsourcingDeliveryNoticeERP(string ODNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  899. {
  900. try
  901. {
  902. #region ERP
  903. string sql = @"SELECT a.VenCode+a.DepCode+y.OOCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.OOCode,a.MUSER,a.MTIME,conStock.Enable AS CompleteVerification,
  904. a.Sequence,a.InvCode,a.Quantity,CASE invBat.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.OODetailID
  905. ,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,
  906. 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
  907. INTO #TempERP
  908. FROM ICSODeliveryNotice a
  909. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  910. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  911. INNER JOIN ICSOutsourcingOrder y ON a.OODetailID=y.OODetailID AND a.WorkPoint=y.WorkPoint
  912. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='CompleteVerification003'
  913. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  914. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,CompleteVerification FROM #TempERP
  915. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,OODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  916. FROM #TempERP
  917. DROP TABLE #TempERP";
  918. sql = string.Format(sql, ODNCode, WorkPoint);
  919. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  920. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  921. string resultStr = HTTPHelper.HttpPost("委外到货", ERPUrl.ODeliveryNoticeURL, Inputstr);
  922. Result result = new Result();
  923. result = JsonConvert.DeserializeObject<Result>(resultStr);
  924. if (result.Success)
  925. {
  926. try
  927. {
  928. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  929. foreach (var item in res)
  930. {
  931. JObject jo = (JObject)item;
  932. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["osArriveorderDetailRet"].ToString());
  933. foreach (var detail in resdetail)
  934. {
  935. JObject det = (JObject)detail;
  936. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  937. where OODetailID='{4}' AND ODNType='1' AND ODNCode='{5}' and Sequence='{6}'";
  938. ERPupdate = string.Format(ERPupdate, jo["ODNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["OODetailID"], ODNCode, det["Sequence"].ToString().Substring(0, det["Sequence"].ToString().Length - 1));
  939. log.Debug("到货单回写sql:"+ERPupdate);
  940. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  941. {
  942. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  943. }
  944. }
  945. }
  946. }
  947. catch (Exception ex)
  948. {
  949. log.Debug(ex.ToString());
  950. log.Debug(resultStr);
  951. }
  952. }
  953. else
  954. {
  955. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  956. }
  957. #endregion
  958. }
  959. catch (Exception)
  960. {
  961. throw;
  962. }
  963. }
  964. #endregion
  965. #region 委外入库
  966. /// <summary>
  967. /// 委外入库
  968. /// </summary>
  969. /// <param name="TransCode"></param>
  970. /// <param name="TransSequence"></param>
  971. /// <param name="Quantity"></param>
  972. /// <param name="WorkPoint"></param>
  973. /// <param name="cmd"></param>
  974. public static void OutsourcingReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  975. {
  976. try
  977. {
  978. string sql = @"DECLARE @Status VARCHAR(10)
  979. SELECT @Status=c.Status FROM ICSInventoryLot a
  980. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  981. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  982. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  983. IF (@Status IS NULL)
  984. BEGIN
  985. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  986. RETURN
  987. END
  988. ELSE IF (@Status='3')
  989. BEGIN
  990. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  991. RETURN
  992. END
  993. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  994. FROM ICSInventoryLot a
  995. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  996. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  997. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  998. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  999. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1000. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1001. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1002. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn004', c.Quantity,1,1,'')<c.InQuantity)
  1003. BEGIN
  1004. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1005. END
  1006. --
  1007. if EXISTS(select top 10 * from ICSODeliveryNotice a
  1008. inner join ICSOutsourcingOrder b on a.OODetailID = b.OODetailID and a.OODetailID=a.ODNDetailID and a.ooid = a.ODNID)
  1009. BEGIN
  1010. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1011. FROM ICSInventoryLot a
  1012. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1013. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1014. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1015. END
  1016. ";
  1017. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1018. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1019. {
  1020. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  1021. }
  1022. }
  1023. catch (Exception)
  1024. {
  1025. throw;
  1026. }
  1027. }
  1028. /// <summary>
  1029. /// 委外入库(奥美)
  1030. /// </summary>
  1031. /// <param name="LotNo"></param>
  1032. /// <param name="Quantity"></param>
  1033. /// <param name="WorkPoint"></param>
  1034. /// <param name="cmd"></param>
  1035. /// <param name="language"></param>
  1036. public static void OutsourcingReceiveAMDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1037. {
  1038. try
  1039. {
  1040. string sql = @"DECLARE @Status VARCHAR(10)
  1041. SELECT @Status=c.Status FROM ICSInventoryLot a
  1042. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1043. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1044. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1045. IF (@Status IS NULL)
  1046. BEGIN
  1047. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1048. RETURN
  1049. END
  1050. ELSE IF (@Status='3')
  1051. BEGIN
  1052. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1053. RETURN
  1054. END
  1055. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  1056. FROM ICSInventoryLot a
  1057. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1058. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1059. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1060. --IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1061. -- INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1062. -- INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1063. -- WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  1064. --BEGIN
  1065. -- RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1066. --END";
  1067. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1068. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1069. {
  1070. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  1071. }
  1072. }
  1073. catch (Exception)
  1074. {
  1075. throw;
  1076. }
  1077. }
  1078. /// <summary>
  1079. /// 委外入库接口
  1080. /// </summary>
  1081. /// <param name="TransType"></param>
  1082. /// <param name="Identification"></param>
  1083. /// <param name="cmd"></param>
  1084. public static void OutsourcingReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1085. {
  1086. try
  1087. {
  1088. string outwhcode = "";
  1089. DataTable flag = null;
  1090. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  1091. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1092. #region ERP
  1093. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1094. INTO #NewTempERP
  1095. from ICSWareHouseLotInfoLog
  1096. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1097. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode,isnull(EATTRIBUTE3,'') as EATTRIBUTE3
  1098. INTO #NewDouTempERP
  1099. from ICSWareHouseLotInfoLog
  1100. WHERE Identification='{0}' AND TransType='13' and BusinessCode ='60'
  1101. SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+f.ODNCode AS Costre,c.OODetailID+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, '')+
  1102. 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, '') AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,c.OOID,f.ODNCode,case when ConErp.enable=1 then f.ODNDetailID else '' end ODNDetailID,a.MUSER,f.Sequence AS ODNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode) AS Sequence,
  1103. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.OODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose,conStockneww.Enable AS CompleteVerification,conWhCode.Enable AS ErpWhCode
  1104. ,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,
  1105. 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,a.TransSequence,lot.eattribute10 as Reason
  1106. INTO #TempERP
  1107. FROM #NewTempERP a
  1108. INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP002'
  1109. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1110. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1111. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1112. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1113. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1114. --INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1115. --INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  1116. left JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1117. INNER JOIN ICSODeliveryNotice f ON (g.OASNCode=f.OASNCode or a.TransCode = f.ODNCode) AND a.WorkPoint=f.WorkPoint AND (conerp.enable = 0 or lot.ExtensionID=f.ExtensionID)
  1118. INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode
  1119. AND b.TransSequence = c.Sequence
  1120. AND f.OODetailID = c.OODetailID
  1121. AND b.WorkPoint = c.WorkPoint
  1122. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1123. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1124. --INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP002'
  1125. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  1126. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose002'
  1127. INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005'
  1128. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1129. GROUP BY conWhCode.Enable,ConErp.Enable,conStockneww.Enable,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,f.ODNCode,f.ODNDetailID,f.Sequence,a.TransSequence,a.InvCode,c.OOID,c.OODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
  1130. ,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, ''),
  1131. 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, ''),lot.eattribute10
  1132. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,
  1133. Enable,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  1134. SELECT Costre,Costre2,Sequence,ODNSequence,TransSequence,
  1135. InvCode,Quantity,Amount,OODetailID,ODNDetailID,Currency,UnitPrice,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,
  1136. ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Reason
  1137. FROM #TempERP
  1138. SELECT a.FromWarehouseCode AS WHCode,c.OODetailID+te.ProjectCode+te.BatchCode+te.Version+te.Brand+te.cFree1+te.cFree2+te.cFree3+te.cFree4+te.cFree5+te.cFree6+te.cFree7+te.cFree8+te.cFree9+te.cFree10 AS Costre2,
  1139. a.TransCode,a.TransSequence AS Sequence,a.InvCode,SUM(a.Quantity) as Quantity,SUM((a.Quantity)*(c.Amount/c.Quantity)) AS Amount,
  1140. c.PickID,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
  1141. ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,
  1142. ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,
  1143. ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  1144. FROM #NewDouTempERP a
  1145. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1146. INNER JOIN ICSOutsourcingOrder b ON b.OOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  1147. INNER JOIN ICSOOPick c ON c.OODetailID=b.OODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1148. INNER JOIN ICSExtension ext ON ext.ID=lot.ExtensionID AND ext.WorkPoint=lot.WorkPoint
  1149. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1150. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1151. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
  1152. and c.OODetailID+a.EATTRIBUTE3 = c.OODetailID+te.ProjectCode+te.BatchCode+te.Version+te.Brand+te.cFree1+te.cFree2+te.cFree3+te.cFree4+te.cFree5+te.cFree6+te.cFree7+te.cFree8+te.cFree9+te.cFree10
  1153. GROUP BY a.EATTRIBUTE3,a.FromWarehouseCode,c.OODetailID,a.TransCode,a.TransSequence,a.InvCode,c.PickID,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, ''),
  1154. 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, ''),a.TransSequence,te.ProjectCode,te.BatchCode,te.Version,te.Brand,te.cFree1,te.cFree2,te.cFree3,te.cFree4,te.cFree5,te.cFree6,te.cFree7,te.cFree8,te.cFree9,te.cFree10
  1155. DROP TABLE #TempERP
  1156. DROP TABLE #NewTempERP
  1157. DROP TABLE #NewDouTempERP";
  1158. sql = string.Format(sql, Identification, BusinessCode);
  1159. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1160. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
  1161. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocURL, Inputstr);
  1162. log.Debug("委外入库ERP接口返回值:" + Environment.NewLine + resultStr);
  1163. Result result = new Result();
  1164. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1165. if (result.Success)
  1166. {
  1167. try
  1168. {
  1169. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1170. {
  1171. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1172. from ICSWareHouseLotInfoLog
  1173. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1174. newsql = string.Format(newsql, Identification, BusinessCode);
  1175. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  1176. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1177. foreach (var item in res)
  1178. {
  1179. JObject jo = (JObject)item;
  1180. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1181. foreach (var detail in resdetail)
  1182. {
  1183. JObject det = (JObject)detail;
  1184. string allcol = "" + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  1185. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1186. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1187. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1188. if (det["detailss"] != null)
  1189. {
  1190. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1191. foreach (var details in resdetails)
  1192. {
  1193. JObject dets = (JObject)details;
  1194. if (dets != null)
  1195. {
  1196. //for (int i = 0; i < dt.Rows.Count; i++)
  1197. //{
  1198. //派纳倒冲排除仓库逻辑
  1199. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  1200. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1201. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1'";
  1202. whsql = string.Format(whsql);
  1203. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  1204. if (dtt.Rows.Count > 0 && dtt != null)
  1205. {
  1206. if (!dtt.Rows[0]["F_ItemCode"].ToString().Equals(dets["WHCode"].ToString()))
  1207. {
  1208. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  1209. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  1210. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  1211. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  1212. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(),
  1213. dets["Brand"].ToString(), cmd, language);
  1214. }
  1215. //回写已领数量
  1216. sql = @"UPDATE ICSOOPick SET IssueQuantity=Quantity WHERE PickID='{0}' AND WorkPoint='{1}'";
  1217. sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1218. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1219. {
  1220. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1221. }
  1222. }
  1223. else
  1224. {
  1225. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  1226. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  1227. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  1228. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  1229. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(),
  1230. dets["Brand"].ToString(), cmd, language);
  1231. //回写已领数量
  1232. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1233. sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1234. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1235. {
  1236. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1237. }
  1238. }
  1239. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", dt.Rows[i]["LotNo"].ToString(), dets["Quantity"].ToString(),
  1240. //"", dt.Rows[i]["WorkPoint"].ToString(), "", "", cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  1241. //}
  1242. }
  1243. }
  1244. }
  1245. }
  1246. }
  1247. }
  1248. else
  1249. {
  1250. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1251. foreach (var item in res)
  1252. {
  1253. JObject jo = (JObject)item;
  1254. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1255. foreach (var detail in resdetail)
  1256. {
  1257. JObject det = (JObject)detail;
  1258. string allcol = "" + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  1259. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1260. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1261. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1262. if (det["detailss"] != null)
  1263. {
  1264. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1265. foreach (var details in resdetails)
  1266. {
  1267. JObject dets = (JObject)details;
  1268. if (dets != null)
  1269. {
  1270. //直接回写
  1271. string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1272. FROM ICSWareHouseLotInfoLog a
  1273. LEFT JOIN ICSOutsourcingOrder b ON a.TransCode=b.OOCode AND a.WorkPoint=b.WorkPoint
  1274. LEFT JOIN ICSOOPick c ON b.OODetailID=c.OODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1275. WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode='60'";
  1276. ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["DetailID"].ToString(), dets["MRCVCode"].ToString()
  1277. , dets["Sequence"].ToString(), BusinessCode);
  1278. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1279. {
  1280. //throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"委外倒冲回写失败!";
  1281. }
  1282. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, dets["ERPID"].ToString(),
  1283. // dets[" "].ToString(), dets["MRCVCode"].ToString(), dets["Sequence"].ToString(), allcol, cmd, language);
  1284. }
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. }
  1291. catch (Exception ex)
  1292. {
  1293. log.Debug(ex.ToString());
  1294. log.Debug(resultStr);
  1295. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  1296. }
  1297. }
  1298. else
  1299. {
  1300. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1301. }
  1302. #endregion
  1303. }
  1304. catch (Exception)
  1305. {
  1306. throw;
  1307. }
  1308. }
  1309. public static void CreateOOArriveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode, string doctype)
  1310. {
  1311. try
  1312. {
  1313. #region ERP
  1314. string sql = @"
  1315. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1316. INTO #NewTempERP
  1317. from ICSWareHouseLotInfoLog
  1318. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1319. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode
  1320. INTO #NewDouTempERP
  1321. from ICSWareHouseLotInfoLog
  1322. WHERE Identification='{0}' AND TransType='13'
  1323. SELECT c.VenCode+a.ToWarehouseCode+c.OOCode+a.MUSER+f.ODNCode AS Costre,c.OODetailID+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, '')+
  1324. 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, '') AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.OOCode,c.OOID,f.ODNCode,f.ODNDetailID,a.MUSER,f.Sequence AS ODNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.OOCode,c.OODetailID,a.InvCode) AS Sequence,
  1325. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.OODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose,conStockneww.Enable AS CompleteVerification
  1326. ,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,
  1327. 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,a.TransSequence
  1328. ,'{2}' as DocTyppe,getdate() as DocDate,c.Sequence as srcDocPOLineNo
  1329. INTO #TempERP
  1330. FROM #NewTempERP a
  1331. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1332. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1333. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1334. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1335. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1336. INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1337. INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  1338. INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode
  1339. AND b.TransSequence = c.Sequence
  1340. AND f.OODetailID = c.OODetailID
  1341. AND b.WorkPoint = c.WorkPoint
  1342. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1343. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1344. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  1345. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose002'
  1346. INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005'
  1347. GROUP BY conStockneww.Enable,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.OOCode,a.MUSER,f.ODNCode,f.ODNDetailID,f.Sequence,a.TransSequence,a.InvCode,c.OOID,c.OODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
  1348. ,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, ''),
  1349. 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, ''),c.Sequence
  1350. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode as POCode,ODNCode as DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose,DocTyppe, DocDate, DocDate as ArrDate FROM #TempERP
  1351. SELECT Costre,Costre2,Sequence,ODNSequence as DNSequence,TransSequence,InvCode,Quantity,Amount,OODetailID as PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WhCode,srcDocPOLineNo
  1352. FROM #TempERP
  1353. DROP TABLE #TempERP
  1354. DROP TABLE #NewTempERP
  1355. DROP TABLE #NewDouTempERP
  1356. ";
  1357. // select LotNo, WorkPoint, InvCode, ToWarehouseCode, MUSER, Quantity, TransSequence
  1358. //INTO #NewTempERP
  1359. //from ICSWareHouseLotInfoLog
  1360. //WHERE Identification = '{0}' AND ERPUpload = '0' AND BusinessCode = '{1}'
  1361. //SELECT c.VenCode + a.ToWarehouseCode + c.POCode + a.MUSER + CASE WHEN(LEN(f.DNID) >= 20) THEN '' ELSE f.DNCode END AS Costre, c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>= 20) THEN '' ELSE f.DNCode END AS DNCode, CASE WHEN(LEN(f.DNID) >= 20) THEN '1' ELSE '0' END AS HasDN,a.MUSER,CASE WHEN(LEN(f.DNID)>= 20) THEN '' ELSE f.Sequence END AS DNSequence, ROW_NUMBER() OVER(ORDER BY c.VenCode, a.ToWarehouseCode, c.POCode, c.PODetailID, a.InvCode) AS Sequence,
  1362. // a.InvCode,SUM(a.Quantity) AS Quantity, CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/ lot.Quantity)) ELSE '0' END AS Amount,isnull((c.UnitPrice), 0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable,conStock.Enable AS UpdateStock,conStocknew.Enable AS IsFillClose
  1363. // --,a.lotno AS Costre2
  1364. // ,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,
  1365. // 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,'{2}' as DocTyppe,getdate() as DocDate,c.Sequence as srcDocPOLineNo
  1366. // INTO #TempERP
  1367. // FROM #NewTempERP a
  1368. // INNER JOIN ICSInventoryLot lot ON a.LotNo = lot.LotNo AND a.WorkPoint = lot.WorkPoint
  1369. // INNER JOIN ICSExtension ext ON lot.ExtensionID = ext.ID AND lot.WorkPoint = ext.WorkPoint
  1370. // INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  1371. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode = invBat.InvCode AND a.ToWarehouseCode = invBat.WHCode AND a.WorkPoint = invBat.WorkPoint
  1372. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  1373. // INNER JOIN ICSASNDetail g ON a.LotNo = g.LotNo AND a.WorkPoint = g.WorkPoint
  1374. // INNER JOIN ICSDeliveryNotice f ON g.ASNCode = f.ASNCode AND g.WorkPoint = f.WorkPoint AND lot.ExtensionID = f.ExtensionID
  1375. // INNER JOIN ICSPurchaseOrder c ON b.TransCode = c.POCode AND b.TransSequence = c.Sequence AND f.PODetailID = c.PODetailID AND b.WorkPoint = c.WorkPoint
  1376. // INNER JOIN ICSConfiguration con ON con.Code = 'Stock001' AND a.WorkPoint = con.WorkPoint
  1377. // INNER JOIN ICSConfiguration conn ON a.WorkPoint = conn.WorkPoint AND conn.Code = 'Escrow001'
  1378. //INNER JOIN ICSConfiguration conStock ON a.WorkPoint = conStock.WorkPoint AND conStock.Code = 'UpdateStock001'
  1379. //INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint = conStocknew.WorkPoint AND conStocknew.Code = 'FillClose003'
  1380. // GROUP BY--a.LotNo,
  1381. // a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,CASE WHEN(LEN(f.DNID)>= 20) THEN '' ELSE f.DNCode END, f.DNID,a.MUSER,a.InvCode,CASE WHEN(LEN(f.DNID)>= 20) THEN '' ELSE f.Sequence END, c.PODetailID,isnull((c.UnitPrice), 0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
  1382. // ,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, ''),
  1383. // 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, ''),c.Sequence
  1384. // SELECT DISTINCT Costre, WorkPoint, VenCode, WarehouseCode AS WhCode, POCode, DNCode, MUSER AS[User],SYSDATETIME() AS MTime, Enable, UpdateTodoQuantity, UpdateStock, IsFillClose, DocTyppe, DocDate, DocDate as ArrDate FROM #TempERP
  1385. // SELECT Costre,
  1386. // --Costre2,
  1387. // Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WhCode,srcDocPOLineNo
  1388. // FROM #TempERP
  1389. //SELECT SUM(a.Quantity) AS Quantity--,a.LotNo AS Costre2,a.LotNo,
  1390. // FROM ICSWareHouseLotInfoLog a
  1391. // INNER JOIN ICSInventoryLot lot ON a.LotNo = lot.LotNo AND a.WorkPoint = lot.WorkPoint
  1392. // INNER JOIN ICSExtension ext ON lot.ExtensionID = ext.ID AND lot.WorkPoint = ext.WorkPoint
  1393. // INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  1394. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode = invBat.InvCode AND a.ToWarehouseCode = invBat.WHCode AND a.WorkPoint = invBat.WorkPoint
  1395. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  1396. // INNER JOIN ICSASNDetail g ON a.LotNo = g.LotNo AND a.WorkPoint = g.WorkPoint
  1397. // INNER JOIN ICSDeliveryNotice f ON g.ASNCode = f.ASNCode AND g.WorkPoint = f.WorkPoint AND lot.ExtensionID = f.ExtensionID
  1398. // INNER JOIN ICSPurchaseOrder c ON b.TransCode = c.POCode AND b.TransSequence = c.Sequence AND f.PODetailID = c.PODetailID AND b.WorkPoint = c.WorkPoint
  1399. // INNER JOIN #TempERP te ON te.Sequence=a.TransSequence
  1400. // WHERE a.Identification = '{0}' AND ERPUpload = '0' AND BusinessCode = '{1}'
  1401. // --GROUP BY a.LotNo
  1402. // SELECT DISTINCT HasDN FROM #TempERP
  1403. // DROP TABLE #TempERP
  1404. // DROP TABLE #NewTempERP
  1405. sql = string.Format(sql, Identification, BusinessCode, doctype);
  1406. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1407. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1408. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  1409. //var IsDNCode = ds.Tables[3];
  1410. //if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  1411. //{
  1412. // throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  1413. //}
  1414. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9CreatePOArrivURL, Inputstr);
  1415. Result result = new Result();
  1416. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1417. if (result.Success)
  1418. {
  1419. try
  1420. {
  1421. //JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1422. //foreach (var item in res)
  1423. //{
  1424. // JObject jo = (JObject)item;
  1425. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1426. // foreach (var detail in resdetail)
  1427. // {
  1428. // JObject det = (JObject)detail;
  1429. // string allcol = jo["cWhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  1430. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1431. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1432. // det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1433. // }
  1434. //}
  1435. }
  1436. catch (Exception ex)
  1437. {
  1438. log.Debug(ex.ToString());
  1439. log.Debug(resultStr);
  1440. }
  1441. }
  1442. else
  1443. {
  1444. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1445. }
  1446. #endregion
  1447. }
  1448. catch (Exception)
  1449. {
  1450. throw;
  1451. }
  1452. }
  1453. #endregion
  1454. #region 委外入库
  1455. /// <summary>
  1456. /// 委外入库
  1457. /// </summary>
  1458. /// <param name="TransCode"></param>
  1459. /// <param name="TransSequence"></param>
  1460. /// <param name="Quantity"></param>
  1461. /// <param name="WorkPoint"></param>
  1462. /// <param name="cmd"></param>
  1463. public static void OutsourcingReceiveRcvDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1464. {
  1465. try
  1466. {
  1467. string sql = @"DECLARE @Status VARCHAR(10)
  1468. SELECT @Status=c.Status FROM ICSInventoryLot a
  1469. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1470. INNER JOIN ICSOutsourcingReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1471. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1472. IF (@Status IS NULL)
  1473. BEGIN
  1474. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1475. RETURN
  1476. END
  1477. ELSE IF (@Status='2')
  1478. BEGIN
  1479. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1480. RETURN
  1481. END
  1482. UPDATE c SET RcvQuantity=ISNULL(RcvQuantity,0)+'{2}'
  1483. FROM ICSInventoryLot a
  1484. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1485. INNER JOIN ICSOutsourcingReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1486. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1487. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1488. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1489. INNER JOIN ICSOutsourcingReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1490. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1491. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', c.Quantity,1,1,'')<c.RcvQuantity)
  1492. BEGIN
  1493. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1494. END";
  1495. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1496. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1497. {
  1498. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  1499. }
  1500. }
  1501. catch (Exception)
  1502. {
  1503. throw;
  1504. }
  1505. }
  1506. /// <summary>
  1507. /// 委外入库-入库单接口
  1508. /// </summary>
  1509. /// <param name="TransType"></param>
  1510. /// <param name="Identification"></param>
  1511. /// <param name="cmd"></param>
  1512. public static void OutsourcingReceiveRcvDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string UserCode)
  1513. {
  1514. try
  1515. {
  1516. #region ERP开立状态单据审核
  1517. string sql = "";
  1518. string outwhcode = "";
  1519. string pnsql = "";
  1520. string Inputstr = "";
  1521. DataTable flag = null;
  1522. DataTable dt = null;
  1523. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  1524. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1525. string sqlflag = @"select * from ICSConfiguration ConErp where ConErp.Code='UploadERP001' and conerp.enable = 1 ";
  1526. DataTable dtflag = DBHelper.SQlReturnData(sqlflag, cmd);
  1527. if (dtflag.Rows.Count > 0 && dtflag != null)
  1528. {
  1529. sql = @"
  1530. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1531. INTO #NewTempERP
  1532. from ICSWareHouseLotInfoLog
  1533. WHERE Identification='{0}' AND ERPUpload='0'
  1534. SELECT b.RCVID+b.Sequence+b.RCVDetailID AS Costre,b.RCVID AS ID,b.RCVDetailID AS DNDetailID,b.Sequence AS DNSequence,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1535. INTO #TempERP
  1536. FROM #NewTempERP a
  1537. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1538. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1539. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1540. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1541. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  1542. select Costre,DNSequence,DNDetailID from #TempERP
  1543. DROP TABLE #TempERP
  1544. DROP TABLE #NewTempERP";
  1545. sql = string.Format(sql, Identification);
  1546. string checksql = @"select distinct b.Quantity AS SUMQty,b.RCVQuantity AS ISSQty,a.transCode,a.transSequence from ICSOutsourcingReceive b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.RCVCode AND b.Sequence=a.TransSequence AND a.WorkPoint=b.WorkPoint
  1547. where a.Identification='{0}' GROUP BY a.transCode,b.Quantity,b.RCVQuantity,a.transSequence";
  1548. checksql = string.Format(checksql, Identification);
  1549. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  1550. for (int i = 0; i < chekdt.Rows.Count; i++)
  1551. {
  1552. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[i]["SUMQty"]);
  1553. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[i]["ISSQty"]);
  1554. string trancode = chekdt.Rows[i]["transCode"].ToString();
  1555. string transSequence = chekdt.Rows[i]["transSequence"].ToString();
  1556. if (SUMQty - ISSQty == 0)
  1557. {
  1558. if (DBHelper.IsPNU9())
  1559. {
  1560. pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1561. INTO #NewTempERP
  1562. from ICSWareHouseLotInfoLog
  1563. WHERE TransCode='{0}' and TransSequence='{1}' AND ERPUpload='0' and EATTRIBUTE1<>'1'
  1564. SELECT b.RCVID+b.Sequence+b.RCVDetailID AS Costre,b.RCVID AS ID,b.RCVDetailID AS DNDetailID,b.Sequence AS DNSequence,'{2}' AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1565. INTO #TempERP
  1566. FROM #NewTempERP a
  1567. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1568. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1569. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1570. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1571. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  1572. select Costre,DNSequence,DNDetailID from #TempERP
  1573. DROP TABLE #TempERP
  1574. DROP TABLE #NewTempERP";
  1575. pnsql = string.Format(pnsql, trancode, transSequence, UserCode);
  1576. }
  1577. else
  1578. {
  1579. pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1580. INTO #NewTempERP
  1581. from ICSWareHouseLotInfoLog
  1582. WHERE TransCode='{0}' and TransSequence='{1}' AND ERPUpload='0'
  1583. SELECT b.RCVID+b.Sequence+b.RCVDetailID AS Costre,b.RCVID AS ID,b.RCVDetailID AS DNDetailID,b.Sequence AS DNSequence,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1584. INTO #TempERP
  1585. FROM #NewTempERP a
  1586. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1587. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1588. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1589. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1590. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  1591. select Costre,DNSequence,DNDetailID from #TempERP
  1592. DROP TABLE #TempERP
  1593. DROP TABLE #NewTempERP";
  1594. pnsql = string.Format(pnsql, trancode, transSequence);
  1595. }
  1596. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  1597. Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1598. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr);
  1599. Result result = new Result();
  1600. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1601. if (result.Success)
  1602. {
  1603. try
  1604. {
  1605. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1606. {
  1607. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1608. from ICSWareHouseLotInfoLog
  1609. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1610. newsql = string.Format(newsql, Identification, BusinessCode);
  1611. DataTable dtnew = DBHelper.SQlReturnData(newsql, cmd);
  1612. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1613. foreach (var item in res)
  1614. {
  1615. JObject jo = (JObject)item;
  1616. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, jo["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1617. //派纳倒冲排除仓库逻辑
  1618. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  1619. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1620. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1' and b.F_ItemCode='{0}'";
  1621. whsql = string.Format(whsql, jo["WHCode"].ToString());
  1622. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  1623. if (dtt.Rows.Count > 0 && dtt != null)
  1624. {
  1625. //if (!jo["WHCode"].ToString().Equals(dtt.Rows[0]["F_ItemCode"].ToString()))
  1626. //{
  1627. // //倒冲
  1628. // ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1629. // jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1630. // jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1631. // jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1632. // jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1633. // jo["Brand"].ToString(), cmd, language);
  1634. //}
  1635. //回写已领数量
  1636. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1637. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1638. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1639. {
  1640. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1641. }
  1642. //for (int i = 0; i < dtt.Rows.Count; i++)
  1643. //{
  1644. // if (outwhcode == "")
  1645. // {
  1646. // outwhcode += "" + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1647. // }
  1648. // else
  1649. // {
  1650. // outwhcode += "," + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1651. // }
  1652. //}
  1653. }
  1654. else
  1655. {
  1656. //倒冲
  1657. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1658. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1659. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1660. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1661. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1662. jo["Brand"].ToString(), cmd, language);
  1663. //回写已领数量
  1664. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1665. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1666. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1667. {
  1668. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1669. }
  1670. }
  1671. }
  1672. }
  1673. else
  1674. {
  1675. foreach (DataRow dr in dt.Rows)
  1676. {
  1677. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1678. }
  1679. }
  1680. }
  1681. catch (Exception ex)
  1682. {
  1683. log.Debug(ex.ToString());
  1684. log.Debug(resultStr);
  1685. }
  1686. }
  1687. else
  1688. {
  1689. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1690. }
  1691. }
  1692. }
  1693. }
  1694. else
  1695. {
  1696. sql = @"
  1697. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1698. INTO #NewTempERP
  1699. from ICSWareHouseLotInfoLog
  1700. WHERE Identification='{0}' AND ERPUpload='0'
  1701. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1702. FROM #NewTempERP a
  1703. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1704. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1705. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1706. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1707. DROP TABLE #NewTempERP";
  1708. sql = string.Format(sql, Identification);
  1709. dt = DBHelper.SQlReturnData(sql, cmd);
  1710. Inputstr = JsonConvert.SerializeObject(dt);
  1711. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr);
  1712. Result result = new Result();
  1713. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1714. if (result.Success)
  1715. {
  1716. try
  1717. {
  1718. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1719. {
  1720. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1721. from ICSWareHouseLotInfoLog
  1722. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1723. newsql = string.Format(newsql, Identification, BusinessCode);
  1724. DataTable dtnew = DBHelper.SQlReturnData(newsql, cmd);
  1725. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1726. foreach (var item in res)
  1727. {
  1728. JObject jo = (JObject)item;
  1729. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, jo["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1730. //派纳倒冲排除仓库逻辑
  1731. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  1732. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1733. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1'";
  1734. whsql = string.Format(whsql);
  1735. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  1736. if (dtt.Rows.Count > 0 && dtt != null)
  1737. {
  1738. if (!jo["WHCode"].ToString().Equals(dtt.Rows[0]["F_ItemCode"].ToString()))
  1739. {
  1740. //倒冲
  1741. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1742. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1743. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1744. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1745. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1746. jo["Brand"].ToString(), cmd, language);
  1747. }
  1748. //回写已领数量
  1749. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1750. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1751. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1752. {
  1753. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1754. }
  1755. //for (int i = 0; i < dtt.Rows.Count; i++)
  1756. //{
  1757. // if (outwhcode == "")
  1758. // {
  1759. // outwhcode += "" + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1760. // }
  1761. // else
  1762. // {
  1763. // outwhcode += "," + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1764. // }
  1765. //}
  1766. }
  1767. else
  1768. {
  1769. //倒冲
  1770. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1771. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1772. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1773. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1774. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1775. jo["Brand"].ToString(), cmd, language);
  1776. //回写已领数量
  1777. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1778. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1779. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1780. {
  1781. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1782. }
  1783. }
  1784. }
  1785. }
  1786. else
  1787. {
  1788. foreach (DataRow dr in dt.Rows)
  1789. {
  1790. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1791. }
  1792. }
  1793. }
  1794. catch (Exception ex)
  1795. {
  1796. log.Debug(ex.ToString());
  1797. log.Debug(resultStr);
  1798. }
  1799. }
  1800. else
  1801. {
  1802. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1803. }
  1804. }
  1805. // string sql = @"
  1806. //select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1807. //INTO #NewTempERP
  1808. //from ICSWareHouseLotInfoLog
  1809. // WHERE Identification='{0}' AND ERPUpload='0'
  1810. // SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1811. // FROM #NewTempERP a
  1812. // INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1813. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1814. // INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1815. // GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1816. //DROP TABLE #NewTempERP";
  1817. // sql = string.Format(sql, Identification);
  1818. // DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1819. // string Inputstr = JsonConvert.SerializeObject(dt);
  1820. #endregion
  1821. }
  1822. catch (Exception)
  1823. {
  1824. throw;
  1825. }
  1826. }
  1827. #endregion
  1828. #region 审核的委外到货单
  1829. /// <summary>
  1830. /// 审核的委外到货单
  1831. /// </summary>
  1832. /// <param name="TransCode"></param>
  1833. /// <param name="TransSequence"></param>
  1834. /// <param name="Quantity"></param>
  1835. /// <param name="WorkPoint"></param>
  1836. /// <param name="cmd"></param>
  1837. public static void ODeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1838. {
  1839. try
  1840. {
  1841. string sql = @"DECLARE @Status VARCHAR(10)
  1842. SELECT @Status=c.Status FROM ICSInventoryLot a
  1843. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1844. INNER JOIN ICSOutsourcingOrder D ON B.TransCode=D.OOCode AND B.TransSequence=D.Sequence AND B.WorkPoint=D.WorkPoint
  1845. INNER JOIN ICSODeliveryNotice c ON C.OODetailID=D.OODetailID AND A.InvCode=C.InvCode AND b.WorkPoint=c.WorkPoint
  1846. INNER JOIN ICSOASNDetail E ON E.LotNo=A.LotNo AND C.OASNCode=E.OASNCode AND E.WorkPoint=A.WorkPoint
  1847. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1848. IF (@Status IS NULL)
  1849. BEGIN
  1850. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1851. RETURN
  1852. END
  1853. ELSE IF (@Status='3')
  1854. BEGIN
  1855. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1856. RETURN
  1857. END
  1858. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1859. FROM ICSInventoryLot a
  1860. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1861. INNER JOIN ICSOutsourcingOrder D ON B.TransCode=D.OOCode AND B.TransSequence=D.Sequence AND B.WorkPoint=D.WorkPoint
  1862. INNER JOIN ICSODeliveryNotice c ON C.OODetailID=D.OODetailID AND A.InvCode=C.InvCode AND b.WorkPoint=c.WorkPoint
  1863. INNER JOIN ICSOASNDetail E ON E.LotNo=A.LotNo AND C.OASNCode=E.OASNCode AND E.WorkPoint=A.WorkPoint
  1864. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1865. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1866. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1867. INNER JOIN ICSOutsourcingOrder D ON B.TransCode=D.OOCode AND B.TransSequence=D.Sequence AND B.WorkPoint=D.WorkPoint
  1868. INNER JOIN ICSODeliveryNotice c ON C.OODetailID=D.OODetailID AND A.InvCode=C.InvCode AND b.WorkPoint=c.WorkPoint
  1869. INNER JOIN ICSOASNDetail E ON E.LotNo=A.LotNo AND C.OASNCode=E.OASNCode AND E.WorkPoint=A.WorkPoint
  1870. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1871. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn005', c.Quantity,1,1,'')<c.RCVQuantity)
  1872. BEGIN
  1873. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1874. END";
  1875. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1876. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1877. {
  1878. throw new Exception(language.GetNameByCode("WMSAPIInfo117"));//"委外到货单更新失败!");
  1879. }
  1880. }
  1881. catch (Exception)
  1882. {
  1883. throw;
  1884. }
  1885. }
  1886. /// <summary>
  1887. /// 审核的委外到货单接口
  1888. /// </summary>
  1889. /// <param name="TransType"></param>
  1890. /// <param name="Identification"></param>
  1891. /// <param name="cmd"></param>
  1892. public static void ODeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1893. {
  1894. try
  1895. {
  1896. DataTable flag = null;
  1897. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  1898. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1899. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1900. {
  1901. //校验库存数量是否满足子件计划数量(倒冲)
  1902. string logsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,ToLocationCode,TransCode,TransSequence
  1903. from ICSWareHouseLotInfoLog
  1904. WHERE Identification = '{0}' AND ERPUpload = '0'";
  1905. logsql = string.Format(logsql, Identification);
  1906. DataTable logdt = DBHelper.SQlReturnData(logsql, cmd);
  1907. if (logdt.Rows.Count > 0 && logdt != null)
  1908. {
  1909. for (int i = 0; i < logdt.Rows.Count; i++)
  1910. {
  1911. ICSWareHouseLotInfoService.WareHouseLotInfoBackOutBefore(Identification, logdt.Rows[i]["ToLocationCode"].ToString(), logdt.Rows[i]["LotNo"].ToString(), logdt.Rows[i]["Quantity"].ToString(),
  1912. logdt.Rows[i]["MUSER"].ToString(), logdt.Rows[i]["WorkPoint"].ToString(), "2", BusinessCode, cmd, language, "", "", logdt.Rows[i]["TransCode"].ToString(), logdt.Rows[i]["TransSequence"].ToString());
  1913. }
  1914. }
  1915. }
  1916. #region ERP
  1917. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  1918. INTO #NewTempERP
  1919. from ICSWareHouseLotInfoLog
  1920. WHERE Identification='{0}' AND ERPUpload='0'
  1921. SELECT c.VenCode+a.ToWarehouseCode+c.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.ODNCode ,c.ODNID,d.OOID,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNDetailID,a.InvCode) AS Sequence,d.OOCode,d.OODetailID,
  1922. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(lot.Amount/lot.Quantity)) ELSE '0' END AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.ODNDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1923. ,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,
  1924. 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
  1925. INTO #TempERP
  1926. FROM #NewTempERP a
  1927. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1928. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1929. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1930. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1931. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1932. INNER JOIN ICSOutsourcingOrder D ON B.TransCode=D.OOCode AND B.TransSequence=D.Sequence AND B.WorkPoint=D.WorkPoint
  1933. INNER JOIN ICSODeliveryNotice c ON C.OODetailID=D.OODetailID AND A.InvCode=C.InvCode AND b.WorkPoint=c.WorkPoint
  1934. INNER JOIN ICSOASNDetail E ON E.LotNo=A.LotNo AND C.OASNCode=E.OASNCode AND E.WorkPoint=A.WorkPoint
  1935. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1936. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1937. GROUP BY c.ODNID,d.OOID,d.OOCode,d.OODetailID,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.ODNCode,c.ODNID,a.MUSER,a.InvCode,c.ODNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conStock.Enable
  1938. ,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, ''),
  1939. 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, '')
  1940. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNID as ODNCode, OOID AS OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1941. SELECT Costre,Sequence,InvCode,Quantity,Amount,ODNDetailID,OODetailID,WarehouseCode AS WHCode,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1942. FROM #TempERP
  1943. DROP TABLE #TempERP
  1944. DROP TABLE #NewTempERP";
  1945. sql = string.Format(sql, Identification,BusinessCode);
  1946. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1947. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1948. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ODeliveryNoticeInURL, Inputstr);
  1949. Result result = new Result();
  1950. log.Debug(resultStr);
  1951. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1952. if (result.Success)
  1953. {
  1954. try
  1955. {
  1956. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1957. {
  1958. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1959. from ICSWareHouseLotInfoLog
  1960. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1961. newsql = string.Format(newsql, Identification, BusinessCode);
  1962. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  1963. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1964. foreach (var item in res)
  1965. {
  1966. JObject jo = (JObject)item;
  1967. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1968. foreach (var detail in resdetail)
  1969. {
  1970. JObject det = (JObject)detail;
  1971. string allcol = "" + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  1972. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1973. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1974. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1975. if (det["detailss"] != null)
  1976. {
  1977. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1978. foreach (var details in resdetails)
  1979. {
  1980. JObject dets = (JObject)details;
  1981. if (dets != null)
  1982. {
  1983. //for (int i = 0; i < dt.Rows.Count; i++)
  1984. //{
  1985. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  1986. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  1987. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  1988. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  1989. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(),
  1990. dets["Brand"].ToString(), cmd, language);
  1991. //回写已领数量
  1992. sql = @"select pickid from ICSOOPick WHERE PickID='{0}' AND WorkPoint='{1}'";
  1993. sql = string.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1994. DataTable ssdt = DBHelper.SQlReturnData(sql, cmd);
  1995. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1996. sql = string.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1997. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1998. {
  1999. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  2000. }
  2001. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", "", dets["Quantity"].ToString(),
  2002. //dt.Rows[0]["MUSER"].ToString(), "", "", BusinessCode, cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  2003. //}
  2004. }
  2005. }
  2006. }
  2007. }
  2008. }
  2009. }
  2010. else
  2011. {
  2012. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2013. foreach (var item in res)
  2014. {
  2015. JObject jo = (JObject)item;
  2016. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2017. foreach (var detail in resdetail)
  2018. {
  2019. JObject det = (JObject)detail;
  2020. string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  2021. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2022. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2023. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2024. }
  2025. }
  2026. }
  2027. }
  2028. catch (Exception ex)
  2029. {
  2030. log.Debug(ex.ToString());
  2031. log.Debug(resultStr);
  2032. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  2033. }
  2034. }
  2035. else
  2036. {
  2037. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2038. }
  2039. #endregion
  2040. }
  2041. catch (Exception)
  2042. {
  2043. throw;
  2044. }
  2045. }
  2046. #endregion
  2047. #region 委外拒收
  2048. /// <summary>
  2049. /// 委外拒收
  2050. /// </summary>
  2051. /// <param name="TransCode"></param>
  2052. /// <param name="TransSequence"></param>
  2053. /// <param name="Quantity"></param>
  2054. /// <param name="WorkPoint"></param>
  2055. /// <param name="cmd"></param>
  2056. public static void OutsourcingRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2057. {
  2058. try
  2059. {
  2060. string sql = @"DECLARE @Status VARCHAR(10)
  2061. SELECT @Status=c.Status FROM ICSInventoryLot a
  2062. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2063. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2064. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2065. IF (@Status IS NULL)
  2066. BEGIN
  2067. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2068. RETURN
  2069. END
  2070. ELSE IF (@Status='3')
  2071. BEGIN
  2072. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  2073. RETURN
  2074. END
  2075. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2076. FROM ICSInventoryLot a
  2077. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2078. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2079. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2080. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2081. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2082. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2083. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2084. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn006', c.Quantity,1,1,'')<c.RCVQuantity)
  2085. BEGIN
  2086. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2087. END";
  2088. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2089. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2090. {
  2091. throw new Exception(language.GetNameByCode("WMSAPIInfo118"));//"委外拒收单更新失败!");
  2092. }
  2093. }
  2094. catch (Exception)
  2095. {
  2096. throw;
  2097. }
  2098. }
  2099. /// <summary>
  2100. /// 委外拒收接口
  2101. /// </summary>
  2102. /// <param name="TransType"></param>
  2103. /// <param name="Identification"></param>
  2104. /// <param name="cmd"></param>
  2105. public static void OutsourcingRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2106. {
  2107. // try
  2108. // {
  2109. // #region ERP
  2110. // 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,
  2111. // a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.ODNDetailID,Enable AS UpdateTodoQuantity
  2112. // ,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,
  2113. // 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
  2114. // INTO #TempERP
  2115. // FROM ICSWareHouseLotInfoLog a
  2116. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2117. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2118. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2119. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2120. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2121. // INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2122. // INNER JOIN ICSODeliveryNotice d ON c.OODetailID=d.ODNDetailID AND d.WorkPoint=c.WorkPoint
  2123. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2124. // WHERE a.Identification='{0}' AND ERPUpload='0'
  2125. // 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
  2126. // ,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, ''),
  2127. // 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, '')
  2128. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,ODNCode AS DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint FROM #TempERP
  2129. //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
  2130. // FROM #TempERP
  2131. // DROP TABLE #TempERP";
  2132. // sql = string.Format(sql, Identification);
  2133. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2134. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  2135. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  2136. // Result result = new Result();
  2137. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  2138. // if (result.Success)
  2139. // {
  2140. // try
  2141. // {
  2142. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2143. // foreach (var item in res)
  2144. // {
  2145. // JObject jo = (JObject)item;
  2146. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2147. // foreach (var detail in resdetail)
  2148. // {
  2149. // JObject det = (JObject)detail;
  2150. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["OODetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  2151. // }
  2152. // }
  2153. // }
  2154. // catch (Exception ex)
  2155. // {
  2156. // log.Debug(ex.ToString());
  2157. // log.Debug(resultStr);
  2158. // }
  2159. // }
  2160. // else
  2161. // {
  2162. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2163. // }
  2164. // #endregion
  2165. // }
  2166. // catch (Exception)
  2167. // {
  2168. // throw;
  2169. // }
  2170. }
  2171. /// <summary>
  2172. /// 委外拒收接口
  2173. /// </summary>
  2174. /// <param name="TransType"></param>
  2175. /// <param name="Identification"></param>
  2176. /// <param name="cmd"></param>
  2177. public static void OutsourcingRejectDocInNewERP(string ODNCode, string OJDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2178. {
  2179. try
  2180. {
  2181. #region ERP
  2182. string sql = @"SELECT a.VenCode+a.DepCode+x.ODNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,x.ODNCode,a.MUSER,a.MTIME,
  2183. a.Sequence,a.InvCode,Sum(a.Quantity) AS Quantity,CASE invBat.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,x.ODNDetailID
  2184. ,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,
  2185. 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
  2186. INTO #TempERP
  2187. FROM ICSODeliveryNotice a
  2188. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2189. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  2190. INNER JOIN ICSODeliveryNotice x ON x.ODNDetailID=a.OODetailID AND a.WorkPoint=x.WorkPoint
  2191. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  2192. GROUP BY invBat.AmountEnable,a.VenCode,a.DepCode,invBat.AmountEnable,x.ODNCode,a.MUSER,a.MTIME,a.Sequence,a.InvCode,a.Amount,a.Quantity,a.UnitPrice,a.Currency,x.ODNDetailID,
  2193. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  2194. 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, '')
  2195. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  2196. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,ODNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  2197. FROM #TempERP
  2198. DROP TABLE #TempERP";
  2199. sql = string.Format(sql, OJDNCode, WorkPoint);
  2200. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2201. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  2202. string resultStr = HTTPHelper.HttpPost("委外拒收", ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  2203. Result result = new Result();
  2204. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2205. if (result.Success)
  2206. {
  2207. try
  2208. {
  2209. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2210. foreach (var item in res)
  2211. {
  2212. JObject jo = (JObject)item;
  2213. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2214. foreach (var detail in resdetail)
  2215. {
  2216. JObject det = (JObject)detail;
  2217. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  2218. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  2219. where OODetailID='{4}' AND ODNType='3' AND ODNCode='{5}' ";
  2220. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], OJDNCode);
  2221. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2222. {
  2223. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  2224. }
  2225. }
  2226. }
  2227. }
  2228. catch (Exception ex)
  2229. {
  2230. log.Debug(ex.ToString());
  2231. log.Debug(resultStr);
  2232. }
  2233. }
  2234. else
  2235. {
  2236. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2237. }
  2238. #endregion
  2239. }
  2240. catch (Exception)
  2241. {
  2242. throw;
  2243. }
  2244. }
  2245. #endregion
  2246. #region 委外退货
  2247. /// <summary>
  2248. /// 委外退货
  2249. /// </summary>
  2250. /// <param name="TransCode"></param>
  2251. /// <param name="TransSequence"></param>
  2252. /// <param name="Quantity"></param>
  2253. /// <param name="WorkPoint"></param>
  2254. /// <param name="cmd"></param>
  2255. public static void OutsourcingReturnBack(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  2256. {
  2257. try
  2258. {
  2259. string sql = @"DECLARE @Status VARCHAR(10)
  2260. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='2' AND id='{4}' and WorkPoint='{1}'
  2261. IF (@Status IS NULL)
  2262. BEGIN
  2263. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  2264. RETURN
  2265. END
  2266. ELSE IF (@Status!='2')
  2267. BEGIN
  2268. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  2269. RETURN
  2270. END
  2271. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2272. FROM ICSODeliveryNotice a
  2273. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.id='{4}' AND ODNType='2'
  2274. UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}'
  2275. FROM ICSOutsourcingOrder b inner join ICSODeliveryNotice a on a.ooID = b.ooID and a.OODetailID = b.OODetailID
  2276. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND ODNType='2'
  2277. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  2278. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}' AND a.Quantity<a.RCVQuantity AND ODNType='2')
  2279. BEGIN
  2280. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  2281. RETURN
  2282. END
  2283. --退 eattribute4 = ODNDetailID 退
  2284. IF EXISTS(SELECT b.ID FROM ICSODeliveryNotice a inner join ICSODeliveryNotice b on a.eattribute4 = b.ODNDetailID
  2285. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.ODNType='2' AND a.eattribute3='退')
  2286. BEGIN
  2287. UPDATE b SET RCVQuantity=ISNULL(b.RCVQuantity,0)-'{2}'
  2288. FROM ICSODeliveryNotice b inner join ICSODeliveryNotice a on a.eattribute4 = b.ODNDetailID
  2289. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.ODNType='2' AND a.eattribute3='退'
  2290. END
  2291. ";
  2292. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  2293. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2294. {
  2295. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  2296. }
  2297. }
  2298. catch (Exception)
  2299. {
  2300. throw;
  2301. }
  2302. }
  2303. public static void OutsourcingReturnBackOO(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID)
  2304. {
  2305. try
  2306. {
  2307. string sql = @"DECLARE @Status VARCHAR(10)
  2308. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='1' AND id='{4}' and WorkPoint='{1}'
  2309. IF (@Status IS NULL)
  2310. BEGIN
  2311. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  2312. RETURN
  2313. END
  2314. ELSE IF (@Status!='2')
  2315. BEGIN
  2316. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  2317. RETURN
  2318. END
  2319. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)-'{2}'
  2320. FROM ICSODeliveryNotice a
  2321. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.id='{4}' AND ODNType='1'
  2322. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  2323. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}' AND a.RCVQuantity<0 AND ODNType='1')
  2324. BEGIN
  2325. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  2326. RETURN
  2327. END";
  2328. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  2329. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2330. {
  2331. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  2332. }
  2333. }
  2334. catch (Exception)
  2335. {
  2336. throw;
  2337. }
  2338. }
  2339. /// <summary>
  2340. /// 委外退货接口
  2341. /// </summary>
  2342. /// <param name="TransType"></param>
  2343. /// <param name="Identification"></param>
  2344. /// <param name="cmd"></param>
  2345. public static void OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2346. {
  2347. try
  2348. {
  2349. #region ERP
  2350. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2351. INTO #NewTempERP
  2352. from ICSWareHouseLotInfoLog
  2353. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2354. 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,
  2355. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount, y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  2356. ,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,
  2357. 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
  2358. INTO #TempERP
  2359. FROM #NewTempERP a
  2360. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2361. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2362. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2363. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2364. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2365. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2366. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2367. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2368. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2369. GROUP BY conWhCode.Enable,inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conv.Enable,conStock.Enable
  2370. ,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, ''),
  2371. 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, '')
  2372. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode AS ODNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,ODNCode AS SourceCode, SYSDATETIME() AS DocDate,'RCV25' as DocTypeCode FROM #TempERP
  2373. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ODNDetailID AS ODNRTDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  2374. FROM #TempERP
  2375. DROP TABLE #TempERP
  2376. DROP TABLE #NewTempERP";
  2377. sql = string.Format(sql, Identification);
  2378. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2379. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2380. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackURL, Inputstr);
  2381. Result result = new Result();
  2382. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2383. if (result.Success)
  2384. {
  2385. try
  2386. {
  2387. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2388. foreach (var item in res)
  2389. {
  2390. JObject jo = (JObject)item;
  2391. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2392. foreach (var detail in resdetail)
  2393. {
  2394. JObject det = (JObject)detail;
  2395. string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  2396. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2397. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2398. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2399. }
  2400. }
  2401. }
  2402. catch (Exception ex)
  2403. {
  2404. log.Debug(ex.ToString());
  2405. log.Debug(resultStr);
  2406. }
  2407. }
  2408. else
  2409. {
  2410. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2411. }
  2412. #endregion
  2413. }
  2414. catch (Exception)
  2415. {
  2416. throw;
  2417. }
  2418. }
  2419. public static string OutsourcingReturnBackOOERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2420. {
  2421. string msg = "";
  2422. try
  2423. {
  2424. #region ERP
  2425. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2426. INTO #NewTempERP
  2427. from ICSWareHouseLotInfoLog
  2428. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2429. 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,
  2430. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount, y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,conWhCode.Enable AS ErpWhCode
  2431. ,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,
  2432. 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
  2433. INTO #TempERP
  2434. FROM #NewTempERP a
  2435. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2436. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2437. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2438. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2439. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2440. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2441. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2442. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2443. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2444. GROUP BY conWhCode.Enable,inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conv.Enable,conStock.Enable
  2445. ,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, ''),
  2446. 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, '')
  2447. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode AS OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,ODNCode AS SourceCode, SYSDATETIME() AS DocDate,'RCV25' as DocTypeCode FROM #TempERP
  2448. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,ODNDetailID AS OODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  2449. FROM #TempERP
  2450. DROP TABLE #TempERP
  2451. DROP TABLE #NewTempERP";
  2452. sql = string.Format(sql, Identification);
  2453. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2454. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2455. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackOOURL, Inputstr);
  2456. Result result = new Result();
  2457. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2458. if (result.Success)
  2459. {
  2460. log.Debug(resultStr);
  2461. try
  2462. {
  2463. string newsql = @"select LotNo,WorkPoint,InvCode,FromWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  2464. from ICSWareHouseLotInfoLog
  2465. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  2466. newsql = string.Format(newsql, Identification, BusinessCode);
  2467. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  2468. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2469. foreach (var item in res)
  2470. {
  2471. JObject jo = (JObject)item;
  2472. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2473. foreach (var detail in resdetail)
  2474. {
  2475. JObject det = (JObject)detail;
  2476. string allcol = jo["WhCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  2477. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2478. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2479. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2480. if (det["detailss"] != null)
  2481. {
  2482. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2483. foreach (var details in resdetails)
  2484. {
  2485. JObject dets = (JObject)details;
  2486. if (dets != null)
  2487. {
  2488. //for (int i = 0; i < dt.Rows.Count; i++)
  2489. //(string Identification,
  2490. //string TransCode, string TransSequence, string InvCode, string WHCode, string Quantity, string User,
  2491. //string WorkPoint, string TransType, string BusinessCode, string ERPID, string ERPDetailID, string ERPCode, string ERPSequence,
  2492. ICSWareHouseLotInfoService.WareHouseLotInfoBackInMF(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  2493. dets["WhCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  2494. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  2495. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  2496. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["cBatch"].ToString(), dets["version"].ToString(),
  2497. dets["brand"].ToString(), dets["PickID"].ToString(), cmd, language);
  2498. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", dt.Rows[i]["LotNo"].ToString(), dets["Quantity"].ToString(),
  2499. //"", dt.Rows[i]["WorkPoint"].ToString(), "", "", cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  2500. //}
  2501. }
  2502. }
  2503. }
  2504. }
  2505. }
  2506. }
  2507. catch (Exception ex)
  2508. {
  2509. log.Debug(ex.ToString());
  2510. log.Debug(resultStr);
  2511. }
  2512. }
  2513. else
  2514. {
  2515. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2516. }
  2517. #endregion
  2518. }
  2519. catch (Exception)
  2520. {
  2521. throw;
  2522. }
  2523. return msg;
  2524. }
  2525. public static void RTOutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2526. {
  2527. try
  2528. {
  2529. #region ERP
  2530. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2531. INTO #NewTempERP
  2532. from ICSWareHouseLotInfoLog
  2533. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2534. 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,z.Sequence AS srcDocPOLineNo,y.OODetailID,z.ODNCode AS POCode,y.DepCode,
  2535. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  2536. ,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,
  2537. 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
  2538. INTO #TempERP
  2539. FROM #NewTempERP a
  2540. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2541. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2542. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2543. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2544. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2545. INNER JOIN ICSODeliveryNotice z ON z.Sequence=y.OoDetailID AND z.ODNCode=y.OOID AND a.WorkPoint=y.WorkPoint
  2546. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2547. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2548. GROUP BY y.DepCode,z.Sequence,y.OODetailID,z.ODNCode,inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conStock.Enable
  2549. ,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, ''),
  2550. 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, '')
  2551. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,'' AS DocType,MUSER AS [User],SYSDATETIME() AS MTime,SYSDATETIME() AS DocDate,SYSDATETIME() AS ArrDate FROM #TempERP
  2552. SELECT Costre,Sequence,InvCode,srcDocPOLineNo,Quantity,Amount,UnitPrice,Currency,OODetailID AS PODetailID,ProjectCode,BatchCode,WarehouseCode AS WhCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  2553. FROM #TempERP
  2554. DROP TABLE #TempERP
  2555. DROP TABLE #NewTempERP";
  2556. sql = string.Format(sql, Identification);
  2557. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2558. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2559. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.RTPurchaseReturnBackURL, Inputstr);
  2560. Result result = new Result();
  2561. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2562. if (result.Success)
  2563. {
  2564. try
  2565. {
  2566. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2567. foreach (var item in res)
  2568. {
  2569. JObject jo = (JObject)item;
  2570. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2571. foreach (var detail in resdetail)
  2572. {
  2573. JObject det = (JObject)detail;
  2574. string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  2575. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2576. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2577. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2578. }
  2579. }
  2580. }
  2581. catch (Exception ex)
  2582. {
  2583. log.Debug(ex.ToString());
  2584. log.Debug(resultStr);
  2585. }
  2586. }
  2587. else
  2588. {
  2589. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2590. }
  2591. #endregion
  2592. }
  2593. catch (Exception)
  2594. {
  2595. throw;
  2596. }
  2597. }
  2598. public static void U9OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2599. {
  2600. try
  2601. {
  2602. #region ERP
  2603. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2604. INTO #NewTempERP
  2605. from ICSWareHouseLotInfoLog
  2606. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2607. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  2608. INNER JOIN ICSODeliveryNotice b ON a.TransCode=b.ODNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2609. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  2610. BEGIN
  2611. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  2612. RETURN
  2613. END
  2614. 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,
  2615. a.InvCode,SUM(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN SUM(a.Quantity*(y.Amount/y.Quantity)) ELSE '0' END AS Amount, y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  2616. ,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,
  2617. 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
  2618. ,y.Sequence as oSequence INTO #TempERP
  2619. FROM #NewTempERP a
  2620. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2621. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2622. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2623. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2624. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2625. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2626. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2627. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2628. GROUP BY inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.ODNCode,a.MUSER,a.InvCode,y.ODNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conv.Enable,conStock.Enable
  2629. ,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, ''),
  2630. 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, ''),y.Sequence
  2631. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode AS ODNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,CompleteVerification,UpdateStock,ODNCode AS SourceCode, SYSDATETIME() AS DocDate,oSequence as Sequence,InvCode,Quantity,'RCV25' as DocTypeCode,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 FROM #TempERP
  2632. DROP TABLE #TempERP
  2633. DROP TABLE #NewTempERP";
  2634. sql = string.Format(sql, Identification);
  2635. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2636. string Inputstr = DataToJsonHelper.ToJson(ds.Tables[0]);
  2637. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingReturnBackURL, Inputstr);
  2638. Result result = new Result();
  2639. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2640. if (result.Success)
  2641. {
  2642. try
  2643. {
  2644. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2645. foreach (var item in res)
  2646. {
  2647. JObject jo = (JObject)item;
  2648. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2649. foreach (var detail in resdetail)
  2650. {
  2651. JObject det = (JObject)detail;
  2652. string allcol = jo["WHCode"].ToString() + det["ProjectCode"].ToString() + det["cBatch"].ToString() + det["version"].ToString() + det["brand"].ToString() + det["cFree1"].ToString() + det["cFree2"].ToString() + det["cFree3"].ToString() + det["cFree4"].ToString() + det["cFree5"].ToString()
  2653. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2654. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2655. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2656. }
  2657. }
  2658. }
  2659. catch (Exception ex)
  2660. {
  2661. log.Debug(ex.ToString());
  2662. log.Debug(resultStr);
  2663. }
  2664. }
  2665. else
  2666. {
  2667. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2668. }
  2669. #endregion
  2670. }
  2671. catch (Exception)
  2672. {
  2673. throw;
  2674. }
  2675. }
  2676. #endregion
  2677. #region 开立委外红字入库
  2678. /// <summary>
  2679. /// 开立委外红字入库
  2680. /// </summary>
  2681. /// <param name="TransCode"></param>
  2682. /// <param name="TransSequence"></param>
  2683. /// <param name="Quantity"></param>
  2684. /// <param name="WorkPoint"></param>
  2685. /// <param name="cmd"></param>
  2686. public static void OutsourcingReceiveDocNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  2687. {
  2688. try
  2689. {
  2690. string sql = @"DECLARE @Status VARCHAR(10)
  2691. SELECT @Status=a.Status FROM ICSOutsourcingReceive a
  2692. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2'
  2693. IF (@Status IS NULL)
  2694. BEGIN
  2695. RAISERROR('" + language.GetNameByCode("WMSAPIInfo122") + @"',16,1);
  2696. RETURN
  2697. END
  2698. ELSE IF (@Status!='1')
  2699. BEGIN
  2700. RAISERROR('" + language.GetNameByCode("WMSAPIInfo123") + @"',16,1);
  2701. RETURN
  2702. END
  2703. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2704. FROM ICSOutsourcingReceive a
  2705. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2'
  2706. IF EXISTS(SELECT a.ID FROM ICSOutsourcingReceive a
  2707. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  2708. BEGIN
  2709. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  2710. RETURN
  2711. END";
  2712. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,TransID);
  2713. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2714. {
  2715. throw new Exception(language.GetNameByCode("WMSAPIInfo124"));//"委外红字入库单更新失败!");
  2716. }
  2717. }
  2718. catch (Exception)
  2719. {
  2720. throw;
  2721. }
  2722. }
  2723. /// <summary>
  2724. /// 开立委外红字入库接口
  2725. /// </summary>
  2726. /// <param name="TransType"></param>
  2727. /// <param name="Identification"></param>
  2728. /// <param name="cmd"></param>
  2729. public static void OutsourcingReceiveDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2730. {
  2731. try
  2732. {
  2733. string sql = string.Empty;
  2734. if (DBHelper.IsPNU9())
  2735. {
  2736. #region ERP开立状态单据审核
  2737. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2738. INTO #NewTempERP
  2739. from ICSWareHouseLotInfoLog
  2740. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  2741. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2742. FROM #NewTempERP a
  2743. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2744. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2745. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  2746. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2747. DROP TABLE #NewTempERP";
  2748. sql = string.Format(sql, Identification);
  2749. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2750. //string Inputstr = JsonConvert.SerializeObject(dt);
  2751. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.RCVQuantity) AS ISSQty,a.transCode from ICSOutsourcingReceive b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2752. where a.Identification='{0}' GROUP BY a.transCode";
  2753. checksql = string.Format(checksql, Identification);
  2754. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  2755. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  2756. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  2757. string trancode = chekdt.Rows[0]["transCode"].ToString();
  2758. if (SUMQty - ISSQty == 0)
  2759. {
  2760. string pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2761. INTO #NewTempERP
  2762. from ICSWareHouseLotInfoLog
  2763. WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  2764. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2765. FROM #NewTempERP a
  2766. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2767. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2768. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  2769. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2770. DROP TABLE #NewTempERP";
  2771. pnsql = string.Format(pnsql, trancode);
  2772. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  2773. string Inputstr = JsonConvert.SerializeObject(dt);
  2774. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  2775. Result result = new Result();
  2776. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2777. if (result.Success)
  2778. {
  2779. try
  2780. {
  2781. foreach (DataRow dr in dt.Rows)
  2782. {
  2783. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2784. }
  2785. }
  2786. catch (Exception ex)
  2787. {
  2788. log.Debug(ex.ToString());
  2789. log.Debug(resultStr);
  2790. }
  2791. }
  2792. else
  2793. {
  2794. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2795. }
  2796. }
  2797. #endregion
  2798. }
  2799. else
  2800. {
  2801. #region ERP开立状态单据审核
  2802. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2803. INTO #NewTempERP
  2804. from ICSWareHouseLotInfoLog
  2805. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  2806. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  2807. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2808. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  2809. BEGIN
  2810. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  2811. RETURN
  2812. END
  2813. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2814. FROM #NewTempERP a
  2815. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2816. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2817. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  2818. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2819. DROP TABLE #NewTempERP";
  2820. sql = string.Format(sql, Identification);
  2821. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2822. string Inputstr = JsonConvert.SerializeObject(dt);
  2823. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  2824. Result result = new Result();
  2825. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2826. if (result.Success)
  2827. {
  2828. try
  2829. {
  2830. foreach (DataRow dr in dt.Rows)
  2831. {
  2832. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2833. }
  2834. }
  2835. catch (Exception ex)
  2836. {
  2837. log.Debug(ex.ToString());
  2838. log.Debug(resultStr);
  2839. }
  2840. }
  2841. else
  2842. {
  2843. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2844. }
  2845. #endregion
  2846. }
  2847. }
  2848. catch (Exception)
  2849. {
  2850. throw;
  2851. }
  2852. }
  2853. #endregion
  2854. }
  2855. }