纽威
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.

1059 lines
63 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years 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 = @"SELECT a.VenCode+a.DepCode+y.POCode+a.MUSER AS Costre,a.VenCode,a.DepCode,y.POCode,a.MUSER,a.MTIME,
  35. a.Sequence,a.InvCode,a.Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.PODetailID
  36. ,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,
  37. 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
  38. INTO #TempERP
  39. FROM ICSDeliveryNotice a
  40. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  41. LEFT JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  42. INNER JOIN ICSPurchaseOrder y ON a.PODetailID=y.PODetailID AND a.WorkPoint=y.WorkPoint
  43. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  44. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,POCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  45. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,PODetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  46. FROM #TempERP
  47. DROP TABLE #TempERP";
  48. sql = string.Format(sql, DNCode, WorkPoint);
  49. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  50. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  51. string resultStr = HTTPHelper.HttpPost("采购到货", ERPUrl.CreatePOArrivURL, Inputstr);
  52. Result result = new Result();
  53. result = JsonConvert.DeserializeObject<Result>(resultStr);
  54. if (result.Success)
  55. {
  56. try
  57. {
  58. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  59. foreach (var item in res)
  60. {
  61. JObject jo = (JObject)item;
  62. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  63. foreach (var detail in resdetail)
  64. {
  65. JObject det = (JObject)detail;
  66. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  67. where PODetailID='{4}' AND DNType='1' AND DNCode='{5}' ";
  68. ERPupdate = string.Format(ERPupdate, jo["DNCode"], det["Sequence"], jo["ID"], det["DetailID"], det["PODetailID"], DNCode);
  69. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  70. {
  71. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  72. }
  73. }
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. log.Debug(ex.ToString());
  79. log.Debug(resultStr);
  80. }
  81. }
  82. else
  83. {
  84. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  85. }
  86. #endregion
  87. }
  88. catch (Exception)
  89. {
  90. throw;
  91. }
  92. }
  93. #endregion
  94. #region 采购入库
  95. /// <summary>
  96. /// 采购入库
  97. /// </summary>
  98. /// <param name="TransCode"></param>
  99. /// <param name="TransSequence"></param>
  100. /// <param name="Quantity"></param>
  101. /// <param name="WorkPoint"></param>
  102. /// <param name="cmd"></param>
  103. public static void PurchaseReceiveDoc(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  104. {
  105. try
  106. {
  107. string sql = @"DECLARE @Status VARCHAR(10)
  108. SELECT @Status=c.Status FROM ICSInventoryLot a
  109. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  110. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  111. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  112. IF (@Status IS NULL)
  113. BEGIN
  114. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  115. RETURN
  116. END
  117. ELSE IF (@Status='3')
  118. BEGIN
  119. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  120. RETURN
  121. END
  122. UPDATE c SET InQuantity=ISNULL(InQuantity,0)+'{2}'
  123. FROM ICSInventoryLot a
  124. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  125. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  126. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  127. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  128. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  129. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  130. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.Quantity<c.InQuantity)
  131. BEGIN
  132. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  133. END";
  134. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  135. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  136. {
  137. throw new Exception(language.GetNameByCode("WMSAPIInfo104"));//"采购入库单更新失败!");
  138. }
  139. }
  140. catch (Exception)
  141. {
  142. throw;
  143. }
  144. }
  145. /// <summary>
  146. /// 采购入库接口
  147. /// </summary>
  148. /// <param name="TransType"></param>
  149. /// <param name="Identification"></param>
  150. /// <param name="cmd"></param>
  151. public static void PurchaseReceiveDocERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  152. {
  153. try
  154. {
  155. #region ERP
  156. string sql = @"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,
  157. a.InvCode,SUM(a.Quantity) AS Quantity,SUM(a.Quantity*(lot.Amount/lot.Quantity)) AS Amount,isnull((c.UnitPrice),0) as UnitPrice,c.Currency,c.PODetailID,con.Enable AS UpdateTodoQuantity,conn.Enable
  158. ,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,
  159. 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
  160. INTO #TempERP
  161. FROM ICSWareHouseLotInfoLog a
  162. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  163. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  164. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  165. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  166. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  167. INNER JOIN ICSASNDetail g ON a.LotNo=g.LotNo AND a.WorkPoint=g.WorkPoint
  168. INNER JOIN ICSDeliveryNotice f ON g.ASNCode=f.ASNCode AND g.WorkPoint=f.WorkPoint
  169. INNER JOIN ICSPurchaseOrder c ON b.TransCode=c.POCode AND b.TransSequence=c.Sequence AND f.PODetailID=c.PODetailID AND b.WorkPoint=c.WorkPoint
  170. INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  171. INNER JOIN ICSConfiguration conn ON con.WorkPoint=conn.WorkPoint AND conn.Code='Escrow001'
  172. WHERE a.Identification='{0}' AND ERPUpload='0' AND BusinessCode='{1}'
  173. GROUP BY 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
  174. ,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, ''),
  175. 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, '')
  176. SELECT DISTINCT Costre,WorkPoint,VenCode,WarehouseCode AS WHCode,POCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,Enable,UpdateTodoQuantity FROM #TempERP
  177. SELECT Costre,Sequence,DNSequence,InvCode,Quantity,Amount,PODetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  178. FROM #TempERP
  179. SELECT HasDN FROM #TempERP
  180. DROP TABLE #TempERP";
  181. sql = string.Format(sql, Identification, BusinessCode);
  182. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  183. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "details", "Costre");
  184. var IsDNCode = ds.Tables[2];
  185. if (IsDNCode == null || IsDNCode.Rows.Count != 1)
  186. {
  187. throw new Exception(language.GetNameByCode("WMSAPIInfo463"));//ERP到货单只能选择启用或不启用中的一种!
  188. }
  189. string dncode = Convert.ToString(IsDNCode.Rows[0]["HasDN"]);
  190. if (dncode.Equals(""))
  191. {
  192. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.DeliveryNoticeURL, Inputstr);
  193. Result result = new Result();
  194. result = JsonConvert.DeserializeObject<Result>(resultStr);
  195. if (result.Success)
  196. {
  197. try
  198. {
  199. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  200. foreach (var item in res)
  201. {
  202. JObject jo = (JObject)item;
  203. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  204. foreach (var detail in resdetail)
  205. {
  206. JObject det = (JObject)detail;
  207. 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()
  208. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  209. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(),
  210. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  211. }
  212. }
  213. }
  214. catch (Exception ex)
  215. {
  216. log.Debug(ex.ToString());
  217. log.Debug(resultStr);
  218. }
  219. }
  220. else
  221. {
  222. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  223. }
  224. }
  225. else
  226. {
  227. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseOrderURL, Inputstr);
  228. Result result = new Result();
  229. result = JsonConvert.DeserializeObject<Result>(resultStr);
  230. if (result.Success)
  231. {
  232. try
  233. {
  234. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  235. foreach (var item in res)
  236. {
  237. JObject jo = (JObject)item;
  238. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  239. foreach (var detail in resdetail)
  240. {
  241. JObject det = (JObject)detail;
  242. 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()
  243. + det["cFree6"].ToString() + det["cFree7"].ToString() + det["cFree8"].ToString() + det["cFree9"].ToString() + det["cFree10"].ToString();
  244. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["PODetailID"].ToString(), Identification, jo["ID"].ToString(),
  245. det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), allcol, cmd, language, BusinessCode);
  246. }
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. log.Debug(ex.ToString());
  252. log.Debug(resultStr);
  253. }
  254. }
  255. else
  256. {
  257. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  258. }
  259. }
  260. #endregion
  261. }
  262. catch (Exception)
  263. {
  264. throw;
  265. }
  266. }
  267. #endregion
  268. /// <summary>
  269. /// 审核的到货单(货柜)
  270. /// </summary>
  271. /// <param name="TransCode"></param>
  272. /// <param name="TransSequence"></param>
  273. /// <param name="Quantity"></param>
  274. /// <param name="WorkPoint"></param>
  275. /// <param name="cmd"></param>
  276. public static void DeliveryNoticeInForHG(string DocNO, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  277. {
  278. try
  279. {
  280. string sql = @" UPDATE ICSDeliveryNotice set RCVQuantity=Quantity
  281. Where DNCode='{0}' and WorkPoint='{1}'";
  282. sql = string.Format(sql, DocNO, WorkPoint);
  283. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  284. {
  285. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  286. }
  287. }
  288. catch (Exception)
  289. {
  290. throw;
  291. }
  292. }
  293. #region 审核的到货单
  294. /// <summary>
  295. /// 审核的到货单
  296. /// </summary>
  297. /// <param name="TransCode"></param>
  298. /// <param name="TransSequence"></param>
  299. /// <param name="Quantity"></param>
  300. /// <param name="WorkPoint"></param>
  301. /// <param name="cmd"></param>
  302. public static void DeliveryNoticeIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  303. {
  304. try
  305. {
  306. string sql = @"DECLARE @Status VARCHAR(10)
  307. SELECT @Status=c.Status FROM ICSInventoryLot a
  308. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  309. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  310. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  311. IF (@Status IS NULL)
  312. BEGIN
  313. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  314. RETURN
  315. END
  316. ELSE IF (@Status='3')
  317. BEGIN
  318. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  319. RETURN
  320. END
  321. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  322. FROM ICSInventoryLot a
  323. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  324. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  325. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  326. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  327. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  328. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  329. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND c.Quantity<c.RCVQuantity)
  330. BEGIN
  331. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  332. END";
  333. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  334. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  335. {
  336. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  337. }
  338. }
  339. catch (Exception)
  340. {
  341. throw;
  342. }
  343. }
  344. /// <summary>
  345. /// 审核的到货单接口
  346. /// </summary>
  347. /// <param name="TransType"></param>
  348. /// <param name="Identification"></param>
  349. /// <param name="cmd"></param>
  350. public static void DeliveryNoticeInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  351. {
  352. try
  353. {
  354. #region SAP(检验合格单为两层结构 一行对应一个序列号)
  355. string IsSuccess = "";
  356. string ErrorMessage = "";
  357. string sql = @" select Distinct A.DNCode,A.WorkPoint from ICSDeliveryNotice A
  358. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.DNCode AND B.WorkPoint=A.WorkPoint
  359. where B.Identification='{0}' AND BusinessCode='2'";
  360. sql = string.Format(sql, Identification);
  361. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  362. if (dt.Rows.Count > 1)
  363. {
  364. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  365. }
  366. for (int i = 0; i < dt.Rows.Count; i++)
  367. {
  368. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  369. where DNCode='{0}' and WorkPoint='{1}'
  370. GROUP BY DNCode,WorkPoint";
  371. chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  372. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  373. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) != Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  374. {
  375. return;
  376. }
  377. sql = @"select A.DNCode,SUM(A.RCVQuantity) AS RCVQuantity,B.BatchCode from ICSDeliveryNotice A
  378. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  379. WHERE DNCode='{0}' AND A.WorkPoint='{1}'
  380. GROUP BY A.DNCode,B.BatchCode";
  381. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  382. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  383. if (Sapdt.Rows.Count == 0)
  384. {
  385. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo205"), dt.Rows[i]["DNCode"].ToString()));//单据查询失败
  386. }
  387. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU Client = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU();
  388. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1 Info = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKU1();
  389. Info.NEWID = Identification;
  390. Info.PRUEFLOS = Sapdt.Rows[0]["DNCode"].ToString();
  391. Info.L_LME = System.Decimal.Round(Convert.ToDecimal(Sapdt.Rows[0]["RCVQuantity"].ToString()), 3);
  392. Info.SERNP = Sapdt.Rows[0]["BatchCode"].ToString();
  393. Info.Z_GERNR = new SAPCallBackJYHGDVPN.ZWEBS_GERNR[0];
  394. SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse result = new SAPCallBackJYHGDVPN.ZWMS_SK_WS_RUKUResponse();
  395. result = Client.CallZWMS_SK_WS_RUKU(Info);
  396. if (result.Z_NULL == "N")
  397. {
  398. ErrorMessage += result.L_MESSAGE;
  399. }
  400. }
  401. if (IsSuccess == "N")
  402. {
  403. throw new Exception(ErrorMessage);
  404. }
  405. #endregion
  406. }
  407. catch (Exception)
  408. {
  409. throw;
  410. }
  411. }
  412. #endregion
  413. #region 叉车采购入库
  414. /// <summary>
  415. /// 叉车采购入库
  416. /// </summary>
  417. /// <param name="TransCode"></param>
  418. /// <param name="TransSequence"></param>
  419. /// <param name="Quantity"></param>
  420. /// <param name="WorkPoint"></param>
  421. /// <param name="cmd"></param>
  422. public static void DeliveryNoticeForkLift(string ContainerCode, SqlCommand cmd, Dictionary<string, string> language)
  423. {
  424. try
  425. {
  426. string lotsql = @" select A.LotNo,C.Quantity,B.WorkPoint from ICSContainerLot A
  427. LEFT JOIN ICSContainer B ON B.ID=A.ContainerID AND B.WorkPoint=A.WorkPoint
  428. LEFT JOIN ICSInventoryLot C ON C.LotNo=A.LotNo AND C.WorkPoint=A.WorkPoint
  429. where B.ContainerCode='{0}'";
  430. lotsql = string.Format(lotsql, ContainerCode);
  431. DataTable lotdt = DBHelper.SQlReturnData(lotsql, cmd);
  432. if (lotdt.Rows.Count == 0)
  433. {
  434. throw new Exception("托盘号不存在或者尚未绑定条码!");
  435. }
  436. foreach (DataRow dr in lotdt.Rows)
  437. {
  438. string sql = @" UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  439. FROM ICSInventoryLot a
  440. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  441. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  442. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1'
  443. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  444. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  445. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  446. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='1' AND c.Quantity<c.RCVQuantity)
  447. BEGIN
  448. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  449. END";
  450. sql = string.Format(sql, dr["LotNo"].ToString(), dr["WorkPoint"].ToString(), dr["Quantity"].ToString());
  451. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  452. {
  453. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  454. }
  455. }
  456. }
  457. catch (Exception)
  458. {
  459. throw;
  460. }
  461. }
  462. #endregion
  463. #region 采购拒收
  464. /// <summary>
  465. /// 采购拒收
  466. /// </summary>
  467. /// <param name="TransCode"></param>
  468. /// <param name="TransSequence"></param>
  469. /// <param name="Quantity"></param>
  470. /// <param name="WorkPoint"></param>
  471. /// <param name="cmd"></param>
  472. public static void PurchaseRejectDocIn(string LotNo, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  473. {
  474. try
  475. {
  476. string sql = @"DECLARE @Status VARCHAR(10)
  477. SELECT @Status=c.Status FROM ICSInventoryLot a
  478. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  479. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  480. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  481. IF (@Status IS NULL)
  482. BEGIN
  483. RAISERROR('" + language.GetNameByCode("WMSAPIInfo081") + @"',16,1);
  484. RETURN
  485. END
  486. ELSE IF (@Status='3')
  487. BEGIN
  488. RAISERROR('" + language.GetNameByCode("WMSAPIInfo082") + @"',16,1);
  489. RETURN
  490. END
  491. UPDATE c SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  492. FROM ICSInventoryLot a
  493. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  494. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  495. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3'
  496. IF EXISTS(SELECT a.LotNo FROM ICSInventoryLot a
  497. INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  498. INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  499. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' AND c.DNType='3' AND c.Quantity<c.RCVQuantity)
  500. BEGIN
  501. RAISERROR('" + language.GetNameByCode("WMSAPIInfo083") + @"',16,1);
  502. END";
  503. sql = string.Format(sql, LotNo, WorkPoint, Quantity);
  504. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  505. {
  506. throw new Exception(language.GetNameByCode("WMSAPIInfo084"));//"拒收单更新失败!");
  507. }
  508. }
  509. catch (Exception)
  510. {
  511. throw;
  512. }
  513. }
  514. /// <summary>
  515. /// 采购拒收接口
  516. /// </summary>
  517. /// <param name="TransType"></param>
  518. /// <param name="Identification"></param>
  519. /// <param name="cmd"></param>
  520. public static void PurchaseRejectDocInNewERP(string DNCode, string JDNCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  521. {
  522. //try
  523. //{
  524. // #region ERP
  525. // 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,
  526. // 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
  527. // ,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,
  528. // 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
  529. // INTO #TempERP
  530. // FROM ICSWareHouseLotInfoLog a
  531. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  532. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  533. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  534. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  535. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  536. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  537. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  538. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  539. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  540. // WHERE a.Identification='{0}' AND ERPUpload='0'
  541. // 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
  542. // ,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, ''),
  543. // 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, '')
  544. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  545. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  546. // FROM #TempERP
  547. // DROP TABLE #TempERP";
  548. // sql = string.Format(sql, Identification);
  549. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  550. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  551. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  552. // Result result = new Result();
  553. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  554. // if (result.Success)
  555. // {
  556. // try
  557. // {
  558. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  559. // foreach (var item in res)
  560. // {
  561. // JObject jo = (JObject)item;
  562. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  563. // foreach (var detail in resdetail)
  564. // {
  565. // JObject det = (JObject)detail;
  566. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  567. // }
  568. // }
  569. // }
  570. // catch (Exception ex)
  571. // {
  572. // log.Debug(ex.ToString());
  573. // log.Debug(resultStr);
  574. // }
  575. // }
  576. // else
  577. // {
  578. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  579. // }
  580. // #endregion
  581. //}
  582. //catch (Exception)
  583. //{
  584. // throw;
  585. //}
  586. try
  587. {
  588. #region ERP
  589. string sql = @"SELECT a.VenCode+a.DepCode+a.DNCode+a.MUSER AS Costre,a.VenCode,a.DepCode,a.DNCode,a.MUSER,a.MTIME,
  590. a.Sequence,a.InvCode,Sum(x.Quantity) AS Quantity,a.Amount,ISNULL(a.UnitPrice,0) AS UnitPrice,a.Currency,a.DNDetailID
  591. ,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,
  592. 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
  593. INTO #TempERP
  594. FROM ICSDeliveryNotice a
  595. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  596. INNER JOIN ICSInventory invBat ON a.InvCode=invBat.InvCode AND a.WorkPoint=invBat.WorkPoint
  597. INNER JOIN ICSDeliveryNotice x ON a.DNDetailID=x.PODetailID AND a.WorkPoint=x.WorkPoint
  598. WHERE a.DNCode='{0}' AND a.WorkPoint='{1}'
  599. GROUP BY a.VenCode,a.DepCode,a.DNCode,a.MUSER,a.MTIME,a.Sequence,a.InvCode,a.Amount,a.Quantity,a.UnitPrice,a.Currency,a.DNDetailID,
  600. a.WorkPoint,ISNULL(ext.ProjectCode, ''),ISNULL(invBat.BatchEnable, ''),ISNULL(ext.BatchCode, ''),ISNULL(ext.Version, ''),ISNULL(ext.Brand, ''),
  601. 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, '')
  602. SELECT DISTINCT Costre,WorkPoint,VenCode,DepCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime FROM #TempERP
  603. SELECT Costre,Sequence,InvCode,Quantity,Amount,UnitPrice,Currency,DNDetailID,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  604. FROM #TempERP
  605. DROP TABLE #TempERP";
  606. sql = string.Format(sql, DNCode, WorkPoint);
  607. DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  608. string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  609. string resultStr = HTTPHelper.HttpPost("采购拒收", ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  610. Result result = new Result();
  611. result = JsonConvert.DeserializeObject<Result>(resultStr);
  612. if (result.Success)
  613. {
  614. try
  615. {
  616. JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  617. foreach (var item in res)
  618. {
  619. JObject jo = (JObject)item;
  620. JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  621. foreach (var detail in resdetail)
  622. {
  623. JObject det = (JObject)detail;
  624. //ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RJTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  625. string ERPupdate = @"update ICSDeliveryNotice set DNCode='{0}',Sequence='{1}',DNID='{2}',DNDetailID='{3}'
  626. where PODetailID='{4}' AND DNType='3' AND DNCode='{5}' ";
  627. ERPupdate = string.Format(ERPupdate, jo["RJTCode"], det["Sequence"], jo["ID"], det["DetailID"], det["DNDetailID"], JDNCode);
  628. if (!DBHelper.ExecuteNonQuery(ERPupdate, cmd))
  629. {
  630. throw new Exception(language.GetNameByCode("WMSAPIInfo079"));//"到货单更新失败!");
  631. }
  632. }
  633. }
  634. }
  635. catch (Exception ex)
  636. {
  637. log.Debug(ex.ToString());
  638. log.Debug(resultStr);
  639. }
  640. }
  641. else
  642. {
  643. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  644. }
  645. #endregion
  646. }
  647. catch (Exception)
  648. {
  649. throw;
  650. }
  651. }
  652. /// <summary>
  653. /// 采购拒收接口
  654. /// </summary>
  655. /// <param name="TransType"></param>
  656. /// <param name="Identification"></param>
  657. /// <param name="cmd"></param>
  658. public static void PurchaseRejectDocInERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  659. {
  660. //try
  661. //{
  662. // #region ERP
  663. // 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,
  664. // 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
  665. // ,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,
  666. // 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
  667. // INTO #TempERP
  668. // FROM ICSWareHouseLotInfoLog a
  669. // INNER JOIN ICSInventoryLotDetail b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  670. // INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  671. // INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  672. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  673. // LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  674. // INNER JOIN ICSDeliveryNotice c ON b.TransCode=c.DNCode AND b.TransSequence=c.Sequence AND b.WorkPoint=c.WorkPoint
  675. // INNER JOIN ICSDeliveryNotice d ON c.PODetailID=d.DNDetailID AND d.WorkPoint=c.WorkPoint
  676. // INNER JOIN ICSConfiguration con ON con.Code='Stock001' AND a.WorkPoint=con.WorkPoint
  677. // INNER JOIN ICSConfiguration conv ON con.Code='CompleteVerification' AND a.WorkPoint=conv.WorkPoint
  678. // WHERE a.Identification='{0}' AND ERPUpload='0'
  679. // 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
  680. // ,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, ''),
  681. // 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, '')
  682. // SELECT DISTINCT Costre,VenCode,WarehouseCode AS WHCode,DNCode,MUSER AS [User],SYSDATETIME() AS MTime,UpdateTodoQuantity,VerificationEnable,WorkPoint FROM #TempERP
  683. // SELECT Costre,Sequence,InvCode,Quantity,Amount,DNDetailID,Currency,UnitPrice,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10
  684. // FROM #TempERP
  685. // DROP TABLE #TempERP";
  686. // sql = string.Format(sql, Identification);
  687. // DataSet ds = DBHelper.SQlReturnDataSet(sql, cmd);
  688. // string Inputstr = DataToJsonHelper.DataSetToJson(ds, "Vouchs", "Costre");
  689. // string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.CreatePuArrivalVouchURL, Inputstr);
  690. // Result result = new Result();
  691. // result = JsonConvert.DeserializeObject<Result>(resultStr);
  692. // if (result.Success)
  693. // {
  694. // try
  695. // {
  696. // JArray res = (JArray)JsonConvert.DeserializeObject(result.Data.ToString());
  697. // foreach (var item in res)
  698. // {
  699. // JObject jo = (JObject)item;
  700. // JArray resdetail = (JArray)JsonConvert.DeserializeObject(jo["details"].ToString());
  701. // foreach (var detail in resdetail)
  702. // {
  703. // JObject det = (JObject)detail;
  704. // ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, det["DNDetailID"].ToString(), Identification, jo["ID"].ToString(), det["DetailID"].ToString(), jo["RCVTCode"].ToString(), det["Sequence"].ToString(), cmd, language);
  705. // }
  706. // }
  707. // }
  708. // catch (Exception ex)
  709. // {
  710. // log.Debug(ex.ToString());
  711. // log.Debug(resultStr);
  712. // }
  713. // }
  714. // else
  715. // {
  716. // throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  717. // }
  718. // #endregion
  719. //}
  720. //catch (Exception)
  721. //{
  722. // throw;
  723. //}
  724. }
  725. #endregion
  726. #region 采购退货
  727. /// <summary>
  728. /// 采购退货
  729. /// </summary>
  730. /// <param name="TransCode"></param>
  731. /// <param name="TransSequence"></param>
  732. /// <param name="Quantity"></param>
  733. /// <param name="WorkPoint"></param>
  734. /// <param name="cmd"></param>
  735. public static void PurchaseReceiveDoctNegative(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  736. {
  737. try
  738. {
  739. string sql = @"DECLARE @Status VARCHAR(10)
  740. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' AND DNType='2' AND WorkPoint='{1}'
  741. IF (@Status IS NULL)
  742. BEGIN
  743. RAISERROR('" + language.GetNameByCode("WMSAPIInfo085") + @"',16,1);
  744. RETURN
  745. END
  746. ELSE IF (@Status!='2')
  747. BEGIN
  748. RAISERROR('" + language.GetNameByCode("WMSAPIInfo086") + @"',16,1);
  749. RETURN
  750. END
  751. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  752. FROM ICSDeliveryNotice a
  753. WHERE a.DNCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND DNType='2'
  754. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a
  755. WHERE a.DNCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Quantity<a.RCVQuantity AND DNType='2')
  756. BEGIN
  757. RAISERROR('" + language.GetNameByCode("WMSAPIInfo087") + @"',16,1);
  758. RETURN
  759. END";
  760. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  761. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  762. {
  763. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  764. }
  765. }
  766. catch (Exception)
  767. {
  768. throw;
  769. }
  770. }
  771. /// <summary>
  772. /// 采购退货(货柜)
  773. /// </summary>
  774. /// <param name="TransCode"></param>
  775. /// <param name="TransSequence"></param>
  776. /// <param name="Quantity"></param>
  777. /// <param name="WorkPoint"></param>
  778. /// <param name="cmd"></param>
  779. public static void PurchaseReceiveDoctNegativeHG(string TransCode, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  780. {
  781. try
  782. {
  783. string sql = @" UPDATE ICSDeliveryNotice SET RCVQuantity=Quantity
  784. WHERE DNCode='{0}' AND WorkPoint='{1}'";
  785. sql = string.Format(sql, TransCode, WorkPoint);
  786. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  787. {
  788. throw new Exception(language.GetNameByCode("WMSAPIInfo088"));//"采购退货单更新失败!");
  789. }
  790. }
  791. catch (Exception)
  792. {
  793. throw;
  794. }
  795. }
  796. /// <summary>
  797. /// 采购退货接口
  798. /// </summary>
  799. /// <param name="TransType"></param>
  800. /// <param name="Identification"></param>
  801. /// <param name="cmd"></param>
  802. public static void PurchaseReceiveDoctNegativeERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  803. {
  804. try
  805. {
  806. #region SAP(三层结构)
  807. string IsSuccess = "";
  808. string ErrorMessage = "";
  809. string sql = @" select Distinct A.DNCode,A.WorkPoint from ICSDeliveryNotice A
  810. LEFT JOIN ICSWareHouseLotInfoLog B ON B.TransCode=A.DNCode AND B.WorkPoint=A.WorkPoint
  811. where B.Identification='{0}' AND BusinessCode='3'";
  812. sql = string.Format(sql, Identification);
  813. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  814. if (dt.Rows.Count > 1)
  815. {
  816. throw new Exception(language.GetNameByCode("WMSAPIInfo202"));//单次提交单据数量卡控(只允许一张单据)
  817. }
  818. for (int i = 0; i < dt.Rows.Count; i++)
  819. {
  820. string chksql = @"select SUM(Quantity) AS Quantity,SUM(RCVQuantity) AS RCVQuantity from ICSDeliveryNotice
  821. where DNCode='{0}' and WorkPoint='{1}'
  822. GROUP BY DNCode,WorkPoint";
  823. chksql = string.Format(chksql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  824. DataTable chkdt = DBHelper.SQlReturnData(chksql, cmd);
  825. if (Convert.ToDecimal(chkdt.Rows[0]["Quantity"]) == Convert.ToDecimal(chkdt.Rows[0]["RCVQuantity"]))
  826. {
  827. SAPCallBackDocVPN.ZWMS_SK_WS_PZ Client = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ();
  828. SAPCallBackDocVPN.ZWMS_SK_WS_PZ1 Info = new SAPCallBackDocVPN.ZWMS_SK_WS_PZ1();
  829. Info.NEWID = Identification;
  830. Info.DANJU = dt.Rows[i]["DNCode"].ToString();
  831. Info.STATE = "0";
  832. List<SAPCallBackDocVPN.ZWMS_PZ> ItemList = new List<SAPCallBackDocVPN.ZWMS_PZ>();
  833. List<SAPCallBackDocVPN.ZWEBS_GERNR> ItemLineList = new List<SAPCallBackDocVPN.ZWEBS_GERNR>();
  834. Info.Z_FLAG = new SAPCallBackDocVPN.ZWEB_RETURN[1];
  835. sql = @"select A.DNCode,A.SAPSequence,A.InvCode,A.Sequence,A.Quantity,A.RCVQuantity
  836. ,ISNULL(B.BatchCode,'') AS BatchCode from ICSDeliveryNotice A
  837. LEFT JOIN ICSExtension B ON B.ID=A.ExtensionID AND B.WorkPoint=A.WorkPoint
  838. WHERE DNCode='{0}' AND A.WorkPoint='{1}'";
  839. sql = string.Format(sql, dt.Rows[i]["DNCode"].ToString(), dt.Rows[i]["WorkPoint"].ToString());
  840. DataTable Sapdt = DBHelper.SQlReturnData(sql, cmd);
  841. foreach (DataRow dr in Sapdt.Rows)
  842. {
  843. if (Convert.ToDecimal(dr["Quantity"].ToString()) == Convert.ToDecimal(dr["RCVQuantity"].ToString()))
  844. {
  845. SAPCallBackDocVPN.ZWMS_PZ Item = new SAPCallBackDocVPN.ZWMS_PZ();
  846. SAPCallBackDocVPN.ZWEBS_GERNR ItemLine = new SAPCallBackDocVPN.ZWEBS_GERNR();
  847. Item.DANJU = dr["DNCode"].ToString();
  848. Item.POSNR = dr["SAPSequence"].ToString();
  849. Item.LINGYSL = System.Decimal.Round(Convert.ToDecimal(dr["Quantity"].ToString()), 3);
  850. ItemList.Add(Item);
  851. if (dr["BatchCode"].ToString() != "")
  852. {
  853. ItemLine.DANJU = dr["DNCode"].ToString();
  854. ItemLine.POSNR = dr["SAPSequence"].ToString();
  855. ItemLine.MATNR = dr["InvCode"].ToString();
  856. ItemLine.GERNR = dr["BatchCode"].ToString();
  857. ItemLineList.Add(ItemLine);
  858. }
  859. }
  860. }
  861. if (ItemList.Count > 0)
  862. {
  863. Info.Z_ITEM = ItemList.ToArray();
  864. if (ItemLineList.Count > 0)
  865. {
  866. Info.Z_GERNR = ItemLineList.ToArray();
  867. }
  868. else
  869. {
  870. Info.Z_GERNR = new SAPCallBackDocVPN.ZWEBS_GERNR[1];
  871. }
  872. SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse result = new SAPCallBackDocVPN.ZWMS_SK_WS_PZResponse();
  873. result = Client.CallZWMS_SK_WS_PZ(Info);
  874. if (result.Z_NULL == "N")
  875. {
  876. foreach (SAPCallBackDocVPN.ZWEB_RETURN resultItem in result.Z_FLAG)
  877. {
  878. IsSuccess = "N";
  879. ErrorMessage += resultItem.L_MESSAGE + "/r/n";
  880. }
  881. }
  882. }
  883. }
  884. }
  885. if (IsSuccess == "N")
  886. {
  887. throw new Exception(ErrorMessage);
  888. }
  889. #endregion
  890. }
  891. catch (Exception)
  892. {
  893. throw;
  894. }
  895. }
  896. #endregion
  897. #region 开立红字入库
  898. /// <summary>
  899. /// 开立红字入库
  900. /// </summary>
  901. /// <param name="TransCode"></param>
  902. /// <param name="TransSequence"></param>
  903. /// <param name="Quantity"></param>
  904. /// <param name="WorkPoint"></param>
  905. /// <param name="cmd"></param>
  906. public static void PurchaseReceive(string TransCode, string TransSequence, string Quantity, string WorkPoint, SqlCommand cmd, Dictionary<string, string> language)
  907. {
  908. try
  909. {
  910. string sql = @"DECLARE @Status VARCHAR(10)
  911. SELECT @Status=a.Status FROM ICSPurchaseReceive a
  912. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  913. IF (@Status IS NULL)
  914. BEGIN
  915. RAISERROR('" + language.GetNameByCode("WMSAPIInfo089") + @"',16,1);
  916. RETURN
  917. END
  918. ELSE IF (@Status!='1')
  919. BEGIN
  920. RAISERROR('" + language.GetNameByCode("WMSAPIInfo090") + @"',16,1);
  921. RETURN
  922. END
  923. UPDATE a SET RCVQuantity=ISNULL(RCVQuantity,0)+'{2}'
  924. FROM ICSPurchaseReceive a
  925. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' AND a.WorkPoint='{1}' AND a.Type='2'
  926. IF EXISTS(SELECT a.ID FROM ICSPurchaseReceive a
  927. WHERE a.RCVCode='{0}' AND a.Sequence='{3}' and a.WorkPoint='{1}' AND a.Type='2' AND a.Quantity<a.RCVQuantity)
  928. BEGIN
  929. RAISERROR('" + language.GetNameByCode("WMSAPIInfo091") + @"',16,1);
  930. RETURN
  931. END";
  932. sql = string.Format(sql, TransCode, WorkPoint, Quantity, TransSequence);
  933. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  934. {
  935. throw new Exception(language.GetNameByCode("WMSAPIInfo092"));//"红字入库单更新失败!");
  936. }
  937. }
  938. catch (Exception)
  939. {
  940. throw;
  941. }
  942. }
  943. /// <summary>
  944. /// 开立红字入库接口
  945. /// </summary>
  946. /// <param name="TransType"></param>
  947. /// <param name="Identification"></param>
  948. /// <param name="cmd"></param>
  949. public static void PurchaseReceiveERP(string TransType, string Identification, SqlCommand cmd, Dictionary<string, string> language, string BusinessCode)
  950. {
  951. try
  952. {
  953. #region ERP开立状态单据审核
  954. string sql = @"IF EXISTS(SELECT b.ID FROM ICSWareHouseLotInfoLog a
  955. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  956. WHERE a.Identification='{0}' AND b.Quantity!=b.RCVQuantity)
  957. BEGIN
  958. RAISERROR('" + language.GetNameByCode("WMSAPIInfo093") + @"',16,1);
  959. RETURN
  960. END
  961. SELECT b.RCVID AS ID,a.MUSER AS [User],SYSDATETIME() AS MTime,con.Enable AS UpdateTodoQuantity,conStock.Enable AS UpdateStock,a.WorkPoint
  962. FROM ICSWareHouseLotInfoLog a
  963. INNER JOIN ICSPurchaseReceive b ON a.TransCode=b.RCVCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  964. INNER JOIN ICSConfiguration con ON con.Code='Stock002' AND a.WorkPoint=con.WorkPoint
  965. INNER JOIN ICSConfiguration conStock ON conStock.Code='UpdateStock001' AND a.WorkPoint=conStock.WorkPoint
  966. WHERE a.Identification='{0}' AND ERPUpload='0' AND a.BusinessCode = '4'
  967. GROUP BY b.RCVID,a.MUSER,con.Enable,conStock.Enable,a.WorkPoint";
  968. sql = string.Format(sql, Identification);
  969. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  970. string Inputstr = JsonConvert.SerializeObject(dt);
  971. string resultStr = HTTPHelper.HttpPost(TransType, ERPUrl.PurchaseReceiveDoctNegativeURL, Inputstr);
  972. Result result = new Result();
  973. result = JsonConvert.DeserializeObject<Result>(resultStr);
  974. if (result.Success)
  975. {
  976. try
  977. {
  978. foreach (DataRow dr in dt.Rows)
  979. {
  980. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdate(TransType, dr["ID"].ToString(), Identification, "", "", "", "", "", cmd, language, BusinessCode);
  981. }
  982. }
  983. catch (Exception ex)
  984. {
  985. log.Debug(ex.ToString());
  986. log.Debug(resultStr);
  987. }
  988. }
  989. else
  990. {
  991. throw new Exception(language.GetNameByCode("WMSAPIInfo080") + result.Message);
  992. }
  993. #endregion
  994. }
  995. catch (Exception)
  996. {
  997. throw;
  998. }
  999. }
  1000. #endregion
  1001. }
  1002. }