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.

2349 lines
162 KiB

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