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

1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week ago
1 week 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["details"].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='{1}'";
  938. ERPupdate = string.Format(ERPupdate, jo["ODNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["OODetailID"], ODNCode);
  939. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  940. {
  941. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  942. }
  943. }
  944. }
  945. }
  946. catch (Exception ex)
  947. {
  948. log.Debug(ex.ToString());
  949. log.Debug(resultStr);
  950. }
  951. }
  952. else
  953. {
  954. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  955. }
  956. #endregion
  957. }
  958. catch (Exception)
  959. {
  960. throw;
  961. }
  962. }
  963. #endregion
  964. #region 委外入库
  965. /// <summary>
  966. /// 委外入库
  967. /// </summary>
  968. /// <param name="TransCode"></param>
  969. /// <param name="TransSequence"></param>
  970. /// <param name="Quantity"></param>
  971. /// <param name="WorkPoint"></param>
  972. /// <param name="cmd"></param>
  973. public static void OutsourcingReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  974. {
  975. try
  976. {
  977. string sql = @"DECLARE @Status VARCHAR(10)
  978. SELECT @Status=c.Status FROM ICSInventoryLot a
  979. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  980. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  981. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  982. IF (@Status IS NULL)
  983. BEGIN
  984. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  985. RETURN
  986. END
  987. ELSE IF (@Status='3')
  988. BEGIN
  989. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  990. RETURN
  991. END
  992. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  993. FROM ICSInventoryLot a
  994. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  995. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  996. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  997. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  998. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  999. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1000. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1001. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn004', c.Quantity,1,1,'')<c.InQuantity)
  1002. BEGIN
  1003. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1004. END
  1005. --
  1006. if EXISTS(select top 10 * from ICSODeliveryNotice a
  1007. inner join ICSOutsourcingOrder b on a.OODetailID = b.OODetailID and a.OODetailID=a.ODNDetailID and a.ooid = a.ODNID)
  1008. BEGIN
  1009. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1010. FROM ICSInventoryLot a
  1011. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1012. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1013. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1014. END
  1015. ";
  1016. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1017. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1018. {
  1019. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  1020. }
  1021. }
  1022. catch (Exception)
  1023. {
  1024. throw;
  1025. }
  1026. }
  1027. /// <summary>
  1028. /// 委外入库(奥美)
  1029. /// </summary>
  1030. /// <param name="LotNo"></param>
  1031. /// <param name="Quantity"></param>
  1032. /// <param name="WorkPoint"></param>
  1033. /// <param name="cmd"></param>
  1034. /// <param name="language"></param>
  1035. public static void OutsourcingReceiveAMDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1036. {
  1037. try
  1038. {
  1039. string sql = @"DECLARE @Status VARCHAR(10)
  1040. SELECT @Status=c.Status FROM ICSInventoryLot a
  1041. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1042. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1043. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1044. IF (@Status IS NULL)
  1045. BEGIN
  1046. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1047. RETURN
  1048. END
  1049. ELSE IF (@Status='3')
  1050. BEGIN
  1051. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1052. RETURN
  1053. END
  1054. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  1055. FROM ICSInventoryLot a
  1056. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1057. INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1058. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1059. --IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1060. -- INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1061. -- INNER JOIN ICSOutsourcingOrder c ON b.TransCode=c.OOCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1062. -- WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  1063. --BEGIN
  1064. -- RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1065. --END";
  1066. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1067. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1068. {
  1069. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  1070. }
  1071. }
  1072. catch (Exception)
  1073. {
  1074. throw;
  1075. }
  1076. }
  1077. /// <summary>
  1078. /// 委外入库接口
  1079. /// </summary>
  1080. /// <param name="TransType"></param>
  1081. /// <param name="Identification"></param>
  1082. /// <param name="cmd"></param>
  1083. public static void OutsourcingReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1084. {
  1085. try
  1086. {
  1087. string outwhcode = "";
  1088. DataTable flag = null;
  1089. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  1090. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1091. #region ERP
  1092. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1093. INTO #NewTempERP
  1094. from ICSWareHouseLotInfoLog
  1095. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1096. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode,isnull(EATTRIBUTE3,'') as EATTRIBUTE3
  1097. INTO #NewDouTempERP
  1098. from ICSWareHouseLotInfoLog
  1099. WHERE Identification='{0}' AND TransType='13' and BusinessCode ='60'
  1100. 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, '')+
  1101. 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,
  1102. 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
  1103. ,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,
  1104. 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
  1105. INTO #TempERP
  1106. FROM #NewTempERP a
  1107. INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP002'
  1108. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1109. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1110. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1111. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1112. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1113. --INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1114. --INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  1115. left JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1116. 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)
  1117. INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode
  1118. AND b.TransSequence = c.Sequence
  1119. AND f.OODetailID = c.OODetailID
  1120. AND b.WorkPoint = c.WorkPoint
  1121. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1122. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1123. --INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP002'
  1124. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  1125. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose002'
  1126. INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005'
  1127. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1128. 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
  1129. ,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, ''),
  1130. 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
  1131. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,OOCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime,
  1132. Enable,UpdateTodoQuantity,CompleteVerification,UpdateStock,IsFillClose FROM #TempERP
  1133. SELECT Costre,Costre2,Sequence,ODNSequence,TransSequence,
  1134. InvCode,Quantity,Amount,OODetailID,ODNDetailID,Currency,UnitPrice,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,
  1135. ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,Reason
  1136. FROM #TempERP
  1137. 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,
  1138. a.TransCode,a.TransSequence AS Sequence,a.InvCode,SUM(a.Quantity) as Quantity,SUM((a.Quantity)*(c.Amount/c.Quantity)) AS Amount,
  1139. 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,
  1140. ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,
  1141. ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,
  1142. ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10
  1143. FROM #NewDouTempERP a
  1144. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1145. INNER JOIN ICSOutsourcingOrder b ON b.OOCode=a.TransCode AND b.WorkPoint=a.WorkPoint
  1146. INNER JOIN ICSOOPick c ON c.OODetailID=b.OODetailID AND c.WorkPoint=b.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1147. INNER JOIN ICSExtension ext ON ext.ID=lot.ExtensionID AND ext.WorkPoint=lot.WorkPoint
  1148. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1149. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1150. INNER JOIN #TempERP te ON te.TransSequence=SUBSTRING(a.TransSequence,1,CHARINDEX('~',a.TransSequence)-1)
  1151. 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
  1152. 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, ''),
  1153. 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
  1154. DROP TABLE #TempERP
  1155. DROP TABLE #NewTempERP
  1156. DROP TABLE #NewDouTempERP";
  1157. sql = string.Format(sql, Identification, BusinessCode);
  1158. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1159. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "detailss", "Costre2");
  1160. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocURL, Inputstr);
  1161. log.Debug("委外入库ERP接口返回值:" + Environment.NewLine + resultStr);
  1162. Result result = new Result();
  1163. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1164. if (result.Success)
  1165. {
  1166. try
  1167. {
  1168. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1169. {
  1170. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1171. from ICSWareHouseLotInfoLog
  1172. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1173. newsql = string.Format(newsql, Identification, BusinessCode);
  1174. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  1175. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1176. foreach (var item in res)
  1177. {
  1178. JObject jo = (JObject)item;
  1179. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1180. foreach (var detail in resdetail)
  1181. {
  1182. JObject det = (JObject)detail;
  1183. 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()
  1184. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1185. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1186. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1187. if (det["detailss"] != null)
  1188. {
  1189. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1190. foreach (var details in resdetails)
  1191. {
  1192. JObject dets = (JObject)details;
  1193. if (dets != null)
  1194. {
  1195. //for (int i = 0; i < dt.Rows.Count; i++)
  1196. //{
  1197. //派纳倒冲排除仓库逻辑
  1198. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  1199. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1200. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1'";
  1201. whsql = string.Format(whsql);
  1202. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  1203. if (dtt.Rows.Count > 0 && dtt != null)
  1204. {
  1205. if (!dtt.Rows[0]["F_ItemCode"].ToString().Equals(dets["WHCode"].ToString()))
  1206. {
  1207. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  1208. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  1209. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  1210. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  1211. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(),
  1212. dets["Brand"].ToString(), cmd, language);
  1213. }
  1214. //回写已领数量
  1215. sql = @"UPDATE ICSOOPick SET IssueQuantity=Quantity WHERE PickID='{0}' AND WorkPoint='{1}'";
  1216. sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1217. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1218. {
  1219. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1220. }
  1221. }
  1222. else
  1223. {
  1224. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  1225. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  1226. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  1227. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  1228. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(),
  1229. dets["Brand"].ToString(), cmd, language);
  1230. //回写已领数量
  1231. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1232. sql = String.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1233. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1234. {
  1235. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1236. }
  1237. }
  1238. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", dt.Rows[i]["LotNo"].ToString(), dets["Quantity"].ToString(),
  1239. //"", dt.Rows[i]["WorkPoint"].ToString(), "", "", cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  1240. //}
  1241. }
  1242. }
  1243. }
  1244. }
  1245. }
  1246. }
  1247. else
  1248. {
  1249. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1250. foreach (var item in res)
  1251. {
  1252. JObject jo = (JObject)item;
  1253. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1254. foreach (var detail in resdetail)
  1255. {
  1256. JObject det = (JObject)detail;
  1257. 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()
  1258. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1259. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1260. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1261. if (det["detailss"] != null)
  1262. {
  1263. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1264. foreach (var details in resdetails)
  1265. {
  1266. JObject dets = (JObject)details;
  1267. if (dets != null)
  1268. {
  1269. //直接回写
  1270. string ERPupdate = @"UPDATE a set ERPID='{2}',ERPDetailID='{3}',ERPCode='{4}',ERPSequence='{5}',ERPUpload='1'
  1271. FROM ICSWareHouseLotInfoLog a
  1272. LEFT JOIN ICSOutsourcingOrder b ON a.TransCode=b.OOCode AND a.WorkPoint=b.WorkPoint
  1273. LEFT JOIN ICSOOPick c ON b.OODetailID=c.OODetailID AND b.WorkPoint=c.WorkPoint AND a.TransSequence=b.Sequence+'~'+c.Sequence
  1274. WHERE c.PickID='{0}' and a.Identification='{1}' AND ERPUpload='0' AND a.BusinessCode='60'";
  1275. ERPupdate = string.Format(ERPupdate, dets["SourceDetailID"].ToString(), Identification, dets["IDs"].ToString(), dets["DetailID"].ToString(), dets["MRCVCode"].ToString()
  1276. , dets["Sequence"].ToString(), BusinessCode);
  1277. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1278. {
  1279. //throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"委外倒冲回写失败!";
  1280. }
  1281. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, dets["ERPID"].ToString(),
  1282. // dets[" "].ToString(), dets["MRCVCode"].ToString(), dets["Sequence"].ToString(), allcol, cmd, language);
  1283. }
  1284. }
  1285. }
  1286. }
  1287. }
  1288. }
  1289. }
  1290. catch (Exception ex)
  1291. {
  1292. log.Debug(ex.ToString());
  1293. log.Debug(resultStr);
  1294. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  1295. }
  1296. }
  1297. else
  1298. {
  1299. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1300. }
  1301. #endregion
  1302. }
  1303. catch (Exception)
  1304. {
  1305. throw;
  1306. }
  1307. }
  1308. public static void CreateOOArriveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode, string doctype)
  1309. {
  1310. try
  1311. {
  1312. #region ERP
  1313. string sql = @"
  1314. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1315. INTO #NewTempERP
  1316. from ICSWareHouseLotInfoLog
  1317. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1318. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,LogID,TransSequence,TransCode,FromWarehouseCode
  1319. INTO #NewDouTempERP
  1320. from ICSWareHouseLotInfoLog
  1321. WHERE Identification='{0}' AND TransType='13'
  1322. 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, '')+
  1323. 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,
  1324. 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
  1325. ,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,
  1326. 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
  1327. ,'{2}' as DocTyppe,getdate() as DocDate,c.Sequence as srcDocPOLineNo
  1328. INTO #TempERP
  1329. FROM #NewTempERP a
  1330. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1331. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1332. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1333. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1334. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1335. INNER JOIN ICSOASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1336. INNER JOIN ICSODeliveryNotice f ON g.OASNCode=f.OASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  1337. INNER JOIN ICSOutsourcingOrder c ON b.TransCode = c.OOCode
  1338. AND b.TransSequence = c.Sequence
  1339. AND f.OODetailID = c.OODetailID
  1340. AND b.WorkPoint = c.WorkPoint
  1341. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1342. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1343. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  1344. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose002'
  1345. INNER JOIN ICSConfiguration conStockneww ON a.WorkPoint=conStockneww.WorkPoint AND conStockneww.Code='CompleteVerification005'
  1346. 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
  1347. ,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, ''),
  1348. 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
  1349. 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
  1350. 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
  1351. FROM #TempERP
  1352. DROP TABLE #TempERP
  1353. DROP TABLE #NewTempERP
  1354. DROP TABLE #NewDouTempERP
  1355. ";
  1356. // select LotNo, WorkPoint, InvCode, ToWarehouseCode, MUSER, Quantity, TransSequence
  1357. //INTO #NewTempERP
  1358. //from ICSWareHouseLotInfoLog
  1359. //WHERE Identification = '{0}' AND ERPUpload = '0' AND BusinessCode = '{1}'
  1360. //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,
  1361. // 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
  1362. // --,a.lotno AS Costre2
  1363. // ,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,
  1364. // 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
  1365. // INTO #TempERP
  1366. // FROM #NewTempERP a
  1367. // INNER JOIN ICSInventoryLot lot ON a.LotNo = lot.LotNo AND a.WorkPoint = lot.WorkPoint
  1368. // INNER JOIN ICSExtension ext ON lot.ExtensionID = ext.ID AND lot.WorkPoint = ext.WorkPoint
  1369. // INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  1370. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode = invBat.InvCode AND a.ToWarehouseCode = invBat.WHCode AND a.WorkPoint = invBat.WorkPoint
  1371. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  1372. // INNER JOIN ICSASNDetail g ON a.LotNo = g.LotNo AND a.WorkPoint = g.WorkPoint
  1373. // INNER JOIN ICSDeliveryNotice f ON g.ASNCode = f.ASNCode AND g.WorkPoint = f.WorkPoint AND lot.ExtensionID = f.ExtensionID
  1374. // INNER JOIN ICSPurchaseOrder c ON b.TransCode = c.POCode AND b.TransSequence = c.Sequence AND f.PODetailID = c.PODetailID AND b.WorkPoint = c.WorkPoint
  1375. // INNER JOIN ICSConfiguration con ON con.Code = 'Stock001' AND a.WorkPoint = con.WorkPoint
  1376. // INNER JOIN ICSConfiguration conn ON a.WorkPoint = conn.WorkPoint AND conn.Code = 'Escrow001'
  1377. //INNER JOIN ICSConfiguration conStock ON a.WorkPoint = conStock.WorkPoint AND conStock.Code = 'UpdateStock001'
  1378. //INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint = conStocknew.WorkPoint AND conStocknew.Code = 'FillClose003'
  1379. // GROUP BY--a.LotNo,
  1380. // 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
  1381. // ,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, ''),
  1382. // 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
  1383. // 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
  1384. // SELECT Costre,
  1385. // --Costre2,
  1386. // 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
  1387. // FROM #TempERP
  1388. //SELECT SUM(a.Quantity) AS Quantity--,a.LotNo AS Costre2,a.LotNo,
  1389. // FROM ICSWareHouseLotInfoLog a
  1390. // INNER JOIN ICSInventoryLot lot ON a.LotNo = lot.LotNo AND a.WorkPoint = lot.WorkPoint
  1391. // INNER JOIN ICSExtension ext ON lot.ExtensionID = ext.ID AND lot.WorkPoint = ext.WorkPoint
  1392. // INNER JOIN ICSInventory inv ON a.InvCode = inv.InvCode AND a.WorkPoint = inv.WorkPoint
  1393. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode = invBat.InvCode AND a.ToWarehouseCode = invBat.WHCode AND a.WorkPoint = invBat.WorkPoint
  1394. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo = b.LotNo AND a.WorkPoint = b.WorkPoint
  1395. // INNER JOIN ICSASNDetail g ON a.LotNo = g.LotNo AND a.WorkPoint = g.WorkPoint
  1396. // INNER JOIN ICSDeliveryNotice f ON g.ASNCode = f.ASNCode AND g.WorkPoint = f.WorkPoint AND lot.ExtensionID = f.ExtensionID
  1397. // INNER JOIN ICSPurchaseOrder c ON b.TransCode = c.POCode AND b.TransSequence = c.Sequence AND f.PODetailID = c.PODetailID AND b.WorkPoint = c.WorkPoint
  1398. // INNER JOIN #TempERP te ON te.Sequence=a.TransSequence
  1399. // WHERE a.Identification = '{0}' AND ERPUpload = '0' AND BusinessCode = '{1}'
  1400. // --GROUP BY a.LotNo
  1401. // SELECT DISTINCT HasDN FROM #TempERP
  1402. // DROP TABLE #TempERP
  1403. // DROP TABLE #NewTempERP
  1404. sql = string.Format(sql, Identification, BusinessCode, doctype);
  1405. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1406. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1407. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  1408. //var IsDNCode = ds.Tables[3];
  1409. //if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  1410. //{
  1411. // throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  1412. //}
  1413. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9CreatePOArrivURL, Inputstr);
  1414. Result result = new Result();
  1415. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1416. if (result.Success)
  1417. {
  1418. try
  1419. {
  1420. //JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1421. //foreach (var item in res)
  1422. //{
  1423. // JObject jo = (JObject)item;
  1424. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1425. // foreach (var detail in resdetail)
  1426. // {
  1427. // JObject det = (JObject)detail;
  1428. // 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()
  1429. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1430. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1431. // det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1432. // }
  1433. //}
  1434. }
  1435. catch (Exception ex)
  1436. {
  1437. log.Debug(ex.ToString());
  1438. log.Debug(resultStr);
  1439. }
  1440. }
  1441. else
  1442. {
  1443. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1444. }
  1445. #endregion
  1446. }
  1447. catch (Exception)
  1448. {
  1449. throw;
  1450. }
  1451. }
  1452. #endregion
  1453. #region 委外入库
  1454. /// <summary>
  1455. /// 委外入库
  1456. /// </summary>
  1457. /// <param name="TransCode"></param>
  1458. /// <param name="TransSequence"></param>
  1459. /// <param name="Quantity"></param>
  1460. /// <param name="WorkPoint"></param>
  1461. /// <param name="cmd"></param>
  1462. public static void OutsourcingReceiveRcvDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1463. {
  1464. try
  1465. {
  1466. string sql = @"DECLARE @Status VARCHAR(10)
  1467. SELECT @Status=c.Status FROM ICSInventoryLot a
  1468. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1469. INNER JOIN ICSOutsourcingReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1470. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1471. IF (@Status IS NULL)
  1472. BEGIN
  1473. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1474. RETURN
  1475. END
  1476. ELSE IF (@Status='2')
  1477. BEGIN
  1478. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  1479. RETURN
  1480. END
  1481. UPDATE c SET RcvQuantity=ISNULL(RcvQuantity,0)+'{2}'
  1482. FROM ICSInventoryLot a
  1483. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1484. INNER JOIN ICSOutsourcingReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1485. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1486. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1487. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1488. INNER JOIN ICSOutsourcingReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1489. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  1490. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', c.Quantity,1,1,'')<c.RcvQuantity)
  1491. BEGIN
  1492. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1493. END";
  1494. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1495. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1496. {
  1497. throw new Exception(language.GetNameByCode("WMSAPIInfo115"));//"委外退料单更新失败!");
  1498. }
  1499. }
  1500. catch (Exception)
  1501. {
  1502. throw;
  1503. }
  1504. }
  1505. /// <summary>
  1506. /// 委外入库-入库单接口
  1507. /// </summary>
  1508. /// <param name="TransType"></param>
  1509. /// <param name="Identification"></param>
  1510. /// <param name="cmd"></param>
  1511. public static void OutsourcingReceiveRcvDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string UserCode)
  1512. {
  1513. try
  1514. {
  1515. #region ERP开立状态单据审核
  1516. string sql = "";
  1517. string outwhcode = "";
  1518. string pnsql = "";
  1519. string Inputstr = "";
  1520. DataTable flag = null;
  1521. DataTable dt = null;
  1522. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  1523. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1524. string sqlflag = @"select * from ICSConfiguration ConErp where ConErp.Code='UploadERP001' and conerp.enable = 1 ";
  1525. DataTable dtflag = DBHelper.SQlReturnData(sqlflag, cmd);
  1526. if (dtflag.Rows.Count > 0 && dtflag != null)
  1527. {
  1528. sql = @"
  1529. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1530. INTO #NewTempERP
  1531. from ICSWareHouseLotInfoLog
  1532. WHERE Identification='{0}' AND ERPUpload='0'
  1533. 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
  1534. INTO #TempERP
  1535. FROM #NewTempERP a
  1536. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1537. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1538. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1539. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1540. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  1541. select Costre,DNSequence,DNDetailID from #TempERP
  1542. DROP TABLE #TempERP
  1543. DROP TABLE #NewTempERP";
  1544. sql = string.Format(sql, Identification);
  1545. 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
  1546. where a.Identification='{0}' GROUP BY a.transCode,b.Quantity,b.RCVQuantity,a.transSequence";
  1547. checksql = string.Format(checksql, Identification);
  1548. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  1549. for (int i = 0; i < chekdt.Rows.Count; i++)
  1550. {
  1551. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[i]["SUMQty"]);
  1552. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[i]["ISSQty"]);
  1553. string trancode = chekdt.Rows[i]["transCode"].ToString();
  1554. string transSequence = chekdt.Rows[i]["transSequence"].ToString();
  1555. if (SUMQty - ISSQty == 0)
  1556. {
  1557. if (DBHelper.IsPNU9())
  1558. {
  1559. pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1560. INTO #NewTempERP
  1561. from ICSWareHouseLotInfoLog
  1562. WHERE TransCode='{0}' and TransSequence='{1}' AND ERPUpload='0' and EATTRIBUTE1<>'1'
  1563. 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
  1564. INTO #TempERP
  1565. FROM #NewTempERP a
  1566. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1567. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1568. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1569. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1570. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  1571. select Costre,DNSequence,DNDetailID from #TempERP
  1572. DROP TABLE #TempERP
  1573. DROP TABLE #NewTempERP";
  1574. pnsql = string.Format(pnsql, trancode, transSequence, UserCode);
  1575. }
  1576. else
  1577. {
  1578. pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1579. INTO #NewTempERP
  1580. from ICSWareHouseLotInfoLog
  1581. WHERE TransCode='{0}' and TransSequence='{1}' AND ERPUpload='0'
  1582. 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
  1583. INTO #TempERP
  1584. FROM #NewTempERP a
  1585. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1586. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1587. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1588. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1589. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  1590. select Costre,DNSequence,DNDetailID from #TempERP
  1591. DROP TABLE #TempERP
  1592. DROP TABLE #NewTempERP";
  1593. pnsql = string.Format(pnsql, trancode, transSequence);
  1594. }
  1595. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  1596. Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1597. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr);
  1598. Result result = new Result();
  1599. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1600. if (result.Success)
  1601. {
  1602. try
  1603. {
  1604. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1605. {
  1606. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1607. from ICSWareHouseLotInfoLog
  1608. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1609. newsql = string.Format(newsql, Identification, BusinessCode);
  1610. DataTable dtnew = DBHelper.SQlReturnData(newsql, cmd);
  1611. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1612. foreach (var item in res)
  1613. {
  1614. JObject jo = (JObject)item;
  1615. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, jo["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1616. //派纳倒冲排除仓库逻辑
  1617. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  1618. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1619. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1' and b.F_ItemCode='{0}'";
  1620. whsql = string.Format(whsql, jo["WHCode"].ToString());
  1621. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  1622. if (dtt.Rows.Count > 0 && dtt != null)
  1623. {
  1624. //if (!jo["WHCode"].ToString().Equals(dtt.Rows[0]["F_ItemCode"].ToString()))
  1625. //{
  1626. // //倒冲
  1627. // ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1628. // jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1629. // jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1630. // jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1631. // jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1632. // jo["Brand"].ToString(), cmd, language);
  1633. //}
  1634. //回写已领数量
  1635. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1636. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1637. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1638. {
  1639. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1640. }
  1641. //for (int i = 0; i < dtt.Rows.Count; i++)
  1642. //{
  1643. // if (outwhcode == "")
  1644. // {
  1645. // outwhcode += "" + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1646. // }
  1647. // else
  1648. // {
  1649. // outwhcode += "," + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1650. // }
  1651. //}
  1652. }
  1653. else
  1654. {
  1655. //倒冲
  1656. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1657. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1658. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1659. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1660. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1661. jo["Brand"].ToString(), cmd, language);
  1662. //回写已领数量
  1663. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1664. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1665. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1666. {
  1667. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1668. }
  1669. }
  1670. }
  1671. }
  1672. else
  1673. {
  1674. foreach (DataRow dr in dt.Rows)
  1675. {
  1676. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1677. }
  1678. }
  1679. }
  1680. catch (Exception ex)
  1681. {
  1682. log.Debug(ex.ToString());
  1683. log.Debug(resultStr);
  1684. }
  1685. }
  1686. else
  1687. {
  1688. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1689. }
  1690. }
  1691. }
  1692. }
  1693. else
  1694. {
  1695. sql = @"
  1696. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1697. INTO #NewTempERP
  1698. from ICSWareHouseLotInfoLog
  1699. WHERE Identification='{0}' AND ERPUpload='0'
  1700. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1701. FROM #NewTempERP a
  1702. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1703. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1704. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1705. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1706. DROP TABLE #NewTempERP";
  1707. sql = string.Format(sql, Identification);
  1708. dt = DBHelper.SQlReturnData(sql, cmd);
  1709. Inputstr = JsonConvert.SerializeObject(dt);
  1710. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr);
  1711. Result result = new Result();
  1712. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1713. if (result.Success)
  1714. {
  1715. try
  1716. {
  1717. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1718. {
  1719. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1720. from ICSWareHouseLotInfoLog
  1721. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1722. newsql = string.Format(newsql, Identification, BusinessCode);
  1723. DataTable dtnew = DBHelper.SQlReturnData(newsql, cmd);
  1724. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1725. foreach (var item in res)
  1726. {
  1727. JObject jo = (JObject)item;
  1728. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, jo["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1729. //派纳倒冲排除仓库逻辑
  1730. string whsql = @"SELECT b.F_ItemCode,b.F_ItemName FROM Sys_SRM_Items a
  1731. INNER JOIN Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId
  1732. where a.F_EnCode='OutWHCode' AND b.F_EnabledMark='1'";
  1733. whsql = string.Format(whsql);
  1734. DataTable dtt = DBHelper.SQlReturnData(whsql, cmd);
  1735. if (dtt.Rows.Count > 0 && dtt != null)
  1736. {
  1737. if (!jo["WHCode"].ToString().Equals(dtt.Rows[0]["F_ItemCode"].ToString()))
  1738. {
  1739. //倒冲
  1740. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1741. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1742. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1743. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1744. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1745. jo["Brand"].ToString(), cmd, language);
  1746. }
  1747. //回写已领数量
  1748. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1749. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1750. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1751. {
  1752. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1753. }
  1754. //for (int i = 0; i < dtt.Rows.Count; i++)
  1755. //{
  1756. // if (outwhcode == "")
  1757. // {
  1758. // outwhcode += "" + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1759. // }
  1760. // else
  1761. // {
  1762. // outwhcode += "," + dtt.Rows[i]["F_ItemCode"].ToString() + "";
  1763. // }
  1764. //}
  1765. }
  1766. else
  1767. {
  1768. //倒冲
  1769. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, jo["SourceCode"].ToString(), jo["SourceSequence"].ToString(), jo["InvCode"].ToString(),
  1770. jo["WHCode"].ToString(), jo["Quantity"].ToString(), dtnew.Rows[0]["MUSER"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, jo["ID"].ToString(),
  1771. jo["DetailID"].ToString(), jo["TransCode"].ToString(), jo["TransSequence"].ToString(), jo["cFree1"].ToString(), jo["cFree2"].ToString(),
  1772. jo["cFree3"].ToString(), jo["cFree4"].ToString(), jo["cFree5"].ToString(), jo["cFree6"].ToString(), jo["cFree7"].ToString(),
  1773. jo["cFree8"].ToString(), jo["cFree9"].ToString(), jo["cFree10"].ToString(), jo["ProjectCode"].ToString(), jo["BatchCode"].ToString(), jo["Version"].ToString(),
  1774. jo["Brand"].ToString(), cmd, language);
  1775. //回写已领数量
  1776. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + jo["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1777. sql = String.Format(sql, jo["PickID"].ToString(), dtnew.Rows[0]["WorkPoint"].ToString());
  1778. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1779. {
  1780. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1781. }
  1782. }
  1783. }
  1784. }
  1785. else
  1786. {
  1787. foreach (DataRow dr in dt.Rows)
  1788. {
  1789. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1790. }
  1791. }
  1792. }
  1793. catch (Exception ex)
  1794. {
  1795. log.Debug(ex.ToString());
  1796. log.Debug(resultStr);
  1797. }
  1798. }
  1799. else
  1800. {
  1801. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1802. }
  1803. }
  1804. // string sql = @"
  1805. //select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  1806. //INTO #NewTempERP
  1807. //from ICSWareHouseLotInfoLog
  1808. // WHERE Identification='{0}' AND ERPUpload='0'
  1809. // SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1810. // FROM #NewTempERP a
  1811. // INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1812. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1813. // INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  1814. // GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1815. //DROP TABLE #NewTempERP";
  1816. // sql = string.Format(sql, Identification);
  1817. // DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1818. // string Inputstr = JsonConvert.SerializeObject(dt);
  1819. #endregion
  1820. }
  1821. catch (Exception)
  1822. {
  1823. throw;
  1824. }
  1825. }
  1826. #endregion
  1827. #region 审核的委外到货单
  1828. /// <summary>
  1829. /// 审核的委外到货单
  1830. /// </summary>
  1831. /// <param name="TransCode"></param>
  1832. /// <param name="TransSequence"></param>
  1833. /// <param name="Quantity"></param>
  1834. /// <param name="WorkPoint"></param>
  1835. /// <param name="cmd"></param>
  1836. public static void ODeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1837. {
  1838. try
  1839. {
  1840. string sql = @"DECLARE @Status VARCHAR(10)
  1841. SELECT @Status=c.Status FROM ICSInventoryLot a
  1842. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1843. INNER JOIN ICSOutsourcingOrder D ON B.TransCode=D.OOCode AND B.TransSequence=D.Sequence AND B.WorkPoint=D.WorkPoint
  1844. INNER JOIN ICSODeliveryNotice c ON C.OODetailID=D.OODetailID AND A.InvCode=C.InvCode AND b.WorkPoint=c.WorkPoint
  1845. INNER JOIN ICSOASNDetail E ON E.LotNo=A.LotNo AND C.OASNCode=E.OASNCode AND E.WorkPoint=A.WorkPoint
  1846. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1847. IF (@Status IS NULL)
  1848. BEGIN
  1849. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1850. RETURN
  1851. END
  1852. ELSE IF (@Status='3')
  1853. BEGIN
  1854. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1855. RETURN
  1856. END
  1857. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1858. FROM ICSInventoryLot a
  1859. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1860. INNER JOIN ICSOutsourcingOrder D ON B.TransCode=D.OOCode AND B.TransSequence=D.Sequence AND B.WorkPoint=D.WorkPoint
  1861. INNER JOIN ICSODeliveryNotice c ON C.OODetailID=D.OODetailID AND A.InvCode=C.InvCode AND b.WorkPoint=c.WorkPoint
  1862. INNER JOIN ICSOASNDetail E ON E.LotNo=A.LotNo AND C.OASNCode=E.OASNCode AND E.WorkPoint=A.WorkPoint
  1863. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1864. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1865. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1866. INNER JOIN ICSOutsourcingOrder D ON B.TransCode=D.OOCode AND B.TransSequence=D.Sequence AND B.WorkPoint=D.WorkPoint
  1867. INNER JOIN ICSODeliveryNotice c ON C.OODetailID=D.OODetailID AND A.InvCode=C.InvCode AND b.WorkPoint=c.WorkPoint
  1868. INNER JOIN ICSOASNDetail E ON E.LotNo=A.LotNo AND C.OASNCode=E.OASNCode AND E.WorkPoint=A.WorkPoint
  1869. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1870. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn005', c.Quantity,1,1,'')<c.RCVQuantity)
  1871. BEGIN
  1872. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1873. END";
  1874. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1875. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1876. {
  1877. throw new Exception(language.GetNameByCode("WMSAPIInfo117"));//"委外到货单更新失败!");
  1878. }
  1879. }
  1880. catch (Exception)
  1881. {
  1882. throw;
  1883. }
  1884. }
  1885. /// <summary>
  1886. /// 审核的委外到货单接口
  1887. /// </summary>
  1888. /// <param name="TransType"></param>
  1889. /// <param name="Identification"></param>
  1890. /// <param name="cmd"></param>
  1891. public static void ODeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1892. {
  1893. try
  1894. {
  1895. DataTable flag = null;
  1896. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  1897. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1898. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1899. {
  1900. //校验库存数量是否满足子件计划数量(倒冲)
  1901. string logsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,ToLocationCode,TransCode,TransSequence
  1902. from ICSWareHouseLotInfoLog
  1903. WHERE Identification = '{0}' AND ERPUpload = '0'";
  1904. logsql = string.Format(logsql, Identification);
  1905. DataTable logdt = DBHelper.SQlReturnData(logsql, cmd);
  1906. if (logdt.Rows.Count > 0 && logdt != null)
  1907. {
  1908. for (int i = 0; i < logdt.Rows.Count; i++)
  1909. {
  1910. ICSWareHouseLotInfoService.WareHouseLotInfoBackOutBefore(Identification, logdt.Rows[i]["ToLocationCode"].ToString(), logdt.Rows[i]["LotNo"].ToString(), logdt.Rows[i]["Quantity"].ToString(),
  1911. logdt.Rows[i]["MUSER"].ToString(), logdt.Rows[i]["WorkPoint"].ToString(), "2", BusinessCode, cmd, language, "", "", logdt.Rows[i]["TransCode"].ToString(), logdt.Rows[i]["TransSequence"].ToString());
  1912. }
  1913. }
  1914. }
  1915. #region ERP
  1916. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  1917. INTO #NewTempERP
  1918. from ICSWareHouseLotInfoLog
  1919. WHERE Identification='{0}' AND ERPUpload='0'
  1920. 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,
  1921. 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
  1922. ,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,
  1923. 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
  1924. INTO #TempERP
  1925. FROM #NewTempERP a
  1926. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1927. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1928. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1929. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1930. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1931. INNER JOIN ICSOutsourcingOrder D ON B.TransCode=D.OOCode AND B.TransSequence=D.Sequence AND B.WorkPoint=D.WorkPoint
  1932. INNER JOIN ICSODeliveryNotice c ON C.OODetailID=D.OODetailID AND A.InvCode=C.InvCode AND b.WorkPoint=c.WorkPoint
  1933. INNER JOIN ICSOASNDetail E ON E.LotNo=A.LotNo AND C.OASNCode=E.OASNCode AND E.WorkPoint=A.WorkPoint
  1934. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1935. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1936. 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
  1937. ,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, ''),
  1938. 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, '')
  1939. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNID as ODNCode, OOID AS OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1940. 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
  1941. FROM #TempERP
  1942. DROP TABLE #TempERP
  1943. DROP TABLE #NewTempERP";
  1944. sql = string.Format(sql, Identification,BusinessCode);
  1945. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1946. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1947. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ODeliveryNoticeInURL, Inputstr);
  1948. Result result = new Result();
  1949. log.Debug(resultStr);
  1950. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1951. if (result.Success)
  1952. {
  1953. try
  1954. {
  1955. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1956. {
  1957. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1958. from ICSWareHouseLotInfoLog
  1959. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1960. newsql = string.Format(newsql, Identification, BusinessCode);
  1961. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  1962. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1963. foreach (var item in res)
  1964. {
  1965. JObject jo = (JObject)item;
  1966. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1967. foreach (var detail in resdetail)
  1968. {
  1969. JObject det = (JObject)detail;
  1970. 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()
  1971. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1972. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1973. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1974. if (det["detailss"] != null)
  1975. {
  1976. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1977. foreach (var details in resdetails)
  1978. {
  1979. JObject dets = (JObject)details;
  1980. if (dets != null)
  1981. {
  1982. //for (int i = 0; i < dt.Rows.Count; i++)
  1983. //{
  1984. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  1985. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  1986. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  1987. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  1988. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(),
  1989. dets["Brand"].ToString(), cmd, language);
  1990. //回写已领数量
  1991. sql = @"select pickid from ICSOOPick WHERE PickID='{0}' AND WorkPoint='{1}'";
  1992. sql = string.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1993. DataTable ssdt = DBHelper.SQlReturnData(sql, cmd);
  1994. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1995. sql = string.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1996. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1997. {
  1998. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1999. }
  2000. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", "", dets["Quantity"].ToString(),
  2001. //dt.Rows[0]["MUSER"].ToString(), "", "", BusinessCode, cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  2002. //}
  2003. }
  2004. }
  2005. }
  2006. }
  2007. }
  2008. }
  2009. else
  2010. {
  2011. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2012. foreach (var item in res)
  2013. {
  2014. JObject jo = (JObject)item;
  2015. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2016. foreach (var detail in resdetail)
  2017. {
  2018. JObject det = (JObject)detail;
  2019. 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()
  2020. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2021. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2022. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2023. }
  2024. }
  2025. }
  2026. }
  2027. catch (Exception ex)
  2028. {
  2029. log.Debug(ex.ToString());
  2030. log.Debug(resultStr);
  2031. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  2032. }
  2033. }
  2034. else
  2035. {
  2036. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2037. }
  2038. #endregion
  2039. }
  2040. catch (Exception)
  2041. {
  2042. throw;
  2043. }
  2044. }
  2045. #endregion
  2046. #region 委外拒收
  2047. /// <summary>
  2048. /// 委外拒收
  2049. /// </summary>
  2050. /// <param name="TransCode"></param>
  2051. /// <param name="TransSequence"></param>
  2052. /// <param name="Quantity"></param>
  2053. /// <param name="WorkPoint"></param>
  2054. /// <param name="cmd"></param>
  2055. public static void OutsourcingRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2056. {
  2057. try
  2058. {
  2059. string sql = @"DECLARE @Status VARCHAR(10)
  2060. SELECT @Status=c.Status FROM ICSInventoryLot a
  2061. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2062. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2063. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2064. IF (@Status IS NULL)
  2065. BEGIN
  2066. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2067. RETURN
  2068. END
  2069. ELSE IF (@Status='3')
  2070. BEGIN
  2071. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  2072. RETURN
  2073. END
  2074. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2075. FROM ICSInventoryLot a
  2076. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2077. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2078. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2079. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2080. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2081. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2082. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2083. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn006', c.Quantity,1,1,'')<c.RCVQuantity)
  2084. BEGIN
  2085. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2086. END";
  2087. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2088. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2089. {
  2090. throw new Exception(language.GetNameByCode("WMSAPIInfo118"));//"委外拒收单更新失败!");
  2091. }
  2092. }
  2093. catch (Exception)
  2094. {
  2095. throw;
  2096. }
  2097. }
  2098. /// <summary>
  2099. /// 委外拒收接口
  2100. /// </summary>
  2101. /// <param name="TransType"></param>
  2102. /// <param name="Identification"></param>
  2103. /// <param name="cmd"></param>
  2104. public static void OutsourcingRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2105. {
  2106. // try
  2107. // {
  2108. // #region ERP
  2109. // 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,
  2110. // a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.ODNDetailID,Enable AS UpdateTodoQuantity
  2111. // ,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,
  2112. // 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
  2113. // INTO #TempERP
  2114. // FROM ICSWareHouseLotInfoLog a
  2115. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2116. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2117. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2118. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2119. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2120. // INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2121. // INNER JOIN ICSODeliveryNotice d ON c.OODetailID=d.ODNDetailID AND d.WorkPoint=c.WorkPoint
  2122. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2123. // WHERE a.Identification='{0}' AND ERPUpload='0'
  2124. // 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
  2125. // ,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, ''),
  2126. // 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, '')
  2127. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,ODNCode AS DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint FROM #TempERP
  2128. //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
  2129. // FROM #TempERP
  2130. // DROP TABLE #TempERP";
  2131. // sql = string.Format(sql, Identification);
  2132. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2133. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  2134. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  2135. // Result result = new Result();
  2136. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  2137. // if (result.Success)
  2138. // {
  2139. // try
  2140. // {
  2141. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2142. // foreach (var item in res)
  2143. // {
  2144. // JObject jo = (JObject)item;
  2145. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2146. // foreach (var detail in resdetail)
  2147. // {
  2148. // JObject det = (JObject)detail;
  2149. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["OODetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  2150. // }
  2151. // }
  2152. // }
  2153. // catch (Exception ex)
  2154. // {
  2155. // log.Debug(ex.ToString());
  2156. // log.Debug(resultStr);
  2157. // }
  2158. // }
  2159. // else
  2160. // {
  2161. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2162. // }
  2163. // #endregion
  2164. // }
  2165. // catch (Exception)
  2166. // {
  2167. // throw;
  2168. // }
  2169. }
  2170. /// <summary>
  2171. /// 委外拒收接口
  2172. /// </summary>
  2173. /// <param name="TransType"></param>
  2174. /// <param name="Identification"></param>
  2175. /// <param name="cmd"></param>
  2176. public static void OutsourcingRejectDocInNewERP(string ODNCode, string OJDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2177. {
  2178. try
  2179. {
  2180. #region ERP
  2181. string sql = @"SELECT a.VenCode+a.DepCode+x.ODNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,x.ODNCode,a.MUSER,a.MTIME,
  2182. 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
  2183. ,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,
  2184. 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
  2185. INTO #TempERP
  2186. FROM ICSODeliveryNotice a
  2187. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2188. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  2189. INNER JOIN ICSODeliveryNotice x ON x.ODNDetailID=a.OODetailID AND a.WorkPoint=x.WorkPoint
  2190. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  2191. 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,
  2192. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  2193. 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, '')
  2194. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  2195. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,ODNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  2196. FROM #TempERP
  2197. DROP TABLE #TempERP";
  2198. sql = string.Format(sql, OJDNCode, WorkPoint);
  2199. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2200. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  2201. string resultStr = HTTPHelper.HttpPost("委外拒收", ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  2202. Result result = new Result();
  2203. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2204. if (result.Success)
  2205. {
  2206. try
  2207. {
  2208. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2209. foreach (var item in res)
  2210. {
  2211. JObject jo = (JObject)item;
  2212. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2213. foreach (var detail in resdetail)
  2214. {
  2215. JObject det = (JObject)detail;
  2216. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  2217. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  2218. where OODetailID='{4}' AND ODNType='3' AND ODNCode='{5}' ";
  2219. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], OJDNCode);
  2220. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2221. {
  2222. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  2223. }
  2224. }
  2225. }
  2226. }
  2227. catch (Exception ex)
  2228. {
  2229. log.Debug(ex.ToString());
  2230. log.Debug(resultStr);
  2231. }
  2232. }
  2233. else
  2234. {
  2235. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2236. }
  2237. #endregion
  2238. }
  2239. catch (Exception)
  2240. {
  2241. throw;
  2242. }
  2243. }
  2244. #endregion
  2245. #region 委外退货
  2246. /// <summary>
  2247. /// 委外退货
  2248. /// </summary>
  2249. /// <param name="TransCode"></param>
  2250. /// <param name="TransSequence"></param>
  2251. /// <param name="Quantity"></param>
  2252. /// <param name="WorkPoint"></param>
  2253. /// <param name="cmd"></param>
  2254. public static void OutsourcingReturnBack(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  2255. {
  2256. try
  2257. {
  2258. string sql = @"DECLARE @Status VARCHAR(10)
  2259. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='2' AND id='{4}' and WorkPoint='{1}'
  2260. IF (@Status IS NULL)
  2261. BEGIN
  2262. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  2263. RETURN
  2264. END
  2265. ELSE IF (@Status!='2')
  2266. BEGIN
  2267. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  2268. RETURN
  2269. END
  2270. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2271. FROM ICSODeliveryNotice a
  2272. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.id='{4}' AND ODNType='2'
  2273. UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}'
  2274. FROM ICSOutsourcingOrder b inner join ICSODeliveryNotice a on a.ooID = b.ooID and a.OODetailID = b.OODetailID
  2275. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND ODNType='2'
  2276. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  2277. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}' AND a.Quantity<a.RCVQuantity AND ODNType='2')
  2278. BEGIN
  2279. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  2280. RETURN
  2281. END
  2282. --退 eattribute4 = ODNDetailID 退
  2283. IF EXISTS(SELECT b.ID FROM ICSODeliveryNotice a inner join ICSODeliveryNotice b on a.eattribute4 = b.ODNDetailID
  2284. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.ODNType='2' AND a.eattribute3='退')
  2285. BEGIN
  2286. UPDATE b SET RCVQuantity=ISNULL(b.RCVQuantity,0)-'{2}'
  2287. FROM ICSODeliveryNotice b inner join ICSODeliveryNotice a on a.eattribute4 = b.ODNDetailID
  2288. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.ODNType='2' AND a.eattribute3='退'
  2289. END
  2290. ";
  2291. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  2292. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2293. {
  2294. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  2295. }
  2296. }
  2297. catch (Exception)
  2298. {
  2299. throw;
  2300. }
  2301. }
  2302. public static void OutsourcingReturnBackOO(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID)
  2303. {
  2304. try
  2305. {
  2306. string sql = @"DECLARE @Status VARCHAR(10)
  2307. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='1' AND id='{4}' and WorkPoint='{1}'
  2308. IF (@Status IS NULL)
  2309. BEGIN
  2310. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  2311. RETURN
  2312. END
  2313. ELSE IF (@Status!='2')
  2314. BEGIN
  2315. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  2316. RETURN
  2317. END
  2318. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)-'{2}'
  2319. FROM ICSODeliveryNotice a
  2320. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.id='{4}' AND ODNType='1'
  2321. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  2322. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}' AND a.RCVQuantity<0 AND ODNType='1')
  2323. BEGIN
  2324. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  2325. RETURN
  2326. END";
  2327. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  2328. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2329. {
  2330. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  2331. }
  2332. }
  2333. catch (Exception)
  2334. {
  2335. throw;
  2336. }
  2337. }
  2338. /// <summary>
  2339. /// 委外退货接口
  2340. /// </summary>
  2341. /// <param name="TransType"></param>
  2342. /// <param name="Identification"></param>
  2343. /// <param name="cmd"></param>
  2344. public static void OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2345. {
  2346. try
  2347. {
  2348. #region ERP
  2349. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2350. INTO #NewTempERP
  2351. from ICSWareHouseLotInfoLog
  2352. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2353. 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,
  2354. 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
  2355. ,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,
  2356. 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
  2357. INTO #TempERP
  2358. FROM #NewTempERP a
  2359. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2360. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2361. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2362. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2363. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2364. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2365. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2366. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2367. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2368. 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
  2369. ,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, ''),
  2370. 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, '')
  2371. 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
  2372. 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
  2373. FROM #TempERP
  2374. DROP TABLE #TempERP
  2375. DROP TABLE #NewTempERP";
  2376. sql = string.Format(sql, Identification);
  2377. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2378. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2379. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackURL, Inputstr);
  2380. Result result = new Result();
  2381. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2382. if (result.Success)
  2383. {
  2384. try
  2385. {
  2386. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2387. foreach (var item in res)
  2388. {
  2389. JObject jo = (JObject)item;
  2390. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2391. foreach (var detail in resdetail)
  2392. {
  2393. JObject det = (JObject)detail;
  2394. 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()
  2395. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2396. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2397. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2398. }
  2399. }
  2400. }
  2401. catch (Exception ex)
  2402. {
  2403. log.Debug(ex.ToString());
  2404. log.Debug(resultStr);
  2405. }
  2406. }
  2407. else
  2408. {
  2409. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2410. }
  2411. #endregion
  2412. }
  2413. catch (Exception)
  2414. {
  2415. throw;
  2416. }
  2417. }
  2418. public static string OutsourcingReturnBackOOERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2419. {
  2420. string msg = "";
  2421. try
  2422. {
  2423. #region ERP
  2424. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2425. INTO #NewTempERP
  2426. from ICSWareHouseLotInfoLog
  2427. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2428. 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,
  2429. 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
  2430. ,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,
  2431. 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
  2432. INTO #TempERP
  2433. FROM #NewTempERP a
  2434. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2435. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2436. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2437. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2438. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2439. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2440. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2441. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2442. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2443. 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
  2444. ,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, ''),
  2445. 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, '')
  2446. 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
  2447. 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
  2448. FROM #TempERP
  2449. DROP TABLE #TempERP
  2450. DROP TABLE #NewTempERP";
  2451. sql = string.Format(sql, Identification);
  2452. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2453. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2454. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackOOURL, Inputstr);
  2455. Result result = new Result();
  2456. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2457. if (result.Success)
  2458. {
  2459. log.Debug(resultStr);
  2460. try
  2461. {
  2462. string newsql = @"select LotNo,WorkPoint,InvCode,FromWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  2463. from ICSWareHouseLotInfoLog
  2464. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  2465. newsql = string.Format(newsql, Identification, BusinessCode);
  2466. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  2467. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2468. foreach (var item in res)
  2469. {
  2470. JObject jo = (JObject)item;
  2471. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2472. foreach (var detail in resdetail)
  2473. {
  2474. JObject det = (JObject)detail;
  2475. 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()
  2476. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2477. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2478. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2479. if (det["detailss"] != null)
  2480. {
  2481. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2482. foreach (var details in resdetails)
  2483. {
  2484. JObject dets = (JObject)details;
  2485. if (dets != null)
  2486. {
  2487. //for (int i = 0; i < dt.Rows.Count; i++)
  2488. //(string Identification,
  2489. //string TransCode, string TransSequence, string InvCode, string WHCode, string Quantity, string User,
  2490. //string WorkPoint, string TransType, string BusinessCode, string ERPID, string ERPDetailID, string ERPCode, string ERPSequence,
  2491. ICSWareHouseLotInfoService.WareHouseLotInfoBackInMF(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  2492. dets["WhCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  2493. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  2494. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  2495. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["cBatch"].ToString(), dets["version"].ToString(),
  2496. dets["brand"].ToString(), dets["PickID"].ToString(), cmd, language);
  2497. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", dt.Rows[i]["LotNo"].ToString(), dets["Quantity"].ToString(),
  2498. //"", dt.Rows[i]["WorkPoint"].ToString(), "", "", cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  2499. //}
  2500. }
  2501. }
  2502. }
  2503. }
  2504. }
  2505. }
  2506. catch (Exception ex)
  2507. {
  2508. log.Debug(ex.ToString());
  2509. log.Debug(resultStr);
  2510. }
  2511. }
  2512. else
  2513. {
  2514. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2515. }
  2516. #endregion
  2517. }
  2518. catch (Exception)
  2519. {
  2520. throw;
  2521. }
  2522. return msg;
  2523. }
  2524. public static void RTOutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2525. {
  2526. try
  2527. {
  2528. #region ERP
  2529. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2530. INTO #NewTempERP
  2531. from ICSWareHouseLotInfoLog
  2532. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2533. 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,
  2534. 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
  2535. ,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,
  2536. 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
  2537. INTO #TempERP
  2538. FROM #NewTempERP a
  2539. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2540. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2541. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2542. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2543. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2544. INNER JOIN ICSODeliveryNotice z ON z.Sequence=y.OoDetailID AND z.ODNCode=y.OOID AND a.WorkPoint=y.WorkPoint
  2545. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2546. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2547. 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
  2548. ,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, ''),
  2549. 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, '')
  2550. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,'' AS DocType,MUSER AS [User],SYSDATETIME() AS MTime,SYSDATETIME() AS DocDate,SYSDATETIME() AS ArrDate FROM #TempERP
  2551. 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
  2552. FROM #TempERP
  2553. DROP TABLE #TempERP
  2554. DROP TABLE #NewTempERP";
  2555. sql = string.Format(sql, Identification);
  2556. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2557. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2558. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.RTPurchaseReturnBackURL, Inputstr);
  2559. Result result = new Result();
  2560. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2561. if (result.Success)
  2562. {
  2563. try
  2564. {
  2565. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2566. foreach (var item in res)
  2567. {
  2568. JObject jo = (JObject)item;
  2569. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2570. foreach (var detail in resdetail)
  2571. {
  2572. JObject det = (JObject)detail;
  2573. 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()
  2574. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2575. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2576. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2577. }
  2578. }
  2579. }
  2580. catch (Exception ex)
  2581. {
  2582. log.Debug(ex.ToString());
  2583. log.Debug(resultStr);
  2584. }
  2585. }
  2586. else
  2587. {
  2588. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2589. }
  2590. #endregion
  2591. }
  2592. catch (Exception)
  2593. {
  2594. throw;
  2595. }
  2596. }
  2597. public static void U9OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2598. {
  2599. try
  2600. {
  2601. #region ERP
  2602. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2603. INTO #NewTempERP
  2604. from ICSWareHouseLotInfoLog
  2605. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2606. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  2607. INNER JOIN ICSODeliveryNotice b ON a.TransCode=b.ODNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2608. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  2609. BEGIN
  2610. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  2611. RETURN
  2612. END
  2613. 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,
  2614. 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
  2615. ,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,
  2616. 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
  2617. ,y.Sequence as oSequence INTO #TempERP
  2618. FROM #NewTempERP a
  2619. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2620. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2621. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2622. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2623. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2624. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2625. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2626. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2627. 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
  2628. ,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, ''),
  2629. 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
  2630. 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
  2631. DROP TABLE #TempERP
  2632. DROP TABLE #NewTempERP";
  2633. sql = string.Format(sql, Identification);
  2634. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2635. string Inputstr = DataToJsonHelper.ToJson(ds.Tables[0]);
  2636. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingReturnBackURL, Inputstr);
  2637. Result result = new Result();
  2638. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2639. if (result.Success)
  2640. {
  2641. try
  2642. {
  2643. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2644. foreach (var item in res)
  2645. {
  2646. JObject jo = (JObject)item;
  2647. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2648. foreach (var detail in resdetail)
  2649. {
  2650. JObject det = (JObject)detail;
  2651. 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()
  2652. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2653. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2654. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2655. }
  2656. }
  2657. }
  2658. catch (Exception ex)
  2659. {
  2660. log.Debug(ex.ToString());
  2661. log.Debug(resultStr);
  2662. }
  2663. }
  2664. else
  2665. {
  2666. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2667. }
  2668. #endregion
  2669. }
  2670. catch (Exception)
  2671. {
  2672. throw;
  2673. }
  2674. }
  2675. #endregion
  2676. #region 开立委外红字入库
  2677. /// <summary>
  2678. /// 开立委外红字入库
  2679. /// </summary>
  2680. /// <param name="TransCode"></param>
  2681. /// <param name="TransSequence"></param>
  2682. /// <param name="Quantity"></param>
  2683. /// <param name="WorkPoint"></param>
  2684. /// <param name="cmd"></param>
  2685. public static void OutsourcingReceiveDocNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  2686. {
  2687. try
  2688. {
  2689. string sql = @"DECLARE @Status VARCHAR(10)
  2690. SELECT @Status=a.Status FROM ICSOutsourcingReceive a
  2691. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2'
  2692. IF (@Status IS NULL)
  2693. BEGIN
  2694. RAISERROR('" + language.GetNameByCode("WMSAPIInfo122") + @"',16,1);
  2695. RETURN
  2696. END
  2697. ELSE IF (@Status!='1')
  2698. BEGIN
  2699. RAISERROR('" + language.GetNameByCode("WMSAPIInfo123") + @"',16,1);
  2700. RETURN
  2701. END
  2702. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2703. FROM ICSOutsourcingReceive a
  2704. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2'
  2705. IF EXISTS(SELECT a.ID FROM ICSOutsourcingReceive a
  2706. 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)
  2707. BEGIN
  2708. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  2709. RETURN
  2710. END";
  2711. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,TransID);
  2712. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2713. {
  2714. throw new Exception(language.GetNameByCode("WMSAPIInfo124"));//"委外红字入库单更新失败!");
  2715. }
  2716. }
  2717. catch (Exception)
  2718. {
  2719. throw;
  2720. }
  2721. }
  2722. /// <summary>
  2723. /// 开立委外红字入库接口
  2724. /// </summary>
  2725. /// <param name="TransType"></param>
  2726. /// <param name="Identification"></param>
  2727. /// <param name="cmd"></param>
  2728. public static void OutsourcingReceiveDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2729. {
  2730. try
  2731. {
  2732. string sql = string.Empty;
  2733. if (DBHelper.IsPNU9())
  2734. {
  2735. #region ERP开立状态单据审核
  2736. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2737. INTO #NewTempERP
  2738. from ICSWareHouseLotInfoLog
  2739. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  2740. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2741. FROM #NewTempERP a
  2742. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2743. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2744. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  2745. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2746. DROP TABLE #NewTempERP";
  2747. sql = string.Format(sql, Identification);
  2748. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2749. //string Inputstr = JsonConvert.SerializeObject(dt);
  2750. 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
  2751. where a.Identification='{0}' GROUP BY a.transCode";
  2752. checksql = string.Format(checksql, Identification);
  2753. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  2754. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  2755. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  2756. string trancode = chekdt.Rows[0]["transCode"].ToString();
  2757. if (SUMQty - ISSQty == 0)
  2758. {
  2759. string pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2760. INTO #NewTempERP
  2761. from ICSWareHouseLotInfoLog
  2762. WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  2763. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2764. FROM #NewTempERP a
  2765. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2766. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2767. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  2768. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2769. DROP TABLE #NewTempERP";
  2770. pnsql = string.Format(pnsql, trancode);
  2771. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  2772. string Inputstr = JsonConvert.SerializeObject(dt);
  2773. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  2774. Result result = new Result();
  2775. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2776. if (result.Success)
  2777. {
  2778. try
  2779. {
  2780. foreach (DataRow dr in dt.Rows)
  2781. {
  2782. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2783. }
  2784. }
  2785. catch (Exception ex)
  2786. {
  2787. log.Debug(ex.ToString());
  2788. log.Debug(resultStr);
  2789. }
  2790. }
  2791. else
  2792. {
  2793. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2794. }
  2795. }
  2796. #endregion
  2797. }
  2798. else
  2799. {
  2800. #region ERP开立状态单据审核
  2801. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2802. INTO #NewTempERP
  2803. from ICSWareHouseLotInfoLog
  2804. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  2805. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  2806. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2807. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  2808. BEGIN
  2809. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  2810. RETURN
  2811. END
  2812. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2813. FROM #NewTempERP a
  2814. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2815. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2816. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  2817. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2818. DROP TABLE #NewTempERP";
  2819. sql = string.Format(sql, Identification);
  2820. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2821. string Inputstr = JsonConvert.SerializeObject(dt);
  2822. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  2823. Result result = new Result();
  2824. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2825. if (result.Success)
  2826. {
  2827. try
  2828. {
  2829. foreach (DataRow dr in dt.Rows)
  2830. {
  2831. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2832. }
  2833. }
  2834. catch (Exception ex)
  2835. {
  2836. log.Debug(ex.ToString());
  2837. log.Debug(resultStr);
  2838. }
  2839. }
  2840. else
  2841. {
  2842. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2843. }
  2844. #endregion
  2845. }
  2846. }
  2847. catch (Exception)
  2848. {
  2849. throw;
  2850. }
  2851. }
  2852. #endregion
  2853. }
  2854. }