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.

3054 lines
226 KiB

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