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.

2024 lines
142 KiB

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