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.

2271 lines
160 KiB

3 weeks ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 采购模块
  18. /// </summary>
  19. public class ICSPurchaseService
  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="TransType"></param>
  27. /// <param name="Identification"></param>
  28. /// <param name="cmd"></param>
  29. public static string DeliveryNoticeERP(string DNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  30. {
  31. try
  32. {
  33. #region ERP
  34. string sql = "";
  35. sql = @"SELECT isnull(a.VenCode,'')+isnull(a.DepCode,'')+isnull(a.MUSER,'') AS Costre,a.VenCode,a.DepCode,y.POCode,a.MUSER,a.MTIME,
  36. 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.PODetailID
  37. ,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,
  38. 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
  39. INTO #TempERP
  40. FROM ICSDeliveryNotice a
  41. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  42. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  43. INNER JOIN ICSPurchaseOrder y ON a.PODetailID=y.PODetailID AND a.WorkPoint=y.WorkPoint
  44. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  45. -- SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  46. -- SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,PODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  47. -- FROM #TempERP
  48. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode
  49. ,CASE (SELECT Enable FROM ICSConfiguration WHERE Code='POCodeDisplayed' AND WorkPoint='{1}') WHEN 0 THEN '' ELSE POCode END AS POCode
  50. ,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  51. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,POCode,PODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  52. FROM #TempERP
  53. DROP TABLE #TempERP";
  54. sql = string.Format(sql, DNCode, WorkPoint);
  55. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  56. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  57. string resultStr = HTTPHelper.HttpPost("采购到货", ERPUrl.CreatePOArrivURL, Inputstr);
  58. Result result = new Result();
  59. result = JsonConvert.DeserializeObject<Result>(resultStr);
  60. if (result.Success)
  61. {
  62. try
  63. {
  64. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  65. foreach (var item in res)
  66. {
  67. JObject jo = (JObject)item;
  68. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  69. foreach (var detail in resdetail)
  70. {
  71. JObject det = (JObject)detail;
  72. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  73. where PODetailID='{4}' AND DNType='1' AND DNCode='{5}' and Sequence='{1}'";
  74. ERPupdate = string.Format(ERPupdate, jo["DNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["PODetailID"],DNCode);
  75. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  76. {
  77. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  78. }
  79. }
  80. }
  81. return resultStr;
  82. }
  83. catch (Exception ex)
  84. {
  85. log.Debug(ex.ToString() + Environment.NewLine + resultStr);
  86. JArray paramArr = new JArray();
  87. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  88. foreach (var item in res)
  89. {
  90. JObject paramObj = new JObject();
  91. JObject jo = (JObject)item;
  92. paramObj.Add("DNCode", jo["DNCode"].ToString());
  93. paramObj.Add("WorkPoint", jo["WorkPoint"].ToString());
  94. paramObj.Add("User", ds.Tables[0].Rows[0]["User"].ToString());
  95. paramObj.Add("MTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  96. paramArr.Add(paramObj);
  97. }
  98. HTTPHelper.HttpPost("采购到货", ERPUrl.CreatePOArriveDelete, JsonConvert.ToString(paramArr));
  99. throw ex;
  100. }
  101. }
  102. else
  103. {
  104. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  105. }
  106. #endregion
  107. }
  108. catch (Exception)
  109. {
  110. throw;
  111. }
  112. }
  113. #endregion
  114. #region 采购入库
  115. /// <summary>
  116. /// 采购入库
  117. /// </summary>
  118. /// <param name="TransCode"></param>
  119. /// <param name="TransSequence"></param>
  120. /// <param name="Quantity"></param>
  121. /// <param name="WorkPoint"></param>
  122. /// <param name="cmd"></param>
  123. public static void PurchaseReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  124. {
  125. try
  126. {
  127. string sql = @"DECLARE @Status VARCHAR(10)
  128. SELECT @Status=c.Status FROM ICSInventoryLot a
  129. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  130. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  131. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  132. IF (@Status IS NULL)
  133. BEGIN
  134. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  135. RETURN
  136. END
  137. ELSE IF (@Status='3')
  138. BEGIN
  139. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  140. RETURN
  141. END
  142. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  143. FROM ICSInventoryLot a
  144. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  145. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  146. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  147. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  148. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  149. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  150. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  151. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', c.Quantity,1,1,'')<c.InQuantity)
  152. BEGIN
  153. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  154. END";
  155. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  156. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  157. {
  158. throw new Exception(language.GetNameByCode("WMSAPIInfo104"));//"采购入库单更新失败!");
  159. }
  160. }
  161. catch (Exception)
  162. {
  163. throw;
  164. }
  165. }
  166. public static void PurchaseReceiveDoc(string LotNo, string Quantity, Decimal BadQty, string InvCode, bool InvIQC, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  167. {
  168. try
  169. {
  170. if(BadQty > 0)
  171. {
  172. string insUptSql;
  173. if(InvIQC)
  174. {
  175. //需要检验物料,修改检验合格数量
  176. insUptSql = string.Format(@"UPDATE ICSInspection SET QualifiedQuantity=QualifiedQuantity-{2},UnqualifiedQuantity=ISNULL(UnqualifiedQuantity,0) + {2},BCCode='LL',BRCode='短装' WHERE LotNo='{0}' AND WorkPoint='{1}'",
  177. LotNo, WorkPoint, BadQty);
  178. }
  179. else
  180. {
  181. //免检物料,修改送货单已到货数量
  182. insUptSql = string.Format(@"UPDATE ICSASNDetail SET DNQuantity=DNQuantity-{2} WHERE LotNo='{0}' AND WorkPoint='{1}'",
  183. LotNo, WorkPoint, BadQty);
  184. }
  185. if(!DBHelper.ExecuteNonQuery(insUptSql, cmd))
  186. {
  187. throw new Exception("更新拒收失败");
  188. }
  189. }
  190. string sql = @"DECLARE @Status VARCHAR(10)
  191. SELECT @Status=c.Status FROM ICSInventoryLot a
  192. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  193. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  194. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  195. IF (@Status IS NULL)
  196. BEGIN
  197. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  198. RETURN
  199. END
  200. ELSE IF (@Status='3')
  201. BEGIN
  202. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  203. RETURN
  204. END
  205. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  206. FROM ICSInventoryLot a
  207. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  208. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  209. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  210. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  211. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  212. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  213. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  214. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', c.Quantity,1,1,'')<c.InQuantity)
  215. BEGIN
  216. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  217. END";
  218. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  219. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  220. {
  221. throw new Exception(language.GetNameByCode("WMSAPIInfo104"));//"采购入库单更新失败!");
  222. }
  223. }
  224. catch (Exception)
  225. {
  226. throw;
  227. }
  228. }
  229. /// <summary>
  230. /// 采购入库接口
  231. /// </summary>
  232. /// <param name="TransType"></param>
  233. /// <param name="Identification"></param>
  234. /// <param name="cmd"></param>
  235. public static void PurchaseReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode,string PalletCode)
  236. {
  237. try
  238. {
  239. #region ERP
  240. string sql = "";
  241. string sqlCheckSign = @"select * from ICSConfiguration where code = 'UploadERP001' and enable = '1'";
  242. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  243. //到货指定仓库(批次汇总)
  244. string Dsql = @"SELECT a.F_itemCode
  245. FROM Sys_SRM_ItemsDetail a
  246. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  247. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1'";
  248. Dsql = string.Format(Dsql);
  249. DataTable dtdao = DBHelper.SQlReturnData(Dsql, cmd);
  250. if (dtdao != null && dtdao.Rows.Count > 0)
  251. {
  252. sql = @"select a.LotNo,a.WorkPoint,a.InvCode,a.ToWarehouseCode,a.MUSER,a.Quantity,a.TransCode,a.TransSequence,a.Identification,
  253. 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,
  254. 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
  255. INTO #NewTempERP
  256. from ICSWareHouseLotInfoLog a
  257. INNER JOIN ICSInventoryLot lot ON lot.LotNo=a.LotNo AND lot.WorkPoint=a.WOrkPoint
  258. INNER JOIN ICSExtension ext ON ext.ID=lot.ExtensionID AND ext.WorkPoint=lot.WorkPoint
  259. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  260. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  261. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND a.BusinessCode='{1}'
  262. SELECT DISTINCT Identification,isnull(c.VenCode,'')+a.ToWarehouseCode+c.POCode+a.MUSER+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS Costre,
  263. a.TransCode+a.TransSequence+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode+f.Sequence END AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNDetailID)=36) THEN '' ELSE f.DNCode END AS DNCode,CASE WHEN((LEN(f.DNDetailID)<>36)) 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,a.TransCode,a.TransSequence,lot.EATTRIBUTE11 AS Weight,lot.EATTRIBUTE12 AS MemoBatch,
  264. 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,case when ConErp.enable=1 then f.DNDetailID else '' end AS DNDetailID,conWhCode.Enable AS ErpWhCode
  265. ,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,
  266. 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
  267. INTO #TempERP
  268. FROM #NewTempERP a
  269. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  270. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  271. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  272. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  273. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND b.TransCode=a.TransCode AND b.TransSequence=a.TransSequence AND a.WorkPoint=b.WorkPoint
  274. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  275. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint --AND lot.ExtensionID=f.ExtensionID
  276. INNER JOIN ICSExtension extd ON f.ExtensionID=extd.ID AND f.WorkPoint=extd.WorkPoint
  277. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  278. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  279. INNER JOIN ICSConfiguration conn ON a.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  280. INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP001'
  281. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  282. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose003'
  283. LEFT JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  284. where ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  285. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=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, '')+'~'+
  286. 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, '')
  287. GROUP BY lot.EATTRIBUTE11,lot.EATTRIBUTE12,conWhCode.Enable,ConErp.Enable,a.TransCode,a.Identification,a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,f.DNDetailID,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.DNCode+f.Sequence END,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
  288. ,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, ''),
  289. 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, ''),f.DNCode
  290. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock,IsFillClose FROM #TempERP
  291. SELECT Costre, Costre2,Sequence,DNSequence,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,Weight,MemoBatch,InvCode,Quantity,Amount,PODetailID,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  292. FROM #TempERP
  293. select a.LotNo,a.Quantity,a.Identification,a.TransCode+a.TransSequence+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode+f.Sequence END AS Costre2
  294. from ICSWareHouseLotInfoLog a
  295. INNER JOIN ICSInventoryLot lot ON lot.LotNo=a.LotNo AND lot.WorkPoint=a.WOrkPoint
  296. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  297. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND b.TransCode=a.TransCode AND b.TransSequence=a.TransSequence AND a.WorkPoint=b.WorkPoint
  298. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  299. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  300. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  301. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint --AND lot.ExtensionID=f.ExtensionID
  302. INNER JOIN ICSExtension extd ON f.ExtensionID=extd.ID AND f.WorkPoint=extd.WorkPoint
  303. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  304. WHERE a.Identification='{0}' AND a.ERPUpload='0' AND a.BusinessCode='{1}'
  305. AND ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  306. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')=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, '')+'~'+
  307. 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, '')
  308. SELECT DISTINCT HasDN FROM #TempERP
  309. DROP TABLE #TempERP
  310. DROP TABLE #NewTempERP
  311. ";
  312. }
  313. else
  314. {
  315. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,Identification
  316. INTO #NewTempERP
  317. from ICSWareHouseLotInfoLog
  318. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  319. SELECT Identification,isnull(c.VenCode,'')+a.ToWarehouseCode+c.POCode+a.MUSER+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode END AS Costre,a.TransCode+a.TransSequence+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode+f.Sequence END AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,CASE WHEN(LEN(f.DNDetailID)=36) THEN '' ELSE f.DNCode END AS DNCode,CASE WHEN((LEN(f.DNDetailID)<>36)) 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,a.TransSequence,lot.EATTRIBUTE11 AS Weight,lot.EATTRIBUTE12 AS MemoBatch,
  320. 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,case when ConErp.enable=1 then f.DNDetailID else '' end AS DNDetailID
  321. ,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,
  322. 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
  323. INTO #TempERP
  324. FROM #NewTempERP a
  325. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  326. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  327. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  328. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  329. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND b.TransCode=a.TransCode AND b.TransSequence=a.TransSequence AND a.WorkPoint=b.WorkPoint
  330. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  331. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  332. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  333. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  334. INNER JOIN ICSConfiguration conn ON a.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  335. INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP001'
  336. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  337. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose003'
  338. GROUP BY lot.EATTRIBUTE11,lot.EATTRIBUTE12,ConErp.Enable,a.TransCode,a.Identification,a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,f.DNDetailID,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.DNCode+f.Sequence END,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
  339. ,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, ''),
  340. 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, ''),f.DNCode
  341. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock,IsFillClose FROM #TempERP
  342. SELECT Costre, Costre2,Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,'{2}'AS PalletCode,Weight,MemoBatch,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WHCode
  343. FROM #TempERP
  344. SELECT a.LotNo,a.Quantity,a.TransCode+a.TransSequence+CASE WHEN(LEN(f.DNID)>=20) THEN '' ELSE f.DNCode+f.Sequence END AS Costre2,a.Identification
  345. FROM ICSWareHouseLotInfoLog a
  346. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  347. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  348. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  349. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND b.TransCode=a.TransCode AND b.TransSequence=a.TransSequence AND a.WorkPoint=b.WorkPoint
  350. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  351. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  352. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  353. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  354. SELECT DISTINCT HasDN FROM #TempERP
  355. DROP TABLE #TempERP
  356. DROP TABLE #NewTempERP
  357. ";
  358. }
  359. sql = string.Format(sql, Identification, BusinessCode, PalletCode);
  360. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  361. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  362. string Inputstr = DataToJsonHelper.DataSetToJsonImprove(ds, "details", "Costre", "LOTNO", "Costre2");
  363. log.Debug("采购上架ERP接口传参:" + Environment.NewLine + Inputstr);
  364. var IsDNCode = ds.Tables[3];
  365. if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  366. {
  367. throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  368. }
  369. string dncode = Convert.ToString(IsDNCode.Rows[0]["HasDN"]);
  370. if (dncode.Equals("0"))
  371. {
  372. string resultStr = string.Empty;
  373. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  374. log.Debug("采购上架ERP接口返回值:" + Environment.NewLine + resultStr);
  375. Result result = new Result();
  376. result = JsonConvert.DeserializeObject<Result>(resultStr);
  377. if (result.Success)
  378. {
  379. try
  380. {
  381. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  382. foreach (var item in res)
  383. {
  384. JObject jo = (JObject)item;
  385. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  386. foreach (var detail in resdetail)
  387. {
  388. JObject det = (JObject)detail;
  389. 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()
  390. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  391. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  392. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  393. }
  394. }
  395. }
  396. catch (Exception ex)
  397. {
  398. if (!DBHelper.IsDX())
  399. {
  400. JArray paramArr = new JArray();
  401. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  402. foreach (var item in res)
  403. {
  404. JObject paramObj = new JObject();
  405. JObject jo = (JObject)item;
  406. paramObj.Add("RCVTCode", jo["RCVTCode"].ToString());
  407. paramObj.Add("WorkPoint", jo["WorkPoint"].ToString());
  408. paramObj.Add("User", ds.Tables[0].Rows[0]["User"].ToString());
  409. paramObj.Add("MTime", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
  410. paramArr.Add(paramObj);
  411. }
  412. HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDocDelete, JsonConvert.ToString(paramArr));
  413. }
  414. else
  415. {
  416. log.Debug(ex.ToString());
  417. log.Debug(resultStr);
  418. }
  419. }
  420. }
  421. else
  422. {
  423. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  424. }
  425. }
  426. else
  427. {
  428. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr);
  429. log.Debug("采购上架ERP接口返回值:" + Environment.NewLine + resultStr);
  430. Result result = new Result();
  431. result = JsonConvert.DeserializeObject<Result>(resultStr);
  432. if (result.Success)
  433. {
  434. try
  435. {
  436. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  437. foreach (var item in res)
  438. {
  439. JObject jo = (JObject)item;
  440. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  441. foreach (var detail in resdetail)
  442. {
  443. JObject det = (JObject)detail;
  444. 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()
  445. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  446. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  447. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  448. }
  449. }
  450. }
  451. catch (Exception ex)
  452. {
  453. log.Debug(ex.ToString());
  454. }
  455. }
  456. else
  457. {
  458. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  459. }
  460. }
  461. #endregion
  462. }
  463. catch (Exception)
  464. {
  465. log.Error(000);
  466. throw;
  467. }
  468. }
  469. /// <summary>
  470. /// 创建标准收货单U9(采购)
  471. /// </summary>
  472. /// <param name="TransType"></param>
  473. /// <param name="Identification"></param>
  474. /// <param name="cmd"></param>
  475. public static void CreatePOArriveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string doctype)
  476. {
  477. try
  478. {
  479. #region ERP
  480. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransSequence
  481. INTO #NewTempERP
  482. from ICSWareHouseLotInfoLog
  483. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  484. 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,
  485. 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
  486. --,a.lotno AS Costre2
  487. ,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,
  488. 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
  489. INTO #TempERP
  490. FROM #NewTempERP a
  491. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  492. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  493. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  494. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  495. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  496. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  497. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  498. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  499. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  500. INNER JOIN ICSConfiguration conn ON a.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  501. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  502. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose003'
  503. GROUP BY-- a.LotNo,
  504. 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
  505. ,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, ''),
  506. 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
  507. 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
  508. SELECT Costre,
  509. --Costre2,
  510. 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
  511. FROM #TempERP
  512. SELECT SUM(a.Quantity) AS Quantity--,a.LotNo AS Costre2,a.LotNo,
  513. FROM ICSWareHouseLotInfoLog a
  514. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  515. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  516. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  517. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  518. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  519. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  520. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  521. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  522. INNER JOIN #TempERP te ON te.Sequence=a.TransSequence
  523. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  524. --GROUP BY a.LotNo
  525. SELECT DISTINCT HasDN FROM #TempERP
  526. DROP TABLE #TempERP
  527. DROP TABLE #NewTempERP";
  528. sql = string.Format(sql, Identification, BusinessCode,doctype);
  529. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  530. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  531. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  532. var IsDNCode = ds.Tables[3];
  533. if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  534. {
  535. throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  536. }
  537. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9CreatePOArrivURL, Inputstr);
  538. Result result = new Result();
  539. result = JsonConvert.DeserializeObject<Result>(resultStr);
  540. if (result.Success)
  541. {
  542. try
  543. {
  544. //JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  545. //foreach (var item in res)
  546. //{
  547. // JObject jo = (JObject)item;
  548. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  549. // foreach (var detail in resdetail)
  550. // {
  551. // JObject det = (JObject)detail;
  552. // 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()
  553. // + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  554. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  555. // det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  556. // }
  557. //}
  558. }
  559. catch (Exception ex)
  560. {
  561. log.Debug(ex.ToString());
  562. log.Debug(resultStr);
  563. }
  564. }
  565. else
  566. {
  567. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  568. }
  569. #endregion
  570. }
  571. catch (Exception)
  572. {
  573. throw;
  574. }
  575. }
  576. #endregion
  577. #region 采购入库-入库单
  578. /// <summary>
  579. /// 采购入库-入库单
  580. /// </summary>
  581. /// <param name="TransCode"></param>
  582. /// <param name="TransSequence"></param>
  583. /// <param name="Quantity"></param>
  584. /// <param name="WorkPoint"></param>
  585. /// <param name="cmd"></param>
  586. public static void PurchaseReceiveRevDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  587. {
  588. try
  589. {
  590. string sql = @"DECLARE @Status VARCHAR(10)
  591. SELECT @Status=c.Status FROM ICSInventoryLot a
  592. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  593. INNER JOIN ICSPurchaseReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  594. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  595. IF (@Status IS NULL)
  596. BEGIN
  597. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  598. RETURN
  599. END
  600. ELSE IF (@Status='2')
  601. BEGIN
  602. RAISERROR('" + language.GetNameByCode("WMSAPIInfo137") + @"',16,1);
  603. RETURN
  604. END
  605. UPDATE c SET RcvQuantity=ISNULL(RcvQuantity,0)+'{2}'
  606. FROM ICSInventoryLot a
  607. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  608. INNER JOIN ICSPurchaseReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  609. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  610. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  611. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  612. INNER JOIN ICSPurchaseReceive c ON b.TransCode=c.RCVCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  613. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  614. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn001', c.Quantity,1,1,'')<c.RcvQuantity)
  615. BEGIN
  616. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  617. END";
  618. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  619. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  620. {
  621. throw new Exception(language.GetNameByCode("WMSAPIInfo104"));//"采购入库单更新失败!");
  622. }
  623. }
  624. catch (Exception)
  625. {
  626. throw;
  627. }
  628. }
  629. /// <summary>
  630. /// 采购入库-入库单接口
  631. /// </summary>
  632. /// <param name="TransType"></param>
  633. /// <param name="Identification"></param>
  634. /// <param name="cmd"></param>
  635. public static void PurchaseReceiveRevDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode,string UserCode)
  636. {
  637. try
  638. {
  639. #region ERP开立状态单据审核
  640. string sql = "";
  641. string Inputstr = "";
  642. string pnsql = "";
  643. DataTable dt = null;
  644. string sqlflag = @"select * from ICSConfiguration ConErp where ConErp.Code='UploadERP001' and conerp.enable = 1 ";
  645. DataTable dtflag = DBHelper.SQlReturnData(sqlflag, cmd);
  646. if (dtflag.Rows.Count>0&& dtflag != null)
  647. {
  648. sql = @"
  649. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  650. INTO #NewTempERP
  651. from ICSWareHouseLotInfoLog
  652. WHERE Identification='{0}' AND ERPUpload='0'
  653. 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
  654. INTO #TempERP
  655. FROM #NewTempERP a
  656. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  657. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  658. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  659. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  660. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  661. select Costre,DNSequence,DNDetailID from #TempERP
  662. DROP TABLE #TempERP
  663. DROP TABLE #NewTempERP";
  664. sql = string.Format(sql, Identification);
  665. string checksql = @"select distinct b.Quantity AS SUMQty,b.RCVQuantity AS ISSQty,a.transCode,a.transSequence from ICSPurchaseReceive b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.RCVCode AND b.Sequence=a.TransSequence AND a.WorkPoint=b.WorkPoint
  666. where a.Identification='{0}' GROUP BY a.transCode,b.Quantity,b.RCVQuantity,a.transSequence";
  667. checksql = string.Format(checksql, Identification);
  668. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  669. for (int i=0;i<chekdt.Rows.Count;i++)
  670. {
  671. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[i]["SUMQty"]);
  672. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[i]["ISSQty"]);
  673. string trancode = chekdt.Rows[i]["transCode"].ToString();
  674. string transSequence = chekdt.Rows[i]["transSequence"].ToString();
  675. if (SUMQty - ISSQty == 0)
  676. {
  677. if (DBHelper.IsPNU9())
  678. {
  679. pnsql = @"select distinct WorkPoint,MUSER,TransCode,TransSequence
  680. INTO #NewTempERP
  681. from ICSWareHouseLotInfoLog
  682. WHERE TransCode='{0}' and TransSequence='{1}' AND ERPUpload='0' and EATTRIBUTE1<>'1'
  683. 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
  684. INTO #TempERP
  685. FROM #NewTempERP a
  686. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  687. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  688. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  689. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  690. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  691. select Costre,DNSequence,DNDetailID from #TempERP
  692. DROP TABLE #TempERP
  693. DROP TABLE #NewTempERP";
  694. pnsql = string.Format(pnsql, trancode, transSequence,UserCode);
  695. }
  696. else
  697. {
  698. pnsql = @"select distinct WorkPoint,MUSER,TransCode,TransSequence
  699. INTO #NewTempERP
  700. from ICSWareHouseLotInfoLog
  701. WHERE TransCode='{0}' and TransSequence='{1}' AND ERPUpload='0'
  702. 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
  703. INTO #TempERP
  704. FROM #NewTempERP a
  705. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  706. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  707. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  708. GROUP BY b.RCVID,b.RCVDetailID,b.Sequence,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  709. SELECT distinct Costre,ID,[User],MTime,UpdateTodoQuantity,UpdateStock,WorkPoint from #TempERP
  710. select Costre,DNSequence,DNDetailID from #TempERP
  711. DROP TABLE #TempERP
  712. DROP TABLE #NewTempERP";
  713. pnsql = string.Format(pnsql, trancode, transSequence);
  714. }
  715. DataSet ds = DBHelper.SQlReturnDataSet(pnsql, cmd);
  716. Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  717. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr);
  718. Result result = new Result();
  719. result = JsonConvert.DeserializeObject<Result>(resultStr);
  720. if (result.Success)
  721. {
  722. try
  723. {
  724. foreach (DataRow dr in dt.Rows)
  725. {
  726. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  727. }
  728. }
  729. catch (Exception ex)
  730. {
  731. log.Debug(ex.ToString());
  732. log.Debug(resultStr);
  733. }
  734. }
  735. else
  736. {
  737. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  738. }
  739. }
  740. }
  741. }
  742. else
  743. {
  744. sql = @"
  745. select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence
  746. INTO #NewTempERP
  747. from ICSWareHouseLotInfoLog
  748. WHERE Identification='{0}' AND ERPUpload='0'
  749. IF EXISTS(SELECT b.ID FROM ICSPurchaseReceive b
  750. WHERE b.RCVCode+b.WorkPoint IN (SELECT a.TransCode+a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification='{0}')
  751. AND b.Quantity!=b.RCVQuantity)
  752. BEGIN
  753. RAISERROR('',16,1);
  754. RETURN
  755. END
  756. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  757. FROM #NewTempERP a
  758. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  759. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  760. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock003' AND a.WorkPoint=conStock.WorkPoint
  761. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  762. DROP TABLE #NewTempERP";
  763. sql = string.Format(sql, Identification);
  764. dt = DBHelper.SQlReturnData(sql, cmd);
  765. Inputstr = JsonConvert.SerializeObject(dt);
  766. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.U9DeliveryNoticeURL, Inputstr);
  767. Result result = new Result();
  768. result = JsonConvert.DeserializeObject<Result>(resultStr);
  769. if (result.Success)
  770. {
  771. try
  772. {
  773. foreach (DataRow dr in dt.Rows)
  774. {
  775. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  776. }
  777. }
  778. catch (Exception ex)
  779. {
  780. log.Debug(ex.ToString());
  781. log.Debug(resultStr);
  782. }
  783. }
  784. else
  785. {
  786. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  787. }
  788. }
  789. #endregion
  790. }
  791. catch (Exception)
  792. {
  793. throw;
  794. }
  795. }
  796. #endregion
  797. #region 审核的到货单
  798. /// <summary>
  799. /// 审核的到货单
  800. /// </summary>
  801. /// <param name="TransCode"></param>
  802. /// <param name="TransSequence"></param>
  803. /// <param name="Quantity"></param>
  804. /// <param name="WorkPoint"></param>
  805. /// <param name="cmd"></param>
  806. public static void DeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  807. {
  808. try
  809. {
  810. string sql = @"DECLARE @Status VARCHAR(10)
  811. SELECT @Status=c.Status FROM ICSInventoryLot a
  812. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  813. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  814. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  815. IF (@Status IS NULL)
  816. BEGIN
  817. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  818. RETURN
  819. END
  820. ELSE IF (@Status='3')
  821. BEGIN
  822. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  823. RETURN
  824. END
  825. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  826. FROM ICSInventoryLot a
  827. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  828. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  829. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  830. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  831. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  832. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  833. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  834. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn002', c.Quantity,1,1,'')<c.RCVQuantity)
  835. BEGIN
  836. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  837. END";
  838. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  839. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  840. {
  841. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  842. }
  843. }
  844. catch (Exception)
  845. {
  846. throw;
  847. }
  848. }
  849. /// <summary>
  850. /// 审核的到货单接口
  851. /// </summary>
  852. /// <param name="TransType"></param>
  853. /// <param name="Identification"></param>
  854. /// <param name="cmd"></param>
  855. public static DataTable DeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode,string PalletCode)
  856. {
  857. string Inputstr2 = "";
  858. string resultStr = "";
  859. Result result = new Result();
  860. try
  861. {
  862. DataTable dtablee = new DataTable();
  863. string checklotno = "";
  864. string checksql = @"SELECT c.dncode,a.lotno FROM ICSInventoryLot a
  865. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  866. INNER JOIN (select dncode,Sequence,WorkPoint FROM ICSDeliveryNotice) c ON b.TransCode=c.dncode
  867. AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  868. left join ICSWareHouseLotInfo d on a.lotno=d.lotno and a.WorkPoint=d.WorkPoint
  869. WHERE c.dncode in (select TransCode from ICSWareHouseLotInfoLog
  870. where Identification='{0}' )
  871. and d.lotno is null";
  872. checksql = string.Format(checksql, Identification);
  873. DataTable dtt = DBHelper.SQlReturnData(checksql, cmd);
  874. if (dtt.Rows.Count > 1)
  875. {
  876. // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
  877. foreach (DataRow row in dtt.Rows)
  878. {
  879. checklotno += row["lotno"].ToString() + ",";
  880. }
  881. checklotno = checklotno.TrimEnd(','); // 去除最后一个逗号
  882. }
  883. else if (dtt.Rows.Count == 1)
  884. {
  885. // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  886. checklotno = dtt.Rows[0]["lotno"].ToString();
  887. }
  888. string checkrcvcode = "";
  889. string checknewsql = @"SELECT distinct c.DNCode FROM ICSInventoryLot a
  890. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  891. INNER JOIN (select DNCode,Sequence,WorkPoint FROM ICSDeliveryNotice) c ON b.TransCode=c.DNCode
  892. AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  893. left join ICSWareHouseLotInfo d on a.lotno=d.lotno and a.WorkPoint=d.WorkPoint
  894. WHERE c.DNCode in (select TransCode from ICSWareHouseLotInfoLog
  895. where Identification='{0}' )
  896. and d.lotno is NULL";
  897. checknewsql = string.Format(checknewsql, Identification);
  898. DataTable dttnew = DBHelper.SQlReturnData(checknewsql, cmd);
  899. if (dttnew.Rows.Count > 1)
  900. {
  901. // 如果dtt的行数大于1,将lotno以逗号隔开的形式加入checklotno中
  902. foreach (DataRow row in dttnew.Rows)
  903. {
  904. checkrcvcode += row["DNCode"].ToString() + ",";
  905. }
  906. checkrcvcode = checkrcvcode.TrimEnd(','); // 去除最后一个逗号
  907. }
  908. else if (dttnew.Rows.Count == 1)
  909. {
  910. // 如果dtt的行数等于1,直接将lotno赋值给checklotno
  911. checkrcvcode = dttnew.Rows[0]["DNCode"].ToString();
  912. }
  913. string sqlflag = @"select * from ICSConfiguration ConErp where ConErp.Code='UploadERP001' and conerp.enable = 1 ";
  914. //判断是否启用到货功能(未启用到货的 调用入库采购订单接口)
  915. DataTable dtflag = DBHelper.SQlReturnData(sqlflag, cmd);
  916. if (dtflag.Rows.Count > 0&& dtflag!=null)
  917. {
  918. #region ERP
  919. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity
  920. INTO #NewTempERP
  921. from ICSWareHouseLotInfoLog
  922. WHERE Identification='{0}' AND ERPUpload='0'
  923. SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER+d.POCode AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.DNCode ,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNDetailID,a.InvCode) AS Sequence,d.POCode,d.PODetailID,lot.EATTRIBUTE11 AS Weight,
  924. 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.DNDetailID,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  925. ,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,
  926. 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
  927. ,c.DNID
  928. INTO #TempERP
  929. FROM #NewTempERP a
  930. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  931. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  932. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  933. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  934. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  935. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  936. inner join ICSPurchaseOrder d on c.PODetailID=d.PODetailID and c.WorkPoint=d.WorkPoint
  937. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  938. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  939. GROUP BY lot.EATTRIBUTE11,d.POCode,d.PODetailID,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNID,a.MUSER,a.InvCode,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conStock.Enable
  940. ,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, ''),
  941. 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, '')
  942. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode,POCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock,DNID FROM #TempERP
  943. SELECT Costre,Sequence,InvCode,Quantity,Amount,'{2}'AS PalletCode,Weight,DNDetailID,PODetailID,WarehouseCode AS WHCode,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WarehouseCode AS WHCode
  944. FROM #TempERP
  945. DROP TABLE #TempERP
  946. DROP TABLE #NewTempERP
  947. ";
  948. sql = string.Format(sql, Identification, checklotno, checkrcvcode);
  949. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  950. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  951. Inputstr2 = Inputstr;
  952. //晶华
  953. string checkksql = @"SELECT DISTINCT
  954. b.F_ItemCode
  955. FROM Sys_SRM_Items a
  956. LEFT JOIN Sys_SRM_ItemsDetail b ON a.F_Id = b.F_ItemId
  957. WHERE a.F_EnCode = 'locationOfliku'
  958. ";
  959. DataTable chekdtt = DBHelper.SQlReturnData(checkksql, cmd);
  960. if (chekdtt != null && chekdtt.Rows.Count > 0)
  961. {
  962. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr);
  963. }
  964. else
  965. {
  966. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  967. }
  968. //Result result = new Result();
  969. result = JsonConvert.DeserializeObject<Result>(resultStr);
  970. if (result.Success)
  971. {
  972. try
  973. {
  974. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  975. foreach (var item in res)
  976. {
  977. JObject jo = (JObject)item;
  978. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  979. foreach (var detail in resdetail)
  980. {
  981. JObject det = (JObject)detail;
  982. 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()
  983. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  984. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  985. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  986. }
  987. }
  988. }
  989. catch (Exception ex)
  990. {
  991. log.Debug(ex.ToString());
  992. log.Debug(resultStr);
  993. }
  994. }
  995. else
  996. {
  997. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  998. }
  999. //sql= @" SELECT {1},{2} FROM ICSDeliveryNotice b
  1000. // WHERE b.DNCode + b.WorkPoint IN(SELECT a.TransCode + a.WorkPoint FROM ICSWareHouseLotInfoLog a WHERE a.Identification = '{0}'
  1001. // and SUM(Quantity)<>SUM(RCVQuantity))";
  1002. //sql = string.Format(sql, Identification, checklotno, checkrcvcode);
  1003. #endregion
  1004. }
  1005. else
  1006. {
  1007. #region ERP
  1008. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,Identification
  1009. INTO #NewTempERP
  1010. from ICSWareHouseLotInfoLog
  1011. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1012. SELECT Identification,c.VenCode+a.ToWarehouseCode+c.POCode+a.MUSER AS Costre,a.TransCode+a.TransSequence+CONVERT(VARCHAR,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,a.InvCode)) AS Costre2,c.VenCode,a.ToWarehouseCode AS WarehouseCode,c.POCode,'' AS DNCode,'0' AS HasDN,a.MUSER,'' AS DNSequence,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,a.InvCode) AS Sequence,a.TransSequence,
  1013. 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, '' AS DNDetailID
  1014. ,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,
  1015. 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
  1016. INTO #TempERP
  1017. FROM #NewTempERP a WITH(nolock)
  1018. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1019. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1020. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1021. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1022. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1023. --INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1024. INNER JOIN ICSDeliveryNotice f ON a.TransCode=f.DNCode AND a.TransSequence=f.Sequence AND a.WorkPoint=f.WorkPoint --AND lot.ExtensionID=f.ExtensionID
  1025. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  1026. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1027. INNER JOIN ICSConfiguration conn ON a.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  1028. INNER JOIN ICSConfiguration ConErp ON a.WorkPoint=ConErp.WorkPoint AND ConErp.Code='UploadERP001'
  1029. INNER JOIN ICSConfiguration conStock ON a.WorkPoint=conStock.WorkPoint AND conStock.Code='UpdateStock001'
  1030. INNER JOIN ICSConfiguration conStocknew ON a.WorkPoint=conStocknew.WorkPoint AND conStocknew.Code='FillClose003'
  1031. GROUP BY ConErp.Enable,a.TransCode,a.Identification,a.TransSequence,inv.AmountEnable,c.VenCode,a.ToWarehouseCode,c.POCode,f.DNDetailID,a.MUSER,a.InvCode,c.PODetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conn.Enable,conStock.Enable,conStocknew.Enable
  1032. ,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, ''),
  1033. 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, '')
  1034. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity,UpdateStock,IsFillClose FROM #TempERP
  1035. SELECT Costre, Costre2,Sequence,DNSequence,InvCode,Quantity,'{2}'AS PalletCode,Amount,PODetailID,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1036. FROM #TempERP
  1037. SELECT a.LotNo,SUM(a.Quantity) AS Quantity,te.Costre2,a.Identification
  1038. FROM ICSWareHouseLotInfoLog a
  1039. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1040. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1041. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1042. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1043. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1044. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  1045. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint AND lot.ExtensionID=f.ExtensionID
  1046. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  1047. INNER JOIN #TempERP te ON te.TransSequence=a.TransSequence
  1048. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  1049. GROUP BY a.LotNo,a.Identification,a.TransCode,a.TransSequence,c.VenCode,a.ToWarehouseCode,c.POCode,c.PODetailID,a.InvCode,te.Sequence,te.Costre2
  1050. SELECT DISTINCT HasDN FROM #TempERP
  1051. DROP TABLE #TempERP
  1052. DROP TABLE #NewTempERP
  1053. ";
  1054. sql = string.Format(sql, Identification, BusinessCode,PalletCode);
  1055. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1056. //string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1057. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre", "LOTNO", "Costre2");
  1058. Inputstr2 = Inputstr;
  1059. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr);
  1060. //Result result = new Result();
  1061. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1062. if (result.Success)
  1063. {
  1064. try
  1065. {
  1066. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1067. foreach (var item in res)
  1068. {
  1069. JObject jo = (JObject)item;
  1070. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1071. foreach (var detail in resdetail)
  1072. {
  1073. JObject det = (JObject)detail;
  1074. 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()
  1075. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1076. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  1077. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1078. }
  1079. }
  1080. }
  1081. catch (Exception ex)
  1082. {
  1083. log.Debug(ex.ToString());
  1084. log.Debug(resultStr);
  1085. }
  1086. }
  1087. else
  1088. {
  1089. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1090. }
  1091. #endregion
  1092. }
  1093. DataTable chekdt = new DataTable();
  1094. chekdt.Columns.Add("checkrcvcode", typeof(string));
  1095. chekdt.Columns.Add("checklotno", typeof(string));
  1096. DataRow newrow = chekdt.NewRow();
  1097. newrow["checkrcvcode"] = checkrcvcode;
  1098. newrow["checklotno"] = checklotno;
  1099. chekdt.Rows.Add(newrow);
  1100. string aaaa = JsonConvert.SerializeObject(chekdt);
  1101. return chekdt;
  1102. }
  1103. catch (Exception)
  1104. {
  1105. //DataTable WHtable = ICSControlModeService.GetJHWHCode();
  1106. //if (WHtable == null)
  1107. //{
  1108. throw;
  1109. //}
  1110. //else
  1111. //{
  1112. // //ICSControlModeService.InsertErrLog(ERPUrl.DeliveryNoticeURL, Inputstr2, result.Message, JObject.Parse(Inputstr2)["UserCode"]?.ToString(), JObject.Parse(Inputstr2)["OrgCode"]?.ToString(),cmd);
  1113. // ICSControlModeService.InsertErrLog(ERPUrl.DeliveryNoticeURL, Inputstr2, result.Message, JArray.Parse(Inputstr2)[0]["User"]?.ToString(), JArray.Parse(Inputstr2)[0]["WorkPoint"]?.ToString(), cmd);
  1114. // return new DataTable();
  1115. //}
  1116. }
  1117. }
  1118. #endregion
  1119. #region 采购拒收
  1120. /// <summary>
  1121. /// 采购拒收
  1122. /// </summary>
  1123. /// <param name="TransCode"></param>
  1124. /// <param name="TransSequence"></param>
  1125. /// <param name="Quantity"></param>
  1126. /// <param name="WorkPoint"></param>
  1127. /// <param name="cmd"></param>
  1128. public static void PurchaseRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1129. {
  1130. try
  1131. {
  1132. string sql = @"DECLARE @Status VARCHAR(10)
  1133. SELECT @Status=c.Status FROM ICSInventoryLot a
  1134. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1135. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1136. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  1137. IF (@Status IS NULL)
  1138. BEGIN
  1139. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  1140. RETURN
  1141. END
  1142. ELSE IF (@Status='3')
  1143. BEGIN
  1144. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  1145. RETURN
  1146. END
  1147. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1148. FROM ICSInventoryLot a
  1149. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1150. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1151. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  1152. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  1153. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1154. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1155. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  1156. AND dbo.GetExcessInQty(c.InvCode, c.WorkPoint, 'OverIn003', c.Quantity,1,1,'')<c.RCVQuantity)
  1157. BEGIN
  1158. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  1159. END";
  1160. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  1161. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1162. {
  1163. throw new Exception(language.GetNameByCode("WMSAPIInfo084"));//"拒收单更新失败!");
  1164. }
  1165. }
  1166. catch (Exception)
  1167. {
  1168. throw;
  1169. }
  1170. }
  1171. /// <summary>
  1172. /// 采购拒收接口
  1173. /// </summary>
  1174. /// <param name="TransType"></param>
  1175. /// <param name="Identification"></param>
  1176. /// <param name="cmd"></param>
  1177. public static void PurchaseRejectDocInNewERP(string DNCode, string JDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  1178. {
  1179. //try
  1180. //{
  1181. // #region ERP
  1182. // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNDetailID,a.InvCode) AS Sequence,
  1183. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.DNDetailID,con.Enable AS UpdateTodoQuantity
  1184. // ,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,
  1185. // 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 VerificationEnable
  1186. // INTO #TempERP
  1187. // FROM ICSWareHouseLotInfoLog a
  1188. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1189. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1190. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1191. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1192. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1193. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1194. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  1195. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1196. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  1197. // WHERE a.Identification='{0}' AND ERPUpload='0'
  1198. // GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,lot.Amount,lot.Quantity,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conv.Enable
  1199. // ,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, ''),
  1200. // 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, '')
  1201. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  1202. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1203. // FROM #TempERP
  1204. // DROP TABLE #TempERP";
  1205. // sql = string.Format(sql, Identification);
  1206. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1207. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  1208. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  1209. // Result result = new Result();
  1210. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  1211. // if (result.Success)
  1212. // {
  1213. // try
  1214. // {
  1215. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1216. // foreach (var item in res)
  1217. // {
  1218. // JObject jo = (JObject)item;
  1219. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1220. // foreach (var detail in resdetail)
  1221. // {
  1222. // JObject det = (JObject)detail;
  1223. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1224. // }
  1225. // }
  1226. // }
  1227. // catch (Exception ex)
  1228. // {
  1229. // log.Debug(ex.ToString());
  1230. // log.Debug(resultStr);
  1231. // }
  1232. // }
  1233. // else
  1234. // {
  1235. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1236. // }
  1237. // #endregion
  1238. //}
  1239. //catch (Exception)
  1240. //{
  1241. // throw;
  1242. //}
  1243. try
  1244. {
  1245. #region ERP
  1246. string whcode = string.Empty;
  1247. string sql = string.Empty;
  1248. //到货指定仓库(批次汇总)
  1249. string Dsql = @"SELECT a.F_itemCode
  1250. FROM Sys_SRM_ItemsDetail a
  1251. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  1252. WHERE b.F_EnCode='DaoWHCode' AND a.F_EnabledMark='1'";
  1253. Dsql = string.Format(Dsql);
  1254. DataTable dtdao = DBHelper.SQlReturnData(Dsql, cmd);
  1255. if (dtdao.Rows.Count > 0 && dtdao != null)
  1256. {
  1257. whcode = dtdao.Rows[0]["F_itemCode"].ToString();
  1258. sql = @"SELECT ISNULL(a.VenCode,'')+ISNULL(a.DepCode,'')+ISNULL(x.DNCode,'')+ISNULL(a.MUSER,'') AS Costre,a.VenCode,ISNULL(a.DepCode,'') AS DepCode,x.DNCode,a.MUSER,SYSDATETIME() AS MTIME,
  1259. ROW_NUMBER() OVER (ORDER BY x.DNCode,x.DNDetailID,a.InvCode) AS Sequence,a.InvCode,Sum(a.Quantity) AS Quantity,CASE inv.AmountEnable WHEN '1' THEN a.Amount ELSE '0' END AS Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,x.DNDetailID
  1260. ,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,
  1261. 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
  1262. INTO #TempERP
  1263. FROM ICSDeliveryNotice a
  1264. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1265. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1266. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND '{2}'=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1267. INNER JOIN ICSDeliveryNotice x ON x.DNDetailID=a.PODetailID AND a.WorkPoint=x.WorkPoint
  1268. INNER JOIN ICSExtension extd ON x.ExtensionID=extd.ID AND x.WorkPoint=extd.WorkPoint
  1269. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}' and
  1270. 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, '')+'~'+
  1271. 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, '') = ISNULL(extd.ProjectCode, '')+'~'+CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(extd.BatchCode, '') ELSE '' END+'~'+ISNULL(extd.Version, '')+'~'+ISNULL(extd.Brand, '')+'~'+
  1272. ISNULL(extd.cFree1, '')+'~'+ISNULL(extd.cFree2, '')+'~'+ISNULL(extd.cFree3, '')+'~'+ISNULL(extd.cFree4, '')+'~'+ISNULL(extd.cFree5, '')+'~'+ISNULL(extd.cFree6, '')+'~'+ISNULL(extd.cFree7, '')+'~'+ISNULL(extd.cFree8, '')+'~'+ISNULL(extd.cFree9, '')+'~'+ISNULL(extd.cFree10, '')
  1273. GROUP BY a.VenCode,a.DepCode,x.DNCode,a.MUSER,inv.AmountEnable,invBat.BatchEnable,a.InvCode,a.Amount,a.UnitPrice,a.Currency,x.DNDetailID,
  1274. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(inv.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  1275. 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, '')
  1276. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  1277. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1278. FROM #TempERP
  1279. DROP TABLE #TempERP
  1280. SELECT * FROM ICSInventoryBatchEnable";
  1281. sql = string.Format(sql, JDNCode, WorkPoint, whcode);
  1282. }
  1283. else
  1284. {
  1285. sql = @"SELECT ISNULL(a.VenCode,'')+ISNULL(a.DepCode,'')+ISNULL(x.DNCode,'')+ISNULL(a.MUSER,'') AS Costre,a.VenCode,ISNULL(a.DepCode,'') AS DepCode,x.DNCode,a.MUSER,SYSDATETIME() AS MTIME,
  1286. ROW_NUMBER() OVER (ORDER BY x.DNCode,x.DNDetailID,a.InvCode) AS 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.DNDetailID
  1287. ,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,
  1288. 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
  1289. INTO #TempERP
  1290. FROM ICSDeliveryNotice a
  1291. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1292. INNER JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  1293. INNER JOIN ICSDeliveryNotice x ON x.DNDetailID=a.PODetailID AND a.WorkPoint=x.WorkPoint
  1294. INNER JOIN ICSExtension extd ON x.ExtensionID=extd.ID AND x.WorkPoint=extd.WorkPoint
  1295. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  1296. GROUP BY a.VenCode,a.DepCode,x.DNCode,a.MUSER,invBat.AmountEnable,a.InvCode,a.Amount,a.UnitPrice,a.Currency,x.DNDetailID,
  1297. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  1298. 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, '')
  1299. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  1300. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1301. FROM #TempERP
  1302. DROP TABLE #TempERP";
  1303. sql = string.Format(sql, JDNCode, WorkPoint);
  1304. }
  1305. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1306. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  1307. string resultStr = HTTPHelper.HttpPost("采购拒收", ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  1308. Result result = new Result();
  1309. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1310. if (result.Success)
  1311. {
  1312. try
  1313. {
  1314. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1315. foreach (var item in res)
  1316. {
  1317. JObject jo = (JObject)item;
  1318. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1319. foreach (var detail in resdetail)
  1320. {
  1321. JObject det = (JObject)detail;
  1322. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1323. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  1324. where PODetailID='{4}' AND DNType='3' AND DNCode='{5}' ";
  1325. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], JDNCode);
  1326. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  1327. {
  1328. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  1329. }
  1330. }
  1331. }
  1332. }
  1333. catch (Exception ex)
  1334. {
  1335. log.Debug(ex.ToString());
  1336. log.Debug(resultStr);
  1337. }
  1338. }
  1339. else
  1340. {
  1341. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1342. }
  1343. #endregion
  1344. }
  1345. catch (Exception)
  1346. {
  1347. throw;
  1348. }
  1349. }
  1350. /// <summary>
  1351. /// 采购拒收接口
  1352. /// </summary>
  1353. /// <param name="TransType"></param>
  1354. /// <param name="Identification"></param>
  1355. /// <param name="cmd"></param>
  1356. public static void PurchaseRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1357. {
  1358. //try
  1359. //{
  1360. // #region ERP
  1361. // string sql = @"SELECT c.VenCode+a.ToWarehouseCode+c.DNCode+a.MUSER AS Costre,c.VenCode,a.ToWarehouseCode AS WarehouseCode,d.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY c.VenCode,a.ToWarehouseCode,c.DNCode,c.DNDetailID,a.InvCode) AS Sequence,
  1362. // a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,d.DNDetailID,con.Enable AS UpdateTodoQuantity
  1363. // ,a.WorkPoint,ISNULL(ext.ProjectCode, '') AS ProjectCode,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,ISNULL(ext.Version, '') AS Version,ISNULL(ext.Brand, '') AS Brand,
  1364. // ISNULL(ext.cFree1, '') AS cFree1,ISNULL(ext.cFree2, '') AS cFree2,ISNULL(ext.cFree3, '') AS cFree3,ISNULL(ext.cFree4, '') AS cFree4,ISNULL(ext.cFree5, '') AS cFree5,ISNULL(ext.cFree6, '') AS cFree6,ISNULL(ext.cFree7, '') AS cFree7,ISNULL(ext.cFree8, '') AS cFree8,ISNULL(ext.cFree9, '') AS cFree9,ISNULL(ext.cFree10, '') AS cFree10,conv.Enable AS VerificationEnable
  1365. // INTO #TempERP
  1366. // FROM ICSWareHouseLotInfoLog a
  1367. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  1368. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1369. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1370. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1371. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1372. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  1373. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  1374. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  1375. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  1376. // WHERE a.Identification='{0}' AND ERPUpload='0'
  1377. // GROUP BY c.VenCode,a.ToWarehouseCode,c.DNCode,d.DNCode,a.MUSER,a.InvCode,d.DNDetailID,c.DNDetailID,isnull((c.UnitPrice),0),c.Currency,con.Enable,conv.Enable
  1378. // ,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, ''),
  1379. // 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, '')
  1380. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  1381. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1382. // FROM #TempERP
  1383. // DROP TABLE #TempERP";
  1384. // sql = string.Format(sql, Identification);
  1385. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1386. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  1387. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  1388. // Result result = new Result();
  1389. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  1390. // if (result.Success)
  1391. // {
  1392. // try
  1393. // {
  1394. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1395. // foreach (var item in res)
  1396. // {
  1397. // JObject jo = (JObject)item;
  1398. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1399. // foreach (var detail in resdetail)
  1400. // {
  1401. // JObject det = (JObject)detail;
  1402. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  1403. // }
  1404. // }
  1405. // }
  1406. // catch (Exception ex)
  1407. // {
  1408. // log.Debug(ex.ToString());
  1409. // log.Debug(resultStr);
  1410. // }
  1411. // }
  1412. // else
  1413. // {
  1414. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1415. // }
  1416. // #endregion
  1417. //}
  1418. //catch (Exception)
  1419. //{
  1420. // throw;
  1421. //}
  1422. }
  1423. #endregion
  1424. #region 采购退货
  1425. /// <summary>
  1426. /// 采购退货
  1427. /// </summary>
  1428. /// <param name="TransCode"></param>
  1429. /// <param name="TransSequence"></param>
  1430. /// <param name="Quantity"></param>
  1431. /// <param name="WorkPoint"></param>
  1432. /// <param name="cmd"></param>
  1433. public static void PurchaseReceiveDoctNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  1434. {
  1435. try
  1436. {
  1437. string sql = @"DECLARE @Status VARCHAR(10)
  1438. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}' --and ID='{4}'
  1439. IF (@Status IS NULL)
  1440. BEGIN
  1441. RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
  1442. RETURN
  1443. END
  1444. ELSE IF (@Status!='2')
  1445. BEGIN
  1446. RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
  1447. RETURN
  1448. END
  1449. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1450. FROM ICSDeliveryNotice a
  1451. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2' --and a.ID='{4}'
  1452. UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}'
  1453. FROM icsPurchaseOrder b inner join ICSDeliveryNotice a on a.poID = b.poid and a.PODetailID = b.PODetailID
  1454. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  1455. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
  1456. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND DNType='2' --and a.ID='{4}'
  1457. )
  1458. BEGIN
  1459. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  1460. RETURN
  1461. END
  1462. --退 eattribute8 = DNDetailID 退
  1463. IF EXISTS(SELECT b.ID FROM ICSDeliveryNotice a inner join ICSDeliveryNotice b on a.eattribute8 = b.DNDetailID
  1464. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.DNType='2' AND a.eattribute7='退')
  1465. BEGIN
  1466. UPDATE b SET RCVQuantity=ISNULL(b.RCVQuantity,0)-'{2}'
  1467. FROM ICSDeliveryNotice b inner join ICSDeliveryNotice a on a.eattribute8 = b.DNDetailID
  1468. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.DNType='2' AND a.eattribute7='退'
  1469. END
  1470. --退 eattribute9 = 2 退
  1471. IF EXISTS(SELECT b.ID FROM ICSDeliveryNotice a inner join icsPurchaseOrder b on a.poID = b.poid and a.PODetailID = b.PODetailID
  1472. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.eattribute9='2' AND DNType='2')
  1473. BEGIN
  1474. UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}'
  1475. FROM icsPurchaseOrder b inner join ICSDeliveryNotice a on a.poID = b.poid and a.PODetailID = b.PODetailID
  1476. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  1477. END
  1478. ";
  1479. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  1480. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1481. {
  1482. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  1483. }
  1484. }
  1485. catch (Exception)
  1486. {
  1487. throw;
  1488. }
  1489. }
  1490. /// <summary>
  1491. /// 采购退货接口
  1492. /// </summary>
  1493. /// <param name="TransType"></param>
  1494. /// <param name="Identification"></param>
  1495. /// <param name="cmd"></param>
  1496. public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1497. {
  1498. string resultStr = "";
  1499. string Inputstr2 = "";
  1500. Result result = new Result();
  1501. try
  1502. {
  1503. #region ERP
  1504. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1505. INTO #NewTempERP
  1506. from ICSWareHouseLotInfoLog
  1507. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '3'
  1508. SELECT y.VenCode+a.FromWarehouseCode+y.DNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.DNCode,y.DNDetailID,a.InvCode) AS Sequence,conWhCode.Enable AS ErpWhCode,
  1509. 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.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1510. ,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,
  1511. 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
  1512. INTO #TempERP
  1513. FROM #NewTempERP a
  1514. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1515. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1516. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1517. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1518. INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  1519. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1520. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1521. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1522. GROUP BY conWhCode.Enable,inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conStock.Enable
  1523. ,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, ''),
  1524. 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, '')
  1525. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode AS DNRTCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1526. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,DNDetailID AS DNRTDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1527. FROM #TempERP
  1528. DROP TABLE #TempERP
  1529. DROP TABLE #NewTempERP";
  1530. sql = string.Format(sql, Identification);
  1531. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1532. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1533. Inputstr2 = Inputstr;
  1534. resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReturnBackURL, Inputstr);
  1535. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1536. if (result.Success)
  1537. {
  1538. try
  1539. {
  1540. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1541. foreach (var item in res)
  1542. {
  1543. JObject jo = (JObject)item;
  1544. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1545. foreach (var detail in resdetail)
  1546. {
  1547. JObject det = (JObject)detail;
  1548. 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()
  1549. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1550. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1551. det["DetailID"].ToString(), jo["RCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol,cmd, language,BusinessCode);
  1552. }
  1553. }
  1554. }
  1555. catch (Exception ex)
  1556. {
  1557. log.Debug(ex.ToString());
  1558. log.Debug(resultStr);
  1559. }
  1560. }
  1561. else
  1562. {
  1563. throw new Exception(language.GetNameByCode("WMSAPIInfo080")+result.Message);
  1564. }
  1565. #endregion
  1566. }
  1567. catch (Exception)
  1568. {
  1569. //DataTable WHtable = ICSControlModeService.GetJHWHCode();
  1570. //if (WHtable == null)
  1571. //{
  1572. throw;
  1573. //}
  1574. //else
  1575. //{
  1576. // // ICSControlModeService.InsertErrLog(ERPUrl.PurchaseReturnBackURL, Inputstr2, result.Message, JObject.Parse(Inputstr2)["UserCode"]?.ToString(), JObject.Parse(Inputstr2)["OrgCode"]?.ToString(),cmd);
  1577. // ICSControlModeService.InsertErrLog(ERPUrl.PurchaseReturnBackURL, Inputstr2, result.Message, JArray.Parse(Inputstr2)[0]["User"]?.ToString(), JArray.Parse(Inputstr2)[0]["WorkPoint"]?.ToString(), cmd);
  1578. //}
  1579. }
  1580. }
  1581. /// <summary>
  1582. /// 采购退货接口
  1583. /// </summary>
  1584. /// <param name="TransType"></param>
  1585. /// <param name="Identification"></param>
  1586. /// <param name="cmd"></param>
  1587. public static void RTPurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1588. {
  1589. try
  1590. {
  1591. #region ERP
  1592. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1593. INTO #NewTempERP
  1594. from ICSWareHouseLotInfoLog
  1595. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '3'
  1596. SELECT y.VenCode+a.FromWarehouseCode+y.DNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.DNCode,y.DNDetailID,a.InvCode) AS Sequence,z.Sequence AS srcDocPOLineNo,y.PODetailID,z.DNCode AS POCode,y.DepCode,
  1597. 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.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1598. ,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,
  1599. 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
  1600. INTO #TempERP
  1601. FROM #NewTempERP a
  1602. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1603. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1604. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1605. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1606. INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  1607. INNER JOIN ICSDeliveryNotice z ON z.Sequence=y.PoDetailID AND z.DNCode=y.POID AND a.WorkPoint=y.WorkPoint
  1608. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1609. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1610. GROUP BY y.DepCode,z.Sequence,y.PODetailID,z.DNCode,inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conStock.Enable
  1611. ,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, ''),
  1612. 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, '')
  1613. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,'' AS DocType,MUSER AS [User],SYSDATETIME() AS MTime,SYSDATETIME() AS DocDate,SYSDATETIME() AS ArrDate FROM #TempERP
  1614. SELECT Costre,Sequence,InvCode,srcDocPOLineNo,Quantity,Amount,UnitPrice,Currency,PODetailID,ProjectCode,BatchCode,WarehouseCode AS WhCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1615. FROM #TempERP
  1616. DROP TABLE #TempERP
  1617. DROP TABLE #NewTempERP";
  1618. sql = string.Format(sql, Identification);
  1619. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1620. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1621. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.RTPurchaseReturnBackURL, Inputstr);
  1622. Result result = new Result();
  1623. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1624. if (result.Success)
  1625. {
  1626. try
  1627. {
  1628. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1629. foreach (var item in res)
  1630. {
  1631. JObject jo = (JObject)item;
  1632. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1633. foreach (var detail in resdetail)
  1634. {
  1635. JObject det = (JObject)detail;
  1636. 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()
  1637. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1638. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1639. det["DetailID"].ToString(), jo["RCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1640. }
  1641. }
  1642. }
  1643. catch (Exception ex)
  1644. {
  1645. log.Debug(ex.ToString());
  1646. log.Debug(resultStr);
  1647. }
  1648. }
  1649. else
  1650. {
  1651. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1652. }
  1653. #endregion
  1654. }
  1655. catch (Exception)
  1656. {
  1657. throw;
  1658. }
  1659. }
  1660. #endregion
  1661. #region 采购退货-采购订单
  1662. /// <summary>
  1663. /// 采购退货-采购订单
  1664. /// </summary>
  1665. /// <param name="TransCode"></param>
  1666. /// <param name="TransSequence"></param>
  1667. /// <param name="Quantity"></param>
  1668. /// <param name="WorkPoint"></param>
  1669. /// <param name="cmd"></param>
  1670. public static void PurchaseReceiveDoctNegativePo(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language, string TransID)
  1671. {
  1672. try
  1673. {
  1674. string sql = "";
  1675. sql = @"DECLARE @Status VARCHAR(10)
  1676. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='1' AND WorkPoint='{1}' and ID='{4}'
  1677. IF (@Status IS NULL)
  1678. BEGIN
  1679. RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
  1680. RETURN
  1681. END
  1682. ELSE IF (@Status!='2')
  1683. BEGIN
  1684. RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
  1685. RETURN
  1686. END
  1687. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)-'{2}'
  1688. FROM ICSDeliveryNotice a
  1689. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.ID='{4}' AND a.WorkPoint='{1}' AND DNType='1'
  1690. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
  1691. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' and a.ID='{4}' AND a.RCVQuantity<0 AND DNType='1')
  1692. BEGIN
  1693. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  1694. RETURN
  1695. END
  1696. --退 eattribute9 = 2 退
  1697. IF EXISTS(SELECT b.ID FROM ICSDeliveryNotice a inner join icsPurchaseOrder b on a.poID = b.poid and a.PODetailID = b.PODetailID
  1698. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.eattribute9='2' AND DNType='2')
  1699. BEGIN
  1700. UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}'
  1701. FROM icsPurchaseOrder b inner join ICSDeliveryNotice a on a.poID = b.poid and a.PODetailID = b.PODetailID
  1702. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  1703. END
  1704. ";
  1705. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  1706. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1707. {
  1708. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  1709. }
  1710. }
  1711. catch (Exception)
  1712. {
  1713. throw;
  1714. }
  1715. }
  1716. public static void PurchaseReceiveDoctNegativePoERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  1717. {
  1718. try
  1719. {
  1720. #region ERP
  1721. string sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1722. INTO #NewTempERP
  1723. from ICSWareHouseLotInfoLog
  1724. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '3'
  1725. SELECT y.VenCode+a.FromWarehouseCode+y.DNCode+a.MUSER AS Costre,y.VenCode,a.FromWarehouseCode AS WarehouseCode,y.DNCode,a.MUSER,ROW_NUMBER() OVER (ORDER BY y.VenCode,a.FromWarehouseCode,y.DNCode,y.DNDetailID,a.InvCode) AS Sequence,conWhCode.Enable AS ErpWhCode,
  1726. 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.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0) AS UnitPrice,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock
  1727. ,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,
  1728. 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
  1729. INTO #TempERP
  1730. FROM #NewTempERP a
  1731. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1732. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1733. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1734. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1735. INNER JOIN ICSDeliveryNotice y ON a.TransCode=y.DNCode AND a.TransSequence=y.Sequence AND a.WorkPoint=y.WorkPoint
  1736. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1737. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock002' AND a.WorkPoint=conStock.WorkPoint
  1738. INNER JOIN ICSConfiguration conWhCode ON conWhCode.Code='ERPWHCode' AND a.WorkPoint=conWhCode.WorkPoint
  1739. GROUP BY conWhCode.Enable,inv.AmountEnable,y.VenCode,a.FromWarehouseCode,y.DNCode,a.MUSER,a.InvCode,y.DNDetailID,y.Currency,ISNULL(y.UnitPrice, 0),con.Enable,conStock.Enable
  1740. ,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, ''),
  1741. 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, '')
  1742. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,DNCode AS POCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,UpdateStock FROM #TempERP
  1743. SELECT Costre,Sequence,InvCode,Quantity,Amount,CASE WHEN isnull(ErpWhCode,0)='1' then WarehouseCode ELSE '' END AS WHCode,DNDetailID AS PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  1744. FROM #TempERP
  1745. DROP TABLE #TempERP
  1746. DROP TABLE #NewTempERP";
  1747. sql = string.Format(sql, Identification);
  1748. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  1749. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  1750. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReturnBackPoURL, Inputstr);
  1751. Result result = new Result();
  1752. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1753. if (result.Success)
  1754. {
  1755. try
  1756. {
  1757. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  1758. foreach (var item in res)
  1759. {
  1760. JObject jo = (JObject)item;
  1761. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  1762. foreach (var detail in resdetail)
  1763. {
  1764. JObject det = (JObject)detail;
  1765. 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()
  1766. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  1767. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNRTDetailID"].ToString(), Identification, jo["ID"].ToString(),
  1768. det["DetailID"].ToString(), jo["RCVNEGCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  1769. }
  1770. }
  1771. }
  1772. catch (Exception ex)
  1773. {
  1774. log.Debug(ex.ToString());
  1775. log.Debug(resultStr);
  1776. }
  1777. }
  1778. else
  1779. {
  1780. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1781. }
  1782. #endregion
  1783. }
  1784. catch (Exception)
  1785. {
  1786. throw;
  1787. }
  1788. }
  1789. #endregion
  1790. #region 开立红字入库
  1791. /// <summary>
  1792. /// 开立红字入库
  1793. /// </summary>
  1794. /// <param name="TransCode"></param>
  1795. /// <param name="TransSequence"></param>
  1796. /// <param name="Quantity"></param>
  1797. /// <param name="WorkPoint"></param>
  1798. /// <param name="cmd"></param>
  1799. public static void PurchaseReceive(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language,string TransID)
  1800. {
  1801. try
  1802. {
  1803. string sql = string.Empty;
  1804. if (string.IsNullOrWhiteSpace(TransID))
  1805. {
  1806. sql = @"DECLARE @Status VARCHAR(10)
  1807. SELECT @Status=a.Status FROM ICSPurchaseReceive a
  1808. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1809. IF (@Status IS NULL)
  1810. BEGIN
  1811. RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1);
  1812. RETURN
  1813. END
  1814. ELSE IF (@Status!='1')
  1815. BEGIN
  1816. RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
  1817. RETURN
  1818. END
  1819. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1820. FROM ICSPurchaseReceive a
  1821. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  1822. IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a
  1823. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  1824. BEGIN
  1825. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1826. RETURN
  1827. END
  1828. --退 eattribute9 = 2 退 (退id与采购订单erpid一致)
  1829. IF EXISTS(SELECT b.ID FROM ICSPurchaseReceive a inner join icsPurchaseOrder b on a.rcvid = b.poid and a.rcvdetailID = b.PODetailID
  1830. WHERE a.rcvcode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND Type='2')
  1831. BEGIN
  1832. UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}'
  1833. FROM icsPurchaseOrder b inner join ICSPurchaseReceive a on a.rcvid = b.poid and a.rcvdetailID = b.PODetailID
  1834. WHERE a.rcvcode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND Type='2'
  1835. END
  1836. ";
  1837. }
  1838. else
  1839. {
  1840. sql = @"DECLARE @Status VARCHAR(10)
  1841. SELECT @Status=a.Status FROM ICSPurchaseReceive a
  1842. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2'
  1843. IF (@Status IS NULL)
  1844. BEGIN
  1845. RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1);
  1846. RETURN
  1847. END
  1848. ELSE IF (@Status!='1')
  1849. BEGIN
  1850. RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
  1851. RETURN
  1852. END
  1853. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  1854. FROM ICSPurchaseReceive a
  1855. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' and a.id='{4}' AND a.Type='2'
  1856. IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a
  1857. 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)
  1858. BEGIN
  1859. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  1860. RETURN
  1861. END
  1862. --退 eattribute9 = 2 退 (退id与采购订单erpid一致)
  1863. IF EXISTS(SELECT b.ID FROM ICSPurchaseReceive a inner join icsPurchaseOrder b on a.rcvid = b.poid and a.rcvdetailID = b.PODetailID
  1864. WHERE a.rcvcode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND Type='2')
  1865. BEGIN
  1866. UPDATE b SET Inquantity=ISNULL(b.Inquantity,0)-'{2}'
  1867. FROM icsPurchaseOrder b inner join ICSPurchaseReceive a on a.rcvid = b.poid and a.rcvdetailID = b.PODetailID
  1868. WHERE a.rcvcode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND Type='2'
  1869. END
  1870. ";
  1871. }
  1872. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence, TransID);
  1873. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1874. {
  1875. throw new Exception(language.GetNameByCode("WMSAPIInfo092"));//"红字入库单更新失败!");
  1876. }
  1877. }
  1878. catch (Exception)
  1879. {
  1880. throw;
  1881. }
  1882. }
  1883. /// <summary>
  1884. /// 开立红字入库接口
  1885. /// </summary>
  1886. /// <param name="TransType"></param>
  1887. /// <param name="Identification"></param>
  1888. /// <param name="cmd"></param>
  1889. public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language,string BusinessCode)
  1890. {
  1891. try
  1892. {
  1893. string sql = string.Empty;
  1894. if (DBHelper.IsPNU9())
  1895. {
  1896. #region ERP开立状态单据审核
  1897. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1898. INTO #NewTempERP
  1899. from ICSWareHouseLotInfoLog
  1900. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '4'
  1901. SELECT b.RCVCode AS RCVTCode,b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1902. FROM #NewTempERP a
  1903. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1904. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1905. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1906. GROUP BY b.RCVCode,b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1907. DROP TABLE #NewTempERP";
  1908. sql = string.Format(sql, Identification);
  1909. //DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1910. //string Inputstr = JsonConvert.SerializeObject(dt);
  1911. string checksql = @"select SUM(b.Quantity) AS SUMQty,SUM(b.RCVQuantity) AS ISSQty,a.transCode from ICSPurchaseReceive b inner join ICSWareHouseLotInfoLog a ON a.TransCode=b.RCVCode AND a.WorkPoint=b.WorkPoint
  1912. where a.Identification='{0}' AND a.BusinessCode = '4' GROUP BY a.transCode";
  1913. checksql = string.Format(checksql, Identification);
  1914. DataTable chekdt = DBHelper.SQlReturnData(checksql, cmd);
  1915. decimal SUMQty = Convert.ToDecimal(chekdt.Rows[0]["SUMQty"]);
  1916. decimal ISSQty = Convert.ToDecimal(chekdt.Rows[0]["ISSQty"]);
  1917. string trancode = chekdt.Rows[0]["transCode"].ToString();
  1918. if (SUMQty - ISSQty == 0)
  1919. {
  1920. string pnsql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1921. INTO #NewTempERP
  1922. from ICSWareHouseLotInfoLog
  1923. WHERE TransCode='{0}' AND ERPUpload='0' AND BusinessCode = '4'
  1924. SELECT b.RCVCode AS RCVTCode,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  1925. FROM #NewTempERP a
  1926. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1927. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1928. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1929. GROUP BY b.RCVCode,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint
  1930. DROP TABLE #NewTempERP";
  1931. pnsql = string.Format(pnsql, trancode);
  1932. DataTable dt = DBHelper.SQlReturnData(pnsql, cmd);
  1933. string Inputstr = JsonConvert.SerializeObject(dt);
  1934. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr);
  1935. Result result = new Result();
  1936. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1937. if (result.Success)
  1938. {
  1939. try
  1940. {
  1941. foreach (DataRow dr in dt.Rows)
  1942. {
  1943. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1944. }
  1945. }
  1946. catch (Exception ex)
  1947. {
  1948. log.Debug(ex.ToString());
  1949. log.Debug(resultStr);
  1950. }
  1951. }
  1952. else
  1953. {
  1954. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  1955. }
  1956. }
  1957. #endregion
  1958. }
  1959. else
  1960. {
  1961. #region ERP开立状态单据审核
  1962. sql = @"select LotNo,WorkPoint,InvCode,ToWarehouseCode,MUSER,Quantity,TransCode,TransSequence,FromWarehouseCode
  1963. INTO #NewTempERP
  1964. from ICSWareHouseLotInfoLog
  1965. WHERE Identification='{0}' AND ERPUpload='0' AND BusinessCode = '4'
  1966. IF EXISTS(SELECT b.id FROM ICSPurchaseReceive b where rcvcode in
  1967. (select DISTINCT TransCode from ICSWareHouseLotInfoLog where Identification='{0}') and b.Quantity!=b.RCVQuantity)
  1968. BEGIN
  1969. RAISERROR('" + language.GetNameByCode("WMSAPIInfo093") + @"',16,1);
  1970. RETURN
  1971. END
  1972. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint,b.RCVCode as RCVTCode
  1973. FROM #NewTempERP a
  1974. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  1975. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  1976. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  1977. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint,b.RCVCode
  1978. DROP TABLE #NewTempERP";
  1979. sql = string.Format(sql, Identification);
  1980. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1981. string Inputstr = JsonConvert.SerializeObject(dt);
  1982. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr);
  1983. Result result = new Result();
  1984. result = JsonConvert.DeserializeObject<Result>(resultStr);
  1985. if (result.Success)
  1986. {
  1987. try
  1988. {
  1989. foreach (DataRow dr in dt.Rows)
  1990. {
  1991. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  1992. }
  1993. }
  1994. catch (Exception ex)
  1995. {
  1996. log.Debug(ex.ToString());
  1997. log.Debug(resultStr);
  1998. }
  1999. }
  2000. else
  2001. {
  2002. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  2003. }
  2004. #endregion
  2005. }
  2006. }
  2007. catch (Exception)
  2008. {
  2009. throw;
  2010. }
  2011. }
  2012. #endregion
  2013. #region 获取生成拒收单的数据
  2014. public static List<ICSDeliveryNotice> GetPoRefuseMsg(LOTStockUpCreateIModel model, SqlCommand cmd)
  2015. {
  2016. try
  2017. {
  2018. StringBuilder lotSb = new StringBuilder();
  2019. foreach (var det in model.detail)
  2020. {
  2021. if (lotSb.Length > 0)
  2022. lotSb = lotSb.Append(",");
  2023. lotSb = lotSb.Append("'").Append(det.LotNo).Append("'");
  2024. }
  2025. string sql = string.Format(@"select distinct a.VenCode,a.DNID,a.DepCode,a.DNCode,a.WorkPoint,'{1}' AS [User] from ICSDeliveryNotice a
  2026. inner join ICSASNDetail b on a.ASNCode=b.ASNCode AND b.WorkPoint=a.WorkPoint
  2027. left join dbo.ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint AND c.ExtensionID=a.ExtensionID
  2028. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2029. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2030. WHERE b.LotNo IN ({0})
  2031. select distinct c.InvCode,d.UnqualifiedQuantity-d.WaiveQuantity as Quantity,isnull(c.Amount,0) as Amount,a.Currency,isnull(a.UnitPrice,0) as UnitPrice,DNDetailID,DNID,b.LotNo
  2032. from ICSDeliveryNotice a
  2033. left join ICSASNDetail b on a.ASNCode=b.ASNCode and a.WorkPoint=b.WorkPoint
  2034. left join ICSInventoryLot c on b.LotNo=c.LotNo and a.InvCode=c.InvCode and b.WorkPoint=c.WorkPoint
  2035. left join ICSInventoryLotDetail e on c.LotNo=e.LotNo and c.WorkPoint=e.WorkPoint
  2036. inner JOIN ICSPurchaseOrder l ON e.TransCode =l.POCode AND e.TransSequence=l.Sequence AND a.PODetailID=l.PODetailID AND c.WorkPoint=l.WorkPoint
  2037. left join ICSInspection d on b.LotNo=d.LotNo and b.WorkPoint=d.WorkPoint AND d.Enable='1'
  2038. WHERE b.LotNo in ({0})", lotSb, model.User);
  2039. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  2040. string jsonStr = DataToJsonHelper.DataSetToJson(ds, "detail", "DNID");
  2041. List<ICSDeliveryNotice> list = JsonConvert.DeserializeObject<List<ICSDeliveryNotice>>(jsonStr);
  2042. foreach(ICSDeliveryNotice item in list)
  2043. {
  2044. for(int i = 0;i < item.detail.Count;i++)
  2045. {
  2046. var det = item.detail[i];
  2047. det.Sequence = "" + (i + 1);
  2048. foreach (var modelDet in model.detail)
  2049. {
  2050. if (modelDet.LotNo == det.LotNo)
  2051. {
  2052. det.Quantity = modelDet.BadQty.ToString();
  2053. break;
  2054. }
  2055. }
  2056. }
  2057. }
  2058. return list;
  2059. }
  2060. catch
  2061. {
  2062. throw;
  2063. }
  2064. }
  2065. #endregion
  2066. }
  2067. }