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.

3111 lines
231 KiB

  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 ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1844. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1845. IF (@Status IS NULL)
  1846. BEGIN
  1847. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1848. RETURN
  1849. END
  1850. ELSE IF (@Status='3')
  1851. BEGIN
  1852. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1853. RETURN
  1854. END
  1855. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1856. FROM ICSInventoryLot a
  1857. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1858. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1859. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1860. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1861. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1862. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1863. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='1'
  1864. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn005', c.Quantity,1,1,'')<c.RCVQuantity)
  1865. BEGIN
  1866. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1867. END";
  1868. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1869. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1870. {
  1871. throw new Exception(language.GetNameByCode("WMSAPIInfo117"));//"委外到货单更新失败!");
  1872. }
  1873. }
  1874. catch (Exception)
  1875. {
  1876. throw;
  1877. }
  1878. }
  1879. /// <summary>
  1880. /// 审核的委外到货单接口
  1881. /// </summary>
  1882. /// <param name="TransType"></param>
  1883. /// <param name="Identification"></param>
  1884. /// <param name="cmd"></param>
  1885. public static void ODeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1886. {
  1887. try
  1888. {
  1889. DataTable flag = null;
  1890. string enablesql = @"select * from ICSConfiguration where code = 'OostackInBack002' and enable = '1'";
  1891. flag = DBHelper.SQlReturnData(enablesql, cmd);
  1892. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1893. {
  1894. //校验库存数量是否满足子件计划数量(倒冲)
  1895. string logsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,ToLocationCode,TransCode,TransSequence
  1896. from ICSWareHouseLotInfoLog
  1897. WHERE Identification = '{0}' AND ERPUpload = '0'";
  1898. logsql = string.Format(logsql, Identification);
  1899. DataTable logdt = DBHelper.SQlReturnData(logsql, cmd);
  1900. if (logdt.Rows.Count > 0 && logdt != null)
  1901. {
  1902. for (int i = 0; i < logdt.Rows.Count; i++)
  1903. {
  1904. ICSWareHouseLotInfoService.WareHouseLotInfoBackOutBefore(Identification, logdt.Rows[i]["ToLocationCode"].ToString(), logdt.Rows[i]["LotNo"].ToString(), logdt.Rows[i]["Quantity"].ToString(),
  1905. logdt.Rows[i]["MUSER"].ToString(), logdt.Rows[i]["WorkPoint"].ToString(), "2", BusinessCode, cmd, language, "", "", logdt.Rows[i]["TransCode"].ToString(), logdt.Rows[i]["TransSequence"].ToString());
  1906. }
  1907. }
  1908. }
  1909. #region ERP
  1910. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  1911. INTO #NewTempERP
  1912. from ICSWareHouseLotInfoLog
  1913. WHERE Identification='{0}' AND ERPUpload='0'
  1914. SELECT c.VenCode+a.ToWarehouseCode+c.ODNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.ODNCode ,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.ODNDetailID,a.InvCode) AS Sequence,d.OOCode,d.OODetailID,
  1915. 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
  1916. ,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,
  1917. 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
  1918. INTO #TempERP
  1919. FROM #NewTempERP a
  1920. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1921. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1922. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1923. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1924. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1925. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1926. inner join ICSOutsourcingOrder d on c.OODetailID=d.OODetailID and c.WorkPoint=d.WorkPoint
  1927. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1928. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1929. GROUP BY 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
  1930. ,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, ''),
  1931. 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, '')
  1932. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,ODNCode,OOCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1933. 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
  1934. FROM #TempERP
  1935. DROP TABLE #TempERP
  1936. DROP TABLE #NewTempERP";
  1937. sql = string.Format(sql, Identification,BusinessCode);
  1938. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1939. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1940. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.ODeliveryNoticeInURL, Inputstr);
  1941. Result result = new Result();
  1942. log.Debug(resultStr);
  1943. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1944. if (result.Success)
  1945. {
  1946. try
  1947. {
  1948. if (flag != null && flag.Rows.Count > 0)//委外入库倒冲开关(u9)
  1949. {
  1950. string newsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  1951. from ICSWareHouseLotInfoLog
  1952. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  1953. newsql = string.Format(newsql, Identification, BusinessCode);
  1954. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  1955. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1956. foreach (var item in res)
  1957. {
  1958. JObject jo = (JObject)item;
  1959. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1960. foreach (var detail in resdetail)
  1961. {
  1962. JObject det = (JObject)detail;
  1963. 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()
  1964. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1965. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1966. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1967. if (det["detailss"] != null)
  1968. {
  1969. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  1970. foreach (var details in resdetails)
  1971. {
  1972. JObject dets = (JObject)details;
  1973. if (dets != null)
  1974. {
  1975. //for (int i = 0; i < dt.Rows.Count; i++)
  1976. //{
  1977. ICSWareHouseLotInfoService.WareHouseLotInfoBackOut(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  1978. dets["WHCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  1979. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  1980. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  1981. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["BatchCode"].ToString(), dets["Version"].ToString(),
  1982. dets["Brand"].ToString(), cmd, language);
  1983. //回写已领数量
  1984. sql = @"select pickid from ICSOOPick WHERE PickID='{0}' AND WorkPoint='{1}'";
  1985. sql = string.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1986. DataTable ssdt = DBHelper.SQlReturnData(sql, cmd);
  1987. sql = @"UPDATE ICSOOPick SET IssueQuantity=(ISNULL(IssueQuantity,0)+" + dets["Quantity"].ToString() + ") WHERE PickID='{0}' AND WorkPoint='{1}'";
  1988. sql = string.Format(sql, dets["PickID"].ToString(), dt.Rows[0]["WorkPoint"].ToString());
  1989. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1990. {
  1991. throw new Exception(language.GetNameByCode("WMSAPIInfo199"));
  1992. }
  1993. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", "", dets["Quantity"].ToString(),
  1994. //dt.Rows[0]["MUSER"].ToString(), "", "", BusinessCode, cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  1995. //}
  1996. }
  1997. }
  1998. }
  1999. }
  2000. }
  2001. }
  2002. else
  2003. {
  2004. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2005. foreach (var item in res)
  2006. {
  2007. JObject jo = (JObject)item;
  2008. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2009. foreach (var detail in resdetail)
  2010. {
  2011. JObject det = (JObject)detail;
  2012. 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()
  2013. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2014. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2015. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2016. }
  2017. }
  2018. }
  2019. }
  2020. catch (Exception ex)
  2021. {
  2022. log.Debug(ex.ToString());
  2023. log.Debug(resultStr);
  2024. throw new Exception(language.GetNameByCode("WMSAPIInfo200") + ex);
  2025. }
  2026. }
  2027. else
  2028. {
  2029. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2030. }
  2031. #endregion
  2032. }
  2033. catch (Exception)
  2034. {
  2035. throw;
  2036. }
  2037. }
  2038. #endregion
  2039. #region 委外拒收
  2040. /// <summary>
  2041. /// 委外拒收
  2042. /// </summary>
  2043. /// <param name="TransCode"></param>
  2044. /// <param name="TransSequence"></param>
  2045. /// <param name="Quantity"></param>
  2046. /// <param name="WorkPoint"></param>
  2047. /// <param name="cmd"></param>
  2048. public static void OutsourcingRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2049. {
  2050. try
  2051. {
  2052. string sql = @"DECLARE @Status VARCHAR(10)
  2053. SELECT @Status=c.Status FROM ICSInventoryLot a
  2054. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2055. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2056. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2057. IF (@Status IS NULL)
  2058. BEGIN
  2059. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  2060. RETURN
  2061. END
  2062. ELSE IF (@Status='3')
  2063. BEGIN
  2064. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  2065. RETURN
  2066. END
  2067. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2068. FROM ICSInventoryLot a
  2069. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2070. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2071. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2072. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  2073. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2074. INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2075. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.ODNType='3'
  2076. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn006', c.Quantity,1,1,'')<c.RCVQuantity)
  2077. BEGIN
  2078. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  2079. END";
  2080. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  2081. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2082. {
  2083. throw new Exception(language.GetNameByCode("WMSAPIInfo118"));//"委外拒收单更新失败!");
  2084. }
  2085. }
  2086. catch (Exception)
  2087. {
  2088. throw;
  2089. }
  2090. }
  2091. /// <summary>
  2092. /// 委外拒收接口
  2093. /// </summary>
  2094. /// <param name="TransType"></param>
  2095. /// <param name="Identification"></param>
  2096. /// <param name="cmd"></param>
  2097. public static void OutsourcingRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2098. {
  2099. // try
  2100. // {
  2101. // #region ERP
  2102. // 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,
  2103. // a.InvCode,SUM(a.Quantity) AS Quantity,0 AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.ODNDetailID,Enable AS UpdateTodoQuantity
  2104. // ,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,
  2105. // 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
  2106. // INTO #TempERP
  2107. // FROM ICSWareHouseLotInfoLog a
  2108. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2109. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2110. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2111. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2112. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2113. // INNER JOIN ICSODeliveryNotice c ON b.TransCode=c.ODNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  2114. // INNER JOIN ICSODeliveryNotice d ON c.OODetailID=d.ODNDetailID AND d.WorkPoint=c.WorkPoint
  2115. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  2116. // WHERE a.Identification='{0}' AND ERPUpload='0'
  2117. // 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
  2118. // ,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, ''),
  2119. // 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, '')
  2120. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,ODNCode AS DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,WorkPoint FROM #TempERP
  2121. //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
  2122. // FROM #TempERP
  2123. // DROP TABLE #TempERP";
  2124. // sql = string.Format(sql, Identification);
  2125. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2126. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  2127. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  2128. // Result result = new Result();
  2129. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  2130. // if (result.Success)
  2131. // {
  2132. // try
  2133. // {
  2134. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2135. // foreach (var item in res)
  2136. // {
  2137. // JObject jo = (JObject)item;
  2138. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2139. // foreach (var detail in resdetail)
  2140. // {
  2141. // JObject det = (JObject)detail;
  2142. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["OODetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  2143. // }
  2144. // }
  2145. // }
  2146. // catch (Exception ex)
  2147. // {
  2148. // log.Debug(ex.ToString());
  2149. // log.Debug(resultStr);
  2150. // }
  2151. // }
  2152. // else
  2153. // {
  2154. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2155. // }
  2156. // #endregion
  2157. // }
  2158. // catch (Exception)
  2159. // {
  2160. // throw;
  2161. // }
  2162. }
  2163. /// <summary>
  2164. /// 委外拒收接口
  2165. /// </summary>
  2166. /// <param name="TransType"></param>
  2167. /// <param name="Identification"></param>
  2168. /// <param name="cmd"></param>
  2169. public static void OutsourcingRejectDocInNewERP(string ODNCode, string OJDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  2170. {
  2171. try
  2172. {
  2173. #region ERP
  2174. string sql = @"SELECT a.VenCode+a.DepCode+x.ODNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,x.ODNCode,a.MUSER,a.MTIME,
  2175. 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
  2176. ,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,
  2177. 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
  2178. INTO #TempERP
  2179. FROM ICSODeliveryNotice a
  2180. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2181. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  2182. INNER JOIN ICSODeliveryNotice x ON x.ODNDetailID=a.OODetailID AND a.WorkPoint=x.WorkPoint
  2183. WHERE a.ODNCode='{0}' AND a.WorkPoint='{1}'
  2184. 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,
  2185. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  2186. 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, '')
  2187. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,ODNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  2188. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,ODNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  2189. FROM #TempERP
  2190. DROP TABLE #TempERP";
  2191. sql = string.Format(sql, OJDNCode, WorkPoint);
  2192. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2193. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  2194. string resultStr = HTTPHelper.HttpPost("委外拒收", ERPUrl.CreateWPuArrivalVouchURL, Inputstr);
  2195. Result result = new Result();
  2196. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2197. if (result.Success)
  2198. {
  2199. try
  2200. {
  2201. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2202. foreach (var item in res)
  2203. {
  2204. JObject jo = (JObject)item;
  2205. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2206. foreach (var detail in resdetail)
  2207. {
  2208. JObject det = (JObject)detail;
  2209. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  2210. string ERPupdate = @"update ICSODeliveryNotice set ODNCode='{0}',Sequence='{1}',ODNID='{2}',ODNDetailID='{3}'
  2211. where OODetailID='{4}' AND ODNType='3' AND ODNCode='{5}' ";
  2212. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], OJDNCode);
  2213. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  2214. {
  2215. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  2216. }
  2217. }
  2218. }
  2219. }
  2220. catch (Exception ex)
  2221. {
  2222. log.Debug(ex.ToString());
  2223. log.Debug(resultStr);
  2224. }
  2225. }
  2226. else
  2227. {
  2228. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2229. }
  2230. #endregion
  2231. }
  2232. catch (Exception)
  2233. {
  2234. throw;
  2235. }
  2236. }
  2237. #endregion
  2238. #region 委外退货
  2239. /// <summary>
  2240. /// 委外退货
  2241. /// </summary>
  2242. /// <param name="TransCode"></param>
  2243. /// <param name="TransSequence"></param>
  2244. /// <param name="Quantity"></param>
  2245. /// <param name="WorkPoint"></param>
  2246. /// <param name="cmd"></param>
  2247. public static void OutsourcingReturnBack(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  2248. {
  2249. try
  2250. {
  2251. string sql = @"DECLARE @Status VARCHAR(10)
  2252. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='2' AND id='{4}' and WorkPoint='{1}'
  2253. IF (@Status IS NULL)
  2254. BEGIN
  2255. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  2256. RETURN
  2257. END
  2258. ELSE IF (@Status!='2')
  2259. BEGIN
  2260. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  2261. RETURN
  2262. END
  2263. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2264. FROM ICSODeliveryNotice a
  2265. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.id='{4}' AND ODNType='2'
  2266. UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}'
  2267. FROM ICSOutsourcingOrder b inner join ICSODeliveryNotice a on a.ooID = b.ooID and a.OODetailID = b.OODetailID
  2268. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND ODNType='2'
  2269. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  2270. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}' AND a.Quantity<a.RCVQuantity AND ODNType='2')
  2271. BEGIN
  2272. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  2273. RETURN
  2274. END
  2275. --退 eattribute4 = ODNDetailID 退
  2276. IF EXISTS(SELECT b.ID FROM ICSODeliveryNotice a inner join ICSODeliveryNotice b on a.eattribute4 = b.ODNDetailID
  2277. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.ODNType='2' AND a.eattribute3='退')
  2278. BEGIN
  2279. UPDATE b SET RCVQuantity=ISNULL(b.RCVQuantity,0)-'{2}'
  2280. FROM ICSODeliveryNotice b inner join ICSODeliveryNotice a on a.eattribute4 = b.ODNDetailID
  2281. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.ODNType='2' AND a.eattribute3='退'
  2282. END
  2283. ";
  2284. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  2285. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2286. {
  2287. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  2288. }
  2289. }
  2290. catch (Exception)
  2291. {
  2292. throw;
  2293. }
  2294. }
  2295. public static void OutsourcingReturnBackOO(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID)
  2296. {
  2297. try
  2298. {
  2299. string sql = @"DECLARE @Status VARCHAR(10)
  2300. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' AND ODNType='1' AND id='{4}' and WorkPoint='{1}'
  2301. IF (@Status IS NULL)
  2302. BEGIN
  2303. RAISERROR('" + language.GetNameByCode("WMSAPIInfo119") + @"',16,1);
  2304. RETURN
  2305. END
  2306. ELSE IF (@Status!='2')
  2307. BEGIN
  2308. RAISERROR('" + language.GetNameByCode("WMSAPIInfo120") + @"',16,1);
  2309. RETURN
  2310. END
  2311. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)-'{2}'
  2312. FROM ICSODeliveryNotice a
  2313. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.id='{4}' AND ODNType='1'
  2314. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a
  2315. WHERE a.ODNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.id='{4}' AND a.RCVQuantity<0 AND ODNType='1')
  2316. BEGIN
  2317. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  2318. RETURN
  2319. END";
  2320. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  2321. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2322. {
  2323. throw new Exception(language.GetNameByCode("WMSAPIInfo121"));//"委外退货单更新失败!");
  2324. }
  2325. }
  2326. catch (Exception)
  2327. {
  2328. throw;
  2329. }
  2330. }
  2331. /// <summary>
  2332. /// 委外退货接口
  2333. /// </summary>
  2334. /// <param name="TransType"></param>
  2335. /// <param name="Identification"></param>
  2336. /// <param name="cmd"></param>
  2337. public static void OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2338. {
  2339. try
  2340. {
  2341. #region ERP
  2342. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2343. INTO #NewTempERP
  2344. from ICSWareHouseLotInfoLog
  2345. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2346. 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,
  2347. 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
  2348. ,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,
  2349. 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
  2350. INTO #TempERP
  2351. FROM #NewTempERP a
  2352. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2353. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2354. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2355. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2356. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2357. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2358. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2359. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2360. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2361. 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
  2362. ,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, ''),
  2363. 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, '')
  2364. 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
  2365. 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
  2366. FROM #TempERP
  2367. DROP TABLE #TempERP
  2368. DROP TABLE #NewTempERP";
  2369. sql = string.Format(sql, Identification);
  2370. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2371. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2372. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackURL, Inputstr);
  2373. Result result = new Result();
  2374. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2375. if (result.Success)
  2376. {
  2377. try
  2378. {
  2379. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2380. foreach (var item in res)
  2381. {
  2382. JObject jo = (JObject)item;
  2383. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2384. foreach (var detail in resdetail)
  2385. {
  2386. JObject det = (JObject)detail;
  2387. 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()
  2388. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2389. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2390. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2391. }
  2392. }
  2393. }
  2394. catch (Exception ex)
  2395. {
  2396. log.Debug(ex.ToString());
  2397. log.Debug(resultStr);
  2398. }
  2399. }
  2400. else
  2401. {
  2402. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2403. }
  2404. #endregion
  2405. }
  2406. catch (Exception)
  2407. {
  2408. throw;
  2409. }
  2410. }
  2411. public static string OutsourcingReturnBackOOERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2412. {
  2413. string msg = "";
  2414. try
  2415. {
  2416. #region ERP
  2417. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2418. INTO #NewTempERP
  2419. from ICSWareHouseLotInfoLog
  2420. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2421. 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,
  2422. 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
  2423. ,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,
  2424. 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
  2425. INTO #TempERP
  2426. FROM #NewTempERP a
  2427. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2428. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2429. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2430. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2431. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2432. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2433. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2434. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2435. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  2436. 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
  2437. ,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, ''),
  2438. 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, '')
  2439. 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
  2440. 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
  2441. FROM #TempERP
  2442. DROP TABLE #TempERP
  2443. DROP TABLE #NewTempERP";
  2444. sql = string.Format(sql, Identification);
  2445. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2446. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2447. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReturnBackOOURL, Inputstr);
  2448. Result result = new Result();
  2449. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2450. if (result.Success)
  2451. {
  2452. log.Debug(resultStr);
  2453. try
  2454. {
  2455. string newsql = @"select LotNo,WorkPoint,InvCode,FromWarehouseCode,MUSER,Quantity,TransSequence,TransCode
  2456. from ICSWareHouseLotInfoLog
  2457. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'";
  2458. newsql = string.Format(newsql, Identification, BusinessCode);
  2459. DataTable dt = DBHelper.SQlReturnData(newsql, cmd);
  2460. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2461. foreach (var item in res)
  2462. {
  2463. JObject jo = (JObject)item;
  2464. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2465. foreach (var detail in resdetail)
  2466. {
  2467. JObject det = (JObject)detail;
  2468. 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()
  2469. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2470. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["OODetailID"].ToString(), Identification, jo["ID"].ToString(),
  2471. det["DetailID"].ToString(), jo["ORCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2472. if (det["detailss"] != null)
  2473. {
  2474. JArray resdetails = (JArray)JsonConvert.DeserializeObject(det["detailss"].ToString());
  2475. foreach (var details in resdetails)
  2476. {
  2477. JObject dets = (JObject)details;
  2478. if (dets != null)
  2479. {
  2480. //for (int i = 0; i < dt.Rows.Count; i++)
  2481. //(string Identification,
  2482. //string TransCode, string TransSequence, string InvCode, string WHCode, string Quantity, string User,
  2483. //string WorkPoint, string TransType, string BusinessCode, string ERPID, string ERPDetailID, string ERPCode, string ERPSequence,
  2484. ICSWareHouseLotInfoService.WareHouseLotInfoBackInMF(Identification, dets["SourceCode"].ToString(), dets["SourceSequence"].ToString(), dets["InvCode"].ToString(),
  2485. dets["WhCode"].ToString(), dets["Quantity"].ToString(), dt.Rows[0]["MUSER"].ToString(), dt.Rows[0]["WorkPoint"].ToString(), "13", BusinessCode, dets["ID"].ToString(),
  2486. dets["DetailID"].ToString(), dets["TransCode"].ToString(), dets["TransSequence"].ToString(), dets["cFree1"].ToString(), dets["cFree2"].ToString(),
  2487. dets["cFree3"].ToString(), dets["cFree4"].ToString(), dets["cFree5"].ToString(), dets["cFree6"].ToString(), dets["cFree7"].ToString(),
  2488. dets["cFree8"].ToString(), dets["cFree9"].ToString(), dets["cFree10"].ToString(), dets["ProjectCode"].ToString(), dets["cBatch"].ToString(), dets["version"].ToString(),
  2489. dets["brand"].ToString(), dets["PickID"].ToString(), cmd, language);
  2490. //ICSWareHouseLotInfoService.WareHouseLotInfoBack(Identification, "", dt.Rows[i]["LotNo"].ToString(), dets["Quantity"].ToString(),
  2491. //"", dt.Rows[i]["WorkPoint"].ToString(), "", "", cmd, language, "", "", "", "", dets["DCInvCode"].ToString(), dets["WHCode"].ToString());
  2492. //}
  2493. }
  2494. }
  2495. }
  2496. }
  2497. }
  2498. }
  2499. catch (Exception ex)
  2500. {
  2501. log.Debug(ex.ToString());
  2502. log.Debug(resultStr);
  2503. }
  2504. }
  2505. else
  2506. {
  2507. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2508. }
  2509. #endregion
  2510. }
  2511. catch (Exception)
  2512. {
  2513. throw;
  2514. }
  2515. return msg;
  2516. }
  2517. public static void RTOutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2518. {
  2519. try
  2520. {
  2521. #region ERP
  2522. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2523. INTO #NewTempERP
  2524. from ICSWareHouseLotInfoLog
  2525. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2526. 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,
  2527. 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
  2528. ,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,
  2529. 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
  2530. INTO #TempERP
  2531. FROM #NewTempERP a
  2532. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2533. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2534. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2535. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2536. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2537. INNER JOIN ICSODeliveryNotice z ON z.Sequence=y.OoDetailID AND z.ODNCode=y.OOID AND a.WorkPoint=y.WorkPoint
  2538. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2539. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2540. 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
  2541. ,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, ''),
  2542. 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, '')
  2543. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,'' AS DocType,MUSER AS [User],SYSDATETIME() AS MTime,SYSDATETIME() AS DocDate,SYSDATETIME() AS ArrDate FROM #TempERP
  2544. 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
  2545. FROM #TempERP
  2546. DROP TABLE #TempERP
  2547. DROP TABLE #NewTempERP";
  2548. sql = string.Format(sql, Identification);
  2549. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2550. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  2551. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.RTPurchaseReturnBackURL, Inputstr);
  2552. Result result = new Result();
  2553. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2554. if (result.Success)
  2555. {
  2556. try
  2557. {
  2558. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2559. foreach (var item in res)
  2560. {
  2561. JObject jo = (JObject)item;
  2562. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2563. foreach (var detail in resdetail)
  2564. {
  2565. JObject det = (JObject)detail;
  2566. 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()
  2567. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2568. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2569. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2570. }
  2571. }
  2572. }
  2573. catch (Exception ex)
  2574. {
  2575. log.Debug(ex.ToString());
  2576. log.Debug(resultStr);
  2577. }
  2578. }
  2579. else
  2580. {
  2581. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2582. }
  2583. #endregion
  2584. }
  2585. catch (Exception)
  2586. {
  2587. throw;
  2588. }
  2589. }
  2590. public static void U9OutsourcingReturnBackERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  2591. {
  2592. try
  2593. {
  2594. #region ERP
  2595. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2596. INTO #NewTempERP
  2597. from ICSWareHouseLotInfoLog
  2598. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '11'
  2599. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  2600. INNER JOIN ICSODeliveryNotice b ON a.TransCode=b.ODNCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2601. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  2602. BEGIN
  2603. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  2604. RETURN
  2605. END
  2606. 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,
  2607. 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
  2608. ,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,
  2609. 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
  2610. ,y.Sequence as oSequence INTO #TempERP
  2611. FROM #NewTempERP a
  2612. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2613. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2614. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2615. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2616. INNER JOIN ICSODeliveryNotice y ON a.TransCode=y.ODNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  2617. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2618. INNER JOIN ICSConfiguration conv ON conv.Code='CompleteVerification002' AND a.WorkPoint=conv.WorkPoint
  2619. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  2620. 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
  2621. ,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, ''),
  2622. 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
  2623. 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
  2624. DROP TABLE #TempERP
  2625. DROP TABLE #NewTempERP";
  2626. sql = string.Format(sql, Identification);
  2627. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2628. string Inputstr = DataToJsonHelper.ToJson(ds.Tables[0]);
  2629. string resultStr = resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9OutsourcingReturnBackURL, Inputstr);
  2630. Result result = new Result();
  2631. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2632. if (result.Success)
  2633. {
  2634. try
  2635. {
  2636. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  2637. foreach (var item in res)
  2638. {
  2639. JObject jo = (JObject)item;
  2640. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  2641. foreach (var detail in resdetail)
  2642. {
  2643. JObject det = (JObject)detail;
  2644. 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()
  2645. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  2646. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["ODNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  2647. det["DetailID"].ToString(), jo["ORCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  2648. }
  2649. }
  2650. }
  2651. catch (Exception ex)
  2652. {
  2653. log.Debug(ex.ToString());
  2654. log.Debug(resultStr);
  2655. }
  2656. }
  2657. else
  2658. {
  2659. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2660. }
  2661. #endregion
  2662. }
  2663. catch (Exception)
  2664. {
  2665. throw;
  2666. }
  2667. }
  2668. #endregion
  2669. #region 开立委外红字入库
  2670. /// <summary>
  2671. /// 开立委外红字入库
  2672. /// </summary>
  2673. /// <param name="TransCode"></param>
  2674. /// <param name="TransSequence"></param>
  2675. /// <param name="Quantity"></param>
  2676. /// <param name="WorkPoint"></param>
  2677. /// <param name="cmd"></param>
  2678. public static void OutsourcingReceiveDocNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  2679. {
  2680. try
  2681. {
  2682. string sql = @"DECLARE @Status VARCHAR(10)
  2683. SELECT @Status=a.Status FROM ICSOutsourcingReceive a
  2684. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2'
  2685. IF (@Status IS NULL)
  2686. BEGIN
  2687. RAISERROR('" + language.GetNameByCode("WMSAPIInfo122") + @"',16,1);
  2688. RETURN
  2689. END
  2690. ELSE IF (@Status!='1')
  2691. BEGIN
  2692. RAISERROR('" + language.GetNameByCode("WMSAPIInfo123") + @"',16,1);
  2693. RETURN
  2694. END
  2695. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  2696. FROM ICSOutsourcingReceive a
  2697. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2'
  2698. IF EXISTS(SELECT a.ID FROM ICSOutsourcingReceive a
  2699. 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)
  2700. BEGIN
  2701. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  2702. RETURN
  2703. END";
  2704. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence,TransID);
  2705. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2706. {
  2707. throw new Exception(language.GetNameByCode("WMSAPIInfo124"));//"委外红字入库单更新失败!");
  2708. }
  2709. }
  2710. catch (Exception)
  2711. {
  2712. throw;
  2713. }
  2714. }
  2715. /// <summary>
  2716. /// 开立委外红字入库接口
  2717. /// </summary>
  2718. /// <param name="TransType"></param>
  2719. /// <param name="Identification"></param>
  2720. /// <param name="cmd"></param>
  2721. public static void OutsourcingReceiveDocNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  2722. {
  2723. try
  2724. {
  2725. string sql = string.Empty;
  2726. if (DBHelper.IsPNU9())
  2727. {
  2728. #region ERP开立状态单据审核
  2729. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2730. INTO #NewTempERP
  2731. from ICSWareHouseLotInfoLog
  2732. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  2733. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2734. FROM #NewTempERP a
  2735. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2736. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2737. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  2738. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2739. DROP TABLE #NewTempERP";
  2740. sql = string.Format(sql, Identification);
  2741. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2742. //string Inputstr = JsonConvert.SerializeObject(dt);
  2743. 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
  2744. where a.Identification='{0}' GROUP BY a.transCode";
  2745. checksql = string.Format(checksql, Identification);
  2746. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  2747. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  2748. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  2749. string trancode = chekdt.Rows[0]["transCode"].ToString();
  2750. if (SUMQty - ISSQty == 0)
  2751. {
  2752. string pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2753. INTO #NewTempERP
  2754. from ICSWareHouseLotInfoLog
  2755. WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  2756. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2757. FROM #NewTempERP a
  2758. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2759. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2760. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  2761. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2762. DROP TABLE #NewTempERP";
  2763. pnsql = string.Format(pnsql, trancode);
  2764. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  2765. string Inputstr = JsonConvert.SerializeObject(dt);
  2766. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  2767. Result result = new Result();
  2768. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2769. if (result.Success)
  2770. {
  2771. try
  2772. {
  2773. foreach (DataRow dr in dt.Rows)
  2774. {
  2775. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2776. }
  2777. }
  2778. catch (Exception ex)
  2779. {
  2780. log.Debug(ex.ToString());
  2781. log.Debug(resultStr);
  2782. }
  2783. }
  2784. else
  2785. {
  2786. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2787. }
  2788. }
  2789. #endregion
  2790. }
  2791. else
  2792. {
  2793. #region ERP开立状态单据审核
  2794. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  2795. INTO #NewTempERP
  2796. from ICSWareHouseLotInfoLog
  2797. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '12'
  2798. IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  2799. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2800. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  2801. BEGIN
  2802. RAISERROR('" + language.GetNameByCode("WMSAPIInfo103") + @"',16,1);
  2803. RETURN
  2804. END
  2805. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  2806. FROM #NewTempERP a
  2807. INNER JOIN ICSOutsourcingReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  2808. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  2809. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  2810. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  2811. DROP TABLE #NewTempERP";
  2812. sql = string.Format(sql, Identification);
  2813. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2814. string Inputstr = JsonConvert.SerializeObject(dt);
  2815. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.OutsourcingReceiveDocNegativeURL, Inputstr);
  2816. Result result = new Result();
  2817. result = JsonConvert.DeserializeObject<Result>(resultStr);
  2818. if (result.Success)
  2819. {
  2820. try
  2821. {
  2822. foreach (DataRow dr in dt.Rows)
  2823. {
  2824. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  2825. }
  2826. }
  2827. catch (Exception ex)
  2828. {
  2829. log.Debug(ex.ToString());
  2830. log.Debug(resultStr);
  2831. }
  2832. }
  2833. else
  2834. {
  2835. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2836. }
  2837. #endregion
  2838. }
  2839. }
  2840. catch (Exception)
  2841. {
  2842. throw;
  2843. }
  2844. }
  2845. #endregion
  2846. }
  2847. }