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.

24142 lines
1.3 MiB

1 month ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using NFine.Code;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Data.SqlClient;
  10. using System.Linq;
  11. using System.Net.Http;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace ICSSoft.DataProject
  15. {
  16. /// <summary>
  17. /// 使用中
  18. /// 提交业务处理
  19. /// </summary>
  20. public class ICSSubmitService
  21. {
  22. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  23. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  24. private static string enableCode = "";
  25. private static string excessQtySql = "";
  26. #region 源头单据信息
  27. /// <summary>
  28. /// 源头单据信息
  29. /// </summary>
  30. /// <param name="JsonData"></param>
  31. /// <returns></returns>
  32. public static DataTable TransInformationGet(WMSSourceDocumentModel JsonData)
  33. {
  34. var language = LanguageHelper.GetName("WMSAPIInfo");
  35. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  36. {
  37. conn.Open();
  38. string sql = string.Empty;
  39. SqlCommand cmd = new SqlCommand();
  40. cmd.Connection = conn;
  41. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  42. try
  43. {
  44. if (string.IsNullOrEmpty(JsonData.TransCode))
  45. {
  46. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  47. }
  48. else if (string.IsNullOrEmpty(JsonData.TransType))
  49. {
  50. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  51. }
  52. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  53. {
  54. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  55. }
  56. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  57. {
  58. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  59. }
  60. string TransType = JsonData.TransType;
  61. string enableCode = "";
  62. string excessQtySql = "";
  63. #region SLQ
  64. string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  65. BEGIN
  66. RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  67. RETURN
  68. END
  69. ";
  70. //查询是否需要去除单据中已发完明细
  71. string excludeSql = @"DECLARE @ExcludeEnable BIT
  72. SET @ExcludeEnable=(SELECT Enable FROM ICSConfiguration WHERE Code='excludeInvDelivered')";
  73. if (TransType == TransTypeEnum.ASN.GetDescription()|| TransType == TransTypeEnum.OASN.GetDescription())
  74. {
  75. sql = @"SELECT a.ID,
  76. {0}
  77. convert(varchar(100),'') AS LocationCode,
  78. convert(varchar(100),'') AS LotNo,
  79. convert(varchar(10),'') AS ToWarehouseCode,
  80. 0 AS LocationQty,
  81. 0 AS isMatched,
  82. a.InvCode,
  83. inv.InvName,
  84. inv.InvStd,
  85. a.Quantity,
  86. inv.InvUnit,
  87. a.Amount,
  88. --a.WHCode,
  89. inv.AmountUnit,
  90. --wh.WarehouseName AS WHName,
  91. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  92. a.ExtensionID,
  93. --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,
  94. ISNULL(ext.Version, '') AS Version,
  95. ISNULL(ext.Brand, '') AS Brand,
  96. ISNULL(ext.cFree1, '') AS cFree1,
  97. ISNULL(ext.cFree2, '') AS cFree2,
  98. ISNULL(ext.cFree3, '') AS cFree3,
  99. ISNULL(ext.cFree4, '') AS cFree4,
  100. ISNULL(ext.cFree5, '') AS cFree5,
  101. ISNULL(ext.cFree6, '') AS cFree6,
  102. ISNULL(ext.cFree7, '') AS cFree7,
  103. ISNULL(ext.cFree8, '') AS cFree8,
  104. ISNULL(ext.cFree9, '') AS cFree9,
  105. ISNULL(ext.cFree10, '') AS cFree10,
  106. a.MUSER AS [User],
  107. a.MTIME AS [MTime]
  108. {4}
  109. FROM {1}
  110. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  111. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  112. --LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  113. --LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  114. WHERE {2}
  115. Order By asn.Sequence ASC";
  116. }
  117. else if(TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
  118. {
  119. sql = @"SELECT a.ID,
  120. {0}
  121. convert(varchar(100),'') AS LocationCode,
  122. convert(varchar(100),'') AS LotNo,
  123. convert(varchar(10),'') AS ToWarehouseCode,
  124. 0 AS LocationQty,
  125. 0 AS isMatched,
  126. a.InvCode,
  127. inv.InvName,
  128. inv.InvStd,
  129. a.Quantity,
  130. inv.InvUnit,
  131. a.Amount,
  132. a.ToWarehouseCode AS WHCode,
  133. inv.AmountUnit,
  134. wh.WarehouseName AS WHName,
  135. (select a.F_EnabledMark from Sys_SRM_ItemsDetail a
  136. inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
  137. where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
  138. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  139. a.ExtensionID,
  140. 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,
  141. ISNULL(ext.Version, '') AS Version,
  142. ISNULL(ext.Brand, '') AS Brand,
  143. ISNULL(ext.cFree1, '') AS cFree1,
  144. ISNULL(ext.cFree2, '') AS cFree2,
  145. ISNULL(ext.cFree3, '') AS cFree3,
  146. ISNULL(ext.cFree4, '') AS cFree4,
  147. ISNULL(ext.cFree5, '') AS cFree5,
  148. ISNULL(ext.cFree6, '') AS cFree6,
  149. ISNULL(ext.cFree7, '') AS cFree7,
  150. ISNULL(ext.cFree8, '') AS cFree8,
  151. ISNULL(ext.cFree9, '') AS cFree9,
  152. ISNULL(ext.cFree10, '') AS cFree10,
  153. a.MUSER AS [User],
  154. a.MTIME AS [MTime]
  155. FROM {1}
  156. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  157. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  158. LEFT JOIN ICSWarehouse wh ON a.ToWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  159. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.ToWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  160. WHERE {2} ";
  161. }
  162. else
  163. {
  164. sql = @"SELECT a.ID,
  165. {0}
  166. convert(varchar(100),'') AS LocationCode,
  167. convert(varchar(100),'') AS LotNo,
  168. convert(varchar(10),'') AS ToWarehouseCode,
  169. 0 AS LocationQty,
  170. 0 AS isMatched,
  171. a.InvCode,
  172. inv.InvName,
  173. inv.InvStd,
  174. a.Quantity,
  175. inv.InvUnit,
  176. a.Amount,
  177. a.WHCode,
  178. inv.AmountUnit,
  179. wh.WarehouseName AS WHName,
  180. (select a.F_EnabledMark from Sys_SRM_ItemsDetail a
  181. inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
  182. where b.F_id='4f733e37-445b-4534-8ec0-9f88d0842381') AS TransEnable,
  183. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  184. a.ExtensionID,
  185. 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,
  186. ISNULL(ext.Version, '') AS Version,
  187. ISNULL(ext.Brand, '') AS Brand,
  188. ISNULL(ext.cFree1, '') AS cFree1,
  189. ISNULL(ext.cFree2, '') AS cFree2,
  190. ISNULL(ext.cFree3, '') AS cFree3,
  191. ISNULL(ext.cFree4, '') AS cFree4,
  192. ISNULL(ext.cFree5, '') AS cFree5,
  193. ISNULL(ext.cFree6, '') AS cFree6,
  194. ISNULL(ext.cFree7, '') AS cFree7,
  195. ISNULL(ext.cFree8, '') AS cFree8,
  196. ISNULL(ext.cFree9, '') AS cFree9,
  197. ISNULL(ext.cFree10, '') AS cFree10,
  198. ISNULL(inv.EATTRIBUTE1, '') AS EATTRIBUTE1,
  199. a.MUSER AS [User],
  200. a.MTIME AS [MTime]
  201. {4}
  202. FROM {1}
  203. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  204. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  205. LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  206. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  207. WHERE {2} {5} ";
  208. }
  209. string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  210. c.Code,
  211. c.InvCode,
  212. c.InvName,
  213. c.InvStd,
  214. c.InvUnit,
  215. FLOOR(c.iQuantity) AS iQuantity,
  216. d.WarehouseCode,
  217. d.LocationCode,
  218. d.LotNO,
  219. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  220. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  221. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  222. FROM
  223. ({0}) c
  224. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND ((LEN(ISNULL(c.WHCode,''))<=0) OR (LEN(ISNULL(c.WHCode,''))>0) AND c.WhCode=d.WarehouseCode) AND d.WorkPoint='{1}' AND d.Quantity>0
  225. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  226. LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  227. DECLARE @ItemCode VARCHAR(50),
  228. @QTY DECIMAL(18,3),
  229. @ItemCodeCurrent VARCHAR(50),
  230. @QTYCurrent DECIMAL(18,3),
  231. @iQuantityCurrent DECIMAL(18,3),
  232. @CanDelete BIT,
  233. @Row INT,
  234. @rowCurrent INT
  235. SET @Row = @@rowcount
  236. SET @rowCurrent=1
  237. SET @CanDelete=0
  238. SET @ItemCode=''
  239. WHILE @rowCurrent<=@Row
  240. BEGIN
  241. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  242. PRINT(@rowCurrent)
  243. IF @ItemCode<>@ItemCodeCurrent
  244. BEGIN
  245. SET @ItemCode=@ItemCodeCurrent
  246. SET @QTY=0
  247. SET @CanDelete=0
  248. END
  249. IF @CanDelete=1
  250. BEGIN
  251. DELETE FROM #temp WHERE rowNo=@rowCurrent
  252. SET @rowCurrent += 1
  253. CONTINUE
  254. END
  255. SET @QTY += @QTYCurrent
  256. IF @QTY>=@iQuantityCurrent
  257. BEGIN
  258. SET @CanDelete=1
  259. END
  260. SET @rowCurrent += 1
  261. END
  262. SELECT * FROM #temp
  263. DROP TABLE #temp
  264. ";
  265. #endregion
  266. bool isDeliveryNotice = false; //送货、到货、含委外
  267. string columns = string.Empty; //查询源头单据表的特殊列名
  268. string tableName = string.Empty; //查询源头单据表名
  269. string where = string.Empty; //查询源头单据的过滤条件
  270. string invWhere = ""; //查询特殊物料要求的过滤条件
  271. bool isMerge = false; //合并发料
  272. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  273. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  274. string sqls= string.Empty;
  275. string sqlCheckSign = "";
  276. string isRTOut = "0";
  277. string isPN = "0";
  278. string whcode = "";
  279. string EATTRIBUTE = "";
  280. DataTable flag =null;
  281. #region 检料表信息
  282. //enableCode = "";
  283. //excessQtySql = "";
  284. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  285. {
  286. enableCode = "Over001";
  287. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  288. #region 工单备料sql
  289. sqls = @" SELECT
  290. c.MOCode as Code,
  291. a.InvCode,
  292. b.InvName,
  293. b.InvStd,
  294. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  295. a.WhCode,
  296. b.InvUnit,
  297. a.ExtensionID
  298. FROM
  299. ICSMOPick a
  300. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  301. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  302. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  303. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  304. #endregion
  305. }
  306. if (TransType == TransTypeEnum.MOApply.GetDescription())
  307. {
  308. enableCode = "Over002";
  309. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  310. #region 工单领料SQL
  311. sqls = @" select
  312. a.ApplyCode as Code,
  313. a.InvCode,
  314. b.InvName,
  315. b.InvStd,
  316. b.InvUnit,
  317. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  318. a.WhCode,
  319. a.ExtensionID
  320. FROM
  321. ICSMOApply a
  322. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  323. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  324. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  325. #endregion
  326. }
  327. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  328. {
  329. enableCode = "Over003";
  330. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  331. #region 工单材料出库SQL
  332. sqls = @" select
  333. a.IssueCode as Code,
  334. a.InvCode,
  335. b.InvName,
  336. b.InvStd,
  337. b.InvUnit,
  338. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  339. a.WhCode,
  340. a.ExtensionID
  341. FROM
  342. ICSMOIssue a
  343. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  344. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  345. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  346. #endregion
  347. }
  348. if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription()|| TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
  349. {
  350. enableCode = "Over004";
  351. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  352. #region 委外备料SQL
  353. sqls = @" select
  354. c.OOCode as Code,
  355. a.InvCode,
  356. b.InvName,
  357. b.InvStd,
  358. b.InvUnit,
  359. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  360. a.WhCode,
  361. a.ExtensionID
  362. FROM
  363. ICSOOPick a
  364. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  365. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  366. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  367. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  368. #endregion
  369. }
  370. if (TransType == TransTypeEnum.OOApply.GetDescription())
  371. {
  372. enableCode = "Over005";
  373. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  374. #region 委外领料SQL
  375. sqls = @" select
  376. a.ApplyCode as Code,
  377. a.InvCode,
  378. b.InvName,
  379. b.InvStd,
  380. b.InvUnit,
  381. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  382. a.WhCode,
  383. a.ExtensionID
  384. FROM
  385. ICSOApply a
  386. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  387. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  388. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  389. #endregion
  390. }
  391. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  392. {
  393. //enableCode = "Over006";
  394. excessQtySql = "";
  395. #region 委外材料出库SQL
  396. sqls = @" select
  397. a.IssueCode as Code,
  398. a.InvCode,
  399. b.InvName,
  400. b.InvStd,
  401. b.InvUnit,
  402. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  403. a.WhCode,
  404. a.ExtensionID
  405. FROM
  406. ICSOIssue a
  407. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  408. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  409. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  410. #endregion
  411. }
  412. if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  413. {
  414. enableCode = "";
  415. excessQtySql = "";
  416. #region 销售发货SQL
  417. sqls = @" select
  418. a.SDNCode as Code,
  419. a.InvCode,
  420. b.InvName,
  421. b.InvStd,
  422. b.InvUnit,
  423. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  424. a.WhCode,
  425. a.ExtensionID
  426. FROM
  427. ICSSDN a
  428. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  429. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  430. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  431. #endregion
  432. }
  433. if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  434. {
  435. enableCode = "";
  436. excessQtySql = "";
  437. #region 其它出库SQL
  438. sqls = @" select
  439. a.OutCode as Code,
  440. a.InvCode,
  441. b.InvName,
  442. b.InvStd,
  443. b.InvUnit,
  444. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  445. a.WhCode,
  446. a.ExtensionID
  447. FROM
  448. ICSOtherOut a
  449. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  450. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  451. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  452. #endregion
  453. }
  454. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  455. {
  456. enableCode = "";
  457. excessQtySql = "";
  458. #region 借用SQL
  459. sqls = @"select
  460. a.BrrowCode as Code,
  461. a.InvCode,
  462. b.InvName,
  463. b.InvStd,
  464. b.InvUnit,
  465. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  466. a.WhCode,
  467. a.ExtensionID
  468. FROM
  469. ICSBrrow a
  470. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  471. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  472. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  473. #endregion
  474. }
  475. if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  476. {
  477. enableCode = "";
  478. excessQtySql = "";
  479. #region 物料调拨
  480. sqls = @" select
  481. a.TransferNO as Code,
  482. a.InvCode,
  483. b.InvName,
  484. b.InvStd,
  485. b.InvUnit,
  486. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  487. a.FromWarehouseCode as WhCode,
  488. a.ExtensionID
  489. FROM
  490. ICSTransfer a
  491. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  492. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  493. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  494. #endregion
  495. }
  496. if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  497. {
  498. enableCode = "";
  499. excessQtySql = "";
  500. #region 两步调出
  501. sqls = @"select
  502. a.OutCode as Code,
  503. a.InvCode,
  504. b.InvName,
  505. b.InvStd,
  506. b.InvUnit,
  507. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  508. a.WHCode ,
  509. a.ExtensionID
  510. from ICSOtherOut a
  511. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  512. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  513. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  514. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  515. #endregion
  516. }
  517. #endregion
  518. #region 出库
  519. #region 采购退货
  520. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  521. {
  522. isDeliveryNotice = true;
  523. columns = @"a.DNCode AS TransCode,
  524. a.DNDetailID AS DetailID,
  525. a.DNType AS Type,
  526. a.Sequence AS TransSequence,
  527. ISNULL(a.RCVQuantity,0) AS IssueQuantity,
  528. a.Quantity,
  529. a.Amount,
  530. a.MUSER AS [User],
  531. a.MTIME AS [MTime],";
  532. tableName = @"ICSDeliveryNotice a ";
  533. where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' AND a.Status<>'3'";
  534. }
  535. #region 采购退货(采购订单)
  536. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription())
  537. {
  538. isDeliveryNotice = true;
  539. columns = @"a.DNCode AS TransCode,
  540. a.DNDetailID AS DetailID,
  541. a.DNType AS Type,
  542. a.Sequence AS TransSequence,
  543. a.Quantity - a.RCVQuantity AS IssueQuantity,
  544. a.Quantity,
  545. a.Amount,
  546. a.MUSER AS [User],
  547. a.MTIME AS [MTime],";
  548. tableName = @"ICSDeliveryNotice a ";
  549. where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='1' AND a.Status<>'3'";
  550. }
  551. #endregion
  552. #endregion
  553. //#region 工单关联
  554. //else if (TransType == TransTypeEnum.ICSMOReceive.GetDescription())
  555. //{
  556. // isDeliveryNotice = true;
  557. // columns = @"a.MOCode AS TransCode,
  558. // a.Sequence AS TransSequence,";
  559. // tableName = @"ICSMO a ";
  560. // where = @" a.MOCode='{0}' AND a.WorkPoint='{1}' and a.ERPStatus<>'3'";
  561. //}
  562. //#endregion
  563. #region 委外发料(合并发料)
  564. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
  565. {
  566. if (JsonData.IsRTOut=="1")
  567. {
  568. isRTOut = "1";
  569. }
  570. else
  571. {
  572. isRTOut = "0";
  573. }
  574. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode004' and enable = '1'";
  575. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  576. isMerge = true;
  577. columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
  578. a.PickID AS DetailID,
  579. a.SupplyType AS Type,
  580. b.Sequence+'~'+a.Sequence AS TransSequence,
  581. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  582. tableNameMerge = @"ICSOOPick a
  583. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  584. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  585. columns = @"b.OOCode AS TransCode,
  586. a.PickID AS DetailID,
  587. a.SupplyType AS Type,
  588. b.Sequence+'~'+a.Sequence AS TransSequence,
  589. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  590. tableName = @"ICSOOPick a
  591. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  592. where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and isnull(a.EATTRIBUTE1,'')<>'1' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
  593. }
  594. #endregion
  595. #region 委外退货
  596. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  597. {
  598. isDeliveryNotice = true;
  599. columns = @"a.ODNCode AS TransCode,
  600. a.ODNDetailID AS DetailID,
  601. a.ODNType AS Type,
  602. a.Sequence AS TransSequence,
  603. ISNULL(a.RCVQuantity,0) AS IssueQuantity,
  604. a.Quantity,
  605. a.Amount,
  606. a.MUSER AS [User],
  607. a.MTIME AS [MTime],";
  608. tableName = @"ICSODeliveryNotice a ";
  609. where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' AND a.Status<>'3'";
  610. }
  611. #endregion
  612. #region 委外退货(委外采购订单)
  613. else if (TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription())
  614. {
  615. isDeliveryNotice = true;
  616. columns = @"a.ODNCode AS TransCode,
  617. a.ODNDetailID AS DetailID,
  618. a.ODNType AS Type,
  619. a.Sequence AS TransSequence,
  620. a.Quantity - ISNULL(a.RCVQuantity,0) AS IssueQuantity,
  621. a.Quantity,
  622. a.Amount,
  623. a.MUSER AS [User],
  624. a.MTIME AS [MTime],";
  625. tableName = @"ICSODeliveryNotice a ";
  626. where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='1' AND a.Status<>'3'";
  627. }
  628. #endregion
  629. #region 生产发料(合并发料)
  630. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  631. {
  632. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
  633. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  634. isMerge = true;
  635. columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  636. a.PickID AS DetailID,
  637. a.SupplyType AS Type,
  638. b.Sequence+'~'+a.Sequence AS TransSequence,
  639. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  640. tableNameMerge = @"ICSMOPick a
  641. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  642. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  643. columns = @"b.MOCode AS TransCode,
  644. a.PickID AS DetailID,
  645. a.SupplyType AS Type,
  646. b.Sequence+'~'+a.Sequence AS TransSequence,
  647. ISNULL(a.IssueQuantity,0) AS IssueQuantity,
  648. ISNULL(a.EATTRIBUTE3, isnull(A.Quantity,0)) as DHexcessQty,";
  649. tableName = @"ICSMOPick a
  650. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  651. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1'
  652. AND ((@ExcludeEnable=1 AND dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0) OR (@ExcludeEnable=0 OR @ExcludeEnable IS NULL)) ";
  653. invWhere = DBHelper.SearchConditonGet("Trans_btnInvOut", JsonData.User, cmd);
  654. #region 锐腾杂发控制线边仓发料
  655. DataTable rtdt = null;
  656. string rtsql = @"select a.F_ItemCode,a.F_Define1 from Sys_SRM_ItemsDetail a
  657. inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
  658. where b.F_id='d51a7d1a-cc8a-4b8e-b306-d4ef3a108549' and a.F_EnabledMark='1' AND a.F_ItemCode='{0}'";
  659. rtsql = string.Format(rtsql, JsonData.User);
  660. rtdt = DBHelper.SQlReturnData(rtsql, cmd);
  661. if (rtdt != null && rtdt.Rows.Count > 0)
  662. {
  663. for (int i = 0; i < rtdt.Rows.Count; i++)
  664. {
  665. whcode = rtdt.Rows[i]["F_Define1"].ToString();
  666. }
  667. }
  668. if (whcode != "")
  669. {
  670. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' and a.WHCode in ({2})";
  671. }
  672. #endregion
  673. }
  674. #endregion
  675. #region 生产发料——自动出库
  676. else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
  677. {
  678. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
  679. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  680. isMerge = true;
  681. columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  682. a.PickID AS DetailID,
  683. a.SupplyType AS Type,
  684. b.Sequence+'~'+a.Sequence AS TransSequence,
  685. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  686. tableNameMerge = @"ICSMOPick a
  687. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  688. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  689. columns = @"b.MOCode AS TransCode,
  690. a.PickID AS DetailID,
  691. a.SupplyType AS Type,
  692. b.Sequence+'~'+a.Sequence AS TransSequence,
  693. ISNULL(a.IssueQuantity,0) AS IssueQuantity,
  694. ISNULL(a.EATTRIBUTE3, isnull(A.Quantity,0)) as DHexcessQty,";
  695. tableName = @"ICSMOPick a
  696. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  697. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1'
  698. AND ((@ExcludeEnable=1 AND dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0) OR (@ExcludeEnable=0 OR @ExcludeEnable IS NULL)) ";
  699. invWhere = DBHelper.SearchConditonGet("Trans_btnInvOutAuto", JsonData.User, cmd);
  700. }
  701. #endregion
  702. #region 销售出库(合并发料)
  703. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  704. {
  705. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
  706. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  707. isMerge = true;
  708. columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
  709. a.SDNDetailID AS DetailID,
  710. a.SOCode,
  711. a.Type,
  712. a.Sequence AS TransSequence,
  713. ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
  714. tableNameMerge = @"ICSSDN a
  715. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  716. columns = @"a.SDNCode AS TransCode,
  717. a.SDNDetailID AS DetailID,
  718. a.SOCode,
  719. a.Type,
  720. a.Sequence AS TransSequence,
  721. ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
  722. tableName = @"ICSSDN a ";
  723. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3'";
  724. }
  725. #endregion
  726. #region 销售发货单-快递单
  727. else if (TransType == TransTypeEnum.SalesBindCourierDoc.GetDescription())
  728. {
  729. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
  730. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  731. isMerge = true;
  732. columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
  733. a.SDNDetailID AS DetailID,
  734. a.SOCode,
  735. a.Type,
  736. a.Sequence AS TransSequence,
  737. ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
  738. tableNameMerge = @"ICSSDN a
  739. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  740. columns = @"a.SDNCode AS TransCode,
  741. a.SDNDetailID AS DetailID,
  742. a.SOCode,
  743. a.Type,
  744. a.Sequence AS TransSequence,
  745. a.EATTRIBUTE3 AS CourierCode,
  746. ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
  747. tableName = @"ICSSDN a ";
  748. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3'";
  749. }
  750. #endregion
  751. #region 销售出库-出库单(合并发料)
  752. else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription())
  753. {
  754. if (DBHelper.IsPNU9())
  755. {
  756. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode013' and enable = '1'";
  757. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  758. isMerge = true;
  759. columnsMerge = @"mer.MergeID+'~'+a.SSDCode AS TransCode,
  760. a.SSDDetailID AS DetailID,
  761. isnull(a.EATTRIBUTE3,'') AS FDQuantity,
  762. a.SDNCode,
  763. a.Type,
  764. a.Sequence AS TransSequence,
  765. ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
  766. tableNameMerge = @"ICSSSD a
  767. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  768. columns = @"a.SSDCode AS TransCode,
  769. a.SSDDetailID AS DetailID,
  770. isnull(a.EATTRIBUTE3,'') AS FDQuantity,
  771. a.SDNCode,
  772. a.Type,
  773. a.Sequence AS TransSequence,
  774. ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
  775. tableName = @"ICSSSD a
  776. INNER JOIN ICSSO b on a.SDNCode=b.SOcode and a.SDNSequence=b.Sequence and a.WorkPoint=b.WorkPoint";
  777. where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-a.SSDQuantity>0";
  778. }
  779. else
  780. {
  781. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode013' and enable = '1'";
  782. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  783. isMerge = true;
  784. columnsMerge = @"mer.MergeID+'~'+a.SSDCode AS TransCode,
  785. a.SSDDetailID AS DetailID,
  786. '' AS FDQuantity,
  787. a.SDNCode,
  788. a.Type,
  789. a.Sequence AS TransSequence,
  790. ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
  791. tableNameMerge = @"ICSSSD a
  792. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  793. columns = @"a.SSDCode AS TransCode,
  794. a.SSDDetailID AS DetailID,
  795. '' AS FDQuantity,
  796. a.SDNCode,
  797. a.Type,
  798. a.Sequence AS TransSequence,
  799. ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
  800. tableName = @"ICSSSD a ";
  801. where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-a.SSDQuantity>0";
  802. }
  803. }
  804. #endregion
  805. #region 盘点
  806. else if (TransType == TransTypeEnum.Check.GetDescription())
  807. {
  808. #region SLQ
  809. sql = @"SELECT a.ID,
  810. {0}
  811. a.Quantity,
  812. a.SelectLevel AS LocationCode,
  813. a.Amount,
  814. a.MUSER AS [User],
  815. a.MTIME AS [MTime]
  816. FROM {1}
  817. WHERE {2} ";
  818. #endregion
  819. columns = @"a.CheckCode AS TransCode,
  820. a.ID,
  821. '' AS Type,";
  822. tableName = @"ICSCheck a ";
  823. where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' ";
  824. }
  825. #endregion
  826. #region 一步调拨(合并发料)
  827. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  828. {
  829. if (JsonData.IsPN == "1")
  830. {
  831. isPN = "1";
  832. }
  833. else
  834. {
  835. isPN = "0";
  836. }
  837. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
  838. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  839. isMerge = true;
  840. string Wsql = @"select ColumnCode from ICSColumnEnable where TableCode='ICSTransfer' and Enable='1' and WorkPoint='{0}'";
  841. DataTable chekdt = DBHelper.SQlReturnData(Wsql, cmd);
  842. if (chekdt.Rows.Count > 0)
  843. {
  844. EATTRIBUTE = "a."+chekdt.Rows[0]["ColumnCode"].ToString();
  845. }
  846. if (!EATTRIBUTE.Equals(""))
  847. {
  848. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  849. a.TransferDetailID AS DetailID,
  850. '' AS Type,
  851. a.Sequence AS TransSequence,
  852. '"+ EATTRIBUTE + @" as NewWorkPoint,'
  853. ISNULL(a.TransferQuantity,0) AS IssueQuantity,
  854. a.ToWarehouseCode,";
  855. }
  856. else
  857. {
  858. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  859. a.TransferDetailID AS DetailID,
  860. '' AS Type,
  861. a.Sequence AS TransSequence,
  862. ISNULL(a.TransferQuantity,0) AS IssueQuantity,
  863. a.ToWarehouseCode,";
  864. }
  865. tableNameMerge = @"ICSTransfer a
  866. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  867. #region SLQ
  868. sql = @"SELECT a.ID,
  869. {0}
  870. convert(varchar(100),'') AS LocationCode,
  871. convert(varchar(100),'') AS LotNo,
  872. 0 AS LocationQty,
  873. 0 AS isMatched,
  874. a.InvCode,
  875. inv.InvName,
  876. inv.InvStd,
  877. a.Quantity,
  878. inv.InvUnit,
  879. a.Amount,
  880. a.FromWarehouseCode AS WHCode,
  881. inv.AmountUnit,
  882. wh.WarehouseName AS WHName,
  883. a.ExtensionID,
  884. ext.ProjectCode,
  885. 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,
  886. ext.Version,
  887. ext.Brand,
  888. ext.cFree1,
  889. ext.cFree2,
  890. ext.cFree3,
  891. ext.cFree4,
  892. ext.cFree5,
  893. ext.cFree6,
  894. ext.cFree7,
  895. ext.cFree8,
  896. ext.cFree9,
  897. ext.cFree10,
  898. a.MUSER AS [User],
  899. a.MTIME AS [MTime]
  900. FROM {1}
  901. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  902. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  903. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  904. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  905. WHERE {2} ";
  906. #endregion
  907. if (!EATTRIBUTE.Equals(""))
  908. {
  909. columns = @"a.TransferNO AS TransCode,
  910. a.TransferDetailID AS DetailID,
  911. '' AS Type,
  912. a.Sequence AS TransSequence,
  913. '" + EATTRIBUTE + @" as NewWorkPoint,'
  914. ISNULL(a.TransferQuantity,0) AS IssueQuantity,
  915. a.ToWarehouseCode,";
  916. }
  917. else
  918. {
  919. columns = @"a.TransferNO AS TransCode,
  920. a.TransferDetailID AS DetailID,
  921. '' AS Type,
  922. a.Sequence AS TransSequence,
  923. ISNULL(a.TransferQuantity,0) AS IssueQuantity,
  924. a.ToWarehouseCode,";
  925. }
  926. tableName = @"ICSTransfer a ";
  927. if (isPN=="1")
  928. {
  929. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3' and a.type='3'";
  930. }
  931. else
  932. {
  933. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3'";
  934. }
  935. }
  936. #endregion
  937. #region 物料调拨-自动
  938. else if (TransType == TransTypeEnum.OneStepTransferDocAuto.GetDescription())
  939. {
  940. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
  941. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  942. isMerge = true;
  943. string Wsql = @"select ColumnCode from ICSColumnEnable where TableCode='ICSTransfer' and Enable='1' and WorkPoint='{0}'";
  944. DataTable chekdt = DBHelper.SQlReturnData(Wsql, cmd);
  945. if (chekdt.Rows.Count > 0)
  946. {
  947. EATTRIBUTE = "a." + chekdt.Rows[0]["ColumnCode"].ToString();
  948. }
  949. if (!EATTRIBUTE.Equals(""))
  950. {
  951. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  952. a.TransferDetailID AS DetailID,
  953. '' AS Type,
  954. a.Sequence AS TransSequence,
  955. '" + EATTRIBUTE + @" as NewWorkPoint,'
  956. ISNULL(a.TransferQuantity,0) AS IssueQuantity,
  957. a.ToWarehouseCode,";
  958. }
  959. else
  960. {
  961. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  962. a.TransferDetailID AS DetailID,
  963. '' AS Type,
  964. a.Sequence AS TransSequence,
  965. ISNULL(a.TransferQuantity,0) AS IssueQuantity,
  966. a.ToWarehouseCode,";
  967. }
  968. tableNameMerge = @"ICSTransfer a
  969. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  970. #region SLQ
  971. sql = @"SELECT a.ID,
  972. {0}
  973. convert(varchar(100),'') AS LocationCode,
  974. convert(varchar(100),'') AS LotNo,
  975. 0 AS LocationQty,
  976. 0 AS isMatched,
  977. a.InvCode,
  978. inv.InvName,
  979. inv.InvStd,
  980. a.Quantity,
  981. inv.InvUnit,
  982. a.Amount,
  983. a.FromWarehouseCode AS WHCode,
  984. inv.AmountUnit,
  985. wh.WarehouseName AS WHName,
  986. a.ExtensionID,
  987. ext.ProjectCode,
  988. 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,
  989. ext.Version,
  990. ext.Brand,
  991. ext.cFree1,
  992. ext.cFree2,
  993. ext.cFree3,
  994. ext.cFree4,
  995. ext.cFree5,
  996. ext.cFree6,
  997. ext.cFree7,
  998. ext.cFree8,
  999. ext.cFree9,
  1000. ext.cFree10,
  1001. a.MUSER AS [User],
  1002. a.MTIME AS [MTime]
  1003. FROM {1}
  1004. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1005. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1006. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1007. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1008. WHERE {2} {5} ";
  1009. #endregion
  1010. if (!EATTRIBUTE.Equals(""))
  1011. {
  1012. columns = @"a.TransferNO AS TransCode,
  1013. a.TransferDetailID AS DetailID,
  1014. '' AS Type,
  1015. a.Sequence AS TransSequence,
  1016. '" + EATTRIBUTE + @" as NewWorkPoint,'
  1017. ISNULL(a.TransferQuantity,0) AS IssueQuantity,
  1018. a.ToWarehouseCode,";
  1019. }
  1020. else
  1021. {
  1022. columns = @"a.TransferNO AS TransCode,
  1023. a.TransferDetailID AS DetailID,
  1024. '' AS Type,
  1025. a.Sequence AS TransSequence,
  1026. ISNULL(a.TransferQuantity,0) AS IssueQuantity,
  1027. a.ToWarehouseCode,";
  1028. }
  1029. tableName = @"ICSTransfer a ";
  1030. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3' ";
  1031. invWhere = DBHelper.SearchConditonGet("Trans_btnInvTransAuto", JsonData.User, cmd);
  1032. }
  1033. #endregion
  1034. #region 调拨申请单(领料)
  1035. else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
  1036. {
  1037. isMerge = true;
  1038. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  1039. a.TransferDetailID AS DetailID,
  1040. '' AS Type,a.EATTRIBUTE29 AS OutWorkPoint,a.EATTRIBUTE30 InWorkPoint,
  1041. a.Sequence AS TransSequence,
  1042. ISNULL(a.TransferQuantity,0) AS IssueQuantity,
  1043. a.ToWarehouseCode,";
  1044. tableNameMerge = @"ICSTransferApplication a
  1045. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1046. #region SLQ
  1047. sql = @"SELECT a.ID,
  1048. {0}
  1049. convert(varchar(100),'') AS LocationCode,
  1050. convert(varchar(100),'') AS LotNo,
  1051. 0 AS LocationQty,
  1052. 0 AS isMatched,
  1053. a.InvCode,
  1054. inv.InvName,
  1055. inv.InvStd,
  1056. a.Quantity,
  1057. inv.InvUnit,
  1058. a.Amount,
  1059. a.FromWarehouseCode AS WHCode,
  1060. inv.AmountUnit,
  1061. wh.WarehouseName AS WHName,
  1062. a.ExtensionID,
  1063. ext.ProjectCode,
  1064. 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,
  1065. ext.Version,
  1066. ext.Brand,
  1067. ext.cFree1,
  1068. ext.cFree2,
  1069. ext.cFree3,
  1070. ext.cFree4,
  1071. ext.cFree5,
  1072. ext.cFree6,
  1073. ext.cFree7,
  1074. ext.cFree8,
  1075. ext.cFree9,
  1076. ext.cFree10,
  1077. a.MUSER AS [User],
  1078. a.MTIME AS [MTime]
  1079. FROM {1}
  1080. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1081. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1082. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1083. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1084. WHERE {2} ";
  1085. #endregion
  1086. columns = @"a.TransferNO AS TransCode,
  1087. a.TransferDetailID AS DetailID,
  1088. '' AS Type,a.EATTRIBUTE29 AS OutWorkPoint,a.EATTRIBUTE30 InWorkPoint,
  1089. a.Sequence AS TransSequence,
  1090. ISNULL(a.TransferQuantity,0) AS IssueQuantity,
  1091. a.ToWarehouseCode,";
  1092. tableName = @"ICSTransferApplication a ";
  1093. if (isPN == "1")
  1094. {
  1095. where = @" a.TransferNO='{0}' AND a.Status='2' AND a.Status<>'3'";
  1096. }
  1097. else
  1098. {
  1099. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='2' AND a.Status<>'3'";
  1100. }
  1101. }
  1102. #endregion
  1103. #region 调拨(合并发料)
  1104. else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
  1105. {
  1106. }
  1107. #endregion
  1108. #region 两步调出(合并发料)
  1109. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  1110. {
  1111. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode010' and enable = '1'";
  1112. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1113. isMerge = true;
  1114. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  1115. a.OutDetailID AS DetailID,
  1116. '' AS Type,
  1117. a.Sequence AS TransSequence,
  1118. ISNULL(a.OutQuantity,0) AS IssueQuantity,";
  1119. tableNameMerge = @"ICSOtherOut a
  1120. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1121. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1122. columns = @"a.OutCode AS TransCode,
  1123. a.OutDetailID AS DetailID,
  1124. '' AS Type,
  1125. a.Sequence AS TransSequence,
  1126. ISNULL(a.OutQuantity,0) AS IssueQuantity,";
  1127. tableName = @"ICSOtherOut a
  1128. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  1129. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.OutQuantity>0";
  1130. }
  1131. #endregion
  1132. #region 其他出库(合并发料)
  1133. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  1134. {
  1135. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
  1136. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1137. isMerge = true;
  1138. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  1139. a.OutDetailID AS DetailID,
  1140. '' AS Type,
  1141. a.Sequence AS TransSequence,
  1142. ISNULL(a.OutQuantity,0) AS IssueQuantity,";
  1143. tableNameMerge = @"ICSOtherOut a
  1144. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1145. columns = @"a.OutCode AS TransCode,
  1146. a.OutDetailID AS DetailID,
  1147. '' AS Type,
  1148. a.Sequence AS TransSequence,
  1149. ISNULL(a.OutQuantity,0) AS IssueQuantity,";
  1150. tableName = @"ICSOtherOut a ";
  1151. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.OutQuantity, 0)>0";
  1152. invWhere = DBHelper.SearchConditonGet("Trans_btnOtherOut", JsonData.User, cmd);
  1153. #region 锐腾杂发控制线边仓发料
  1154. DataTable rtdt = null;
  1155. string rtsql = @"select a.F_ItemCode,a.F_Define1 from Sys_SRM_ItemsDetail a
  1156. inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
  1157. where b.F_id='d51a7d1a-cc8a-4b8e-b306-d4ef3a108549' and a.F_EnabledMark='1' AND a.F_ItemCode='{0}'";
  1158. rtsql = string.Format(rtsql, JsonData.User);
  1159. rtdt = DBHelper.SQlReturnData(rtsql, cmd);
  1160. if (rtdt != null && rtdt.Rows.Count > 0)
  1161. {
  1162. for (int i = 0; i < rtdt.Rows.Count; i++)
  1163. {
  1164. whcode = rtdt.Rows[i]["F_Define1"].ToString();
  1165. }
  1166. }
  1167. if (whcode != "")
  1168. {
  1169. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.OutQuantity, 0)>0 and a.WHCode in ({2})";
  1170. }
  1171. #endregion
  1172. }
  1173. #endregion
  1174. #region 其他出库-自动出库
  1175. else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
  1176. {
  1177. sqlCheck += @"IF EXISTS (SELECT 1
  1178. FROM ICSOtherOut a
  1179. INNER JOIN ICSInventory inv ON inv.InvCode=a.InvCode AND inv.WorkPoint=a.WorkPoint
  1180. WHERE {2} " + DBHelper.SearchConditonGet("Trans_btnOtherOut", JsonData.User, cmd) + @")
  1181. BEGIN
  1182. RAISERROR('" + language.GetNameByCode("WMSAPIInfo530") + @"',16,1);
  1183. RETURN
  1184. END
  1185. ";
  1186. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
  1187. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1188. isMerge = false;
  1189. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  1190. a.OutDetailID AS DetailID,
  1191. '' AS Type,
  1192. a.Sequence AS TransSequence,
  1193. ISNULL(a.OutQuantity,0) AS IssueQuantity,";
  1194. tableNameMerge = @"ICSOtherOut a
  1195. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1196. columns = @"a.OutCode AS TransCode,
  1197. a.OutDetailID AS DetailID,
  1198. '' AS Type,
  1199. a.Sequence AS TransSequence,
  1200. ISNULL(a.OutQuantity,0) AS IssueQuantity,";
  1201. tableName = @"ICSOtherOut a ";
  1202. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.OutQuantity, 0)>0 ";
  1203. invWhere = DBHelper.SearchConditonGet("Trans_btnOtherOutAuto", JsonData.User, cmd);
  1204. }
  1205. #endregion
  1206. #region 红字其他入库
  1207. else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
  1208. {
  1209. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
  1210. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1211. isMerge = true;
  1212. columnsMerge = @"mer.MergeID+'~'+a.InCode AS TransCode,
  1213. a.InDetailID AS DetailID,
  1214. '' AS Type,
  1215. a.Sequence AS TransSequence,
  1216. ISNULL(a.InQuantity,0) AS IssueQuantity,";
  1217. tableNameMerge = @"ICSOtherIn a
  1218. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1219. columns = @"a.InCode AS TransCode,
  1220. a.InDetailID AS DetailID,
  1221. '' AS Type,
  1222. a.Sequence AS TransSequence,
  1223. ISNULL(a.InQuantity,0) AS IssueQuantity,";
  1224. tableName = @"ICSOtherIn a ";
  1225. where = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.InQuantity>0 AND a.Type='2'";
  1226. }
  1227. #endregion
  1228. #region 领料申请单发料(合并发料)
  1229. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  1230. {
  1231. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode002' and enable = '1'";
  1232. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1233. isMerge = true;
  1234. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  1235. a.ApplyDetailID AS DetailID,
  1236. a.Type,
  1237. a.Sequence AS TransSequence,
  1238. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  1239. tableNameMerge = @"ICSMOApply a
  1240. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1241. columns = @"a.ApplyCode AS TransCode,
  1242. a.ApplyDetailID AS DetailID,
  1243. a.Type,
  1244. a.Sequence AS TransSequence,
  1245. ISNULL(a.IssueQuantity,0) AS IssueQuantity,
  1246. ";
  1247. tableName = @"ICSMOApply a ";
  1248. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
  1249. // 东辉增加备用字段
  1250. //受益部门(EATTRIBUTE)、单据类型EATTRIBUTE2、
  1251. //RD编号EATTRIBUTE5、项目编号EATTRIBUTE8、实际领用部门DepName、备注EATTRIBUTE11
  1252. if (DBHelper.IsU9())
  1253. { columns += @"isnull(a.EATTRIBUTE15,'') as EATTRIBUTE1,
  1254. isnull(a.EATTRIBUTE17,'') as EATTRIBUTE2,
  1255. isnull(a.EATTRIBUTE5,'') as EATTRIBUTE5,
  1256. isnull(a.EATTRIBUTE8,'') as EATTRIBUTE8,
  1257. isnull(its.F_itemName,'') as DepName,
  1258. isnull(a.EATTRIBUTE11,'') as EATTRIBUTE11,
  1259. isnull(lotinfo.qty,0) as invLotQty,
  1260. ";
  1261. tableName = @"ICSMOApply a
  1262. LEFT join Sys_SRM_Items it on it.F_EnCode = 'LYDep'
  1263. LEFT join Sys_SRM_ItemsDetail its on it.F_id = its.f_itemid and its.F_itemcode = a.DepCode
  1264. left join (select invcode,sum(Quantity) as qty from icswarehouselotinfo group by invcode) lotinfo on a.invcode = lotinfo.invcode
  1265. ";
  1266. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
  1267. sqlCheck += @"
  1268. DECLARE @status VARCHAR(20)
  1269. select top 1 @status = status from ICSMOApply where ApplyCode='"+ JsonData.TransCode + @"'
  1270. IF(@status!=2)
  1271. BEGIN
  1272. RAISERROR('',16,1);
  1273. RETURN
  1274. END
  1275. ";
  1276. }
  1277. }
  1278. #endregion
  1279. #region 补料申请单发料(合并发料)
  1280. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  1281. {
  1282. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode012' and enable = '1'";
  1283. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1284. isMerge = true;
  1285. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  1286. a.ApplyDetailID AS DetailID,
  1287. a.Type,
  1288. a.Sequence AS TransSequence,
  1289. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  1290. tableNameMerge = @"ICSMOReplenishment a
  1291. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1292. columns = @"a.ReplenishmentCode AS TransCode,
  1293. a.ReplenishmentDetailID AS DetailID,
  1294. a.Type,
  1295. a.Sequence AS TransSequence,
  1296. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  1297. tableName = @"ICSMOReplenishment a ";
  1298. where = @" a.ReplenishmentCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
  1299. }
  1300. #endregion
  1301. #region 委外领料申请单发料(合并发料)
  1302. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  1303. {
  1304. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode005' and enable = '1'";
  1305. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1306. isMerge = true;
  1307. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  1308. a.ApplyDetailID AS DetailID,
  1309. a.Type,
  1310. a.Sequence AS TransSequence,
  1311. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  1312. tableNameMerge = @"ICSOApply a
  1313. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1314. columns = @"a.ApplyCode AS TransCode,
  1315. a.ApplyDetailID AS DetailID,
  1316. a.Type,
  1317. a.Sequence AS TransSequence,
  1318. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  1319. tableName = @"ICSOApply a ";
  1320. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
  1321. }
  1322. #endregion
  1323. #region 开立材料出库(合并发料)
  1324. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  1325. {
  1326. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode003' and enable = '1'";
  1327. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1328. isMerge = true;
  1329. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  1330. a.IssueDetailID AS DetailID,
  1331. a.Type,
  1332. a.Sequence AS TransSequence,
  1333. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  1334. tableNameMerge = @"ICSMOIssue a
  1335. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1336. columns = @"a.IssueCode AS TransCode,
  1337. a.IssueDetailID AS DetailID,
  1338. a.Type,
  1339. a.Sequence AS TransSequence,
  1340. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  1341. tableName = @"ICSMOIssue a ";
  1342. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
  1343. #region 锐腾杂发控制线边仓发料
  1344. DataTable rtdt = null;
  1345. string rtsql = @"select a.F_ItemCode,a.F_Define1 from Sys_SRM_ItemsDetail a
  1346. inner JOIN Sys_SRM_Items b on a.F_ItemId=b.F_id
  1347. where b.F_id='d51a7d1a-cc8a-4b8e-b306-d4ef3a108549' and a.F_EnabledMark='1' AND a.F_ItemCode='{0}'";
  1348. rtsql = string.Format(rtsql, JsonData.User);
  1349. rtdt = DBHelper.SQlReturnData(rtsql, cmd);
  1350. if (rtdt != null && rtdt.Rows.Count > 0)
  1351. {
  1352. for (int i = 0; i < rtdt.Rows.Count; i++)
  1353. {
  1354. whcode = rtdt.Rows[i]["F_Define1"].ToString();
  1355. }
  1356. }
  1357. if (whcode != "")
  1358. {
  1359. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0 and a.WHCode in ({2})";
  1360. }
  1361. #endregion
  1362. }
  1363. #endregion
  1364. #region 开立委外材料出库(合并发料)
  1365. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  1366. {
  1367. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode006' and enable = '1'";
  1368. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1369. isMerge = true;
  1370. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  1371. a.IssueDetailID AS DetailID,
  1372. a.Type,
  1373. a.Sequence AS TransSequence,
  1374. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  1375. tableNameMerge = @"ICSOIssue a
  1376. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1377. columns = @"a.IssueCode AS TransCode,
  1378. a.IssueDetailID AS DetailID,
  1379. a.Type,
  1380. a.Sequence AS TransSequence,
  1381. ISNULL(a.IssueQuantity,0) AS IssueQuantity,";
  1382. tableName = @"ICSOIssue a ";
  1383. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.IssueQuantity,0)>0";
  1384. }
  1385. #endregion
  1386. #region 开立红字入库单
  1387. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  1388. {
  1389. columns = @"a.RCVCode AS TransCode,
  1390. a.RCVDetailID AS DetailID,
  1391. a.Type,
  1392. a.Sequence AS TransSequence,
  1393. ISNULL(a.RCVQuantity, 0) AS IssueQuantity,";
  1394. tableName = @"ICSPurchaseReceive a ";
  1395. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  1396. }
  1397. #endregion
  1398. #region 开立委外红字入库单
  1399. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  1400. {
  1401. columns = @"a.RCVCode AS TransCode,
  1402. a.RCVDetailID AS DetailID,
  1403. a.Type,
  1404. a.Sequence AS TransSequence,
  1405. ISNULL(a.RCVQuantity,0) AS IssueQuantity,";
  1406. tableName = @"ICSOutsourcingReceive a ";
  1407. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  1408. }
  1409. #endregion
  1410. #region 借用(合并发料)
  1411. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  1412. {
  1413. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode011' and enable = '1'";
  1414. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1415. isMerge = true;
  1416. columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
  1417. a.BrrowDetailID AS DetailID,
  1418. '' AS Type,
  1419. a.Sequence AS TransSequence,
  1420. ISNULL(a.BrrowQuantity,0) AS IssueQuantity,";
  1421. tableNameMerge = @"ICSBrrow a
  1422. INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  1423. columns = @"a.BrrowCode AS TransCode,
  1424. a.BrrowDetailID AS DetailID,
  1425. '' AS Type,
  1426. a.Sequence AS TransSequence,
  1427. ISNULL(a.BrrowQuantity,0) AS IssueQuantity,";
  1428. tableName = @"ICSBrrow a ";
  1429. where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-ISNULL(a.BrrowQuantity,0)>0";
  1430. }
  1431. #endregion
  1432. #region 送货单
  1433. else if (TransType == TransTypeEnum.ASN.GetDescription())
  1434. {
  1435. isDeliveryNotice = true;
  1436. columns = @"asn.ASNCode AS TransCode,
  1437. asn.ID AS DetailID,
  1438. asn.LotNo,
  1439. '' AS Type,
  1440. asn.Sequence AS TransSequence,
  1441. ISNULL(asn.DNQuantity,0) AS IssueQuantity,
  1442. asn.Quantity,
  1443. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  1444. asn.MUSER AS [User],
  1445. asn.MTIME AS [MTime],
  1446. --
  1447. case when its.F_Define1 is not null then '1' else '0' end as needScan,
  1448. case when invinfo.INVIQC =1 then isnull(ins.enable,0) else '1' end as inspection,
  1449. POQuantity , YDNQuantity , (POQuantity-YDNQuantity) as NDNQuantity,";
  1450. tableName = @"ICSInventoryLot a
  1451. INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint
  1452. LEFT join Sys_SRM_Items it on it.F_EnCode = 'Arrive_inv'
  1453. LEFT join Sys_SRM_ItemsDetail its on it.F_id = its.f_itemid and SUBSTRING(a.InvCode, 1, 1) = its.F_Define1
  1454. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1
  1455. INNER JOIN ICSInventoryLotDetail lotdetail ON a.LotNo=lotdetail.LotNo AND a.WorkPoint=lotdetail.WorkPoint
  1456. INNER JOIN ICSInventory invinfo on invinfo.invcode = a.invcode AND a.WorkPoint=invinfo.WorkPoint
  1457. LEFT join
  1458. (select c.Quantity as POQuantity ,SUM(a.DNQuantity) as YDNQuantity,c.pocode ,c.sequence
  1459. from ICSASNDetail a
  1460. inner join ICSInventoryLotdetail b on a.lotno =b.lotno
  1461. inner join ICSPurchaseOrder c on b.transcode = c.pocode and b.transSequence = c.sequence
  1462. GROUP BY c.pocode ,c.sequence,c.Quantity) potemp on lotdetail.transcode = potemp.pocode and lotdetail.transSequence = potemp.sequence
  1463. ";
  1464. where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
  1465. }
  1466. #endregion
  1467. #region 委外送货单
  1468. else if (TransType == TransTypeEnum.OASN.GetDescription())
  1469. {
  1470. isDeliveryNotice = true;
  1471. columns = @"asn.OASNCode AS TransCode,
  1472. asn.ID AS DetailID,
  1473. asn.LotNo,
  1474. '' AS Type,
  1475. asn.Sequence AS TransSequence,
  1476. ISNULL(asn.ODNQuantity,0) AS IssueQuantity,
  1477. asn.Quantity,
  1478. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  1479. asn.MUSER AS [User],
  1480. asn.MTIME AS [MTime],";
  1481. tableName = @"ICSInventoryLot a
  1482. INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  1483. where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
  1484. }
  1485. #endregion
  1486. #endregion
  1487. #region 入库
  1488. #region 采购入库
  1489. else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1490. {
  1491. }
  1492. #endregion
  1493. #region 采购入库-入库单
  1494. else if (TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription())
  1495. {
  1496. }
  1497. #endregion
  1498. #region 审核的到货单
  1499. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1500. {
  1501. }
  1502. #endregion
  1503. #region 采购拒收
  1504. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1505. {
  1506. }
  1507. #endregion
  1508. #region 审核的委外到货单
  1509. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1510. {
  1511. }
  1512. #endregion
  1513. #region 委外拒收
  1514. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1515. {
  1516. }
  1517. #endregion
  1518. #region 委外入库
  1519. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1520. {
  1521. }
  1522. #endregion
  1523. #region 生产退料
  1524. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1525. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1526. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1527. {
  1528. }
  1529. #endregion
  1530. #region 委外退料
  1531. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1532. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1533. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1534. {
  1535. #region SLQ
  1536. sql = @"SELECT a.ID,
  1537. {0}
  1538. FROM {1}
  1539. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1540. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1541. WHERE {2} ";
  1542. #endregion
  1543. columns = @"a.OApplyNegCode AS TransCode,
  1544. a.Sequence AS TransSequence";
  1545. tableName = @"ICSOApplyNegDetail a
  1546. INNER JOIN ICSOApplyNeg d ON a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint";
  1547. where = @" a.OApplyNegCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>a.IssueNegQuantity AND d.Status<>'3'";
  1548. }
  1549. #endregion
  1550. #region 生产入库
  1551. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1552. {
  1553. }
  1554. #endregion
  1555. #region 开立的生产入库单
  1556. else if (TransType == TransTypeEnum.ManufactureMESReceive.GetDescription())
  1557. {
  1558. columns = @"a.RCVCode AS TransCode,
  1559. a.RCVDetailID AS DetailID,
  1560. a.Type AS Type,
  1561. a.Sequence AS TransSequence,
  1562. a.SourceCode,
  1563. a.SourceSequence,
  1564. ISNULL(a.RCVQuantity,0) AS IssueQuantity,";
  1565. tableName = @"ICSManufactureReceive a ";
  1566. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status='1' AND a.Quantity>ISNULL(a.RCVQuantity, 0)";
  1567. }
  1568. #endregion
  1569. #region 返工工单
  1570. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1571. {
  1572. }
  1573. #endregion
  1574. #region 销售退货
  1575. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1576. {
  1577. }
  1578. #endregion
  1579. #region 销售出库-红字出库单原条码
  1580. else if (TransType == TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription())
  1581. {
  1582. columns = @"a.SSDCode AS TransCode,
  1583. a.SSDDetailID AS DetailID,
  1584. a.SDNCode,
  1585. a.Type,
  1586. a.Sequence AS TransSequence,
  1587. ISNULL(a.SSDQuantity,0) AS IssueQuantity,";
  1588. tableName = @"ICSSSD a ";
  1589. where = @" a.SSDCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status='1' AND a.Quantity-ISNULL(a.SSDQuantity,0)>0";
  1590. }
  1591. #endregion
  1592. #region 两步调入
  1593. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1594. {
  1595. columns = @"a.InCode AS TransCode,
  1596. a.InDetailID AS DetailID,
  1597. '' AS Type,
  1598. a.Sequence AS TransSequence,
  1599. ISNULL(a.InQuantity,0) AS IssueQuantity,";
  1600. tableName = @"ICSOtherIn a
  1601. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  1602. where = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  1603. }
  1604. #endregion
  1605. #region 锐腾两步调入
  1606. else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
  1607. {
  1608. columns = @"a.TransferNO AS TransCode,
  1609. a.TransferDetailID AS DetailID,
  1610. '' AS Type,
  1611. a.Sequence AS TransSequence,
  1612. a.TransferQuantity AS IssueQuantity,";
  1613. tableName = @"ICSTransfer a ";
  1614. where = @" a.TransferNo='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  1615. }
  1616. #endregion
  1617. #region 销售退货-原条码
  1618. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1619. {
  1620. columns = @"a.SDNCode AS TransCode,
  1621. a.SOCode ,
  1622. a.SDNDetailID AS DetailID,
  1623. a.Type,
  1624. a.Sequence AS TransSequence,
  1625. ISNULL(a.SDNQuantity,0) AS IssueQuantity,";
  1626. tableName = @"ICSSDN a ";
  1627. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  1628. }
  1629. #endregion
  1630. #region 其他入库
  1631. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1632. {
  1633. }
  1634. #endregion
  1635. #region 拆卸单
  1636. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1637. {
  1638. columns = @"a.DABDOCCode AS TransCode,
  1639. a.DABDOCDetailID AS DetailID,
  1640. a.DABDOCType AS Type,
  1641. a.Sequence AS TransSequence,
  1642. ISNULL(a.DABDOCQuantity,0) AS IssueQuantity,";
  1643. tableName = @"ICSDisassemblyDoc a";
  1644. where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' AND a.Status<>'3' ";
  1645. }
  1646. #endregion
  1647. #region 归还
  1648. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1649. {
  1650. }
  1651. #endregion
  1652. #endregion
  1653. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
  1654. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  1655. #region 判断是否启用匹配库位
  1656. if ((flag != null && flag.Rows.Count > 0)|| isRTOut=="1")
  1657. //if (true)
  1658. {
  1659. sql = @"select * into #maintemp from (" + sql + @")a
  1660. select * into #resulttemp from #maintemp
  1661. truncate table #resulttemp
  1662. select a.lotno,a.locationcode,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime,a.warehousecode,isnull(ext.ProjectCode,'')as ProjectCode, isnull(ext.Version,'')as Version,
  1663. isnull(ext.Brand,'')as Brand,
  1664. isnull(ext.cFree1,'')as cFree1,
  1665. isnull(ext.cFree2,'') cFree2,
  1666. isnull(ext.cFree3,'') cFree3,
  1667. isnull(ext.cFree4,'') cFree4,
  1668. isnull(ext.cFree5,'') cFree5,
  1669. isnull(ext.cFree6,'') cFree6,
  1670. isnull(ext.cFree7,'') cFree7,
  1671. isnull(ext.cFree8,'') cFree8,
  1672. isnull(ext.cFree9,'') cFree9,
  1673. isnull(ext.cFree10,'') cFree10,ISNULL(ext.BatchCode, '') BatchCode into #barcodetemp
  1674. from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1675. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1676. LEFT JOIN
  1677. (select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp
  1678. group by invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE) b on a.invcode = b.invcode
  1679. where (a.warehousecode = b.whcode or ISNULL(b.whcode,'')='') and a.Quantity-a.lockQuantity>0 and
  1680. ((LEN(ISNULL(b.ProjectCode,''))<=0)or((LEN(ISNULL(b.ProjectCode,''))>0) and ext.ProjectCode = b.ProjectCode))
  1681. and ((LEN(ISNULL(b.Version,''))<=0)or((LEN(ISNULL(b.Version,''))>0) and ext.Version =b.Version)) and
  1682. ((LEN(ISNULL(b.Brand,''))<=0)or ((LEN(ISNULL(b.Brand,''))>0) and ext.Brand =b.Brand)) and
  1683. ((LEN(ISNULL(b.BatchCode,''))<=0)or((LEN(ISNULL(b.BatchCode,''))>0) and ext.BatchCode =b.BatchCode)) and
  1684. ((LEN(ISNULL(b.cFree1,''))<=0)or((LEN(ISNULL(b.cFree1,''))>0) and ext.cFree1 =b.cFree1)) and
  1685. ((LEN(ISNULL(b.cFree2,''))<=0)or((LEN(ISNULL(b.cFree2,''))>0) and ext.cFree2 =b.cFree2)) and
  1686. ((LEN(ISNULL(b.cFree3,''))<=0)or((LEN(ISNULL(b.cFree3,''))>0) and ext.cFree3 =b.cFree3)) and
  1687. ((LEN(ISNULL(b.cFree4,''))<=0)or((LEN(ISNULL(b.cFree4,''))>0) and ext.cFree4 =b.cFree4)) and
  1688. ((LEN(ISNULL(b.cFree5,''))<=0)or((LEN(ISNULL(b.cFree5,''))>0) and ext.cFree5 =b.cFree5)) and
  1689. ((LEN(ISNULL(b.cFree6,''))<=0)or((LEN(ISNULL(b.cFree6,''))>0) and ext.cFree6 =b.cFree6)) and
  1690. ((LEN(ISNULL(b.cFree7,''))<=0)or((LEN(ISNULL(b.cFree7,''))>0) and ext.cFree7 =b.cFree7)) and
  1691. ((LEN(ISNULL(b.cFree8,''))<=0)or((LEN(ISNULL(b.cFree8,''))>0) and ext.cFree8 =b.cFree8)) and
  1692. ((LEN(ISNULL(b.cFree9,''))<=0)or((LEN(ISNULL(b.cFree9,''))>0) and ext.cFree9 =b.cFree9)) and
  1693. ((LEN(ISNULL(b.cFree10,''))<=0)or((LEN(ISNULL(b.cFree10,''))>0) and ext.cFree10 =b.cFree10)) order by a.mtime
  1694. BEGIN
  1695. DECLARE @transSequence VARCHAR(50);--
  1696. DECLARE @qty decimal(18, 4);--
  1697. DECLARE @needqty decimal(18, 4);--
  1698. DECLARE @lotno VARCHAR(50);--
  1699. DECLARE @locationcode VARCHAR(50);--
  1700. DECLARE @WHCode VARCHAR(50);--
  1701. DECLARE @invcode VARCHAR(50);--
  1702. DECLARE @mtime DATE;
  1703. DECLARE @issueQuantity decimal(18, 4);
  1704. DECLARE tempCursor CURSOR FOR (select transSequence from #maintemp); --tempCursor
  1705. OPEN tempCursor; --
  1706. FETCH NEXT FROM tempCursor INTO @transSequence; --
  1707. WHILE @@fetch_status=0
  1708. BEGIN
  1709. select @needqty=Quantity,@issueQuantity=issueQuantity from #maintemp where transSequence = @transSequence
  1710. PRINT @transSequence
  1711. WHILE @needqty>0
  1712. BEGIN
  1713. select top 1 @qty = isnull(a.quantity,0), @locationcode = isnull(a.locationcode,''),@lotno = isnull(a.lotno,''),@WHCode = isnull(a.warehousecode,''),@mtime=a.mtime,@invcode = b.invcode from #barcodetemp a
  1714. right JOIN(select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp where transSequence=@transSequence)b on a.invcode = b.invcode
  1715. and ((isnull(b.ProjectCode,'')<>'' and b.ProjectCode = a.ProjectCode) or isnull(b.ProjectCode,'') ='') and
  1716. ((isnull(b.Version,'')<>'' and b.Version = a.Version) or isnull(b.Version,'') ='') and
  1717. ((isnull(b.Brand,'')<>'' and b.Brand = a.Brand )or isnull(b.Brand,'') ='') and
  1718. ((isnull(b.cFree1,'')<>'' and b.cFree1 =a.cFree1) or isnull(b.cFree1,'') ='') and
  1719. ((isnull(b.cFree2,'')<>'' and b.cFree2 =a.cFree2 )or isnull(b.cFree2,'') ='') and
  1720. ((isnull(b.cFree3,'')<>'' and b.cFree3 =a.cFree3 )or isnull(b.cFree3,'') ='') and
  1721. ((isnull(b.cFree4,'')<>'' and b.cFree4 =a.cFree4 )or isnull(b.cFree4,'') ='') and
  1722. ((isnull(b.cFree5,'')<>'' and b.cFree5 =a.cFree5) or isnull(b.cFree5,'') ='') and
  1723. ((isnull(b.cFree6,'')<>'' and b.cFree6 =a.cFree6 )or isnull(b.cFree6,'') ='') and
  1724. ((isnull(b.cFree7,'')<>'' and b.cFree7 =a.cFree7) or isnull(b.cFree7,'') ='') and
  1725. ((isnull(b.cFree8,'')<>'' and b.cFree8 =a.cFree8) or isnull(b.cFree8,'') ='') and
  1726. ((isnull(b.cFree9,'')<>'' and b.cFree9 =a.cFree9) or isnull(b.cFree9,'') ='') and
  1727. ((isnull(b.cFree10,'')<>'' and b.cFree10 =a.cFree10) or isnull(b.cFree10,'') ='') and
  1728. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =a.BatchCode) or isnull(b.BatchCode,'') ='')ORDER BY a.mtime,a.locationcode
  1729. IF(@needqty-@issueQuantity-@qty>=0 and ISNULL(@lotno, '')<>'')
  1730. BEGIN
  1731. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1732. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotNo,
  1733. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  1734. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1735. ISNULL(Amount, 0),[User],@mtime,InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),@qty,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  1736. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  1737. delete from #barcodetemp where lotno = @lotno
  1738. SET @needqty=@needqty-@qty
  1739. END
  1740. ELSE if(@needqty-@issueQuantity-@qty<0 and ISNULL(@lotno, '')<>''and @needqty-@issueQuantity>0)
  1741. BEGIN
  1742. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1743. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  1744. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  1745. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1746. ISNULL(Amount, 0),[User],@mtime,InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),case WHEN ISNULL(@qty, 0)=0 THEN 0 else @needqty-@issueQuantity end ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  1747. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  1748. update #barcodetemp set quantity = @qty-@needqty+-@issueQuantity where lotno = @lotno
  1749. SET @needqty=@needqty-@issueQuantity-@qty
  1750. END
  1751. ELSE
  1752. BEGIN
  1753. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1754. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  1755. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  1756. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1757. ISNULL(Amount, 0),[User],@mtime,InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),0 ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  1758. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  1759. SET @needqty=0
  1760. END
  1761. END
  1762. FETCH NEXT FROM tempCursor INTO @transSequence;
  1763. END
  1764. CLOSE tempCursor
  1765. DEALLOCATE tempCursor
  1766. END
  1767. select id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1768. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,sum(LocationQty)as LocationQty,isMatched,AmountUnit,LotNo,
  1769. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #resulttemp GROUP BY id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1770. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,isMatched,AmountUnit,LotNo,
  1771. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ORDER BY locationcode ASC ,InvCode ASC
  1772. DROP table #maintemp
  1773. DROP table #resulttemp
  1774. DROP table #barcodetemp";
  1775. }
  1776. #endregion
  1777. if (isDeliveryNotice)//送货、到货、含委外
  1778. {
  1779. #region SLQ
  1780. sql = sqlCheck + @"SELECT a.ID,
  1781. {0}
  1782. a.InvCode,
  1783. inv.InvName,
  1784. inv.InvStd,
  1785. inv.InvUnit,
  1786. '' AS WHCode,
  1787. inv.AmountUnit,
  1788. '' AS WHName,
  1789. a.ExtensionID,
  1790. ext.ProjectCode,
  1791. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  1792. ext.Version,
  1793. ext.Brand,
  1794. ext.cFree1,
  1795. ext.cFree2,
  1796. ext.cFree3,
  1797. ext.cFree4,
  1798. ext.cFree5,
  1799. ext.cFree6,
  1800. ext.cFree7,
  1801. ext.cFree8,
  1802. ext.cFree9,
  1803. ext.cFree10
  1804. FROM {1}
  1805. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1806. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1807. WHERE {2} ";
  1808. #endregion
  1809. }
  1810. else if(isMerge)//合并发料
  1811. {
  1812. #region SLQ
  1813. string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='"+ JsonData.TransCode + "' AND WorkPoint='"+ JsonData.WorkPoint + "'";
  1814. DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
  1815. if (sign != null && sign.Rows.Count > 0)
  1816. {
  1817. string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
  1818. sql = string.Format(sql, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, excessQtySql, invWhere);
  1819. }
  1820. else
  1821. {
  1822. sql = @" BEGIN
  1823. IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
  1824. BEGIN
  1825. RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
  1826. RETURN
  1827. END
  1828. " + sqlCheck + sql + @"
  1829. END";
  1830. }
  1831. #endregion
  1832. }
  1833. else
  1834. {
  1835. sql = sqlCheck + sql;
  1836. }
  1837. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint, whcode);
  1838. sql = excludeSql + sql;
  1839. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode, excessQtySql, invWhere);
  1840. sqls = string.Format(sqls, JsonData.TransCode, JsonData.WorkPoint);
  1841. Picksql = string.Format(Picksql,sqls,JsonData.WorkPoint);
  1842. //DataTable table2 = DBHelper.SQlReturnData(Picksql, cmd);
  1843. //return table2;
  1844. log.Debug("源头单据sql:" + sql);
  1845. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  1846. return table;
  1847. }
  1848. catch (Exception ex)
  1849. {
  1850. log.Error(ex.Message);
  1851. throw new Exception(ex.Message);
  1852. }
  1853. finally
  1854. {
  1855. if (conn.State == ConnectionState.Open)
  1856. {
  1857. conn.Close();
  1858. }
  1859. conn.Dispose();
  1860. }
  1861. }
  1862. }
  1863. #endregion
  1864. #region 源头单据检料表信息
  1865. /// <summary>
  1866. /// 源头单据信息
  1867. /// </summary>
  1868. /// <param name="JsonData"></param>
  1869. /// <returns></returns>
  1870. public static DataTable TransPickGet(WMSSourceDocumentModel JsonData)
  1871. {
  1872. var language = LanguageHelper.GetName("WMSAPIInfo");
  1873. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1874. {
  1875. conn.Open();
  1876. SqlCommand cmd = new SqlCommand();
  1877. cmd.Connection = conn;
  1878. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  1879. try
  1880. {
  1881. if (string.IsNullOrEmpty(JsonData.TransCode))
  1882. {
  1883. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1884. }
  1885. else if (string.IsNullOrEmpty(JsonData.TransType))
  1886. {
  1887. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  1888. }
  1889. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  1890. {
  1891. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  1892. }
  1893. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  1894. {
  1895. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  1896. }
  1897. string TransType = JsonData.TransType;
  1898. #region 原拣料SLQ
  1899. // string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1900. // c.Code,
  1901. // c.InvCode,
  1902. // c.InvName,
  1903. // c.InvStd,
  1904. //c.InvUnit,
  1905. // FLOOR(c.iQuantity) AS iQuantity,
  1906. // d.WarehouseCode,
  1907. // d.LocationCode,
  1908. // d.LotNO,
  1909. // FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1910. // CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1911. // FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1912. // FROM
  1913. // ({0}) c
  1914. // LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND ((LEN(ISNULL(c.WHCode,''))<=0) OR (LEN(ISNULL(c.WHCode,''))>0) AND c.WhCode=d.WarehouseCode) AND d.WorkPoint='{1}' AND d.Quantity>0
  1915. // left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1916. // LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  1917. //DECLARE @ItemCode VARCHAR(50),
  1918. // @QTY DECIMAL(18,3),
  1919. // @ItemCodeCurrent VARCHAR(50),
  1920. // @QTYCurrent DECIMAL(18,3),
  1921. // @iQuantityCurrent DECIMAL(18,3),
  1922. // @CanDelete BIT,
  1923. // @Row INT,
  1924. // @rowCurrent INT
  1925. //SET @Row = @@rowcount
  1926. //SET @rowCurrent=1
  1927. //SET @CanDelete=0
  1928. //SET @ItemCode=''
  1929. //WHILE @rowCurrent<=@Row
  1930. // BEGIN
  1931. // SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  1932. //PRINT(@rowCurrent)
  1933. // IF @ItemCode<>@ItemCodeCurrent
  1934. // BEGIN
  1935. // SET @ItemCode=@ItemCodeCurrent
  1936. // SET @QTY=0
  1937. // SET @CanDelete=0
  1938. // END
  1939. // IF @CanDelete=1
  1940. // BEGIN
  1941. // DELETE FROM #temp WHERE rowNo=@rowCurrent
  1942. // SET @rowCurrent += 1
  1943. // CONTINUE
  1944. // END
  1945. // SET @QTY += @QTYCurrent
  1946. // IF @QTY>=@iQuantityCurrent
  1947. // BEGIN
  1948. // SET @CanDelete=1
  1949. // END
  1950. // SET @rowCurrent += 1
  1951. // END
  1952. //SELECT * FROM #temp
  1953. //DROP TABLE #temp
  1954. //";
  1955. #endregion
  1956. #region SLQ
  1957. string Picksql = @" EXEC ICSPicking '{0}', '{1}','{2}', '{3}'";
  1958. #endregion
  1959. string sqls = string.Empty;
  1960. string type = string.Empty;
  1961. bool isMerge = true;
  1962. #region 检料表信息
  1963. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  1964. {
  1965. #region 工单备料sql
  1966. type = "1";
  1967. #endregion
  1968. }
  1969. if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
  1970. {
  1971. #region 工单备料(自动出库)sql
  1972. type = "1";
  1973. #endregion
  1974. }
  1975. if (TransType == TransTypeEnum.MOApply.GetDescription())
  1976. {
  1977. #region 工单领料SQL
  1978. type = "2";
  1979. #endregion
  1980. }
  1981. if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  1982. {
  1983. #region 工单补料SQL
  1984. type = "12";
  1985. #endregion
  1986. }
  1987. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  1988. {
  1989. #region 工单材料出库SQL
  1990. type = "3";
  1991. #endregion
  1992. }
  1993. if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  1994. {
  1995. #region 委外备料SQL
  1996. type = "4";
  1997. #endregion
  1998. }
  1999. if (TransType == TransTypeEnum.OOApply.GetDescription())
  2000. {
  2001. #region 委外领料SQL
  2002. type = "5";
  2003. #endregion
  2004. }
  2005. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2006. {
  2007. #region 委外材料出库SQL
  2008. type = "6";
  2009. #endregion
  2010. }
  2011. if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2012. {
  2013. #region 销售发货SQL
  2014. type = "7";
  2015. #endregion
  2016. }
  2017. if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2018. {
  2019. #region 其他出库SQL
  2020. type = "8";
  2021. #endregion
  2022. }
  2023. if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
  2024. {
  2025. #region 其他出库(自动出库)SQL
  2026. type = "8";
  2027. #endregion
  2028. }
  2029. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2030. {
  2031. #region 借用SQL
  2032. type = "9";
  2033. #endregion
  2034. }
  2035. if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  2036. {
  2037. #region 物料调拨
  2038. type = "10";
  2039. #endregion
  2040. }
  2041. if (TransType == TransTypeEnum.OneStepTransferDocAuto.GetDescription())
  2042. {
  2043. #region 物料调拨
  2044. type = "10";
  2045. #endregion
  2046. }
  2047. if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2048. {
  2049. #region 两步调出
  2050. type = "11";
  2051. #endregion
  2052. }
  2053. if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription())
  2054. {
  2055. #region 销售出库单
  2056. type = "16";
  2057. #endregion
  2058. }
  2059. if (isMerge)
  2060. {
  2061. string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='" + JsonData.TransCode + "' AND WorkPoint='" + JsonData.WorkPoint + "'";
  2062. DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
  2063. if (sign != null && sign.Rows.Count > 0)
  2064. {
  2065. isMerge = true;
  2066. }
  2067. else
  2068. {
  2069. isMerge = false;
  2070. }
  2071. }
  2072. #endregion
  2073. JsonData.TransCode="'"+ JsonData.TransCode + "'";
  2074. JsonData.TransCode = JsonData.TransCode.TrimEnd(',').Replace("'", "''");
  2075. Picksql = string.Format(Picksql, JsonData.TransCode, type, isMerge, JsonData.WorkPoint);
  2076. DataTable table = DBHelper.SQlReturnData(Picksql, cmd);
  2077. return table;
  2078. }
  2079. catch (Exception ex)
  2080. {
  2081. log.Error(ex.Message);
  2082. throw new Exception(ex.Message);
  2083. }
  2084. finally
  2085. {
  2086. if (conn.State == ConnectionState.Open)
  2087. {
  2088. conn.Close();
  2089. }
  2090. conn.Dispose();
  2091. }
  2092. }
  2093. }
  2094. #endregion
  2095. /// <summary>
  2096. /// 所有未完成单据号
  2097. /// </summary>
  2098. /// <param name="JsonData"></param>
  2099. /// <returns></returns>
  2100. public static DataTable TransCodeGet(WMSSourceDocumentModel JsonData)
  2101. {
  2102. var language = LanguageHelper.GetName("WMSAPIInfo");
  2103. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2104. {
  2105. conn.Open();
  2106. SqlCommand cmd = new SqlCommand();
  2107. cmd.Connection = conn;
  2108. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  2109. try
  2110. {
  2111. if (string.IsNullOrEmpty(JsonData.TransType))
  2112. {
  2113. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  2114. }
  2115. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  2116. {
  2117. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  2118. }
  2119. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  2120. {
  2121. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  2122. }
  2123. string TransType = JsonData.TransType;
  2124. #region SLQ
  2125. //string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  2126. // BEGIN
  2127. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  2128. // RETURN
  2129. // END
  2130. // ";
  2131. string sql = @"SELECT
  2132. {0},a.MTime
  2133. FROM {1}
  2134. WHERE {2}
  2135. order by {3}";
  2136. #endregion
  2137. bool isDeliveryNotice = false; //送货、到货、含委外
  2138. bool MOApplyWithBin = false; //生产领料-库位
  2139. bool OtherOutDocWithBin = false; //杂发-库位
  2140. string columns = string.Empty; //查询源头单据表的特殊列名
  2141. string tableName = string.Empty; //查询源头单据表名
  2142. string where = string.Empty; //查询源头单据的过滤条件
  2143. string orderby = string.Empty; //查询源头单据的排序方式
  2144. bool isMerge = false; //合并发料
  2145. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  2146. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  2147. #region 出库
  2148. #region 采购退货
  2149. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2150. {
  2151. columns = @" DISTINCT a.DNCode AS TransCode";
  2152. tableName = @"ICSDeliveryNotice a ";
  2153. where = @" a.WorkPoint='{1}' AND a.DNType='2' AND a.Status='2' AND (a.Quantity-a.RCVQuantity)>0";
  2154. orderby = @" a.MTIME DESC";
  2155. }
  2156. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription())
  2157. {
  2158. columns = @" DISTINCT a.DNCode AS TransCode";
  2159. tableName = @"ICSDeliveryNotice a ";
  2160. where = @" a.WorkPoint='{1}' AND a.DNType='2' AND a.Status='1' AND a.RCVQuantity>0";
  2161. orderby = @" a.MTIME DESC";
  2162. }
  2163. #endregion
  2164. #region 其他出库
  2165. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2166. {
  2167. columns = @" DISTINCT a.OutCode AS TransCode,a.MTIME";
  2168. tableName = @"ICSOtherOut a ";
  2169. where = @" a.Status='1' AND a.WorkPoint='{1}' and a.Quantity>ISNULL(a.OutQuantity, 0)";
  2170. orderby = @" a.MTIME DESC";
  2171. }
  2172. #endregion
  2173. #region 其他出库-自动出库
  2174. else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
  2175. {
  2176. columns = @" DISTINCT a.OutCode AS TransCode,a.MTIME";
  2177. tableName = @"ICSOtherOut a
  2178. INNER JOIN ICSInventory inv ON inv.InvCode=a.InvCode AND inv.WorkPoint=a.WorkPoint ";
  2179. where = @" a.Status='1' AND a.WorkPoint='{1}' and a.Quantity>ISNULL(a.OutQuantity, 0)";
  2180. where += DBHelper.SearchConditonGet("Trans_btnOtherOutAuto", JsonData.User, cmd);
  2181. orderby = @" a.MTIME DESC";
  2182. }
  2183. #endregion
  2184. #region 红字其他入库
  2185. else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
  2186. {
  2187. columns = @" DISTINCT a.InCode AS TransCode,a.MTIME";
  2188. tableName = @"ICSOtherIn a ";
  2189. where = @" a.Status='1' AND a.WorkPoint='{1}' and a.Quantity>a.InQuantity and a.EATTRIBUTE2='2'";
  2190. orderby = @" a.MTIME DESC";
  2191. }
  2192. #endregion
  2193. #region 一步调拨(合并发料)
  2194. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  2195. {
  2196. columns = @" DISTINCT a.TransferNO AS TransCode,a.MTIME";
  2197. tableName = @"ICSTransfer a ";
  2198. where = @" a.WorkPoint='{1}' AND a.Status='1' AND a.Quantity>a.TransferQuantity AND Type='1'";
  2199. orderby = @" a.MTIME DESC";
  2200. }
  2201. #endregion
  2202. #region 自动调拨
  2203. else if (TransType == TransTypeEnum.OneStepTransferDocAuto.GetDescription())
  2204. {
  2205. columns = @" DISTINCT a.TransferNO AS TransCode,a.MTIME";
  2206. tableName = @"ICSTransfer a
  2207. INNER JOIN ICSInventory inv ON inv.InvCode=a.InvCode AND inv.WorkPoint=a.WorkPoint ";
  2208. where = @" a.WorkPoint='{1}' AND a.Status='1' AND a.Quantity>a.TransferQuantity AND Type='1' ";
  2209. where += DBHelper.SearchConditonGet("Trans_btnInvTransAuto", JsonData.User, cmd);
  2210. orderby = @" a.MTIME DESC";
  2211. }
  2212. #endregion
  2213. #region 调拨申请单(合并发料)
  2214. else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
  2215. {
  2216. columns = @" DISTINCT a.TransferNO AS TransCode,a.MTIME";
  2217. tableName = @"ICSTransferApplication a ";
  2218. where = @" a.WorkPoint='{1}' AND a.Status='2' AND a.Quantity>a.TransferQuantity AND Type='1'";
  2219. orderby = @" a.MTIME DESC";
  2220. }
  2221. #endregion
  2222. #region 委外退料
  2223. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  2224. {
  2225. columns = @" DISTINCT a.OApplyNegCode AS TransCode,a.MTIME";
  2226. tableName = @"ICSOApplyNegDetail a
  2227. INNER JOIN ICSOApplyNeg d ON a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint";
  2228. where = @" a.WorkPoint='{1}' AND d.Status='1' AND a.Quantity>a.IssueNegQuantity AND d.Type='1'";
  2229. orderby = @" a.MTIME DESC";
  2230. }
  2231. #endregion
  2232. #region 生产发料(合并发料)
  2233. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2234. {
  2235. columns = @" DISTINCT b.MOCode AS TransCode,a.MTIME";
  2236. tableName = @" ICSMOPick a
  2237. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  2238. where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' and dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0";
  2239. orderby = @" a.MTIME DESC";
  2240. }
  2241. #endregion
  2242. #region 生产发料——自动出库
  2243. else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
  2244. {
  2245. columns = @" DISTINCT b.MOCode AS TransCode,b.MTIME";
  2246. tableName = @" ICSMOPick a
  2247. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  2248. INNER JOIN ICSInventory inv ON inv.InvCode=a.InvCode AND inv.WorkPoint=a.WorkPoint ";
  2249. where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' and dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'{2}', 2, 2,'')-ISNULL(a.IssueQuantity,0)>0";
  2250. where += DBHelper.SearchConditonGet("Trans_btnInvOutAuto", JsonData.User, cmd);
  2251. orderby = @" b.MTIME DESC";
  2252. }
  2253. #endregion
  2254. #region 开立材料出库(合并发料)
  2255. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2256. {
  2257. columns = @" DISTINCT a.IssueCode AS TransCode,a.MTIME";
  2258. tableName = @" ICSMOIssue a ";
  2259. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  2260. orderby = @" a.MTIME DESC";
  2261. }
  2262. #endregion
  2263. #region 生产发料-领料申请单
  2264. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  2265. {
  2266. columns = @" DISTINCT a.ApplyCode AS TransCode,a.MTIME";
  2267. tableName = @" ICSMOApply a";
  2268. where = @" a.Status='2' AND a.WorkPoint='{1}' and a.Quantity-a.IssueQuantity>0";
  2269. orderby = @" a.MTIME DESC";
  2270. }
  2271. #endregion
  2272. #region 开立委外材料出库(合并发料)
  2273. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2274. {
  2275. columns = @" DISTINCT a.IssueCode AS TransCode,a.MTIME";
  2276. tableName = @" ICSOIssue a ";
  2277. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  2278. orderby = @" a.MTIME DESC";
  2279. }
  2280. #endregion
  2281. #region 委外领料申请单发料(合并发料)
  2282. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  2283. {
  2284. columns = @" DISTINCT a.ApplyCode AS TransCode,a.MTIME";
  2285. tableName = @" ICSOApply a ";
  2286. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  2287. orderby = @" a.MTIME DESC";
  2288. }
  2289. #endregion
  2290. #region 委外发料(合并发料)
  2291. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription()|| TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
  2292. {
  2293. columns = @" DISTINCT b.OOCode AS TransCode,a.MTIME";
  2294. tableName = @" ICSOOPick a
  2295. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  2296. where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and a.EATTRIBUTE1<>'1' and a.Quantity-a.IssueQuantity>0";
  2297. orderby = @" a.MTIME DESC";
  2298. }
  2299. #endregion
  2300. #region 销售出库(合并发料)
  2301. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2302. {
  2303. columns = @" DISTINCT a.SDNCode AS TransCode,a.MTIME";
  2304. tableName = @"ICSSDN a ";
  2305. where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' and a.Quantity-a.SDNQuantity>0";
  2306. orderby = @" a.MTIME DESC";
  2307. }
  2308. #endregion
  2309. #region 销售出库(合并发料)
  2310. else if (TransType == TransTypeEnum.SalesBindCourierDoc.GetDescription())
  2311. {
  2312. columns = @" DISTINCT a.SDNCode AS TransCode,a.MTIME";
  2313. tableName = @"ICSSDN a ";
  2314. where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' and a.Quantity-a.SDNQuantity>0";
  2315. orderby = @" a.MTIME DESC";
  2316. }
  2317. #endregion
  2318. #region 销售出库-出库单(合并发料)
  2319. else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription())
  2320. {
  2321. columns = @" DISTINCT a.SSDCode AS TransCode,a.MTIME";
  2322. tableName = @"ICSSSD a ";
  2323. where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' and a.Quantity-a.SSDQuantity>0";
  2324. orderby = @" a.MTIME DESC";
  2325. }
  2326. #endregion
  2327. #region 盘点
  2328. else if (TransType == TransTypeEnum.Check.GetDescription())
  2329. {
  2330. columns = @" DISTINCT a.CheckCode AS TransCode,a.MTIME";
  2331. tableName = @"ICSCheck a ";
  2332. where = @" a.WorkPoint='{1}' ";
  2333. orderby = @" a.MTIME DESC";
  2334. }
  2335. #endregion
  2336. #endregion
  2337. #region 入库
  2338. #region 产成品入库-产成品入库单
  2339. else if (TransType == TransTypeEnum.ManufactureMESReceive.GetDescription())
  2340. {
  2341. columns = @" DISTINCT a.RCVCode AS TransCode,a.MTIME";
  2342. tableName = @"ICSManufactureReceive a ";
  2343. where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status='1' AND a.Quantity>ISNULL(a.RCVQuantity, 0)";
  2344. orderby = @" a.MTIME DESC";
  2345. }
  2346. #endregion
  2347. #endregion
  2348. else
  2349. {
  2350. //throw new Exception();
  2351. }
  2352. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint, enableCode);
  2353. sql = string.Format(sql, columns, tableName, where, orderby);
  2354. log.Debug("源头单据sql : " + sql);
  2355. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  2356. return table;
  2357. }
  2358. catch (Exception ex)
  2359. {
  2360. log.Error(ex.Message);
  2361. throw new Exception(ex.Message);
  2362. }
  2363. finally
  2364. {
  2365. if (conn.State == ConnectionState.Open)
  2366. {
  2367. conn.Close();
  2368. }
  2369. conn.Dispose();
  2370. }
  2371. }
  2372. }
  2373. /// <summary>
  2374. ///
  2375. /// </summary>
  2376. /// <param name="JsonData"></param>
  2377. /// <returns></returns>
  2378. public static DataTable SRMItemsGet(WMSSourceDocumentModel JsonData)
  2379. {
  2380. var language = LanguageHelper.GetName("WMSAPIInfo");
  2381. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2382. {
  2383. conn.Open();
  2384. SqlCommand cmd = new SqlCommand();
  2385. cmd.Connection = conn;
  2386. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  2387. try
  2388. {
  2389. if (string.IsNullOrEmpty(JsonData.TransType))
  2390. {
  2391. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  2392. }
  2393. string TransType = JsonData.TransType;
  2394. #region SLQ
  2395. string sql = @"SELECT
  2396. {0}
  2397. FROM {1}
  2398. WHERE {2}
  2399. ";
  2400. #endregion
  2401. string columns = string.Empty; //查询源头单据表的特殊列名
  2402. string tableName = string.Empty; //查询源头单据表名
  2403. string where = string.Empty; //查询源头单据的过滤条件
  2404. #region 出库
  2405. columns = @" DISTINCT its.F_define1 AS TransCode";
  2406. tableName = @" Sys_SRM_Items it
  2407. inner join Sys_SRM_ItemsDetail its on it.F_id = its.f_itemid ";
  2408. where = @" it.F_ENCODE='{0}' ";
  2409. where = string.Format(where, JsonData.TransType);
  2410. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode);
  2411. log.Debug("获取自定义档案: " + sql);
  2412. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  2413. return table;
  2414. #endregion
  2415. }
  2416. catch (Exception ex)
  2417. {
  2418. log.Error(ex.Message);
  2419. throw new Exception(ex.Message);
  2420. }
  2421. finally
  2422. {
  2423. if (conn.State == ConnectionState.Open)
  2424. {
  2425. conn.Close();
  2426. }
  2427. conn.Dispose();
  2428. }
  2429. }
  2430. }
  2431. #region 条码信息
  2432. /// <summary>
  2433. /// 条码信息
  2434. /// </summary>
  2435. /// <param name="JsonData"></param>
  2436. /// <returns></returns>
  2437. public static Result BarCodeInformationGet(BarCodeModel JsonData)
  2438. {
  2439. var language = LanguageHelper.GetName("WMSAPIInfo");
  2440. DataTable table = new DataTable();
  2441. DataTable ZLtable = new DataTable();
  2442. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2443. {
  2444. conn.Open();
  2445. SqlCommand cmd = new SqlCommand();
  2446. cmd.Connection = conn;
  2447. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  2448. try
  2449. {
  2450. string ScanType = DBHelper.ScanTypeCheck(JsonData.Code, JsonData.WorkPoint, cmd);
  2451. if (string.IsNullOrEmpty(JsonData.Code))
  2452. {
  2453. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  2454. }
  2455. else if (string.IsNullOrEmpty(JsonData.TransType))
  2456. {
  2457. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  2458. }
  2459. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  2460. {
  2461. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  2462. }
  2463. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  2464. {
  2465. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  2466. }
  2467. string TransType = JsonData.TransType;
  2468. string sql = "";
  2469. string LotTypesql = "";
  2470. string Losql = "";
  2471. string Printsql = "";
  2472. string sqlNew = "";
  2473. string LotType = "";
  2474. bool iszl = false;
  2475. string zlqty = "0";
  2476. bool needIns = ICSControlModeService.GetOrderIns(EnumHelper.GetDBValue(typeof(TransTypeEnum), TransType));
  2477. #region SLQ
  2478. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  2479. {
  2480. //Losql = @"SELECT a.ID,
  2481. // con.ContainerCode,
  2482. // con.ContainerName,
  2483. // a.LotNo,
  2484. // a.InvCode,
  2485. // inv.InvName,
  2486. // inv.InvStd,
  2487. // inv.InvUnit,
  2488. // inv.LotEnable,
  2489. // {0}
  2490. // inv.AmountUnit,
  2491. // ext.ID AS ExtensionID,
  2492. // ext.ProjectCode,
  2493. // ext.Version,
  2494. // ext.Brand,
  2495. // ext.cFree1,
  2496. // ext.cFree2,
  2497. // ext.cFree3,
  2498. // ext.cFree4,
  2499. // ext.cFree5,
  2500. // ext.cFree6,
  2501. // ext.cFree7,
  2502. // ext.cFree8,
  2503. // ext.cFree9,
  2504. // ext.cFree10,
  2505. // a.MUSER AS [User],
  2506. // a.MTIME AS [MTime]
  2507. // FROM {1}
  2508. // LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  2509. // LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  2510. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2511. // WHERE a.Quantity>0 and a.WorkPoint='{3}'";
  2512. Losql = @" DECLARE @wheresql VARCHAR(MAX)
  2513. DECLARE @groupsql VARCHAR(MAX)
  2514. DECLARE @aa VARCHAR(MAX)
  2515. DECLARE @bb VARCHAR(MAX)
  2516. DECLARE @cc VARCHAR(MAX)
  2517. DECLARE @dd VARCHAR(MAX)
  2518. DECLARE @b VARCHAR(MAX)
  2519. select @aa=id from ICSWareHouseLotInfo where LotNo='{2}'
  2520. IF @aa IS NOT NULL
  2521. BEGIN
  2522. set @wheresql='and a.lotno=''{2}'' and s.invcode IN(SELECT invcode FROM ICSWareHouseLotInfo where LotNo=''{2}'') and a.invcode=s.invcode '
  2523. set @groupsql=' group by lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
  2524. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME'
  2525. END
  2526. select @bb=id from ICSLocation where LocationCode='{2}'
  2527. IF @bb IS not NULL
  2528. BEGIN
  2529. set @wheresql='and a.locationcode=s.locationcode and a.LocationCode=''{2}'' '
  2530. set @groupsql = 'group by lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
  2531. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME'
  2532. END
  2533. select @cc=id from ICSInventory where invcode='{2}'
  2534. IF @cc IS not NULL
  2535. BEGIN
  2536. set @wheresql='and inv.invcode=''{2}'' and a.invcode=s.invcode '
  2537. set @groupsql='group by lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
  2538. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME'
  2539. END
  2540. select @dd=id from ICSInventory where InvStd LIKE '%{2}%'
  2541. IF @dd IS not NULL
  2542. BEGIN
  2543. set @wheresql='and inv.InvStd LIKE ''%{2}%'' '
  2544. set @groupsql='group by lot.ProductDate,ext.BatchCode,inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
  2545. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME'
  2546. END
  2547. IF @aa IS NULL and @bb IS NULL and @cc IS NULL and @dd IS NULL
  2548. BEGIN
  2549. RAISERROR('" + language.GetNameByCode("WMSAPIInfo478") + @"',16,1)
  2550. END
  2551. ELSE
  2552. BEGIN
  2553. set @b =
  2554. 'SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
  2555. inv.InvName,
  2556. inv.InvStd,
  2557. inv.InvUnit,
  2558. inv.LotEnable,lot.ProductDate,
  2559. a.WarehouseCode,a.LocationCode,a.Quantity as Qty,SUM(s.sumQty) sumQty,
  2560. inv.AmountUnit,
  2561. ext.ID AS ExtensionID,
  2562. ext.ProjectCode,
  2563. ext.BatchCode,
  2564. ext.Version,
  2565. ext.Brand,
  2566. ext.cFree1,
  2567. ext.cFree2,
  2568. ext.cFree3,
  2569. ext.cFree4,
  2570. ext.cFree5,
  2571. ext.cFree6,
  2572. ext.cFree7,
  2573. ext.cFree8,
  2574. ext.cFree9,
  2575. ext.cFree10,
  2576. a.MUSER AS [User],
  2577. a.MTIME AS [MTime]
  2578. FROM ICSWareHouseLotInfo a
  2579. LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  2580. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2581. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2582. LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint
  2583. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  2584. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  2585. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2586. WHERE a.Quantity>0 and a.WorkPoint=''{3}'' ' + @wheresql + @groupsql
  2587. END
  2588. exec(@b)
  2589. ";
  2590. }
  2591. else if (TransType == TransTypeEnum.CodePrint.GetDescription())
  2592. {
  2593. Printsql = @"select ISNULL(C.LotNo,'') AS LOTNO,ISNULL(B.InvCode,'') AS InvCode,ISNULL(d.InvName,'') AS INVNAME,ISNULL(d.InvStd,'') AS INVSTD,ISNULL(C.Quantity,0) AS LotQty,
  2594. ISNULL(c.MTIME,'') AS MTIME,ISNULL(f.VenCode,'') AS VenCode,ISNULL(h.VenName,'') AS cVenName,ISNULL(d.InvUnit,'') AS InvUnit,ISNULL(f.POCode,'') AS POCode,ISNULL(f.EATTRIBUTE4,'') AS EATTRIBUTE4,ISNULL(d.InvUnit,'') AS InvUnit,ISNULL(g.BatchCode,'') AS BatchCode from ICSInventoryLot B
  2595. left join ICSWareHouseLotInfo C ON B.LotNO=C.LotNO and B.WorkPoint=c.WorkPoint
  2596. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  2597. left join ICSInventoryLotDetail e on b.lotNo=e.LotNo and b.WorkPoint=e.WorkPoint
  2598. LEFT JOIN ICSPurchaseOrder f ON f.POCode=e.TransCode AND f.Sequence=e.TransSequence AND f.WorkPoint=e.WorkPoint
  2599. left join ICSVendor h on f.VenCode=h.VenCode and e.WorkPoint=h.WorkPoint
  2600. left join ICSExtension g on b.ExtensionID=g.ID and b.WorkPoint=g.WorkPoint
  2601. where B.LotNo='{2}' AND B.workpoint='{3}'
  2602. UNION ALL
  2603. select ISNULL(C.LotNo,'') AS LOTNO,ISNULL(B.InvCode,'') AS InvCode,ISNULL(d.InvName,'') AS INVNAME,ISNULL(d.InvStd,'') AS INVSTD,ISNULL(C.Quantity,0) AS LotQty,
  2604. ISNULL(c.MTIME,'') AS MTIME,'' AS VenCode,'' AS cVenName,d.InvUnit,'' AS POCode,'' AS EATTRIBUTE4,d.InvUnit,g.BatchCode from ICSInventoryLot B
  2605. left join ICSWareHouseLotInfo C ON B.LotNO=C.LotNO and B.WorkPoint=c.WorkPoint
  2606. left join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  2607. left join ICSInventoryLotDetail e on b.lotNo=e.LotNo and b.WorkPoint=e.WorkPoint
  2608. left join ICSExtension g on b.ExtensionID=g.ID and b.WorkPoint=g.WorkPoint
  2609. where B.LotNo='{2}' AND B.workpoint='{3}'
  2610. UNION ALL
  2611. select ISNULL(C.LotNo,'') AS LOTNO,ISNULL(B.InvCode,'') AS InvCode,ISNULL(d.InvName,'') AS INVNAME,ISNULL(d.InvStd,'') AS INVSTD,ISNULL(C.Quantity,0) AS LotQty,
  2612. ISNULL(c.MTIME,'') AS MTIME,ISNULL(f.VenCode,'') AS VenCode,ISNULL(h.VenName,'') AS cVenName,ISNULL(d.InvUnit,'') AS InvUnit,ISNULL(f.POCode,'') AS POCode,ISNULL(f.EATTRIBUTE4,'') AS EATTRIBUTE4,ISNULL(d.InvUnit,'') AS InvUnit,ISNULL(g.BatchCode,'') AS BatchCode from ICSInventoryLot B
  2613. inner join ICSWareHouseLotInfo C ON B.LotNO=C.LotNO and B.WorkPoint=c.WorkPoint
  2614. inner join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  2615. inner join ICSInventoryLotDetail e on b.lotNo=e.LotNo and b.WorkPoint=e.WorkPoint
  2616. inner JOIN ICSPurchaseOrder f ON f.POCode=e.TransCode AND f.Sequence=e.TransSequence AND f.WorkPoint=e.WorkPoint
  2617. inner join ICSVendor h on f.VenCode=h.VenCode and e.WorkPoint=h.WorkPoint
  2618. inner join ICSExtension g on b.ExtensionID=g.ID and b.WorkPoint=g.WorkPoint
  2619. where B.InvCode='{2}' AND B.workpoint='{3}'
  2620. UNION ALL
  2621. select ISNULL(C.LotNo,'') AS LOTNO,ISNULL(B.InvCode,'') AS InvCode,ISNULL(d.InvName,'') AS INVNAME,ISNULL(d.InvStd,'') AS INVSTD,ISNULL(C.Quantity,0) AS LotQty,
  2622. ISNULL(c.MTIME,'') AS MTIME,'' AS VenCode,'' AS cVenName,d.InvUnit,'' AS POCode,'' AS EATTRIBUTE4,d.InvUnit,g.BatchCode from ICSInventoryLot B
  2623. inner join ICSWareHouseLotInfo C ON B.LotNO=C.LotNO and B.WorkPoint=c.WorkPoint
  2624. inner join ICSInventory D on b.INVCODE=d.INVCODE and b.WorkPoint=d.WorkPoint
  2625. inner join ICSInventoryLotDetail e on b.lotNo=e.LotNo and b.WorkPoint=e.WorkPoint
  2626. inner join ICSExtension g on b.ExtensionID=g.ID and b.WorkPoint=g.WorkPoint
  2627. where B.InvCode='{2}' AND B.workpoint='{3}'
  2628. ";
  2629. }
  2630. else
  2631. {
  2632. //派纳调拨,不用站点条件
  2633. if (DBHelper.IsPNU9() && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  2634. {
  2635. if (ScanType == "LOTNO")
  2636. {
  2637. sql = @"SELECT a.ID,
  2638. con.ContainerCode,
  2639. con.ContainerName,
  2640. a.LotNo,
  2641. a.InvCode,
  2642. inv.InvName,
  2643. inv.InvStd,
  2644. inv.InvUnit,
  2645. inv.LotEnable,
  2646. {0}
  2647. inv.AmountUnit,
  2648. ext.ID AS ExtensionID,
  2649. ext.ProjectCode,
  2650. ext.Version,
  2651. --ext.BatchCode,
  2652. ext.Brand,
  2653. ext.cFree1,
  2654. ext.cFree2,
  2655. ext.cFree3,
  2656. ext.cFree4,
  2657. ext.cFree5,
  2658. ext.cFree6,
  2659. ext.cFree7,
  2660. ext.cFree8,
  2661. ext.cFree9,
  2662. ext.cFree10,
  2663. a.MUSER AS [User],
  2664. a.MTIME AS [MTime]
  2665. FROM {1}
  2666. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  2667. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  2668. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2669. WHERE a.LotNo='{2}' ";
  2670. }
  2671. else
  2672. {
  2673. sql = @"SELECT a.ID,
  2674. con.ContainerCode,
  2675. con.ContainerName,
  2676. a.LotNo,
  2677. a.InvCode,
  2678. inv.InvName,
  2679. inv.InvStd,
  2680. inv.InvUnit,
  2681. {0}
  2682. inv.AmountUnit,
  2683. ext.ID AS ExtensionID,
  2684. ext.ProjectCode,
  2685. ext.Version,
  2686. --ext.BatchCode,
  2687. ext.Brand,
  2688. ext.cFree1,
  2689. ext.cFree2,
  2690. ext.cFree3,
  2691. ext.cFree4,
  2692. ext.cFree5,
  2693. ext.cFree6,
  2694. ext.cFree7,
  2695. ext.cFree8,
  2696. ext.cFree9,
  2697. ext.cFree10,
  2698. a.MUSER AS [User],
  2699. a.MTIME AS [MTime]
  2700. FROM {1}
  2701. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  2702. LEFT JOIN ICSBomALL bom ON bom.ID=conlot.ContainerID
  2703. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  2704. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2705. WHERE bom.TContainerCode='{2}' ";
  2706. }
  2707. }
  2708. else
  2709. {
  2710. if (ScanType == "LOTNO")
  2711. {
  2712. sql = @"SELECT a.ID,
  2713. con.ContainerCode,
  2714. con.ContainerName,
  2715. a.LotNo,
  2716. a.InvCode,
  2717. inv.InvName,
  2718. inv.InvStd,
  2719. inv.InvUnit,
  2720. inv.LotEnable,
  2721. {0}
  2722. inv.AmountUnit,
  2723. ext.ID AS ExtensionID,
  2724. ext.ProjectCode,
  2725. ext.Version,
  2726. --ext.BatchCode,
  2727. ext.Brand,
  2728. ext.cFree1,
  2729. ext.cFree2,
  2730. ext.cFree3,
  2731. ext.cFree4,
  2732. ext.cFree5,
  2733. ext.cFree6,
  2734. ext.cFree7,
  2735. ext.cFree8,
  2736. ext.cFree9,
  2737. ext.cFree10,
  2738. a.MUSER AS [User],
  2739. a.MTIME AS [MTime]
  2740. FROM {1}
  2741. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  2742. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  2743. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2744. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' ";
  2745. }
  2746. else
  2747. {
  2748. sql = @"SELECT a.ID,
  2749. con.ContainerCode,
  2750. con.ContainerName,
  2751. a.LotNo,
  2752. a.InvCode,
  2753. inv.InvName,
  2754. inv.InvStd,
  2755. inv.InvUnit,
  2756. {0}
  2757. inv.AmountUnit,
  2758. ext.ID AS ExtensionID,
  2759. ext.ProjectCode,
  2760. ext.Version,
  2761. --ext.BatchCode,
  2762. ext.Brand,
  2763. ext.cFree1,
  2764. ext.cFree2,
  2765. ext.cFree3,
  2766. ext.cFree4,
  2767. ext.cFree5,
  2768. ext.cFree6,
  2769. ext.cFree7,
  2770. ext.cFree8,
  2771. ext.cFree9,
  2772. ext.cFree10,
  2773. a.MUSER AS [User],
  2774. a.MTIME AS [MTime]
  2775. FROM {1}
  2776. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  2777. LEFT JOIN ICSBomALL bom ON bom.ID=conlot.ContainerID
  2778. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  2779. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2780. WHERE bom.TContainerCode='{2}' AND a.WorkPoint='{3}' ";
  2781. }
  2782. }
  2783. }
  2784. #endregion
  2785. bool isOut = false; //出库标记
  2786. string columns = string.Empty; //查询源头单据表的特殊列名
  2787. string columnsLOCODE = string.Empty;
  2788. string columnsLONAME = string.Empty;
  2789. string columnsWHCODE = string.Empty;
  2790. string columnsWHNAME = string.Empty;
  2791. string tableName = string.Empty; //查询源头单据表名
  2792. string where = string.Empty; //排序
  2793. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription() //采购退货
  2794. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() //委外发料
  2795. || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription() //委外发料
  2796. || TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription() //委外退货
  2797. || TransType == TransTypeEnum.MOIssueDoc.GetDescription() //生产发料
  2798. || TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription() //生产发料——自动出库
  2799. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() //销售出库
  2800. || TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription() //销售出库
  2801. || TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription() //一步调拨
  2802. || TransType == TransTypeEnum.StepTransferDocIn.GetDescription() //调拨
  2803. || TransType == TransTypeEnum.StepNoTransferDocIn.GetDescription() //无源头调拨
  2804. || TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription() //调拨申请单
  2805. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() //两步调出
  2806. || TransType == TransTypeEnum.OtherOutDoc.GetDescription() //其他出库
  2807. || TransType == TransTypeEnum.OtherInRedDoc.GetDescription() //红字其他入库
  2808. || TransType == TransTypeEnum.Check.GetDescription() //盘点
  2809. || TransType == TransTypeEnum.MOApply.GetDescription() //领料申请单
  2810. || TransType == TransTypeEnum.MOReplenishment.GetDescription() //领料申请单
  2811. || TransType == TransTypeEnum.OOApply.GetDescription() //委外领料申请单
  2812. || TransType == TransTypeEnum.MOIssue.GetDescription() //开立材料出库单
  2813. || TransType == TransTypeEnum.OOIssue.GetDescription() //开立委外材料出库单
  2814. || TransType == TransTypeEnum.PurchaseReceive.GetDescription() //开立红字入库单
  2815. || TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription()//开立委外红字入库单
  2816. || TransType == TransTypeEnum.BrrowDoc.GetDescription() //借用
  2817. || TransType == TransTypeEnum.TransferLibrary.GetDescription() //移库
  2818. || TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription() //移库
  2819. || TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription() //采购退货-采购订单
  2820. || TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription() //委外退货-委外采购订单
  2821. //|| TransType == TransTypeEnum.DisassemblyDoc.GetDescription() //拆卸单(散件生成条码入库)
  2822. )
  2823. {
  2824. isOut = true;
  2825. }
  2826. //库位查询
  2827. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  2828. {
  2829. // Losql = @"" + Losql + "group by a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,s.sumQty,inv.AmountUnit,ext.ID,ext.ProjectCode,ext.Version,ext.Brand, " +
  2830. // "ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME";
  2831. // columns = @"s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,sum(a.Quantity) as Qty,s.sumQty,";
  2832. // tableName = @"ICSWareHouseLotInfo a
  2833. //LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  2834. //INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2835. //INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2836. //LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode from ICSWareHouseLotInfo group by WarehouseCode,INVCode)s
  2837. //ON a.INVCode=s.INVCode ";
  2838. }
  2839. //库位查询
  2840. else if (TransType == TransTypeEnum.CodePrint.GetDescription())
  2841. {
  2842. }
  2843. else
  2844. {
  2845. //两步调入条码
  2846. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  2847. {
  2848. if (string.IsNullOrEmpty(JsonData.TransCode))
  2849. {
  2850. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2851. }
  2852. if (ScanType == "LOTNO")
  2853. {
  2854. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSOtherIn Otin
  2855. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  2856. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  2857. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  2858. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2859. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND Otin.InCode = '" + JsonData.TransCode + @"')
  2860. BEGIN
  2861. RAISERROR('" + language.GetNameByCode("WMSAPIInfo036") + @"',16,1);
  2862. RETURN
  2863. END
  2864. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  2865. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  2866. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  2867. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  2868. columns = @"SUM(log.Quantity) AS Quantity,
  2869. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  2870. a.WarehouseCode AS WHCode,
  2871. wh.WarehouseName AS WHName,
  2872. a.LocationCode,
  2873. loc.LocationName,
  2874. 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,";
  2875. tableName = @"ICSOtherIn Otin
  2876. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  2877. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  2878. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  2879. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2880. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2881. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2882. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2883. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2884. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2885. }
  2886. else
  2887. {
  2888. sql = @"WITH ICSBomALL AS
  2889. (
  2890. SELECT
  2891. ContainerCode AS TContainerCode,
  2892. ContainerCode AS PContainerCode,
  2893. ContainerCode AS ContainerCode,
  2894. ID,
  2895. ContainerID,
  2896. 0 AS [Level],
  2897. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  2898. CAST('00001' AS nvarchar(MAX)) AS Sort
  2899. FROM ICSContainer
  2900. WHERE ContainerCode='{2}'
  2901. UNION ALL
  2902. SELECT
  2903. b.TContainerCode,
  2904. b.ContainerCode AS PContainerCode,
  2905. a.ContainerCode,
  2906. a.ID,
  2907. a.ContainerID,
  2908. b.[Level]+1 AS [Level],
  2909. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  2910. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  2911. FROM
  2912. ICSContainer a
  2913. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  2914. )
  2915. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  2916. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  2917. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  2918. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  2919. columns = @"SUM(log.Quantity) AS Quantity,
  2920. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  2921. a.WarehouseCode AS WHCode,
  2922. wh.WarehouseName AS WHName,
  2923. a.LocationCode,
  2924. loc.LocationName,
  2925. 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,";
  2926. tableName = @"ICSOtherIn Otin
  2927. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  2928. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  2929. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  2930. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2931. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2932. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2933. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2934. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2935. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2936. }
  2937. }
  2938. //销售退货-原条码(可支持一个条码多次发货,汇总数量,目前加了限制:785-793行)
  2939. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  2940. {
  2941. if (string.IsNullOrEmpty(JsonData.TransCode))
  2942. {
  2943. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2944. }
  2945. if (ScanType == "LOTNO")
  2946. {
  2947. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSSDN sdn
  2948. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  2949. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2950. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1')
  2951. BEGIN
  2952. RAISERROR('" + language.GetNameByCode("WMSAPIInfo037") + @"',16,1);
  2953. RETURN
  2954. END
  2955. IF EXISTS(SELECT log.LotNo FROM ICSSDN sdn
  2956. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  2957. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2958. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1' AND log.BusinessCode='19'
  2959. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  2960. BEGIN
  2961. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo191"), "{2}") + @"',16,1);
  2962. RETURN
  2963. END
  2964. " + sql + @"AND sdn.Type='1'
  2965. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  2966. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  2967. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  2968. columns = @"SUM(log.Quantity) AS Quantity,
  2969. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  2970. a.WarehouseCode AS WHCode,
  2971. wh.WarehouseName AS WHName,
  2972. a.LocationCode,
  2973. loc.LocationName,
  2974. 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,";
  2975. tableName = @"ICSSDN sdn
  2976. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  2977. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2978. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2979. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2980. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2981. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2982. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2983. }
  2984. else
  2985. {
  2986. sql = @"WITH ICSBomALL AS
  2987. (
  2988. SELECT
  2989. ContainerCode AS TContainerCode,
  2990. ContainerCode AS PContainerCode,
  2991. ContainerCode AS ContainerCode,
  2992. ID,
  2993. ContainerID,
  2994. 0 AS [Level],
  2995. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  2996. CAST('00001' AS nvarchar(MAX)) AS Sort
  2997. FROM ICSContainer
  2998. WHERE ContainerCode='{2}'
  2999. UNION ALL
  3000. SELECT
  3001. b.TContainerCode,
  3002. b.ContainerCode AS PContainerCode,
  3003. a.ContainerCode,
  3004. a.ID,
  3005. a.ContainerID,
  3006. b.[Level]+1 AS [Level],
  3007. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  3008. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  3009. FROM
  3010. ICSContainer a
  3011. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  3012. )
  3013. " + sql + @"AND sdn.Type='1'
  3014. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  3015. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  3016. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  3017. columns = @"SUM(log.Quantity) AS Quantity,
  3018. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  3019. a.WarehouseCode AS WHCode,
  3020. wh.WarehouseName AS WHName,
  3021. a.LocationCode,
  3022. loc.LocationName,
  3023. 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,";
  3024. tableName = @"ICSSDN sdn
  3025. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  3026. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  3027. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3028. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3029. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  3030. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  3031. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  3032. }
  3033. }
  3034. //销售出库红字出库单-原条码(可支持一个条码多次发货,汇总数量,目前加了限制:785-793行)
  3035. else if (TransType == TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription())
  3036. {
  3037. if (string.IsNullOrEmpty(JsonData.TransCode))
  3038. {
  3039. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3040. }
  3041. if (ScanType == "LOTNO")
  3042. {
  3043. sql = @"IF NOT EXISTS(SELECT log.ID FROM ICSWareHouseLotInfoLog log
  3044. WHERE log.LotNo='{2}' AND log.WorkPoint='{3}' AND log.BusinessCode IN ('19','55'))
  3045. BEGIN
  3046. RAISERROR('" + language.GetNameByCode("WMSAPIInfo037") + @"',16,1);
  3047. RETURN
  3048. END
  3049. IF EXISTS(SELECT log.LotNo FROM ICSWareHouseLotInfoLog log
  3050. WHERE log.LotNo='{2}' AND log.WorkPoint='{3}' AND log.BusinessCode IN ('19','55')
  3051. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  3052. BEGIN
  3053. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo191"), "{2}") + @"',16,1);
  3054. RETURN
  3055. END
  3056. " + sql + @" AND log.BusinessCode IN ('19','55')
  3057. GROUP BY inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  3058. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  3059. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  3060. columns = @"SUM(log.Quantity) AS Quantity,
  3061. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  3062. a.WarehouseCode AS WHCode,
  3063. wh.WarehouseName AS WHName,
  3064. a.LocationCode,
  3065. loc.LocationName,
  3066. log.ID AS LogID,
  3067. 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,";
  3068. tableName = @" ICSWareHouseLotInfoLog log
  3069. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  3070. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3071. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3072. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  3073. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  3074. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  3075. }
  3076. else
  3077. {
  3078. sql = @"WITH ICSBomALL AS
  3079. (
  3080. SELECT
  3081. ContainerCode AS TContainerCode,
  3082. ContainerCode AS PContainerCode,
  3083. ContainerCode AS ContainerCode,
  3084. ID,
  3085. ContainerID,
  3086. 0 AS [Level],
  3087. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  3088. CAST('00001' AS nvarchar(MAX)) AS Sort
  3089. FROM ICSContainer
  3090. WHERE ContainerCode='{2}'
  3091. UNION ALL
  3092. SELECT
  3093. b.TContainerCode,
  3094. b.ContainerCode AS PContainerCode,
  3095. a.ContainerCode,
  3096. a.ID,
  3097. a.ContainerID,
  3098. b.[Level]+1 AS [Level],
  3099. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  3100. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  3101. FROM
  3102. ICSContainer a
  3103. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  3104. )
  3105. " + sql + @"AND log.BusinessCode IN ('19','55')
  3106. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  3107. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  3108. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  3109. columns = @"SUM(log.Quantity) AS Quantity,
  3110. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  3111. a.WarehouseCode AS WHCode,
  3112. wh.WarehouseName AS WHName,
  3113. a.LocationCode,
  3114. loc.LocationName,
  3115. 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,";
  3116. tableName = @" ICSWareHouseLotInfoLog log
  3117. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  3118. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3119. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3120. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  3121. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  3122. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  3123. }
  3124. }
  3125. //生产(委外)退料-原条码+新条码
  3126. //先校验日志里面是否有原条码(同一种类型的条码只能发一次料才能原条码退,不然更新源头单据数量有问题,根据LogID判断是否原条码退回),如果没有查询新条码
  3127. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  3128. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  3129. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription()
  3130. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  3131. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  3132. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  3133. {
  3134. string type = "13";
  3135. string msglanguage = "WMSAPIInfo185";
  3136. if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  3137. {
  3138. type = "14";
  3139. msglanguage = "WMSAPIInfo186";
  3140. }
  3141. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  3142. {
  3143. type = "15";
  3144. msglanguage = "WMSAPIInfo187";
  3145. }
  3146. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  3147. {
  3148. type = "5";
  3149. msglanguage = "WMSAPIInfo188";
  3150. }
  3151. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  3152. {
  3153. type = "6";
  3154. msglanguage = "WMSAPIInfo189";
  3155. }
  3156. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  3157. {
  3158. type = "7";
  3159. msglanguage = "WMSAPIInfo190";
  3160. }
  3161. #region 新条码
  3162. if (ScanType == "LOTNO")
  3163. {
  3164. sqlNew = @"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  3165. BEGIN
  3166. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  3167. RETURN
  3168. END
  3169. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  3170. BEGIN
  3171. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  3172. RETURN
  3173. END
  3174. " + sql;
  3175. //东辉生产退料不需要检验 先注释
  3176. // IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  3177. // INNER JOIN ICSInventory b ON a.InvCode = b.InvCode AND a.WorkPoint = b.WorkPoint
  3178. // LEFT JOIN ICSInspection ins ON a.LotNo = ins.LotNo AND a.WorkPoint = ins.WorkPoint
  3179. // WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}' AND(b.InvIQC = '1'AND ins.LotNo IS NULL))
  3180. // BEGIN
  3181. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"', 16, 1);
  3182. // RETURN
  3183. //END
  3184. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  3185. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  3186. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  3187. {
  3188. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  3189. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  3190. (select negg.WHCode from ICSMOApplyNegDetail neg
  3191. INNER JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  3192. inner join ICSInventoryLotDetail lotdetail on neg.ApplyNegCode=lotdetail.TransCode
  3193. and neg.Sequence=lotdetail.TransSequence
  3194. where lotdetail.LotNo=a.LotNo and lotdetail.WorkPoint=a.WorkPoint) AS WHCode,
  3195. '' AS WHName,
  3196. '' AS LocationCode,
  3197. '' AS LocationName,
  3198. '' AS LogID,
  3199. ext.BatchCode AS BatchCode,";
  3200. }
  3201. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  3202. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  3203. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  3204. {
  3205. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  3206. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  3207. (select negg.WHCode from ICSOApplyNegDetail neg
  3208. INNER JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  3209. inner join ICSInventoryLotDetail lotdetail on neg.OApplyNegCode=lotdetail.TransCode
  3210. and neg.Sequence=lotdetail.TransSequence
  3211. where lotdetail.LotNo=a.LotNo and lotdetail.WorkPoint=a.WorkPoint) AS WHCode,
  3212. '' AS WHName,
  3213. '' AS LocationCode,
  3214. '' AS LocationName,
  3215. '' AS LogID,
  3216. ext.BatchCode AS BatchCode,";
  3217. }
  3218. tableName = @"ICSInventoryLot a
  3219. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3220. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1 ";
  3221. }
  3222. else
  3223. {
  3224. sqlNew = @"WITH ICSBomALL AS
  3225. (
  3226. SELECT
  3227. ContainerCode AS TContainerCode,
  3228. ContainerCode AS PContainerCode,
  3229. ContainerCode AS ContainerCode,
  3230. ID,
  3231. ContainerID,
  3232. 0 AS [Level],
  3233. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  3234. CAST('00001' AS nvarchar(MAX)) AS Sort
  3235. FROM ICSContainer
  3236. WHERE ContainerCode='{2}'
  3237. UNION ALL
  3238. SELECT
  3239. b.TContainerCode,
  3240. b.ContainerCode AS PContainerCode,
  3241. a.ContainerCode,
  3242. a.ID,
  3243. a.ContainerID,
  3244. b.[Level]+1 AS [Level],
  3245. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  3246. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  3247. FROM
  3248. ICSContainer a
  3249. INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
  3250. )
  3251. " + sql;
  3252. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  3253. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  3254. '' AS WHCode,
  3255. '' AS WHName,
  3256. '' AS LocationCode,
  3257. '' AS LocationName,
  3258. ext.BatchCode AS BatchCode,";
  3259. tableName = @"ICSInventoryLot a
  3260. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3261. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
  3262. }
  3263. sqlNew = string.Format(sqlNew, columns, tableName, JsonData.Code, JsonData.WorkPoint, zlqty);
  3264. #endregion
  3265. #region 原条码
  3266. if (ScanType == "LOTNO")
  3267. {
  3268. sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  3269. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN(invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')= '1') OR ISNULL(invBat.BatchEnable, '0')= '1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  3270. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME
  3271. ";
  3272. sql = @"IF EXISTS(" + sql + @")
  3273. BEGIN
  3274. " + sql + @"
  3275. END
  3276. ELSE
  3277. BEGIN
  3278. " + sqlNew + @"
  3279. END";
  3280. sql = @"IF EXISTS(SELECT log.LotNo FROM ICSWareHouseLotInfoLog log
  3281. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  3282. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND log.BusinessCode='" + type + @"'
  3283. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  3284. BEGIN
  3285. RAISERROR('" + string.Format(language.GetNameByCode(msglanguage), "{2}") + @"',16,1);
  3286. RETURN
  3287. END
  3288. " + sql;
  3289. columns = @"SUM(log.Quantity) AS Quantity,
  3290. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  3291. a.WarehouseCode AS WHCode,
  3292. wh.WarehouseName AS WHName,
  3293. a.LocationCode,
  3294. loc.LocationName,
  3295. log.ID AS LogID,
  3296. 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,";
  3297. tableName = @"ICSWareHouseLotInfoLog log
  3298. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  3299. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3300. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3301. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  3302. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  3303. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  3304. }
  3305. else
  3306. {
  3307. sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  3308. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN(invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')= '1') OR ISNULL(invBat.BatchEnable, '0')= '1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  3309. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME
  3310. ";
  3311. sql = @"IF EXISTS(" + sql + @")
  3312. BEGIN
  3313. " + sql + @"
  3314. END
  3315. ELSE
  3316. BEGIN
  3317. " + sqlNew + @"
  3318. END";
  3319. sql = @"WITH ICSBomALL AS
  3320. (
  3321. SELECT
  3322. ContainerCode AS TContainerCode,
  3323. ContainerCode AS PContainerCode,
  3324. ContainerCode AS ContainerCode,
  3325. ID,
  3326. ContainerID,
  3327. 0 AS [Level],
  3328. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  3329. CAST('00001' AS nvarchar(MAX)) AS Sort
  3330. FROM ICSContainer
  3331. WHERE ContainerCode='{2}'
  3332. UNION ALL
  3333. SELECT
  3334. b.TContainerCode,
  3335. b.ContainerCode AS PContainerCode,
  3336. a.ContainerCode,
  3337. a.ID,
  3338. a.ContainerID,
  3339. b.[Level]+1 AS [Level],
  3340. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  3341. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  3342. FROM
  3343. ICSContainer a
  3344. INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
  3345. )
  3346. " + sql;
  3347. columns = @"SUM(log.Quantity) AS Quantity,
  3348. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  3349. a.WarehouseCode AS WHCode,
  3350. wh.WarehouseName AS WHName,
  3351. a.LocationCode,
  3352. loc.LocationName,
  3353. log.ID AS LogID,
  3354. 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,";
  3355. tableName = @"ICSWareHouseLotInfoLog log
  3356. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  3357. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3358. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3359. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  3360. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  3361. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  3362. }
  3363. #endregion
  3364. }
  3365. //分批
  3366. else if (TransType == TransTypeEnum.LOTSplit.GetDescription() || TransType == TransTypeEnum.LOTMerge.GetDescription())
  3367. {
  3368. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  3369. BEGIN
  3370. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  3371. RETURN
  3372. END
  3373. " + sql;
  3374. columns = @"a.Quantity,
  3375. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  3376. a.WarehouseCode AS WHCode,
  3377. wh.WarehouseName AS WHName,
  3378. a.LocationCode,
  3379. loc.LocationName,
  3380. 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,
  3381. ISNULL(split.SplitLotNo, a.LotNo+'-1') AS SplitLotNo,";
  3382. tableName = @"ICSWareHouseLotInfo a
  3383. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3384. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3385. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  3386. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  3387. LEFT JOIN (SELECT EATTRIBUTE1 AS LotNo,WorkPoint,EATTRIBUTE1+'-'+CAST((MAX(CAST(reverse(substring(reverse(LotNo),1,charindex('-',reverse(LotNo)) - 1)) AS INT))) AS VARCHAR) AS SplitLotNo FROM ICSInventoryLot GROUP BY EATTRIBUTE1,WorkPoint) split ON a.LotNo=split.LotNo AND a.WorkPoint=split.WorkPoint
  3388. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  3389. }
  3390. //出库条码
  3391. else if (isOut)
  3392. {
  3393. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() || TransType == TransTypeEnum.MOApply.GetDescription()
  3394. || TransType == TransTypeEnum.MOIssue.GetDescription() || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription()
  3395. || TransType == TransTypeEnum.OOApply.GetDescription() || TransType == TransTypeEnum.OOIssue.GetDescription()
  3396. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() || TransType == TransTypeEnum.OtherOutDoc.GetDescription()
  3397. || TransType == TransTypeEnum.BrrowDoc.GetDescription() || TransType == TransTypeEnum.StepTransferDocIn.GetDescription()
  3398. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() || TransType == TransTypeEnum.MOReplenishment.GetDescription()
  3399. || TransType == TransTypeEnum.OtherInRedDoc.GetDescription() || TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription()
  3400. || TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription())
  3401. {
  3402. if (JsonData.IsPick!="1")
  3403. {
  3404. ZLtable = ICSControlModeService.GetZL();
  3405. if (ZLtable == null)
  3406. {
  3407. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  3408. }
  3409. for (int i = 0; i < ZLtable.Rows.Count; i++)
  3410. {
  3411. string zlName = ZLtable.Rows[i]["Name"].ToString();
  3412. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  3413. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  3414. if (JsonData.TransType.Equals(zlName))
  3415. {
  3416. if (Enable.Equals("True"))
  3417. {
  3418. if (JsonData.TransCode.Contains("~"))
  3419. {
  3420. JsonData.TransCode = JsonData.TransCode.Substring(0, JsonData.TransCode.IndexOf('~'));
  3421. }
  3422. string zlsql = @"IF NOT EXISTS(select a.Quantity from ICSWareHouseLotInfoLog a
  3423. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
  3424. --left join ICSType c on a.BusinessCode=c.Code and c.tablecode='ICSWareHouseLotInfoLog' and c.ColumnCode='BusinessCode'
  3425. where b.LotNo='{0}' and b.WorkPoint='{1}' and a.TransType='15' and (a.TransCode='{3}' or a.MergeID='{3}') and isnull(a.EATTRIBUTE2,'')<>'1')
  3426. BEGIN
  3427. RAISERROR('" + language.GetNameByCode("WMSAPIInfo469") + @"',16,1);
  3428. RETURN
  3429. END
  3430. select sum(a.Quantity) AS Quantity from ICSWareHouseLotInfoLog a
  3431. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
  3432. --left join ICSType c on a.BusinessCode=c.Code and c.tablecode='ICSWareHouseLotInfoLog' and c.ColumnCode='BusinessCode'
  3433. where b.LotNo='{0}' and b.WorkPoint='{1}' and a.TransType='15' and (a.TransCode='{3}' or a.MergeID='{3}') and isnull(a.EATTRIBUTE2,'')<>'1'";
  3434. zlsql = string.Format(zlsql, JsonData.Code, JsonData.WorkPoint, JsonData.TransType, JsonData.TransCode);
  3435. DataTable zlltable = DBHelper.SQlReturnData(zlsql, cmd);
  3436. if (zlltable != null || zlltable.Rows.Count > 0)
  3437. {
  3438. zlqty = zlltable.Rows[0]["Quantity"].ToString();
  3439. iszl = true;
  3440. }
  3441. }
  3442. }
  3443. }
  3444. }
  3445. }
  3446. if (ScanType == "LOTNO")
  3447. {
  3448. //东辉盘点 判断是否存在于子表
  3449. if (TransType == TransTypeEnum.Check.GetDescription())
  3450. {
  3451. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  3452. BEGIN
  3453. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  3454. RETURN
  3455. END
  3456. IF NOT EXISTS(SELECT a.ID FROM ICSCheckDetail a inner join ICSCheck b on a.CheckID = b.id WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND b.CheckCode = '{5}')
  3457. BEGIN
  3458. RAISERROR('',16,1);
  3459. RETURN
  3460. END
  3461. " + sql;
  3462. }
  3463. else //原逻辑
  3464. {
  3465. if(DBHelper.IsPNU9()&& TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  3466. {
  3467. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.Quantity>0)
  3468. BEGIN
  3469. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  3470. RETURN
  3471. END
  3472. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.Quantity>0 AND a.Freeze='1')
  3473. BEGIN
  3474. RAISERROR('',16,1);
  3475. RETURN
  3476. END
  3477. " + sql;
  3478. }
  3479. else
  3480. {
  3481. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  3482. BEGIN
  3483. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  3484. RETURN
  3485. END
  3486. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0 AND a.Freeze='1')
  3487. BEGIN
  3488. RAISERROR('',16,1);
  3489. RETURN
  3490. END
  3491. " + sql;
  3492. }
  3493. log.Debug(sql);
  3494. }
  3495. if (iszl)
  3496. {
  3497. columns = @"{0} as Quantity,
  3498. {0}*(lot.Amount/lot.Quantity) AS Amount,
  3499. a.id AS LogID,
  3500. a.FromWarehouseCode AS WHCode,
  3501. wh.WarehouseName AS WHName,
  3502. inv.LotEnable,
  3503. a.FromLocationCode,
  3504. loc.LocationName,
  3505. 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,";
  3506. columns = string.Format(columns, zlqty);
  3507. tableName = @"ICSWareHouseLotInfoLog a
  3508. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint and a.transtype='15'
  3509. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3510. INNER JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  3511. INNER JOIN ICSLocation loc ON a.FromLocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  3512. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  3513. }
  3514. else
  3515. {
  3516. columns = @"(a.Quantity-a.lockQuantity) AS Quantity,
  3517. (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
  3518. '' AS LogID,
  3519. a.WarehouseCode AS WHCode,
  3520. wh.WarehouseName AS WHName,
  3521. inv.LotEnable,
  3522. a.LocationCode,
  3523. loc.LocationName,
  3524. 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,";
  3525. tableName = @"ICSWareHouseLotInfo a
  3526. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3527. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3528. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  3529. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  3530. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  3531. }
  3532. }
  3533. else
  3534. {
  3535. sql = @"
  3536. WITH ICSBomALL AS
  3537. (
  3538. SELECT
  3539. ContainerCode AS TContainerCode,
  3540. ContainerCode AS PContainerCode,
  3541. ContainerCode AS ContainerCode,
  3542. ID,
  3543. ContainerID,
  3544. 0 AS [Level],
  3545. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  3546. CAST('00001' AS nvarchar(MAX)) AS Sort
  3547. FROM ICSContainer
  3548. WHERE ContainerCode='{2}'
  3549. UNION ALL
  3550. SELECT
  3551. b.TContainerCode,
  3552. b.ContainerCode AS PContainerCode,
  3553. a.ContainerCode,
  3554. a.ID,
  3555. a.ContainerID,
  3556. b.[Level]+1 AS [Level],
  3557. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  3558. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  3559. FROM
  3560. ICSContainer a
  3561. INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
  3562. )
  3563. " + sql;
  3564. columns = @"(a.Quantity-a.lockQuantity) AS Quantity,
  3565. (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
  3566. a.WarehouseCode AS WHCode,
  3567. wh.WarehouseName AS WHName,
  3568. a.LocationCode,
  3569. loc.LocationName,
  3570. 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,";
  3571. tableName = @"ICSWareHouseLotInfo a
  3572. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  3573. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  3574. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  3575. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  3576. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  3577. ";
  3578. }
  3579. }
  3580. //入库条码
  3581. else
  3582. {
  3583. if (ScanType == "LOTNO")
  3584. {
  3585. if ((TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  3586. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  3587. || TransType == TransTypeEnum.MOStockINByProduct.GetDescription() || TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription()
  3588. || TransType == TransTypeEnum.OOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription()
  3589. ||TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription() || TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription()) && needIns)
  3590. {
  3591. sql = @"
  3592. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  3593. BEGIN
  3594. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  3595. RETURN
  3596. END
  3597. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  3598. BEGIN
  3599. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  3600. RETURN
  3601. END
  3602. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  3603. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  3604. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  3605. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1' AND ins.LotNo IS NULL))
  3606. BEGIN
  3607. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  3608. RETURN
  3609. END
  3610. " + sql;
  3611. }
  3612. else if ((TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription()
  3613. || TransType == TransTypeEnum.ManufactureMESReceive.GetDescription()) && needIns)
  3614. {
  3615. sql = @"
  3616. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  3617. BEGIN
  3618. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  3619. RETURN
  3620. END
  3621. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  3622. BEGIN
  3623. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  3624. RETURN
  3625. END
  3626. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  3627. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  3628. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  3629. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvFQC='1' AND ins.LotNo IS NULL))
  3630. BEGIN
  3631. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  3632. RETURN
  3633. END
  3634. " + sql;
  3635. }
  3636. else
  3637. {
  3638. sql = @"
  3639. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  3640. BEGIN
  3641. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  3642. RETURN
  3643. END
  3644. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  3645. BEGIN
  3646. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  3647. RETURN
  3648. END
  3649. " + sql;
  3650. }
  3651. ControlMode mode = ICSControlModeService.GetSuLocation();
  3652. //获取条码类型
  3653. LotTypesql = @"IF NOT EXISTS(SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}')
  3654. BEGIN
  3655. RAISERROR('" + language.GetNameByCode("WMSAPIInfo461") + @"',16,1);
  3656. RETURN
  3657. END
  3658. SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3659. LotTypesql = string.Format(LotTypesql, JsonData.Code, JsonData.WorkPoint);
  3660. DataTable dt = DBHelper.SQlReturnData(LotTypesql, cmd);
  3661. if (dt != null && dt.Rows.Count > 0)
  3662. {
  3663. LotType = dt.Rows[0]["Type"].ToString();
  3664. }
  3665. if (mode != null)
  3666. {
  3667. if (mode.itemCode.Equals("LocationRemind01"))//固定库位:物料和库位绑定,显示库位名称列表
  3668. {
  3669. columnsLONAME = @"
  3670. (SELECT locat.LocationName from ICSWareHouseLotInfo loinfo
  3671. LEFT JOIN ICSLocation locat on locat.LocationCode=loinfo.LocationCode and loinfo.WorkPoint=locat.WorkPoint
  3672. where loinfo.lotno=a.lotno and loinfo.invcode=a.invcode and a.WorkPoint=loinfo.WorkPoint) AS LocationName,";
  3673. columnsLOCODE = @"
  3674. (SELECT locat.LocationCode from ICSWareHouseLotInfo loinfo
  3675. LEFT JOIN ICSLocation locat on locat.LocationCode=loinfo.LocationCode and loinfo.WorkPoint=locat.WorkPoint
  3676. where loinfo.lotno=a.lotno and loinfo.invcode=a.invcode and a.WorkPoint=loinfo.WorkPoint) AS LocationCode,";
  3677. }
  3678. else if (mode.itemCode.Equals("LocationRemind02"))//在库库位:物料有库存的对应库位,显示库位名称列表
  3679. {
  3680. columnsLONAME = @"
  3681. STUFF(
  3682. (SELECT DISTINCT ',' + LocationName
  3683. from ICSLocation wh
  3684. LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
  3685. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
  3686. FOR xml path('')
  3687. ),1,1,''
  3688. ) AS LocationName,";
  3689. columnsLOCODE = @"
  3690. STUFF(
  3691. (SELECT DISTINCT ',' + LocationCode
  3692. from ICSLocation wh
  3693. LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
  3694. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
  3695. FOR xml path('')
  3696. ),1,1,''
  3697. ) AS LocationCode,";
  3698. }
  3699. else if (mode.itemCode.Equals("LocationRemind03"))//最近一次出入库的库位,显示库位名称
  3700. {
  3701. columnsLONAME = @"
  3702. (SELECT Top 1 locat.LocationName from ICSWareHouseLotInfoLog log
  3703. LEFT JOIN ICSLocation locat on locat.LocationCode=log.ToLocationCode and log.WorkPoint=locat.WorkPoint where log.TransType='2' and a.InvCode=log.InvCode AND a.WorkPoint=log.WorkPoint
  3704. ORDER BY log.Mtime desc) AS LocationName,";
  3705. columnsLOCODE = @"
  3706. (SELECT Top 1 locat.LocationCode from ICSWareHouseLotInfoLog log
  3707. LEFT JOIN ICSLocation locat on locat.LocationCode=log.ToLocationCode and log.WorkPoint=locat.WorkPoint where log.TransType='2' and a.InvCode=log.InvCode AND a.WorkPoint=log.WorkPoint
  3708. ORDER BY log.Mtime desc) AS LocationCode,";
  3709. }
  3710. }
  3711. else
  3712. {
  3713. columnsLONAME = @"
  3714. STUFF(
  3715. (SELECT DISTINCT ',' + LocationName
  3716. from ICSLocation wh
  3717. LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
  3718. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
  3719. FOR xml path('')
  3720. ),1,1,''
  3721. ) AS LocationName,";
  3722. columnsLOCODE = @"
  3723. STUFF(
  3724. (SELECT DISTINCT ',' + LocationCode
  3725. from ICSLocation wh
  3726. LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
  3727. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
  3728. FOR xml path('')
  3729. ),1,1,''
  3730. ) AS LocationCode,";
  3731. }
  3732. #region 根据条码类型找到单据仓库信息
  3733. if (LotType.Equals("1"))
  3734. {//生产退料
  3735. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  3736. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1'),'') AS WHCode";
  3737. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  3738. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
  3739. }
  3740. else if (LotType.Equals("2"))
  3741. {//委外退料
  3742. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  3743. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1'),'') AS WHCode";
  3744. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  3745. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
  3746. }
  3747. else if (LotType.Equals("3"))
  3748. {//工单
  3749. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSMO a WHERE a.MOCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
  3750. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSMO a WHERE a.MOCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
  3751. }
  3752. else if (LotType.Equals("4"))
  3753. {//销售退货
  3754. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSSDN a WHERE a.SDNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
  3755. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSSDN a WHERE a.SDNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
  3756. }
  3757. else if (LotType.Equals("5"))
  3758. {//其他入库
  3759. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSOtherIn a WHERE a.InCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
  3760. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSOtherIn a WHERE a.InCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
  3761. }
  3762. else if (LotType.Equals("6"))
  3763. {//归还单
  3764. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSReturn a WHERE a.ReturnCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
  3765. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSReturn a WHERE a.ReturnCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
  3766. }
  3767. else if (LotType.Equals("7"))
  3768. {//采购到货单
  3769. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='1'),'') AS WHCode";
  3770. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
  3771. }
  3772. else if (LotType.Equals("8"))
  3773. {//委外到货单
  3774. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='1'),'') AS WHCode";
  3775. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
  3776. }
  3777. else if (LotType.Equals("9"))
  3778. {//成品入库单
  3779. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSManufactureReceive a WHERE a.RCVCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
  3780. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSManufactureReceive a WHERE a.RCVCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
  3781. }
  3782. else if (LotType.Equals("10"))
  3783. {//拒收单
  3784. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='3'),'') AS WHCode";
  3785. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
  3786. }
  3787. else if (LotType.Equals("11"))
  3788. {//委外拒收单
  3789. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='3'),'') AS WHCode";
  3790. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
  3791. }
  3792. else if (LotType.Equals("12"))
  3793. {//领料申请退料
  3794. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  3795. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2'),'') AS WHCode";
  3796. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  3797. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2') AND WorkPoint=a.WorkPoint),'') AS WHName";
  3798. }
  3799. else if (LotType.Equals("13"))
  3800. {//材料出库退料
  3801. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  3802. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3'),'') AS WHCode";
  3803. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  3804. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
  3805. }
  3806. else if (LotType.Equals("14"))
  3807. {//委外领料申请退料
  3808. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  3809. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2'),'') AS WHCode";
  3810. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  3811. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2') AND WorkPoint=a.WorkPoint),'') AS WHName";
  3812. }
  3813. else if (LotType.Equals("15"))
  3814. {//委外材料出库退料
  3815. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  3816. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3'),'') AS WHCode";
  3817. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  3818. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
  3819. }
  3820. else if (LotType.Equals("16"))
  3821. {//返工工单
  3822. columnsWHCODE = @"ISNULL((SELECT pick.WHCode FROM ICSMOPick pick LEFT JOIN ICSMO moo ON pick.MODetailID=moo.MODetailID AND pick.WorkPoint=moo.WorkPoint
  3823. WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint),'') AS WHCode ";
  3824. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT pick.WHCode FROM ICSMOPick pick LEFT JOIN ICSMO moo ON pick.MODetailID=moo.MODetailID AND pick.WorkPoint=moo.WorkPoint
  3825. WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName ";
  3826. }
  3827. else
  3828. {
  3829. columnsWHCODE = @"'' AS WHCode";
  3830. columnsWHNAME = @"'' AS WHName";
  3831. }
  3832. #endregion
  3833. if ((TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  3834. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  3835. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription()
  3836. || TransType == TransTypeEnum.ManufactureReceive.GetDescription() || TransType == TransTypeEnum.OOStockINByProduct.GetDescription()
  3837. || TransType == TransTypeEnum.MOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription() || TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription()
  3838. || TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription() ||TransType == TransTypeEnum.ManufactureMESReceive.GetDescription()) && needIns)
  3839. {
  3840. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  3841. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  3842. {0},{2},
  3843. lotdd.TransCode,lotdd.TransSequence,
  3844. {3}
  3845. {1}
  3846. ext.BatchCode AS BatchCode,";
  3847. tableName = @"ICSInventoryLot a
  3848. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3849. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
  3850. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
  3851. }
  3852. else if(TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  3853. {
  3854. columns = @"a.Quantity AS Quantity,
  3855. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  3856. {0},{2},
  3857. {3}
  3858. {1}
  3859. ext.BatchCode AS BatchCode,
  3860. isnull(lotdd.TransCode,'') as TransCode,isnull(lotdd.TransSequence,'') as TransSequence,
  3861. sdn.SOCode,";
  3862. tableName = @"ICSInventoryLot a
  3863. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3864. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
  3865. INNER join ICSSDN sdn on lotdd.transcode=sdn.sdncode and lotdd.TransSequence=sdn.Sequence and lotdd.WorkPoint=sdn.WorkPoint";
  3866. }
  3867. else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
  3868. {
  3869. columns = @"a.Quantity AS Quantity,
  3870. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  3871. '','',
  3872. '',
  3873. '',
  3874. ext.BatchCode AS BatchCode,
  3875. isnull(lotdd.TransCode,'') as TransCode,isnull(lotdd.TransSequence,'') as TransSequence,";
  3876. tableName = @"ICSInventoryLot a
  3877. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3878. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint";
  3879. }
  3880. else
  3881. {
  3882. columns = @"a.Quantity AS Quantity,
  3883. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  3884. {0},{2},
  3885. {3}
  3886. {1}
  3887. ext.BatchCode AS BatchCode,
  3888. isnull(lotdd.TransCode,'') as TransCode,isnull(lotdd.TransSequence,'') as TransSequence,";
  3889. tableName = @"ICSInventoryLot a
  3890. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3891. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint";
  3892. }
  3893. columns = string.Format(columns, columnsWHCODE, columnsLONAME, columnsWHNAME, columnsLOCODE);
  3894. }
  3895. else
  3896. {
  3897. sql = @"
  3898. WITH ICSBomALL AS
  3899. (
  3900. SELECT
  3901. ContainerCode AS TContainerCode,
  3902. ContainerCode AS PContainerCode,
  3903. ContainerCode AS ContainerCode,
  3904. ID,
  3905. ContainerID,
  3906. 0 AS [Level],
  3907. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  3908. CAST('00001' AS nvarchar(MAX)) AS Sort
  3909. FROM ICSContainer
  3910. WHERE ContainerCode='{2}'
  3911. UNION ALL
  3912. SELECT
  3913. b.TContainerCode,
  3914. b.ContainerCode AS PContainerCode,
  3915. a.ContainerCode,
  3916. a.ID,
  3917. a.ContainerID,
  3918. b.[Level]+1 AS [Level],
  3919. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  3920. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  3921. FROM
  3922. ICSContainer a
  3923. INNER JOIN ICSBomALL b ON a.ContainerID=b.ID
  3924. )
  3925. " + sql;
  3926. if ((TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  3927. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  3928. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription()
  3929. || TransType == TransTypeEnum.MOStockINByProduct.GetDescription() || TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription()
  3930. || TransType == TransTypeEnum.OOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription() || TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription()
  3931. || TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription() || TransType == TransTypeEnum.ManufactureMESReceive.GetDescription()) && needIns)
  3932. {
  3933. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  3934. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  3935. lotdd.TransCode,lotdd.TransSequence,
  3936. '' AS WHCode,
  3937. '' AS WHName,
  3938. '' AS LocationCode,
  3939. '' AS LocationName,
  3940. ext.BatchCode AS BatchCode,";
  3941. tableName = @"ICSInventoryLot a
  3942. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3943. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
  3944. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint and ins.enable = 1";
  3945. }
  3946. else
  3947. {
  3948. columns = @"a.Quantity AS Quantity,
  3949. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  3950. lotdd.TransCode,lotdd.TransSequence,
  3951. '' AS WHCode,
  3952. '' AS WHName,
  3953. '' AS LocationCode,
  3954. '' AS LocationName,
  3955. ext.BatchCode AS BatchCode,";
  3956. tableName = @"ICSInventoryLot a
  3957. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
  3958. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint";
  3959. }
  3960. }
  3961. }
  3962. }
  3963. if (TransType != TransTypeEnum.LocationSeatch.GetDescription()&& TransType != TransTypeEnum.CodePrint.GetDescription())
  3964. {
  3965. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName))
  3966. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  3967. }
  3968. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  3969. {
  3970. Losql = string.Format(Losql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  3971. table = DBHelper.SQlReturnData(Losql, cmd);
  3972. }
  3973. else if (TransType == TransTypeEnum.CodePrint.GetDescription())
  3974. {
  3975. Printsql = string.Format(Printsql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  3976. table = DBHelper.SQlReturnData(Printsql, cmd);
  3977. }
  3978. else
  3979. {
  3980. sql = string.Format(sql, columns, tableName, JsonData.Code, JsonData.WorkPoint,zlqty, JsonData.TransCode);
  3981. //sql += DBHelper.SearchConditonGet("Search", "f6d34ca8-a5d2-4a35-9ded-b19626954f57", cmd);
  3982. log.Info("条码sql:" + sql);
  3983. table = DBHelper.SQlReturnData(sql, cmd);
  3984. }
  3985. if (table == null || table.Rows.Count <= 0)
  3986. throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
  3987. #region 出库检验是否符合源头单据
  3988. string msg = string.Empty;
  3989. bool isLimit = false;
  3990. string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode' and F_EnabledMark = '1'";
  3991. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  3992. if (isOut) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
  3993. {//&& TransType != TransTypeEnum.TransferLibrary.GetDescription()
  3994. string Lot = "";
  3995. string workP = "";
  3996. if (TransType == TransTypeEnum.TransferLibrary.GetDescription())
  3997. {
  3998. foreach (DataRow drLot in table.Rows)
  3999. {
  4000. Lot = drLot["LotNo"].ToString();
  4001. sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  4002. sql = string.Format(sql, Lot, JsonData.WorkPoint);
  4003. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  4004. if (dt == null || dt.Rows.Count <= 0)
  4005. {
  4006. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), Lot));
  4007. }
  4008. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  4009. if (!JsonData.WHCode.Equals(whcode))
  4010. {
  4011. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo395"), JsonData.WHCode, whcode));
  4012. }
  4013. }
  4014. }
  4015. else if(TransType != TransTypeEnum.LocationSeatch.GetDescription() && TransType != TransTypeEnum.StepNoTransferDocIn.GetDescription()
  4016. && TransType != TransTypeEnum.CodePrint.GetDescription())
  4017. {
  4018. if (string.IsNullOrEmpty(JsonData.TransCode))
  4019. {
  4020. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  4021. }
  4022. WMSSourceDocumentModel model = new WMSSourceDocumentModel();
  4023. model.TransCode = JsonData.TransCode;
  4024. model.TransType = JsonData.TransType;
  4025. model.WorkPoint = JsonData.WorkPoint;
  4026. model.User = JsonData.User;
  4027. DataTable TransData = TransInformationGet(model);
  4028. DataView dataView = TransData.DefaultView;
  4029. foreach (DataRow drLot in table.Rows)
  4030. {
  4031. Lot = drLot["LotNo"].ToString();
  4032. //盘点不需要对比以下属性
  4033. if (TransType == TransTypeEnum.Check.GetDescription())
  4034. continue;
  4035. string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
  4036. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
  4037. rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
  4038. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
  4039. rowFilter += " AND (LEN(ISNULL(ProjectCode,''))<=0 OR (LEN(ISNULL(ProjectCode,''))>0 AND ProjectCode='" + drLot["ProjectCode"] + "'))";
  4040. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["ProjectCode"], GetExtentionName("ProjectCode", JsonData.WorkPoint, cmd, language)));
  4041. rowFilter += "AND (LEN(ISNULL(BatchCode,''))<=0 OR (LEN(ISNULL(BatchCode,''))>0 AND BatchCode='" + drLot["BatchCode"] + "'))";
  4042. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["BatchCode"], GetExtentionName("BatchCode", JsonData.WorkPoint, cmd, language)));
  4043. rowFilter += "AND (LEN(ISNULL(Version,''))<=0 OR (LEN(ISNULL(Version,''))>0 AND Version='" + drLot["Version"] + "'))";
  4044. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["Version"], GetExtentionName("Version", JsonData.WorkPoint, cmd, language)));
  4045. rowFilter += "AND (LEN(ISNULL(Brand,''))<=0 OR (LEN(ISNULL(Brand,''))>0 AND Brand='" + drLot["Brand"] + "'))";
  4046. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["Brand"], GetExtentionName("Brand", JsonData.WorkPoint, cmd, language)));
  4047. rowFilter += "AND (LEN(ISNULL(cFree1,''))<=0 OR (LEN(ISNULL(cFree1,''))>0 AND cFree1='" + drLot["cFree1"] + "'))";
  4048. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree1"], GetExtentionName("cFree1", JsonData.WorkPoint, cmd, language)));
  4049. rowFilter += "AND (LEN(ISNULL(cFree2,''))<=0 OR (LEN(ISNULL(cFree2,''))>0 AND cFree2='" + drLot["cFree2"] + "'))";
  4050. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree2"], GetExtentionName("cFree2", JsonData.WorkPoint, cmd, language)));
  4051. rowFilter += "AND (LEN(ISNULL(cFree3,''))<=0 OR (LEN(ISNULL(cFree3,''))>0 AND cFree3='" + drLot["cFree3"] + "'))";
  4052. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree3"], GetExtentionName("cFree3", JsonData.WorkPoint, cmd, language)));
  4053. rowFilter += "AND (LEN(ISNULL(cFree4,''))<=0 OR (LEN(ISNULL(cFree4,''))>0 AND cFree4='" + drLot["cFree4"] + "'))";
  4054. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree4"], GetExtentionName("cFree4", JsonData.WorkPoint, cmd, language)));
  4055. rowFilter += "AND (LEN(ISNULL(cFree5,''))<=0 OR (LEN(ISNULL(cFree5,''))>0 AND cFree5='" + drLot["cFree5"] + "'))";
  4056. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree5"], GetExtentionName("cFree5", JsonData.WorkPoint, cmd, language)));
  4057. rowFilter += "AND (LEN(ISNULL(cFree6,''))<=0 OR (LEN(ISNULL(cFree6,''))>0 AND cFree6='" + drLot["cFree6"] + "'))";
  4058. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree6"], GetExtentionName("cFree6", JsonData.WorkPoint, cmd, language)));
  4059. rowFilter += "AND (LEN(ISNULL(cFree7,''))<=0 OR (LEN(ISNULL(cFree7,''))>0 AND cFree7='" + drLot["cFree7"] + "'))";
  4060. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree7"], GetExtentionName("cFree7", JsonData.WorkPoint, cmd, language)));
  4061. rowFilter += "AND (LEN(ISNULL(cFree8,''))<=0 OR (LEN(ISNULL(cFree8,''))>0 AND cFree8='" + drLot["cFree8"] + "'))";
  4062. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree8"], GetExtentionName("cFree8", JsonData.WorkPoint, cmd, language)));
  4063. rowFilter += "AND (LEN(ISNULL(cFree9,''))<=0 OR (LEN(ISNULL(cFree9,''))>0 AND cFree9='" + drLot["cFree9"] + "'))";
  4064. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree9"], GetExtentionName("cFree9", JsonData.WorkPoint, cmd, language)));
  4065. rowFilter += "AND (LEN(ISNULL(cFree10,''))<=0 OR (LEN(ISNULL(cFree10,''))>0 AND cFree10='" + drLot["cFree10"] + "'))";
  4066. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree10"], GetExtentionName("cFree10", JsonData.WorkPoint, cmd, language)));
  4067. if (flag != null && flag.Rows.Count > 0)
  4068. {
  4069. rowFilter += " AND LocationCode='" + drLot["LocationCode"] + "'";
  4070. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["LocationCode"]));
  4071. }
  4072. //保质期管理
  4073. var resultEffective = Effective(Lot, JsonData.WorkPoint, JsonData.TransType, cmd, language);
  4074. //0 - 已经是最早的批次
  4075. //1 - 不管控
  4076. //2 - 提醒
  4077. //3 - 限制
  4078. if (resultEffective == "2")
  4079. {
  4080. msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
  4081. }
  4082. else if (resultEffective == "3")
  4083. {
  4084. msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
  4085. isLimit = true;
  4086. }
  4087. string rowFilternew = rowFilter+" AND LEN(ISNULL(ProjectCode,''))>0";
  4088. string sqlnew = CheckTransnew(dataView, rowFilternew, "ProjectCode");
  4089. rowFilternew = rowFilter + " AND LEN(ISNULL(BatchCode,''))>0";
  4090. sqlnew += CheckTransnew(dataView, rowFilternew, "BatchCode");
  4091. rowFilternew = rowFilter + " AND LEN(ISNULL(Version,''))>0";
  4092. sqlnew += CheckTransnew(dataView, rowFilternew, "Version");
  4093. rowFilternew = rowFilter + " AND LEN(ISNULL(Brand,''))>0";
  4094. sqlnew += CheckTransnew(dataView, rowFilternew, "Brand");
  4095. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree1,''))>0";
  4096. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree1");
  4097. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree2,''))>0";
  4098. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree2");
  4099. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree3,''))>0";
  4100. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree3");
  4101. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree4,''))>0";
  4102. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree4");
  4103. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree5,''))>0";
  4104. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree5");
  4105. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree6,''))>0";
  4106. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree6");
  4107. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree7,''))>0";
  4108. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree7");
  4109. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree8,''))>0 ";
  4110. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree8");
  4111. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree9,''))>0";
  4112. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree9");
  4113. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree10,''))>0";
  4114. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree10");
  4115. //先进先出判断
  4116. if (JsonData.CheckPassWord !="")
  4117. {
  4118. if (JsonData.CheckPassWord=="0")
  4119. {
  4120. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, sqlnew, JsonData.TransType, cmd, language);
  4121. //0 - 已经是最早的批次
  4122. //1 - 不管控
  4123. //2 - 提醒
  4124. //3 - 限制
  4125. if (result == "2")
  4126. {
  4127. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  4128. }
  4129. else if (result == "3")
  4130. {
  4131. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  4132. isLimit = true;
  4133. }
  4134. }
  4135. }
  4136. else
  4137. {
  4138. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, sqlnew, JsonData.TransType, cmd, language);
  4139. //0 - 已经是最早的批次
  4140. //1 - 不管控
  4141. //2 - 提醒
  4142. //3 - 限制
  4143. if (result == "2")
  4144. {
  4145. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  4146. }
  4147. else if (result == "3")
  4148. {
  4149. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  4150. isLimit = true;
  4151. }
  4152. }
  4153. }
  4154. }
  4155. }
  4156. #endregion
  4157. //return table;
  4158. Result res = new Result();
  4159. res.Success = true;
  4160. res.Message = msg;// "接口调用成功!";
  4161. if (!isLimit)
  4162. res.Data = table;
  4163. return res;
  4164. //出库时
  4165. //Message无值、Data有值,可直接处理
  4166. //Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
  4167. //Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
  4168. }
  4169. catch (Exception ex)
  4170. {
  4171. log.Error(ex.Message);
  4172. throw new Exception(ex.Message);
  4173. }
  4174. finally
  4175. {
  4176. if (conn.State == ConnectionState.Open)
  4177. {
  4178. conn.Close();
  4179. }
  4180. conn.Dispose();
  4181. }
  4182. }
  4183. }
  4184. /// <summary>
  4185. /// 校验条码对应的物料、自由项等信息是否与源头单据匹配
  4186. /// </summary>
  4187. private static DataView CheckTrans(DataView dataView, string rowFilter, string message)
  4188. {
  4189. dataView.RowFilter = rowFilter;
  4190. if (dataView == null || dataView.Count <= 0)
  4191. throw new Exception(message);
  4192. return dataView;
  4193. }
  4194. #endregion
  4195. private static string CheckTransnew(DataView dataView, string rowFilter, string aaa)
  4196. {
  4197. dataView.RowFilter = rowFilter;
  4198. if (dataView == null || dataView.Count <= 0)
  4199. return "";
  4200. return " AND bext."+ aaa + "=yext."+ aaa ;
  4201. }
  4202. /// <summary>
  4203. /// 上架
  4204. /// </summary>BusinessCode,TransType 两个类型
  4205. /// <param name="JsonData"></param>
  4206. /// <returns></returns>
  4207. public static DataTable LOTStockCreate(List<LOTStockUpCreateIModel> JsonData)
  4208. {
  4209. var language = LanguageHelper.GetName("WMSAPIInfo");
  4210. if (JsonData.Count <= 0)
  4211. {
  4212. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4213. }
  4214. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4215. {
  4216. conn.Open();
  4217. SqlTransaction sqlTran = conn.BeginTransaction();
  4218. SqlCommand cmd = new SqlCommand();
  4219. cmd.Transaction = sqlTran;
  4220. cmd.Connection = conn;
  4221. cmd.CommandTimeout= Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  4222. string BusinessCode = string.Empty;
  4223. try
  4224. {
  4225. DataTable dtable = new DataTable();
  4226. string result = string.Empty;
  4227. string IsDx = string.Empty;
  4228. string TransType = string.Empty;
  4229. string TransTypeOriginal = string.Empty;//记录不合格入库条码的原条码的类型
  4230. string Identification = Guid.NewGuid().ToString();
  4231. foreach (var item in JsonData)
  4232. {
  4233. if (string.IsNullOrEmpty(item.IsDx))
  4234. {
  4235. IsDx = "";
  4236. }
  4237. else
  4238. {
  4239. IsDx = item.IsDx;
  4240. }
  4241. TransType = item.TransType;
  4242. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  4243. {
  4244. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  4245. }
  4246. string WHTransType = "2";
  4247. foreach (var itemInfo in item.detail)
  4248. {
  4249. #region 两步调入
  4250. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  4251. {
  4252. //更新源头单据数量
  4253. ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4254. //入库
  4255. ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  4256. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  4257. }
  4258. #endregion
  4259. #region 锐腾两步调入
  4260. if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
  4261. {
  4262. //更新源头单据数量
  4263. ICSWareHouseService.RTTwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4264. //入库
  4265. ICSWareHouseLotInfoService.RTWareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  4266. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.RTTwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  4267. }
  4268. #endregion
  4269. #region 销售退货-原条码
  4270. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  4271. {
  4272. //更新源头单据数量
  4273. ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4274. //入库
  4275. BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription<DBValue>();
  4276. //入库
  4277. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  4278. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode,"","");
  4279. //更新日志表源头单据信息
  4280. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  4281. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' ";
  4282. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  4283. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4284. {
  4285. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  4286. }
  4287. }
  4288. #endregion
  4289. #region 销售退货-原条码
  4290. else if (TransType == TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription())
  4291. {
  4292. //更新源头单据数量
  4293. ICSSalesService.SalesShipmentOutRedYuanDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4294. //入库
  4295. BusinessCode = TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription<DBValue>();
  4296. //入库
  4297. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  4298. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, "", "");
  4299. //更新日志表源头单据信息
  4300. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  4301. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' ";
  4302. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  4303. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4304. {
  4305. throw new Exception(language.GetNameByCode("WMSAPIInfo531"));//"红字销售出库单更新失败!");
  4306. }
  4307. }
  4308. #endregion
  4309. else
  4310. {
  4311. #region 采购入库
  4312. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  4313. {
  4314. //更新源头单据数量
  4315. log.Debug("0");
  4316. ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4317. BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription<DBValue>();
  4318. }
  4319. #endregion
  4320. #region 采购入库-入库单
  4321. else if (TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription())
  4322. {
  4323. //更新源头单据数量
  4324. ICSPurchaseService.PurchaseReceiveRevDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4325. BusinessCode = TransTypeEnum.PurchaseReceiveRevDoc.GetDescription<DBValue>();
  4326. }
  4327. #endregion
  4328. #region 审核的到货单
  4329. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  4330. {
  4331. //更新源头单据数量
  4332. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4333. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  4334. }
  4335. #endregion
  4336. #region 采购拒收
  4337. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  4338. {
  4339. //更新源头单据数量
  4340. ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4341. BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription<DBValue>();
  4342. }
  4343. #endregion
  4344. #region 审核的委外到货单
  4345. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  4346. {
  4347. //更新源头单据数量
  4348. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4349. BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  4350. }
  4351. #endregion
  4352. #region 委外拒收
  4353. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  4354. {
  4355. //更新源头单据数量
  4356. ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4357. BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription<DBValue>();
  4358. }
  4359. #endregion
  4360. #region 委外退料
  4361. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  4362. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  4363. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  4364. {
  4365. //更新源头单据数量
  4366. ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
  4367. BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  4368. }
  4369. #endregion
  4370. #region 返工工单
  4371. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  4372. {
  4373. //更新源头单据数量
  4374. ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>(), cmd, language);
  4375. BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>();
  4376. }
  4377. #endregion
  4378. #region 委外入库
  4379. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  4380. {
  4381. //更新源头单据数量
  4382. ICSOutsourcingService.OutsourcingReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4383. BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>();
  4384. }
  4385. #endregion
  4386. #region 委外入库-入库单
  4387. else if (TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription())
  4388. {
  4389. //更新源头单据数量
  4390. ICSOutsourcingService.OutsourcingReceiveRcvDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4391. BusinessCode = TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription<DBValue>();
  4392. }
  4393. #endregion
  4394. #region 生产退料
  4395. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  4396. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  4397. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  4398. {
  4399. log.Debug("生产退料1" + TransTypeEnum.MOIssueDocNegative.GetDescription());
  4400. log.Debug("生产退料2" + TransTypeEnum.MOIssueDocNegativeApply.GetDescription());
  4401. log.Debug("生产退料3" + TransTypeEnum.MOIssueDocNegativeIssue.GetDescription());
  4402. log.Debug("生产退料4"+TransType);
  4403. //更新源头单据数量
  4404. ICSManufactureService.MOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4405. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  4406. log.Debug("生产退料5");
  4407. }
  4408. #endregion
  4409. #region 生产入库
  4410. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  4411. {
  4412. log.Debug("生产入库" + TransType);
  4413. //更新源头单据数量
  4414. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4415. BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  4416. }
  4417. #endregion
  4418. #region 开立的生产入库单
  4419. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  4420. {
  4421. //更新源头单据数量
  4422. ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4423. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  4424. }
  4425. #endregion
  4426. #region MES产成品入库单
  4427. else if (TransType == TransTypeEnum.ManufactureMESReceive.GetDescription())
  4428. {
  4429. //更新源头单据数量
  4430. ICSManufactureService.ManufactureMESReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4431. BusinessCode = TransTypeEnum.ManufactureMESReceive.GetDescription<DBValue>();
  4432. }
  4433. #endregion
  4434. #region 销售退货
  4435. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  4436. {
  4437. //更新源头单据数量
  4438. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4439. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  4440. }
  4441. #endregion
  4442. #region 销售出库-红字出库单
  4443. else if (TransType == TransTypeEnum.SalesShipmentOutRedDoc.GetDescription())
  4444. {
  4445. //更新源头单据数量
  4446. ICSSalesService.SalesShipmentOutRedDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4447. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  4448. }
  4449. #endregion
  4450. #region 其他入库
  4451. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  4452. {
  4453. //更新源头单据数量
  4454. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4455. BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  4456. }
  4457. #endregion
  4458. #region 拆卸单
  4459. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  4460. {
  4461. ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4462. WHTransType = "11";
  4463. BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription<DBValue>();
  4464. }
  4465. #endregion
  4466. #region 归还
  4467. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  4468. {
  4469. //更新源头单据数量
  4470. ICSWareHouseService.ReturnDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4471. BusinessCode = TransTypeEnum.ReturnDoc.GetDescription<DBValue>();
  4472. }
  4473. #endregion
  4474. #region 不合格入库
  4475. else if (TransType == TransTypeEnum.UnqualifiedIN.GetDescription())
  4476. {
  4477. string sql = @"SELECT b.Type FROM ICSInventoryLot a
  4478. LEFT JOIN ICSInventoryLot b ON a.EATTRIBUTE1=b.LotNo AND b.WorkPoint=a.WorkPoint
  4479. WHERE a.LotNo='{0}' AND a.Type='17' AND a.WorkPoint='{1}'";
  4480. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint);
  4481. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  4482. if (dt.Rows.Count != 0)
  4483. {
  4484. TransTypeOriginal = dt.Rows[0]["Type"].ToString();
  4485. }
  4486. if (TransTypeOriginal == string.Empty)
  4487. {
  4488. //throw new Exception(language.GetNameByCode(""));
  4489. throw new Exception("未查询到条码" + itemInfo.LotNo + "的原条码");
  4490. }
  4491. #region 审核的到货单
  4492. else if (TransTypeOriginal == "7")
  4493. {
  4494. //更新源头单据数量
  4495. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4496. //BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  4497. TransTypeOriginal = TransTypeEnum.DeliveryNotice.GetDescription();
  4498. }
  4499. #endregion
  4500. #region 审核的委外到货单
  4501. else if (TransTypeOriginal == "8")
  4502. {
  4503. //更新源头单据数量
  4504. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4505. //BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  4506. TransTypeOriginal = TransTypeEnum.ODeliveryNotice.GetDescription();
  4507. }
  4508. #endregion
  4509. #region 委外退料
  4510. else if (TransTypeOriginal == "2"
  4511. || TransTypeOriginal == "14"
  4512. || TransTypeOriginal == "15")
  4513. {
  4514. //更新源头单据数量
  4515. ICSOutsourcingService.OutsourcingIssueDoNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
  4516. //BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  4517. TransTypeOriginal = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription();
  4518. }
  4519. #endregion
  4520. #region 生产退料
  4521. else if (TransTypeOriginal == "1"
  4522. || TransTypeOriginal == "12"
  4523. || TransTypeOriginal == "13")
  4524. {
  4525. log.Debug("生产退料1" + TransTypeEnum.MOIssueDocNegative.GetDescription());
  4526. log.Debug("生产退料2" + TransTypeEnum.MOIssueDocNegativeApply.GetDescription());
  4527. log.Debug("生产退料3" + TransTypeEnum.MOIssueDocNegativeIssue.GetDescription());
  4528. log.Debug("生产退料4" + TransTypeOriginal);
  4529. //更新源头单据数量
  4530. ICSManufactureService.MOIssueDocNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4531. //BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  4532. TransTypeOriginal = TransTypeEnum.MOIssueDocNegative.GetDescription();
  4533. }
  4534. #endregion
  4535. #region 生产入库
  4536. else if (TransTypeOriginal == "3")
  4537. {
  4538. log.Debug("生产入库" + TransTypeOriginal);
  4539. //更新源头单据数量
  4540. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4541. //BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  4542. TransTypeOriginal = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
  4543. }
  4544. #endregion
  4545. #region 销售退货
  4546. else if (TransTypeOriginal == "4")
  4547. {
  4548. //更新源头单据数量
  4549. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4550. //BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  4551. TransTypeOriginal = TransTypeEnum.SalesShipmentDocNegative.GetDescription();
  4552. }
  4553. #endregion
  4554. #region 其他入库
  4555. else if (TransTypeOriginal == "5")
  4556. {
  4557. //更新源头单据数量
  4558. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4559. //BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  4560. TransTypeOriginal = TransTypeEnum.OtherInDoc.GetDescription();
  4561. }
  4562. #endregion
  4563. BusinessCode = TransTypeEnum.UnqualifiedIN.GetDescription<DBValue>();
  4564. }
  4565. #endregion
  4566. #region 副产品入库
  4567. else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
  4568. {
  4569. log.Debug("副产品入库" + TransType);
  4570. //更新源头单据数量
  4571. ICSManufactureService.MOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4572. BusinessCode = TransTypeEnum.MOStockINByProduct.GetDescription<DBValue>();
  4573. }
  4574. #endregion
  4575. #region 委外副产品入库
  4576. else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  4577. {
  4578. log.Debug("副产品入库" + TransType);
  4579. //更新源头单据数量
  4580. ICSManufactureService.OOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4581. BusinessCode = TransTypeEnum.OOStockINByProduct.GetDescription<DBValue>();
  4582. }
  4583. #endregion
  4584. #region 无源头副产品入库
  4585. else if (TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
  4586. {
  4587. log.Debug("无源头副产品入库" + TransType);
  4588. //更新源头单据数量
  4589. //ICSManufactureService.MOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4590. BusinessCode = TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>();
  4591. }
  4592. #endregion
  4593. else
  4594. {
  4595. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  4596. }
  4597. log.Debug("1");
  4598. //入库
  4599. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  4600. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language,itemInfo.LogID,itemInfo.InvCode + itemInfo.WarehouseCode, itemInfo.TransCode, itemInfo.TransSequence);
  4601. }
  4602. }
  4603. #region 拆卸单
  4604. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  4605. {
  4606. //更新套件锁定数量
  4607. ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
  4608. }
  4609. #endregion}
  4610. }
  4611. //上传ERP
  4612. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  4613. {
  4614. log.Debug("ERP接口");
  4615. if (TransTypeOriginal != string.Empty)
  4616. {
  4617. TransType = TransTypeOriginal;
  4618. }
  4619. //采购入库
  4620. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  4621. {
  4622. if (DBHelper.IsU9())
  4623. { ICSPurchaseService.CreatePOArriveERP(TransType, Identification, cmd, language, BusinessCode, "RCV01"); }
  4624. else
  4625. {
  4626. log.Debug("2");
  4627. ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language, BusinessCode); }
  4628. }
  4629. //采购入库-入库单
  4630. else if (TransType == TransTypeEnum.PurchaseReceiveRevDoc.GetDescription())
  4631. {
  4632. ICSPurchaseService.PurchaseReceiveRevDocERP(TransType, Identification, cmd, language, BusinessCode);
  4633. }
  4634. //审核的到货单
  4635. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  4636. dtable = ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  4637. //采购拒收
  4638. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  4639. ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  4640. //审核的委外到货单
  4641. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  4642. ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  4643. //委外拒收
  4644. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  4645. ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  4646. //委外退料
  4647. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  4648. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  4649. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  4650. ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4651. //委外入库
  4652. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  4653. {
  4654. if (DBHelper.IsU9())
  4655. { ICSOutsourcingService.CreateOOArriveERP(TransType, Identification, cmd, language, BusinessCode, "RCV11"); }
  4656. else
  4657. {
  4658. ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  4659. }
  4660. }
  4661. //委外入库
  4662. else if (TransType == TransTypeEnum.OutsourcingReceiveRevDoc.GetDescription())
  4663. {
  4664. ICSOutsourcingService.OutsourcingReceiveRcvDocERP(TransType, Identification, cmd, language, BusinessCode);
  4665. }
  4666. //生产退料
  4667. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  4668. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  4669. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  4670. {
  4671. if (DBHelper.IsDX())
  4672. {
  4673. ICSManufactureService.DXMOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode, IsDx);
  4674. }
  4675. else
  4676. {
  4677. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4678. }
  4679. }
  4680. //生产入库
  4681. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  4682. ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  4683. //副产品入库
  4684. else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
  4685. ICSManufactureService.MOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
  4686. //委外副产品入库
  4687. else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  4688. ICSManufactureService.OOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
  4689. //无源头副产品入库
  4690. else if (TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
  4691. ICSManufactureService.MOStockINByProductNoTransDocERP(TransType, Identification, cmd, language, BusinessCode);
  4692. //开立的生产入库单
  4693. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  4694. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  4695. //MES产成品入库单
  4696. else if (TransType == TransTypeEnum.ManufactureMESReceive.GetDescription())
  4697. ICSManufactureService.ManufactureMESReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  4698. //返工工单
  4699. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  4700. ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language, BusinessCode);
  4701. //销售退货
  4702. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  4703. {
  4704. if (DBHelper.IsU9())
  4705. ICSSalesService.U9SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4706. else
  4707. ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4708. }
  4709. //红字销售出库单
  4710. else if (TransType == TransTypeEnum.SalesShipmentOutRedDoc.GetDescription()|| TransType == TransTypeEnum.SalesShipmentOutRedYuanDoc.GetDescription())
  4711. {
  4712. ICSSalesService.SalesShipmentDocOutRedERP(TransType, Identification, cmd, language, BusinessCode);
  4713. }
  4714. //两步调入
  4715. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  4716. ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
  4717. //两步调入
  4718. else if (TransType == TransTypeEnum.RTTwoStepTransferDocIn.GetDescription())
  4719. ICSWareHouseService.RTTwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
  4720. //销售退货-原条码
  4721. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  4722. ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language, BusinessCode);
  4723. //其他入库
  4724. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  4725. {
  4726. if (DBHelper.IsU9())
  4727. ICSWareHouseService.CreateOtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
  4728. else
  4729. ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
  4730. }
  4731. //拆卸单
  4732. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  4733. ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language, BusinessCode);
  4734. //归还
  4735. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  4736. ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language, BusinessCode);
  4737. }
  4738. if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  4739. {
  4740. cmd.Transaction.Commit();
  4741. return dtable;
  4742. }
  4743. else
  4744. {
  4745. DataTable table = GetData(Identification, 1, cmd);
  4746. cmd.Transaction.Commit();
  4747. return table;
  4748. }
  4749. }
  4750. catch (Exception ex)
  4751. {
  4752. if (cmd.Transaction != null)
  4753. cmd.Transaction.Rollback();
  4754. log.Error(ex.Message);
  4755. throw new Exception(ex.Message);
  4756. }
  4757. finally
  4758. {
  4759. if (conn.State == ConnectionState.Open)
  4760. {
  4761. conn.Close();
  4762. }
  4763. conn.Dispose();
  4764. }
  4765. }
  4766. }
  4767. /// <summary>
  4768. /// 上架(奥美专用)
  4769. /// </summary>BusinessCode,TransType 两个类型
  4770. /// <param name="JsonData"></param>
  4771. /// <returns></returns>
  4772. public static DataTable LOTStockCreateAM(List<LOTStockUpCreateIModel> JsonData)
  4773. {
  4774. var language = LanguageHelper.GetName("WMSAPIInfo");
  4775. if (JsonData.Count <= 0)
  4776. {
  4777. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4778. }
  4779. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4780. {
  4781. conn.Open();
  4782. SqlTransaction sqlTran = conn.BeginTransaction();
  4783. SqlCommand cmd = new SqlCommand();
  4784. cmd.Transaction = sqlTran;
  4785. cmd.Connection = conn;
  4786. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  4787. string BusinessCode = string.Empty;
  4788. try
  4789. {
  4790. string TransType = string.Empty;
  4791. DataTable dtable = new DataTable();
  4792. string TransTypeOriginal = string.Empty;//记录不合格入库条码的原条码的类型
  4793. string Identification = Guid.NewGuid().ToString();
  4794. foreach (var item in JsonData)
  4795. {
  4796. TransType = item.TransType;
  4797. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  4798. {
  4799. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  4800. }
  4801. string WHTransType = "2";
  4802. foreach (var itemInfo in item.detail)
  4803. {
  4804. #region 两步调入
  4805. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  4806. {
  4807. //更新源头单据数量
  4808. ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4809. //入库
  4810. ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  4811. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  4812. }
  4813. #endregion
  4814. #region 销售退货-原条码
  4815. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  4816. {
  4817. //更新源头单据数量
  4818. ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4819. //入库
  4820. BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription<DBValue>();
  4821. //入库
  4822. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  4823. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode,"","");
  4824. //更新日志表源头单据信息
  4825. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  4826. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' AND TransCode='' AND TransSequence=''";
  4827. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  4828. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4829. {
  4830. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  4831. }
  4832. }
  4833. #endregion
  4834. else
  4835. {
  4836. #region 采购入库
  4837. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  4838. {
  4839. //更新源头单据数量
  4840. ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4841. BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription<DBValue>();
  4842. }
  4843. #endregion
  4844. #region 审核的到货单
  4845. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  4846. {
  4847. //更新源头单据数量
  4848. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4849. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  4850. }
  4851. #endregion
  4852. #region 采购拒收
  4853. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  4854. {
  4855. //更新源头单据数量
  4856. ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4857. BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription<DBValue>();
  4858. }
  4859. #endregion
  4860. #region 审核的委外到货单
  4861. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  4862. {
  4863. //更新源头单据数量
  4864. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4865. BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  4866. }
  4867. #endregion
  4868. #region 委外拒收
  4869. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  4870. {
  4871. //更新源头单据数量
  4872. ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4873. BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription<DBValue>();
  4874. }
  4875. #endregion
  4876. #region 委外退料
  4877. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  4878. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  4879. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  4880. {
  4881. //更新源头单据数量
  4882. ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
  4883. BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  4884. }
  4885. #endregion
  4886. #region 返工工单
  4887. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  4888. {
  4889. //更新源头单据数量
  4890. ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>(), cmd, language);
  4891. BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>();
  4892. }
  4893. #endregion
  4894. #region 委外入库
  4895. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  4896. {
  4897. //更新源头单据数量
  4898. ICSOutsourcingService.OutsourcingReceiveAMDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4899. BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>();
  4900. }
  4901. #endregion
  4902. #region 生产退料
  4903. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  4904. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  4905. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  4906. {
  4907. log.Debug("生产退料1" + TransTypeEnum.MOIssueDocNegative.GetDescription());
  4908. log.Debug("生产退料2" + TransTypeEnum.MOIssueDocNegativeApply.GetDescription());
  4909. log.Debug("生产退料3" + TransTypeEnum.MOIssueDocNegativeIssue.GetDescription());
  4910. log.Debug("生产退料4" + TransType);
  4911. //更新源头单据数量
  4912. ICSManufactureService.AMMOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint,itemInfo.TransCode,itemInfo.TransSequence, cmd, language);
  4913. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  4914. log.Debug("生产退料5");
  4915. }
  4916. #endregion
  4917. #region 生产入库
  4918. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  4919. {
  4920. log.Debug("生产入库" + TransType);
  4921. //更新源头单据数量
  4922. ICSManufactureService.ManufactureReceiveDocAM(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4923. BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  4924. }
  4925. #endregion
  4926. #region 开立的生产入库单
  4927. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  4928. {
  4929. //更新源头单据数量
  4930. ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4931. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  4932. }
  4933. #endregion
  4934. #region 销售退货
  4935. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  4936. {
  4937. //更新源头单据数量
  4938. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4939. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  4940. }
  4941. #endregion
  4942. #region 其他入库
  4943. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  4944. {
  4945. //更新源头单据数量
  4946. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4947. BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  4948. }
  4949. #endregion
  4950. #region 拆卸单
  4951. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  4952. {
  4953. ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4954. WHTransType = "11";
  4955. BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription<DBValue>();
  4956. }
  4957. #endregion
  4958. #region 归还
  4959. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  4960. {
  4961. //更新源头单据数量
  4962. ICSWareHouseService.ReturnDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4963. BusinessCode = TransTypeEnum.ReturnDoc.GetDescription<DBValue>();
  4964. }
  4965. #endregion
  4966. #region 不合格入库
  4967. else if (TransType == TransTypeEnum.UnqualifiedIN.GetDescription())
  4968. {
  4969. string sql = @"SELECT b.Type FROM ICSInventoryLot a
  4970. LEFT JOIN ICSInventoryLot b ON a.EATTRIBUTE1=b.LotNo AND b.WorkPoint=a.WorkPoint
  4971. WHERE a.LotNo='{0}' AND a.Type='17' AND a.WorkPoint='{1}'";
  4972. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint);
  4973. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  4974. if (dt.Rows.Count != 0)
  4975. {
  4976. TransTypeOriginal = dt.Rows[0]["Type"].ToString();
  4977. }
  4978. if (TransTypeOriginal == string.Empty)
  4979. {
  4980. //throw new Exception(language.GetNameByCode(""));
  4981. throw new Exception("未查询到条码" + itemInfo.LotNo + "的原条码");
  4982. }
  4983. #region 审核的到货单
  4984. else if (TransTypeOriginal == "7")
  4985. {
  4986. //更新源头单据数量
  4987. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4988. //BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  4989. TransTypeOriginal = TransTypeEnum.DeliveryNotice.GetDescription();
  4990. }
  4991. #endregion
  4992. #region 审核的委外到货单
  4993. else if (TransTypeOriginal == "8")
  4994. {
  4995. //更新源头单据数量
  4996. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4997. //BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  4998. TransTypeOriginal = TransTypeEnum.ODeliveryNotice.GetDescription();
  4999. }
  5000. #endregion
  5001. #region 委外退料
  5002. else if (TransTypeOriginal == "2"
  5003. || TransTypeOriginal == "14"
  5004. || TransTypeOriginal == "15")
  5005. {
  5006. //更新源头单据数量
  5007. ICSOutsourcingService.OutsourcingIssueDoNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
  5008. //BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  5009. TransTypeOriginal = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription();
  5010. }
  5011. #endregion
  5012. #region 生产退料
  5013. else if (TransTypeOriginal == "1"
  5014. || TransTypeOriginal == "12"
  5015. || TransTypeOriginal == "13")
  5016. {
  5017. log.Debug("生产退料1" + TransTypeEnum.MOIssueDocNegative.GetDescription());
  5018. log.Debug("生产退料2" + TransTypeEnum.MOIssueDocNegativeApply.GetDescription());
  5019. log.Debug("生产退料3" + TransTypeEnum.MOIssueDocNegativeIssue.GetDescription());
  5020. log.Debug("生产退料4" + TransTypeOriginal);
  5021. //更新源头单据数量
  5022. ICSManufactureService.MOIssueDocNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  5023. //BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  5024. TransTypeOriginal = TransTypeEnum.MOIssueDocNegative.GetDescription();
  5025. }
  5026. #endregion
  5027. #region 生产入库
  5028. else if (TransTypeOriginal == "3")
  5029. {
  5030. log.Debug("生产入库" + TransTypeOriginal);
  5031. //更新源头单据数量
  5032. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  5033. //BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  5034. TransTypeOriginal = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
  5035. }
  5036. #endregion
  5037. #region 销售退货
  5038. else if (TransTypeOriginal == "4")
  5039. {
  5040. //更新源头单据数量
  5041. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  5042. //BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  5043. TransTypeOriginal = TransTypeEnum.SalesShipmentDocNegative.GetDescription();
  5044. }
  5045. #endregion
  5046. #region 其他入库
  5047. else if (TransTypeOriginal == "5")
  5048. {
  5049. //更新源头单据数量
  5050. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  5051. //BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  5052. TransTypeOriginal = TransTypeEnum.OtherInDoc.GetDescription();
  5053. }
  5054. #endregion
  5055. BusinessCode = TransTypeEnum.UnqualifiedIN.GetDescription<DBValue>();
  5056. }
  5057. #endregion
  5058. #region 联副产品入库
  5059. else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
  5060. {
  5061. log.Debug("联副产品入库" + TransType);
  5062. //更新源头单据数量
  5063. ICSManufactureService.MOStockINByProductAMDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  5064. BusinessCode = TransTypeEnum.MOStockINByProduct.GetDescription<DBValue>();
  5065. }
  5066. #endregion
  5067. else
  5068. {
  5069. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  5070. }
  5071. //入库
  5072. ICSWareHouseLotInfoService.WareHouseLotInfoUpAM(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  5073. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, itemInfo.TransCode, itemInfo.TransSequence);
  5074. }
  5075. }
  5076. #region 拆卸单
  5077. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  5078. {
  5079. //更新套件锁定数量
  5080. ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
  5081. }
  5082. #endregion}
  5083. }
  5084. //上传ERP
  5085. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  5086. {
  5087. if (TransTypeOriginal != string.Empty)
  5088. {
  5089. TransType = TransTypeOriginal;
  5090. }
  5091. //采购入库
  5092. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  5093. ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  5094. //审核的到货单
  5095. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  5096. dtable = ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  5097. //采购拒收
  5098. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  5099. ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  5100. //审核的委外到货单
  5101. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  5102. ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  5103. //委外拒收
  5104. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  5105. ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  5106. //委外退料
  5107. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  5108. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  5109. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  5110. ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  5111. //委外入库
  5112. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  5113. ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  5114. //生产退料
  5115. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  5116. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  5117. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  5118. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  5119. //生产入库
  5120. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  5121. ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  5122. //副产品入库
  5123. else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
  5124. ICSManufactureService.MOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
  5125. //委外副产品入库
  5126. else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  5127. ICSManufactureService.OOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
  5128. //开立的生产入库单
  5129. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  5130. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  5131. //返工工单
  5132. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  5133. ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language, BusinessCode);
  5134. //销售退货
  5135. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  5136. ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  5137. //两步调入
  5138. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  5139. ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
  5140. //销售退货-原条码
  5141. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  5142. ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language, BusinessCode);
  5143. //其他入库
  5144. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  5145. ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
  5146. //拆卸单
  5147. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  5148. ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language, BusinessCode);
  5149. //归还
  5150. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  5151. ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language, BusinessCode);
  5152. }
  5153. if(TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  5154. {
  5155. cmd.Transaction.Commit();
  5156. return dtable;
  5157. }
  5158. else
  5159. {
  5160. DataTable table = GetData(Identification, 1, cmd);
  5161. cmd.Transaction.Commit();
  5162. return table;
  5163. }
  5164. }
  5165. catch (Exception ex)
  5166. {
  5167. if (cmd.Transaction != null)
  5168. cmd.Transaction.Rollback();
  5169. log.Error(ex.Message);
  5170. throw new Exception(ex.Message);
  5171. }
  5172. finally
  5173. {
  5174. if (conn.State == ConnectionState.Open)
  5175. {
  5176. conn.Close();
  5177. }
  5178. conn.Dispose();
  5179. }
  5180. }
  5181. }
  5182. /// <summary>
  5183. ///
  5184. /// </summary>
  5185. /// <param name="JsonData"></param>
  5186. /// <returns></returns>
  5187. public static DataTable GetPickTable(string ID, string Type, string WorkPoint, SqlCommand cmd)
  5188. {
  5189. ID = string.IsNullOrWhiteSpace(ID) ? "''" : ID.TrimEnd(',');
  5190. //string Code = SqlHelper.GetItemsDetailEnabledMark("MtimeControl");
  5191. string sql = @"EXEC ICSPicking '''{0}''','{1}','0','{2}'";
  5192. sql = string.Format(sql, ID, Type, WorkPoint);
  5193. DataSet dataset = DBHelper.SQlReturnDataSet(sql, cmd);//sql 查询
  5194. if (dataset.Tables[0].Rows.Count == 0)
  5195. return null;
  5196. DataTable table = dataset.Tables[0];
  5197. try
  5198. {
  5199. DataRow[] dss = table.Select("LotNO=''");
  5200. foreach (var item in dss)
  5201. {
  5202. DataRow[] dsss = table.Select("Code='" + item["Code"].ToString() + "' and Sequence='" + item["Sequence"].ToString() + "' and LotNO <> '' ");
  5203. if (dsss != null && dsss.Length > 0)
  5204. {
  5205. table.Rows.Remove(item);
  5206. }
  5207. }
  5208. var result = DBHelper.ConvertCellToString(table);
  5209. return result;
  5210. }
  5211. catch (Exception ex)
  5212. {
  5213. throw new Exception(ex.Message);
  5214. }
  5215. }
  5216. public static DataTable LOTStockDownByCode(List<LOTStockModel> JsonData)
  5217. {
  5218. string msg = string.Empty;
  5219. string Inputstr = string.Empty;//拣料结果
  5220. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5221. {
  5222. conn.Open();
  5223. SqlTransaction sqlTran = conn.BeginTransaction();
  5224. SqlCommand cmd = new SqlCommand();
  5225. cmd.Transaction = sqlTran;
  5226. cmd.Connection = conn;
  5227. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  5228. try
  5229. {
  5230. foreach (var item in JsonData)
  5231. {
  5232. string WorkPoint = item.WorkPoint;
  5233. string UserCode = item.User;
  5234. List<LOTStockModel> lOTStockModels = new List<LOTStockModel>();
  5235. string ID = item.TransCode;
  5236. //单据先进行拣料
  5237. DataTable dateTable = GetPickTable(ID, "2", WorkPoint, cmd);//2--东辉辅料领料
  5238. DataRow[] dateRows = dateTable?.Select($@"LotNo <> '' And LotNo is not null");
  5239. decimal ToltalCount = 0.0M;
  5240. string ZDsql = $@" SELECT Sum(Quantity) AS Quantity FROM ICSMOApply WHERE ApplyCode in('{ID}') and WorkPoint='{WorkPoint}' ";
  5241. var dt = DBHelper.SQlReturnData(ZDsql,cmd);
  5242. ZDsql = $@" SELECT ApplyCode as Code,ID, Sequence FROM ICSMOApply WHERE ApplyCode in('{ID}') and WorkPoint='{WorkPoint}' ";
  5243. DataTable dtdd = DBHelper.SQlReturnData(ZDsql, cmd);
  5244. if (dateRows == null || dateRows.Length <= 0)
  5245. {
  5246. throw new Exception("库存不足,请先检查库存");//"传送数据为空!"
  5247. }
  5248. else
  5249. {
  5250. string docCode = string.Empty;
  5251. string docCodeAfter = string.Empty;
  5252. LOTStockModel lOTStockModel = null;
  5253. // 使用 LINQ 根据 Code 字段对 DataRow[] 进行分组
  5254. var groups = dateRows.Cast<DataRow>().GroupBy(row => new
  5255. {
  5256. Code = row.Field<string>("Code"),
  5257. Sequence = row.Field<string>("Sequence"),
  5258. iQuantity = row.Field<string>("iQuantity")
  5259. });
  5260. foreach (var group in groups)
  5261. {
  5262. var firstRow = group.First();
  5263. var code = firstRow["Code"];
  5264. decimal count = 0.0M;
  5265. DataRow[] idrow = dtdd?.Select($@"Code = '" + firstRow["Code"].ToString() + "' And Sequence ='"+ firstRow["Sequence"].ToString() + "'");
  5266. lOTStockModel = new LOTStockModel
  5267. {
  5268. TransCode = firstRow["Code"].ToString(),
  5269. TransSequence = firstRow["Sequence"].ToString(),
  5270. Amount = "0",
  5271. User = UserCode,
  5272. MTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  5273. WorkPoint = WorkPoint,
  5274. detail = new List<LOTStockModelList>(),
  5275. TransType = item.TransType,
  5276. TransID = idrow[0]["ID"].ToString()
  5277. };
  5278. foreach (var row in group)
  5279. {
  5280. count += Convert.ToDecimal(row["QTY"]);
  5281. LOTStockModelList lOTStockModelList = new LOTStockModelList
  5282. {
  5283. TransSequence = firstRow["Sequence"].ToString(),
  5284. CurrentQuantity = row["QTY"].ToString(),
  5285. LotNo = row["LotNo"].ToString(),
  5286. CurrentAmount = "0",
  5287. Sequence = row["Sequence"].ToString(),
  5288. WarehouseCode = row["WarehouseCode"].ToString(),
  5289. LocationCode = row["LocationCode"].ToString()
  5290. };
  5291. lOTStockModel.detail.Add(lOTStockModelList);
  5292. }
  5293. lOTStockModel.Quantity = count.ToString();
  5294. lOTStockModels.Add(lOTStockModel);
  5295. ToltalCount += count;
  5296. }
  5297. if (ToltalCount != Convert.ToDecimal(dt.Rows[0]["Quantity"]))
  5298. {
  5299. throw new Exception("库存不足,请先检查库存");//"传送数据为空!"
  5300. }
  5301. Inputstr = JsonConvert.SerializeObject(lOTStockModels);
  5302. conn.Close();
  5303. conn.Dispose();
  5304. }
  5305. }
  5306. return LOTStockDownCreate(JsonConvert.DeserializeObject<List<LOTStockModel>>(Inputstr));//pda只能调用一张单据 pda传参一张单据
  5307. }
  5308. catch (Exception ex)
  5309. {
  5310. if (cmd.Transaction != null)
  5311. cmd.Transaction.Rollback();
  5312. throw ex;
  5313. }
  5314. finally
  5315. {
  5316. if (conn.State == ConnectionState.Open)
  5317. {
  5318. conn.Close();
  5319. }
  5320. conn.Dispose();
  5321. }
  5322. }
  5323. }
  5324. /// <summary>
  5325. /// 下架
  5326. /// </summary>
  5327. /// <param name="JsonData"></param>
  5328. /// <returns></returns>
  5329. public static DataTable LOTStockDownCreate(List<LOTStockModel> JsonData)
  5330. {
  5331. String PrintEnable = "";
  5332. string workPoint = "";
  5333. var language = LanguageHelper.GetName("WMSAPIInfo");
  5334. if (JsonData.Count <= 0)
  5335. {
  5336. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5337. }
  5338. List<LOTStockModelList> model = new List<LOTStockModelList>();
  5339. DataTable printTable = new DataTable();
  5340. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5341. {
  5342. conn.Open();
  5343. SqlTransaction sqlTran = conn.BeginTransaction();
  5344. SqlCommand cmd = new SqlCommand();
  5345. cmd.Transaction = sqlTran;
  5346. cmd.Connection = conn;
  5347. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  5348. string BusinessCode = string.Empty;
  5349. try
  5350. {
  5351. string TransType = string.Empty;
  5352. string Identification = Guid.NewGuid().ToString();
  5353. foreach (var item in JsonData)
  5354. {
  5355. TransType = item.TransType;
  5356. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  5357. {
  5358. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  5359. }
  5360. else if (string.IsNullOrEmpty(item.TransCode))
  5361. {
  5362. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  5363. }
  5364. string[] trans = item.TransCode.Split('~');
  5365. string MergeID = "";
  5366. if (trans.Length == 2)
  5367. {
  5368. MergeID = trans[0];
  5369. item.TransCode = trans[1];
  5370. }
  5371. #region 采购退货
  5372. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  5373. {
  5374. BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>();
  5375. //更新源头单据数量
  5376. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5377. foreach (var itemInfo in item.detail)
  5378. {
  5379. //出库
  5380. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5381. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, "");
  5382. }
  5383. }//PurchaseReceiveDoctNegativePo
  5384. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription()) {
  5385. BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription<DBValue>();
  5386. //更新源头单据数量
  5387. ICSPurchaseService.PurchaseReceiveDoctNegativePo(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5388. foreach (var itemInfo in item.detail)
  5389. {
  5390. //出库
  5391. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5392. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, "");
  5393. }
  5394. }
  5395. #endregion
  5396. #region 委外发料
  5397. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() || TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
  5398. {
  5399. BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>();
  5400. //更新源头单据数量
  5401. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
  5402. foreach (var itemInfo in item.detail)
  5403. {
  5404. //出库
  5405. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5406. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5407. }
  5408. }
  5409. #endregion
  5410. #region 委外退货
  5411. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  5412. {
  5413. BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>();
  5414. //更新源头单据数量
  5415. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5416. foreach (var itemInfo in item.detail)
  5417. {
  5418. //出库
  5419. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5420. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, "");
  5421. }
  5422. }
  5423. else if (TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription())
  5424. {
  5425. BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>();
  5426. //更新源头单据数量
  5427. ICSOutsourcingService.OutsourcingReturnBackOO(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5428. foreach (var itemInfo in item.detail)
  5429. {
  5430. //出库
  5431. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5432. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, "");
  5433. }
  5434. }
  5435. #endregion
  5436. #region 生产发料
  5437. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  5438. {
  5439. BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription<DBValue>();
  5440. //更新源头单据数量
  5441. ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
  5442. foreach (var itemInfo in item.detail)
  5443. {
  5444. //出库
  5445. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5446. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5447. }
  5448. // 东辉日志表记录交接人EATTRIBUTE3
  5449. if (!String.IsNullOrWhiteSpace(item.Heir))
  5450. ICSWareHouseLotInfoService.WareHouseLotInfoLogUpdateHeir(Identification, TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, item.Heir);
  5451. }
  5452. #endregion
  5453. #region 生产发料——自动出库
  5454. else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
  5455. {
  5456. BusinessCode = TransTypeEnum.MOIssueAutoDoc.GetDescription<DBValue>();
  5457. //更新源头单据数量
  5458. ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
  5459. foreach (var itemInfo in item.detail)
  5460. {
  5461. //出库
  5462. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5463. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueAutoDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5464. }
  5465. }
  5466. #endregion
  5467. #region 销售出库
  5468. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  5469. {
  5470. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  5471. //更新源头单据数量
  5472. ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID, item.CourierCode);
  5473. foreach (var itemInfo in item.detail)
  5474. {
  5475. workPoint = item.WorkPoint;
  5476. //出库
  5477. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5478. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5479. }
  5480. }
  5481. #endregion
  5482. #region 销售出库-出库单
  5483. else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription())
  5484. {
  5485. BusinessCode = TransTypeEnum.SalesShipmentOutDoc.GetDescription<DBValue>();
  5486. //更新源头单据数量
  5487. ICSSalesService.SalesShipmentOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID, item.CourierCode);
  5488. foreach (var itemInfo in item.detail)
  5489. {
  5490. //出库
  5491. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5492. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentOutDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5493. }
  5494. }
  5495. #endregion
  5496. #region 两步调出
  5497. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  5498. {
  5499. BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>();
  5500. //更新源头单据数量
  5501. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5502. foreach (var itemInfo in item.detail)
  5503. {
  5504. //出库
  5505. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5506. item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5507. }
  5508. }
  5509. #endregion
  5510. #region 其他出库
  5511. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  5512. {
  5513. BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription<DBValue>();
  5514. //更新源头单据数量
  5515. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5516. foreach (var itemInfo in item.detail)
  5517. {
  5518. //出库
  5519. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5520. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5521. }
  5522. }
  5523. #endregion
  5524. #region 其他出库——自动出库
  5525. else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
  5526. {
  5527. BusinessCode = TransTypeEnum.OtherOutAutoDoc.GetDescription<DBValue>();
  5528. //更新源头单据数量
  5529. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5530. foreach (var itemInfo in item.detail)
  5531. {
  5532. //出库
  5533. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5534. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5535. }
  5536. }
  5537. #endregion
  5538. #region 红字其他入库
  5539. else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
  5540. {
  5541. BusinessCode = TransTypeEnum.OtherInRedDoc.GetDescription<DBValue>();
  5542. //更新源头单据数量
  5543. ICSWareHouseService.OtherInRedDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5544. foreach (var itemInfo in item.detail)
  5545. {
  5546. //出库
  5547. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5548. item.User, item.WorkPoint, "3", TransTypeEnum.OtherInRedDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5549. }
  5550. }
  5551. #endregion
  5552. #region 领料申请单发料
  5553. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  5554. {
  5555. BusinessCode = TransTypeEnum.MOApply.GetDescription<DBValue>();
  5556. //更新源头单据数量
  5557. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
  5558. foreach (var itemInfo in item.detail)
  5559. {
  5560. //出库
  5561. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5562. item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5563. }
  5564. }
  5565. #endregion
  5566. #region 补料申请单发料
  5567. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  5568. {
  5569. BusinessCode = TransTypeEnum.MOReplenishment.GetDescription<DBValue>();
  5570. //更新源头单据数量
  5571. ICSManufactureService.MOReplenishment(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
  5572. foreach (var itemInfo in item.detail)
  5573. {
  5574. //出库
  5575. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5576. item.User, item.WorkPoint, "3", TransTypeEnum.MOReplenishment.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5577. }
  5578. }
  5579. #endregion
  5580. #region 委外领料申请单发料
  5581. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  5582. {
  5583. BusinessCode = TransTypeEnum.OOApply.GetDescription<DBValue>();
  5584. //更新源头单据数量
  5585. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
  5586. foreach (var itemInfo in item.detail)
  5587. {
  5588. //出库
  5589. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5590. item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5591. }
  5592. }
  5593. #endregion
  5594. #region 开立材料出库
  5595. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  5596. {
  5597. BusinessCode = TransTypeEnum.MOIssue.GetDescription<DBValue>();
  5598. //更新源头单据数量
  5599. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
  5600. foreach (var itemInfo in item.detail)
  5601. {
  5602. //出库
  5603. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5604. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5605. }
  5606. }
  5607. #endregion
  5608. #region 开立委外材料出库
  5609. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  5610. {
  5611. BusinessCode = TransTypeEnum.OOIssue.GetDescription<DBValue>();
  5612. //更新源头单据数量
  5613. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5614. foreach (var itemInfo in item.detail)
  5615. {
  5616. //出库
  5617. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5618. item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5619. }
  5620. }
  5621. #endregion
  5622. #region 开立红字入库单
  5623. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  5624. {
  5625. BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription<DBValue>();
  5626. //更新源头单据数量
  5627. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5628. foreach (var itemInfo in item.detail)
  5629. {
  5630. //出库
  5631. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5632. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, "");
  5633. }
  5634. }
  5635. #endregion
  5636. #region 开立委外红字入库单
  5637. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  5638. {
  5639. BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>();
  5640. //更新源头单据数量
  5641. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5642. foreach (var itemInfo in item.detail)
  5643. {
  5644. //出库
  5645. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5646. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, "");
  5647. }
  5648. }
  5649. #endregion
  5650. #region 借用
  5651. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  5652. {
  5653. BusinessCode = TransTypeEnum.BrrowDoc.GetDescription<DBValue>();
  5654. //更新源头单据数量
  5655. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  5656. foreach (var itemInfo in item.detail)
  5657. {
  5658. //出库
  5659. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5660. item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5661. }
  5662. }
  5663. #endregion
  5664. else
  5665. {
  5666. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  5667. }
  5668. }
  5669. //上传ERP
  5670. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  5671. {
  5672. //采购退货
  5673. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  5674. {
  5675. //if (DBHelper.IsRTU9())
  5676. //{
  5677. // ICSPurchaseService.RTPurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  5678. //}
  5679. //else
  5680. //{
  5681. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  5682. //}
  5683. }
  5684. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegativePo.GetDescription())
  5685. {
  5686. ICSPurchaseService.PurchaseReceiveDoctNegativePoERP(TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription(), Identification, cmd, language, BusinessCode);
  5687. }
  5688. //委外发料
  5689. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription()|| TransType == TransTypeEnum.RTOutsourcingIssueDoc.GetDescription())
  5690. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  5691. //委外退货
  5692. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  5693. {
  5694. if (DBHelper.IsU9())
  5695. {
  5696. ICSOutsourcingService.U9OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
  5697. }
  5698. //else if (DBHelper.IsRTU9())
  5699. //{
  5700. // ICSOutsourcingService.RTOutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
  5701. //}
  5702. else
  5703. {
  5704. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
  5705. }
  5706. }
  5707. //铭锋委外退货 源头单据采购订单(同步到到货单表)
  5708. else if (TransType == TransTypeEnum.OutsourcingReturnBackPo.GetDescription())
  5709. {
  5710. //铭锋委外退货 源头单据采购订单(同步到到货单表)
  5711. ICSOutsourcingService.OutsourcingReturnBackOOERP(TransTypeEnum.OutsourcingReturnBack.GetDescription(), Identification, cmd, language, BusinessCode);
  5712. }
  5713. //生产发料
  5714. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  5715. {
  5716. if (DBHelper.IsDX())
  5717. {
  5718. ICSManufactureService.DXMOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  5719. }
  5720. else
  5721. {
  5722. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  5723. }
  5724. }
  5725. //生产发料——自动出库
  5726. else if (TransType == TransTypeEnum.MOIssueAutoDoc.GetDescription())
  5727. {
  5728. if (DBHelper.IsDX())
  5729. {
  5730. ICSManufactureService.DXMOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  5731. }
  5732. else
  5733. {
  5734. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  5735. }
  5736. }
  5737. //销售出库
  5738. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  5739. {
  5740. //铭锋先进先出
  5741. if (!string.IsNullOrWhiteSpace(JsonData[0].passFlag) && JsonData[0].passFlag == "0")
  5742. {
  5743. string message = SubmitCanOut(Identification, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), workPoint, cmd);
  5744. if (!string.IsNullOrWhiteSpace(message))
  5745. {
  5746. throw new Exception(message);
  5747. }
  5748. }
  5749. if (DBHelper.IsU9() || DBHelper.IsPNU9())
  5750. { ICSSalesService.U9SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
  5751. else { ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
  5752. }
  5753. //销售出库-出库单
  5754. else if (TransType == TransTypeEnum.SalesShipmentOutDoc.GetDescription())
  5755. {
  5756. ICSSalesService.SalesShipmentDocOutERP(TransType, Identification, cmd, language, BusinessCode);
  5757. }
  5758. //两步调出
  5759. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  5760. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
  5761. //其他出库
  5762. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  5763. {
  5764. if (DBHelper.IsU9())
  5765. {
  5766. ICSWareHouseService.CreateOtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  5767. }
  5768. else
  5769. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  5770. }
  5771. //其他出库——自动出库
  5772. else if (TransType == TransTypeEnum.OtherOutAutoDoc.GetDescription())
  5773. {
  5774. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  5775. }
  5776. //红字其他入库
  5777. else if (TransType == TransTypeEnum.OtherInRedDoc.GetDescription())
  5778. {
  5779. ICSWareHouseService.OtherInRedDocERP(TransType, Identification, cmd, language, BusinessCode);
  5780. }
  5781. //领料申请单发料
  5782. if (TransType == TransTypeEnum.MOApply.GetDescription())
  5783. {
  5784. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  5785. }
  5786. //补料申请单发料
  5787. if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  5788. ICSManufactureService.MOReplenishmentERP(TransType, Identification, cmd, language, BusinessCode);
  5789. //委外领料申请单发料
  5790. if (TransType == TransTypeEnum.OOApply.GetDescription())
  5791. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  5792. //开立材料出库
  5793. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  5794. {
  5795. if (DBHelper.IsU9())
  5796. { ICSManufactureService.U9MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
  5797. else { ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
  5798. }
  5799. //开立委外材料出库
  5800. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  5801. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  5802. //开立红字入库单
  5803. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  5804. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  5805. //开立委外红字入库单
  5806. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  5807. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  5808. //借用
  5809. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  5810. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
  5811. }
  5812. if (!printTable.Equals("{}"))
  5813. {
  5814. cmd.Transaction.Commit();
  5815. return printTable;
  5816. }
  5817. else
  5818. {
  5819. DataTable table = GetData(Identification, 2, cmd);
  5820. cmd.Transaction.Commit();
  5821. return table;
  5822. }
  5823. }
  5824. catch (Exception ex)
  5825. {
  5826. if (cmd.Transaction != null)
  5827. cmd.Transaction.Rollback();
  5828. log.Error(ex.Message);
  5829. throw new Exception(ex.Message);
  5830. }
  5831. finally
  5832. {
  5833. if (conn.State == ConnectionState.Open)
  5834. {
  5835. conn.Close();
  5836. }
  5837. conn.Dispose();
  5838. }
  5839. }
  5840. }
  5841. /// <summary>
  5842. /// 下架奥美
  5843. /// </summary>
  5844. /// <param name="JsonData"></param>
  5845. /// <returns></returns>
  5846. public static DataTable LOTStockDownAMCreate(List<LOTStockModel> JsonData)
  5847. {
  5848. String PrintEnable = "";
  5849. var language = LanguageHelper.GetName("WMSAPIInfo");
  5850. if (JsonData.Count <= 0)
  5851. {
  5852. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5853. }
  5854. List<LOTStockModelList> model = new List<LOTStockModelList>();
  5855. DataTable printTable = new DataTable();
  5856. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5857. {
  5858. conn.Open();
  5859. SqlTransaction sqlTran = conn.BeginTransaction();
  5860. SqlCommand cmd = new SqlCommand();
  5861. cmd.Transaction = sqlTran;
  5862. cmd.Connection = conn;
  5863. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  5864. string BusinessCode = string.Empty;
  5865. try
  5866. {
  5867. string TransType = string.Empty;
  5868. string Identification = Guid.NewGuid().ToString();
  5869. foreach (var item in JsonData)
  5870. {
  5871. TransType = item.TransType;
  5872. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  5873. {
  5874. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  5875. }
  5876. else if (string.IsNullOrEmpty(item.TransCode))
  5877. {
  5878. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  5879. }
  5880. string[] trans = item.TransCode.Split('~');
  5881. string MergeID = "";
  5882. if (trans.Length == 2)
  5883. {
  5884. MergeID = trans[0];
  5885. item.TransCode = trans[1];
  5886. }
  5887. #region 采购退货
  5888. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  5889. {
  5890. BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>();
  5891. //更新源头单据数量
  5892. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language,item.TransID);
  5893. foreach (var itemInfo in item.detail)
  5894. {
  5895. //出库
  5896. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5897. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, "");
  5898. }
  5899. }
  5900. #endregion
  5901. #region 委外发料
  5902. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  5903. {
  5904. BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>();
  5905. //更新源头单据数量
  5906. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
  5907. foreach (var itemInfo in item.detail)
  5908. {
  5909. //出库
  5910. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5911. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5912. }
  5913. }
  5914. #endregion
  5915. #region 委外退货
  5916. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  5917. {
  5918. BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>();
  5919. //更新源头单据数量
  5920. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5921. foreach (var itemInfo in item.detail)
  5922. {
  5923. //出库
  5924. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5925. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, "");
  5926. }
  5927. }
  5928. #endregion
  5929. #region 生产发料
  5930. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  5931. {
  5932. BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription<DBValue>();
  5933. //更新源头单据数量
  5934. ICSManufactureService.AMMOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
  5935. foreach (var itemInfo in item.detail)
  5936. {
  5937. //出库
  5938. printTable = ICSWareHouseLotInfoService.AMWareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5939. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5940. }
  5941. }
  5942. #endregion
  5943. #region 销售出库
  5944. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  5945. {
  5946. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  5947. //更新源头单据数量
  5948. ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language,item.TransID,item.CourierCode);
  5949. foreach (var itemInfo in item.detail)
  5950. {
  5951. //出库
  5952. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5953. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5954. }
  5955. }
  5956. #endregion
  5957. #region 两步调出
  5958. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  5959. {
  5960. BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>();
  5961. //更新源头单据数量
  5962. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5963. foreach (var itemInfo in item.detail)
  5964. {
  5965. //出库
  5966. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5967. item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5968. }
  5969. }
  5970. #endregion
  5971. #region 其他出库
  5972. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  5973. {
  5974. BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription<DBValue>();
  5975. //更新源头单据数量
  5976. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  5977. foreach (var itemInfo in item.detail)
  5978. {
  5979. //出库
  5980. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5981. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5982. }
  5983. }
  5984. #endregion
  5985. #region 领料申请单发料
  5986. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  5987. {
  5988. BusinessCode = TransTypeEnum.MOApply.GetDescription<DBValue>();
  5989. //更新源头单据数量
  5990. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
  5991. foreach (var itemInfo in item.detail)
  5992. {
  5993. //出库
  5994. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  5995. item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  5996. }
  5997. }
  5998. #endregion
  5999. #region 补料申请单发料
  6000. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  6001. {
  6002. BusinessCode = TransTypeEnum.MOReplenishment.GetDescription<DBValue>();
  6003. //更新源头单据数量
  6004. ICSManufactureService.MOReplenishment(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
  6005. foreach (var itemInfo in item.detail)
  6006. {
  6007. //出库
  6008. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  6009. item.User, item.WorkPoint, "3", TransTypeEnum.MOReplenishment.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  6010. }
  6011. }
  6012. #endregion
  6013. #region 委外领料申请单发料
  6014. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  6015. {
  6016. BusinessCode = TransTypeEnum.OOApply.GetDescription<DBValue>();
  6017. //更新源头单据数量
  6018. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode,item.TransID);
  6019. foreach (var itemInfo in item.detail)
  6020. {
  6021. //出库
  6022. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  6023. item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  6024. }
  6025. }
  6026. #endregion
  6027. #region 开立材料出库
  6028. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  6029. {
  6030. BusinessCode = TransTypeEnum.MOIssue.GetDescription<DBValue>();
  6031. //更新源头单据数量
  6032. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode, item.TransID);
  6033. foreach (var itemInfo in item.detail)
  6034. {
  6035. //出库
  6036. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  6037. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  6038. }
  6039. }
  6040. #endregion
  6041. #region 开立委外材料出库
  6042. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  6043. {
  6044. BusinessCode = TransTypeEnum.OOIssue.GetDescription<DBValue>();
  6045. //更新源头单据数量
  6046. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  6047. foreach (var itemInfo in item.detail)
  6048. {
  6049. //出库
  6050. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  6051. item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  6052. }
  6053. }
  6054. #endregion
  6055. #region 开立红字入库单
  6056. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  6057. {
  6058. BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription<DBValue>();
  6059. //更新源头单据数量
  6060. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  6061. foreach (var itemInfo in item.detail)
  6062. {
  6063. //出库
  6064. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  6065. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, "");
  6066. }
  6067. }
  6068. #endregion
  6069. #region 开立委外红字入库单
  6070. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  6071. {
  6072. BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>();
  6073. //更新源头单据数量
  6074. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, item.TransID);
  6075. foreach (var itemInfo in item.detail)
  6076. {
  6077. //出库
  6078. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  6079. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, "");
  6080. }
  6081. }
  6082. #endregion
  6083. #region 借用
  6084. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  6085. {
  6086. BusinessCode = TransTypeEnum.BrrowDoc.GetDescription<DBValue>();
  6087. //更新源头单据数量
  6088. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  6089. foreach (var itemInfo in item.detail)
  6090. {
  6091. //出库
  6092. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  6093. item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, item.TransID, MergeID);
  6094. }
  6095. }
  6096. #endregion
  6097. else
  6098. {
  6099. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  6100. }
  6101. }
  6102. //上传ERP
  6103. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  6104. {
  6105. //采购退货
  6106. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  6107. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  6108. //委外发料
  6109. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  6110. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  6111. //委外退货
  6112. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  6113. {
  6114. if (DBHelper.IsU9())
  6115. { ICSOutsourcingService.U9OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode); }
  6116. else
  6117. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
  6118. }
  6119. //生产发料
  6120. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  6121. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  6122. //销售出库
  6123. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  6124. {
  6125. if (DBHelper.IsU9())
  6126. { ICSSalesService.U9SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
  6127. else { ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
  6128. }
  6129. //两步调出
  6130. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  6131. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
  6132. //其他出库
  6133. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  6134. {
  6135. if (DBHelper.IsU9())
  6136. {
  6137. ICSWareHouseService.CreateOtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  6138. }
  6139. else
  6140. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  6141. }
  6142. //领料申请单发料
  6143. if (TransType == TransTypeEnum.MOApply.GetDescription())
  6144. {
  6145. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  6146. }
  6147. //补料申请单发料
  6148. if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  6149. ICSManufactureService.MOReplenishmentERP(TransType, Identification, cmd, language, BusinessCode);
  6150. //委外领料申请单发料
  6151. if (TransType == TransTypeEnum.OOApply.GetDescription())
  6152. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  6153. //开立材料出库
  6154. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  6155. {
  6156. if (DBHelper.IsU9())
  6157. { ICSManufactureService.U9MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
  6158. else { ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
  6159. }
  6160. //开立委外材料出库
  6161. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  6162. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  6163. //开立红字入库单
  6164. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  6165. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  6166. //开立委外红字入库单
  6167. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  6168. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  6169. //借用
  6170. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  6171. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
  6172. }
  6173. if (!printTable.Equals("{}"))
  6174. {
  6175. cmd.Transaction.Commit();
  6176. return printTable;
  6177. }
  6178. else
  6179. {
  6180. DataTable table = GetData(Identification, 2, cmd);
  6181. cmd.Transaction.Commit();
  6182. return table;
  6183. }
  6184. }
  6185. catch (Exception ex)
  6186. {
  6187. if (cmd.Transaction != null)
  6188. cmd.Transaction.Rollback();
  6189. log.Error(ex.Message);
  6190. throw new Exception(ex.Message);
  6191. }
  6192. finally
  6193. {
  6194. if (conn.State == ConnectionState.Open)
  6195. {
  6196. conn.Close();
  6197. }
  6198. conn.Dispose();
  6199. }
  6200. }
  6201. }
  6202. #region 采购
  6203. /// <summary>
  6204. /// 采购到货
  6205. /// </summary>
  6206. /// <param name="JsonData"></param>
  6207. /// <returns></returns>
  6208. public static DataTable DeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  6209. {
  6210. var language = LanguageHelper.GetName("WMSAPIInfo");
  6211. if (JsonData.Count <= 0)
  6212. {
  6213. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6214. }
  6215. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6216. {
  6217. conn.Open();
  6218. SqlTransaction sqlTran = conn.BeginTransaction();
  6219. SqlCommand cmd = new SqlCommand();
  6220. cmd.Transaction = sqlTran;
  6221. cmd.Connection = conn;
  6222. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6223. try
  6224. {
  6225. string asncodes = string.Empty;
  6226. string DNCodes = string.Empty;
  6227. string DNLotNo = string.Empty;
  6228. string sql = string.Empty;
  6229. string picname = string.Empty;
  6230. foreach (var item in JsonData)
  6231. {
  6232. if (string.IsNullOrEmpty(item.ASNCode))
  6233. {
  6234. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
  6235. }
  6236. sql = @"SELECT a.DNCode FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}'";
  6237. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  6238. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  6239. if (dt.Rows.Count > 0)
  6240. {
  6241. DNCodes = dt.Rows[0]["DNCode"].ToString();
  6242. }
  6243. log.Debug("已到货的到货单"+DNCodes);
  6244. //获取单号
  6245. sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  6246. BEGIN
  6247. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  6248. RETURN
  6249. END
  6250. DECLARE @Status VARCHAR(10)
  6251. SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  6252. IF (@Status IS NULL)
  6253. BEGIN
  6254. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  6255. RETURN
  6256. END
  6257. ELSE IF (@Status!='2')
  6258. BEGIN
  6259. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  6260. RETURN
  6261. END
  6262. DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  6263. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  6264. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  6265. IF @MaxNO IS NULL
  6266. BEGIN
  6267. SELECT @date+'00001' AS Code
  6268. END
  6269. ELSE
  6270. BEGIN
  6271. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  6272. END ";
  6273. sql = string.Format(sql, item.ASNCode, item.WorkPoint, DNCodes);
  6274. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  6275. //修改送货单到货数量
  6276. foreach (var itemInfo in item.detail)
  6277. {
  6278. if (string.IsNullOrEmpty(itemInfo.TransSequence))
  6279. {
  6280. picname = "";
  6281. }
  6282. else
  6283. {
  6284. picname = itemInfo.TransSequence;
  6285. }
  6286. sql = @"
  6287. UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
  6288. WHERE LotNo='{0}' AND WorkPoint='{1}'
  6289. IF EXISTS(SELECT id FROM ICSASNDetail WHERE LotNo='{0}' AND WorkPoint='{1}' AND Quantity<DNQuantity)
  6290. BEGIN
  6291. RAISERROR(',',16,1);
  6292. RETURN
  6293. END ";
  6294. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  6295. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6296. {
  6297. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
  6298. }
  6299. sql = @"UPDATE ICSInventoryLot SET Quantity='{2}'
  6300. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  6301. if (itemInfo.IsUrgency == "1")
  6302. sql = @"UPDATE ICSInventoryLot SET Quantity='{2}' ,eattribute6 = '1' WHERE LotNo='{0}' AND WorkPoint='{1}'";
  6303. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  6304. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6305. {
  6306. throw new Exception(language.GetNameByCode("WMSAPIInfo462")); //"条码表信息更新失败!");
  6307. }
  6308. if (DNLotNo.Equals(""))
  6309. {
  6310. DNLotNo = "'" + itemInfo.LotNo + "'";
  6311. }
  6312. else
  6313. {
  6314. DNLotNo = ",'" + itemInfo.LotNo + "";
  6315. }
  6316. }
  6317. //创建到货单信息
  6318. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  6319. BEGIN
  6320. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  6321. RETURN
  6322. END
  6323. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  6324. DNType,InvCode,Quantity,Amount,RCVQuantity,
  6325. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  6326. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  6327. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode,EATTRIBUTE8)
  6328. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  6329. '1',b.InvCode,SUM(a.DNQuantity),'0','0',
  6330. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  6331. d.POID,d.PODetailID,'{0}',newid(),b.ExtensionID,
  6332. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode,'{4}'
  6333. FROM ICSASNDetail a
  6334. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  6335. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  6336. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  6337. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  6338. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}' and a.DNQuantity>0
  6339. GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.ASNCode,e.F_Account,e.F_RealName,a.WorkPoint";
  6340. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode,picname);
  6341. log.Debug("到货单sql:" + sql);
  6342. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6343. {
  6344. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  6345. }
  6346. string sqlCheckSign = @"select * from ICSConfiguration where code = 'UploadERP001' and enable = '1'";
  6347. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  6348. if (flag != null && flag.Rows.Count > 0)
  6349. {
  6350. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  6351. {
  6352. if (!DBHelper.IsU9())
  6353. ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  6354. }
  6355. }
  6356. asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
  6357. }
  6358. if (string.IsNullOrWhiteSpace(asncodes))
  6359. {
  6360. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  6361. }
  6362. #region 查询返回数据
  6363. sql = @"SELECT
  6364. n.POCode,
  6365. n.Sequence AS POSequence,
  6366. a.ASNCode,
  6367. a.DNCode,
  6368. a.Sequence,
  6369. a.VenCode,
  6370. a.DepCode,
  6371. a.InvCode,
  6372. inv.InvName,
  6373. inv.InvStd,
  6374. a.Quantity,
  6375. inv.InvUnit,
  6376. a.Amount,
  6377. inv.AmountUnit,
  6378. a.RCVQuantity,
  6379. a.UnitPrice,
  6380. a.Currency,
  6381. a.POID,
  6382. a.PODetailID,
  6383. a.DNID,
  6384. a.DNDetailID,
  6385. ext.ProjectCode,
  6386. ext.BatchCode,
  6387. ext.Version,
  6388. ext.Brand,
  6389. ext.cFree1,
  6390. ext.cFree2,
  6391. ext.cFree3,
  6392. ext.cFree4,
  6393. ext.cFree5,
  6394. ext.cFree6,
  6395. ext.cFree7,
  6396. ext.cFree8,
  6397. ext.cFree9,
  6398. ext.cFree10,
  6399. a.MUSER AS [User],
  6400. a.MTIME AS [MTime]
  6401. FROM ICSDeliveryNotice a
  6402. INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
  6403. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  6404. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  6405. WHERE a.ASNCode+a.WorkPoint IN ({0})";
  6406. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  6407. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6408. #endregion
  6409. cmd.Transaction.Commit();
  6410. return data;
  6411. }
  6412. catch (Exception ex)
  6413. {
  6414. if (cmd.Transaction != null)
  6415. cmd.Transaction.Rollback();
  6416. log.Error(ex.Message);
  6417. throw new Exception(ex.Message);
  6418. }
  6419. finally
  6420. {
  6421. if (conn.State == ConnectionState.Open)
  6422. {
  6423. conn.Close();
  6424. }
  6425. conn.Dispose();
  6426. }
  6427. }
  6428. }
  6429. /// <summary>
  6430. /// 采购到货
  6431. /// </summary>
  6432. /// <param name="JsonData"></param>
  6433. /// <returns></returns>
  6434. public static DataTable DxDeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  6435. {
  6436. var language = LanguageHelper.GetName("WMSAPIInfo");
  6437. if (JsonData.Count <= 0)
  6438. {
  6439. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6440. }
  6441. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6442. {
  6443. conn.Open();
  6444. SqlTransaction sqlTran = conn.BeginTransaction();
  6445. SqlCommand cmd = new SqlCommand();
  6446. cmd.Transaction = sqlTran;
  6447. cmd.Connection = conn;
  6448. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6449. try
  6450. {
  6451. string asncodes = string.Empty;
  6452. string DNCodes = string.Empty;
  6453. string DNLotNo = string.Empty;
  6454. string sql = string.Empty;
  6455. foreach (var item in JsonData)
  6456. {
  6457. if (string.IsNullOrEmpty(item.ASNCode))
  6458. {
  6459. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
  6460. }
  6461. sql = @"SELECT a.DNCode FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}'";
  6462. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  6463. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  6464. if (dt.Rows.Count > 0)
  6465. {
  6466. DNCodes = dt.Rows[0]["DNCode"].ToString();
  6467. }
  6468. log.Debug("已到货的到货单" + DNCodes);
  6469. //获取单号
  6470. sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  6471. BEGIN
  6472. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  6473. RETURN
  6474. END
  6475. DECLARE @Status VARCHAR(10)
  6476. SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  6477. IF (@Status IS NULL)
  6478. BEGIN
  6479. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  6480. RETURN
  6481. END
  6482. ELSE IF (@Status!='2')
  6483. BEGIN
  6484. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  6485. RETURN
  6486. END
  6487. DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  6488. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  6489. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  6490. IF @MaxNO IS NULL
  6491. BEGIN
  6492. SELECT @date+'00001' AS Code
  6493. END
  6494. ELSE
  6495. BEGIN
  6496. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  6497. END ";
  6498. sql = string.Format(sql, item.ASNCode, item.WorkPoint, DNCodes);
  6499. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  6500. //修改送货单到货数量
  6501. foreach (var itemInfo in item.detail)
  6502. {
  6503. sql = @"UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
  6504. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  6505. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  6506. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6507. {
  6508. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
  6509. }
  6510. sql = @"UPDATE ICSInventoryLot SET Quantity='{2}'
  6511. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  6512. if (itemInfo.IsUrgency == "1")
  6513. sql = @"UPDATE ICSInventoryLot SET Quantity='{2}' ,eattribute6 = '1' WHERE LotNo='{0}' AND WorkPoint='{1}'";
  6514. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  6515. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6516. {
  6517. throw new Exception(language.GetNameByCode("WMSAPIInfo462")); //"条码表信息更新失败!");
  6518. }
  6519. if (DNLotNo.Equals(""))
  6520. {
  6521. DNLotNo += "'" + itemInfo.LotNo + "'";
  6522. }
  6523. else
  6524. {
  6525. DNLotNo += ",'" + itemInfo.LotNo + "'";
  6526. }
  6527. }
  6528. //创建到货单信息
  6529. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  6530. BEGIN
  6531. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  6532. RETURN
  6533. END
  6534. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  6535. DNType,InvCode,Quantity,Amount,RCVQuantity,
  6536. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  6537. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  6538. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  6539. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  6540. '1',b.InvCode,SUM(a.DNQuantity),'0','0',
  6541. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  6542. d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,
  6543. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode
  6544. FROM ICSASNDetail a
  6545. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  6546. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  6547. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  6548. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  6549. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}' and a.DNQuantity>0 and b.lotno in ({4})
  6550. GROUP BY d.POID,d.PODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.ASNCode,e.F_Account,e.F_RealName,a.WorkPoint";
  6551. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode, DNLotNo);
  6552. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6553. {
  6554. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  6555. }
  6556. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  6557. {
  6558. if (!DBHelper.IsU9())
  6559. ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  6560. }
  6561. asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
  6562. }
  6563. if (string.IsNullOrWhiteSpace(asncodes))
  6564. {
  6565. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  6566. }
  6567. #region 查询返回数据
  6568. sql = @"SELECT
  6569. n.POCode,
  6570. n.Sequence AS POSequence,
  6571. a.ASNCode,
  6572. a.DNCode,
  6573. a.Sequence,
  6574. a.VenCode,
  6575. a.DepCode,
  6576. a.InvCode,
  6577. inv.InvName,
  6578. inv.InvStd,
  6579. a.Quantity,
  6580. inv.InvUnit,
  6581. a.Amount,
  6582. inv.AmountUnit,
  6583. a.RCVQuantity,
  6584. a.UnitPrice,
  6585. a.Currency,
  6586. a.POID,
  6587. a.PODetailID,
  6588. a.DNID,
  6589. a.DNDetailID,
  6590. ext.ProjectCode,
  6591. ext.BatchCode,
  6592. ext.Version,
  6593. ext.Brand,
  6594. ext.cFree1,
  6595. ext.cFree2,
  6596. ext.cFree3,
  6597. ext.cFree4,
  6598. ext.cFree5,
  6599. ext.cFree6,
  6600. ext.cFree7,
  6601. ext.cFree8,
  6602. ext.cFree9,
  6603. ext.cFree10,
  6604. a.MUSER AS [User],
  6605. a.MTIME AS [MTime]
  6606. FROM ICSDeliveryNotice a
  6607. INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
  6608. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  6609. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  6610. WHERE a.ASNCode+a.WorkPoint IN ({0})";
  6611. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  6612. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6613. #endregion
  6614. cmd.Transaction.Commit();
  6615. return data;
  6616. }
  6617. catch (Exception ex)
  6618. {
  6619. if (cmd.Transaction != null)
  6620. cmd.Transaction.Rollback();
  6621. log.Error(ex.Message);
  6622. throw new Exception(ex.Message);
  6623. }
  6624. finally
  6625. {
  6626. if (conn.State == ConnectionState.Open)
  6627. {
  6628. conn.Close();
  6629. }
  6630. conn.Dispose();
  6631. }
  6632. }
  6633. }
  6634. /// <summary>
  6635. /// 采购拒收
  6636. /// </summary>
  6637. /// <param name="JsonData"></param>
  6638. /// <returns></returns>
  6639. public static DataTable PurchaseRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  6640. {
  6641. var language = LanguageHelper.GetName("WMSAPIInfo");
  6642. if (JsonData.Count <= 0)
  6643. {
  6644. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6645. }
  6646. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6647. {
  6648. conn.Open();
  6649. SqlTransaction sqlTran = conn.BeginTransaction();
  6650. SqlCommand cmd = new SqlCommand();
  6651. cmd.Transaction = sqlTran;
  6652. cmd.Connection = conn;
  6653. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6654. try
  6655. {
  6656. string lots = string.Empty;
  6657. string sql = string.Empty;
  6658. foreach (var item in JsonData)
  6659. {
  6660. if (string.IsNullOrEmpty(item.DNCode))
  6661. {
  6662. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  6663. }
  6664. //获取单号
  6665. sql = @"DECLARE @Status VARCHAR(10)
  6666. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  6667. IF (@Status IS NULL)
  6668. BEGIN
  6669. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  6670. RETURN
  6671. END
  6672. ELSE IF (@Status!='2')
  6673. BEGIN
  6674. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  6675. RETURN
  6676. END
  6677. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  6678. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  6679. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  6680. IF @MaxNO IS NULL
  6681. BEGIN
  6682. SELECT @date+'00001' AS Code
  6683. END
  6684. ELSE
  6685. BEGIN
  6686. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  6687. END ";
  6688. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  6689. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  6690. //修改送货单到货数量
  6691. foreach (var itemInfo in item.detail)
  6692. {
  6693. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  6694. BEGIN
  6695. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  6696. RETURN
  6697. END
  6698. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  6699. BEGIN
  6700. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  6701. RETURN
  6702. END
  6703. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  6704. DNType,InvCode,Quantity,Amount,RCVQuantity,
  6705. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  6706. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  6707. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  6708. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  6709. '3',d.InvCode,'{7}', '{8}', 0,
  6710. '{9}', '{10}',
  6711. case when isnull(config.enable,0)=0 then '2' else '1' end,
  6712. e.F_Account, SYSDATETIME(),
  6713. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  6714. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, d.LOTNO,''
  6715. FROM ICSDeliveryNotice a
  6716. INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  6717. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint and a.ExtensionID = d.ExtensionID
  6718. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  6719. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  6720. INNER JOIN ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint and h.enable = 1
  6721. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  6722. left join icsConfiguration config on 1=1 and config.Code ='SaveReview001'
  6723. WHERE a.DNCode='{0}' and d.LOTNO='{1}' AND a.WorkPoint='{2}'";
  6724. sql = string.Format(sql, item.DNCode, itemInfo.LotNo, item.WorkPoint, item.User, Code, item.VenCode, item.DepCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.UnitPrice, itemInfo.Currency, itemInfo.Sequence);
  6725. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6726. {
  6727. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  6728. }
  6729. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  6730. }
  6731. //增加了webconfig 判断不是U9,调用U8接口
  6732. string sqlCheckSign = @"select * from ICSConfiguration where code = 'UploadERP003' and enable = '1'";
  6733. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  6734. if (flag != null && flag.Rows.Count > 0)
  6735. {
  6736. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]) && !DBHelper.IsU9())
  6737. ICSPurchaseService.PurchaseRejectDocInNewERP(item.DNCode, Code, item.WorkPoint, cmd, language);
  6738. }
  6739. }
  6740. if (string.IsNullOrWhiteSpace(lots))
  6741. {
  6742. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  6743. }
  6744. #region 查询返回数据
  6745. sql = @"SELECT
  6746. n.DNCode,
  6747. n.Sequence,
  6748. a.DNCode AS RJTCode,
  6749. a.Sequence AS RJTSequence,
  6750. a.VenCode,
  6751. a.DepCode,
  6752. a.InvCode,
  6753. inv.InvName,
  6754. inv.InvStd,
  6755. a.Quantity,
  6756. inv.InvUnit,
  6757. a.Amount,
  6758. inv.AmountUnit,
  6759. a.RCVQuantity,
  6760. a.UnitPrice,
  6761. a.Currency,
  6762. a.POID,
  6763. a.PODetailID,
  6764. a.DNID,
  6765. a.DNDetailID,
  6766. ext.ProjectCode,
  6767. ext.BatchCode,
  6768. ext.Version,
  6769. ext.Brand,
  6770. ext.cFree1,
  6771. ext.cFree2,
  6772. ext.cFree3,
  6773. ext.cFree4,
  6774. ext.cFree5,
  6775. ext.cFree6,
  6776. ext.cFree7,
  6777. ext.cFree8,
  6778. ext.cFree9,
  6779. ext.cFree10,
  6780. a.MUSER AS [User],
  6781. a.MTIME AS [MTime]
  6782. FROM ICSDeliveryNotice a
  6783. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  6784. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  6785. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  6786. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  6787. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  6788. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6789. #endregion
  6790. cmd.Transaction.Commit();
  6791. return data;
  6792. }
  6793. catch (Exception ex)
  6794. {
  6795. if (cmd.Transaction != null)
  6796. cmd.Transaction.Rollback();
  6797. log.Error(ex.Message);
  6798. throw new Exception(ex.Message);
  6799. }
  6800. finally
  6801. {
  6802. if (conn.State == ConnectionState.Open)
  6803. {
  6804. conn.Close();
  6805. }
  6806. conn.Dispose();
  6807. }
  6808. }
  6809. }
  6810. /// <summary>
  6811. /// 无订单采购拒收
  6812. /// </summary>
  6813. /// <param name="JsonData"></param>
  6814. /// <returns></returns>
  6815. public static DataTable PurchaseRejectDocNoTransCreate(List<ICSDeliveryNotice> JsonData)
  6816. {
  6817. var language = LanguageHelper.GetName("WMSAPIInfo");
  6818. if (JsonData.Count <= 0)
  6819. {
  6820. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6821. }
  6822. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6823. {
  6824. conn.Open();
  6825. SqlTransaction sqlTran = conn.BeginTransaction();
  6826. SqlCommand cmd = new SqlCommand();
  6827. cmd.Transaction = sqlTran;
  6828. cmd.Connection = conn;
  6829. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6830. try
  6831. {
  6832. string lots = string.Empty;
  6833. string sql = string.Empty;
  6834. foreach (var item in JsonData)
  6835. {
  6836. if (string.IsNullOrEmpty(item.DNCode))
  6837. {
  6838. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  6839. }
  6840. //获取单号
  6841. sql = @"DECLARE @Status VARCHAR(10)
  6842. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  6843. IF (@Status IS NULL)
  6844. BEGIN
  6845. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  6846. RETURN
  6847. END
  6848. ELSE IF (@Status!='2')
  6849. BEGIN
  6850. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  6851. RETURN
  6852. END
  6853. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  6854. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  6855. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  6856. IF @MaxNO IS NULL
  6857. BEGIN
  6858. SELECT @date+'00001' AS Code
  6859. END
  6860. ELSE
  6861. BEGIN
  6862. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  6863. END ";
  6864. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  6865. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  6866. //修改送货单到货数量
  6867. foreach (var itemInfo in item.detail)
  6868. {
  6869. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  6870. BEGIN
  6871. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  6872. RETURN
  6873. END
  6874. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  6875. BEGIN
  6876. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  6877. RETURN
  6878. END
  6879. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  6880. DNType,InvCode,Quantity,Amount,RCVQuantity,
  6881. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  6882. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  6883. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  6884. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  6885. '3',d.InvCode,'{7}', '{8}', 0,
  6886. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  6887. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  6888. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, d.LOTNO,''
  6889. FROM ICSDeliveryNotice a
  6890. --INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  6891. INNER JOIN ICSInventoryLotDetail m on a.DNCode=m.TransCode and a.Sequence=m.TransSequence and a.WorkPoint=m.WorkPoint
  6892. INNER JOIN ICSInventoryLot d ON m.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint
  6893. --INNER JOIN ICSPurchaseOrder n ON a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  6894. INNER JOIN ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint and h.enable = 1
  6895. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  6896. WHERE a.DNCode='{0}' and d.LOTNO='{1}' AND a.WorkPoint='{2}'";
  6897. sql = string.Format(sql, item.DNCode, itemInfo.LotNo, item.WorkPoint, item.User, Code, item.VenCode, item.DepCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.UnitPrice, itemInfo.Currency, itemInfo.Sequence);
  6898. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6899. {
  6900. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  6901. }
  6902. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  6903. }
  6904. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"])&&!DBHelper.IsRTU9())
  6905. ICSPurchaseService.PurchaseRejectDocInNewERP(item.DNCode, Code, item.WorkPoint, cmd, language);
  6906. }
  6907. if (string.IsNullOrWhiteSpace(lots))
  6908. {
  6909. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  6910. }
  6911. #region 查询返回数据
  6912. sql = @"SELECT
  6913. n.DNCode,
  6914. n.Sequence,
  6915. a.DNCode AS RJTCode,
  6916. a.Sequence AS RJTSequence,
  6917. a.VenCode,
  6918. a.DepCode,
  6919. a.InvCode,
  6920. inv.InvName,
  6921. inv.InvStd,
  6922. a.Quantity,
  6923. inv.InvUnit,
  6924. a.Amount,
  6925. inv.AmountUnit,
  6926. a.RCVQuantity,
  6927. a.UnitPrice,
  6928. a.Currency,
  6929. a.POID,
  6930. a.PODetailID,
  6931. a.DNID,
  6932. a.DNDetailID,
  6933. ext.ProjectCode,
  6934. ext.BatchCode,
  6935. ext.Version,
  6936. ext.Brand,
  6937. ext.cFree1,
  6938. ext.cFree2,
  6939. ext.cFree3,
  6940. ext.cFree4,
  6941. ext.cFree5,
  6942. ext.cFree6,
  6943. ext.cFree7,
  6944. ext.cFree8,
  6945. ext.cFree9,
  6946. ext.cFree10,
  6947. a.MUSER AS [User],
  6948. a.MTIME AS [MTime]
  6949. FROM ICSDeliveryNotice a
  6950. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  6951. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  6952. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  6953. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  6954. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  6955. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6956. #endregion
  6957. cmd.Transaction.Commit();
  6958. return data;
  6959. }
  6960. catch (Exception ex)
  6961. {
  6962. if (cmd.Transaction != null)
  6963. cmd.Transaction.Rollback();
  6964. log.Error(ex.Message);
  6965. throw new Exception(ex.Message);
  6966. }
  6967. finally
  6968. {
  6969. if (conn.State == ConnectionState.Open)
  6970. {
  6971. conn.Close();
  6972. }
  6973. conn.Dispose();
  6974. }
  6975. }
  6976. }
  6977. /// <summary>
  6978. /// 采购订单
  6979. /// </summary>
  6980. /// <param name="JsonData"></param>
  6981. /// <returns></returns>
  6982. public static DataTable PurOrderCreate(List<ICSPurchaseOrder> JsonData)
  6983. {
  6984. var language = LanguageHelper.GetName("WMSAPIInfo");
  6985. if (JsonData.Count <= 0)
  6986. {
  6987. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6988. }
  6989. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6990. {
  6991. conn.Open();
  6992. SqlTransaction sqlTran = conn.BeginTransaction();
  6993. SqlCommand cmd = new SqlCommand();
  6994. cmd.Transaction = sqlTran;
  6995. cmd.Connection = conn;
  6996. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6997. try
  6998. {
  6999. string codes = string.Empty;
  7000. string sql = string.Empty;
  7001. string Colspan = string.Empty;
  7002. string IDD = string.Empty;
  7003. //获取单号
  7004. sql = @"DECLARE @MaxNO INT,@date varchar(20)='POIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  7005. SELECT @MaxNO=SUBSTRING(MAX(POCode),LEN(@date)+1,LEN(MAX(POCode))-LEN(@date))+1 FROM ICSPurchaseOrder
  7006. WHERE SUBSTRING(POCode, 1, LEN(@date))=@date
  7007. IF @MaxNO IS NULL
  7008. BEGIN
  7009. SELECT @date+'00001' AS Code
  7010. END
  7011. ELSE
  7012. BEGIN
  7013. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  7014. END ";
  7015. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  7016. HashSet<string> uniqueItems = new HashSet<string>();
  7017. foreach (var item in JsonData)
  7018. {
  7019. //检验自由项
  7020. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  7021. + "~" + item.Brand + "~" + item.cFree1
  7022. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  7023. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  7024. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  7025. sql = @"select ID,Colspan from ICSExtension a
  7026. where Colspan='{0}' and WorkPoint='{1}'";
  7027. sql = string.Format(sql, Colspan, item.WorkPoint);
  7028. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  7029. if (dttt.Rows.Count == 0)
  7030. {
  7031. IDD = Guid.NewGuid().ToString();
  7032. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  7033. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  7034. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  7035. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7036. {
  7037. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  7038. }
  7039. }
  7040. else
  7041. {
  7042. IDD = dttt.Rows[0]["ID"].ToString();
  7043. }
  7044. string key = item.Sequence + "~" + item.InvCode;
  7045. if (uniqueItems.Contains(key))
  7046. {
  7047. throw new Exception("子件不可重复添加!");
  7048. }
  7049. uniqueItems.Add(key);
  7050. //创建主表
  7051. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{6}' AND F_Location='{4}')
  7052. BEGIN
  7053. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{6}") + @"',16,1);
  7054. RETURN
  7055. END
  7056. INSERT INTO ICSPurchaseOrder(ID,POCode ,Sequence,VenCode,DepCode
  7057. ,PersonCode,POType,InvCode,Quantity,Amount
  7058. ,InQuantity,UnitPrice,Currency ,Status ,CreatePerson
  7059. ,CreateDateTime ,ReleaseState ,ReleaseDate,PlanArriveDate,ArriveUser,ArriveDate
  7060. ,DeliveryUser ,DeliveryDate,PRID ,PRDetailID ,POID
  7061. ,PODetailID ,ExtensionID ,MUSER,MUSERName,MTIME
  7062. ,WorkPoint ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10)
  7063. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  7064. '','1','{5}','{8}',0,
  7065. 0,0,'','1','',
  7066. '{7}','0','','','','',
  7067. '','','0','0','',
  7068. '','{9}','{6}',(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{4}'),'{7}',
  7069. '{4}','','','','','','','','','','')";
  7070. sql = string.Format(sql, Code, item.Sequence, item.VenCode, item.DepCode,item.WorkPoint, item.InvCode, item.User,
  7071. item.MTime, item.Quantity, IDD);
  7072. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7073. {
  7074. throw new Exception(language.GetNameByCode("WMSAPIInfo0206"));//"采购订单信息创建失败!!");
  7075. }
  7076. codes += "'" + Code + item.WorkPoint + "',";
  7077. }
  7078. if (string.IsNullOrWhiteSpace(codes))
  7079. {
  7080. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  7081. }
  7082. #region 查询返回数据
  7083. sql = @"SELECT a.POCode,a.Sequence,
  7084. a.VenCode,a.DepCode,a.PersonCode,
  7085. d.Name AS Status,
  7086. a.Sequence,
  7087. a.InvCode,
  7088. inv.InvName,
  7089. inv.InvStd,
  7090. a.Quantity,
  7091. inv.InvUnit,
  7092. a.Amount,
  7093. inv.AmountUnit,
  7094. a.InQuantity,
  7095. ext.ProjectCode,
  7096. ext.BatchCode,
  7097. ext.Version,
  7098. ext.Brand,
  7099. ext.cFree1,
  7100. ext.cFree2,
  7101. ext.cFree3,
  7102. ext.cFree4,
  7103. ext.cFree5,
  7104. ext.cFree6,
  7105. ext.cFree7,
  7106. ext.cFree8,
  7107. ext.cFree9,
  7108. ext.cFree10,
  7109. a.MUSER AS [User],
  7110. a.MTIME AS [MTime]
  7111. FROM ICSPurchaseOrder a
  7112. LEFT JOIN ICSType d ON d.TableCode='ICSPurchaseOrder' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  7113. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  7114. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  7115. WHERE a.POCode+a.WorkPoint IN ({0})";
  7116. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  7117. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7118. #endregion
  7119. cmd.Transaction.Commit();
  7120. return data;
  7121. }
  7122. catch (Exception ex)
  7123. {
  7124. if (cmd.Transaction != null)
  7125. cmd.Transaction.Rollback();
  7126. log.Error(ex.Message);
  7127. throw new Exception(ex.Message);
  7128. }
  7129. finally
  7130. {
  7131. if (conn.State == ConnectionState.Open)
  7132. {
  7133. conn.Close();
  7134. }
  7135. conn.Dispose();
  7136. }
  7137. }
  7138. }
  7139. /// <summary>
  7140. /// 采购订单 修改
  7141. /// </summary>
  7142. /// <param name="JsonData"></param>
  7143. /// <returns></returns>
  7144. public static DataTable ICSPurOrderUpdate(List<ICSPurchaseOrder> JsonData)
  7145. {
  7146. var language = LanguageHelper.GetName("WMSAPIInfo");
  7147. if (JsonData.Count <= 0)
  7148. {
  7149. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7150. }
  7151. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7152. {
  7153. conn.Open();
  7154. SqlTransaction sqlTran = conn.BeginTransaction();
  7155. SqlCommand cmd = new SqlCommand();
  7156. cmd.Transaction = sqlTran;
  7157. cmd.Connection = conn;
  7158. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7159. try
  7160. {
  7161. string sql = string.Empty;
  7162. string Checksql = string.Empty;
  7163. string Code = string.Empty;
  7164. string ids = string.Empty;
  7165. string Colspan = string.Empty;
  7166. string IDD = string.Empty;
  7167. foreach (var item in JsonData)
  7168. {
  7169. //检验自由项
  7170. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  7171. + "~" + item.Brand + "~" + item.cFree1
  7172. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  7173. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  7174. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  7175. Checksql = @"select ID,Colspan from ICSExtension a
  7176. where Colspan='{0}' and WorkPoint='{1}'";
  7177. Checksql = string.Format(Checksql, Colspan, item.WorkPoint);
  7178. DataTable dttt = DBHelper.SQlReturnData(Checksql, cmd);
  7179. if (dttt.Rows.Count == 0)
  7180. {
  7181. IDD = Guid.NewGuid().ToString();
  7182. Checksql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  7183. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  7184. Checksql = string.Format(Checksql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  7185. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  7186. {
  7187. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  7188. }
  7189. }
  7190. else
  7191. {
  7192. IDD = dttt.Rows[0]["ID"].ToString();
  7193. }
  7194. //主表修改
  7195. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  7196. BEGIN
  7197. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  7198. RETURN
  7199. END
  7200. DECLARE @Status VARCHAR(10)
  7201. SELECT distinct @Status=Status FROM ICSPurchaseOrder WHERE PoCode='{0}' and WorkPoint='{6}'
  7202. IF (@Status IS NULL)
  7203. BEGIN
  7204. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo0205"), "{0}") + @"',16,1);
  7205. RETURN
  7206. END
  7207. ELSE IF (@Status!='1')
  7208. BEGIN
  7209. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo0202"), "{0}") + @"',16,1);
  7210. RETURN
  7211. END
  7212. ";
  7213. sql = string.Format(sql, item.PoCode, item.Sequence, item.InvCode, item.Quantity, item.User,
  7214. item.MTime, item.WorkPoint);
  7215. if (!string.IsNullOrWhiteSpace(item.Sequence))
  7216. {
  7217. //创建子表
  7218. sql += @"IF EXISTS(Select * from ICSPurchaseOrder where PoCode ='{0}'and Sequence ='{1}')
  7219. Begin
  7220. UPDATE ICSPurchaseOrder set InvCode='{5}',Quantity='{8}',MUSER= '{6}',VenCode = '{2}',DepCode = '{3}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{4}'),MTIME='{7}'
  7221. where PoCode ='{0}'and Sequence ='{1}'
  7222. UPDATE b set b.ProjectCode='{10}',b.BatchCode='{11}',b.Version='{12}',b.Brand='{13}',
  7223. b.cFree1='{14}',b.cFree2='{15}',b.cFree3='{16}',b.cFree4='{17}',b.cFree5='{18}',b.cFree6='{19}',b.cFree7='{20}',
  7224. b.cFree8='{21}',b.cFree9='{22}',b.cFree10='{23}'
  7225. from ICSPurchaseOrder a
  7226. INNER JOIN ICSExtension b ON a.ExtensionID=b.id and a.workpoint=b.workpoint
  7227. where a.PoCode ='{0}'and a.Sequence ='{1}'
  7228. END
  7229. ELSE
  7230. BEGIN
  7231. INSERT INTO ICSPurchaseOrder
  7232. (ID,POCode ,Sequence,VenCode,DepCode
  7233. ,PersonCode,POType,InvCode,Quantity,Amount
  7234. ,InQuantity,UnitPrice,Currency ,Status ,CreatePerson
  7235. ,CreateDateTime ,ReleaseState ,ReleaseDate,PlanArriveDate,ArriveUser,ArriveDate
  7236. ,DeliveryUser ,DeliveryDate,PRID ,PRDetailID ,POID
  7237. ,PODetailID ,ExtensionID ,MUSER,MUSERName,MTIME
  7238. ,WorkPoint ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10)
  7239. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  7240. '','1','{5}','{8}',0,
  7241. 0,0,'','1','',
  7242. '','0','','','','',
  7243. '','','0','0','',
  7244. '','',(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{4}'),'{6}','{7}',
  7245. '{4}','','','','','','','','','','')
  7246. END";
  7247. sql = string.Format(sql, item.PoCode, item.Sequence, item.VenCode, item.DepCode, item.WorkPoint, item.InvCode, item.User,
  7248. item.MTime, item.Quantity, IDD, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10);
  7249. }
  7250. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7251. {
  7252. throw new Exception(language.GetNameByCode("WMSAPIInfo0204"));//"采购订单信息修改失败!");
  7253. }
  7254. ids += "'" + item.Sequence + "',";
  7255. Code = item.PoCode;
  7256. }
  7257. sql = @"DELETE from ICSPurchaseOrder where PoCode ='{0}' and Sequence not in ({1})";
  7258. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  7259. DBHelper.ExecuteNonQuery(sql, cmd);
  7260. #region 查询返回数据
  7261. sql = @"SELECT a.POCode,a.Sequence,
  7262. a.VenCode,a.DepCode,a.PersonCode,
  7263. d.Name AS Status,
  7264. a.Sequence,
  7265. a.InvCode,
  7266. inv.InvName,
  7267. inv.InvStd,
  7268. a.Quantity,
  7269. inv.InvUnit,
  7270. a.Amount,
  7271. inv.AmountUnit,
  7272. a.InQuantity,
  7273. ext.ProjectCode,
  7274. ext.BatchCode,
  7275. ext.Version,
  7276. ext.Brand,
  7277. ext.cFree1,
  7278. ext.cFree2,
  7279. ext.cFree3,
  7280. ext.cFree4,
  7281. ext.cFree5,
  7282. ext.cFree6,
  7283. ext.cFree7,
  7284. ext.cFree8,
  7285. ext.cFree9,
  7286. ext.cFree10,
  7287. a.MUSER AS [User],
  7288. a.MTIME AS [MTime]
  7289. FROM ICSPurchaseOrder a
  7290. LEFT JOIN ICSType d ON d.TableCode='ICSPurchaseOrder' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  7291. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  7292. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  7293. WHERE a.POCode+a.WorkPoint IN ('{0}')";
  7294. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  7295. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7296. #endregion
  7297. cmd.Transaction.Commit();
  7298. return data;
  7299. }
  7300. catch (Exception ex)
  7301. {
  7302. if (cmd.Transaction != null)
  7303. cmd.Transaction.Rollback();
  7304. log.Error(ex.Message);
  7305. throw new Exception(ex.Message);
  7306. }
  7307. finally
  7308. {
  7309. if (conn.State == ConnectionState.Open)
  7310. {
  7311. conn.Close();
  7312. }
  7313. conn.Dispose();
  7314. }
  7315. }
  7316. }
  7317. /// <summary>
  7318. /// 采购订单审核
  7319. /// </summary>
  7320. /// <param name="JsonData"></param>
  7321. /// <returns></returns>
  7322. public static DataTable PurOrderApprove(List<ICSUser> JsonData)
  7323. {
  7324. string flag = string.Empty;
  7325. var language = LanguageHelper.GetName("WMSAPIInfo");
  7326. if (JsonData.Count <= 0)
  7327. {
  7328. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7329. }
  7330. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7331. {
  7332. conn.Open();
  7333. SqlTransaction sqlTran = conn.BeginTransaction();
  7334. SqlCommand cmd = new SqlCommand();
  7335. cmd.Transaction = sqlTran;
  7336. cmd.Connection = conn;
  7337. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7338. try
  7339. {
  7340. string sql = string.Empty;
  7341. string ids = string.Empty;
  7342. foreach (var item in JsonData)
  7343. {
  7344. bool hasApproveFlag = JsonData.Any(u => u.ApproveFlag != null);
  7345. if (hasApproveFlag == true)
  7346. {
  7347. flag = item.ApproveFlag;
  7348. }
  7349. if (string.IsNullOrEmpty(item.ID))
  7350. {
  7351. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  7352. }
  7353. if (string.IsNullOrEmpty(item.User))
  7354. {
  7355. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  7356. }
  7357. if (item.MTime <= new DateTime(2000, 1, 1))
  7358. {
  7359. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  7360. }
  7361. if (flag.Equals("1")|| flag=="")
  7362. {
  7363. //获取单号
  7364. sql = @"DECLARE @Status VARCHAR(10)
  7365. SELECT @Status=Status FROM ICSPurchaseOrder WHERE PoCode='{0}'
  7366. IF (@Status IS NULL)
  7367. BEGIN
  7368. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  7369. RETURN
  7370. END
  7371. ELSE IF (@Status!='1')
  7372. BEGIN
  7373. RAISERROR('" + language.GetNameByCode("WMSAPIInfo0202") + @"',16,1);
  7374. RETURN
  7375. END
  7376. update ICSPurchaseOrder set Status='2',MUSER='{1}',MTIME='{2}' where PoCode='{0}'";
  7377. sql = string.Format(sql, item.ID, item.User, item.MTime);
  7378. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7379. {
  7380. throw new Exception(language.GetNameByCode("WMSAPIInfo0203"));//"采购订单审核失败!");
  7381. }
  7382. ids += "'" + item.ID + "',";
  7383. }
  7384. else
  7385. {
  7386. //获取单号
  7387. sql = @"DECLARE @Status VARCHAR(10)
  7388. SELECT @Status=Status FROM ICSPurchaseOrder WHERE PoCode='{0}'
  7389. IF (@Status IS NULL)
  7390. BEGIN
  7391. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  7392. RETURN
  7393. END
  7394. ELSE IF (@Status!='2')
  7395. BEGIN
  7396. RAISERROR('" + language.GetNameByCode("WMSAPIInfo473") + @"',16,1);
  7397. RETURN
  7398. END
  7399. IF EXISTS (select id from ICSPurchaseOrder where PoCode='{0}' and InQuantity>0)
  7400. BEGIN
  7401. RAISERROR('" + language.GetNameByCode("WMSAPIInfo474") + @"',16,1);
  7402. RETURN
  7403. END
  7404. update ICSPurchaseOrder set Status='1',MUSER='{1}',MTIME='{2}' where PoCode='{0}'";
  7405. sql = string.Format(sql, item.ID, item.User, item.MTime);
  7406. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7407. {
  7408. throw new Exception(language.GetNameByCode("WMSAPIInfo475"));//"采购订单弃审失败!");
  7409. }
  7410. ids += "'" + item.ID + "',";
  7411. }
  7412. }
  7413. if (string.IsNullOrWhiteSpace(ids))
  7414. {
  7415. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  7416. }
  7417. #region 查询返回数据
  7418. sql = @"SELECT a.POCode,a.Sequence,
  7419. a.VenCode,a.DepCode,a.PersonCode,
  7420. d.Name AS Status,
  7421. a.Sequence,
  7422. a.InvCode,
  7423. inv.InvName,
  7424. inv.InvStd,
  7425. a.Quantity,
  7426. inv.InvUnit,
  7427. a.Amount,
  7428. inv.AmountUnit,
  7429. a.InQuantity,
  7430. ext.ProjectCode,
  7431. ext.BatchCode,
  7432. ext.Version,
  7433. ext.Brand,
  7434. ext.cFree1,
  7435. ext.cFree2,
  7436. ext.cFree3,
  7437. ext.cFree4,
  7438. ext.cFree5,
  7439. ext.cFree6,
  7440. ext.cFree7,
  7441. ext.cFree8,
  7442. ext.cFree9,
  7443. ext.cFree10,
  7444. a.MUSER AS [User],
  7445. a.MTIME AS [MTime]
  7446. FROM ICSPurchaseOrder a
  7447. LEFT JOIN ICSType d ON d.TableCode='ICSPurchaseOrder' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  7448. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  7449. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  7450. WHERE a.ID IN ({0})";
  7451. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  7452. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7453. #endregion
  7454. cmd.Transaction.Commit();
  7455. return data;
  7456. }
  7457. catch (Exception ex)
  7458. {
  7459. if (cmd.Transaction != null)
  7460. cmd.Transaction.Rollback();
  7461. log.Error(ex.Message);
  7462. throw new Exception(ex.Message);
  7463. }
  7464. finally
  7465. {
  7466. if (conn.State == ConnectionState.Open)
  7467. {
  7468. conn.Close();
  7469. }
  7470. conn.Dispose();
  7471. }
  7472. }
  7473. }
  7474. /// <summary>
  7475. /// 销售订单审核
  7476. /// </summary>
  7477. /// <param name="JsonData"></param>
  7478. /// <returns></returns>
  7479. public static DataTable SalesOrderApprove(List<ICSUser> JsonData)
  7480. {
  7481. string flag = string.Empty;
  7482. var language = LanguageHelper.GetName("WMSAPIInfo");
  7483. if (JsonData.Count <= 0)
  7484. {
  7485. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7486. }
  7487. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7488. {
  7489. conn.Open();
  7490. SqlTransaction sqlTran = conn.BeginTransaction();
  7491. SqlCommand cmd = new SqlCommand();
  7492. cmd.Transaction = sqlTran;
  7493. cmd.Connection = conn;
  7494. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7495. try
  7496. {
  7497. string sql = string.Empty;
  7498. string ids = string.Empty;
  7499. foreach (var item in JsonData)
  7500. {
  7501. bool hasApproveFlag = JsonData.Any(u => u.ApproveFlag != null);
  7502. if (hasApproveFlag==true)
  7503. {
  7504. flag = item.ApproveFlag;
  7505. }
  7506. if (string.IsNullOrEmpty(item.ID))
  7507. {
  7508. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  7509. }
  7510. if (string.IsNullOrEmpty(item.User))
  7511. {
  7512. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  7513. }
  7514. if (item.MTime <= new DateTime(2000, 1, 1))
  7515. {
  7516. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  7517. }
  7518. if (flag.Equals("1")|| flag=="")
  7519. {
  7520. //获取单号
  7521. sql = @"DECLARE @Status VARCHAR(10)
  7522. SELECT @Status=Status FROM ICSSDN WHERE SDNCode='{0}'
  7523. IF (@Status IS NULL)
  7524. BEGIN
  7525. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  7526. RETURN
  7527. END
  7528. ELSE IF (@Status!='1')
  7529. BEGIN
  7530. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  7531. RETURN
  7532. END
  7533. update ICSSDN set Status='2',MUSER='{1}',MTIME='{2}' where SDNCode='{0}'";
  7534. sql = string.Format(sql, item.ID, item.User, item.MTime);
  7535. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7536. {
  7537. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  7538. }
  7539. ids += "'" + item.ID + "',";
  7540. }
  7541. else
  7542. {
  7543. //获取单号
  7544. sql = @"DECLARE @Status VARCHAR(10)
  7545. SELECT @Status=Status FROM ICSSDN WHERE SDNCode='{0}'
  7546. IF (@Status IS NULL)
  7547. BEGIN
  7548. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  7549. RETURN
  7550. END
  7551. ELSE IF (@Status!='2')
  7552. BEGIN
  7553. RAISERROR('" + language.GetNameByCode("WMSAPIInfo473") + @"',16,1);
  7554. RETURN
  7555. END
  7556. IF EXISTS (select id from ICSSDN where SDNCode='{0}' and SDNQuantity>0)
  7557. BEGIN
  7558. RAISERROR('" + language.GetNameByCode("WMSAPIInfo474") + @"',16,1);
  7559. RETURN
  7560. END
  7561. update ICSSDN set Status='1',MUSER='{1}',MTIME='{2}' where SDNCode='{0}'";
  7562. sql = string.Format(sql, item.ID, item.User, item.MTime);
  7563. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7564. {
  7565. throw new Exception(language.GetNameByCode("WMSAPIInfo475"));//"生产退料申请单审核失败!");
  7566. }
  7567. ids += "'" + item.ID + "',";
  7568. }
  7569. }
  7570. if (string.IsNullOrWhiteSpace(ids))
  7571. {
  7572. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  7573. }
  7574. #region 查询返回数据
  7575. sql = @"SELECT a.SDNCode,a.Sequence,
  7576. d.Name AS Status,
  7577. a.Sequence,
  7578. a.InvCode,
  7579. inv.InvName,
  7580. inv.InvStd,
  7581. a.Quantity,
  7582. inv.InvUnit,
  7583. a.Amount,
  7584. inv.AmountUnit,
  7585. ext.ProjectCode,
  7586. ext.BatchCode,
  7587. ext.Version,
  7588. ext.Brand,
  7589. ext.cFree1,
  7590. ext.cFree2,
  7591. ext.cFree3,
  7592. ext.cFree4,
  7593. ext.cFree5,
  7594. ext.cFree6,
  7595. ext.cFree7,
  7596. ext.cFree8,
  7597. ext.cFree9,
  7598. ext.cFree10,
  7599. a.MUSER AS [User],
  7600. a.MTIME AS [MTime]
  7601. FROM ICSSDN a
  7602. LEFT JOIN ICSType d ON d.TableCode='ICSSDN' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  7603. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  7604. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  7605. WHERE a.SDNCode IN ({0})";
  7606. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  7607. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7608. #endregion
  7609. cmd.Transaction.Commit();
  7610. return data;
  7611. }
  7612. catch (Exception ex)
  7613. {
  7614. if (cmd.Transaction != null)
  7615. cmd.Transaction.Rollback();
  7616. log.Error(ex.Message);
  7617. throw new Exception(ex.Message);
  7618. }
  7619. finally
  7620. {
  7621. if (conn.State == ConnectionState.Open)
  7622. {
  7623. conn.Close();
  7624. }
  7625. conn.Dispose();
  7626. }
  7627. }
  7628. }
  7629. /// <summary>
  7630. /// 生产订单审核
  7631. /// </summary>
  7632. /// <param name="JsonData"></param>
  7633. /// <returns></returns>
  7634. public static DataTable ICSMOApprove(List<ICSUser> JsonData)
  7635. {
  7636. string flag = string.Empty;
  7637. var language = LanguageHelper.GetName("WMSAPIInfo");
  7638. if (JsonData.Count <= 0)
  7639. {
  7640. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7641. }
  7642. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7643. {
  7644. conn.Open();
  7645. SqlTransaction sqlTran = conn.BeginTransaction();
  7646. SqlCommand cmd = new SqlCommand();
  7647. cmd.Transaction = sqlTran;
  7648. cmd.Connection = conn;
  7649. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7650. try
  7651. {
  7652. string sql = string.Empty;
  7653. string ids = string.Empty;
  7654. foreach (var item in JsonData)
  7655. {
  7656. bool hasApproveFlag = JsonData.Any(u => u.ApproveFlag != null);
  7657. if (hasApproveFlag == true)
  7658. {
  7659. flag = item.ApproveFlag;
  7660. }
  7661. if (string.IsNullOrEmpty(item.ID))
  7662. {
  7663. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  7664. }
  7665. if (string.IsNullOrEmpty(item.User))
  7666. {
  7667. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  7668. }
  7669. if (item.MTime <= new DateTime(2000, 1, 1))
  7670. {
  7671. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  7672. }
  7673. if (flag.Equals("1")|| flag=="")
  7674. {
  7675. //获取单号
  7676. sql = @"DECLARE @Status VARCHAR(10)
  7677. SELECT @Status=MOStatus FROM ICSMO WHERE mocode='{0}'
  7678. IF (@Status IS NULL)
  7679. BEGIN
  7680. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  7681. RETURN
  7682. END
  7683. ELSE IF (@Status!='1')
  7684. BEGIN
  7685. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  7686. RETURN
  7687. END
  7688. update ICSMO set MOStatus='2',MUSER='{1}',MTIME='{2}' where mocode='{0}'";
  7689. sql = string.Format(sql, item.ID, item.User, item.MTime);
  7690. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7691. {
  7692. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  7693. }
  7694. ids += "'" + item.ID + "',";
  7695. }
  7696. else
  7697. {
  7698. //获取单号
  7699. sql = @"DECLARE @Status VARCHAR(10)
  7700. SELECT @Status=MOStatus FROM ICSMO WHERE mocode='{0}'
  7701. IF (@Status IS NULL)
  7702. BEGIN
  7703. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  7704. RETURN
  7705. END
  7706. ELSE IF (@Status!='2')
  7707. BEGIN
  7708. RAISERROR('" + language.GetNameByCode("WMSAPIInfo473") + @"',16,1);
  7709. RETURN
  7710. END
  7711. IF EXISTS (select id from ICSMO where MOCode='{0}' and RCVQuantity>0)
  7712. BEGIN
  7713. RAISERROR('" + language.GetNameByCode("WMSAPIInfo474") + @"',16,1);
  7714. RETURN
  7715. END
  7716. update ICSMO set MOStatus='1',MUSER='{1}',MTIME='{2}' where mocode='{0}'";
  7717. sql = string.Format(sql, item.ID, item.User, item.MTime);
  7718. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7719. {
  7720. throw new Exception(language.GetNameByCode("WMSAPIInfo475"));//"生产退料申请单审核失败!");
  7721. }
  7722. ids += "'" + item.ID + "',";
  7723. }
  7724. }
  7725. if (string.IsNullOrWhiteSpace(ids))
  7726. {
  7727. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  7728. }
  7729. #region 查询返回数据
  7730. sql = @"SELECT a.ID, a.MOCode, a.Sequence, a.InvCode, a.Quantity,
  7731. a.Amount, a.RCVQuantity, a.DepCode, a.WHCode, a.StartDate, a.DueDate,
  7732. a.MOStatus, a.MOMemo, a.CreatePerson, a.CreateDateTime, a.ERPStatus, a.MOID, a.MODetailID,
  7733. a.ExtensionID, a.MUSER, a.MUSERName, a.MTIME, a.WorkPoint
  7734. FROM ICSMO a
  7735. WHERE a.mocode IN ({0})";
  7736. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  7737. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7738. #endregion
  7739. cmd.Transaction.Commit();
  7740. return data;
  7741. }
  7742. catch (Exception ex)
  7743. {
  7744. if (cmd.Transaction != null)
  7745. cmd.Transaction.Rollback();
  7746. log.Error(ex.Message);
  7747. throw new Exception(ex.Message);
  7748. }
  7749. finally
  7750. {
  7751. if (conn.State == ConnectionState.Open)
  7752. {
  7753. conn.Close();
  7754. }
  7755. conn.Dispose();
  7756. }
  7757. }
  7758. }
  7759. #endregion
  7760. /// <summary>
  7761. /// 生产订单
  7762. /// </summary>
  7763. /// <param name="JsonData"></param>
  7764. /// <returns></returns>
  7765. public static DataTable ICSMOCreate(List<ICSMO> JsonData)
  7766. {
  7767. var language = LanguageHelper.GetName("WMSAPIInfo");
  7768. if (JsonData.Count <= 0)
  7769. {
  7770. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7771. }
  7772. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7773. {
  7774. conn.Open();
  7775. SqlTransaction sqlTran = conn.BeginTransaction();
  7776. SqlCommand cmd = new SqlCommand();
  7777. string Colspan = string.Empty;
  7778. string IDD = string.Empty;
  7779. cmd.Transaction = sqlTran;
  7780. cmd.Connection = conn;
  7781. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7782. try
  7783. {
  7784. string codes = string.Empty;
  7785. string sql = string.Empty;
  7786. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MO'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  7787. SELECT @MaxNO=SUBSTRING(MAX(MOCODE),LEN(@date)+1,LEN(MAX(MOCODE))-LEN(@date))+1 FROM ICSMO
  7788. WHERE SUBSTRING(MOCODE, 1, LEN(@date))=@date
  7789. IF @MaxNO IS NULL
  7790. BEGIN
  7791. SELECT @date+'00001' AS Code
  7792. END
  7793. ELSE
  7794. BEGIN
  7795. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  7796. END ";
  7797. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  7798. HashSet<string> uniqueItems = new HashSet<string>();
  7799. foreach (var item in JsonData)
  7800. {
  7801. //检验自由项
  7802. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  7803. + "~" + item.Brand + "~" + item.cFree1
  7804. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  7805. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  7806. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  7807. sql = @"select ID,Colspan from ICSExtension a
  7808. where Colspan='{0}' and WorkPoint='{1}'";
  7809. sql = string.Format(sql, Colspan, item.WorkPoint);
  7810. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  7811. if (dttt.Rows.Count == 0)
  7812. {
  7813. IDD = Guid.NewGuid().ToString();
  7814. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  7815. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  7816. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  7817. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7818. {
  7819. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  7820. }
  7821. }
  7822. else
  7823. {
  7824. IDD = dttt.Rows[0]["ID"].ToString();
  7825. }
  7826. //获取单号
  7827. string key = item.Sequence + "~" + item.InvCode;
  7828. if (uniqueItems.Contains(key))
  7829. {
  7830. throw new Exception("子件不可重复添加!");
  7831. }
  7832. uniqueItems.Add(key);
  7833. //创建主表
  7834. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  7835. BEGIN
  7836. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  7837. RETURN
  7838. END
  7839. INSERT INTO ICSMO
  7840. (a.ID, a.MOCode, a.Sequence, a.InvCode, a.Quantity,
  7841. a.Amount, a.RCVQuantity, a.DepCode, a.WHCode, a.StartDate, a.DueDate,
  7842. a.MOStatus, a.MOMemo, a.CreatePerson, a.CreateDateTime, a.ERPStatus, a.MOID, a.MODetailID,
  7843. a.ExtensionID, a.MUSER, a.MUSERName, a.MTIME, a.WorkPoint, a.EATTRIBUTE1, a.EATTRIBUTE2,
  7844. a.EATTRIBUTE3, a.EATTRIBUTE4, a.EATTRIBUTE5,
  7845. a.EATTRIBUTE6, a.EATTRIBUTE7, a.EATTRIBUTE8, a.EATTRIBUTE9, a.EATTRIBUTE10)
  7846. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  7847. '0','0','','','{8}',
  7848. '{9}',1,'','{4}','{5}',
  7849. '1','','','{7}',
  7850. '{4}',(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{6}'),'{5}','{6}','',
  7851. '','','','','','','','','')";
  7852. sql = string.Format(sql, Code, item.Sequence, item.InvCode, item.Quantity, item.User,
  7853. item.MTIME, item.WorkPoint,IDD,item.StartDate,item.EndDate,item.WHCODE);
  7854. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7855. {
  7856. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产订单信息创建失败!");
  7857. }
  7858. }
  7859. codes = "'" + Code + "'";
  7860. if (string.IsNullOrWhiteSpace(codes))
  7861. {
  7862. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  7863. }
  7864. #region 查询返回数据
  7865. sql = @"SELECT a.ID, a.MOCode, a.Sequence, a.InvCode, a.Quantity,
  7866. a.Amount, a.RCVQuantity, a.DepCode, a.WHCode, a.StartDate, a.DueDate,
  7867. a.MOStatus, a.MOMemo, a.CreatePerson, a.CreateDateTime, a.ERPStatus, a.MOID, a.MODetailID,
  7868. a.ExtensionID, a.MUSER, a.MUSERName, a.MTIME, a.WorkPoint
  7869. FROM ICSMO a
  7870. WHERE a.MOCODE+a.WorkPoint IN ({0})";
  7871. sql = string.Format(sql, codes);
  7872. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7873. #endregion
  7874. cmd.Transaction.Commit();
  7875. return data;
  7876. }
  7877. catch (Exception ex)
  7878. {
  7879. if (cmd.Transaction != null)
  7880. cmd.Transaction.Rollback();
  7881. log.Error(ex.Message);
  7882. throw new Exception(ex.Message);
  7883. }
  7884. finally
  7885. {
  7886. if (conn.State == ConnectionState.Open)
  7887. {
  7888. conn.Close();
  7889. }
  7890. conn.Dispose();
  7891. }
  7892. }
  7893. }
  7894. #region 销售订单
  7895. /// <summary>
  7896. /// 销售订单创建
  7897. /// </summary>
  7898. /// <returns></returns>
  7899. public static DataTable ICSSalesOrderCreate(List<ICSSalesOrder> JsonData)
  7900. {
  7901. var language = LanguageHelper.GetName("WMSAPIInfo");
  7902. if (JsonData.Count <= 0)
  7903. {
  7904. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7905. }
  7906. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7907. {
  7908. conn.Open();
  7909. SqlTransaction sqlTran = conn.BeginTransaction();
  7910. SqlCommand cmd = new SqlCommand();
  7911. cmd.Transaction = sqlTran;
  7912. cmd.Connection = conn;
  7913. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7914. try
  7915. {
  7916. string codes = string.Empty;
  7917. string sql = string.Empty;
  7918. string Colspan = string.Empty;
  7919. string IDD = string.Empty;
  7920. //获取单号
  7921. sql = @"DECLARE @MaxNO INT,@date varchar(20)='POIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  7922. SELECT @MaxNO=SUBSTRING(MAX(SDNCode),LEN(@date)+1,LEN(MAX(SDNCode))-LEN(@date))+1 FROM ICSSDN
  7923. WHERE SUBSTRING(SDNCode, 1, LEN(@date))=@date
  7924. IF @MaxNO IS NULL
  7925. BEGIN
  7926. SELECT @date+'00001' AS Code
  7927. END
  7928. ELSE
  7929. BEGIN
  7930. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  7931. END ";
  7932. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  7933. HashSet<string> uniqueItems = new HashSet<string>();
  7934. foreach (var item in JsonData)
  7935. {
  7936. //检验自由项
  7937. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  7938. + "~" + item.Brand + "~" + item.cFree1
  7939. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  7940. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  7941. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  7942. sql = @"select ID,Colspan from ICSExtension a
  7943. where Colspan='{0}' and WorkPoint='{1}'";
  7944. sql = string.Format(sql, Colspan, item.WorkPoint);
  7945. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  7946. if (dttt.Rows.Count == 0)
  7947. {
  7948. IDD = Guid.NewGuid().ToString();
  7949. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  7950. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  7951. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  7952. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7953. {
  7954. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  7955. }
  7956. }
  7957. else
  7958. {
  7959. IDD = dttt.Rows[0]["ID"].ToString();
  7960. }
  7961. string key = item.Sequence + "~" + item.InvCode;
  7962. if (uniqueItems.Contains(key))
  7963. {
  7964. throw new Exception("子件不可重复添加!");
  7965. }
  7966. uniqueItems.Add(key);
  7967. //创建主表
  7968. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{7}' AND F_Location='{6}')
  7969. BEGIN
  7970. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{7}") + @"',16,1);
  7971. RETURN
  7972. END
  7973. INSERT INTO ICSSDN(ID,SDNCode,Sequence,SOCode,SOSequence,CusCode,CusName,Type,ArriveDate,WHCode,
  7974. InvCode,Quantity,CreatePerson,CreateDateTime,Status,SDNID,SDNDetailID,ExtensionID,MUSER,MUSERName,MTIME,WorkPoint)
  7975. VALUES(NEWID(),'{0}',{1},'','','{2}','{3}',3,'{8}','{10}',
  7976. '{4}',{5},'{7}','{8}',1,'','','{9}','{7}','{7}','{8}','{6}')
  7977. ";
  7978. sql = string.Format(sql, Code, item.Sequence, item.CusCode, item.CusName, item.InvCode, item.Quantity, item.WorkPoint, item.User,
  7979. item.MTime, IDD, item.WHCode);
  7980. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7981. {
  7982. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"采购订单信息创建失败!");
  7983. }
  7984. codes += "'" + Code + item.WorkPoint + "',";
  7985. }
  7986. if (string.IsNullOrWhiteSpace(codes))
  7987. {
  7988. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  7989. }
  7990. #region 查询返回数据
  7991. sql = @"SELECT a.DNCode,a.Sequence,
  7992. a.VenCode,a.DepCode,
  7993. d.Name AS Status,
  7994. a.Sequence,
  7995. a.InvCode,
  7996. inv.InvName,
  7997. inv.InvStd,
  7998. a.Quantity,
  7999. inv.InvUnit,
  8000. a.Amount,
  8001. inv.AmountUnit,
  8002. ext.ProjectCode,
  8003. ext.BatchCode,
  8004. ext.Version,
  8005. ext.Brand,
  8006. ext.cFree1,
  8007. ext.cFree2,
  8008. ext.cFree3,
  8009. ext.cFree4,
  8010. ext.cFree5,
  8011. ext.cFree6,
  8012. ext.cFree7,
  8013. ext.cFree8,
  8014. ext.cFree9,
  8015. ext.cFree10,
  8016. a.MUSER AS [User],
  8017. a.MTIME AS [MTime]
  8018. FROM ICSDeliveryNotice a
  8019. LEFT JOIN ICSType d ON d.TableCode='ICSDeliveryNotice' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  8020. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8021. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8022. WHERE a.DNCode+a.WorkPoint IN ({0})";
  8023. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  8024. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8025. #endregion
  8026. cmd.Transaction.Commit();
  8027. return data;
  8028. }
  8029. catch (Exception ex)
  8030. {
  8031. if (cmd.Transaction != null)
  8032. cmd.Transaction.Rollback();
  8033. log.Error(ex.Message);
  8034. throw new Exception(ex.Message);
  8035. }
  8036. finally
  8037. {
  8038. if (conn.State == ConnectionState.Open)
  8039. {
  8040. conn.Close();
  8041. }
  8042. conn.Dispose();
  8043. }
  8044. }
  8045. }
  8046. /// <summary>
  8047. /// 销售订单 修改
  8048. /// </summary>
  8049. /// <param name="JsonData"></param>
  8050. /// <returns></returns>
  8051. public static DataTable ICSSalesOrderUpdate(List<ICSSalesOrder> JsonData)
  8052. {
  8053. var language = LanguageHelper.GetName("WMSAPIInfo");
  8054. if (JsonData.Count <= 0)
  8055. {
  8056. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8057. }
  8058. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8059. {
  8060. conn.Open();
  8061. SqlTransaction sqlTran = conn.BeginTransaction();
  8062. SqlCommand cmd = new SqlCommand();
  8063. cmd.Transaction = sqlTran;
  8064. cmd.Connection = conn;
  8065. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8066. try
  8067. {
  8068. string sql = string.Empty;
  8069. string Checksql = string.Empty;
  8070. string Code = string.Empty;
  8071. string ids = string.Empty;
  8072. string Colspan = string.Empty;
  8073. string IDD = string.Empty;
  8074. foreach (var item in JsonData)
  8075. {
  8076. //检验自由项
  8077. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  8078. + "~" + item.Brand + "~" + item.cFree1
  8079. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  8080. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  8081. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  8082. Checksql = @"select ID,Colspan from ICSExtension a
  8083. where Colspan='{0}' and WorkPoint='{1}'";
  8084. Checksql = string.Format(Checksql, Colspan, item.WorkPoint);
  8085. DataTable dttt = DBHelper.SQlReturnData(Checksql, cmd);
  8086. if (dttt.Rows.Count == 0)
  8087. {
  8088. IDD = Guid.NewGuid().ToString();
  8089. Checksql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  8090. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  8091. Checksql = string.Format(Checksql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  8092. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  8093. {
  8094. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  8095. }
  8096. }
  8097. else
  8098. {
  8099. IDD = dttt.Rows[0]["ID"].ToString();
  8100. }
  8101. //主表修改
  8102. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  8103. BEGIN
  8104. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  8105. RETURN
  8106. END
  8107. DECLARE @Status VARCHAR(10)
  8108. SELECT distinct @Status=Status FROM ICSSDN WHERE SDNCode='{0}' and WorkPoint='{6}'
  8109. IF (@Status IS NULL)
  8110. BEGIN
  8111. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{0}") + @"',16,1);
  8112. RETURN
  8113. END
  8114. ELSE IF (@Status!='1')
  8115. BEGIN
  8116. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{0}") + @"',16,1);
  8117. RETURN
  8118. END
  8119. ";
  8120. sql = string.Format(sql, item.SDNCode, item.Sequence, item.InvCode, item.Quantity, item.User,
  8121. item.MTime, item.WorkPoint);
  8122. if (!string.IsNullOrWhiteSpace(item.Sequence))
  8123. {
  8124. //创建子表
  8125. sql += @"IF EXISTS(Select * from ICSSDN where SDNCode ='{0}'and Sequence ='{1}')
  8126. Begin
  8127. UPDATE ICSSDN set InvCode='{4}',Quantity='{5}',WHCode='{10}',MUSER= '{7}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{6}'),MTIME='{8}'
  8128. where SDNCode ='{0}' and Sequence ='{1}'
  8129. END
  8130. ELSE
  8131. BEGIN
  8132. INSERT INTO ICSSDN(ID,SDNCode,Sequence,SOCode,SOSequence,CusCode,CusName,Type,ArriveDate,WHCode,
  8133. InvCode,Quantity,CreatePerson,CreateDateTime,Status,SDNID,SDNDetailID,ExtensionID,MUSER,MUSERName,MTIME,WorkPoint)
  8134. VALUES(NEWID(),'{0}',{1},'','','{2}','{3}',3,'{8}','{10}',
  8135. '{4}',{5},'{7}','{8}',1,'','','{9}','{7}','{7}','{8}','{6}')
  8136. END";
  8137. sql = string.Format(sql, item.SDNCode, item.Sequence, item.CusCode, item.CusName, item.InvCode, item.Quantity, item.WorkPoint, item.User,
  8138. item.MTime, IDD, item.WHCode);
  8139. }
  8140. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8141. {
  8142. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"采购订单信息修改失败!");
  8143. }
  8144. ids += "'" + item.Sequence + "',";
  8145. Code = item.SDNCode;
  8146. }
  8147. sql = @"DELETE from ICSDeliveryNotice where DNCode ='{0}' and Sequence not in ({1})";
  8148. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  8149. DBHelper.ExecuteNonQuery(sql, cmd);
  8150. #region 查询返回数据
  8151. sql = @"SELECT a.DNCode,a.Sequence,
  8152. a.VenCode,a.DepCode,
  8153. d.Name AS Status,
  8154. a.Sequence,
  8155. a.InvCode,
  8156. inv.InvName,
  8157. inv.InvStd,
  8158. a.Quantity,
  8159. inv.InvUnit,
  8160. a.Amount,
  8161. inv.AmountUnit,
  8162. ext.ProjectCode,
  8163. ext.BatchCode,
  8164. ext.Version,
  8165. ext.Brand,
  8166. ext.cFree1,
  8167. ext.cFree2,
  8168. ext.cFree3,
  8169. ext.cFree4,
  8170. ext.cFree5,
  8171. ext.cFree6,
  8172. ext.cFree7,
  8173. ext.cFree8,
  8174. ext.cFree9,
  8175. ext.cFree10,
  8176. a.MUSER AS [User],
  8177. a.MTIME AS [MTime]
  8178. FROM ICSDeliveryNotice a
  8179. LEFT JOIN ICSType d ON d.TableCode='ICSDeliveryNotice' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  8180. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8181. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8182. WHERE a.DNCode+a.WorkPoint IN ('{0}')";
  8183. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  8184. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8185. #endregion
  8186. cmd.Transaction.Commit();
  8187. return data;
  8188. }
  8189. catch (Exception ex)
  8190. {
  8191. if (cmd.Transaction != null)
  8192. cmd.Transaction.Rollback();
  8193. log.Error(ex.Message);
  8194. throw new Exception(ex.Message);
  8195. }
  8196. finally
  8197. {
  8198. if (conn.State == ConnectionState.Open)
  8199. {
  8200. conn.Close();
  8201. }
  8202. conn.Dispose();
  8203. }
  8204. }
  8205. }
  8206. #endregion
  8207. /// <summary>
  8208. /// 生产退料 修改
  8209. /// </summary>
  8210. /// <param name="JsonData"></param>
  8211. /// <returns></returns>
  8212. public static DataTable ICSMOUpdate(List<ICSMO> JsonData)
  8213. {
  8214. var language = LanguageHelper.GetName("WMSAPIInfo");
  8215. if (JsonData.Count <= 0)
  8216. {
  8217. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8218. }
  8219. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8220. {
  8221. conn.Open();
  8222. SqlTransaction sqlTran = conn.BeginTransaction();
  8223. SqlCommand cmd = new SqlCommand();
  8224. cmd.Transaction = sqlTran;
  8225. cmd.Connection = conn;
  8226. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8227. try
  8228. {
  8229. string sql = string.Empty;
  8230. string Checksql = string.Empty;
  8231. string Code = string.Empty;
  8232. string ids = string.Empty;
  8233. string Colspan = string.Empty;
  8234. string IDD = string.Empty;
  8235. foreach (var item in JsonData)
  8236. {
  8237. //检验自由项
  8238. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  8239. + "~" + item.Brand + "~" + item.cFree1
  8240. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  8241. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  8242. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  8243. Checksql = @"select ID,Colspan from ICSExtension a
  8244. where Colspan='{0}' and WorkPoint='{1}'";
  8245. Checksql = string.Format(Checksql, Colspan, item.WorkPoint);
  8246. DataTable dttt = DBHelper.SQlReturnData(Checksql, cmd);
  8247. if (dttt.Rows.Count == 0)
  8248. {
  8249. IDD = Guid.NewGuid().ToString();
  8250. Checksql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  8251. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  8252. Checksql = string.Format(Checksql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  8253. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  8254. {
  8255. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  8256. }
  8257. }
  8258. else
  8259. {
  8260. IDD = dttt.Rows[0]["ID"].ToString();
  8261. }
  8262. //主表修改
  8263. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  8264. BEGIN
  8265. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  8266. RETURN
  8267. END
  8268. DECLARE @Status VARCHAR(10)
  8269. SELECT distinct @Status=moStatus FROM ICSMO WHERE MOCODE='{0}' and WorkPoint='{6}'
  8270. IF (@Status IS NULL)
  8271. BEGIN
  8272. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{0}") + @"',16,1);
  8273. RETURN
  8274. END
  8275. ELSE IF (@Status!='1')
  8276. BEGIN
  8277. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{0}") + @"',16,1);
  8278. RETURN
  8279. END
  8280. ";
  8281. sql = string.Format(sql, item.MOCODE, item.Sequence, item.InvCode, item.Quantity, item.User,
  8282. item.MTIME, item.WorkPoint);
  8283. if (!string.IsNullOrWhiteSpace(item.Sequence))
  8284. {
  8285. //创建子表
  8286. sql+= @"IF EXISTS(Select * from icsmo where mocode ='{0}'and Sequence ='{1}')
  8287. Begin
  8288. UPDATE icsmo set InvCode='{2}',Quantity='{3}',MUSER= '{4}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{6}'),MTIME='{5}'
  8289. where mocode ='{0}'and Sequence ='{1}'
  8290. END
  8291. ELSE
  8292. BEGIN
  8293. INSERT INTO ICSMO
  8294. (ID, MOCode, Sequence, InvCode, Quantity,
  8295. Amount, RCVQuantity, DepCode, WHCode, StartDate, DueDate,
  8296. MOStatus, MOMemo, CreatePerson, CreateDateTime, ERPStatus, MOID, MODetailID,
  8297. ExtensionID, MUSER, MUSERName, MTIME, WorkPoint, EATTRIBUTE1, EATTRIBUTE2,
  8298. EATTRIBUTE3, EATTRIBUTE4, EATTRIBUTE5,
  8299. EATTRIBUTE6, EATTRIBUTE7, EATTRIBUTE8, EATTRIBUTE9, EATTRIBUTE10)
  8300. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  8301. '0','0','','','{5}',
  8302. '{5}',1,'','{4}','{5}',
  8303. '1','','','',
  8304. '{4}',(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{6}'),'{5}','{6}','{7}',
  8305. '','','','','','','','','')
  8306. END";
  8307. sql = string.Format(sql, item.MOCODE, item.Sequence, item.InvCode, item.Quantity, item.User,
  8308. item.MTIME, item.WorkPoint,IDD);
  8309. log.Debug("111"+sql);
  8310. }
  8311. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8312. {
  8313. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  8314. }
  8315. ids += "'" + item.Sequence + "',";
  8316. Code = item.MOCODE;
  8317. }
  8318. sql = @"DELETE from icsmo where mocode ='{0}' and Sequence not in ({1})";
  8319. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  8320. DBHelper.ExecuteNonQuery(sql, cmd);
  8321. #region 查询返回数据
  8322. sql = @"SELECT a.ID, a.MOCode, a.Sequence, a.InvCode, a.Quantity,
  8323. a.Amount, a.RCVQuantity, a.DepCode, a.WHCode, a.StartDate, a.DueDate,
  8324. a.MOStatus, a.MOMemo, a.CreatePerson, a.CreateDateTime, a.ERPStatus, a.MOID, a.MODetailID,
  8325. a.ExtensionID, a.MUSER, a.MUSERName, a.MTIME, a.WorkPoint, a.EATTRIBUTE1, a.EATTRIBUTE2,
  8326. a.EATTRIBUTE3, a.EATTRIBUTE4, a.EATTRIBUTE5,
  8327. a.EATTRIBUTE6, a.EATTRIBUTE7, a.EATTRIBUTE8, a.EATTRIBUTE9, a.EATTRIBUTE10
  8328. FROM ICSMO a
  8329. WHERE mocode ='{0}' and Sequence in ({1})";
  8330. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  8331. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8332. #endregion
  8333. cmd.Transaction.Commit();
  8334. return data;
  8335. }
  8336. catch (Exception ex)
  8337. {
  8338. if (cmd.Transaction != null)
  8339. cmd.Transaction.Rollback();
  8340. log.Error(ex.Message);
  8341. throw new Exception(ex.Message);
  8342. }
  8343. finally
  8344. {
  8345. if (conn.State == ConnectionState.Open)
  8346. {
  8347. conn.Close();
  8348. }
  8349. conn.Dispose();
  8350. }
  8351. }
  8352. }
  8353. #region 委外
  8354. /// <summary>
  8355. /// 委外退料 新建
  8356. /// </summary>
  8357. /// <param name="JsonData"></param>
  8358. /// <returns></returns>
  8359. public static DataTable OutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  8360. {
  8361. var language = LanguageHelper.GetName("WMSAPIInfo");
  8362. if (JsonData.Count <= 0)
  8363. {
  8364. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8365. }
  8366. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8367. {
  8368. conn.Open();
  8369. SqlTransaction sqlTran = conn.BeginTransaction();
  8370. SqlCommand cmd = new SqlCommand();
  8371. cmd.Transaction = sqlTran;
  8372. cmd.Connection = conn;
  8373. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8374. try
  8375. {
  8376. string codes = string.Empty;
  8377. string sql = string.Empty;
  8378. foreach (var item in JsonData)
  8379. {
  8380. //获取单号
  8381. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  8382. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  8383. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  8384. IF @MaxNO IS NULL
  8385. BEGIN
  8386. SELECT @date+'00001' AS Code
  8387. END
  8388. ELSE
  8389. BEGIN
  8390. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  8391. END ";
  8392. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8393. //创建主表
  8394. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  8395. BEGIN
  8396. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  8397. RETURN
  8398. END
  8399. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8400. VALUES (NEWID(),'{0}','{1}','1','{5}','','{2}','{3}','{2}',(select F_RealName from Sys_SRM_User where F_Account='{2}' and F_Location='{4}'),'{3}','{4}','')";
  8401. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  8402. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8403. {
  8404. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  8405. }
  8406. HashSet<string> uniqueItems = new HashSet<string>();
  8407. foreach (var itemInfo in item.detail)
  8408. {
  8409. string key = itemInfo.Sequence + "~" + itemInfo.InvCode;
  8410. if (uniqueItems.Contains(key))
  8411. {
  8412. throw new Exception("子件不可重复添加!");
  8413. }
  8414. uniqueItems.Add(key);
  8415. // 创建子表
  8416. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  8417. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  8418. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8419. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  8420. '{4}','{5}',0,'{6}','{7}',
  8421. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  8422. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  8423. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8424. {
  8425. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  8426. }
  8427. }
  8428. //校验退料数量是否超出领料数量
  8429. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  8430. DBHelper.ExecuteNonQuery(sql, cmd);
  8431. codes += "'" + Code + item.WorkPoint + "',";
  8432. }
  8433. if (string.IsNullOrWhiteSpace(codes))
  8434. {
  8435. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  8436. }
  8437. #region 查询返回数据
  8438. sql = @"SELECT a.OApplyNegCode,
  8439. c.WHCode,
  8440. c.Memo,
  8441. d.Name AS Status,
  8442. a.Sequence,
  8443. a.InvCode,
  8444. inv.InvName,
  8445. inv.InvStd,
  8446. a.Quantity,
  8447. inv.InvUnit,
  8448. a.Amount,
  8449. inv.AmountUnit,
  8450. a.IssueNegQuantity,
  8451. ext.ProjectCode,
  8452. ext.BatchCode,
  8453. ext.Version,
  8454. ext.Brand,
  8455. ext.cFree1,
  8456. ext.cFree2,
  8457. ext.cFree3,
  8458. ext.cFree4,
  8459. ext.cFree5,
  8460. ext.cFree6,
  8461. ext.cFree7,
  8462. ext.cFree8,
  8463. ext.cFree9,
  8464. ext.cFree10,
  8465. a.MUSER AS [User],
  8466. a.MTIME AS [MTime]
  8467. FROM ICSOApplyNegDetail a
  8468. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  8469. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  8470. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8471. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8472. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  8473. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  8474. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8475. #endregion
  8476. cmd.Transaction.Commit();
  8477. return data;
  8478. }
  8479. catch (Exception ex)
  8480. {
  8481. if (cmd.Transaction != null)
  8482. cmd.Transaction.Rollback();
  8483. log.Error(ex.Message);
  8484. throw new Exception(ex.Message);
  8485. }
  8486. finally
  8487. {
  8488. if (conn.State == ConnectionState.Open)
  8489. {
  8490. conn.Close();
  8491. }
  8492. conn.Dispose();
  8493. }
  8494. }
  8495. }
  8496. /// <summary>
  8497. /// 委外退料 新建
  8498. /// </summary>
  8499. /// <param name="JsonData"></param>
  8500. /// <returns></returns>
  8501. public static DataTable AMOutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  8502. {
  8503. var language = LanguageHelper.GetName("WMSAPIInfo");
  8504. if (JsonData.Count <= 0)
  8505. {
  8506. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8507. }
  8508. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8509. {
  8510. conn.Open();
  8511. SqlTransaction sqlTran = conn.BeginTransaction();
  8512. SqlCommand cmd = new SqlCommand();
  8513. cmd.Transaction = sqlTran;
  8514. cmd.Connection = conn;
  8515. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8516. try
  8517. {
  8518. string codes = string.Empty;
  8519. string sql = string.Empty;
  8520. foreach (var item in JsonData)
  8521. {
  8522. //获取单号
  8523. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  8524. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  8525. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  8526. IF @MaxNO IS NULL
  8527. BEGIN
  8528. SELECT @date+'00001' AS Code
  8529. END
  8530. ELSE
  8531. BEGIN
  8532. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  8533. END ";
  8534. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8535. //创建主表
  8536. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  8537. BEGIN
  8538. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  8539. RETURN
  8540. END
  8541. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8542. VALUES (NEWID(),'{0}','{1}','1','{5}','','{2}','{3}','{2}',(select F_RealName from Sys_SRM_User where F_Account='{2}' and F_Location='{4}'),'{3}','{4}','')";
  8543. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  8544. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8545. {
  8546. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  8547. }
  8548. HashSet<string> uniqueItems = new HashSet<string>();
  8549. foreach (var itemInfo in item.detail)
  8550. {
  8551. string chekksql = @"select c.EATTRIBUTE1 ICSInventory c
  8552. WHERE c.InvCode='{0}'AND c.WorkPoint='{1}' and c.AmountEnable='1'";
  8553. chekksql = string.Format(chekksql, itemInfo.InvCode, itemInfo.WorkPoint);
  8554. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  8555. if (dta.Rows.Count > 0)
  8556. {
  8557. itemInfo.Quantity = (itemInfo.Quantity * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString()));
  8558. }
  8559. string key = itemInfo.Sequence + "~" + itemInfo.InvCode;
  8560. if (uniqueItems.Contains(key))
  8561. {
  8562. throw new Exception("子件不可重复添加!");
  8563. }
  8564. uniqueItems.Add(key);
  8565. // 创建子表
  8566. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  8567. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  8568. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8569. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  8570. '{4}','{5}',0,'{6}','{7}',
  8571. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  8572. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  8573. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8574. {
  8575. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  8576. }
  8577. }
  8578. //校验退料数量是否超出领料数量
  8579. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  8580. DBHelper.ExecuteNonQuery(sql, cmd);
  8581. codes += "'" + Code + item.WorkPoint + "',";
  8582. }
  8583. if (string.IsNullOrWhiteSpace(codes))
  8584. {
  8585. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  8586. }
  8587. #region 查询返回数据
  8588. sql = @"SELECT a.OApplyNegCode,
  8589. c.WHCode,
  8590. c.Memo,
  8591. d.Name AS Status,
  8592. a.Sequence,
  8593. a.InvCode,
  8594. inv.InvName,
  8595. inv.InvStd,
  8596. a.Quantity,
  8597. inv.InvUnit,
  8598. a.Amount,
  8599. inv.AmountUnit,
  8600. a.IssueNegQuantity,
  8601. ext.ProjectCode,
  8602. ext.BatchCode,
  8603. ext.Version,
  8604. ext.Brand,
  8605. ext.cFree1,
  8606. ext.cFree2,
  8607. ext.cFree3,
  8608. ext.cFree4,
  8609. ext.cFree5,
  8610. ext.cFree6,
  8611. ext.cFree7,
  8612. ext.cFree8,
  8613. ext.cFree9,
  8614. ext.cFree10,
  8615. a.MUSER AS [User],
  8616. a.MTIME AS [MTime]
  8617. FROM ICSOApplyNegDetail a
  8618. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  8619. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  8620. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8621. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8622. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  8623. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  8624. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8625. #endregion
  8626. cmd.Transaction.Commit();
  8627. return data;
  8628. }
  8629. catch (Exception ex)
  8630. {
  8631. if (cmd.Transaction != null)
  8632. cmd.Transaction.Rollback();
  8633. log.Error(ex.Message);
  8634. throw new Exception(ex.Message);
  8635. }
  8636. finally
  8637. {
  8638. if (conn.State == ConnectionState.Open)
  8639. {
  8640. conn.Close();
  8641. }
  8642. conn.Dispose();
  8643. }
  8644. }
  8645. }
  8646. private static string CheckOutsourcingIssueDoc(string Type, string Code, string WorkPoint, Dictionary<string, string> language)
  8647. {
  8648. string sql = string.Empty;
  8649. if (Type == "1")
  8650. {
  8651. sql = @"DECLARE @PickID VARCHAR(10)
  8652. SELECT @PickID=b.PickID
  8653. FROM ICSOApplyNegDetail a
  8654. INNER JOIN ICSOOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  8655. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  8656. WHERE c.Type='{2}' AND a.WorkPoint='{1}' and a.Quantity<>a.IssueNegQuantity
  8657. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  8658. FROM ICSOApplyNegDetail a
  8659. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  8660. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}' )
  8661. GROUP BY b.PickID
  8662. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  8663. IF (@PickID IS NOT NULL)
  8664. BEGIN
  8665. DECLARE @InvCode VARCHAR(100)
  8666. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  8667. RAISERROR(@InvCode,16,1);
  8668. RETURN
  8669. END ";
  8670. }
  8671. else if (Type == "2")
  8672. {
  8673. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  8674. SELECT @ApplyDetailID=b.ApplyDetailID
  8675. FROM ICSOApplyNegDetail a
  8676. INNER JOIN ICSOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  8677. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  8678. WHERE c.Type='{2}' AND a.WorkPoint='{1}' and a.Quantity<>a.IssueNegQuantity
  8679. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  8680. FROM ICSOApplyNegDetail a
  8681. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  8682. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  8683. GROUP BY b.ApplyDetailID
  8684. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  8685. IF (@ApplyDetailID IS NOT NULL)
  8686. BEGIN
  8687. DECLARE @InvCode VARCHAR(100)
  8688. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  8689. RAISERROR(@InvCode,16,1);
  8690. RETURN
  8691. END ";
  8692. }
  8693. else if (Type == "3")
  8694. {
  8695. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  8696. SELECT @IssueDetailID=b.IssueDetailID
  8697. FROM ICSOApplyNegDetail a
  8698. INNER JOIN ICSOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  8699. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  8700. WHERE c.Type='{2}' AND a.WorkPoint='{1}' and a.Quantity<>a.IssueNegQuantity
  8701. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  8702. FROM ICSOApplyNegDetail a
  8703. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  8704. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  8705. GROUP BY b.IssueDetailID
  8706. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  8707. IF (@IssueDetailID IS NOT NULL)
  8708. BEGIN
  8709. DECLARE @InvCode VARCHAR(100)
  8710. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  8711. RAISERROR(@InvCode,16,1);
  8712. RETURN
  8713. END ";
  8714. }
  8715. else
  8716. {
  8717. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  8718. }
  8719. sql = string.Format(sql, Code, WorkPoint, Type);
  8720. return sql;
  8721. }
  8722. /// <summary>
  8723. /// 委外退料 修改
  8724. /// </summary>
  8725. /// <param name="JsonData"></param>
  8726. /// <returns></returns>
  8727. public static DataTable OutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  8728. {
  8729. var language = LanguageHelper.GetName("WMSAPIInfo");
  8730. if (JsonData.Count <= 0)
  8731. {
  8732. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8733. }
  8734. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8735. {
  8736. conn.Open();
  8737. SqlTransaction sqlTran = conn.BeginTransaction();
  8738. SqlCommand cmd = new SqlCommand();
  8739. cmd.Transaction = sqlTran;
  8740. cmd.Connection = conn;
  8741. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8742. try
  8743. {
  8744. string sql = string.Empty;
  8745. string Code = string.Empty;
  8746. string ids = string.Empty;
  8747. string idss = string.Empty;
  8748. foreach (var item in JsonData)
  8749. {
  8750. //主表修改
  8751. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  8752. BEGIN
  8753. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  8754. RETURN
  8755. END
  8756. DECLARE @Status VARCHAR(10)
  8757. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  8758. IF (@Status IS NULL)
  8759. BEGIN
  8760. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  8761. RETURN
  8762. END
  8763. ELSE IF (@Status!='1')
  8764. BEGIN
  8765. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  8766. RETURN
  8767. END
  8768. update ICSOApplyNeg set WHCode='{0}',MUSER='{1}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{1}' and F_Location='{4}'),MTIME='{2}' where ID='{3}' and WorkPoint='{4}' ";
  8769. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  8770. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8771. {
  8772. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  8773. }
  8774. //var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  8775. //if (detail > 0)
  8776. //{
  8777. // sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  8778. // sql = string.Format(sql, item.id, item.WorkPoint);
  8779. // Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8780. //}
  8781. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  8782. sql = string.Format(sql, item.id, item.WorkPoint);
  8783. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8784. foreach (var itemInfo in item.detail)
  8785. {
  8786. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  8787. {
  8788. //创建子表
  8789. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  8790. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  8791. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8792. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  8793. '{4}','{5}',0,'{6}','{7}',
  8794. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  8795. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  8796. }
  8797. else
  8798. {
  8799. //子表修改
  8800. sql = @"update ICSOApplyNegDetail set InvCode='{0}' ,Quantity='{1}',Amount='{2}',SourceDetailID='{3}',MUSER='{6}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{5}') where ID='{4}' and WorkPoint='{5}'";
  8801. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  8802. }
  8803. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8804. {
  8805. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  8806. }
  8807. idss += "'" + itemInfo.DetailID + "',";
  8808. }
  8809. //校验退料数量是否超出领料数量
  8810. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  8811. DBHelper.ExecuteNonQuery(sql, cmd);
  8812. ids += "'" + item.id + "',";
  8813. }
  8814. sql = @"DELETE from ICSOApplyNegDetail where OApplyNegCode ='{0}' and id not in ({1})";
  8815. sql = string.Format(sql, Code, idss.Substring(0, idss.Length - 1));
  8816. DBHelper.ExecuteNonQuery(sql, cmd);
  8817. if (string.IsNullOrWhiteSpace(ids))
  8818. {
  8819. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  8820. }
  8821. #region 查询返回数据
  8822. sql = @"SELECT a.OApplyNegCode,
  8823. c.WHCode,
  8824. c.Memo,
  8825. d.Name AS Status,
  8826. a.Sequence,
  8827. a.InvCode,
  8828. inv.InvName,
  8829. inv.InvStd,
  8830. a.Quantity,
  8831. inv.InvUnit,
  8832. a.Amount,
  8833. inv.AmountUnit,
  8834. a.IssueNegQuantity,
  8835. ext.ProjectCode,
  8836. ext.BatchCode,
  8837. ext.Version,
  8838. ext.Brand,
  8839. ext.cFree1,
  8840. ext.cFree2,
  8841. ext.cFree3,
  8842. ext.cFree4,
  8843. ext.cFree5,
  8844. ext.cFree6,
  8845. ext.cFree7,
  8846. ext.cFree8,
  8847. ext.cFree9,
  8848. ext.cFree10,
  8849. a.MUSER AS [User],
  8850. a.MTIME AS [MTime]
  8851. FROM ICSOApplyNegDetail a
  8852. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  8853. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  8854. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8855. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8856. WHERE c.ID IN ({0})";
  8857. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  8858. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8859. #endregion
  8860. cmd.Transaction.Commit();
  8861. return data;
  8862. }
  8863. catch (Exception ex)
  8864. {
  8865. if (cmd.Transaction != null)
  8866. cmd.Transaction.Rollback();
  8867. log.Error(ex.Message);
  8868. throw new Exception(ex.Message);
  8869. }
  8870. finally
  8871. {
  8872. if (conn.State == ConnectionState.Open)
  8873. {
  8874. conn.Close();
  8875. }
  8876. conn.Dispose();
  8877. }
  8878. }
  8879. }
  8880. /// <summary>
  8881. /// 委外退料 修改
  8882. /// </summary>
  8883. /// <param name="JsonData"></param>
  8884. /// <returns></returns>
  8885. public static DataTable AMOutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  8886. {
  8887. var language = LanguageHelper.GetName("WMSAPIInfo");
  8888. if (JsonData.Count <= 0)
  8889. {
  8890. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8891. }
  8892. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8893. {
  8894. conn.Open();
  8895. SqlTransaction sqlTran = conn.BeginTransaction();
  8896. SqlCommand cmd = new SqlCommand();
  8897. cmd.Transaction = sqlTran;
  8898. cmd.Connection = conn;
  8899. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8900. try
  8901. {
  8902. string sql = string.Empty;
  8903. string Code = string.Empty;
  8904. string ids = string.Empty;
  8905. string idss = string.Empty;
  8906. foreach (var item in JsonData)
  8907. {
  8908. //主表修改
  8909. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  8910. BEGIN
  8911. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  8912. RETURN
  8913. END
  8914. DECLARE @Status VARCHAR(10)
  8915. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  8916. IF (@Status IS NULL)
  8917. BEGIN
  8918. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  8919. RETURN
  8920. END
  8921. ELSE IF (@Status!='1')
  8922. BEGIN
  8923. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  8924. RETURN
  8925. END
  8926. update ICSOApplyNeg set WHCode='{0}',MUSER='{1}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{1}' and F_Location='{4}'),MTIME='{2}' where ID='{3}' and WorkPoint='{4}' ";
  8927. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  8928. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8929. {
  8930. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  8931. }
  8932. //var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  8933. //if (detail > 0)
  8934. //{
  8935. // sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  8936. // sql = string.Format(sql, item.id, item.WorkPoint);
  8937. // Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8938. //}
  8939. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  8940. sql = string.Format(sql, item.id, item.WorkPoint);
  8941. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8942. foreach (var itemInfo in item.detail)
  8943. {
  8944. string chekksql = @"select c.EATTRIBUTE1 ICSInventory c
  8945. WHERE c.InvCode='{0}'AND c.WorkPoint='{1}' and c.AmountEnable='1'";
  8946. chekksql = string.Format(chekksql, itemInfo.InvCode, itemInfo.WorkPoint);
  8947. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  8948. if (dta.Rows.Count > 0)
  8949. {
  8950. itemInfo.Quantity = (itemInfo.Quantity * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString()));
  8951. }
  8952. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  8953. {
  8954. //创建子表
  8955. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  8956. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  8957. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8958. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  8959. '{4}','{5}',0,'{6}','{7}',
  8960. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  8961. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  8962. }
  8963. else
  8964. {
  8965. //子表修改
  8966. sql = @"update ICSOApplyNegDetail set InvCode='{0}' ,Quantity='{1}',Amount='{2}',SourceDetailID='{3}',MUSER='{6}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{5}') where ID='{4}' and WorkPoint='{5}'";
  8967. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  8968. }
  8969. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8970. {
  8971. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  8972. }
  8973. idss += "'" + itemInfo.DetailID + "',";
  8974. }
  8975. //校验退料数量是否超出领料数量
  8976. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  8977. DBHelper.ExecuteNonQuery(sql, cmd);
  8978. ids += "'" + item.id + "',";
  8979. }
  8980. sql = @"DELETE from ICSOApplyNegDetail where OApplyNegCode ='{0}' and id not in ({1})";
  8981. sql = string.Format(sql, Code, idss.Substring(0, idss.Length - 1));
  8982. DBHelper.ExecuteNonQuery(sql, cmd);
  8983. if (string.IsNullOrWhiteSpace(ids))
  8984. {
  8985. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  8986. }
  8987. #region 查询返回数据
  8988. sql = @"SELECT a.OApplyNegCode,
  8989. c.WHCode,
  8990. c.Memo,
  8991. d.Name AS Status,
  8992. a.Sequence,
  8993. a.InvCode,
  8994. inv.InvName,
  8995. inv.InvStd,
  8996. a.Quantity,
  8997. inv.InvUnit,
  8998. a.Amount,
  8999. inv.AmountUnit,
  9000. a.IssueNegQuantity,
  9001. ext.ProjectCode,
  9002. ext.BatchCode,
  9003. ext.Version,
  9004. ext.Brand,
  9005. ext.cFree1,
  9006. ext.cFree2,
  9007. ext.cFree3,
  9008. ext.cFree4,
  9009. ext.cFree5,
  9010. ext.cFree6,
  9011. ext.cFree7,
  9012. ext.cFree8,
  9013. ext.cFree9,
  9014. ext.cFree10,
  9015. a.MUSER AS [User],
  9016. a.MTIME AS [MTime]
  9017. FROM ICSOApplyNegDetail a
  9018. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  9019. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  9020. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  9021. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  9022. WHERE c.ID IN ({0})";
  9023. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  9024. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  9025. #endregion
  9026. cmd.Transaction.Commit();
  9027. return data;
  9028. }
  9029. catch (Exception ex)
  9030. {
  9031. if (cmd.Transaction != null)
  9032. cmd.Transaction.Rollback();
  9033. log.Error(ex.Message);
  9034. throw new Exception(ex.Message);
  9035. }
  9036. finally
  9037. {
  9038. if (conn.State == ConnectionState.Open)
  9039. {
  9040. conn.Close();
  9041. }
  9042. conn.Dispose();
  9043. }
  9044. }
  9045. }
  9046. /// <summary>
  9047. /// 委外退料审核
  9048. /// </summary>
  9049. /// <param name="JsonData"></param>
  9050. /// <returns></returns>
  9051. public static DataTable OutsourcingIssueDoNegativeApplyApprove(List<ICSUser> JsonData)
  9052. {
  9053. string flag = string.Empty;
  9054. var language = LanguageHelper.GetName("WMSAPIInfo");
  9055. if (JsonData.Count <= 0)
  9056. {
  9057. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9058. }
  9059. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9060. {
  9061. conn.Open();
  9062. SqlTransaction sqlTran = conn.BeginTransaction();
  9063. SqlCommand cmd = new SqlCommand();
  9064. cmd.Transaction = sqlTran;
  9065. cmd.Connection = conn;
  9066. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9067. try
  9068. {
  9069. string sql = string.Empty;
  9070. string ids = string.Empty;
  9071. foreach (var item in JsonData)
  9072. {
  9073. bool hasApproveFlag = JsonData.Any(u => u.ApproveFlag != null);
  9074. if (hasApproveFlag == true)
  9075. {
  9076. flag = item.ApproveFlag;
  9077. }
  9078. if (string.IsNullOrEmpty(item.ID))
  9079. {
  9080. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  9081. }
  9082. if (string.IsNullOrEmpty(item.User))
  9083. {
  9084. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  9085. }
  9086. if (item.MTime <= new DateTime(2000, 1, 1))
  9087. {
  9088. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  9089. }
  9090. if (flag.Equals("1")|| flag=="")
  9091. {
  9092. //获取单号
  9093. sql = @"DECLARE @Status VARCHAR(10)
  9094. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  9095. IF (@Status IS NULL)
  9096. BEGIN
  9097. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  9098. RETURN
  9099. END
  9100. ELSE IF (@Status!='1')
  9101. BEGIN
  9102. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  9103. RETURN
  9104. END
  9105. update ICSOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  9106. sql = string.Format(sql, item.ID, item.User, item.MTime);
  9107. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9108. {
  9109. throw new Exception(language.GetNameByCode("WMSAPIInfo021"));//"委外退料申请单审核失败!");
  9110. }
  9111. ids += "'" + item.ID + "',";
  9112. }
  9113. else
  9114. {
  9115. //获取单号
  9116. sql = @"DECLARE @Status VARCHAR(10)
  9117. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  9118. IF (@Status IS NULL)
  9119. BEGIN
  9120. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  9121. RETURN
  9122. END
  9123. ELSE IF (@Status!='2')
  9124. BEGIN
  9125. RAISERROR('" + language.GetNameByCode("WMSAPIInfo473") + @"',16,1);
  9126. RETURN
  9127. END
  9128. IF EXISTS (select a.id from ICSOApplyNeg a
  9129. left join ICSOApplyNegDetail b on a.OApplyNegCode=b.OApplyNegCode and a.WorkPoint=b.WorkPoint
  9130. where a.ID='{0}' and b.IssueNegQuantity>0)
  9131. BEGIN
  9132. RAISERROR('" + language.GetNameByCode("WMSAPIInfo474") + @"',16,1);
  9133. RETURN
  9134. END
  9135. update ICSOApplyNeg set Status='1',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  9136. sql = string.Format(sql, item.ID, item.User, item.MTime);
  9137. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9138. {
  9139. throw new Exception(language.GetNameByCode("WMSAPIInfo475"));//"委外退料申请单审核失败!");
  9140. }
  9141. ids += "'" + item.ID + "',";
  9142. }
  9143. }
  9144. if (string.IsNullOrWhiteSpace(ids))
  9145. {
  9146. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  9147. }
  9148. #region 查询返回数据
  9149. sql = @"SELECT a.OApplyNegCode,
  9150. c.WHCode,
  9151. c.Memo,
  9152. d.Name AS Status,
  9153. a.Sequence,
  9154. a.InvCode,
  9155. inv.InvName,
  9156. inv.InvStd,
  9157. a.Quantity,
  9158. inv.InvUnit,
  9159. a.Amount,
  9160. inv.AmountUnit,
  9161. a.IssueNegQuantity,
  9162. ext.ProjectCode,
  9163. ext.BatchCode,
  9164. ext.Version,
  9165. ext.Brand,
  9166. ext.cFree1,
  9167. ext.cFree2,
  9168. ext.cFree3,
  9169. ext.cFree4,
  9170. ext.cFree5,
  9171. ext.cFree6,
  9172. ext.cFree7,
  9173. ext.cFree8,
  9174. ext.cFree9,
  9175. ext.cFree10,
  9176. a.MUSER AS [User],
  9177. a.MTIME AS [MTime]
  9178. FROM ICSOApplyNegDetail a
  9179. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  9180. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  9181. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  9182. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  9183. WHERE c.ID IN ({0})";
  9184. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  9185. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  9186. #endregion
  9187. cmd.Transaction.Commit();
  9188. return data;
  9189. }
  9190. catch (Exception ex)
  9191. {
  9192. if (cmd.Transaction != null)
  9193. cmd.Transaction.Rollback();
  9194. log.Error(ex.Message);
  9195. throw new Exception(ex.Message);
  9196. }
  9197. finally
  9198. {
  9199. if (conn.State == ConnectionState.Open)
  9200. {
  9201. conn.Close();
  9202. }
  9203. conn.Dispose();
  9204. }
  9205. }
  9206. }
  9207. /// <summary>
  9208. /// 委外到货
  9209. /// </summary>
  9210. /// <param name="JsonData"></param>
  9211. /// <returns></returns>
  9212. public static DataTable OutsourcingDeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  9213. {
  9214. var language = LanguageHelper.GetName("WMSAPIInfo");
  9215. if (JsonData.Count <= 0)
  9216. {
  9217. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9218. }
  9219. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9220. {
  9221. conn.Open();
  9222. SqlTransaction sqlTran = conn.BeginTransaction();
  9223. SqlCommand cmd = new SqlCommand();
  9224. cmd.Transaction = sqlTran;
  9225. cmd.Connection = conn;
  9226. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9227. try
  9228. {
  9229. string asncodes = string.Empty;
  9230. string sql = string.Empty;
  9231. string DNCodes = string.Empty;
  9232. foreach (var item in JsonData)
  9233. {
  9234. if (string.IsNullOrEmpty(item.OASNCode))
  9235. {
  9236. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!");
  9237. }
  9238. sql = @"SELECT a.ODNCode FROM ICSODeliveryNotice a WHERE a.OASNCode='{0}' AND ODNType = '1' AND a.WorkPoint='{1}'";
  9239. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  9240. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  9241. if (dt.Rows.Count > 0)
  9242. {
  9243. DNCodes = dt.Rows[0]["DNCode"].ToString();
  9244. }
  9245. log.Debug("已到货的到货单" + DNCodes);
  9246. //获取单号
  9247. sql = @"IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.OASNCode='{0}' AND ODNType = '1' AND a.WorkPoint='{1}')
  9248. BEGIN
  9249. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  9250. RETURN
  9251. END
  9252. DECLARE @Status VARCHAR(10)
  9253. SELECT @Status=Status FROM ICSOASN WHERE OASNCode='{0}' and WorkPoint='{1}'
  9254. IF (@Status IS NULL)
  9255. BEGIN
  9256. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  9257. RETURN
  9258. END
  9259. ELSE IF (@Status!='2')
  9260. BEGIN
  9261. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  9262. RETURN
  9263. END
  9264. DECLARE @MaxNO INT,@date varchar(20)='ODN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  9265. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  9266. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  9267. IF @MaxNO IS NULL
  9268. BEGIN
  9269. SELECT @date+'00001' AS Code
  9270. END
  9271. ELSE
  9272. BEGIN
  9273. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  9274. END ";
  9275. sql = string.Format(sql, item.OASNCode, item.WorkPoint, DNCodes);
  9276. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  9277. //修改送货单到货数量
  9278. foreach (var itemInfo in item.detail)
  9279. {
  9280. sql = @"UPDATE ICSOASNDetail SET ODNQuantity=ISNULL(ODNQuantity, 0)+'{2}'
  9281. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  9282. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  9283. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9284. {
  9285. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"委外送货单子表信息更新失败!");
  9286. }
  9287. }
  9288. //创建到货单信息
  9289. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  9290. BEGIN
  9291. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  9292. RETURN
  9293. END
  9294. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  9295. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  9296. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  9297. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  9298. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  9299. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  9300. '1',b.InvCode,SUM(a.ODNQuantity),'0','0',
  9301. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  9302. d.OOID,d.OODetailID,'{0}',newid(),b.ExtensionID,
  9303. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.OASNCode
  9304. FROM ICSOASNDetail a
  9305. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  9306. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  9307. INNER JOIN ICSOutsourcingOrder d ON c.TransCode=d.OOCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  9308. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  9309. WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
  9310. GROUP BY d.OOID,d.OODetailID,d.VenCode,d.UnitPrice,d.Currency,d.DepCode,b.ExtensionID,b.InvCode,a.OASNCode,e.F_Account,e.F_RealName,a.WorkPoint";
  9311. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.OASNCode);
  9312. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9313. {
  9314. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  9315. }
  9316. string sqlCheckSign = @"select * from ICSConfiguration where code = 'UploadERP002' and enable = '1'";
  9317. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  9318. if (flag != null && flag.Rows.Count > 0)
  9319. {
  9320. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  9321. {
  9322. if (!DBHelper.IsU9())
  9323. ICSOutsourcingService.OutsourcingDeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  9324. }
  9325. }
  9326. asncodes += "'" + item.OASNCode + item.WorkPoint + "',";
  9327. }
  9328. if (string.IsNullOrWhiteSpace(asncodes))
  9329. {
  9330. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  9331. }
  9332. #region 查询返回数据
  9333. sql = @"SELECT
  9334. n.OOCode,
  9335. n.Sequence AS OOSequence,
  9336. a.OASNCode,
  9337. a.ODNCode,
  9338. a.Sequence,
  9339. a.VenCode,
  9340. a.DepCode,
  9341. a.InvCode,
  9342. inv.InvName,
  9343. inv.InvStd,
  9344. a.Quantity,
  9345. inv.InvUnit,
  9346. a.Amount,
  9347. inv.AmountUnit,
  9348. a.RCVQuantity,
  9349. a.UnitPrice,
  9350. a.Currency,
  9351. a.OOID,
  9352. a.OODetailID,
  9353. a.ODNID,
  9354. a.ODNDetailID,
  9355. ext.ProjectCode,
  9356. ext.BatchCode,
  9357. ext.Version,
  9358. ext.Brand,
  9359. ext.cFree1,
  9360. ext.cFree2,
  9361. ext.cFree3,
  9362. ext.cFree4,
  9363. ext.cFree5,
  9364. ext.cFree6,
  9365. ext.cFree7,
  9366. ext.cFree8,
  9367. ext.cFree9,
  9368. ext.cFree10,
  9369. a.MUSER AS [User],
  9370. a.MTIME AS [MTime]
  9371. FROM ICSODeliveryNotice a
  9372. INNER JOIN ICSOutsourcingOrder n ON a.OOID =n.OOID AND a.OODetailID=n.OODetailID AND a.WorkPoint=n.WorkPoint
  9373. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  9374. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  9375. WHERE a.OASNCode+a.WorkPoint IN ({0})";
  9376. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  9377. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  9378. #endregion
  9379. cmd.Transaction.Commit();
  9380. return data;
  9381. }
  9382. catch (Exception ex)
  9383. {
  9384. if (cmd.Transaction != null)
  9385. cmd.Transaction.Rollback();
  9386. log.Error(ex.Message);
  9387. throw new Exception(ex.Message);
  9388. }
  9389. finally
  9390. {
  9391. if (conn.State == ConnectionState.Open)
  9392. {
  9393. conn.Close();
  9394. }
  9395. conn.Dispose();
  9396. }
  9397. }
  9398. }
  9399. /// <summary>
  9400. /// 委外拒收
  9401. /// </summary>
  9402. /// <param name="JsonData"></param>
  9403. /// <returns></returns>
  9404. public static DataTable OutsourcingRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  9405. {
  9406. var language = LanguageHelper.GetName("WMSAPIInfo");
  9407. if (JsonData.Count <= 0)
  9408. {
  9409. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9410. }
  9411. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9412. {
  9413. conn.Open();
  9414. SqlTransaction sqlTran = conn.BeginTransaction();
  9415. SqlCommand cmd = new SqlCommand();
  9416. cmd.Transaction = sqlTran;
  9417. cmd.Connection = conn;
  9418. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9419. try
  9420. {
  9421. string lots = string.Empty;
  9422. string sql = string.Empty;
  9423. foreach (var item in JsonData)
  9424. {
  9425. if (string.IsNullOrEmpty(item.ODNCode))
  9426. {
  9427. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  9428. }
  9429. //获取单号
  9430. sql = @"DECLARE @Status VARCHAR(10)
  9431. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  9432. IF (@Status IS NULL)
  9433. BEGIN
  9434. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  9435. RETURN
  9436. END
  9437. ELSE IF (@Status!='2')
  9438. BEGIN
  9439. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  9440. RETURN
  9441. END
  9442. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  9443. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  9444. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  9445. IF @MaxNO IS NULL
  9446. BEGIN
  9447. SELECT @date+'00001' AS Code
  9448. END
  9449. ELSE
  9450. BEGIN
  9451. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  9452. END ";
  9453. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  9454. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  9455. //修改送货单到货数量
  9456. foreach (var itemInfo in item.detail)
  9457. {
  9458. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  9459. BEGIN
  9460. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  9461. RETURN
  9462. END
  9463. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  9464. BEGIN
  9465. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  9466. RETURN
  9467. END
  9468. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  9469. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  9470. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  9471. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  9472. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  9473. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  9474. '3',d.InvCode,'{7}', '{8}', 0,
  9475. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  9476. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  9477. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  9478. FROM ICSODeliveryNotice a
  9479. INNER JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  9480. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint and a.ExtensionID=d.ExtensionID
  9481. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  9482. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND a.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  9483. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint and h.enable = 1
  9484. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  9485. WHERE a.ODNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  9486. sql = string.Format(sql, item.ODNCode, itemInfo.LotNo, item.WorkPoint, item.User, Code, item.VenCode, item.DepCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.UnitPrice, itemInfo.Currency, itemInfo.Sequence);
  9487. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9488. {
  9489. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  9490. }
  9491. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  9492. }
  9493. string sqlCheckSign = @"select * from ICSConfiguration where code = 'UploadERP004' and enable = '1'";
  9494. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  9495. if (flag != null && flag.Rows.Count > 0)
  9496. {
  9497. if (!DBHelper.IsU9())
  9498. ICSOutsourcingService.OutsourcingRejectDocInNewERP(item.ODNCode, Code, item.WorkPoint, cmd, language);
  9499. }
  9500. }
  9501. if (string.IsNullOrWhiteSpace(lots))
  9502. {
  9503. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  9504. }
  9505. #region 查询返回数据
  9506. sql = @"SELECT
  9507. n.ODNCode,
  9508. n.Sequence,
  9509. a.ODNCode AS RJTCode,
  9510. a.Sequence AS RJTSequence,
  9511. a.VenCode,
  9512. a.DepCode,
  9513. a.InvCode,
  9514. inv.InvName,
  9515. inv.InvStd,
  9516. a.Quantity,
  9517. inv.InvUnit,
  9518. a.Amount,
  9519. inv.AmountUnit,
  9520. a.RCVQuantity,
  9521. a.UnitPrice,
  9522. a.Currency,
  9523. a.OOID,
  9524. a.OODetailID,
  9525. a.ODNID,
  9526. a.ODNDetailID,
  9527. ext.ProjectCode,
  9528. ext.BatchCode,
  9529. ext.Version,
  9530. ext.Brand,
  9531. ext.cFree1,
  9532. ext.cFree2,
  9533. ext.cFree3,
  9534. ext.cFree4,
  9535. ext.cFree5,
  9536. ext.cFree6,
  9537. ext.cFree7,
  9538. ext.cFree8,
  9539. ext.cFree9,
  9540. ext.cFree10,
  9541. a.MUSER AS [User],
  9542. a.MTIME AS [MTime]
  9543. FROM ICSODeliveryNotice a
  9544. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  9545. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  9546. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  9547. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  9548. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  9549. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  9550. #endregion
  9551. cmd.Transaction.Commit();
  9552. return data;
  9553. }
  9554. catch (Exception ex)
  9555. {
  9556. if (cmd.Transaction != null)
  9557. cmd.Transaction.Rollback();
  9558. log.Error(ex.Message);
  9559. throw new Exception(ex.Message);
  9560. }
  9561. finally
  9562. {
  9563. if (conn.State == ConnectionState.Open)
  9564. {
  9565. conn.Close();
  9566. }
  9567. conn.Dispose();
  9568. }
  9569. }
  9570. }
  9571. /// <summary>
  9572. /// 无订单委外拒收
  9573. /// </summary>
  9574. /// <param name="JsonData"></param>
  9575. /// <returns></returns>
  9576. public static DataTable OutsourcingRejectDocNoTransCreate(List<ICSDeliveryNotice> JsonData)
  9577. {
  9578. var language = LanguageHelper.GetName("WMSAPIInfo");
  9579. if (JsonData.Count <= 0)
  9580. {
  9581. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9582. }
  9583. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9584. {
  9585. conn.Open();
  9586. SqlTransaction sqlTran = conn.BeginTransaction();
  9587. SqlCommand cmd = new SqlCommand();
  9588. cmd.Transaction = sqlTran;
  9589. cmd.Connection = conn;
  9590. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9591. try
  9592. {
  9593. string lots = string.Empty;
  9594. string sql = string.Empty;
  9595. foreach (var item in JsonData)
  9596. {
  9597. if (string.IsNullOrEmpty(item.ODNCode))
  9598. {
  9599. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  9600. }
  9601. //获取单号
  9602. sql = @"DECLARE @Status VARCHAR(10)
  9603. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  9604. IF (@Status IS NULL)
  9605. BEGIN
  9606. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  9607. RETURN
  9608. END
  9609. ELSE IF (@Status!='2')
  9610. BEGIN
  9611. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  9612. RETURN
  9613. END
  9614. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  9615. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  9616. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  9617. IF @MaxNO IS NULL
  9618. BEGIN6t
  9619. SELECT @date+'00001' AS Code
  9620. END
  9621. ELSE
  9622. BEGIN
  9623. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  9624. END ";
  9625. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  9626. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  9627. //修改送货单到货数量
  9628. foreach (var itemInfo in item.detail)
  9629. {
  9630. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  9631. BEGIN
  9632. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  9633. RETURN
  9634. END
  9635. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  9636. BEGIN
  9637. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  9638. RETURN
  9639. END
  9640. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  9641. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  9642. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  9643. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  9644. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  9645. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  9646. '3',d.InvCode,'{7}', '{8}', 0,
  9647. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  9648. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  9649. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, d.LOTNO,''
  9650. FROM ICSODeliveryNotice a
  9651. INNER JOIN ICSInventoryLotDetail m on a.ODNCode=m.TransCode and a.Sequence=m.TransSequence and a.WorkPoint=m.WorkPoint
  9652. INNER JOIN ICSInventoryLot d ON m.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint
  9653. INNER JOIN ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint and h.enable = 1
  9654. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  9655. WHERE a.ODNCode='{0}' and d.LOTNO='{1}' AND a.WorkPoint='{2}'";
  9656. sql = string.Format(sql, item.ODNCode, itemInfo.LotNo, item.WorkPoint, item.User, Code, item.VenCode, item.DepCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.UnitPrice, itemInfo.Currency, itemInfo.Sequence);
  9657. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9658. {
  9659. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  9660. }
  9661. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  9662. }
  9663. ICSOutsourcingService.OutsourcingRejectDocInNewERP(item.ODNCode, Code, item.WorkPoint, cmd, language);
  9664. }
  9665. if (string.IsNullOrWhiteSpace(lots))
  9666. {
  9667. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  9668. }
  9669. #region 查询返回数据
  9670. sql = @"SELECT
  9671. n.ODNCode,
  9672. n.Sequence,
  9673. a.ODNCode AS RJTCode,
  9674. a.Sequence AS RJTSequence,
  9675. a.VenCode,
  9676. a.DepCode,
  9677. a.InvCode,
  9678. inv.InvName,
  9679. inv.InvStd,
  9680. a.Quantity,
  9681. inv.InvUnit,
  9682. a.Amount,
  9683. inv.AmountUnit,
  9684. a.RCVQuantity,
  9685. a.UnitPrice,
  9686. a.Currency,
  9687. a.OOID,
  9688. a.OODetailID,
  9689. a.ODNID,
  9690. a.ODNDetailID,
  9691. ext.ProjectCode,
  9692. ext.BatchCode,
  9693. ext.Version,
  9694. ext.Brand,
  9695. ext.cFree1,
  9696. ext.cFree2,
  9697. ext.cFree3,
  9698. ext.cFree4,
  9699. ext.cFree5,
  9700. ext.cFree6,
  9701. ext.cFree7,
  9702. ext.cFree8,
  9703. ext.cFree9,
  9704. ext.cFree10,
  9705. a.MUSER AS [User],
  9706. a.MTIME AS [MTime]
  9707. FROM ICSODeliveryNotice a
  9708. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  9709. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  9710. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  9711. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  9712. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  9713. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  9714. #endregion
  9715. cmd.Transaction.Commit();
  9716. return data;
  9717. }
  9718. catch (Exception ex)
  9719. {
  9720. if (cmd.Transaction != null)
  9721. cmd.Transaction.Rollback();
  9722. log.Error(ex.Message);
  9723. throw new Exception(ex.Message);
  9724. }
  9725. finally
  9726. {
  9727. if (conn.State == ConnectionState.Open)
  9728. {
  9729. conn.Close();
  9730. }
  9731. conn.Dispose();
  9732. }
  9733. }
  9734. }
  9735. #endregion
  9736. #region 生产
  9737. /// <summary>
  9738. /// 生产退料 新建
  9739. /// </summary>
  9740. /// <param name="JsonData"></param>
  9741. /// <returns></returns>
  9742. public static DataTable MOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  9743. {
  9744. var language = LanguageHelper.GetName("WMSAPIInfo");
  9745. if (JsonData.Count <= 0)
  9746. {
  9747. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9748. }
  9749. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9750. {
  9751. conn.Open();
  9752. SqlTransaction sqlTran = conn.BeginTransaction();
  9753. SqlCommand cmd = new SqlCommand();
  9754. cmd.Transaction = sqlTran;
  9755. cmd.Connection = conn;
  9756. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9757. try
  9758. {
  9759. string codes = string.Empty;
  9760. string sql = string.Empty;
  9761. string memo = string.Empty;
  9762. foreach (var item in JsonData)
  9763. {
  9764. if (item.Type == "1")
  9765. {
  9766. memo = item.Memo;
  9767. }
  9768. //获取单号
  9769. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  9770. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  9771. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  9772. IF @MaxNO IS NULL
  9773. BEGIN
  9774. SELECT @date+'00001' AS Code
  9775. END
  9776. ELSE
  9777. BEGIN
  9778. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  9779. END ";
  9780. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  9781. //创建主表
  9782. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  9783. BEGIN
  9784. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  9785. RETURN
  9786. END
  9787. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  9788. VALUES (NEWID(),'{0}','{1}','1','{5}','{6}','{2}','{3}','{2}',(select F_RealName from Sys_SRM_User where F_Account='{2}' and F_Location='{4}'),'{3}','{4}','')";
  9789. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type, memo);
  9790. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9791. {
  9792. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  9793. }
  9794. HashSet<string> addedItems = new HashSet<string>();
  9795. foreach (var itemInfo in item.detail)
  9796. {
  9797. // 创建子表
  9798. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  9799. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  9800. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  9801. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  9802. '{4}','{5}',0,'{6}','{7}',
  9803. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  9804. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  9805. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9806. {
  9807. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  9808. }
  9809. string key = itemInfo.Sequence + "~" + itemInfo.InvCode;
  9810. if (addedItems.Contains(key))
  9811. {
  9812. throw new Exception("子件不可重复添加!");
  9813. }
  9814. addedItems.Add(key);
  9815. }
  9816. //校验退料数量是否超出领料数量
  9817. sql = CheckMOIssueDoc(item.Type, Code, item.WorkPoint, language);
  9818. DBHelper.ExecuteNonQuery(sql, cmd);
  9819. codes += "'" + Code + item.WorkPoint + "',";
  9820. }
  9821. if (string.IsNullOrWhiteSpace(codes))
  9822. {
  9823. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  9824. }
  9825. #region 查询返回数据
  9826. sql = @"SELECT a.ApplyNegCode,
  9827. c.WHCode,
  9828. c.Memo,
  9829. d.Name AS Status,
  9830. a.Sequence,
  9831. a.InvCode,
  9832. inv.InvName,
  9833. inv.InvStd,
  9834. a.Quantity,
  9835. inv.InvUnit,
  9836. a.Amount,
  9837. inv.AmountUnit,
  9838. a.IssueNegQuantity,
  9839. ext.ProjectCode,
  9840. ext.BatchCode,
  9841. ext.Version,
  9842. ext.Brand,
  9843. ext.cFree1,
  9844. ext.cFree2,
  9845. ext.cFree3,
  9846. ext.cFree4,
  9847. ext.cFree5,
  9848. ext.cFree6,
  9849. ext.cFree7,
  9850. ext.cFree8,
  9851. ext.cFree9,
  9852. ext.cFree10,
  9853. a.MUSER AS [User],
  9854. a.MTIME AS [MTime]
  9855. FROM ICSMOApplyNegDetail a
  9856. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  9857. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  9858. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  9859. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  9860. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  9861. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  9862. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  9863. #endregion
  9864. cmd.Transaction.Commit();
  9865. return data;
  9866. }
  9867. catch (Exception ex)
  9868. {
  9869. if (cmd.Transaction != null)
  9870. cmd.Transaction.Rollback();
  9871. log.Error(ex.Message);
  9872. throw new Exception(ex.Message);
  9873. }
  9874. finally
  9875. {
  9876. if (conn.State == ConnectionState.Open)
  9877. {
  9878. conn.Close();
  9879. }
  9880. conn.Dispose();
  9881. }
  9882. }
  9883. }
  9884. /// <summary>
  9885. /// 生产退料 新建
  9886. /// </summary>
  9887. /// <param name="JsonData"></param>
  9888. /// <returns></returns>
  9889. public static DataTable AMMOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  9890. {
  9891. var language = LanguageHelper.GetName("WMSAPIInfo");
  9892. if (JsonData.Count <= 0)
  9893. {
  9894. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9895. }
  9896. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9897. {
  9898. conn.Open();
  9899. SqlTransaction sqlTran = conn.BeginTransaction();
  9900. SqlCommand cmd = new SqlCommand();
  9901. cmd.Transaction = sqlTran;
  9902. cmd.Connection = conn;
  9903. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9904. try
  9905. {
  9906. string codes = string.Empty;
  9907. string sql = string.Empty;
  9908. foreach (var item in JsonData)
  9909. {
  9910. //获取单号
  9911. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  9912. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  9913. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  9914. IF @MaxNO IS NULL
  9915. BEGIN
  9916. SELECT @date+'00001' AS Code
  9917. END
  9918. ELSE
  9919. BEGIN
  9920. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  9921. END ";
  9922. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  9923. //创建主表
  9924. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  9925. BEGIN
  9926. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  9927. RETURN
  9928. END
  9929. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  9930. VALUES (NEWID(),'{0}','{1}','1','{5}','','{2}','{3}','{2}',(select F_RealName from Sys_SRM_User where F_Account='{2}' and F_Location='{4}'),'{3}','{4}','')";
  9931. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  9932. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9933. {
  9934. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  9935. }
  9936. HashSet<string> addedItems = new HashSet<string>();
  9937. foreach (var itemInfo in item.detail)
  9938. {
  9939. string chekksql = @"select c.EATTRIBUTE1 ICSInventory c
  9940. WHERE c.InvCode='{0}'AND c.WorkPoint='{1}' and c.AmountEnable='1'";
  9941. chekksql = string.Format(chekksql, itemInfo.InvCode, itemInfo.WorkPoint);
  9942. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  9943. if (dta.Rows.Count > 0)
  9944. {
  9945. itemInfo.Quantity = (decimal.Parse(itemInfo.Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  9946. }
  9947. // 创建子表
  9948. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  9949. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  9950. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  9951. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  9952. '{4}','{5}',0,'{6}','{7}',
  9953. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  9954. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  9955. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9956. {
  9957. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  9958. }
  9959. string key = itemInfo.Sequence + "~" + itemInfo.InvCode;
  9960. if (addedItems.Contains(key))
  9961. {
  9962. throw new Exception("子件不可重复添加!");
  9963. }
  9964. addedItems.Add(key);
  9965. }
  9966. //校验退料数量是否超出领料数量
  9967. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  9968. DBHelper.ExecuteNonQuery(sql, cmd);
  9969. codes += "'" + Code + item.WorkPoint + "',";
  9970. }
  9971. if (string.IsNullOrWhiteSpace(codes))
  9972. {
  9973. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  9974. }
  9975. #region 查询返回数据
  9976. sql = @"SELECT a.ApplyNegCode,
  9977. c.WHCode,
  9978. c.Memo,
  9979. d.Name AS Status,
  9980. a.Sequence,
  9981. a.InvCode,
  9982. inv.InvName,
  9983. inv.InvStd,
  9984. a.Quantity,
  9985. inv.InvUnit,
  9986. a.Amount,
  9987. inv.AmountUnit,
  9988. a.IssueNegQuantity,
  9989. ext.ProjectCode,
  9990. ext.BatchCode,
  9991. ext.Version,
  9992. ext.Brand,
  9993. ext.cFree1,
  9994. ext.cFree2,
  9995. ext.cFree3,
  9996. ext.cFree4,
  9997. ext.cFree5,
  9998. ext.cFree6,
  9999. ext.cFree7,
  10000. ext.cFree8,
  10001. ext.cFree9,
  10002. ext.cFree10,
  10003. a.MUSER AS [User],
  10004. a.MTIME AS [MTime]
  10005. FROM ICSMOApplyNegDetail a
  10006. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  10007. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  10008. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  10009. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  10010. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  10011. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  10012. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  10013. #endregion
  10014. cmd.Transaction.Commit();
  10015. return data;
  10016. }
  10017. catch (Exception ex)
  10018. {
  10019. if (cmd.Transaction != null)
  10020. cmd.Transaction.Rollback();
  10021. log.Error(ex.Message);
  10022. throw new Exception(ex.Message);
  10023. }
  10024. finally
  10025. {
  10026. if (conn.State == ConnectionState.Open)
  10027. {
  10028. conn.Close();
  10029. }
  10030. conn.Dispose();
  10031. }
  10032. }
  10033. }
  10034. private static string CheckMOIssueDoc(string Type, string ID, string WorkPoint, Dictionary<string, string> language)
  10035. {
  10036. string sql = string.Empty;
  10037. if (Type == "1")
  10038. {
  10039. sql = @"DECLARE @PickID VARCHAR(10)
  10040. SELECT @PickID=b.PickID
  10041. FROM ICSMOApplyNegDetail a
  10042. INNER JOIN ICSMOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  10043. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  10044. WHERE c.Type='{2}' AND a.WorkPoint='{1}' and a.Quantity<>a.IssueNegQuantity
  10045. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  10046. FROM ICSMOApplyNegDetail a
  10047. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  10048. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  10049. GROUP BY b.PickID
  10050. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  10051. IF (@PickID IS NOT NULL)
  10052. BEGIN
  10053. DECLARE @InvCode VARCHAR(100)
  10054. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  10055. RAISERROR(@InvCode,16,1);
  10056. RETURN
  10057. END ";
  10058. }
  10059. else if (Type == "2")
  10060. {
  10061. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  10062. SELECT @ApplyDetailID=b.ApplyDetailID
  10063. FROM ICSMOApplyNegDetail a
  10064. INNER JOIN ICSMOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  10065. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  10066. WHERE c.Type='{2}' AND a.WorkPoint='{1}' and a.Quantity<>a.IssueNegQuantity
  10067. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  10068. FROM ICSMOApplyNegDetail a
  10069. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  10070. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  10071. GROUP BY b.ApplyDetailID
  10072. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  10073. IF (@ApplyDetailID IS NOT NULL)
  10074. BEGIN
  10075. DECLARE @InvCode VARCHAR(100)
  10076. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  10077. RAISERROR(@InvCode,16,1);
  10078. RETURN
  10079. END ";
  10080. }
  10081. else if (Type == "3")
  10082. {
  10083. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  10084. SELECT @IssueDetailID=b.IssueDetailID
  10085. FROM ICSMOApplyNegDetail a
  10086. INNER JOIN ICSMOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  10087. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  10088. WHERE c.Type='{2}' AND a.WorkPoint='{1}' and a.Quantity<>a.IssueNegQuantity
  10089. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  10090. FROM ICSMOApplyNegDetail a
  10091. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  10092. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}'and a.Quantity<>a.IssueNegQuantity)
  10093. GROUP BY b.IssueDetailID
  10094. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  10095. IF (@IssueDetailID IS NOT NULL)
  10096. BEGIN
  10097. DECLARE @InvCode VARCHAR(100)
  10098. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  10099. RAISERROR(@InvCode,16,1);
  10100. RETURN
  10101. END ";
  10102. }
  10103. else
  10104. {
  10105. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  10106. }
  10107. sql = string.Format(sql, ID, WorkPoint, Type);
  10108. log.Debug("退料校验发料数量:"+sql);
  10109. return sql;
  10110. }
  10111. /// <summary>
  10112. /// 生产退料 修改
  10113. /// </summary>
  10114. /// <param name="JsonData"></param>
  10115. /// <returns></returns>
  10116. public static DataTable MOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  10117. {
  10118. var language = LanguageHelper.GetName("WMSAPIInfo");
  10119. if (JsonData.Count <= 0)
  10120. {
  10121. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10122. }
  10123. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10124. {
  10125. conn.Open();
  10126. SqlTransaction sqlTran = conn.BeginTransaction();
  10127. SqlCommand cmd = new SqlCommand();
  10128. cmd.Transaction = sqlTran;
  10129. cmd.Connection = conn;
  10130. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10131. try
  10132. {
  10133. string sql = string.Empty;
  10134. string Code = string.Empty;
  10135. string ids = string.Empty;
  10136. string idss = string.Empty;
  10137. string memo = string.Empty;
  10138. foreach (var item in JsonData)
  10139. {
  10140. if (item.Type == "1")
  10141. {
  10142. memo = item.Memo;
  10143. }
  10144. //主表修改
  10145. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  10146. BEGIN
  10147. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  10148. RETURN
  10149. END
  10150. DECLARE @Status VARCHAR(10)
  10151. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  10152. IF (@Status IS NULL)
  10153. BEGIN
  10154. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  10155. RETURN
  10156. END
  10157. ELSE IF (@Status!='1')
  10158. BEGIN
  10159. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  10160. RETURN
  10161. END
  10162. update ICSMOApplyNeg set WHCode='{0}',Memo='{5}',MUSER='{1}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{1}' and F_Location='{4}'),MTIME='{2}' where ID='{3}' and WorkPoint='{4}' ";
  10163. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint, memo);
  10164. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  10165. {
  10166. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  10167. }
  10168. //var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  10169. //if (detail > 0)
  10170. //{
  10171. // sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  10172. // sql = string.Format(sql, item.ID, item.WorkPoint);
  10173. // Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  10174. //}
  10175. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  10176. sql = string.Format(sql, item.ID, item.WorkPoint);
  10177. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  10178. foreach (var itemInfo in item.detail)
  10179. {
  10180. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  10181. {
  10182. //创建子表
  10183. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  10184. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  10185. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  10186. '{4}','{5}',0,'{6}','{7}',
  10187. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  10188. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  10189. }
  10190. else
  10191. {
  10192. //子表修改
  10193. sql = @"update ICSMOApplyNegDetail set InvCode='{0}' ,Quantity='{1}',Amount='{2}',SourceDetailID='{3}',MUSER='{6}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{5}') where ID='{4}' and WorkPoint='{5}'";
  10194. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  10195. }
  10196. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  10197. {
  10198. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  10199. }
  10200. idss += "'" + itemInfo.DetailID + "',";
  10201. }
  10202. //校验退料数量是否超出领料数量
  10203. sql = CheckMOIssueDoc(item.Type, Code, item.WorkPoint, language);
  10204. DBHelper.ExecuteNonQuery(sql, cmd);
  10205. ids += "'" + item.ID + "',";
  10206. }
  10207. sql = @"DELETE from ICSMOApplyNegDetail where ApplyNegCode ='{0}' and id not in ({1})";
  10208. sql = string.Format(sql, Code, idss.Substring(0, idss.Length - 1));
  10209. DBHelper.ExecuteNonQuery(sql, cmd);
  10210. if (string.IsNullOrWhiteSpace(ids))
  10211. {
  10212. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  10213. }
  10214. #region 查询返回数据
  10215. sql = @"SELECT a.ApplyNegCode,
  10216. c.WHCode,
  10217. c.Memo,
  10218. d.Name AS Status,
  10219. a.Sequence,
  10220. a.InvCode,
  10221. inv.InvName,
  10222. inv.InvStd,
  10223. a.Quantity,
  10224. inv.InvUnit,
  10225. a.Amount,
  10226. inv.AmountUnit,
  10227. a.IssueNegQuantity,
  10228. ext.ProjectCode,
  10229. ext.BatchCode,
  10230. ext.Version,
  10231. ext.Brand,
  10232. ext.cFree1,
  10233. ext.cFree2,
  10234. ext.cFree3,
  10235. ext.cFree4,
  10236. ext.cFree5,
  10237. ext.cFree6,
  10238. ext.cFree7,
  10239. ext.cFree8,
  10240. ext.cFree9,
  10241. ext.cFree10,
  10242. a.MUSER AS [User],
  10243. a.MTIME AS [MTime]
  10244. FROM ICSMOApplyNegDetail a
  10245. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  10246. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  10247. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  10248. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  10249. WHERE c.ID IN ({0})";
  10250. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  10251. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  10252. #endregion
  10253. cmd.Transaction.Commit();
  10254. return data;
  10255. }
  10256. catch (Exception ex)
  10257. {
  10258. if (cmd.Transaction != null)
  10259. cmd.Transaction.Rollback();
  10260. log.Error(ex.Message);
  10261. throw new Exception(ex.Message);
  10262. }
  10263. finally
  10264. {
  10265. if (conn.State == ConnectionState.Open)
  10266. {
  10267. conn.Close();
  10268. }
  10269. conn.Dispose();
  10270. }
  10271. }
  10272. }
  10273. /// <summary>
  10274. /// 生产退料 修改
  10275. /// </summary>
  10276. /// <param name="JsonData"></param>
  10277. /// <returns></returns>
  10278. public static DataTable AMMOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  10279. {
  10280. var language = LanguageHelper.GetName("WMSAPIInfo");
  10281. if (JsonData.Count <= 0)
  10282. {
  10283. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10284. }
  10285. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10286. {
  10287. conn.Open();
  10288. SqlTransaction sqlTran = conn.BeginTransaction();
  10289. SqlCommand cmd = new SqlCommand();
  10290. cmd.Transaction = sqlTran;
  10291. cmd.Connection = conn;
  10292. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10293. try
  10294. {
  10295. string sql = string.Empty;
  10296. string Code = string.Empty;
  10297. string ids = string.Empty;
  10298. string idss = string.Empty;
  10299. foreach (var item in JsonData)
  10300. {
  10301. //主表修改
  10302. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  10303. BEGIN
  10304. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  10305. RETURN
  10306. END
  10307. DECLARE @Status VARCHAR(10)
  10308. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  10309. IF (@Status IS NULL)
  10310. BEGIN
  10311. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  10312. RETURN
  10313. END
  10314. ELSE IF (@Status!='1')
  10315. BEGIN
  10316. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  10317. RETURN
  10318. END
  10319. update ICSMOApplyNeg set WHCode='{0}',MUSER='{1}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{1}' and F_Location='{4}'),MTIME='{2}' where ID='{3}' and WorkPoint='{4}' ";
  10320. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint);
  10321. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  10322. {
  10323. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  10324. }
  10325. //var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  10326. //if (detail > 0)
  10327. //{
  10328. // sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  10329. // sql = string.Format(sql, item.ID, item.WorkPoint);
  10330. // Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  10331. //}
  10332. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  10333. sql = string.Format(sql, item.ID, item.WorkPoint);
  10334. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  10335. foreach (var itemInfo in item.detail)
  10336. {
  10337. string chekksql = @"select c.EATTRIBUTE1 ICSInventory c
  10338. WHERE c.InvCode='{0}'AND c.WorkPoint='{1}' and c.AmountEnable='1'";
  10339. chekksql = string.Format(chekksql, itemInfo.InvCode, itemInfo.WorkPoint);
  10340. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  10341. if (dta.Rows.Count > 0)
  10342. {
  10343. itemInfo.Quantity = (decimal.Parse(itemInfo.Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  10344. }
  10345. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  10346. {
  10347. //创建子表
  10348. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  10349. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  10350. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  10351. '{4}','{5}',0,'{6}','{7}',
  10352. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  10353. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  10354. }
  10355. else
  10356. {
  10357. //子表修改
  10358. sql = @"update ICSMOApplyNegDetail set InvCode='{0}' ,Quantity='{1}',Amount='{2}',SourceDetailID='{3}',MUSER='{6}',MUSERName=(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{5}') where ID='{4}' and WorkPoint='{5}'";
  10359. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  10360. }
  10361. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  10362. {
  10363. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  10364. }
  10365. idss += "'" + itemInfo.DetailID + "',";
  10366. }
  10367. //校验退料数量是否超出领料数量
  10368. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  10369. DBHelper.ExecuteNonQuery(sql, cmd);
  10370. ids += "'" + item.ID + "',";
  10371. }
  10372. sql = @"DELETE from ICSMOApplyNegDetail where ApplyNegCode ='{0}' and id not in ({1})";
  10373. sql = string.Format(sql, Code, idss.Substring(0, idss.Length - 1));
  10374. DBHelper.ExecuteNonQuery(sql, cmd);
  10375. if (string.IsNullOrWhiteSpace(ids))
  10376. {
  10377. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  10378. }
  10379. #region 查询返回数据
  10380. sql = @"SELECT a.ApplyNegCode,
  10381. c.WHCode,
  10382. c.Memo,
  10383. d.Name AS Status,
  10384. a.Sequence,
  10385. a.InvCode,
  10386. inv.InvName,
  10387. inv.InvStd,
  10388. a.Quantity,
  10389. inv.InvUnit,
  10390. a.Amount,
  10391. inv.AmountUnit,
  10392. a.IssueNegQuantity,
  10393. ext.ProjectCode,
  10394. ext.BatchCode,
  10395. ext.Version,
  10396. ext.Brand,
  10397. ext.cFree1,
  10398. ext.cFree2,
  10399. ext.cFree3,
  10400. ext.cFree4,
  10401. ext.cFree5,
  10402. ext.cFree6,
  10403. ext.cFree7,
  10404. ext.cFree8,
  10405. ext.cFree9,
  10406. ext.cFree10,
  10407. a.MUSER AS [User],
  10408. a.MTIME AS [MTime]
  10409. FROM ICSMOApplyNegDetail a
  10410. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  10411. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  10412. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  10413. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  10414. WHERE c.ID IN ({0})";
  10415. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  10416. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  10417. #endregion
  10418. cmd.Transaction.Commit();
  10419. return data;
  10420. }
  10421. catch (Exception ex)
  10422. {
  10423. if (cmd.Transaction != null)
  10424. cmd.Transaction.Rollback();
  10425. log.Error(ex.Message);
  10426. throw new Exception(ex.Message);
  10427. }
  10428. finally
  10429. {
  10430. if (conn.State == ConnectionState.Open)
  10431. {
  10432. conn.Close();
  10433. }
  10434. conn.Dispose();
  10435. }
  10436. }
  10437. }
  10438. /// <summary>
  10439. /// 生产退料审核
  10440. /// </summary>
  10441. /// <param name="JsonData"></param>
  10442. /// <returns></returns>
  10443. public static DataTable MOIssueDocNegativeApplyApprove(List<ICSUser> JsonData)
  10444. {
  10445. string flag = string.Empty;
  10446. var language = LanguageHelper.GetName("WMSAPIInfo");
  10447. if (JsonData.Count <= 0)
  10448. {
  10449. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10450. }
  10451. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10452. {
  10453. conn.Open();
  10454. SqlTransaction sqlTran = conn.BeginTransaction();
  10455. SqlCommand cmd = new SqlCommand();
  10456. cmd.Transaction = sqlTran;
  10457. cmd.Connection = conn;
  10458. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10459. try
  10460. {
  10461. string sql = string.Empty;
  10462. string ids = string.Empty;
  10463. foreach (var item in JsonData)
  10464. {
  10465. bool hasApproveFlag = JsonData.Any(u => u.ApproveFlag != null);
  10466. if (hasApproveFlag == true)
  10467. {
  10468. flag = item.ApproveFlag;
  10469. }
  10470. if (string.IsNullOrEmpty(item.ID))
  10471. {
  10472. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  10473. }
  10474. if (string.IsNullOrEmpty(item.User))
  10475. {
  10476. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  10477. }
  10478. if (item.MTime <= new DateTime(2000, 1, 1))
  10479. {
  10480. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  10481. }
  10482. if (flag.Equals("1")|| flag=="")
  10483. {
  10484. //获取单号
  10485. sql = @"DECLARE @Status VARCHAR(10)
  10486. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  10487. IF (@Status IS NULL)
  10488. BEGIN
  10489. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  10490. RETURN
  10491. END
  10492. ELSE IF (@Status!='1')
  10493. BEGIN
  10494. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  10495. RETURN
  10496. END
  10497. update ICSMOApplyNeg set Status='2',eattribute1='{1}',eattribute2='{2}' where ID='{0}'
  10498. --update ICSMOApplyNeg set Status='1',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  10499. sql = string.Format(sql, item.ID, item.User, item.MTime);
  10500. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  10501. {
  10502. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  10503. }
  10504. ids += "'" + item.ID + "',";
  10505. }
  10506. else
  10507. {
  10508. //获取单号
  10509. sql = @"DECLARE @Status VARCHAR(10)
  10510. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  10511. IF (@Status IS NULL)
  10512. BEGIN
  10513. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  10514. RETURN
  10515. END
  10516. ELSE IF (@Status!='2')
  10517. BEGIN
  10518. RAISERROR('" + language.GetNameByCode("WMSAPIInfo473") + @"',16,1);
  10519. RETURN
  10520. END
  10521. IF EXISTS (select a.id from ICSMOApplyNeg a
  10522. left join ICSMOApplyNegDetail b on a.ApplyNegCode=b.ApplyNegCode and a.WorkPoint=b.WorkPoint
  10523. where a.ID='{0}' and b.IssueNegQuantity>0)
  10524. BEGIN
  10525. RAISERROR('" + language.GetNameByCode("WMSAPIInfo474") + @"',16,1);
  10526. RETURN
  10527. END
  10528. update ICSMOApplyNeg set Status='1',eattribute1='{1}',eattribute2='{2}' where ID='{0}'
  10529. --update ICSMOApplyNeg set Status='1',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  10530. sql = string.Format(sql, item.ID, item.User, item.MTime);
  10531. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  10532. {
  10533. throw new Exception(language.GetNameByCode("WMSAPIInfo475"));//"生产退料申请单弃审失败!");
  10534. }
  10535. ids += "'" + item.ID + "',";
  10536. }
  10537. }
  10538. if (string.IsNullOrWhiteSpace(ids))
  10539. {
  10540. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  10541. }
  10542. #region 查询返回数据
  10543. sql = @"SELECT a.ApplyNegCode,
  10544. c.WHCode,
  10545. c.Memo,
  10546. d.Name AS Status,
  10547. a.Sequence,
  10548. a.InvCode,
  10549. inv.InvName,
  10550. inv.InvStd,
  10551. a.Quantity,
  10552. inv.InvUnit,
  10553. a.Amount,
  10554. inv.AmountUnit,
  10555. a.IssueNegQuantity,
  10556. ext.ProjectCode,
  10557. ext.BatchCode,
  10558. ext.Version,
  10559. ext.Brand,
  10560. ext.cFree1,
  10561. ext.cFree2,
  10562. ext.cFree3,
  10563. ext.cFree4,
  10564. ext.cFree5,
  10565. ext.cFree6,
  10566. ext.cFree7,
  10567. ext.cFree8,
  10568. ext.cFree9,
  10569. ext.cFree10,
  10570. a.MUSER AS [User],
  10571. a.MTIME AS [MTime]
  10572. FROM ICSMOApplyNegDetail a
  10573. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  10574. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  10575. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  10576. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  10577. WHERE c.ID IN ({0})";
  10578. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  10579. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  10580. #endregion
  10581. cmd.Transaction.Commit();
  10582. return data;
  10583. }
  10584. catch (Exception ex)
  10585. {
  10586. if (cmd.Transaction != null)
  10587. cmd.Transaction.Rollback();
  10588. log.Error(ex.Message);
  10589. throw new Exception(ex.Message);
  10590. }
  10591. finally
  10592. {
  10593. if (conn.State == ConnectionState.Open)
  10594. {
  10595. conn.Close();
  10596. }
  10597. conn.Dispose();
  10598. }
  10599. }
  10600. }
  10601. #endregion
  10602. #region 一步调拨(调拨申请单)
  10603. /// <summary>
  10604. /// 一步调拨(调拨申请单)
  10605. /// </summary>
  10606. /// <param name="JsonData"></param>
  10607. /// <returns></returns>
  10608. public static DataTable OneStepTransferApplicationIn(List<TransferApplication> JsonData)
  10609. {
  10610. var language = LanguageHelper.GetName("WMSAPIInfo");
  10611. if (JsonData.Count <= 0)
  10612. {
  10613. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10614. }
  10615. DataTable printTable = new DataTable();
  10616. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10617. {
  10618. conn.Open();
  10619. SqlTransaction sqlTran = conn.BeginTransaction();
  10620. SqlCommand cmd = new SqlCommand();
  10621. cmd.Transaction = sqlTran;
  10622. cmd.Connection = conn;
  10623. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10624. string BusinessCode = string.Empty;
  10625. try
  10626. {
  10627. string sql = string.Empty;
  10628. string Identification = Guid.NewGuid().ToString();
  10629. foreach (var item in JsonData)
  10630. {
  10631. if (string.IsNullOrEmpty(item.TransCode))
  10632. {
  10633. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨申请单号不能为空!");
  10634. }
  10635. string[] trans = item.TransCode.Split('~');
  10636. string MergeID = "";
  10637. if (trans.Length == 2)
  10638. {
  10639. MergeID = trans[0];
  10640. item.TransCode = trans[1];
  10641. }
  10642. //验证信息
  10643. sql = @"DECLARE @Status VARCHAR(10)
  10644. SELECT @Status=Status FROM ICSTransferApplication WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  10645. IF (@Status IS NULL)
  10646. BEGIN
  10647. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  10648. RETURN
  10649. END
  10650. ELSE IF (@Status!='1')
  10651. BEGIN
  10652. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  10653. RETURN
  10654. END";
  10655. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  10656. DBHelper.ExecuteNonQuery(sql, cmd);
  10657. foreach (var itemInfo in item.Detail)
  10658. {
  10659. //验证仓库库位信息
  10660. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  10661. BEGIN
  10662. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  10663. RETURN
  10664. END
  10665. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  10666. BEGIN
  10667. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  10668. RETURN
  10669. END
  10670. IF NOT EXISTS(SELECT a.ID
  10671. FROM ICSWareHouse a
  10672. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  10673. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  10674. BEGIN
  10675. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  10676. RETURN
  10677. END";
  10678. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  10679. DBHelper.ExecuteNonQuery(sql, cmd);
  10680. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  10681. //更新源头单据信息
  10682. ICSWareHouseService.OneStepTransferApplicationIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  10683. //更新条码信息
  10684. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  10685. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint,"", "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  10686. }
  10687. }
  10688. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification,"" ,cmd, language, BusinessCode);
  10689. if (!printTable.Equals("{}"))
  10690. {
  10691. cmd.Transaction.Commit();
  10692. return printTable;
  10693. }
  10694. else
  10695. {
  10696. DataTable table = GetData(Identification, 3, cmd);
  10697. cmd.Transaction.Commit();
  10698. return table;
  10699. }
  10700. }
  10701. catch (Exception ex)
  10702. {
  10703. if (cmd.Transaction != null)
  10704. cmd.Transaction.Rollback();
  10705. log.Error(ex.Message);
  10706. throw new Exception(ex.Message);
  10707. }
  10708. finally
  10709. {
  10710. if (conn.State == ConnectionState.Open)
  10711. {
  10712. conn.Close();
  10713. }
  10714. conn.Dispose();
  10715. }
  10716. }
  10717. }
  10718. #endregion
  10719. #region 一步调拨
  10720. /// <summary>
  10721. /// 一步调拨
  10722. /// </summary>
  10723. /// <param name="JsonData"></param>
  10724. /// <returns></returns>
  10725. public static DataTable OneStepTransferDocIn(List<TransferDoc> JsonData)
  10726. {
  10727. var language = LanguageHelper.GetName("WMSAPIInfo");
  10728. if (JsonData.Count <= 0)
  10729. {
  10730. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10731. }
  10732. DataTable printTable = new DataTable();
  10733. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10734. {
  10735. conn.Open();
  10736. SqlTransaction sqlTran = conn.BeginTransaction();
  10737. SqlCommand cmd = new SqlCommand();
  10738. cmd.Transaction = sqlTran;
  10739. cmd.Connection = conn;
  10740. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10741. string BusinessCode = string.Empty;
  10742. try
  10743. {
  10744. string sql = string.Empty;
  10745. string isPN = "0";
  10746. string Identification = Guid.NewGuid().ToString();
  10747. foreach (var item in JsonData)
  10748. {
  10749. if (string.IsNullOrEmpty(item.TransCode))
  10750. {
  10751. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨单号不能为空!");
  10752. }
  10753. if (item.IsPN=="1")
  10754. {
  10755. isPN = "1";
  10756. }
  10757. else
  10758. {
  10759. isPN = "0";
  10760. }
  10761. string[] trans = item.TransCode.Split('~');
  10762. string MergeID = "";
  10763. if (trans.Length == 2)
  10764. {
  10765. MergeID = trans[0];
  10766. item.TransCode = trans[1];
  10767. }
  10768. //验证信息
  10769. if (isPN=="1")
  10770. {
  10771. sql = @"DECLARE @Status VARCHAR(10)
  10772. SELECT @Status=Status FROM ICSTransfer WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '3'
  10773. IF (@Status IS NULL)
  10774. BEGIN
  10775. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  10776. RETURN
  10777. END
  10778. ELSE IF (@Status!='1')
  10779. BEGIN
  10780. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  10781. RETURN
  10782. END";
  10783. }
  10784. else
  10785. {
  10786. sql = @"DECLARE @Status VARCHAR(10)
  10787. SELECT @Status=Status FROM ICSTransfer WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  10788. IF (@Status IS NULL)
  10789. BEGIN
  10790. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  10791. RETURN
  10792. END
  10793. ELSE IF (@Status!='1')
  10794. BEGIN
  10795. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  10796. RETURN
  10797. END";
  10798. }
  10799. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  10800. DBHelper.ExecuteNonQuery(sql, cmd);
  10801. foreach (var itemInfo in item.Detail)
  10802. {
  10803. //验证仓库库位信息
  10804. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  10805. BEGIN
  10806. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  10807. RETURN
  10808. END
  10809. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  10810. BEGIN
  10811. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  10812. RETURN
  10813. END
  10814. IF NOT EXISTS(SELECT a.ID
  10815. FROM ICSWareHouse a
  10816. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  10817. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  10818. BEGIN
  10819. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  10820. RETURN
  10821. END";
  10822. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  10823. DBHelper.ExecuteNonQuery(sql, cmd);
  10824. BusinessCode = TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>();
  10825. //更新源头单据信息
  10826. ICSWareHouseService.OneStepTransferDocIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity,item.IsPN, cmd, language);
  10827. //更新条码信息
  10828. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  10829. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint,"", "6", TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  10830. }
  10831. }
  10832. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, isPN, cmd, language, BusinessCode);
  10833. if (!printTable.Equals("{}"))
  10834. {
  10835. cmd.Transaction.Commit();
  10836. return printTable;
  10837. }
  10838. else
  10839. {
  10840. DataTable table = GetData(Identification, 3, cmd);
  10841. cmd.Transaction.Commit();
  10842. return table;
  10843. }
  10844. }
  10845. catch (Exception ex)
  10846. {
  10847. if (cmd.Transaction != null)
  10848. cmd.Transaction.Rollback();
  10849. log.Error(ex.Message);
  10850. throw new Exception(ex.Message);
  10851. }
  10852. finally
  10853. {
  10854. if (conn.State == ConnectionState.Open)
  10855. {
  10856. conn.Close();
  10857. }
  10858. conn.Dispose();
  10859. }
  10860. }
  10861. }
  10862. #endregion
  10863. #region 调拨
  10864. /// <summary>
  10865. /// 调拨
  10866. /// </summary>
  10867. /// <param name="JsonData"></param>
  10868. /// <returns></returns>
  10869. public static DataTable TransferDocCreate(List<TransferDoc> JsonData)
  10870. {
  10871. var language = LanguageHelper.GetName("WMSAPIInfo");
  10872. if (JsonData.Count <= 0)
  10873. {
  10874. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10875. }
  10876. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10877. {
  10878. conn.Open();
  10879. SqlTransaction sqlTran = conn.BeginTransaction();
  10880. SqlCommand cmd = new SqlCommand();
  10881. cmd.Transaction = sqlTran;
  10882. cmd.Connection = conn;
  10883. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10884. string BusinessCode = string.Empty;
  10885. try
  10886. {
  10887. string sql = string.Empty;
  10888. string Identification = Guid.NewGuid().ToString();
  10889. foreach (var item in JsonData)
  10890. {
  10891. string MergeID = "";
  10892. foreach (var itemInfo in item.Detail)
  10893. {
  10894. //验证仓库库位信息
  10895. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  10896. BEGIN
  10897. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  10898. RETURN
  10899. END
  10900. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  10901. BEGIN
  10902. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  10903. RETURN
  10904. END
  10905. IF NOT EXISTS(SELECT a.ID
  10906. FROM ICSWareHouse a
  10907. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  10908. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  10909. BEGIN
  10910. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  10911. RETURN
  10912. END";
  10913. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  10914. DBHelper.ExecuteNonQuery(sql, cmd);
  10915. BusinessCode = TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>();
  10916. //更新条码信息
  10917. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  10918. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint,"", "6", TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  10919. }
  10920. }
  10921. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  10922. DataTable table = GetData(Identification, 3, cmd);
  10923. cmd.Transaction.Commit();
  10924. return table;
  10925. }
  10926. catch (Exception ex)
  10927. {
  10928. if (cmd.Transaction != null)
  10929. cmd.Transaction.Rollback();
  10930. log.Error(ex.Message);
  10931. throw new Exception(ex.Message);
  10932. }
  10933. finally
  10934. {
  10935. if (conn.State == ConnectionState.Open)
  10936. {
  10937. conn.Close();
  10938. }
  10939. conn.Dispose();
  10940. }
  10941. }
  10942. }
  10943. #endregion
  10944. #region 无源头调拨
  10945. /// <summary>
  10946. /// 无源头调拨
  10947. /// </summary>
  10948. /// <param name="JsonData"></param>
  10949. /// <returns></returns>
  10950. public static DataTable OneStepNoTransferDocIn(List<TransferDoc> JsonData)
  10951. {
  10952. var language = LanguageHelper.GetName("WMSAPIInfo");
  10953. if (JsonData.Count <= 0)
  10954. {
  10955. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10956. }
  10957. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10958. {
  10959. conn.Open();
  10960. SqlTransaction sqlTran = conn.BeginTransaction();
  10961. SqlCommand cmd = new SqlCommand();
  10962. cmd.Transaction = sqlTran;
  10963. DataTable printTable = new DataTable();
  10964. cmd.Connection = conn;
  10965. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10966. string sql = string.Empty;
  10967. try
  10968. {
  10969. string workpoint = "";
  10970. string Identification = Guid.NewGuid().ToString();
  10971. string BusinessCode = "";
  10972. foreach (var item in JsonData)
  10973. {
  10974. string MergeID = "";
  10975. foreach (var itemInfo in item.Detail)
  10976. {
  10977. //验证仓库库位信息
  10978. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  10979. BEGIN
  10980. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  10981. RETURN
  10982. END
  10983. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  10984. BEGIN
  10985. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"),"{2}") + @"',16,1);
  10986. RETURN
  10987. END
  10988. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo = '{3}' AND a.WorkPoint = '{1}' AND a.Quantity >={4})
  10989. BEGIN
  10990. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo368"),"{3}") + @"', 16, 1);
  10991. RETURN
  10992. END
  10993. IF NOT EXISTS(SELECT a.ID
  10994. FROM ICSWareHouse a
  10995. INNER JOIN ICSLocation b ON a.ID = b.WHID AND a.WorkPoint = b.WorkPoint
  10996. WHERE a.WarehouseCode = '{0}' AND a.WorkPoint = '{1}' AND b.LocationCode = '{2}')
  10997. BEGIN
  10998. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"', 16, 1);
  10999. RETURN
  11000. END
  11001. ";
  11002. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.CurrentQuantity);
  11003. log.Error(sql);
  11004. DBHelper.ExecuteNonQuery(sql, cmd);
  11005. BusinessCode = TransTypeEnum.StepNoTransferDocIn.GetDescription<DBValue>();
  11006. workpoint = item.WorkPoint;
  11007. //更新条码信息
  11008. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoNoTransfer(Identification, itemInfo.WarehouseCode, itemInfo.LocationCode,
  11009. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepNoTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID,item.Memo);
  11010. }
  11011. }
  11012. if (!string.IsNullOrWhiteSpace(JsonData[0].passFlag) && JsonData[0].passFlag=="0")
  11013. {
  11014. string message = SubmitCanOut(Identification, "6", TransTypeEnum.StepNoTransferDocIn.GetDescription<DBValue>(), workpoint, cmd);
  11015. if (!string.IsNullOrWhiteSpace(message)) {
  11016. throw new Exception(message);
  11017. }
  11018. }
  11019. ICSWareHouseService.OneStepNoTransferDocInERP(TransTypeEnum.StepNoTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  11020. if (!printTable.Equals("{}"))
  11021. {
  11022. cmd.Transaction.Commit();
  11023. return printTable;
  11024. }
  11025. else
  11026. {
  11027. DataTable table = GetData(Identification, 3, cmd);
  11028. cmd.Transaction.Commit();
  11029. return table;
  11030. }
  11031. }
  11032. catch (Exception ex)
  11033. {
  11034. if (cmd.Transaction != null)
  11035. cmd.Transaction.Rollback();
  11036. log.Error(sql);
  11037. log.Error(ex.Message);
  11038. throw new Exception(ex.Message);
  11039. }
  11040. finally
  11041. {
  11042. if (conn.State == ConnectionState.Open)
  11043. {
  11044. conn.Close();
  11045. }
  11046. conn.Dispose();
  11047. }
  11048. }
  11049. }
  11050. #endregion
  11051. #region 铭锋先进先出卡控提交判断
  11052. /// <summary>
  11053. /// 铭锋先进先出卡控提交判断
  11054. /// </summary>
  11055. /// <param name="JsonData"></param>
  11056. /// <returns></returns>
  11057. public static string SubmitCanOut(string Identification, string TransType, string BusinessCode, string WorkPoint, SqlCommand cmd)
  11058. {
  11059. string message = string.Empty;
  11060. string sql = string.Empty;
  11061. try
  11062. {
  11063. //查出所有发料记录 按照批次排序 物料分组--批次最大的记录
  11064. sql = @"select* from (select c.batchcode,a.invcode,a.FromWAREHOUSECODE, ROW_NUMBER() OVER (PARTITION BY a.Identification, a.invcode,a.FromWAREHOUSECODE ORDER BY c.BatchCode desc) as seq
  11065. from ICSWareHouseLotInfoLog a
  11066. inner join ICSInventoryLot b on a.lotno= b.LotNo and a.WorkPoint = b.WorkPoint
  11067. inner join ICSExtension c on b.ExtensionID = c.ID and c.WorkPoint = b.WorkPoint
  11068. where a.transtype ='{1}' and a.businesscode = '{2}' and a.Identification='{0}') a where a.seq=1";
  11069. sql = string.Format(sql, Identification, TransType, BusinessCode);
  11070. log.Debug("提交先进先出卡控:"+ sql);
  11071. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  11072. foreach (DataRow dr in dt.Rows)
  11073. {//以发料记录内最大的记录 反查库存内是否存在更早的批次
  11074. sql = @"select top 1 c.BatchCode,SUM(a.Quantity) as Quantity,a.invcode,a.warehousecode FROM ICSWareHouseLotInfo a
  11075. inner join ICSInventoryLot b on a.lotno= b.LotNo and a.WorkPoint = b.WorkPoint
  11076. inner join ICSExtension c on b.ExtensionID = c.ID and c.WorkPoint = b.WorkPoint
  11077. GROUP BY c.BatchCode,a.invcode,a.WorkPoint,a.warehousecode
  11078. having a.InvCode = '{0}' and c.batchcode<'{1}' and a.WorkPoint ='{2}'and SUM(a.Quantity)>0 and a.warehousecode='{3}'
  11079. order by c.BatchCode asc";
  11080. sql = string.Format(sql, dr["invcode"], dr["batchcode"], WorkPoint, dr["FromWAREHOUSECODE"]);
  11081. log.Debug("提交先进先出卡控:" + sql);
  11082. DataTable dts = DBHelper.SQlReturnData(sql, cmd);
  11083. if (dts.Rows.Count > 0)
  11084. {
  11085. message += "料号:" + dts.Rows[0]["invcode"] + "在仓库"+ dts.Rows[0]["warehousecode"] + "内存在未发批次:" + dts.Rows[0]["BatchCode"] + "数量:" + dts.Rows[0]["Quantity"]+";";
  11086. }
  11087. }
  11088. }
  11089. catch (Exception ex)
  11090. {
  11091. log.Error(sql);
  11092. log.Error(ex.Message);
  11093. throw new Exception(ex.Message);
  11094. }
  11095. return message;
  11096. }
  11097. #endregion
  11098. #region 调拨申请单
  11099. /// <summary>
  11100. /// 调拨
  11101. /// </summary>
  11102. /// <param name="JsonData"></param>
  11103. /// <returns></returns>
  11104. public static DataTable TransferApplicationCreate(List<TransferApplication> JsonData)
  11105. {
  11106. var language = LanguageHelper.GetName("WMSAPIInfo");
  11107. if (JsonData.Count <= 0)
  11108. {
  11109. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11110. }
  11111. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11112. {
  11113. conn.Open();
  11114. SqlTransaction sqlTran = conn.BeginTransaction();
  11115. SqlCommand cmd = new SqlCommand();
  11116. cmd.Transaction = sqlTran;
  11117. cmd.Connection = conn;
  11118. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11119. string BusinessCode = string.Empty;
  11120. try
  11121. {
  11122. string sql = string.Empty;
  11123. string Identification = Guid.NewGuid().ToString();
  11124. foreach (var item in JsonData)
  11125. {
  11126. string MergeID = "";
  11127. foreach (var itemInfo in item.Detail)
  11128. {
  11129. //验证仓库库位信息
  11130. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  11131. BEGIN
  11132. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  11133. RETURN
  11134. END
  11135. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  11136. BEGIN
  11137. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  11138. RETURN
  11139. END
  11140. IF NOT EXISTS(SELECT a.ID
  11141. FROM ICSWareHouse a
  11142. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  11143. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  11144. BEGIN
  11145. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  11146. RETURN
  11147. END";
  11148. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  11149. DBHelper.ExecuteNonQuery(sql, cmd);
  11150. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  11151. //更新条码信息
  11152. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  11153. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint,"", "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  11154. }
  11155. }
  11156. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferApplicationIn.GetDescription(), Identification, cmd, language, BusinessCode);
  11157. DataTable table = GetData(Identification, 3, cmd);
  11158. cmd.Transaction.Commit();
  11159. return table;
  11160. }
  11161. catch (Exception ex)
  11162. {
  11163. if (cmd.Transaction != null)
  11164. cmd.Transaction.Rollback();
  11165. log.Error(ex.Message);
  11166. throw new Exception(ex.Message);
  11167. }
  11168. finally
  11169. {
  11170. if (conn.State == ConnectionState.Open)
  11171. {
  11172. conn.Close();
  11173. }
  11174. conn.Dispose();
  11175. }
  11176. }
  11177. }
  11178. #endregion
  11179. #region 调拨申请单
  11180. /// <summary>
  11181. /// 调拨申请单
  11182. /// </summary>
  11183. /// <param name="JsonData"></param>
  11184. /// <returns></returns>
  11185. public static DataTable TransferApplicationInCreate(List<TransferApplication> JsonData)
  11186. {
  11187. var language = LanguageHelper.GetName("WMSAPIInfo");
  11188. if (JsonData.Count <= 0)
  11189. {
  11190. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11191. }
  11192. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11193. {
  11194. conn.Open();
  11195. SqlTransaction sqlTran = conn.BeginTransaction();
  11196. SqlCommand cmd = new SqlCommand();
  11197. cmd.Transaction = sqlTran;
  11198. cmd.Connection = conn;
  11199. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11200. string BusinessCode = string.Empty;
  11201. try
  11202. {
  11203. DataTable printTable = new DataTable();
  11204. string sql = string.Empty;
  11205. string Identification = Guid.NewGuid().ToString();
  11206. foreach (var item in JsonData)
  11207. {
  11208. string MergeID = "";
  11209. foreach (var itemInfo in item.Detail)
  11210. {
  11211. //验证仓库库位信息
  11212. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  11213. BEGIN
  11214. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  11215. RETURN
  11216. END
  11217. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  11218. BEGIN
  11219. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  11220. RETURN
  11221. END
  11222. IF NOT EXISTS(SELECT a.ID
  11223. FROM ICSWareHouse a
  11224. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  11225. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  11226. BEGIN
  11227. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  11228. RETURN
  11229. END
  11230. IF EXISTS(SELECT ID
  11231. FROM ICSWareHouseLotInfo
  11232. WHERE WarehouseCode='{0}' AND WorkPoint='{1}' AND LotNo='{3}')
  11233. BEGIN
  11234. RAISERROR('" + language.GetNameByCode("WMSAPIInfo355") + @"',16,1);
  11235. RETURN
  11236. END";
  11237. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode, itemInfo.LotNo);
  11238. DBHelper.ExecuteNonQuery(sql, cmd);
  11239. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  11240. //更新源头单据信息
  11241. ICSWareHouseService.OneStepTransferApplicationIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  11242. //更新条码信息
  11243. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  11244. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint,item.InWorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  11245. }
  11246. }
  11247. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  11248. {
  11249. ICSWareHouseService.StepTransferApplicationERP(TransTypeEnum.StepTransferApplicationIn.GetDescription(), Identification, cmd, language, BusinessCode);
  11250. }
  11251. if (!printTable.Equals("{}"))
  11252. {
  11253. cmd.Transaction.Commit();
  11254. return printTable;
  11255. }
  11256. else
  11257. {
  11258. DataTable table = GetData(Identification, 3, cmd);
  11259. cmd.Transaction.Commit();
  11260. return table;
  11261. }
  11262. }
  11263. catch (Exception ex)
  11264. {
  11265. if (cmd.Transaction != null)
  11266. cmd.Transaction.Rollback();
  11267. log.Error(ex.Message);
  11268. throw new Exception(ex.Message);
  11269. }
  11270. finally
  11271. {
  11272. if (conn.State == ConnectionState.Open)
  11273. {
  11274. conn.Close();
  11275. }
  11276. conn.Dispose();
  11277. }
  11278. }
  11279. }
  11280. #endregion
  11281. //#region 工单关联
  11282. ///// <summary>
  11283. ///// 条码关联工单
  11284. ///// </summary>
  11285. ///// <param name="JsonData"></param>
  11286. ///// <returns></returns>
  11287. //public static DataTable ICSMOReceive(List<LOTStockUpCreateIModel> JsonData)
  11288. //{
  11289. // var language = LanguageHelper.GetName("WMSAPIInfo");
  11290. // if (JsonData.Count <= 0)
  11291. // {
  11292. // throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11293. // }
  11294. // using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11295. // {
  11296. // conn.Open();
  11297. // SqlTransaction sqlTran = conn.BeginTransaction();
  11298. // SqlCommand cmd = new SqlCommand();
  11299. // cmd.Transaction = sqlTran;
  11300. // cmd.Connection = conn;
  11301. // try
  11302. // {
  11303. // string sql = string.Empty;
  11304. // string TransType = string.Empty;
  11305. // string Identification = Guid.NewGuid().ToString();
  11306. // foreach (var item in JsonData)
  11307. // {
  11308. // string MergeID = "";
  11309. // foreach (var itemInfo in item.detail)
  11310. // {
  11311. // ICSWareHouseService.ICSMOReceive(itemInfo.LotNo, itemInfo.Quantity, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint, Identification, item.User, itemInfo.SRMLotGroup, itemInfo.ProjectCode,
  11312. // itemInfo.BatchCode, itemInfo.Version, itemInfo.Brand, itemInfo.cFree1, itemInfo.cFree2, itemInfo.cFree3, itemInfo.cFree4, itemInfo.cFree5,
  11313. // itemInfo.cFree6, itemInfo.cFree7, itemInfo.cFree8, itemInfo.cFree9, itemInfo.cFree10, TransTypeEnum.ICSMOReceive.GetDescription<DBValue>(), cmd, language);
  11314. // }
  11315. // }
  11316. // DataTable table = GetData(Identification, 3, cmd);
  11317. // cmd.Transaction.Commit();
  11318. // return table;
  11319. // }
  11320. // catch (Exception ex)
  11321. // {
  11322. // if (cmd.Transaction != null)
  11323. // cmd.Transaction.Rollback();
  11324. // log.Error(ex.Message);
  11325. // throw new Exception(ex.Message);
  11326. // }
  11327. // finally
  11328. // {
  11329. // if (conn.State == ConnectionState.Open)
  11330. // {
  11331. // conn.Close();
  11332. // }
  11333. // conn.Dispose();
  11334. // }
  11335. // }
  11336. //}
  11337. ///// <summary>
  11338. ///// 条码与工单解绑
  11339. ///// </summary>
  11340. ///// <param name="JsonData"></param>
  11341. ///// <returns></returns>
  11342. //public static DataTable ICSMOReceiveUntie(ICSMOReceiveUntieModel JsonData)
  11343. //{
  11344. // var language = LanguageHelper.GetName("WMSAPIInfo");
  11345. // if (JsonData == null)
  11346. // {
  11347. // throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11348. // }
  11349. // using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11350. // {
  11351. // conn.Open();
  11352. // SqlTransaction sqlTran = conn.BeginTransaction();
  11353. // SqlCommand cmd = new SqlCommand();
  11354. // cmd.Transaction = sqlTran;
  11355. // cmd.Connection = conn;
  11356. // try
  11357. // {
  11358. // string sql = string.Empty;
  11359. // string TransType = string.Empty;
  11360. // string Identification = Guid.NewGuid().ToString();
  11361. // string MergeID = "";
  11362. // ICSWareHouseService.ICSMOReceiveUntie(JsonData.LotNo, JsonData.WorkPoint, TransTypeEnum.ICSMOReceive.GetDescription<DBValue>(), cmd, language);
  11363. // DataTable table = GetData(Identification, 3, cmd);
  11364. // cmd.Transaction.Commit();
  11365. // return table;
  11366. // }
  11367. // catch (Exception ex)
  11368. // {
  11369. // if (cmd.Transaction != null)
  11370. // cmd.Transaction.Rollback();
  11371. // log.Error(ex.Message);
  11372. // throw new Exception(ex.Message);
  11373. // }
  11374. // finally
  11375. // {
  11376. // if (conn.State == ConnectionState.Open)
  11377. // {
  11378. // conn.Close();
  11379. // }
  11380. // conn.Dispose();
  11381. // }
  11382. // }
  11383. //}
  11384. //#endregion
  11385. //#region 工单关联条码检验
  11386. ///// <summary>
  11387. ///// 工单关联条码检验
  11388. ///// </summary>
  11389. ///// <param name="JsonData"></param>
  11390. ///// <returns></returns>
  11391. //public static bool ICSMOReceiveLotCheck(BarCodeModel JsonData)
  11392. //{
  11393. // Boolean LotCheck = false;
  11394. // var language = LanguageHelper.GetName("WMSAPIInfo");
  11395. // using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11396. // {
  11397. // conn.Open();
  11398. // SqlTransaction sqlTran = conn.BeginTransaction();
  11399. // SqlCommand cmd = new SqlCommand();
  11400. // cmd.Transaction = sqlTran;
  11401. // cmd.Connection = conn;
  11402. // try
  11403. // {
  11404. // string sql = string.Empty;
  11405. // string TransType = string.Empty;
  11406. // string Identification = Guid.NewGuid().ToString();
  11407. // sql = @"select * from ICSInventoryLotDetail where LotNo='{0}' and WorkPoint='{1}'";
  11408. // sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  11409. // DataTable table = DBHelper.SQlReturnData(sql, cmd);
  11410. // cmd.Transaction.Commit();
  11411. // if (table.Rows.Count > 0)
  11412. // {
  11413. // LotCheck = true;
  11414. // }
  11415. // return LotCheck;
  11416. // }
  11417. // catch (Exception ex)
  11418. // {
  11419. // if (cmd.Transaction != null)
  11420. // cmd.Transaction.Rollback();
  11421. // log.Error(ex.Message);
  11422. // throw new Exception(ex.Message);
  11423. // }
  11424. // finally
  11425. // {
  11426. // if (conn.State == ConnectionState.Open)
  11427. // {
  11428. // conn.Close();
  11429. // }
  11430. // conn.Dispose();
  11431. // }
  11432. // }
  11433. //}
  11434. //#endregion
  11435. #region 容器
  11436. /// <summary>
  11437. /// 查询容器
  11438. /// </summary>
  11439. /// <param name="JsonData"></param>
  11440. /// <returns></returns>
  11441. public static DataTable ICSContainerGet(BarCodeModel JsonData)
  11442. {
  11443. var language = LanguageHelper.GetName("WMSAPIInfo");
  11444. if (JsonData == null)
  11445. {
  11446. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11447. }
  11448. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11449. {
  11450. conn.Open();
  11451. SqlTransaction sqlTran = conn.BeginTransaction();
  11452. SqlCommand cmd = new SqlCommand();
  11453. cmd.Transaction = sqlTran;
  11454. cmd.Connection = conn;
  11455. try
  11456. {
  11457. string sql = "";
  11458. string TransType = string.Empty;
  11459. string Identification = Guid.NewGuid().ToString();
  11460. // if (JsonData.ifCreateContainer)
  11461. // {
  11462. // sql = @"IF EXISTS(select ContainerCODE from ICSContainer where ContainerCODE='{0}' )
  11463. // BEGIN
  11464. // RAISERROR('容器:{0},已存在!',16,1)
  11465. // RETURN
  11466. // END
  11467. // else
  11468. // BEGIN
  11469. // INSERT INTO dbo.ICSContainer
  11470. // ( ID ,ContainerID ,ContainerCODE ,ContainerName,Memo,MTIME,MUSER ,MUSERName ,WorkPoint
  11471. // ,InventoryMixed,ProjectMixed,BatchMixed,Multiplex)
  11472. // Values(NEWID(),'','{0}','{0}','',GETDATE(),'{2}','{2}','{1}','0','0','0','0')
  11473. // END
  11474. //";
  11475. // }
  11476. sql += @"IF NOT EXISTS(select ContainerCODE from ICSContainer where ContainerCODE='{0}' )
  11477. BEGIN
  11478. -- RAISERROR('{0}',16,1)
  11479. INSERT INTO dbo.ICSContainer
  11480. ( ID ,ContainerID ,ContainerCODE ,ContainerName,Memo,MTIME,MUSER ,MUSERName ,WorkPoint
  11481. ,InventoryMixed,ProjectMixed,BatchMixed,Multiplex)
  11482. Values(NEWID(),'','{0}','{0}','',GETDATE(),'{2}',(SELECT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}'),'{1}','1','1','1','1')
  11483. -- RETURN
  11484. END
  11485. SELECT con.ID,con.ContainerID,con.ContainerCode,con.ContainerName,con.Memo,con.ContainerType,con.InventoryMixed,con.ProjectMixed,con.BatchMixed,con.Multiplex,con.MUSER,con.MUSERName,con.MTIME,con.WorkPoint,con.EATTRIBUTE1 AS cFree1,con.EATTRIBUTE2 AS cFree2,con.EATTRIBUTE3 AS cFree3,con.EATTRIBUTE4 AS cFree4,con.EATTRIBUTE5 AS cFree5,con.EATTRIBUTE6 AS cFree6,con.EATTRIBUTE7 AS cFree7,con.EATTRIBUTE8 AS cFree8,con.EATTRIBUTE9 AS cFree9,con.EATTRIBUTE10 AS cFree10,temp.BindQuantity
  11486. FROM ICSContainer con
  11487. LEFT JOIN (
  11488. SELECT COUNT(1) AS BindQuantity,con.ContainerCode
  11489. FROM ICSContainer con
  11490. INNER JOIN ICSContainerLot conlot ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  11491. WHERE con.ContainerCode='{0}' AND con.WorkPoint='{1}'
  11492. GROUP BY con.ContainerCode
  11493. ) temp ON temp.ContainerCode=con.ContainerCode
  11494. WHERE con.ContainerCode='{0}' AND con.WorkPoint='{1}'";
  11495. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint, JsonData.User);
  11496. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  11497. cmd.Transaction.Commit();
  11498. return table;
  11499. }
  11500. catch (Exception ex)
  11501. {
  11502. if (cmd.Transaction != null)
  11503. cmd.Transaction.Rollback();
  11504. log.Error(ex.Message);
  11505. throw new Exception(ex.Message);
  11506. }
  11507. finally
  11508. {
  11509. if (conn.State == ConnectionState.Open)
  11510. {
  11511. conn.Close();
  11512. }
  11513. conn.Dispose();
  11514. }
  11515. }
  11516. }
  11517. /// <summary>
  11518. /// 容器关联查询容器
  11519. /// </summary>
  11520. /// <param name="JsonData"></param>
  11521. /// <returns></returns>
  11522. public static DataTable ICSContainerConGet(BarCodeModel JsonData)
  11523. {
  11524. var language = LanguageHelper.GetName("WMSAPIInfo");
  11525. if (JsonData == null)
  11526. {
  11527. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11528. }
  11529. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11530. {
  11531. conn.Open();
  11532. SqlTransaction sqlTran = conn.BeginTransaction();
  11533. SqlCommand cmd = new SqlCommand();
  11534. cmd.Transaction = sqlTran;
  11535. cmd.Connection = conn;
  11536. try
  11537. {
  11538. string sql = string.Empty;
  11539. string TransType = string.Empty;
  11540. string Identification = Guid.NewGuid().ToString();
  11541. sql = @"SELECT con.ID,con.ContainerID,con.ContainerCode,con.ContainerName,con.Memo,con.ContainerType,con.InventoryMixed,con.ProjectMixed,con.BatchMixed,con.Multiplex,con.MUSER,con.MUSERName,con.MTIME,con.WorkPoint,con.
  11542. EATTRIBUTE1 AS cFree1,con.EATTRIBUTE2 AS cFree2,con.EATTRIBUTE3 AS cFree3,con.EATTRIBUTE4 AS cFree4,con.EATTRIBUTE5 AS cFree5,con.EATTRIBUTE6 AS cFree6,con.EATTRIBUTE7 AS cFree7
  11543. ,con.EATTRIBUTE8 AS cFree8,con.EATTRIBUTE9 AS cFree9,con.EATTRIBUTE10 AS cFree10
  11544. FROM ICSContainer a
  11545. INNER JOIN ICSContainer con ON con.ContainerID=a.ID
  11546. WHERE a.ContainerCode='{0}' AND a.WorkPoint='{1}'";
  11547. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  11548. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  11549. cmd.Transaction.Commit();
  11550. return table;
  11551. }
  11552. catch (Exception ex)
  11553. {
  11554. if (cmd.Transaction != null)
  11555. cmd.Transaction.Rollback();
  11556. log.Error(ex.Message);
  11557. throw new Exception(ex.Message);
  11558. }
  11559. finally
  11560. {
  11561. if (conn.State == ConnectionState.Open)
  11562. {
  11563. conn.Close();
  11564. }
  11565. conn.Dispose();
  11566. }
  11567. }
  11568. }
  11569. /// <summary>
  11570. /// 条码关联容器——查询容器关联的条码
  11571. /// </summary>
  11572. /// <param name="JsonData"></param>
  11573. /// <returns></returns>
  11574. public static DataTable ICSContainerLotGetCon(BarCodeModel JsonData)
  11575. {
  11576. var language = LanguageHelper.GetName("WMSAPIInfo");
  11577. if (JsonData == null)
  11578. {
  11579. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11580. }
  11581. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11582. {
  11583. conn.Open();
  11584. SqlTransaction sqlTran = conn.BeginTransaction();
  11585. SqlCommand cmd = new SqlCommand();
  11586. cmd.Transaction = sqlTran;
  11587. cmd.Connection = conn;
  11588. try
  11589. {
  11590. string sql = string.Empty;
  11591. string TransType = string.Empty;
  11592. string Identification = Guid.NewGuid().ToString();
  11593. sql = @"SELECT con.ContainerCode,con.ContainerName,con.ContainerType,inv.InvCode,inv.InvName,lot.LotNo,inv.InvStd,lot.Quantity,inv.InvUnit,
  11594. ext.ProjectCode,ext.BatchCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10
  11595. FROM ICSContainer con
  11596. INNER JOIN ICSContainerLot conlot ON conlot.ContainerID=con.ID
  11597. INNER JOIN ICSInventoryLot lot ON lot.LotNo=conLot.LotNo
  11598. INNER JOIN ICSInventory inv ON inv.InvCode=lot.InvCode
  11599. INNER JOIN ICSExtension ext ON ext.ID=lot.ExtensionID
  11600. WHERE con.ContainerCode='{0}' AND con.WorkPoint='{1}'";
  11601. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  11602. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  11603. cmd.Transaction.Commit();
  11604. return table;
  11605. }
  11606. catch (Exception ex)
  11607. {
  11608. if (cmd.Transaction != null)
  11609. cmd.Transaction.Rollback();
  11610. log.Error(ex.Message);
  11611. throw new Exception(ex.Message);
  11612. }
  11613. finally
  11614. {
  11615. if (conn.State == ConnectionState.Open)
  11616. {
  11617. conn.Close();
  11618. }
  11619. conn.Dispose();
  11620. }
  11621. }
  11622. }
  11623. /// <summary>
  11624. /// 条码关联容器--条码查询
  11625. /// </summary>
  11626. /// <param name="JsonData"></param>
  11627. /// <returns></returns>
  11628. public static DataTable ICSContainerLotCheck(BarCodeModel JsonData)
  11629. {
  11630. Boolean LotCheck = false;
  11631. var language = LanguageHelper.GetName("WMSAPIInfo");
  11632. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11633. {
  11634. conn.Open();
  11635. SqlTransaction sqlTran = conn.BeginTransaction();
  11636. SqlCommand cmd = new SqlCommand();
  11637. cmd.Transaction = sqlTran;
  11638. cmd.Connection = conn;
  11639. try
  11640. {
  11641. string sql = string.Empty;
  11642. string TransType = string.Empty;
  11643. string Identification = Guid.NewGuid().ToString();
  11644. sql = @"select lot.LotNo,lot.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,lot.Quantity,lot.ExtensionID,lot.Type
  11645. ,lot.EATTRIBUTE1 AS cFree1,lot.EATTRIBUTE2 AS cFree2,lot.EATTRIBUTE3 AS cFree3,lot.EATTRIBUTE4 AS cFree4
  11646. ,lot.EATTRIBUTE5 AS cFree5,lot.EATTRIBUTE6 AS cFree6,lot.EATTRIBUTE7 AS cFree7
  11647. ,lot.EATTRIBUTE8 AS cFree8,lot.EATTRIBUTE9 AS cFree9,lot.EATTRIBUTE10 AS cFree10
  11648. from ICSInventoryLot lot
  11649. INNER JOIN ICSInventory inv ON inv.InvCode=lot.InvCode AND inv.WorkPoint=lot.WorkPoint
  11650. where lot.LotNo='{0}' and lot.WorkPoint='{1}'";
  11651. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  11652. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  11653. cmd.Transaction.Commit();
  11654. return table;
  11655. }
  11656. catch (Exception ex)
  11657. {
  11658. if (cmd.Transaction != null)
  11659. cmd.Transaction.Rollback();
  11660. log.Error(ex.Message);
  11661. throw new Exception(ex.Message);
  11662. }
  11663. finally
  11664. {
  11665. if (conn.State == ConnectionState.Open)
  11666. {
  11667. conn.Close();
  11668. }
  11669. conn.Dispose();
  11670. }
  11671. }
  11672. }
  11673. /// <summary>
  11674. /// 容器绑定条码
  11675. /// </summary>
  11676. /// <param name="JsonData"></param>
  11677. /// <returns></returns>
  11678. public static string ICSContainerLot(List<ICSContainerLotModel> JsonData)
  11679. {
  11680. var language = LanguageHelper.GetName("WMSAPIInfo");
  11681. Boolean flag;
  11682. if (JsonData.Count <= 0)
  11683. {
  11684. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11685. }
  11686. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11687. {
  11688. conn.Open();
  11689. SqlTransaction sqlTran = conn.BeginTransaction();
  11690. SqlCommand cmd = new SqlCommand();
  11691. cmd.Transaction = sqlTran;
  11692. cmd.Connection = conn;
  11693. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11694. try
  11695. {
  11696. string sql = string.Empty;
  11697. string TransType = string.Empty;
  11698. string Identification = Guid.NewGuid().ToString();
  11699. foreach (var item in JsonData)
  11700. {
  11701. if (item.ifCreateContainer)
  11702. {
  11703. //string ContainerID = Guid.NewGuid().ToString();
  11704. // string ContainerCode = GetSerialCode(item.WorkPoint, "ICSContainer", "ContainerCode", "Container", 5, cmd);
  11705. // sql = @"IF EXISTS(SELECT 1 FROM ICSContainer WHERE ContainerCODE='{0}' AND WorkPoint='{1}')
  11706. // BEGIN
  11707. // RAISERROR('容器编号 " + ContainerCode + @" 已存在!请重新提交',16,1);
  11708. // RETURN;
  11709. // END
  11710. // INSERT INTO dbo.ICSContainer
  11711. // ( ID ,ContainerID ,ContainerCODE ,ContainerName,Memo,MTIME,MUSER ,MUSERName ,WorkPoint
  11712. // ,InventoryMixed,ProjectMixed,BatchMixed,Multiplex)
  11713. //Values('{3}','','{0}','{0}','',GETDATE(),'{2}','{2}','{1}','0','0','0','0')";
  11714. // sql = string.Format(sql, ContainerCode, item.WorkPoint, item.User, ContainerID);
  11715. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  11716. // {
  11717. // throw new Exception("生成箱号失败!");
  11718. // }
  11719. string ContainerID = Guid.NewGuid().ToString();
  11720. sql = @"IF EXISTS(SELECT 1 FROM ICSContainer WHERE ContainerCODE='{0}' AND WorkPoint='{1}')
  11721. BEGIN
  11722. RAISERROR(' {0} ',16,1);
  11723. RETURN;
  11724. END
  11725. INSERT INTO dbo.ICSContainer
  11726. ( ID ,ContainerID ,ContainerCODE ,ContainerName,Memo,MTIME,MUSER ,MUSERName ,WorkPoint
  11727. ,InventoryMixed,ProjectMixed,BatchMixed,Multiplex)
  11728. Values('{3}','','{0}','{4}','',GETDATE(),'{2}','{2}','{1}','1','1','1','1')";
  11729. sql = string.Format(sql, item.ContainerCode, item.WorkPoint, item.User, ContainerID, item.ContainerName);
  11730. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  11731. {
  11732. throw new Exception("生成箱号失败!");
  11733. }
  11734. foreach (var itemInfo in item.detail)
  11735. {
  11736. flag = ICSWareHouseService.ICSContainerLot(itemInfo.LotNo, item.ContainerCode, item.WorkPoint, Identification, item.User, itemInfo.ProjectCode,
  11737. itemInfo.BatchCode, itemInfo.Version, itemInfo.Brand, itemInfo.cFree1, itemInfo.cFree2, itemInfo.cFree3, itemInfo.cFree4, itemInfo.cFree5,
  11738. itemInfo.cFree6, itemInfo.cFree7, itemInfo.cFree8, itemInfo.cFree9, itemInfo.cFree10, TransTypeEnum.ICSMOReceive.GetDescription<DBValue>(), cmd, language);
  11739. if (!flag)
  11740. {
  11741. log.Error("容器绑定条码失败");
  11742. throw new Exception("容器 " + item.ContainerCode + " 绑定条码 " + itemInfo.LotNo + " 失败");
  11743. }
  11744. }
  11745. }
  11746. else
  11747. {
  11748. foreach (var itemInfo in item.detail)
  11749. {
  11750. flag = ICSWareHouseService.ICSContainerLot(itemInfo.LotNo, item.ContainerCode, item.WorkPoint, Identification, item.User, itemInfo.ProjectCode,
  11751. itemInfo.BatchCode, itemInfo.Version, itemInfo.Brand, itemInfo.cFree1, itemInfo.cFree2, itemInfo.cFree3, itemInfo.cFree4, itemInfo.cFree5,
  11752. itemInfo.cFree6, itemInfo.cFree7, itemInfo.cFree8, itemInfo.cFree9, itemInfo.cFree10, TransTypeEnum.ICSMOReceive.GetDescription<DBValue>(), cmd, language);
  11753. if (!flag)
  11754. {
  11755. log.Error("容器绑定条码失败");
  11756. throw new Exception("容器 " + item.ContainerCode + " 绑定条码 " + itemInfo.LotNo + " 失败");
  11757. }
  11758. }
  11759. }
  11760. }
  11761. cmd.Transaction.Commit();
  11762. return LanguageHelper.GetNameSingle("WMSAPI001");// "接口调用成功!";
  11763. }
  11764. catch (Exception ex)
  11765. {
  11766. if (cmd.Transaction != null)
  11767. cmd.Transaction.Rollback();
  11768. log.Error(ex.Message);
  11769. throw new Exception(ex.Message);
  11770. }
  11771. finally
  11772. {
  11773. if (conn.State == ConnectionState.Open)
  11774. {
  11775. conn.Close();
  11776. }
  11777. conn.Dispose();
  11778. }
  11779. }
  11780. }
  11781. public static string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen, SqlCommand cmd)
  11782. {
  11783. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  11784. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  11785. return DBHelper.ExecuteScalar(sql, cmd).ToString();
  11786. }
  11787. public static string ICSGetSerialCode(BarCodeModel JsonData)
  11788. {
  11789. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11790. {
  11791. conn.Open();
  11792. SqlTransaction sqlTran = conn.BeginTransaction();
  11793. SqlCommand cmd = new SqlCommand();
  11794. cmd.Transaction = sqlTran;
  11795. cmd.Connection = conn;
  11796. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11797. try
  11798. {
  11799. string ContainerCode = GetSerialCode(JsonData.WorkPoint, "ICSContainer", "ContainerCode", "PKG" + DateTime.Today.ToString("yyyyMMdd"), 5, cmd);
  11800. cmd.Transaction.Commit();
  11801. return ContainerCode;
  11802. }
  11803. catch (Exception ex)
  11804. {
  11805. if (cmd.Transaction != null)
  11806. cmd.Transaction.Rollback();
  11807. log.Error(ex.Message);
  11808. throw new Exception(ex.Message);
  11809. }
  11810. finally
  11811. {
  11812. if (conn.State == ConnectionState.Open)
  11813. {
  11814. conn.Close();
  11815. }
  11816. conn.Dispose();
  11817. }
  11818. }
  11819. }
  11820. /// <summary>
  11821. /// 容器与条码解绑
  11822. /// </summary>
  11823. /// <param name="JsonData"></param>
  11824. /// <returns></returns>
  11825. public static bool ICSContainerLotUntie(ICSMOReceiveUntieModel JsonData)
  11826. {
  11827. Boolean flag = false;
  11828. var language = LanguageHelper.GetName("WMSAPIInfo");
  11829. if (JsonData == null)
  11830. {
  11831. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11832. }
  11833. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11834. {
  11835. conn.Open();
  11836. SqlTransaction sqlTran = conn.BeginTransaction();
  11837. SqlCommand cmd = new SqlCommand();
  11838. cmd.Transaction = sqlTran;
  11839. cmd.Connection = conn;
  11840. try
  11841. {
  11842. string sql = string.Empty;
  11843. string TransType = string.Empty;
  11844. string Identification = Guid.NewGuid().ToString();
  11845. string MergeID = "";
  11846. foreach (var item in JsonData.detail)
  11847. {
  11848. flag = ICSWareHouseService.ICSContainerLotUntie(JsonData.ContainerCode, item.LotNo, JsonData.WorkPoint, JsonData.User, JsonData.Type, cmd, language);
  11849. }
  11850. cmd.Transaction.Commit();
  11851. return flag;
  11852. }
  11853. catch (Exception ex)
  11854. {
  11855. if (cmd.Transaction != null)
  11856. cmd.Transaction.Rollback();
  11857. log.Error(ex.Message);
  11858. throw new Exception(ex.Message);
  11859. }
  11860. finally
  11861. {
  11862. if (conn.State == ConnectionState.Open)
  11863. {
  11864. conn.Close();
  11865. }
  11866. conn.Dispose();
  11867. }
  11868. }
  11869. }
  11870. /// <summary>
  11871. /// 容器绑定父容器
  11872. /// </summary>
  11873. /// <param name="JsonData"></param>
  11874. /// <returns></returns>
  11875. public static string ICSContainerCon(List<ICSContainerConModel> JsonData)
  11876. {
  11877. var language = LanguageHelper.GetName("WMSAPIInfo");
  11878. Boolean flag;
  11879. if (JsonData.Count <= 0)
  11880. {
  11881. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11882. }
  11883. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11884. {
  11885. conn.Open();
  11886. SqlTransaction sqlTran = conn.BeginTransaction();
  11887. SqlCommand cmd = new SqlCommand();
  11888. cmd.Transaction = sqlTran;
  11889. cmd.Connection = conn;
  11890. try
  11891. {
  11892. string sql = string.Empty;
  11893. string TransType = string.Empty;
  11894. string Identification = Guid.NewGuid().ToString();
  11895. foreach (var item in JsonData)
  11896. {
  11897. string MergeID = "";
  11898. foreach (var itemInfo in item.detail)
  11899. {
  11900. flag = ICSWareHouseService.ICSContainerCon(item.ContainerCode, itemInfo.ContainerCode, item.WorkPoint, item.User, item.MTime, item.Type, cmd, language);
  11901. if (!flag)
  11902. {
  11903. log.Error("容器绑定条码失败");
  11904. throw new Exception("容器 " + itemInfo.ContainerCode + " 绑定父容器 " + item.ContainerCode + " 失败");
  11905. }
  11906. }
  11907. }
  11908. cmd.Transaction.Commit();
  11909. return LanguageHelper.GetNameSingle("WMSAPI001");// "接口调用成功!";
  11910. }
  11911. catch (Exception ex)
  11912. {
  11913. if (cmd.Transaction != null)
  11914. cmd.Transaction.Rollback();
  11915. log.Error(ex.Message);
  11916. throw new Exception(ex.Message);
  11917. }
  11918. finally
  11919. {
  11920. if (conn.State == ConnectionState.Open)
  11921. {
  11922. conn.Close();
  11923. }
  11924. conn.Dispose();
  11925. }
  11926. }
  11927. }
  11928. /// <summary>
  11929. /// 容器解绑父容器
  11930. /// </summary>
  11931. /// <param name="JsonData"></param>
  11932. /// <returns></returns>
  11933. public static bool ICSContainerConUntie(ICSMOReceiveUntieModel JsonData)
  11934. {
  11935. Boolean flag = false;
  11936. var language = LanguageHelper.GetName("WMSAPIInfo");
  11937. if (JsonData == null)
  11938. {
  11939. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11940. }
  11941. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11942. {
  11943. conn.Open();
  11944. SqlTransaction sqlTran = conn.BeginTransaction();
  11945. SqlCommand cmd = new SqlCommand();
  11946. cmd.Transaction = sqlTran;
  11947. cmd.Connection = conn;
  11948. try
  11949. {
  11950. string sql = string.Empty;
  11951. string TransType = string.Empty;
  11952. string Identification = Guid.NewGuid().ToString();
  11953. string MergeID = "";
  11954. flag = ICSWareHouseService.ICSContainerConUntie(JsonData.ContainerCode, JsonData.WorkPoint, JsonData.User, JsonData.Type, cmd, language);
  11955. cmd.Transaction.Commit();
  11956. return flag;
  11957. }
  11958. catch (Exception ex)
  11959. {
  11960. if (cmd.Transaction != null)
  11961. cmd.Transaction.Rollback();
  11962. log.Error(ex.Message);
  11963. throw new Exception(ex.Message);
  11964. }
  11965. finally
  11966. {
  11967. if (conn.State == ConnectionState.Open)
  11968. {
  11969. conn.Close();
  11970. }
  11971. conn.Dispose();
  11972. }
  11973. }
  11974. }
  11975. #endregion
  11976. #region 车次
  11977. public static DataTable ICSCartBarCodeGet(BarCodeModel JsonData)
  11978. {
  11979. Boolean LotCheck = false;
  11980. var language = LanguageHelper.GetName("WMSAPIInfo");
  11981. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11982. {
  11983. conn.Open();
  11984. SqlTransaction sqlTran = conn.BeginTransaction();
  11985. SqlCommand cmd = new SqlCommand();
  11986. cmd.Transaction = sqlTran;
  11987. cmd.Connection = conn;
  11988. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11989. try
  11990. {
  11991. string sql = string.Empty;
  11992. string TransType = string.Empty;
  11993. string Identification = Guid.NewGuid().ToString();
  11994. sql = @"IF EXISTS (SELECT *
  11995. FROM ICSCartLotNoCheckList list
  11996. WHERE list.CartNo='{0}' AND list.LotNo='{1}'
  11997. )
  11998. BEGIN
  11999. RAISERROR('"+ language.GetNameByCode("WMSAPIInfo476") + @"',16,1)
  12000. RETURN
  12001. END
  12002. ELSE IF NOT EXISTS(
  12003. SELECT 1 FROM ICSInventoryLot lot WHERE lot.LotNo='{1}'
  12004. )
  12005. BEGIN
  12006. RAISERROR('" + language.GetNameByCode("WMSAPIInfo477") + @"',16,1)
  12007. END
  12008. ELSE IF NOT EXISTS(
  12009. SELECT 1 FROM ICSWareHouseLotInfo info WHERE info.LotNo='{1}' AND info.Quantity>0
  12010. )
  12011. BEGIN
  12012. RAISERROR('" + language.GetNameByCode("WMSAPIInfo479") +@"',16,1)
  12013. END
  12014. ELSE
  12015. BEGIN
  12016. SELECT lot.LotNo,lot.InvCode,info.Quantity,lot.ExtensionID,lot.Type,ext.cFree1 AS cFree1,ext.cFree2 AS cFree2,ext.cFree3 AS cFree3,ext.cFree4 AS cFree4,ext.cFree5 AS cFree5,ext.cFree6 AS cFree6,ext.cFree7 AS cFree7,ext.cFree8 AS cFree8,ext.cFree9 AS cFree9,ext.cFree10 AS cFree10
  12017. FROM ICSInventoryLot lot
  12018. LEFT JOIN ICSExtension ext ON ext.ID=lot.ExtensionID
  12019. LEFT JOIN ICSWareHouseLotInfo info ON info.LotNo=lot.LotNo
  12020. WHERE lot.LotNo='{1}'
  12021. END";
  12022. sql = string.Format(sql, JsonData.TransCode, JsonData.Code);
  12023. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  12024. cmd.Transaction.Commit();
  12025. return table;
  12026. }
  12027. catch (Exception ex)
  12028. {
  12029. if (cmd.Transaction != null)
  12030. cmd.Transaction.Rollback();
  12031. log.Error(ex.Message);
  12032. throw new Exception(ex.Message);
  12033. }
  12034. finally
  12035. {
  12036. if (conn.State == ConnectionState.Open)
  12037. {
  12038. conn.Close();
  12039. }
  12040. conn.Dispose();
  12041. }
  12042. }
  12043. }
  12044. public static string ICSCartScheduleCreate(List<CartScheduleModel> JsonData)
  12045. {
  12046. var language = LanguageHelper.GetName("WMSAPIInfo");
  12047. Boolean flag;
  12048. if (JsonData.Count <= 0)
  12049. {
  12050. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  12051. }
  12052. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  12053. {
  12054. conn.Open();
  12055. SqlTransaction sqlTran = conn.BeginTransaction();
  12056. SqlCommand cmd = new SqlCommand();
  12057. cmd.Transaction = sqlTran;
  12058. cmd.Connection = conn;
  12059. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  12060. try
  12061. {
  12062. string sql = string.Empty;
  12063. string TransType = string.Empty;
  12064. string Identification = Guid.NewGuid().ToString();
  12065. foreach (var item in JsonData)
  12066. {
  12067. string MergeID = "";
  12068. foreach (var itemInfo in item.detail)
  12069. {
  12070. flag = ICSWareHouseService.ICSCartScheduleCreate(itemInfo.LotNo,itemInfo.Quantity, item.CartNo, item.User, item.WorkPoint, cmd, language);
  12071. if (!flag)
  12072. {
  12073. log.Error("生成车次条码清单失败");
  12074. throw new Exception("车次 " + item.CartNo + " 与条码 " + itemInfo.LotNo + " 生成清单失败");
  12075. }
  12076. }
  12077. }
  12078. cmd.Transaction.Commit();
  12079. return LanguageHelper.GetNameSingle("WMSAPI001");// "接口调用成功!";
  12080. }
  12081. catch (Exception ex)
  12082. {
  12083. if (cmd.Transaction != null)
  12084. cmd.Transaction.Rollback();
  12085. log.Error(ex.Message);
  12086. throw new Exception(ex.Message);
  12087. }
  12088. finally
  12089. {
  12090. if (conn.State == ConnectionState.Open)
  12091. {
  12092. conn.Close();
  12093. }
  12094. conn.Dispose();
  12095. }
  12096. }
  12097. }
  12098. #endregion
  12099. #region 移库
  12100. /// <summary>
  12101. /// 移库
  12102. /// </summary>
  12103. /// <param name="JsonData"></param>
  12104. /// <returns></returns>
  12105. public static DataTable LibraryUpdate(List<ICSLibraryModel> JsonData)
  12106. {
  12107. var language = LanguageHelper.GetName("WMSAPIInfo");
  12108. if (JsonData.Count <= 0)
  12109. {
  12110. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  12111. }
  12112. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  12113. {
  12114. conn.Open();
  12115. SqlTransaction sqlTran = conn.BeginTransaction();
  12116. SqlCommand cmd = new SqlCommand();
  12117. cmd.Transaction = sqlTran;
  12118. cmd.Connection = conn;
  12119. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  12120. try
  12121. {
  12122. string sql = string.Empty;
  12123. string Identification = Guid.NewGuid().ToString();
  12124. foreach (var item in JsonData)
  12125. {
  12126. if (string.IsNullOrEmpty(item.LotNo))
  12127. {
  12128. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  12129. }
  12130. //验证仓库库位信息
  12131. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  12132. BEGIN
  12133. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  12134. RETURN
  12135. END
  12136. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  12137. BEGIN
  12138. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  12139. RETURN
  12140. END
  12141. IF NOT EXISTS(SELECT a.ID
  12142. FROM ICSWareHouse a
  12143. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  12144. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  12145. BEGIN
  12146. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  12147. RETURN
  12148. END";
  12149. sql = string.Format(sql, item.WarehouseCode, item.WorkPoint, item.LocationCode);
  12150. DBHelper.ExecuteNonQuery(sql, cmd);
  12151. //更新条码信息
  12152. ICSWareHouseLotInfoService.WareHouseLotInfoLibrary(Identification, item.TransCode, item.TransSequence, item.WarehouseCode, item.LocationCode, item.LotNo,
  12153. item.User, item.WorkPoint, "7", "29", cmd, language);
  12154. }
  12155. DataTable table = GetData(Identification, 3, cmd);
  12156. cmd.Transaction.Commit();
  12157. return table;
  12158. }
  12159. catch (Exception ex)
  12160. {
  12161. if (cmd.Transaction != null)
  12162. cmd.Transaction.Rollback();
  12163. log.Error(ex.Message);
  12164. throw new Exception(ex.Message);
  12165. }
  12166. finally
  12167. {
  12168. if (conn.State == ConnectionState.Open)
  12169. {
  12170. conn.Close();
  12171. }
  12172. conn.Dispose();
  12173. }
  12174. }
  12175. }
  12176. #endregion
  12177. #region 合并
  12178. /// <summary>
  12179. /// 合并
  12180. /// </summary>
  12181. /// <param name="JsonData"></param>
  12182. /// <returns></returns>
  12183. public static DataTable LOTMergeCreate(List<LOTCreateIModel> JsonData)
  12184. {
  12185. var language = LanguageHelper.GetName("WMSAPIInfo");
  12186. DataTable printTable = new DataTable();
  12187. if (JsonData.Count <= 0)
  12188. {
  12189. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  12190. }
  12191. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  12192. {
  12193. conn.Open();
  12194. SqlTransaction sqlTran = conn.BeginTransaction();
  12195. SqlCommand cmd = new SqlCommand();
  12196. cmd.Transaction = sqlTran;
  12197. cmd.Connection = conn;
  12198. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  12199. try
  12200. {
  12201. string Identification = Guid.NewGuid().ToString();
  12202. foreach (var item in JsonData)
  12203. {
  12204. if (string.IsNullOrEmpty(item.LotNo))
  12205. {
  12206. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  12207. }
  12208. else if (item.detail.Count <= 0)
  12209. {
  12210. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  12211. }
  12212. //合并前日志
  12213. ICSWareHouseLotInfoService.WareHouseLotInfoLogMerge(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  12214. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(),"", cmd, language);
  12215. foreach (var info in item.detail)
  12216. {
  12217. //合并前日志
  12218. ICSWareHouseLotInfoService.WareHouseLotInfoLogMerge(Identification, info.CurrentLotNo, item.User, item.WorkPoint, "5",
  12219. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(),"", cmd, language);
  12220. //更新条码信息
  12221. ICSWareHouseLotInfoService.WareHouseLotInfoMerge(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "5",
  12222. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  12223. }
  12224. //合并后日志
  12225. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoLogMerge(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  12226. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(),"", cmd, language);
  12227. }
  12228. if (!printTable.Equals("{}"))
  12229. {
  12230. cmd.Transaction.Commit();
  12231. return printTable;
  12232. }
  12233. else
  12234. {
  12235. DataTable table = GetData(Identification, 1, cmd);
  12236. cmd.Transaction.Commit();
  12237. return table;
  12238. }
  12239. }
  12240. catch (Exception ex)
  12241. {
  12242. if (cmd.Transaction != null)
  12243. cmd.Transaction.Rollback();
  12244. log.Error(ex.Message);
  12245. throw new Exception(ex.Message);
  12246. }
  12247. finally
  12248. {
  12249. if (conn.State == ConnectionState.Open)
  12250. {
  12251. conn.Close();
  12252. }
  12253. conn.Dispose();
  12254. }
  12255. }
  12256. }
  12257. #endregion
  12258. #region 拆分
  12259. /// <summary>
  12260. /// 拆分
  12261. /// </summary>
  12262. /// <param name="JsonData"></param>
  12263. /// <returns></returns>
  12264. public static DataTable LOTSplitCreate(List<LOTCreateIModel> JsonData)
  12265. {
  12266. var language = LanguageHelper.GetName("WMSAPIInfo");
  12267. string newlotno = "";
  12268. DataTable printTable = new DataTable();
  12269. if (JsonData.Count <= 0)
  12270. {
  12271. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  12272. }
  12273. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  12274. {
  12275. conn.Open();
  12276. SqlTransaction sqlTran = conn.BeginTransaction();
  12277. SqlCommand cmd = new SqlCommand();
  12278. cmd.Transaction = sqlTran;
  12279. cmd.Connection = conn;
  12280. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  12281. try
  12282. {
  12283. string Identification = Guid.NewGuid().ToString();
  12284. foreach (var item in JsonData)
  12285. {
  12286. if (string.IsNullOrEmpty(item.LotNo))
  12287. {
  12288. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  12289. }
  12290. else if (item.detail.Count <= 0)
  12291. {
  12292. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  12293. }
  12294. //拆分前日志
  12295. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  12296. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(),"", cmd, language);
  12297. foreach (var info in item.detail)
  12298. {
  12299. newlotno = info.CurrentLotNo;
  12300. //更新条码信息
  12301. ICSWareHouseLotInfoService.WareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  12302. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  12303. }
  12304. //拆分后日志
  12305. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  12306. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), newlotno, cmd, language);
  12307. }
  12308. //DataTable table = GetData(Identification, 1, cmd);
  12309. //cmd.Transaction.Commit();
  12310. //return table;
  12311. if (!printTable.Equals("{}"))
  12312. {
  12313. cmd.Transaction.Commit();
  12314. return printTable;
  12315. }
  12316. else
  12317. {
  12318. DataTable table = GetData(Identification, 1, cmd);
  12319. cmd.Transaction.Commit();
  12320. return table;
  12321. }
  12322. }
  12323. catch (Exception ex)
  12324. {
  12325. if (cmd.Transaction != null)
  12326. cmd.Transaction.Rollback();
  12327. log.Error(ex.Message);
  12328. throw new Exception(ex.Message);
  12329. }
  12330. finally
  12331. {
  12332. if (conn.State == ConnectionState.Open)
  12333. {
  12334. conn.Close();
  12335. }
  12336. conn.Dispose();
  12337. }
  12338. }
  12339. }
  12340. /// <summary>
  12341. /// 拆分(奥美)
  12342. /// </summary>
  12343. /// <param name="JsonData"></param>
  12344. /// <returns></returns>
  12345. public static DataTable AMLOTSplitCreate(List<LOTCreateIModel> JsonData)
  12346. {
  12347. var language = LanguageHelper.GetName("WMSAPIInfo");
  12348. string newlotno = "";
  12349. DataTable printTable = new DataTable();
  12350. if (JsonData.Count <= 0)
  12351. {
  12352. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  12353. }
  12354. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  12355. {
  12356. conn.Open();
  12357. SqlTransaction sqlTran = conn.BeginTransaction();
  12358. SqlCommand cmd = new SqlCommand();
  12359. cmd.Transaction = sqlTran;
  12360. cmd.Connection = conn;
  12361. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  12362. try
  12363. {
  12364. string Identification = Guid.NewGuid().ToString();
  12365. foreach (var item in JsonData)
  12366. {
  12367. if (string.IsNullOrEmpty(item.LotNo))
  12368. {
  12369. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  12370. }
  12371. else if (item.detail.Count <= 0)
  12372. {
  12373. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  12374. }
  12375. //拆分前日志
  12376. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  12377. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(), "", cmd, language);
  12378. foreach (var info in item.detail)
  12379. {
  12380. newlotno = info.CurrentLotNo;
  12381. //更新条码信息
  12382. ICSWareHouseLotInfoService.AMWareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  12383. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  12384. }
  12385. //拆分后日志
  12386. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  12387. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), newlotno, cmd, language);
  12388. }
  12389. //DataTable table = GetData(Identification, 1, cmd);
  12390. //cmd.Transaction.Commit();
  12391. //return table;
  12392. if (!printTable.Equals("{}"))
  12393. {
  12394. cmd.Transaction.Commit();
  12395. return printTable;
  12396. }
  12397. else
  12398. {
  12399. DataTable table = GetData(Identification, 1, cmd);
  12400. cmd.Transaction.Commit();
  12401. return table;
  12402. }
  12403. }
  12404. catch (Exception ex)
  12405. {
  12406. if (cmd.Transaction != null)
  12407. cmd.Transaction.Rollback();
  12408. log.Error(ex.Message);
  12409. throw new Exception(ex.Message);
  12410. }
  12411. finally
  12412. {
  12413. if (conn.State == ConnectionState.Open)
  12414. {
  12415. conn.Close();
  12416. }
  12417. conn.Dispose();
  12418. }
  12419. }
  12420. }
  12421. #endregion
  12422. /// <summary>
  12423. /// 获取出入库记录信息
  12424. /// </summary>
  12425. /// <param name="Identification"></param>
  12426. /// <param name="type">1:入库,2:出库,3:调拨</param>
  12427. /// <param name="cmd"></param>
  12428. /// <returns></returns>
  12429. private static DataTable GetData(string Identification, int type, SqlCommand cmd)
  12430. {
  12431. #region SLQ
  12432. string sql = @"SELECT log.ID,
  12433. log.TransCode,
  12434. log.TransSequence,
  12435. log.LotNo,
  12436. log.InvCode,
  12437. inv.InvName,
  12438. inv.InvStd,
  12439. log.Quantity,
  12440. inv.InvUnit,
  12441. log.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  12442. inv.AmountUnit,
  12443. {1}
  12444. ext.ProjectCode,
  12445. 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,
  12446. ext.Version,
  12447. ext.Brand,
  12448. ext.cFree1,
  12449. ext.cFree2,
  12450. ext.cFree3,
  12451. ext.cFree4,
  12452. ext.cFree5,
  12453. ext.cFree6,
  12454. ext.cFree7,
  12455. ext.cFree8,
  12456. ext.cFree9,
  12457. ext.cFree10,
  12458. type.Name AS TransType,
  12459. log.MUSER AS [User],
  12460. log.MTIME AS [MTime]
  12461. FROM ICSWareHouseLotInfoLog log
  12462. LEFT JOIN ICSType type ON type.TableCode='ICSWareHouseLotInfoLog' AND type.ColumnCode='BusinessCode' AND log.BusinessCode=type.Code AND log.WorkPoint=type.WorkPoint
  12463. INNER JOIN ICSInventoryLot lot ON log.LotNo=lot.LotNo AND log.WorkPoint=lot.WorkPoint
  12464. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  12465. INNER JOIN ICSInventory inv ON log.InvCode=inv.InvCode AND log.WorkPoint=inv.WorkPoint
  12466. {2}
  12467. LEFT JOIN ICSInventoryBatchEnable invBat ON log.InvCode=invBat.InvCode AND log.FromWarehouseCode=invBat.WHCode AND log.WorkPoint=invBat.WorkPoint
  12468. WHERE log.Identification='{0}'";
  12469. #endregion
  12470. string columns = @"log.ToWarehouseCode AS WHCode,
  12471. log.ToLocationCode AS LocationCode,
  12472. wh.WarehouseName AS WHName,
  12473. loc.LocationName AS LocationName,";
  12474. string tables = @"INNER JOIN ICSWarehouse wh ON log.ToWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  12475. INNER JOIN ICSLocation loc ON log.ToLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  12476. if (type == 2)//出库
  12477. {
  12478. columns = @"log.FromWarehouseCode AS WHCode,
  12479. log.FromLocationCode AS LocationCode,
  12480. wh.WarehouseName AS WHName,
  12481. loc.LocationName AS LocationName,";
  12482. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  12483. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  12484. }
  12485. else if (type == 3)//调拨
  12486. {
  12487. columns = @"log.FromWarehouseCode AS FromWHCode,
  12488. log.FromLocationCode,
  12489. wh.WarehouseName AS FromWHName,
  12490. loc.LocationName AS FromLocationName,
  12491. log.ToWarehouseCode AS ToWHCode,
  12492. log.ToLocationCode,
  12493. whto.WarehouseName AS ToWHName,
  12494. locto.LocationName AS ToLocationName,";
  12495. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  12496. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint
  12497. INNER JOIN ICSWarehouse whto ON log.ToWarehouseCode=whto.WarehouseCode AND log.WorkPoint=whto.WorkPoint
  12498. INNER JOIN ICSLocation locto ON log.ToLocationCode=locto.LocationCode AND log.WorkPoint=locto.WorkPoint";
  12499. }
  12500. sql = string.Format(sql, Identification, columns, tables);
  12501. return DBHelper.SQlReturnData(sql, cmd);
  12502. }
  12503. /// <summary>
  12504. /// 先进先出批次管控
  12505. /// </summary>
  12506. /// <param name="LotNo"></param>
  12507. /// <param name="WorkPoitCode"></param>
  12508. /// <param name="cmd"></param>
  12509. /// <returns></returns>
  12510. public static string CanOut(string LotNo, string WorkPoitCode, string ScanLotCode, string sqlnew,string TransType, SqlCommand cmd, Dictionary<string, string> language)
  12511. {
  12512. try
  12513. {
  12514. string sql = "";
  12515. string tsql = @"SELECT Top 1 a.F_ItemName
  12516. FROM Sys_SRM_ItemsDetail a
  12517. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  12518. WHERE b.F_EnCode='MtimeControl' AND a.F_EnabledMark='1'
  12519. ORDER BY a.F_SortCode DESC";
  12520. tsql = string.Format(tsql);
  12521. DataTable dttt = DBHelper.SQlReturnData(tsql, cmd);
  12522. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  12523. if (DBHelper.IsPNU9()&& (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription() || TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription()))
  12524. {
  12525. sql = @"DECLARE @CountNO INT,@Days INT
  12526. SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
  12527. --
  12528. SELECT WarehouseCode INTO #TEMPWareHouse FROM ICSWareHouse
  12529. where WarehouseCode NOT IN
  12530. (select B.F_Define1 from Sys_SRM_Items A
  12531. INNER JOIN Sys_SRM_ItemsDetail B ON B.F_ItemId=A.F_Id
  12532. WHERE A.F_EnCode='FIFO_Wareouse')
  12533. and WorkPoint='{1}'
  12534. SET @CountNO=(
  12535. SELECT COUNT(a.LotNO) FROM ICSWareHouseLotInfo a
  12536. INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO AND a.WorkPoint=b.WorkPoint
  12537. INNER JOIN ICSExtension bext on b.ExtensionID=bext.id AND b.WorkPoint=bext.WorkPoint
  12538. WHERE ISNULL(a.Quantity,0)>0 AND 1=1
  12539. AND CONVERT(varchar(100), {2}, 23)<
  12540. (SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), {3}, 23)) FROM ICSWareHouseLotInfo x
  12541. INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
  12542. INNER JOIN ICSExtension yext on y.ExtensionID=yext.id AND b.WorkPoint=yext.WorkPoint
  12543. WHERE x.warehousecode in (select WarehouseCode from #TEMPWareHouse) and x.LotNO='{0}' AND y.INVCode=b.INVCode " + sqlnew + @")
  12544. )
  12545. IF @CountNO>0
  12546. BEGIN
  12547. SELECT TOP 1 CASE a.F_ItemCode WHEN 'FIFO01' THEN '1' WHEN 'FIFO02' THEN '2' ELSE '3' END AS Type
  12548. FROM Sys_SRM_ItemsDetail a
  12549. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  12550. WHERE b.F_EnCode='FIFO' AND a.F_EnabledMark='1'
  12551. ORDER BY a.F_SortCode DESC
  12552. END
  12553. ELSE
  12554. BEGIN
  12555. SELECT @CountNO
  12556. END
  12557. drop table #TEMPWareHouse
  12558. ";
  12559. }
  12560. else
  12561. {
  12562. sql = @"DECLARE @CountNO INT,@Days INT
  12563. SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
  12564. --
  12565. SELECT WarehouseCode INTO #TEMPWareHouse FROM ICSWareHouse
  12566. where WarehouseCode NOT IN
  12567. (select B.F_Define1 from Sys_SRM_Items A
  12568. INNER JOIN Sys_SRM_ItemsDetail B ON B.F_ItemId=A.F_Id
  12569. WHERE A.F_EnCode='FIFO_Wareouse')
  12570. and WorkPoint='{1}'
  12571. SET @CountNO=(
  12572. SELECT COUNT(a.LotNO) FROM ICSWareHouseLotInfo a
  12573. INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO AND a.WorkPoint=b.WorkPoint
  12574. INNER JOIN ICSExtension bext on b.ExtensionID=bext.id AND b.WorkPoint=bext.WorkPoint
  12575. WHERE a.WorkPoint='{1}' AND ISNULL(a.Quantity,0)>0 AND 1=1
  12576. AND CONVERT(varchar(100), {2}, 23)<
  12577. (SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), {3}, 23)) FROM ICSWareHouseLotInfo x
  12578. INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
  12579. INNER JOIN ICSExtension yext on y.ExtensionID=yext.id AND b.WorkPoint=yext.WorkPoint
  12580. WHERE x.warehousecode in (select WarehouseCode from #TEMPWareHouse) and x.LotNO='{0}' AND x.WorkPoint='{1}' AND y.INVCode=b.INVCode " + sqlnew + @")
  12581. )
  12582. IF @CountNO>0
  12583. BEGIN
  12584. SELECT TOP 1 CASE a.F_ItemCode WHEN 'FIFO01' THEN '1' WHEN 'FIFO02' THEN '2' ELSE '3' END AS Type
  12585. FROM Sys_SRM_ItemsDetail a
  12586. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  12587. WHERE b.F_EnCode='FIFO' AND a.F_EnabledMark='1'
  12588. ORDER BY a.F_SortCode DESC
  12589. END
  12590. ELSE
  12591. BEGIN
  12592. SELECT @CountNO
  12593. END
  12594. drop table #TEMPWareHouse
  12595. ";
  12596. }
  12597. //0 - 已经是最早的批次
  12598. //1 - 不管控
  12599. //2 - 提醒
  12600. //3 - 限制
  12601. if (dttt.Rows[0]["F_ItemName"].ToString() == "失效日期")
  12602. {
  12603. sql = string.Format(sql, LotNo, WorkPoitCode, "ISNULL(b.ExpirationDate,b.ProductDate)", "ISNULL(y.ExpirationDate,y.ProductDate)");
  12604. }
  12605. else if (dttt.Rows[0]["F_ItemName"].ToString() == "生产日期")
  12606. {
  12607. sql = string.Format(sql, LotNo, WorkPoitCode, "b.ProductDate", "y.ProductDate");
  12608. }
  12609. else
  12610. {
  12611. sql = string.Format(sql, LotNo, WorkPoitCode, "a.InDate", "x.InDate");
  12612. }
  12613. if (!string.IsNullOrWhiteSpace(ScanLotCode))
  12614. {
  12615. sql = sql.Replace("1=1", "a.LotNO NOT IN (" + ScanLotCode + ")");
  12616. }
  12617. log.Debug("先进先出sql:"+sql);
  12618. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  12619. if (string.IsNullOrWhiteSpace(res))
  12620. {
  12621. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  12622. }
  12623. else
  12624. return res;
  12625. }
  12626. catch (Exception ex)
  12627. {
  12628. throw new Exception(ex.Message);
  12629. }
  12630. }
  12631. /// <summary>
  12632. /// 获取自由项名称
  12633. /// </summary>
  12634. /// <param name="LotNo"></param>
  12635. /// <param name="WorkPoitCode"></param>
  12636. /// <param name="cmd"></param>
  12637. /// <returns></returns>
  12638. public static string GetExtentionName(string Code, string WorkPoitCode, SqlCommand cmd, Dictionary<string, string> language)
  12639. {
  12640. try
  12641. {
  12642. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  12643. string sql = @"select ColName from ICSExtensionEnable where ColCode='{0}' and WorkPoint='{1}'";
  12644. sql = string.Format(sql, Code, WorkPoitCode);
  12645. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  12646. return res;
  12647. }
  12648. catch (Exception ex)
  12649. {
  12650. throw new Exception(ex.Message);
  12651. }
  12652. }
  12653. /// <summary>
  12654. /// 保质期管控
  12655. /// </summary>
  12656. /// <param name="LotNo"></param>
  12657. /// <param name="WorkPoitCode"></param>
  12658. /// <param name="cmd"></param>
  12659. /// <returns></returns>
  12660. public static string Effective(string LotNo, string WorkPoitCode, string TransType, SqlCommand cmd, Dictionary<string, string> language)
  12661. {
  12662. try
  12663. {
  12664. string sql = "";
  12665. if (DBHelper.IsPNU9() && (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription()|| TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription()))
  12666. {
  12667. sql = @"DECLARE @CountNO INT,@Days INT,@CurrentDays INT
  12668. SELECT @CountNO=EffectiveEnable,@Days=EffectiveDays,@CurrentDays=DATEDIFF(DAY, GETDATE(), b.ExpirationDate) FROM ICSInventory a
  12669. INNER JOIN ICSInventoryLot b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  12670. INNER JOIN ICSWareHouseLotInfo c ON b.LotNO=c.LotNO AND b.WorkPoint=c.WorkPoint
  12671. WHERE b.LotNO='{0}'
  12672. IF @CountNO='1' AND @CurrentDays<0
  12673. BEGIN
  12674. SELECT TOP 1 CASE a.F_ItemCode WHEN 'Effective01' THEN '1' WHEN 'Effective02' THEN '2' ELSE '3' END AS Type
  12675. FROM Sys_SRM_ItemsDetail a
  12676. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  12677. WHERE b.F_EnCode='Effective' AND a.F_EnabledMark='1'
  12678. ORDER BY a.F_SortCode DESC
  12679. END
  12680. ELSE
  12681. BEGIN
  12682. SELECT @CountNO
  12683. END";
  12684. }
  12685. else
  12686. {
  12687. sql = @"DECLARE @CountNO INT,@Days INT,@CurrentDays INT
  12688. SELECT @CountNO=EffectiveEnable,@Days=EffectiveDays,@CurrentDays=DATEDIFF(DAY, GETDATE(), b.ExpirationDate) FROM ICSInventory a
  12689. INNER JOIN ICSInventoryLot b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  12690. INNER JOIN ICSWareHouseLotInfo c ON b.LotNO=c.LotNO AND b.WorkPoint=c.WorkPoint
  12691. WHERE b.LotNO='{0}' AND b.WorkPoint='{1}'
  12692. IF @CountNO='1' AND @CurrentDays<0
  12693. BEGIN
  12694. SELECT TOP 1 CASE a.F_ItemCode WHEN 'Effective01' THEN '1' WHEN 'Effective02' THEN '2' ELSE '3' END AS Type
  12695. FROM Sys_SRM_ItemsDetail a
  12696. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  12697. WHERE b.F_EnCode='Effective' AND a.F_EnabledMark='1'
  12698. ORDER BY a.F_SortCode DESC
  12699. END
  12700. ELSE
  12701. BEGIN
  12702. SELECT @CountNO
  12703. END";
  12704. }
  12705. //0 - 已经是最早的批次
  12706. //1 - 不管控
  12707. //2 - 提醒
  12708. //3 - 限制
  12709. sql = string.Format(sql, LotNo, WorkPoitCode);
  12710. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  12711. if (string.IsNullOrWhiteSpace(res))
  12712. {
  12713. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  12714. }
  12715. else
  12716. return res;
  12717. }
  12718. catch (Exception ex)
  12719. {
  12720. throw new Exception(ex.Message);
  12721. }
  12722. }
  12723. #region 包装
  12724. /// <summary>
  12725. /// 查询包装信息
  12726. /// </summary>
  12727. /// <param name="JsonData"></param>
  12728. /// <returns></returns>
  12729. public static object ContainerGet(ICSContainer JsonData)
  12730. {
  12731. var language = LanguageHelper.GetName("WMSAPIInfo");
  12732. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  12733. {
  12734. conn.Open();
  12735. SqlTransaction sqlTran = conn.BeginTransaction();
  12736. SqlCommand cmd = new SqlCommand();
  12737. cmd.Transaction = sqlTran;
  12738. cmd.Connection = conn;
  12739. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  12740. try
  12741. {
  12742. string sql = string.Empty;
  12743. //目标包装
  12744. if (JsonData.ToContainerCode != null)
  12745. {
  12746. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  12747. BEGIN
  12748. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  12749. RETURN
  12750. END
  12751. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  12752. sql = string.Format(sql, JsonData.ToContainerCode, JsonData.WorkPoint);
  12753. }
  12754. ///原包装
  12755. else if (JsonData.FromContainerCode != null)
  12756. {
  12757. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  12758. BEGIN
  12759. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  12760. RETURN
  12761. END
  12762. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  12763. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  12764. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  12765. BEGIN
  12766. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  12767. RETURN
  12768. END
  12769. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  12770. sql = string.Format(sql, JsonData.FromContainerCode, JsonData.WorkPoint);
  12771. }
  12772. else
  12773. {
  12774. throw new Exception(language.GetNameByCode("WMSAPIInfo029"));//"请传入包装条码!");
  12775. }
  12776. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  12777. cmd.Transaction.Commit();
  12778. return table;
  12779. }
  12780. catch (Exception ex)
  12781. {
  12782. if (cmd.Transaction != null)
  12783. cmd.Transaction.Rollback();
  12784. log.Error(ex.Message);
  12785. throw new Exception(ex.Message);
  12786. }
  12787. finally
  12788. {
  12789. if (conn.State == ConnectionState.Open)
  12790. {
  12791. conn.Close();
  12792. }
  12793. conn.Dispose();
  12794. }
  12795. }
  12796. }
  12797. /// <summary>
  12798. /// 修改包装信息
  12799. /// </summary>
  12800. /// <param name="JsonData"></param>
  12801. /// <returns></returns>
  12802. public static DataTable ContainerUpdate(List<ICSContainer> JsonData)
  12803. {
  12804. var language = LanguageHelper.GetName("WMSAPIInfo");
  12805. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  12806. {
  12807. conn.Open();
  12808. SqlTransaction sqlTran = conn.BeginTransaction();
  12809. SqlCommand cmd = new SqlCommand();
  12810. cmd.Transaction = sqlTran;
  12811. cmd.Connection = conn;
  12812. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  12813. try
  12814. {
  12815. string sql = string.Empty;
  12816. string codes = string.Empty;
  12817. foreach (ICSContainer container in JsonData)
  12818. {
  12819. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  12820. BEGIN
  12821. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  12822. RETURN
  12823. END
  12824. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  12825. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  12826. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  12827. BEGIN
  12828. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  12829. RETURN
  12830. END
  12831. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{2}' and WorkPoint='{1}')
  12832. BEGIN
  12833. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  12834. RETURN
  12835. END
  12836. UPDATE b SET ContainerID=c.ID
  12837. FROM ICSContainer a
  12838. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  12839. INNER JOIN ICSContainer c ON c.ContainerCODE ='{2}' and a.WorkPoint=c.WorkPoint
  12840. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}'";
  12841. sql = string.Format(sql, container.FromContainerCode, container.WorkPoint, container.ToContainerCode);
  12842. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  12843. {
  12844. throw new Exception(language.GetNameByCode("WMSAPIInfo030"));//"包装更新失败!");
  12845. }
  12846. codes += "'" + container.ToContainerCode + container.WorkPoint + "',";
  12847. }
  12848. sql = @"SELECT a.ContainerCode, a.ContainerName,b.LotNo FROM ICSContainer a
  12849. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  12850. WHERE a.ContainerCODE+a.WorkPoint IN({0})";
  12851. sql = string.Format(sql, codes.Substring(0,codes.Length - 1));
  12852. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  12853. cmd.Transaction.Commit();
  12854. return table;
  12855. }
  12856. catch (Exception ex)
  12857. {
  12858. if (cmd.Transaction != null)
  12859. cmd.Transaction.Rollback();
  12860. log.Error(ex.Message);
  12861. throw new Exception(ex.Message);
  12862. }
  12863. finally
  12864. {
  12865. if (conn.State == ConnectionState.Open)
  12866. {
  12867. conn.Close();
  12868. }
  12869. conn.Dispose();
  12870. }
  12871. }
  12872. }
  12873. #endregion
  12874. #region 盘点
  12875. /// <summary>
  12876. /// 创建盘点单
  12877. /// </summary>
  12878. /// <param name="JsonData"></param>
  12879. /// <returns></returns>
  12880. public static DataTable CheckCreate(List<ICSCheck> JsonData)
  12881. {
  12882. var language = LanguageHelper.GetName("WMSAPIInfo");
  12883. if (JsonData.Count <= 0)
  12884. {
  12885. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  12886. }
  12887. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  12888. {
  12889. conn.Open();
  12890. SqlTransaction sqlTran = conn.BeginTransaction();
  12891. SqlCommand cmd = new SqlCommand();
  12892. cmd.Transaction = sqlTran;
  12893. cmd.Connection = conn;
  12894. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  12895. try
  12896. {
  12897. string Code = string.Empty;
  12898. string sql = string.Empty;
  12899. foreach (var item in JsonData)
  12900. {
  12901. if (string.IsNullOrEmpty(item.User))
  12902. {
  12903. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  12904. }
  12905. if (string.IsNullOrEmpty(item.WorkPoint))
  12906. {
  12907. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  12908. }
  12909. //获取单号
  12910. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  12911. BEGIN
  12912. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  12913. RETURN
  12914. END
  12915. DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  12916. SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck
  12917. WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date
  12918. IF @MaxNO IS NULL
  12919. BEGIN
  12920. SELECT @date+'00001' AS Code
  12921. END
  12922. ELSE
  12923. BEGIN
  12924. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  12925. END ";
  12926. sql = string.Format(sql, item.User, item.WorkPoint);
  12927. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  12928. //创建盘点单
  12929. foreach (var itemInfo in item.detail)
  12930. {
  12931. int len = itemInfo.SelectLevel.Length;
  12932. if (itemInfo.WHCode=="")
  12933. {
  12934. if (len > 0)//传层级
  12935. {
  12936. sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE SUBSTRING(LocationCode,1,{4}) = '{1}')
  12937. BEGIN
  12938. RAISERROR('" + language.GetNameByCode("WMSAPIInfo460") + @"',16,1);
  12939. RETURN
  12940. END
  12941. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  12942. SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'0'
  12943. FROM ICSWareHouseLotInfo a
  12944. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  12945. WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
  12946. GROUP BY b.F_Account,b.F_RealName,b.F_Location
  12947. ";
  12948. //盘点单创建增加参数 StartDate EndDate
  12949. if (item.StartDate == "" || item.StartDate == null)
  12950. {
  12951. sql += @" --东辉新加
  12952. INSERT INTO[dbo].[ICSCheckDetail] ([ID], [CheckID], [LotNo],
  12953. [Quantity], [Amount], [PrimaryQuantity], [PrimaryAmount],
  12954. [ReplayQuantity], [ReplayAmount],
  12955. [CheckQuantity], [CheckAmount], [MUSER], [MUSERName], [MTIME], [WorkPoint],EATTRIBUTE1)
  12956. SELECT NEWID(),c.id,a.lotno,a.Quantity,0,0,0,0,0,0,0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'0'
  12957. FROM ICSWareHouseLotInfo a
  12958. INNER JOIN Sys_SRM_User b ON b.F_Account = '{2}' AND b.F_Location = '{3}'
  12959. inner join ICSCheck c on SUBSTRING(a.LocationCode,1,{4})= c.selectlevel and c.checkcode = '{0}'
  12960. ";
  12961. }
  12962. else
  12963. {
  12964. sql += @" --东辉新加
  12965. INSERT INTO[dbo].[ICSCheckDetail] ([ID], [CheckID], [LotNo],
  12966. [Quantity], [Amount], [PrimaryQuantity], [PrimaryAmount],
  12967. [ReplayQuantity], [ReplayAmount],
  12968. [CheckQuantity], [CheckAmount], [MUSER], [MUSERName], [MTIME], [WorkPoint],EATTRIBUTE1)
  12969. SELECT NEWID(),c.id,a.lotno,a.Quantity,0,0,0,0,0,0,0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'0'
  12970. FROM ICSWareHouseLotInfo a
  12971. INNER JOIN Sys_SRM_User b ON b.F_Account = '{2}' AND b.F_Location = '{3}'
  12972. INNER JOIN (select lotno from ICSWareHouseLotInfoLog where (SUBSTRING(FromLocationCode,1,{4}) ='{1}' or SUBSTRING(ToLocationCode,1,{4}) ='{1}') and (mtime BETWEEN '{5}' and '{6}')GROUP BY lotno )
  12973. lot on a.lotno = lot.lotno
  12974. inner join ICSCheck c on SUBSTRING(a.LocationCode,1,{4})= c.selectlevel and c.checkcode = '{0}'
  12975. ";
  12976. }
  12977. sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len, item.StartDate, item.EndDate);
  12978. }
  12979. else //传物料
  12980. {
  12981. sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE INVCODE = '{1}')
  12982. BEGIN
  12983. RAISERROR('" + language.GetNameByCode("WMSAPIInfo460") + @"',16,1);
  12984. RETURN
  12985. END
  12986. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  12987. SELECT NEWID(),'{0}','','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'0'
  12988. FROM ICSWareHouseLotInfo a
  12989. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  12990. WHERE INVCODE = '{1}'
  12991. GROUP BY b.F_Account,b.F_RealName,b.F_Location
  12992. ";
  12993. //盘点单创建增加参数 StartDate EndDate
  12994. if (item.StartDate == "" || item.StartDate == null)
  12995. {
  12996. sql += @" --东辉新加
  12997. INSERT INTO[dbo].[ICSCheckDetail] ([ID], [CheckID], [LotNo],
  12998. [Quantity], [Amount], [PrimaryQuantity], [PrimaryAmount],
  12999. [ReplayQuantity], [ReplayAmount],
  13000. [CheckQuantity], [CheckAmount], [MUSER], [MUSERName], [MTIME], [WorkPoint],EATTRIBUTE1)
  13001. SELECT NEWID(),c.id,a.lotno,a.Quantity,0,0,0,0,0,0,0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'0'
  13002. FROM ICSWareHouseLotInfo a
  13003. INNER JOIN Sys_SRM_User b ON b.F_Account = '{2}' AND b.F_Location = '{3}'
  13004. inner join ICSCheck c on c.checkcode = '{0}'
  13005. WHERE a.INVCODE = '{1}'
  13006. ";
  13007. }
  13008. else
  13009. {
  13010. sql += @" --东辉新加
  13011. INSERT INTO[dbo].[ICSCheckDetail] ([ID], [CheckID], [LotNo],
  13012. [Quantity], [Amount], [PrimaryQuantity], [PrimaryAmount],
  13013. [ReplayQuantity], [ReplayAmount],
  13014. [CheckQuantity], [CheckAmount], [MUSER], [MUSERName], [MTIME], [WorkPoint],EATTRIBUTE1)
  13015. SELECT NEWID(),c.id,a.lotno,a.Quantity,0,0,0,0,0,0,0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'0'
  13016. FROM ICSWareHouseLotInfo a
  13017. INNER JOIN Sys_SRM_User b ON b.F_Account = '{2}' AND b.F_Location = '{3}'
  13018. INNER JOIN (select lotno from ICSWareHouseLotInfoLog where INVCODE = '{1}' and (mtime BETWEEN '{5}' and '{6}')GROUP BY lotno )
  13019. lot on a.lotno = lot.lotno
  13020. inner join ICSCheck c on c.checkcode = '{0}'
  13021. ";
  13022. }
  13023. sql = string.Format(sql, Code, itemInfo.InvCode, item.User, item.WorkPoint, len, item.StartDate, item.EndDate);
  13024. }
  13025. }
  13026. else
  13027. {
  13028. if (len > 0)//传层级
  13029. {
  13030. sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE WareHouseCode = '{7}')
  13031. BEGIN
  13032. RAISERROR('" + language.GetNameByCode("WMSAPIInfo460") + @"',16,1);
  13033. RETURN
  13034. END
  13035. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  13036. SELECT NEWID(),'{0}','{7}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'1'
  13037. FROM ICSWareHouseLotInfo a
  13038. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  13039. WHERE a.WareHouseCode = '{7}'
  13040. GROUP BY b.F_Account,b.F_RealName,b.F_Location
  13041. ";
  13042. //盘点单创建增加参数 StartDate EndDate
  13043. if (item.StartDate == "" || item.StartDate == null)
  13044. {
  13045. sql += @" --东辉新加
  13046. INSERT INTO[dbo].[ICSCheckDetail] ([ID], [CheckID], [LotNo],
  13047. [Quantity], [Amount], [PrimaryQuantity], [PrimaryAmount],
  13048. [ReplayQuantity], [ReplayAmount],
  13049. [CheckQuantity], [CheckAmount], [MUSER], [MUSERName], [MTIME], [WorkPoint],EATTRIBUTE1)
  13050. SELECT NEWID(),c.id,a.lotno,a.Quantity,0,0,0,0,0,0,0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'0'
  13051. FROM ICSWareHouseLotInfo a
  13052. INNER JOIN Sys_SRM_User b ON b.F_Account = '{2}' AND b.F_Location = '{3}'
  13053. inner join ICSCheck c on a.WareHouseCode= c.selectlevel and c.checkcode = '{0}'
  13054. ";
  13055. }
  13056. else
  13057. {
  13058. sql += @" --东辉新加
  13059. INSERT INTO[dbo].[ICSCheckDetail] ([ID], [CheckID], [LotNo],
  13060. [Quantity], [Amount], [PrimaryQuantity], [PrimaryAmount],
  13061. [ReplayQuantity], [ReplayAmount],
  13062. [CheckQuantity], [CheckAmount], [MUSER], [MUSERName], [MTIME], [WorkPoint],EATTRIBUTE1)
  13063. SELECT NEWID(),c.id,a.lotno,a.Quantity,0,0,0,0,0,0,0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'0'
  13064. FROM ICSWareHouseLotInfo a
  13065. INNER JOIN Sys_SRM_User b ON b.F_Account = '{2}' AND b.F_Location = '{3}'
  13066. INNER JOIN (select lotno from ICSWareHouseLotInfoLog where (FromWareHouseCode ='{7}' or ToWareHouseCode ='{7}') and (mtime BETWEEN '{5}' and '{6}')GROUP BY lotno )
  13067. lot on a.lotno = lot.lotno
  13068. inner join ICSCheck c on a.WareHouseCode= c.selectlevel and c.checkcode = '{0}'
  13069. ";
  13070. }
  13071. sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len, item.StartDate, item.EndDate,itemInfo.WHCode);
  13072. }
  13073. else //传物料
  13074. {
  13075. sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE INVCODE = '{1}')
  13076. BEGIN
  13077. RAISERROR('" + language.GetNameByCode("WMSAPIInfo460") + @"',16,1);
  13078. RETURN
  13079. END
  13080. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  13081. SELECT NEWID(),'{0}','','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'1'
  13082. FROM ICSWareHouseLotInfo a
  13083. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  13084. WHERE INVCODE = '{1}'
  13085. GROUP BY b.F_Account,b.F_RealName,b.F_Location
  13086. ";
  13087. //盘点单创建增加参数 StartDate EndDate
  13088. if (item.StartDate == "" || item.StartDate == null)
  13089. {
  13090. sql += @" --东辉新加
  13091. INSERT INTO[dbo].[ICSCheckDetail] ([ID], [CheckID], [LotNo],
  13092. [Quantity], [Amount], [PrimaryQuantity], [PrimaryAmount],
  13093. [ReplayQuantity], [ReplayAmount],
  13094. [CheckQuantity], [CheckAmount], [MUSER], [MUSERName], [MTIME], [WorkPoint],EATTRIBUTE1)
  13095. SELECT NEWID(),c.id,a.lotno,a.Quantity,0,0,0,0,0,0,0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'0'
  13096. FROM ICSWareHouseLotInfo a
  13097. INNER JOIN Sys_SRM_User b ON b.F_Account = '{2}' AND b.F_Location = '{3}'
  13098. inner join ICSCheck c on c.checkcode = '{0}'
  13099. WHERE a.INVCODE = '{1}'
  13100. ";
  13101. }
  13102. else
  13103. {
  13104. sql += @" --东辉新加
  13105. INSERT INTO[dbo].[ICSCheckDetail] ([ID], [CheckID], [LotNo],
  13106. [Quantity], [Amount], [PrimaryQuantity], [PrimaryAmount],
  13107. [ReplayQuantity], [ReplayAmount],
  13108. [CheckQuantity], [CheckAmount], [MUSER], [MUSERName], [MTIME], [WorkPoint],EATTRIBUTE1)
  13109. SELECT NEWID(),c.id,a.lotno,a.Quantity,0,0,0,0,0,0,0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,'0'
  13110. FROM ICSWareHouseLotInfo a
  13111. INNER JOIN Sys_SRM_User b ON b.F_Account = '{2}' AND b.F_Location = '{3}'
  13112. INNER JOIN (select lotno from ICSWareHouseLotInfoLog where INVCODE = '{1}' and (mtime BETWEEN '{5}' and '{6}')GROUP BY lotno )
  13113. lot on a.lotno = lot.lotno
  13114. inner join ICSCheck c on c.checkcode = '{0}'
  13115. ";
  13116. }
  13117. sql = string.Format(sql, Code, itemInfo.InvCode, item.User, item.WorkPoint, len, item.StartDate, item.EndDate);
  13118. }
  13119. }
  13120. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  13121. {
  13122. throw new Exception(language.GetNameByCode("WMSAPIInfo031"));//"盘点单创建失败!");
  13123. }
  13124. }
  13125. }
  13126. if (string.IsNullOrWhiteSpace(Code))
  13127. {
  13128. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单单号不能为空!");
  13129. }
  13130. #region 查询返回数据
  13131. sql = @"SELECT a.ID,a.CheckCode,a.SelectLevel,
  13132. a.Quantity,
  13133. a.Amount,
  13134. a.MUSER AS [User],
  13135. a.MTIME AS [MTime]
  13136. FROM ICSCheck a
  13137. WHERE a.CheckCode='{0}'";
  13138. sql = string.Format(sql, Code);
  13139. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  13140. #endregion
  13141. cmd.Transaction.Commit();
  13142. return data;
  13143. }
  13144. catch (Exception ex)
  13145. {
  13146. if (cmd.Transaction != null)
  13147. cmd.Transaction.Rollback();
  13148. log.Error(ex.Message);
  13149. throw new Exception(ex.Message);
  13150. }
  13151. finally
  13152. {
  13153. if (conn.State == ConnectionState.Open)
  13154. {
  13155. conn.Close();
  13156. }
  13157. conn.Dispose();
  13158. }
  13159. }
  13160. }
  13161. /// <summary>
  13162. /// 盘点扫描
  13163. /// </summary>
  13164. /// <param name="JsonData"></param>
  13165. /// <returns></returns>
  13166. public static DataTable LOTCheckCreate(List<ICSCheck> JsonData)
  13167. {
  13168. var language = LanguageHelper.GetName("WMSAPIInfo");
  13169. if (JsonData.Count <= 0)
  13170. {
  13171. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  13172. }
  13173. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13174. {
  13175. conn.Open();
  13176. SqlTransaction sqlTran = conn.BeginTransaction();
  13177. SqlCommand cmd = new SqlCommand();
  13178. cmd.Transaction = sqlTran;
  13179. cmd.Connection = conn;
  13180. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13181. try
  13182. {
  13183. string lots = string.Empty;
  13184. string sql = string.Empty;
  13185. int result = 0;
  13186. string Identification = Guid.NewGuid().ToString();
  13187. foreach (var item in JsonData)
  13188. {
  13189. if (string.IsNullOrEmpty(item.User))
  13190. {
  13191. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  13192. }
  13193. if (string.IsNullOrEmpty(item.WorkPoint))
  13194. {
  13195. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  13196. }
  13197. if (string.IsNullOrEmpty(item.CheckCode))
  13198. {
  13199. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单号不能为空!");
  13200. }
  13201. //校验
  13202. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  13203. BEGIN
  13204. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  13205. RETURN
  13206. END
  13207. IF NOT EXISTS(SELECT ID FROM ICSCheck WHERE CheckCode='{2}' AND WorkPoint='{1}')
  13208. BEGIN
  13209. RAISERROR('" + language.GetNameByCode("WMSAPIInfo075") + @"',16,1);
  13210. RETURN
  13211. END";
  13212. sql = string.Format(sql, item.User, item.WorkPoint, item.CheckCode);
  13213. DBHelper.ExecuteNonQuery(sql, cmd);
  13214. //创建盘点单
  13215. foreach (var itemInfo in item.detail)
  13216. {
  13217. sql = @"IF NOT EXISTS(SELECT LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{1}' AND WorkPoint='{3}')
  13218. BEGIN
  13219. RAISERROR('" + language.GetNameByCode("WMSAPIInfo076") + @"',16,1);
  13220. RETURN
  13221. END
  13222. IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  13223. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  13224. WHERE b.CheckCode='{0}' AND a.LotNo='{1}' AND a.WorkPoint='{3}')
  13225. BEGIN
  13226. IF ('{5}'='')
  13227. BEGIN
  13228. UPDATE a SET PrimaryQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE(),EATTRIBUTE1='1'
  13229. FROM ICSCheckDetail a
  13230. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  13231. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  13232. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  13233. END
  13234. ELSE IF ('{5}'='')
  13235. BEGIN
  13236. UPDATE a SET CheckQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE(),EATTRIBUTE1='1'
  13237. FROM ICSCheckDetail a
  13238. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  13239. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  13240. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  13241. END
  13242. ELSE
  13243. BEGIN
  13244. UPDATE a SET ReplayQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE(),EATTRIBUTE1='1'
  13245. FROM ICSCheckDetail a
  13246. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  13247. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  13248. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  13249. END
  13250. END
  13251. ELSE
  13252. BEGIN
  13253. IF ('{5}'='')
  13254. BEGIN
  13255. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  13256. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','{4}','0','0','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  13257. FROM ICSWareHouseLotInfo a
  13258. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  13259. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  13260. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  13261. END
  13262. ELSE IF ('{5}'='')
  13263. BEGIN
  13264. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  13265. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','0','0','{4}','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  13266. FROM ICSWareHouseLotInfo a
  13267. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  13268. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  13269. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  13270. END
  13271. ELSE
  13272. BEGIN
  13273. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  13274. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','{4}','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  13275. FROM ICSWareHouseLotInfo a
  13276. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  13277. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  13278. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  13279. END
  13280. END";
  13281. sql = string.Format(sql, item.CheckCode, itemInfo.LotNo, item.User, item.WorkPoint, itemInfo.ActualQuantity, item.CheckKind);
  13282. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  13283. {
  13284. throw new Exception(language.GetNameByCode("WMSAPIInfo033"));//"盘点扫描创建失败!");
  13285. }
  13286. #region 更新ICSCheckDetail表
  13287. //string strSql = @"UPDATE ICSCheckDetail Set";
  13288. //if (item.CheckKind == "初盘")
  13289. // strSql += @" PrimaryQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  13290. //else if (item.CheckKind == "复盘")
  13291. // strSql += @" ReplayQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  13292. //else
  13293. // strSql += @" CheckQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  13294. //strSql += @" where ToCheckNO='" + item.CheckCode + "' AND WorkPoint='" + item.WorkPoint + "'";
  13295. //cmd.CommandText = strSql;
  13296. //result = cmd.ExecuteNonQuery();
  13297. //if (result <= 0)
  13298. //{
  13299. // throw new Exception(language.GetNameByCode("WMSAPIInfo296"));//"盘点子表数量增加失败!");
  13300. //}
  13301. #endregion
  13302. #region 更新库存
  13303. if (item.UpdateWHLI)
  13304. {
  13305. ICSWareHouseLotInfoService.WareHouseLotInfoUpdate(Identification, item.CheckCode, "", itemInfo.LotNo, itemInfo.ActualQuantity, item.User, item.WorkPoint, TransTypeEnum.Check.GetDescription<DBValue>(), item.CheckKind, cmd, language);
  13306. }
  13307. #endregion
  13308. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  13309. }
  13310. if (string.IsNullOrWhiteSpace(lots))
  13311. {
  13312. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  13313. }
  13314. //sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  13315. // FROM ICSCheck a
  13316. // INNER JOIN (SELECT x.CheckCode,x.WorkPoint,y.WarehouseCode,y.InvCode,SUM(ActualQuantity) AS ActualQuantity FROM ICSCheckDetail x INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint WHERE x.LotNo+x.WorkPoint IN ({2}) GROUP BY x.CheckCode,x.WorkPoint,y.WarehouseCode,y.InvCode) b ON a.CheckCode=b.CheckCode AND a.WorkPoint=b.WorkPoint AND a.WHCode=b.WarehouseCode AND a.InvCode=b.InvCode
  13317. // WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  13318. //sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  13319. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  13320. //{
  13321. // throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  13322. //}
  13323. }
  13324. #region 查询返回数据
  13325. sql = @"SELECT x.ID,x.CheckID,y.WarehouseCode AS WHCode,x.LotNo,
  13326. y.InvCode,
  13327. inv.InvName,
  13328. inv.InvStd,
  13329. x.Quantity,x.PrimaryQuantity,x.PrimaryAmount,x.ReplayQuantity,x.ReplayAmount,x.CheckQuantity,x.CheckAmount,
  13330. inv.InvUnit,
  13331. x.MUSER AS [User],
  13332. x.MTIME AS [MTime]
  13333. FROM ICSCheckDetail x
  13334. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  13335. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  13336. WHERE x.LotNo+x.WorkPoint IN ({0})";
  13337. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  13338. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  13339. #endregion
  13340. cmd.Transaction.Commit();
  13341. return data;
  13342. }
  13343. catch (Exception ex)
  13344. {
  13345. if (cmd.Transaction != null)
  13346. cmd.Transaction.Rollback();
  13347. log.Error(ex.Message);
  13348. throw new Exception(ex.Message);
  13349. }
  13350. finally
  13351. {
  13352. if (conn.State == ConnectionState.Open)
  13353. {
  13354. conn.Close();
  13355. }
  13356. conn.Dispose();
  13357. }
  13358. }
  13359. }
  13360. public static DataTable LOTCheckCreateNew(List<ICSCheck> JsonData)
  13361. {
  13362. var language = LanguageHelper.GetName("WMSAPIInfo");
  13363. if (JsonData.Count <= 0)
  13364. {
  13365. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  13366. }
  13367. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13368. {
  13369. conn.Open();
  13370. SqlTransaction sqlTran = conn.BeginTransaction();
  13371. SqlCommand cmd = new SqlCommand();
  13372. cmd.Transaction = sqlTran;
  13373. cmd.Connection = conn;
  13374. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13375. try
  13376. {
  13377. string lots = string.Empty;
  13378. string sql = string.Empty;
  13379. int result = 0;
  13380. string Identification = Guid.NewGuid().ToString();
  13381. foreach (var item in JsonData)
  13382. {
  13383. if (string.IsNullOrEmpty(item.User))
  13384. {
  13385. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  13386. }
  13387. if (string.IsNullOrEmpty(item.WorkPoint))
  13388. {
  13389. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  13390. }
  13391. if (string.IsNullOrEmpty(item.CheckCode))
  13392. {
  13393. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单号不能为空!");
  13394. }
  13395. //校验
  13396. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  13397. BEGIN
  13398. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  13399. RETURN
  13400. END
  13401. IF NOT EXISTS(SELECT ID FROM ICSCheck WHERE CheckCode='{2}' AND WorkPoint='{1}')
  13402. BEGIN
  13403. RAISERROR('" + language.GetNameByCode("WMSAPIInfo075") + @"',16,1);
  13404. RETURN
  13405. END";
  13406. sql = string.Format(sql, item.User, item.WorkPoint, item.CheckCode);
  13407. DBHelper.ExecuteNonQuery(sql, cmd);
  13408. //创建盘点单
  13409. foreach (var itemInfo in item.detail)
  13410. {
  13411. sql = @"IF NOT EXISTS(SELECT LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{1}' AND WorkPoint='{3}')
  13412. BEGIN
  13413. RAISERROR('" + language.GetNameByCode("WMSAPIInfo076") + @"',16,1);
  13414. RETURN
  13415. END
  13416. IF EXISTS(SELECT LotNo FROM ICSCheckIntermediateTable a
  13417. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  13418. WHERE b.CheckCode='{0}' AND a.LotNo='{1}' AND a.WorkPoint='{3}')
  13419. BEGIN
  13420. UPDATE a SET Quantity='{4}',CheckType='{5}',IsWHUpdate='{6}',IsCheckDetail=0,MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE(),EATTRIBUTE1='0'
  13421. FROM ICSCheckIntermediateTable a
  13422. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  13423. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  13424. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  13425. END
  13426. ELSE
  13427. BEGIN
  13428. INSERT INTO ICSCheckIntermediateTable (ID,CheckID,CheckNo,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,CheckType,IsCheckDetail,IsWHUpdate,MUSER,MUSERName,MTIME,WorkPoint)
  13429. SELECT NEWID(),c.ID,'{0}',a.LotNo,'{4}','0','0','0','0','0','0','0','{5}','0','{6}',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  13430. FROM ICSWareHouseLotInfo a
  13431. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  13432. LEFT JOIN ICSCheck c ON
  13433. (c.EATTRIBUTE1='1' AND a.WareHouseCode=c.SelectLevel) OR
  13434. (c.EATTRIBUTE1<>'1' AND SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel)
  13435. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  13436. END";
  13437. sql = string.Format(sql, item.CheckCode, itemInfo.LotNo, item.User, item.WorkPoint, itemInfo.ActualQuantity, item.CheckKind,item.UpdateWHLI);
  13438. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  13439. {
  13440. throw new Exception(language.GetNameByCode("WMSAPIInfo033"));//"盘点扫描创建失败!");
  13441. }
  13442. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  13443. //库位选填 如果不为空就执行移库操作
  13444. if (itemInfo.LocationCode != ""&& itemInfo.WHCode != "")
  13445. {
  13446. if (string.IsNullOrEmpty(itemInfo.LotNo))
  13447. {
  13448. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  13449. }
  13450. //验证仓库库位信息
  13451. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  13452. BEGIN
  13453. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  13454. RETURN
  13455. END
  13456. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  13457. BEGIN
  13458. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  13459. RETURN
  13460. END
  13461. IF NOT EXISTS(SELECT a.ID
  13462. FROM ICSWareHouse a
  13463. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  13464. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  13465. BEGIN
  13466. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  13467. RETURN
  13468. END";
  13469. sql = string.Format(sql, itemInfo.WHCode, item.WorkPoint, itemInfo.LocationCode);
  13470. DBHelper.ExecuteNonQuery(sql, cmd);
  13471. //更新条码信息
  13472. ICSWareHouseLotInfoService.WareHouseLotInfoLibrary(Identification, "", "", itemInfo.WHCode, itemInfo.LocationCode, itemInfo.LotNo,
  13473. item.User, item.WorkPoint, "7", "29", cmd, language);
  13474. }
  13475. }
  13476. if (string.IsNullOrWhiteSpace(lots))
  13477. {
  13478. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  13479. }
  13480. //sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  13481. // FROM ICSCheck a
  13482. // INNER JOIN (SELECT x.CheckCode,x.WorkPoint,y.WarehouseCode,y.InvCode,SUM(ActualQuantity) AS ActualQuantity FROM ICSCheckDetail x INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint WHERE x.LotNo+x.WorkPoint IN ({2}) GROUP BY x.CheckCode,x.WorkPoint,y.WarehouseCode,y.InvCode) b ON a.CheckCode=b.CheckCode AND a.WorkPoint=b.WorkPoint AND a.WHCode=b.WarehouseCode AND a.InvCode=b.InvCode
  13483. // WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  13484. //sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  13485. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  13486. //{
  13487. // throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  13488. //}
  13489. }
  13490. #region 查询返回数据
  13491. sql = @"SELECT x.ID,x.CheckID,y.WarehouseCode AS WHCode,x.LotNo,
  13492. y.InvCode,
  13493. inv.InvName,
  13494. inv.InvStd,
  13495. x.Quantity,x.PrimaryQuantity,x.PrimaryAmount,x.ReplayQuantity,x.ReplayAmount,x.CheckQuantity,x.CheckAmount,
  13496. inv.InvUnit,
  13497. x.MUSER AS [User],
  13498. x.MTIME AS [MTime]
  13499. FROM ICSCheckIntermediateTable x
  13500. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  13501. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  13502. WHERE x.LotNo+x.WorkPoint IN ({0})";
  13503. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  13504. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  13505. #endregion
  13506. cmd.Transaction.Commit();
  13507. return data;
  13508. }
  13509. catch (Exception ex)
  13510. {
  13511. if (cmd.Transaction != null)
  13512. cmd.Transaction.Rollback();
  13513. log.Error(ex.Message);
  13514. throw new Exception(ex.Message);
  13515. }
  13516. finally
  13517. {
  13518. if (conn.State == ConnectionState.Open)
  13519. {
  13520. conn.Close();
  13521. }
  13522. conn.Dispose();
  13523. }
  13524. }
  13525. }
  13526. #endregion
  13527. #region 多语言
  13528. /// <summary>
  13529. /// 多语言查询
  13530. /// </summary>
  13531. /// <param name="JsonData"></param>
  13532. /// <returns></returns>
  13533. public static DataTable PromptInformationGet(WMSBarCoreModel JsonData)
  13534. {
  13535. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13536. {
  13537. conn.Open();
  13538. SqlCommand cmd = new SqlCommand();
  13539. cmd.Connection = conn;
  13540. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13541. try
  13542. {
  13543. string DefiniteLanguage = ICSDefiniteLanguageService.GetLanguage();
  13544. string sql = @"select " + DefiniteLanguage + " AS Name,Code from Sys_Language where 1=1";
  13545. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  13546. {
  13547. sql += " and Code LIKE '%{0}%'";
  13548. }
  13549. sql = string.Format(sql, JsonData.Code);
  13550. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  13551. return data;
  13552. }
  13553. catch (Exception ex)
  13554. {
  13555. log.Error(ex.Message);
  13556. throw new Exception(ex.Message);
  13557. }
  13558. finally
  13559. {
  13560. if (conn.State == ConnectionState.Open)
  13561. {
  13562. conn.Close();
  13563. }
  13564. conn.Dispose();
  13565. }
  13566. }
  13567. }
  13568. #endregion
  13569. #region 东辉对比U9客户料号
  13570. /// <summary>
  13571. /// 东辉对比U9客户料号
  13572. /// </summary>
  13573. /// <param name="JsonData"></param>
  13574. /// <returns></returns>
  13575. public static DataTable DHCheckGet(WMSBarCoreModel JsonData)
  13576. {
  13577. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13578. {
  13579. conn.Open();
  13580. SqlCommand cmd = new SqlCommand();
  13581. cmd.Connection = conn;
  13582. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13583. try
  13584. {
  13585. string sql = @"select ItemCODE,CustomerItemcode from ICSCustomerItem where 1=1";
  13586. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  13587. {
  13588. sql += " and ItemCode = '{1}' and (CustomerItemcode ='{0}' or (CustomerItemCode+'-'+SysVersion)='{0}')";
  13589. }
  13590. sql = string.Format(sql, JsonData.Code,JsonData.Name);
  13591. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  13592. sql = @"INSERT INTO DHCheckLog(ID,ItemCode,CustomerItemCode,IsChecked,MUSER,MTIME)
  13593. values(newid(),'{0}','{1}','{2}','{3}',getDate())";
  13594. sql = string.Format(sql, JsonData.Name, JsonData.Code, data.Rows.Count>0?1:0, JsonData.User);
  13595. DBHelper.ExecuteNonQuery(sql, cmd);
  13596. return data;
  13597. }
  13598. catch (Exception ex)
  13599. {
  13600. log.Error(ex.Message);
  13601. throw new Exception(ex.Message);
  13602. }
  13603. finally
  13604. {
  13605. if (conn.State == ConnectionState.Open)
  13606. {
  13607. conn.Close();
  13608. }
  13609. conn.Dispose();
  13610. }
  13611. }
  13612. }
  13613. #endregion
  13614. #region 创建盘点单获取层级详细
  13615. /// <summary>
  13616. /// 创建盘点单获取层级详细
  13617. /// </summary>
  13618. /// <param name="JsonData"></param>
  13619. /// <returns></returns>
  13620. public static DataTable SelectLevelGet(WMSBarCoreModel JsonData)
  13621. {
  13622. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13623. {
  13624. conn.Open();
  13625. SqlCommand cmd = new SqlCommand();
  13626. cmd.Connection = conn;
  13627. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13628. try
  13629. {
  13630. string sql = @"select distinct
  13631. dbo.substr_withindex(code,'-',{0}) as WorkPointCode
  13632. from ICSLocation";
  13633. sql = string.Format(sql, JsonData.Code);
  13634. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  13635. return data;
  13636. }
  13637. catch (Exception ex)
  13638. {
  13639. log.Error(ex.Message);
  13640. throw new Exception(ex.Message);
  13641. }
  13642. finally
  13643. {
  13644. if (conn.State == ConnectionState.Open)
  13645. {
  13646. conn.Close();
  13647. }
  13648. conn.Dispose();
  13649. }
  13650. }
  13651. }
  13652. #endregion
  13653. #region 仓库/库位
  13654. /// <summary>
  13655. /// 仓库/库位
  13656. /// </summary>
  13657. /// <param name="JsonData"></param>
  13658. /// <returns></returns>
  13659. public static DataTable LocationGet(ICSLocation JsonData)
  13660. {
  13661. var language = LanguageHelper.GetName("WMSAPIInfo");
  13662. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13663. {
  13664. conn.Open();
  13665. SqlTransaction sqlTran = conn.BeginTransaction();
  13666. SqlCommand cmd = new SqlCommand();
  13667. cmd.Transaction = sqlTran;
  13668. cmd.Connection = conn;
  13669. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13670. try
  13671. {
  13672. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode like '%{0}%' AND a.WorkPoint='{1}')
  13673. BEGIN
  13674. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  13675. RETURN
  13676. END
  13677. IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode like '%{0}%' AND a.WorkPoint='{1}')
  13678. BEGIN
  13679. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  13680. RETURN
  13681. END
  13682. IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode like '%{0}%' AND a.WorkPoint='{1}' and b.Enable='1')
  13683. BEGIN
  13684. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  13685. RETURN
  13686. END
  13687. SELECT
  13688. LocationCode,
  13689. LocationName ,
  13690. WarehouseCode,
  13691. WarehouseName
  13692. FROM ICSLocation a
  13693. INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode = '{0}' AND a.WorkPoint='{1}' and b.Enable='1'";
  13694. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  13695. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  13696. cmd.Transaction.Commit();
  13697. return data;
  13698. }
  13699. catch (Exception ex)
  13700. {
  13701. if (cmd.Transaction != null)
  13702. cmd.Transaction.Rollback();
  13703. log.Error(ex.Message);
  13704. throw new Exception(ex.Message);
  13705. }
  13706. finally
  13707. {
  13708. if (conn.State == ConnectionState.Open)
  13709. {
  13710. conn.Close();
  13711. }
  13712. conn.Dispose();
  13713. }
  13714. }
  13715. }
  13716. /// <summary>
  13717. /// 仓库/库位
  13718. /// </summary>
  13719. /// <param name="JsonData"></param>
  13720. /// <returns></returns>
  13721. public static DataTable AMLocationGet(ICSLocation JsonData)
  13722. {
  13723. var language = LanguageHelper.GetName("WMSAPIInfo");
  13724. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13725. {
  13726. conn.Open();
  13727. SqlTransaction sqlTran = conn.BeginTransaction();
  13728. SqlCommand cmd = new SqlCommand();
  13729. cmd.Transaction = sqlTran;
  13730. cmd.Connection = conn;
  13731. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13732. string UserName = "";
  13733. try
  13734. {
  13735. //检验是否分批
  13736. string uersql = @"SELECT F_RealName from Sys_SRM_User Where F_Account='{0}' AND F_Location='{1}'
  13737. ";
  13738. uersql = string.Format(uersql, JsonData.User,JsonData.WorkPoint);
  13739. DataTable dt = DBHelper.SQlReturnData(uersql, cmd);
  13740. if (dt.Rows.Count == 0)
  13741. {
  13742. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  13743. }
  13744. else
  13745. {
  13746. UserName = dt.Rows[0]["F_RealName"].ToString();
  13747. }
  13748. string UName = UserName.Substring(0, 2);
  13749. switch (UName)
  13750. {
  13751. case "L1":
  13752. UName = "021";
  13753. break;
  13754. case "L2":
  13755. UName = "022";
  13756. break;
  13757. case "L3":
  13758. UName = "023";
  13759. break;
  13760. case "L4":
  13761. UName = "024";
  13762. break;
  13763. case "L5":
  13764. UName = "025";
  13765. break;
  13766. case "L6":
  13767. UName = "026";
  13768. break;
  13769. case "L7":
  13770. UName = "025";
  13771. break;
  13772. case "C1":
  13773. UName = "004";
  13774. break;
  13775. }
  13776. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode like '%{0}%' AND a.WorkPoint='{1}')
  13777. BEGIN
  13778. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  13779. RETURN
  13780. END
  13781. IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode like '%{0}%' AND a.WorkPoint='{1}')
  13782. BEGIN
  13783. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  13784. RETURN
  13785. END
  13786. IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode like '%{0}%' AND a.WorkPoint='{1}' and b.Enable='1')
  13787. BEGIN
  13788. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  13789. RETURN
  13790. END
  13791. IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode like '%{0}%' AND a.WorkPoint='{1}' and b.warehousecode='{2}')
  13792. BEGIN
  13793. RAISERROR('线',16,1)
  13794. RETURN
  13795. END
  13796. SELECT
  13797. LocationCode,
  13798. LocationName ,
  13799. WarehouseCode,
  13800. WarehouseName
  13801. FROM ICSLocation a
  13802. INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode like '%{0}%' AND a.WorkPoint='{1}' and b.Enable='1'";
  13803. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint, UName);
  13804. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  13805. cmd.Transaction.Commit();
  13806. return data;
  13807. }
  13808. catch (Exception ex)
  13809. {
  13810. if (cmd.Transaction != null)
  13811. cmd.Transaction.Rollback();
  13812. log.Error(ex.Message);
  13813. throw new Exception(ex.Message);
  13814. }
  13815. finally
  13816. {
  13817. if (conn.State == ConnectionState.Open)
  13818. {
  13819. conn.Close();
  13820. }
  13821. conn.Dispose();
  13822. }
  13823. }
  13824. }
  13825. #endregion
  13826. /// <summary>
  13827. /// 工单生成条码(mes调用)
  13828. /// </summary>
  13829. /// <param name="JsonData"></param>
  13830. /// <returns></returns>
  13831. public static DataTable CreateItemLotByMo(List<CreateItemLot> JsonData)
  13832. {
  13833. var language = LanguageHelper.GetName("WMSAPIInfo");
  13834. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13835. {
  13836. conn.Open();
  13837. SqlTransaction sqlTran = conn.BeginTransaction();
  13838. SqlCommand cmd = new SqlCommand();
  13839. cmd.Transaction = sqlTran;
  13840. cmd.Connection = conn;
  13841. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13842. try
  13843. {
  13844. string Colspan = "";
  13845. string str1 = "";
  13846. string sql = string.Empty;
  13847. List<string> ExtensionIDList = new List<string>();
  13848. foreach (var item in JsonData)
  13849. {
  13850. Colspan = "~"+ item .BatchCode+ "~~~~~~~~~~~~";
  13851. string sqls = string.Format(@"select ID from ICSExtension where Colspan='{0}' and WorkPoint='{1}'", Colspan, item.WorkPoint);
  13852. object ExtensionID = DBHelper.ExecuteScalar(sqls,cmd);
  13853. string sqlByMo = string.Format(@" select ID from ICSMO where MOCode='{0}' and Sequence='{1}' and WorkPoint='{2}'", item.Code, item.Sequence, item.WorkPoint);
  13854. object MoID = DBHelper.ExecuteScalar(sqlByMo, cmd);
  13855. if (MoID.ToString()==""|| MoID ==null)
  13856. {
  13857. throw new Exception("接口调用失败:未查询到相关工单!");
  13858. }
  13859. bool flag = true;
  13860. foreach (var items in ExtensionIDList)
  13861. {
  13862. if (items == Colspan + item.WorkPoint)
  13863. {
  13864. flag = false;
  13865. }
  13866. }
  13867. if (ExtensionID == null && flag == true)
  13868. {
  13869. str1 = Guid.NewGuid().ToString();
  13870. sql += string.Format(@" Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  13871. Values('{0}','{1}','','{2}','','','','','','','','','','','','',getdate(),'{3}','{4}','{5}' )",
  13872. str1, Colspan, item.BatchCode, item.MUSER, item.MUSERName, item.WorkPoint);
  13873. }
  13874. else if (ExtensionID != null)
  13875. {
  13876. str1 = ExtensionID.ToString();
  13877. }
  13878. ExtensionIDList.Add(Colspan + item.WorkPoint);
  13879. sql += string.Format(@"Insert into ICSInventoryLotDetail(LotNo, TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint,TransID)
  13880. Values('{0}','{1}','{2}','{3}','{4}',getdate(),'{5}','{6}' )",
  13881. item.LotNo, item.Code, item.Sequence, item.MUSER, item.MUSERName, item.WorkPoint, MoID);
  13882. sql += string.Format(@" insert into ICSInventoryLot
  13883. (ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,ExtensionID,Type,MUSER,MUSERName,MTIME,WorkPoint,Amount)
  13884. Values(newid(),'{0}','{1}','{2}','{3}','{4}','{5}','3','{6}','{7}',getdate(),'{8}','{9}') ",
  13885. item.LotNo, item.InvCode, item.ProductDate, item.ExpirationDate, item.Quantity, str1, item.MUSER, item.MUSERName, item.WorkPoint, item.Amount);
  13886. sql += "\r\n";
  13887. }
  13888. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  13889. cmd.Transaction.Commit();
  13890. return data;
  13891. }
  13892. catch (Exception ex)
  13893. {
  13894. if (cmd.Transaction != null)
  13895. cmd.Transaction.Rollback();
  13896. log.Error(ex.Message);
  13897. throw new Exception(ex.Message);
  13898. }
  13899. finally
  13900. {
  13901. if (conn.State == ConnectionState.Open)
  13902. {
  13903. conn.Close();
  13904. }
  13905. conn.Dispose();
  13906. }
  13907. }
  13908. }
  13909. #region 先进先出密码校验
  13910. public static DataTable CheckPassWord(Sys_SRM_User userModel)
  13911. {
  13912. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13913. {
  13914. conn.Open();
  13915. SqlCommand cmd = new SqlCommand();
  13916. cmd.Connection = conn;
  13917. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13918. try
  13919. {
  13920. DataTable dt = null;
  13921. string sql = @"select b.F_Id from Sys_SRM_Items a
  13922. inner join Sys_SRM_ItemsDetail b on a.F_id=b.F_ItemId
  13923. where F_encode='FIFOPW' and F_Define1='{0}' and b.F_EnabledMark=1";//已经启用的账号
  13924. sql = string.Format(sql, userModel.PassWord);
  13925. log.Debug(sql);
  13926. dt = DBHelper.SQlReturnData(sql, cmd);
  13927. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  13928. {
  13929. return dt;
  13930. }
  13931. else
  13932. {
  13933. return dt;
  13934. }
  13935. }
  13936. catch (Exception ex)
  13937. {
  13938. log.Error(ex.Message);
  13939. throw new Exception(ex.Message);
  13940. }
  13941. finally
  13942. {
  13943. if (conn.State == ConnectionState.Open)
  13944. {
  13945. conn.Close();
  13946. }
  13947. conn.Dispose();
  13948. }
  13949. }
  13950. }
  13951. #endregion
  13952. #region 登陆
  13953. public static object CheckLogin(Sys_SRM_User userModel)
  13954. {
  13955. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13956. {
  13957. conn.Open();
  13958. SqlCommand cmd = new SqlCommand();
  13959. cmd.Connection = conn;
  13960. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13961. try
  13962. {
  13963. string sql = @"select F_Account from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  13964. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  13965. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  13966. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  13967. {
  13968. sql = @" select a.[F_Id] as UserId
  13969. ,[F_Account] as userCode
  13970. ,[F_RealName] as UserName
  13971. ,[F_NickName]
  13972. ,b.F_UserPassword
  13973. ,b.F_UserSecretkey
  13974. ,[F_HeadIcon]
  13975. ,[F_Gender]
  13976. ,[F_Birthday]
  13977. ,[F_MobilePhone]
  13978. ,[F_Email]
  13979. ,[F_WeChat]
  13980. ,[F_ManagerId]
  13981. ,[F_SecurityLevel]
  13982. ,[F_Signature]
  13983. ,[F_OrganizeId]
  13984. ,[F_DepartmentId]
  13985. ,[F_RoleId]
  13986. ,[F_DutyId]
  13987. ,[F_IsAdministrator]
  13988. ,[F_SortCode]
  13989. ,[F_DeleteMark]
  13990. ,[F_EnabledMark]
  13991. ,[F_Description]
  13992. ,[F_CreatorTime]
  13993. ,[F_CreatorUserId]
  13994. ,[F_LastModifyTime]
  13995. ,[F_LastModifyUserId]
  13996. ,[F_DeleteTime]
  13997. ,[F_DeleteUserId]
  13998. ,[F_Location] as WorkPoint
  13999. ,[F_VenCode]
  14000. from Sys_SRM_User a
  14001. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  14002. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  14003. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  14004. dt = DBHelper.SQlReturnData(sql, cmd);
  14005. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  14006. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  14007. foreach (var item in users)
  14008. {
  14009. //string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
  14010. string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  14011. if (dbPassword == item.F_UserPassword)
  14012. {
  14013. string json = JsonConvert.SerializeObject(dt);
  14014. List<Sys_SRM_User> userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  14015. return userLogOnEntity;
  14016. }
  14017. else
  14018. {
  14019. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI004"));//"密码不正确,请重新输入");
  14020. }
  14021. }
  14022. }
  14023. else
  14024. {
  14025. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI005"));//"用户名不存在,请重新输入!");
  14026. }
  14027. return null;
  14028. }
  14029. catch (Exception ex)
  14030. {
  14031. log.Error(ex.Message);
  14032. throw new Exception(ex.Message);
  14033. }
  14034. finally
  14035. {
  14036. if (conn.State == ConnectionState.Open)
  14037. {
  14038. conn.Close();
  14039. }
  14040. conn.Dispose();
  14041. }
  14042. }
  14043. }
  14044. #endregion
  14045. #region 获取调拨单
  14046. /// <summary>
  14047. /// 获取未发,未发完调拨单
  14048. /// </summary>
  14049. /// <param name="JsonData"></param>
  14050. /// <returns></returns>
  14051. public static DataTable TransCodemationGet(TransferDoc JsonData)
  14052. {
  14053. var language = LanguageHelper.GetName("WMSAPIInfo");
  14054. if (JsonData == null)
  14055. {
  14056. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  14057. }
  14058. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  14059. {
  14060. conn.Open();
  14061. SqlTransaction sqlTran = conn.BeginTransaction();
  14062. SqlCommand cmd = new SqlCommand();
  14063. cmd.Transaction = sqlTran;
  14064. cmd.Connection = conn;
  14065. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  14066. try
  14067. {
  14068. string Workpoint = "";
  14069. Workpoint = JsonData.WorkPoint;
  14070. string sql = @"SELECT DISTINCT TransferNO as TransCode FROM ICSTransferApplication
  14071. WHERE WorkPoint='{0}' AND Quantity>ISNULL(TransferQuantity, 0) order by TransferNO desc";
  14072. sql = string.Format(sql, Workpoint);
  14073. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  14074. return table;
  14075. }
  14076. catch (Exception ex)
  14077. {
  14078. if (cmd.Transaction != null)
  14079. cmd.Transaction.Rollback();
  14080. log.Error(ex.Message);
  14081. throw new Exception(ex.Message);
  14082. }
  14083. finally
  14084. {
  14085. if (conn.State == ConnectionState.Open)
  14086. {
  14087. conn.Close();
  14088. }
  14089. conn.Dispose();
  14090. }
  14091. }
  14092. }
  14093. #endregion
  14094. #region 源头单据信息(佑伦专用)
  14095. /// <summary>
  14096. /// 源头单据信息(佑伦专用)
  14097. /// </summary>
  14098. /// <param name="JsonData"></param>
  14099. /// <returns></returns>
  14100. public static DataTable YLTransInformationGet(WMSSourceDocumentModel JsonData)
  14101. {
  14102. var language = LanguageHelper.GetName("WMSAPIInfo");
  14103. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  14104. {
  14105. conn.Open();
  14106. SqlCommand cmd = new SqlCommand();
  14107. cmd.Connection = conn;
  14108. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  14109. try
  14110. {
  14111. if (string.IsNullOrEmpty(JsonData.TransCode))
  14112. {
  14113. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  14114. }
  14115. else if (string.IsNullOrEmpty(JsonData.TransType))
  14116. {
  14117. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  14118. }
  14119. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  14120. {
  14121. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  14122. }
  14123. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  14124. {
  14125. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  14126. }
  14127. string TransType = JsonData.TransType;
  14128. #region SLQ
  14129. string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  14130. BEGIN
  14131. RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  14132. RETURN
  14133. END
  14134. ";
  14135. string sql = @"SELECT a.ID,
  14136. {0}
  14137. convert(varchar(100),'') AS LocationCode,
  14138. convert(varchar(100),'') AS LotNo,
  14139. convert(varchar(10),'') AS ToWarehouseCode,
  14140. 0 AS LocationQty,
  14141. 0 AS isMatched,
  14142. a.InvCode,
  14143. inv.InvName,
  14144. inv.InvStd,
  14145. a.Quantity,
  14146. inv.InvUnit,
  14147. a.Amount,
  14148. a.WHCode,
  14149. inv.AmountUnit,
  14150. wh.WarehouseName AS WHName,
  14151. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  14152. a.ExtensionID,
  14153. 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,
  14154. ISNULL(ext.Version, '') AS Version,
  14155. ISNULL(ext.Brand, '') AS Brand,
  14156. ISNULL(ext.cFree1, '') AS cFree1,
  14157. ISNULL(ext.cFree2, '') AS cFree2,
  14158. ISNULL(ext.cFree3, '') AS cFree3,
  14159. ISNULL(ext.cFree4, '') AS cFree4,
  14160. ISNULL(ext.cFree5, '') AS cFree5,
  14161. ISNULL(ext.cFree6, '') AS cFree6,
  14162. ISNULL(ext.cFree7, '') AS cFree7,
  14163. ISNULL(ext.cFree8, '') AS cFree8,
  14164. ISNULL(ext.cFree9, '') AS cFree9,
  14165. ISNULL(ext.cFree10, '') AS cFree10,
  14166. a.MUSER AS [User],
  14167. a.MTIME AS [MTime]
  14168. {4}
  14169. FROM {1}
  14170. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  14171. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  14172. LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  14173. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  14174. WHERE {2} ";
  14175. string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  14176. c.Code,
  14177. c.InvCode,
  14178. c.InvName,
  14179. c.InvStd,
  14180. c.InvUnit,
  14181. FLOOR(c.iQuantity) AS iQuantity,
  14182. d.WarehouseCode,
  14183. d.LocationCode,
  14184. d.LotNO,
  14185. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  14186. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  14187. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  14188. FROM
  14189. ({0}) c
  14190. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND ((LEN(ISNULL(c.WHCode,''))<=0) OR (LEN(ISNULL(c.WHCode,''))>0) AND c.WhCode=d.WarehouseCode) AND d.WorkPoint='{1}' AND d.Quantity>0
  14191. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  14192. LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  14193. DECLARE @ItemCode VARCHAR(50),
  14194. @QTY DECIMAL(18,3),
  14195. @ItemCodeCurrent VARCHAR(50),
  14196. @QTYCurrent DECIMAL(18,3),
  14197. @iQuantityCurrent DECIMAL(18,3),
  14198. @CanDelete BIT,
  14199. @Row INT,
  14200. @rowCurrent INT
  14201. SET @Row = @@rowcount
  14202. SET @rowCurrent=1
  14203. SET @CanDelete=0
  14204. SET @ItemCode=''
  14205. WHILE @rowCurrent<=@Row
  14206. BEGIN
  14207. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  14208. PRINT(@rowCurrent)
  14209. IF @ItemCode<>@ItemCodeCurrent
  14210. BEGIN
  14211. SET @ItemCode=@ItemCodeCurrent
  14212. SET @QTY=0
  14213. SET @CanDelete=0
  14214. END
  14215. IF @CanDelete=1
  14216. BEGIN
  14217. DELETE FROM #temp WHERE rowNo=@rowCurrent
  14218. SET @rowCurrent += 1
  14219. CONTINUE
  14220. END
  14221. SET @QTY += @QTYCurrent
  14222. IF @QTY>=@iQuantityCurrent
  14223. BEGIN
  14224. SET @CanDelete=1
  14225. END
  14226. SET @rowCurrent += 1
  14227. END
  14228. SELECT * FROM #temp
  14229. DROP TABLE #temp
  14230. ";
  14231. #endregion
  14232. bool isDeliveryNotice = false; //送货、到货、含委外
  14233. string columns = string.Empty; //查询源头单据表的特殊列名
  14234. string tableName = string.Empty; //查询源头单据表名
  14235. string where = string.Empty; //查询源头单据的过滤条件
  14236. bool isMerge = false; //合并发料
  14237. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  14238. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  14239. string sqls = string.Empty;
  14240. string sqlCheckSign = "";
  14241. DataTable flag = null;
  14242. #region 检料表信息
  14243. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  14244. {
  14245. enableCode = "Over001";
  14246. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  14247. #region 工单备料sql
  14248. sqls = @" SELECT
  14249. c.MOCode as Code,
  14250. a.InvCode,
  14251. b.InvName,
  14252. b.InvStd,
  14253. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14254. a.WhCode,
  14255. b.InvUnit,
  14256. a.ExtensionID
  14257. FROM
  14258. ICSMOPick a
  14259. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  14260. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14261. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  14262. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  14263. #endregion
  14264. }
  14265. if (TransType == TransTypeEnum.MOApply.GetDescription())
  14266. {
  14267. enableCode = "Over002";
  14268. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  14269. #region 工单领料SQL
  14270. sqls = @" select
  14271. a.ApplyCode as Code,
  14272. a.InvCode,
  14273. b.InvName,
  14274. b.InvStd,
  14275. b.InvUnit,
  14276. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14277. a.WhCode,
  14278. a.ExtensionID
  14279. FROM
  14280. ICSMOApply a
  14281. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14282. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  14283. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  14284. #endregion
  14285. }
  14286. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  14287. {
  14288. enableCode = "Over003";
  14289. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  14290. #region 工单材料出库SQL
  14291. sqls = @" select
  14292. a.IssueCode as Code,
  14293. a.InvCode,
  14294. b.InvName,
  14295. b.InvStd,
  14296. b.InvUnit,
  14297. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14298. a.WhCode,
  14299. a.ExtensionID
  14300. FROM
  14301. ICSMOIssue a
  14302. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14303. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  14304. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  14305. #endregion
  14306. }
  14307. if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  14308. {
  14309. enableCode = "Over004";
  14310. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  14311. #region 委外备料SQL
  14312. sqls = @" select
  14313. c.OOCode as Code,
  14314. a.InvCode,
  14315. b.InvName,
  14316. b.InvStd,
  14317. b.InvUnit,
  14318. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14319. a.WhCode,
  14320. a.ExtensionID
  14321. FROM
  14322. ICSOOPick a
  14323. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  14324. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14325. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  14326. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  14327. #endregion
  14328. }
  14329. if (TransType == TransTypeEnum.OOApply.GetDescription())
  14330. {
  14331. enableCode = "Over005";
  14332. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  14333. #region 委外领料SQL
  14334. sqls = @" select
  14335. a.ApplyCode as Code,
  14336. a.InvCode,
  14337. b.InvName,
  14338. b.InvStd,
  14339. b.InvUnit,
  14340. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14341. a.WhCode,
  14342. a.ExtensionID
  14343. FROM
  14344. ICSOApply a
  14345. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14346. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  14347. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  14348. #endregion
  14349. }
  14350. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  14351. {
  14352. //enableCode = "Over006";
  14353. excessQtySql = "";
  14354. #region 委外材料出库SQL
  14355. sqls = @" select
  14356. a.IssueCode as Code,
  14357. a.InvCode,
  14358. b.InvName,
  14359. b.InvStd,
  14360. b.InvUnit,
  14361. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14362. a.WhCode,
  14363. a.ExtensionID
  14364. FROM
  14365. ICSOIssue a
  14366. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14367. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  14368. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  14369. #endregion
  14370. }
  14371. if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  14372. {
  14373. enableCode = "";
  14374. excessQtySql = "";
  14375. #region 销售发货SQL
  14376. sqls = @" select
  14377. a.SDNCode as Code,
  14378. a.InvCode,
  14379. b.InvName,
  14380. b.InvStd,
  14381. b.InvUnit,
  14382. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14383. a.WhCode,
  14384. a.ExtensionID
  14385. FROM
  14386. ICSSDN a
  14387. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14388. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  14389. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  14390. #endregion
  14391. }
  14392. if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  14393. {
  14394. enableCode = "";
  14395. excessQtySql = "";
  14396. #region 其它出库SQL
  14397. sqls = @" select
  14398. a.OutCode as Code,
  14399. a.InvCode,
  14400. b.InvName,
  14401. b.InvStd,
  14402. b.InvUnit,
  14403. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14404. a.WhCode,
  14405. a.ExtensionID
  14406. FROM
  14407. ICSOtherOut a
  14408. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14409. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  14410. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  14411. #endregion
  14412. }
  14413. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  14414. {
  14415. enableCode = "";
  14416. excessQtySql = "";
  14417. #region 借用SQL
  14418. sqls = @"select
  14419. a.BrrowCode as Code,
  14420. a.InvCode,
  14421. b.InvName,
  14422. b.InvStd,
  14423. b.InvUnit,
  14424. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14425. a.WhCode,
  14426. a.ExtensionID
  14427. FROM
  14428. ICSBrrow a
  14429. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14430. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  14431. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  14432. #endregion
  14433. }
  14434. if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  14435. {
  14436. enableCode = "";
  14437. excessQtySql = "";
  14438. #region 物料调拨
  14439. sqls = @" select
  14440. a.TransferNO as Code,
  14441. a.InvCode,
  14442. b.InvName,
  14443. b.InvStd,
  14444. b.InvUnit,
  14445. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14446. a.FromWarehouseCode as WhCode,
  14447. a.ExtensionID
  14448. FROM
  14449. ICSTransfer a
  14450. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14451. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  14452. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  14453. #endregion
  14454. }
  14455. if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  14456. {
  14457. enableCode = "";
  14458. excessQtySql = "";
  14459. #region 两步调出
  14460. sqls = @"select
  14461. a.OutCode as Code,
  14462. a.InvCode,
  14463. b.InvName,
  14464. b.InvStd,
  14465. b.InvUnit,
  14466. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  14467. a.WHCode ,
  14468. a.ExtensionID
  14469. from ICSOtherOut a
  14470. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  14471. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  14472. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  14473. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  14474. #endregion
  14475. }
  14476. #endregion
  14477. #region 出库
  14478. #region 采购退货
  14479. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  14480. {
  14481. isDeliveryNotice = true;
  14482. columns = @"a.DNCode AS TransCode,
  14483. a.DNDetailID AS DetailID,
  14484. a.DNType AS Type,
  14485. a.Sequence AS TransSequence,
  14486. a.RCVQuantity AS IssueQuantity,
  14487. a.Quantity,
  14488. a.Amount,
  14489. a.MUSER AS [User],
  14490. a.MTIME AS [MTime],";
  14491. tableName = @"ICSDeliveryNotice a ";
  14492. where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' ";
  14493. }
  14494. #endregion
  14495. #region 委外发料(合并发料)
  14496. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  14497. {
  14498. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode004' and enable = '1'";
  14499. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14500. isMerge = true;
  14501. columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
  14502. a.PickID AS DetailID,
  14503. a.SupplyType AS Type,
  14504. b.Sequence+'~'+a.Sequence AS TransSequence,
  14505. a.IssueQuantity AS IssueQuantity,";
  14506. tableNameMerge = @"ICSOOPick a
  14507. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  14508. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14509. columns = @"b.OOCode AS TransCode,
  14510. a.PickID AS DetailID,
  14511. a.SupplyType AS Type,
  14512. b.Sequence+'~'+a.Sequence AS TransSequence,
  14513. a.IssueQuantity AS IssueQuantity,";
  14514. tableName = @"ICSOOPick a
  14515. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  14516. where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' ";
  14517. }
  14518. #endregion
  14519. #region 委外退货
  14520. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  14521. {
  14522. isDeliveryNotice = true;
  14523. columns = @"a.ODNCode AS TransCode,
  14524. a.ODNDetailID AS DetailID,
  14525. a.ODNType AS Type,
  14526. a.Sequence AS TransSequence,
  14527. a.RCVQuantity AS IssueQuantity,
  14528. a.Quantity,
  14529. a.Amount,
  14530. a.MUSER AS [User],
  14531. a.MTIME AS [MTime],";
  14532. tableName = @"ICSODeliveryNotice a ";
  14533. where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' ";
  14534. }
  14535. #endregion
  14536. #region 生产发料(合并发料)
  14537. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  14538. {
  14539. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
  14540. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14541. isMerge = true;
  14542. columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  14543. a.PickID AS DetailID,
  14544. a.SupplyType AS Type,
  14545. ISNULL(a.EATTRIBUTE2,'') AS JIGOU,
  14546. b.Sequence+'~'+a.Sequence AS TransSequence,
  14547. a.IssueQuantity AS IssueQuantity,";
  14548. tableNameMerge = @"ICSMOPick a
  14549. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  14550. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14551. columns = @"b.MOCode AS TransCode,
  14552. a.PickID AS DetailID,
  14553. a.SupplyType AS Type,
  14554. ISNULL(a.EATTRIBUTE2,'') AS JIGOU,
  14555. b.Sequence+'~'+a.Sequence AS TransSequence,
  14556. a.IssueQuantity AS IssueQuantity,";
  14557. tableName = @"ICSMOPick a
  14558. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  14559. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1'";
  14560. }
  14561. #endregion
  14562. #region 销售出库(合并发料)
  14563. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  14564. {
  14565. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
  14566. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14567. isMerge = true;
  14568. columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
  14569. a.SDNDetailID AS DetailID,
  14570. a.SOCode,
  14571. a.Type,
  14572. a.Sequence AS TransSequence,
  14573. a.SDNQuantity AS IssueQuantity,";
  14574. tableNameMerge = @"ICSSDN a
  14575. INNER JOIN ICSMOPickMerge mer ON a.SDNDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14576. columns = @"a.SDNCode AS TransCode,
  14577. a.SDNDetailID AS DetailID,
  14578. a.SOCode,
  14579. a.Type,
  14580. a.Sequence AS TransSequence,
  14581. a.SDNQuantity AS IssueQuantity,";
  14582. tableName = @"ICSSDN a ";
  14583. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' ";
  14584. }
  14585. #endregion
  14586. #region 盘点
  14587. else if (TransType == TransTypeEnum.Check.GetDescription())
  14588. {
  14589. #region SLQ
  14590. sql = @"SELECT a.ID,
  14591. {0}
  14592. a.Quantity,
  14593. a.SelectLevel AS LocationCode,
  14594. a.Amount,
  14595. a.MUSER AS [User],
  14596. a.MTIME AS [MTime]
  14597. FROM {1}
  14598. WHERE {2} ";
  14599. #endregion
  14600. columns = @"a.CheckCode AS TransCode,
  14601. a.ID,
  14602. '' AS Type,";
  14603. tableName = @"ICSCheck a ";
  14604. where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' ";
  14605. }
  14606. #endregion
  14607. #region 一步调拨(合并发料)
  14608. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  14609. {
  14610. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
  14611. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14612. isMerge = true;
  14613. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  14614. a.TransferDetailID AS DetailID,
  14615. '' AS Type,
  14616. a.Sequence AS TransSequence,
  14617. a.TransferQuantity AS IssueQuantity,
  14618. a.ToWarehouseCode,";
  14619. tableNameMerge = @"ICSTransfer a
  14620. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14621. #region SLQ
  14622. sql = @"SELECT a.ID,
  14623. {0}
  14624. convert(varchar(100),'') AS LocationCode,
  14625. convert(varchar(100),'') AS LotNo,
  14626. 0 AS LocationQty,
  14627. 0 AS isMatched,
  14628. a.InvCode,
  14629. inv.InvName,
  14630. inv.InvStd,
  14631. a.Quantity,
  14632. inv.InvUnit,
  14633. a.Amount,
  14634. a.FromWarehouseCode AS WHCode,
  14635. inv.AmountUnit,
  14636. wh.WarehouseName AS WHName,
  14637. a.ExtensionID,
  14638. ext.ProjectCode,
  14639. 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,
  14640. ext.Version,
  14641. ext.Brand,
  14642. ext.cFree1,
  14643. ext.cFree2,
  14644. ext.cFree3,
  14645. ext.cFree4,
  14646. ext.cFree5,
  14647. ext.cFree6,
  14648. ext.cFree7,
  14649. ext.cFree8,
  14650. ext.cFree9,
  14651. ext.cFree10,
  14652. a.MUSER AS [User],
  14653. a.MTIME AS [MTime]
  14654. FROM {1}
  14655. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  14656. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  14657. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  14658. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  14659. WHERE {2} ";
  14660. #endregion
  14661. columns = @"a.TransferNO AS TransCode,
  14662. a.TransferDetailID AS DetailID,
  14663. '' AS Type,
  14664. a.Sequence AS TransSequence,
  14665. a.TransferQuantity AS IssueQuantity,
  14666. a.ToWarehouseCode,";
  14667. tableName = @"ICSTransfer a ";
  14668. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' ";
  14669. }
  14670. #endregion
  14671. #region 调拨申请单(领料)
  14672. else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
  14673. {
  14674. isMerge = true;
  14675. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  14676. a.TransferDetailID AS DetailID,
  14677. '' AS Type,
  14678. a.Sequence AS TransSequence,
  14679. a.TransferQuantity AS IssueQuantity,
  14680. a.ToWarehouseCode,";
  14681. tableNameMerge = @"ICSTransferApplication a
  14682. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14683. #region SLQ
  14684. sql = @"SELECT a.ID,
  14685. {0}
  14686. convert(varchar(100),'') AS LocationCode,
  14687. convert(varchar(100),'') AS LotNo,
  14688. 0 AS LocationQty,
  14689. 0 AS isMatched,
  14690. a.InvCode,
  14691. inv.InvName,
  14692. inv.InvStd,
  14693. a.Quantity,
  14694. inv.InvUnit,
  14695. a.Amount,
  14696. a.FromWarehouseCode AS WHCode,
  14697. inv.AmountUnit,
  14698. wh.WarehouseName AS WHName,
  14699. a.ExtensionID,
  14700. ext.ProjectCode,
  14701. 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,
  14702. ext.Version,
  14703. ext.Brand,
  14704. ext.cFree1,
  14705. ext.cFree2,
  14706. ext.cFree3,
  14707. ext.cFree4,
  14708. ext.cFree5,
  14709. ext.cFree6,
  14710. ext.cFree7,
  14711. ext.cFree8,
  14712. ext.cFree9,
  14713. ext.cFree10,
  14714. a.MUSER AS [User],
  14715. a.MTIME AS [MTime]
  14716. FROM {1}
  14717. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  14718. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  14719. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  14720. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  14721. WHERE {2} ";
  14722. #endregion
  14723. columns = @"a.TransferNO AS TransCode,
  14724. a.TransferDetailID AS DetailID,
  14725. '' AS Type,
  14726. a.Sequence AS TransSequence,
  14727. a.TransferQuantity AS IssueQuantity,
  14728. a.ToWarehouseCode,";
  14729. tableName = @"ICSTransferApplication a ";
  14730. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' ";
  14731. }
  14732. #endregion
  14733. #region 调拨(合并发料)
  14734. else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
  14735. {
  14736. }
  14737. #endregion
  14738. #region 两步调出(合并发料)
  14739. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  14740. {
  14741. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode010' and enable = '1'";
  14742. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14743. isMerge = true;
  14744. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  14745. a.OutDetailID AS DetailID,
  14746. '' AS Type,
  14747. a.Sequence AS TransSequence,
  14748. a.OutQuantity AS IssueQuantity,";
  14749. tableNameMerge = @"ICSOtherOut a
  14750. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  14751. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14752. columns = @"a.OutCode AS TransCode,
  14753. a.OutDetailID AS DetailID,
  14754. '' AS Type,
  14755. a.Sequence AS TransSequence,
  14756. a.OutQuantity AS IssueQuantity,";
  14757. tableName = @"ICSOtherOut a
  14758. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  14759. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' ";
  14760. }
  14761. #endregion
  14762. #region 其他出库(合并发料)
  14763. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  14764. {
  14765. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
  14766. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14767. isMerge = true;
  14768. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  14769. a.OutDetailID AS DetailID,
  14770. '' AS Type,
  14771. a.Sequence AS TransSequence,
  14772. a.OutQuantity AS IssueQuantity,";
  14773. tableNameMerge = @"ICSOtherOut a
  14774. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14775. columns = @"a.OutCode AS TransCode,
  14776. a.OutDetailID AS DetailID,
  14777. '' AS Type,
  14778. a.Sequence AS TransSequence,
  14779. a.OutQuantity AS IssueQuantity,";
  14780. tableName = @"ICSOtherOut a ";
  14781. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' ";
  14782. }
  14783. #endregion
  14784. #region 领料申请单发料(合并发料)
  14785. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  14786. {
  14787. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode002' and enable = '1'";
  14788. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14789. isMerge = true;
  14790. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  14791. a.ApplyDetailID AS DetailID,
  14792. a.Type,
  14793. a.Sequence AS TransSequence,
  14794. a.IssueQuantity AS IssueQuantity,";
  14795. tableNameMerge = @"ICSMOApply a
  14796. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14797. columns = @"a.ApplyCode AS TransCode,
  14798. a.ApplyDetailID AS DetailID,
  14799. a.Type,
  14800. a.Sequence AS TransSequence,
  14801. a.IssueQuantity AS IssueQuantity,";
  14802. tableName = @"ICSMOApply a ";
  14803. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' ";
  14804. }
  14805. #endregion
  14806. #region 补料申请单发料(合并发料)
  14807. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  14808. {
  14809. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode012' and enable = '1'";
  14810. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14811. isMerge = true;
  14812. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  14813. a.ApplyDetailID AS DetailID,
  14814. a.Type,
  14815. a.Sequence AS TransSequence,
  14816. a.IssueQuantity AS IssueQuantity,";
  14817. tableNameMerge = @"ICSMOReplenishment a
  14818. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14819. columns = @"a.ReplenishmentCode AS TransCode,
  14820. a.ReplenishmentDetailID AS DetailID,
  14821. a.Type,
  14822. a.Sequence AS TransSequence,
  14823. a.IssueQuantity AS IssueQuantity,";
  14824. tableName = @"ICSMOReplenishment a ";
  14825. where = @" a.ReplenishmentCode='{0}' AND a.WorkPoint='{1}' ";
  14826. }
  14827. #endregion
  14828. #region 委外领料申请单发料(合并发料)
  14829. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  14830. {
  14831. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode005' and enable = '1'";
  14832. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14833. isMerge = true;
  14834. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  14835. a.ApplyDetailID AS DetailID,
  14836. a.Type,
  14837. a.Sequence AS TransSequence,
  14838. a.IssueQuantity AS IssueQuantity,";
  14839. tableNameMerge = @"ICSOApply a
  14840. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14841. columns = @"a.ApplyCode AS TransCode,
  14842. a.ApplyDetailID AS DetailID,
  14843. a.Type,
  14844. a.Sequence AS TransSequence,
  14845. a.IssueQuantity AS IssueQuantity,";
  14846. tableName = @"ICSOApply a ";
  14847. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' ";
  14848. }
  14849. #endregion
  14850. #region 开立材料出库(合并发料)
  14851. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  14852. {
  14853. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode003' and enable = '1'";
  14854. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14855. isMerge = true;
  14856. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  14857. a.IssueDetailID AS DetailID,
  14858. a.Type,
  14859. a.Sequence AS TransSequence,
  14860. a.IssueQuantity AS IssueQuantity,";
  14861. tableNameMerge = @"ICSMOIssue a
  14862. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14863. columns = @"a.IssueCode AS TransCode,
  14864. a.IssueDetailID AS DetailID,
  14865. a.Type,
  14866. a.Sequence AS TransSequence,
  14867. a.IssueQuantity AS IssueQuantity,";
  14868. tableName = @"ICSMOIssue a ";
  14869. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' ";
  14870. }
  14871. #endregion
  14872. #region 开立委外材料出库(合并发料)
  14873. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  14874. {
  14875. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode006' and enable = '1'";
  14876. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14877. isMerge = true;
  14878. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  14879. a.IssueDetailID AS DetailID,
  14880. a.Type,
  14881. a.Sequence AS TransSequence,
  14882. a.IssueQuantity AS IssueQuantity,";
  14883. tableNameMerge = @"ICSOIssue a
  14884. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14885. columns = @"a.IssueCode AS TransCode,
  14886. a.IssueDetailID AS DetailID,
  14887. a.Type,
  14888. a.Sequence AS TransSequence,
  14889. a.IssueQuantity AS IssueQuantity,";
  14890. tableName = @"ICSOIssue a ";
  14891. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' ";
  14892. }
  14893. #endregion
  14894. #region 开立红字入库单
  14895. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  14896. {
  14897. columns = @"a.RCVCode AS TransCode,
  14898. a.RCVDetailID AS DetailID,
  14899. a.Type,
  14900. a.Sequence AS TransSequence,
  14901. a.RCVQuantity AS IssueQuantity,";
  14902. tableName = @"ICSPurchaseReceive a ";
  14903. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  14904. }
  14905. #endregion
  14906. #region 开立委外红字入库单
  14907. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  14908. {
  14909. columns = @"a.RCVCode AS TransCode,
  14910. a.RCVDetailID AS DetailID,
  14911. a.Type,
  14912. a.Sequence AS TransSequence,
  14913. a.RCVQuantity AS IssueQuantity,";
  14914. tableName = @"ICSOutsourcingReceive a ";
  14915. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  14916. }
  14917. #endregion
  14918. #region 借用(合并发料)
  14919. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  14920. {
  14921. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode011' and enable = '1'";
  14922. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14923. isMerge = true;
  14924. columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
  14925. a.BrrowDetailID AS DetailID,
  14926. '' AS Type,
  14927. a.Sequence AS TransSequence,
  14928. a.BrrowQuantity AS IssueQuantity,";
  14929. tableNameMerge = @"ICSBrrow a
  14930. INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14931. columns = @"a.BrrowCode AS TransCode,
  14932. a.BrrowDetailID AS DetailID,
  14933. '' AS Type,
  14934. a.Sequence AS TransSequence,
  14935. a.BrrowQuantity AS IssueQuantity,";
  14936. tableName = @"ICSBrrow a ";
  14937. where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' ";
  14938. }
  14939. #endregion
  14940. #region 送货单
  14941. else if (TransType == TransTypeEnum.ASN.GetDescription())
  14942. {
  14943. isDeliveryNotice = true;
  14944. columns = @"asn.ASNCode AS TransCode,
  14945. asn.ID AS DetailID,
  14946. asn.LotNo,
  14947. '' AS Type,
  14948. asn.Sequence AS TransSequence,
  14949. asn.DNQuantity AS IssueQuantity,
  14950. asn.Quantity,
  14951. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  14952. asn.MUSER AS [User],
  14953. asn.MTIME AS [MTime],";
  14954. tableName = @"ICSInventoryLot a
  14955. INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  14956. where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
  14957. }
  14958. #endregion
  14959. #region 委外送货单
  14960. else if (TransType == TransTypeEnum.OASN.GetDescription())
  14961. {
  14962. isDeliveryNotice = true;
  14963. columns = @"asn.OASNCode AS TransCode,
  14964. asn.ID AS DetailID,
  14965. asn.LotNo,
  14966. '' AS Type,
  14967. asn.Sequence AS TransSequence,
  14968. asn.ODNQuantity AS IssueQuantity,
  14969. asn.Quantity,
  14970. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  14971. asn.MUSER AS [User],
  14972. asn.MTIME AS [MTime],";
  14973. tableName = @"ICSInventoryLot a
  14974. INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  14975. where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
  14976. }
  14977. #endregion
  14978. #endregion
  14979. #region 入库
  14980. #region 采购入库
  14981. else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  14982. {
  14983. }
  14984. #endregion
  14985. #region 审核的到货单
  14986. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  14987. {//扫描到货单 带出检验合格条码数量 且不再库存的条码 --东辉扫描到货单入库 cjw
  14988. isDeliveryNotice = true;
  14989. columns = @"DN.DNCode AS TransCode,
  14990. ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  14991. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  14992. a.LotNo,
  14993. '' AS Type,
  14994. DN.Sequence AS TransSequence,
  14995. DN.DNQuantity AS IssueQuantity,
  14996. DN.Quantity,
  14997. DN.MUSER AS [User],
  14998. DN.MTIME AS [MTime],";
  14999. tableName = @"ICSInventoryLot a
  15000. inner join ICSInventoryLotDetail det on a.lotno = det.lotno AND a.WorkPoint=det.WorkPoint
  15001. inner join ICSDeliveryNotice on DN.DNCode= det.TransCode and DN.Sequence = det.TransSequence aND DN.WorkPoint=det.WorkPoint AND DN.DNTYPE =1
  15002. inner join ICSInspection ins on INS.lotno = a.lotno and a.workpoint = ins.workpoint
  15003. LEFT JOIN ICSWareHouseLotInfo lotinfo on a.lotno = lotinfo.lotno AND a.WorkPoint=lotinfo.WorkPoint
  15004. ";
  15005. where = @" DN.DNCode='{0}' AND a.WorkPoint='{1}' and lotinfo.id is null ";
  15006. }
  15007. #endregion
  15008. #region 采购拒收
  15009. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  15010. {
  15011. }
  15012. #endregion
  15013. #region 审核的委外到货单
  15014. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  15015. {
  15016. }
  15017. #endregion
  15018. #region 委外拒收
  15019. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  15020. {
  15021. }
  15022. #endregion
  15023. #region 委外退料
  15024. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  15025. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  15026. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  15027. {
  15028. }
  15029. #endregion
  15030. #region 委外入库
  15031. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  15032. {
  15033. }
  15034. #endregion
  15035. #region 生产退料
  15036. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  15037. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  15038. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  15039. {
  15040. }
  15041. #endregion
  15042. #region 生产入库
  15043. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  15044. {
  15045. }
  15046. #endregion
  15047. #region 开立的生产入库单
  15048. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  15049. {
  15050. }
  15051. #endregion
  15052. #region 返工工单
  15053. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  15054. {
  15055. }
  15056. #endregion
  15057. #region 销售退货
  15058. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  15059. {
  15060. }
  15061. #endregion
  15062. #region 两步调入
  15063. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  15064. {
  15065. columns = @"a.InCode AS TransCode,
  15066. a.InDetailID AS DetailID,
  15067. '' AS Type,
  15068. a.Sequence AS TransSequence,
  15069. a.InQuantity AS IssueQuantity,";
  15070. tableName = @"ICSOtherIn a
  15071. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  15072. where = @" a.InCode='{0}' AND a.WorkPoint='{1}' ";
  15073. }
  15074. #endregion
  15075. #region 销售退货-原条码
  15076. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  15077. {
  15078. columns = @"a.SDNCode AS TransCode,
  15079. a.SDNDetailID AS DetailID,
  15080. a.Type,
  15081. a.Sequence AS TransSequence,
  15082. a.SDNQuantity AS IssueQuantity,";
  15083. tableName = @"ICSSDN a ";
  15084. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  15085. }
  15086. #endregion
  15087. #region 其他入库
  15088. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  15089. {
  15090. }
  15091. #endregion
  15092. #region 拆卸单
  15093. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  15094. {
  15095. columns = @"a.DABDOCCode AS TransCode,
  15096. a.DABDOCDetailID AS DetailID,
  15097. a.DABDOCType AS Type,
  15098. a.Sequence AS TransSequence,
  15099. a.DABDOCQuantity AS IssueQuantity,";
  15100. tableName = @"ICSDisassemblyDoc a";
  15101. where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' ";
  15102. }
  15103. #endregion
  15104. #region 归还
  15105. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  15106. {
  15107. }
  15108. #endregion
  15109. #endregion
  15110. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
  15111. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  15112. #region 判断是否启用匹配库位
  15113. if (flag != null && flag.Rows.Count > 0)
  15114. //if (true)
  15115. {
  15116. sql = @"select * into #maintemp from (" + sql + @")a
  15117. select * into #resulttemp from #maintemp
  15118. truncate table #resulttemp
  15119. select a.lotno,a.locationcode,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime,a.warehousecode,isnull(ext.ProjectCode,'')as ProjectCode, isnull(ext.Version,'')as Version,
  15120. isnull(ext.Brand,'')as Brand,
  15121. isnull(ext.cFree1,'')as cFree1,
  15122. isnull(ext.cFree2,'') cFree2,
  15123. isnull(ext.cFree3,'') cFree3,
  15124. isnull(ext.cFree4,'') cFree4,
  15125. isnull(ext.cFree5,'') cFree5,
  15126. isnull(ext.cFree6,'') cFree6,
  15127. isnull(ext.cFree7,'') cFree7,
  15128. isnull(ext.cFree8,'') cFree8,
  15129. isnull(ext.cFree9,'') cFree9,
  15130. isnull(ext.cFree10,'') cFree10,ISNULL(ext.BatchCode, '') BatchCode into #barcodetemp
  15131. from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  15132. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  15133. LEFT JOIN
  15134. (select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp
  15135. group by invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE) b on a.invcode = b.invcode
  15136. where (a.warehousecode = b.whcode or ISNULL(b.whcode,'')='') and a.Quantity-a.lockQuantity>0 and
  15137. isnull(ext.ProjectCode,'') = b.ProjectCode and isnull(ext.Version,'')=b.Version and
  15138. isnull(ext.Brand,'') =b.Brand and
  15139. isnull(ext.cFree1,'')=b.cFree1 and
  15140. isnull(ext.cFree2,'')=b.cFree2 and
  15141. isnull(ext.cFree3,'')=b.cFree3 and
  15142. isnull(ext.cFree4,'')=b.cFree4 and
  15143. isnull(ext.cFree5,'')=b.cFree5 and
  15144. isnull(ext.cFree6,'')=b.cFree6 and
  15145. isnull(ext.cFree7,'')=b.cFree7 and
  15146. isnull(ext.cFree8,'')=b.cFree8 and
  15147. isnull(ext.cFree9,'')=b.cFree9 and
  15148. isnull(ext.cFree10,'')=b.cFree10 and
  15149. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =ext.BatchCode) or isnull(b.BatchCode,'') ='')
  15150. BEGIN
  15151. DECLARE @transSequence VARCHAR(50);--
  15152. DECLARE @qty decimal(18, 4);--
  15153. DECLARE @needqty decimal(18, 4);--
  15154. DECLARE @lotno VARCHAR(50);--
  15155. DECLARE @locationcode VARCHAR(50);--
  15156. DECLARE @WHCode VARCHAR(50);--
  15157. DECLARE @invcode VARCHAR(50);--
  15158. DECLARE @issueQuantity decimal(18, 4);
  15159. DECLARE tempCursor CURSOR FOR (select transSequence from #maintemp); --tempCursor
  15160. OPEN tempCursor; --
  15161. FETCH NEXT FROM tempCursor INTO @transSequence; --
  15162. WHILE @@fetch_status=0
  15163. BEGIN
  15164. select @needqty=Quantity,@issueQuantity=issueQuantity from #maintemp where transSequence = @transSequence
  15165. PRINT @transSequence
  15166. WHILE @needqty>0
  15167. BEGIN
  15168. select top 1 @qty = isnull(a.quantity,0), @locationcode = isnull(a.locationcode,''),@lotno = isnull(a.lotno,''),@WHCode = isnull(a.warehousecode,''),@invcode = b.invcode from #barcodetemp a
  15169. right JOIN(select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp where transSequence=@transSequence)b on a.invcode = b.invcode
  15170. and ((isnull(b.ProjectCode,'')<>'' and b.ProjectCode = a.ProjectCode) or isnull(b.ProjectCode,'') ='') and
  15171. ((isnull(b.Version,'')<>'' and b.Version = a.Version) or isnull(b.Version,'') ='') and
  15172. ((isnull(b.Brand,'')<>'' and b.Brand = a.Brand )or isnull(b.Brand,'') ='') and
  15173. ((isnull(b.cFree1,'')<>'' and b.cFree1 =a.cFree1) or isnull(b.cFree1,'') ='') and
  15174. ((isnull(b.cFree2,'')<>'' and b.cFree2 =a.cFree2 )or isnull(b.cFree2,'') ='') and
  15175. ((isnull(b.cFree3,'')<>'' and b.cFree3 =a.cFree3 )or isnull(b.cFree3,'') ='') and
  15176. ((isnull(b.cFree4,'')<>'' and b.cFree4 =a.cFree4 )or isnull(b.cFree4,'') ='') and
  15177. ((isnull(b.cFree5,'')<>'' and b.cFree5 =a.cFree5) or isnull(b.cFree5,'') ='') and
  15178. ((isnull(b.cFree6,'')<>'' and b.cFree6 =a.cFree6 )or isnull(b.cFree6,'') ='') and
  15179. ((isnull(b.cFree7,'')<>'' and b.cFree7 =a.cFree7) or isnull(b.cFree7,'') ='') and
  15180. ((isnull(b.cFree8,'')<>'' and b.cFree8 =a.cFree8) or isnull(b.cFree8,'') ='') and
  15181. ((isnull(b.cFree9,'')<>'' and b.cFree9 =a.cFree9) or isnull(b.cFree9,'') ='') and
  15182. ((isnull(b.cFree10,'')<>'' and b.cFree10 =a.cFree10) or isnull(b.cFree10,'') ='') and
  15183. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =a.BatchCode) or isnull(b.BatchCode,'') ='')ORDER BY mtime,locationcode
  15184. IF(@needqty-@issueQuantity-@qty>=0 and ISNULL(@lotno, '')<>'')
  15185. BEGIN
  15186. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  15187. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotNo,
  15188. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  15189. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  15190. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),@qty,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  15191. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  15192. delete from #barcodetemp where lotno = @lotno
  15193. SET @needqty=@needqty-@qty
  15194. END
  15195. ELSE if(@needqty-@issueQuantity-@qty<0 and ISNULL(@lotno, '')<>''and @needqty-@issueQuantity>0)
  15196. BEGIN
  15197. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  15198. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  15199. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  15200. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  15201. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),case WHEN ISNULL(@qty, 0)=0 THEN 0 else @needqty-@issueQuantity end ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  15202. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  15203. update #barcodetemp set quantity = @qty-@needqty+-@issueQuantity where lotno = @lotno
  15204. SET @needqty=@needqty-@issueQuantity-@qty
  15205. END
  15206. ELSE
  15207. BEGIN
  15208. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  15209. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  15210. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  15211. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  15212. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),0 ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  15213. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  15214. SET @needqty=0
  15215. END
  15216. END
  15217. FETCH NEXT FROM tempCursor INTO @transSequence;
  15218. END
  15219. CLOSE tempCursor
  15220. DEALLOCATE tempCursor
  15221. END
  15222. select id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  15223. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,sum(LocationQty)as LocationQty,isMatched,AmountUnit,--lotno,
  15224. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #resulttemp GROUP BY id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  15225. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,isMatched,AmountUnit,--lotno,
  15226. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ORDER BY locationcode ASC ,InvCode ASC
  15227. DROP table #maintemp
  15228. DROP table #resulttemp
  15229. DROP table #barcodetemp";
  15230. }
  15231. #endregion
  15232. if (isDeliveryNotice)//送货、到货、含委外
  15233. {
  15234. #region SLQ
  15235. sql = sqlCheck + @"SELECT a.ID,
  15236. {0}
  15237. a.InvCode,
  15238. inv.InvName,
  15239. inv.InvStd,
  15240. inv.InvUnit,
  15241. '' AS WHCode,
  15242. inv.AmountUnit,
  15243. '' AS WHName,
  15244. a.ExtensionID,
  15245. ext.ProjectCode,
  15246. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  15247. ext.Version,
  15248. ext.Brand,
  15249. ext.cFree1,
  15250. ext.cFree2,
  15251. ext.cFree3,
  15252. ext.cFree4,
  15253. ext.cFree5,
  15254. ext.cFree6,
  15255. ext.cFree7,
  15256. ext.cFree8,
  15257. ext.cFree9,
  15258. ext.cFree10
  15259. FROM {1}
  15260. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  15261. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  15262. WHERE {2} ";
  15263. #endregion
  15264. }
  15265. else if (isMerge)//合并发料
  15266. {
  15267. #region SLQ
  15268. string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='" + JsonData.TransCode + "' AND WorkPoint='" + JsonData.WorkPoint + "'";
  15269. DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
  15270. if (sign != null && sign.Rows.Count > 0)
  15271. {
  15272. string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
  15273. sql = string.Format(sql, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, excessQtySql);
  15274. }
  15275. else
  15276. {
  15277. sql = @" BEGIN
  15278. IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
  15279. BEGIN
  15280. RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
  15281. RETURN
  15282. END
  15283. " + sqlCheck + sql + @"
  15284. END";
  15285. }
  15286. #endregion
  15287. }
  15288. else
  15289. {
  15290. sql = sqlCheck + sql;
  15291. }
  15292. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint);
  15293. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode, excessQtySql);
  15294. sqls = string.Format(sqls, JsonData.TransCode, JsonData.WorkPoint);
  15295. Picksql = string.Format(Picksql, sqls, JsonData.WorkPoint);
  15296. //DataTable table2 = DBHelper.SQlReturnData(Picksql, cmd);
  15297. //return table2;
  15298. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  15299. return table;
  15300. }
  15301. catch (Exception ex)
  15302. {
  15303. log.Error(ex.Message);
  15304. throw new Exception(ex.Message);
  15305. }
  15306. finally
  15307. {
  15308. if (conn.State == ConnectionState.Open)
  15309. {
  15310. conn.Close();
  15311. }
  15312. conn.Dispose();
  15313. }
  15314. }
  15315. }
  15316. #endregion
  15317. #region 源头单据信息(奥美专用)
  15318. /// <summary>
  15319. /// 源头单据信息(奥美专用)
  15320. /// </summary>
  15321. /// <param name="JsonData"></param>
  15322. /// <returns></returns>
  15323. public static DataTable AMTransInformationGet(WMSSourceDocumentModel JsonData)
  15324. {
  15325. var language = LanguageHelper.GetName("WMSAPIInfo");
  15326. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  15327. {
  15328. conn.Open();
  15329. SqlCommand cmd = new SqlCommand();
  15330. cmd.Connection = conn;
  15331. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  15332. try
  15333. {
  15334. if (string.IsNullOrEmpty(JsonData.TransCode))
  15335. {
  15336. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  15337. }
  15338. else if (string.IsNullOrEmpty(JsonData.TransType))
  15339. {
  15340. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  15341. }
  15342. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  15343. {
  15344. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  15345. }
  15346. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  15347. {
  15348. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  15349. }
  15350. string TransType = JsonData.TransType;
  15351. #region SLQ
  15352. string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  15353. BEGIN
  15354. RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  15355. RETURN
  15356. END
  15357. ";
  15358. string sql = @"SELECT a.ID,
  15359. {0}
  15360. convert(varchar(100),'') AS LocationCode,
  15361. convert(varchar(100),'') AS LotNo,
  15362. convert(varchar(10),'') AS ToWarehouseCode,
  15363. 0 AS LocationQty,
  15364. 0 AS isMatched,
  15365. a.InvCode,
  15366. inv.InvName,
  15367. inv.InvStd,
  15368. a.Quantity,
  15369. inv.InvUnit,
  15370. a.Amount,
  15371. a.WHCode,
  15372. inv.AmountUnit,
  15373. wh.WarehouseName AS WHName,
  15374. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  15375. a.ExtensionID,
  15376. 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,
  15377. ISNULL(ext.Version, '') AS Version,
  15378. ISNULL(ext.Brand, '') AS Brand,
  15379. ISNULL(ext.cFree1, '') AS cFree1,
  15380. ISNULL(ext.cFree2, '') AS cFree2,
  15381. ISNULL(ext.cFree3, '') AS cFree3,
  15382. ISNULL(ext.cFree4, '') AS cFree4,
  15383. ISNULL(ext.cFree5, '') AS cFree5,
  15384. ISNULL(ext.cFree6, '') AS cFree6,
  15385. ISNULL(ext.cFree7, '') AS cFree7,
  15386. ISNULL(ext.cFree8, '') AS cFree8,
  15387. ISNULL(ext.cFree9, '') AS cFree9,
  15388. ISNULL(ext.cFree10, '') AS cFree10,
  15389. a.MUSER AS [User],
  15390. a.MTIME AS [MTime]
  15391. {4}
  15392. FROM {1}
  15393. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  15394. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  15395. LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15396. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  15397. WHERE {2} ";
  15398. string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  15399. c.Code,
  15400. c.InvCode,
  15401. c.InvName,
  15402. c.InvStd,
  15403. c.InvUnit,
  15404. FLOOR(c.iQuantity) AS iQuantity,
  15405. d.WarehouseCode,
  15406. d.LocationCode,
  15407. d.LotNO,
  15408. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  15409. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  15410. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  15411. FROM
  15412. ({0}) c
  15413. LEFT JOIN ICSWareHouseLotInfo d ON c.InvCode=d.INVCode AND ((LEN(ISNULL(c.WHCode,''))<=0) OR (LEN(ISNULL(c.WHCode,''))>0) AND c.WhCode=d.WarehouseCode) AND d.WorkPoint='{1}' AND d.Quantity>0
  15414. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  15415. LEFT JOIN (SELECT INVCode,WarehouseCode,SUM(Quantity) AS QTYTotal FROM ICSWareHouseLotInfo WHERE WorkPoint='{1}' GROUP BY INVCode,WarehouseCode) f ON c.InvCode=f.INVCode AND c.WhCode=f.WarehouseCode
  15416. DECLARE @ItemCode VARCHAR(50),
  15417. @QTY DECIMAL(18,3),
  15418. @ItemCodeCurrent VARCHAR(50),
  15419. @QTYCurrent DECIMAL(18,3),
  15420. @iQuantityCurrent DECIMAL(18,3),
  15421. @CanDelete BIT,
  15422. @Row INT,
  15423. @rowCurrent INT
  15424. SET @Row = @@rowcount
  15425. SET @rowCurrent=1
  15426. SET @CanDelete=0
  15427. SET @ItemCode=''
  15428. WHILE @rowCurrent<=@Row
  15429. BEGIN
  15430. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  15431. PRINT(@rowCurrent)
  15432. IF @ItemCode<>@ItemCodeCurrent
  15433. BEGIN
  15434. SET @ItemCode=@ItemCodeCurrent
  15435. SET @QTY=0
  15436. SET @CanDelete=0
  15437. END
  15438. IF @CanDelete=1
  15439. BEGIN
  15440. DELETE FROM #temp WHERE rowNo=@rowCurrent
  15441. SET @rowCurrent += 1
  15442. CONTINUE
  15443. END
  15444. SET @QTY += @QTYCurrent
  15445. IF @QTY>=@iQuantityCurrent
  15446. BEGIN
  15447. SET @CanDelete=1
  15448. END
  15449. SET @rowCurrent += 1
  15450. END
  15451. SELECT * FROM #temp
  15452. DROP TABLE #temp
  15453. ";
  15454. #endregion
  15455. bool isDeliveryNotice = false; //送货、到货、含委外
  15456. string columns = string.Empty; //查询源头单据表的特殊列名
  15457. string tableName = string.Empty; //查询源头单据表名
  15458. string where = string.Empty; //查询源头单据的过滤条件
  15459. bool isMerge = false; //合并发料
  15460. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  15461. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  15462. string sqls = string.Empty;
  15463. string sqlCheckSign = "";
  15464. DataTable flag = null;
  15465. #region 检料表信息
  15466. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  15467. {
  15468. enableCode = "Over001";
  15469. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  15470. #region 工单备料sql
  15471. sqls = @" SELECT
  15472. c.MOCode as Code,
  15473. a.InvCode,
  15474. b.InvName,
  15475. b.InvStd,
  15476. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15477. a.WhCode,
  15478. b.InvUnit,
  15479. a.ExtensionID
  15480. FROM
  15481. ICSMOPick a
  15482. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  15483. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15484. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  15485. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  15486. #endregion
  15487. }
  15488. if (TransType == TransTypeEnum.MOApply.GetDescription())
  15489. {
  15490. enableCode = "Over002";
  15491. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  15492. #region 工单领料SQL
  15493. sqls = @" select
  15494. a.ApplyCode as Code,
  15495. a.InvCode,
  15496. b.InvName,
  15497. b.InvStd,
  15498. b.InvUnit,
  15499. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15500. a.WhCode,
  15501. a.ExtensionID
  15502. FROM
  15503. ICSMOApply a
  15504. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15505. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  15506. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  15507. #endregion
  15508. }
  15509. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  15510. {
  15511. //enableCode = "Over003";
  15512. excessQtySql = "";
  15513. #region 工单材料出库SQL
  15514. sqls = @" select
  15515. a.IssueCode as Code,
  15516. a.InvCode,
  15517. b.InvName,
  15518. b.InvStd,
  15519. b.InvUnit,
  15520. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15521. a.WhCode,
  15522. a.ExtensionID
  15523. FROM
  15524. ICSMOIssue a
  15525. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15526. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  15527. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  15528. #endregion
  15529. }
  15530. if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  15531. {
  15532. enableCode = "Over004";
  15533. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  15534. #region 委外备料SQL
  15535. sqls = @" select
  15536. c.OOCode as Code,
  15537. a.InvCode,
  15538. b.InvName,
  15539. b.InvStd,
  15540. b.InvUnit,
  15541. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15542. a.WhCode,
  15543. a.ExtensionID
  15544. FROM
  15545. ICSOOPick a
  15546. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  15547. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15548. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  15549. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  15550. #endregion
  15551. }
  15552. if (TransType == TransTypeEnum.OOApply.GetDescription())
  15553. {
  15554. enableCode = "Over005";
  15555. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Quantity, a.WorkPoint,'" + enableCode + "',2,2,inv.ID)) AS excessQty";
  15556. #region 委外领料SQL
  15557. sqls = @" select
  15558. a.ApplyCode as Code,
  15559. a.InvCode,
  15560. b.InvName,
  15561. b.InvStd,
  15562. b.InvUnit,
  15563. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15564. a.WhCode,
  15565. a.ExtensionID
  15566. FROM
  15567. ICSOApply a
  15568. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15569. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  15570. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  15571. #endregion
  15572. }
  15573. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  15574. {
  15575. //enableCode = "Over006";
  15576. excessQtySql = "";
  15577. #region 委外材料出库SQL
  15578. sqls = @" select
  15579. a.IssueCode as Code,
  15580. a.InvCode,
  15581. b.InvName,
  15582. b.InvStd,
  15583. b.InvUnit,
  15584. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15585. a.WhCode,
  15586. a.ExtensionID
  15587. FROM
  15588. ICSOIssue a
  15589. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15590. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  15591. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  15592. #endregion
  15593. }
  15594. if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  15595. {
  15596. enableCode = "";
  15597. excessQtySql = "";
  15598. #region 销售发货SQL
  15599. sqls = @" select
  15600. a.SDNCode as Code,
  15601. a.InvCode,
  15602. b.InvName,
  15603. b.InvStd,
  15604. b.InvUnit,
  15605. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15606. a.WhCode,
  15607. a.ExtensionID
  15608. FROM
  15609. ICSSDN a
  15610. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15611. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  15612. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  15613. #endregion
  15614. }
  15615. if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  15616. {
  15617. enableCode = "";
  15618. excessQtySql = "";
  15619. #region 其它出库SQL
  15620. sqls = @" select
  15621. a.OutCode as Code,
  15622. a.InvCode,
  15623. b.InvName,
  15624. b.InvStd,
  15625. b.InvUnit,
  15626. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15627. a.WhCode,
  15628. a.ExtensionID
  15629. FROM
  15630. ICSOtherOut a
  15631. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15632. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  15633. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  15634. #endregion
  15635. }
  15636. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  15637. {
  15638. enableCode = "";
  15639. excessQtySql = "";
  15640. #region 借用SQL
  15641. sqls = @"select
  15642. a.BrrowCode as Code,
  15643. a.InvCode,
  15644. b.InvName,
  15645. b.InvStd,
  15646. b.InvUnit,
  15647. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15648. a.WhCode,
  15649. a.ExtensionID
  15650. FROM
  15651. ICSBrrow a
  15652. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15653. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  15654. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  15655. #endregion
  15656. }
  15657. if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  15658. {
  15659. enableCode = "";
  15660. excessQtySql = "";
  15661. #region 物料调拨
  15662. sqls = @" select
  15663. a.TransferNO as Code,
  15664. a.InvCode,
  15665. b.InvName,
  15666. b.InvStd,
  15667. b.InvUnit,
  15668. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15669. a.FromWarehouseCode as WhCode,
  15670. a.ExtensionID
  15671. FROM
  15672. ICSTransfer a
  15673. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15674. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  15675. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  15676. #endregion
  15677. }
  15678. if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  15679. {
  15680. enableCode = "";
  15681. excessQtySql = "";
  15682. #region 两步调出
  15683. sqls = @"select
  15684. a.OutCode as Code,
  15685. a.InvCode,
  15686. b.InvName,
  15687. b.InvStd,
  15688. b.InvUnit,
  15689. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  15690. a.WHCode ,
  15691. a.ExtensionID
  15692. from ICSOtherOut a
  15693. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  15694. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  15695. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  15696. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  15697. #endregion
  15698. }
  15699. #endregion
  15700. #region 出库
  15701. #region 采购退货
  15702. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  15703. {
  15704. isDeliveryNotice = true;
  15705. columns = @"a.DNCode AS TransCode,
  15706. a.DNDetailID AS DetailID,
  15707. a.DNType AS Type,
  15708. a.Sequence AS TransSequence,
  15709. a.RCVQuantity AS IssueQuantity,
  15710. a.Quantity,
  15711. a.Amount,
  15712. a.MUSER AS [User],
  15713. a.MTIME AS [MTime],";
  15714. tableName = @"ICSDeliveryNotice a ";
  15715. where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' AND a.Status<>'3'";
  15716. }
  15717. #endregion
  15718. //#region 工单关联
  15719. //else if (TransType == TransTypeEnum.ICSMOReceive.GetDescription())
  15720. //{
  15721. // isDeliveryNotice = true;
  15722. // columns = @"a.MOCode AS TransCode,
  15723. // a.Sequence AS TransSequence,";
  15724. // tableName = @"ICSMO a ";
  15725. // where = @" a.MOCode='{0}' AND a.WorkPoint='{1}' and a.ERPStatus<>'3'";
  15726. //}
  15727. //#endregion
  15728. #region 委外发料(合并发料)
  15729. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  15730. {
  15731. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode004' and enable = '1'";
  15732. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  15733. isMerge = true;
  15734. columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
  15735. a.PickID AS DetailID,
  15736. a.SupplyType AS Type,
  15737. b.Sequence+'~'+a.Sequence AS TransSequence,
  15738. a.IssueQuantity AS IssueQuantity,";
  15739. tableNameMerge = @"ICSOOPick a
  15740. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  15741. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  15742. columns = @"b.OOCode AS TransCode,
  15743. a.PickID AS DetailID,
  15744. a.SupplyType AS Type,
  15745. b.Sequence+'~'+a.Sequence AS TransSequence,
  15746. ISNULL((select Sum(log.Quantity) from ICSOOPick a
  15747. INNER JOIN ICSOutsourcingOrder m ON a.OODetailID=m.OODetailID AND a.WorkPoint=m.WorkPoint
  15748. INNER JOIN ICSWareHouseLotInfoLog log on m.oocode=log.transcode and m.Sequence=log.TransSequence
  15749. where m.oocode=b.oocode and m.Sequence=b.Sequence and log.TransType='15'),0) AS IssueQuantity,";
  15750. tableName = @"ICSOOPick a
  15751. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  15752. where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3'";
  15753. }
  15754. #endregion
  15755. #region 委外退货
  15756. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  15757. {
  15758. isDeliveryNotice = true;
  15759. columns = @"a.ODNCode AS TransCode,
  15760. a.ODNDetailID AS DetailID,
  15761. a.ODNType AS Type,
  15762. a.Sequence AS TransSequence,
  15763. a.RCVQuantity AS IssueQuantity,
  15764. a.Quantity,
  15765. a.Amount,
  15766. a.MUSER AS [User],
  15767. a.MTIME AS [MTime],";
  15768. tableName = @"ICSODeliveryNotice a ";
  15769. where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' AND a.Status<>'3'";
  15770. }
  15771. #endregion
  15772. #region 生产发料(合并发料)
  15773. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  15774. {
  15775. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
  15776. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  15777. isMerge = true;
  15778. columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  15779. a.PickID AS DetailID,
  15780. a.SupplyType AS Type,
  15781. b.Sequence+'~'+a.Sequence AS TransSequence,
  15782. a.IssueQuantity AS IssueQuantity,";
  15783. tableNameMerge = @"ICSMOPick a
  15784. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  15785. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint
  15786. INNER JOIN ICSDepartment c on b.DepCode=c.DepCode and b.WorkPoint=c.WorkPoint";
  15787. columns = @"b.MOCode AS TransCode,
  15788. a.PickID AS DetailID,
  15789. a.SupplyType AS Type,
  15790. b.Sequence+'~'+a.Sequence AS TransSequence,
  15791. ISNULL((select Sum(log.Quantity) from ICSMOPick a
  15792. INNER JOIN ICSMO m ON a.MODetailID=m.MODetailID AND a.WorkPoint=m.WorkPoint
  15793. INNER JOIN ICSWareHouseLotInfoLog log on m.mocode=log.transcode and m.Sequence=log.TransSequence
  15794. where m.mocode=b.mocode and m.Sequence=b.Sequence and log.TransType='15'),0) AS IssueQuantity,";
  15795. tableName = @"ICSMOPick a
  15796. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  15797. INNER JOIN ICSDepartment dd on b.DepCode=dd.DepCode and b.WorkPoint=dd.WorkPoint";
  15798. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' AND b.Sequence+'~'+a.Sequence='{3}' AND dd.DepName =(SELECT SUBSTRING(F_RealName, 1, 2) FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')";
  15799. }
  15800. #endregion
  15801. #region 销售出库(合并发料)
  15802. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  15803. {
  15804. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
  15805. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  15806. isMerge = true;
  15807. columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
  15808. a.SDNDetailID AS DetailID,
  15809. a.SOCode,
  15810. a.Type,
  15811. a.Sequence AS TransSequence,
  15812. a.SDNQuantity AS IssueQuantity,";
  15813. tableNameMerge = @"ICSSDN a
  15814. INNER JOIN ICSMOPickMerge mer ON a.SDNDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  15815. columns = @"a.SDNCode AS TransCode,
  15816. a.SDNDetailID AS DetailID,
  15817. a.SOCode,
  15818. a.Type,
  15819. a.Sequence AS TransSequence,
  15820. ISNULL((select Sum(b.Quantity) from ICSSDN sdn
  15821. INNER JOIN ICSWareHouseLotInfoLog b on sdn.sdncode=b.transcode and sdn.Sequence=b.TransSequence
  15822. where sdn.sdncode=a.sdncode and sdn.Sequence=a.Sequence and b.TransType='15'),0) AS IssueQuantity,";
  15823. tableName = @"ICSSDN a ";
  15824. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3'";
  15825. }
  15826. #endregion
  15827. #region 盘点
  15828. else if (TransType == TransTypeEnum.Check.GetDescription())
  15829. {
  15830. #region SLQ
  15831. sql = @"SELECT a.ID,
  15832. {0}
  15833. a.Quantity,
  15834. a.SelectLevel AS LocationCode,
  15835. a.Amount,
  15836. a.MUSER AS [User],
  15837. a.MTIME AS [MTime]
  15838. FROM {1}
  15839. WHERE {2} ";
  15840. #endregion
  15841. columns = @"a.CheckCode AS TransCode,
  15842. a.ID,
  15843. '' AS Type,";
  15844. tableName = @"ICSCheck a ";
  15845. where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' ";
  15846. }
  15847. #endregion
  15848. #region 一步调拨(合并发料)
  15849. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  15850. {
  15851. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
  15852. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  15853. isMerge = true;
  15854. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  15855. a.TransferDetailID AS DetailID,
  15856. '' AS Type,
  15857. a.Sequence AS TransSequence,
  15858. a.TransferQuantity AS IssueQuantity,
  15859. a.ToWarehouseCode,";
  15860. tableNameMerge = @"ICSTransfer a
  15861. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  15862. #region SLQ
  15863. sql = @"SELECT a.ID,
  15864. {0}
  15865. convert(varchar(100),'') AS LocationCode,
  15866. convert(varchar(100),'') AS LotNo,
  15867. 0 AS LocationQty,
  15868. 0 AS isMatched,
  15869. a.InvCode,
  15870. inv.InvName,
  15871. inv.InvStd,
  15872. a.Quantity,
  15873. inv.InvUnit,
  15874. a.Amount,
  15875. a.FromWarehouseCode AS WHCode,
  15876. inv.AmountUnit,
  15877. wh.WarehouseName AS WHName,
  15878. a.ExtensionID,
  15879. ext.ProjectCode,
  15880. 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,
  15881. ext.Version,
  15882. ext.Brand,
  15883. ext.cFree1,
  15884. ext.cFree2,
  15885. ext.cFree3,
  15886. ext.cFree4,
  15887. ext.cFree5,
  15888. ext.cFree6,
  15889. ext.cFree7,
  15890. ext.cFree8,
  15891. ext.cFree9,
  15892. ext.cFree10,
  15893. a.MUSER AS [User],
  15894. a.MTIME AS [MTime]
  15895. FROM {1}
  15896. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  15897. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  15898. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15899. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  15900. WHERE {2} ";
  15901. #endregion
  15902. columns = @"a.TransferNO AS TransCode,
  15903. a.TransferDetailID AS DetailID,
  15904. '' AS Type,
  15905. a.Sequence AS TransSequence,
  15906. a.TransferQuantity AS IssueQuantity,
  15907. a.ToWarehouseCode,";
  15908. tableName = @"ICSTransfer a ";
  15909. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3'";
  15910. }
  15911. #endregion
  15912. #region 调拨申请单(领料)
  15913. else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
  15914. {
  15915. isMerge = true;
  15916. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  15917. a.TransferDetailID AS DetailID,
  15918. '' AS Type,
  15919. a.Sequence AS TransSequence,
  15920. a.TransferQuantity AS IssueQuantity,
  15921. a.ToWarehouseCode,";
  15922. tableNameMerge = @"ICSTransferApplication a
  15923. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  15924. #region SLQ
  15925. sql = @"SELECT a.ID,
  15926. {0}
  15927. convert(varchar(100),'') AS LocationCode,
  15928. convert(varchar(100),'') AS LotNo,
  15929. 0 AS LocationQty,
  15930. 0 AS isMatched,
  15931. a.InvCode,
  15932. inv.InvName,
  15933. inv.InvStd,
  15934. a.Quantity,
  15935. inv.InvUnit,
  15936. a.Amount,
  15937. a.FromWarehouseCode AS WHCode,
  15938. inv.AmountUnit,
  15939. wh.WarehouseName AS WHName,
  15940. a.ExtensionID,
  15941. ext.ProjectCode,
  15942. 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,
  15943. ext.Version,
  15944. ext.Brand,
  15945. ext.cFree1,
  15946. ext.cFree2,
  15947. ext.cFree3,
  15948. ext.cFree4,
  15949. ext.cFree5,
  15950. ext.cFree6,
  15951. ext.cFree7,
  15952. ext.cFree8,
  15953. ext.cFree9,
  15954. ext.cFree10,
  15955. a.MUSER AS [User],
  15956. a.MTIME AS [MTime]
  15957. FROM {1}
  15958. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  15959. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  15960. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15961. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  15962. WHERE {2} ";
  15963. #endregion
  15964. columns = @"a.TransferNO AS TransCode,
  15965. a.TransferDetailID AS DetailID,
  15966. '' AS Type,
  15967. a.Sequence AS TransSequence,
  15968. a.TransferQuantity AS IssueQuantity,
  15969. a.ToWarehouseCode,";
  15970. tableName = @"ICSTransferApplication a ";
  15971. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3'";
  15972. }
  15973. #endregion
  15974. #region 调拨(合并发料)
  15975. else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
  15976. {
  15977. }
  15978. #endregion
  15979. #region 两步调出(合并发料)
  15980. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  15981. {
  15982. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode010' and enable = '1'";
  15983. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  15984. isMerge = true;
  15985. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  15986. a.OutDetailID AS DetailID,
  15987. '' AS Type,
  15988. a.Sequence AS TransSequence,
  15989. a.OutQuantity AS IssueQuantity,";
  15990. tableNameMerge = @"ICSOtherOut a
  15991. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  15992. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  15993. columns = @"a.OutCode AS TransCode,
  15994. a.OutDetailID AS DetailID,
  15995. '' AS Type,
  15996. a.Sequence AS TransSequence,
  15997. a.OutQuantity AS IssueQuantity,";
  15998. tableName = @"ICSOtherOut a
  15999. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  16000. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  16001. }
  16002. #endregion
  16003. #region 其他出库(合并发料)
  16004. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  16005. {
  16006. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
  16007. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  16008. isMerge = true;
  16009. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  16010. a.OutDetailID AS DetailID,
  16011. '' AS Type,
  16012. a.Sequence AS TransSequence,
  16013. a.OutQuantity AS IssueQuantity,";
  16014. tableNameMerge = @"ICSOtherOut a
  16015. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  16016. columns = @"a.OutCode AS TransCode,
  16017. a.OutDetailID AS DetailID,
  16018. '' AS Type,
  16019. a.Sequence AS TransSequence,
  16020. a.OutQuantity AS IssueQuantity,";
  16021. tableName = @"ICSOtherOut a ";
  16022. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  16023. }
  16024. #endregion
  16025. #region 领料申请单发料(合并发料)
  16026. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  16027. {
  16028. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode002' and enable = '1'";
  16029. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  16030. isMerge = true;
  16031. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  16032. a.ApplyDetailID AS DetailID,
  16033. a.Type,
  16034. a.Sequence AS TransSequence,
  16035. a.IssueQuantity AS IssueQuantity,";
  16036. tableNameMerge = @"ICSMOApply a
  16037. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  16038. columns = @"a.ApplyCode AS TransCode,
  16039. a.ApplyDetailID AS DetailID,
  16040. a.Type,
  16041. a.Sequence AS TransSequence,
  16042. a.IssueQuantity AS IssueQuantity,";
  16043. tableName = @"ICSMOApply a ";
  16044. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  16045. }
  16046. #endregion
  16047. #region 补料申请单发料(合并发料)
  16048. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  16049. {
  16050. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode012' and enable = '1'";
  16051. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  16052. isMerge = true;
  16053. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  16054. a.ApplyDetailID AS DetailID,
  16055. a.Type,
  16056. a.Sequence AS TransSequence,
  16057. a.IssueQuantity AS IssueQuantity,";
  16058. tableNameMerge = @"ICSMOReplenishment a
  16059. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  16060. columns = @"a.ReplenishmentCode AS TransCode,
  16061. a.ReplenishmentDetailID AS DetailID,
  16062. a.Type,
  16063. a.Sequence AS TransSequence,
  16064. a.IssueQuantity AS IssueQuantity,";
  16065. tableName = @"ICSMOReplenishment a ";
  16066. where = @" a.ReplenishmentCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  16067. }
  16068. #endregion
  16069. #region 委外领料申请单发料(合并发料)
  16070. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  16071. {
  16072. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode005' and enable = '1'";
  16073. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  16074. isMerge = true;
  16075. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  16076. a.ApplyDetailID AS DetailID,
  16077. a.Type,
  16078. a.Sequence AS TransSequence,
  16079. a.IssueQuantity AS IssueQuantity,";
  16080. tableNameMerge = @"ICSOApply a
  16081. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  16082. columns = @"a.ApplyCode AS TransCode,
  16083. a.ApplyDetailID AS DetailID,
  16084. a.Type,
  16085. a.Sequence AS TransSequence,
  16086. a.IssueQuantity AS IssueQuantity,";
  16087. tableName = @"ICSOApply a ";
  16088. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  16089. }
  16090. #endregion
  16091. #region 开立材料出库(合并发料)
  16092. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  16093. {
  16094. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode003' and enable = '1'";
  16095. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  16096. isMerge = true;
  16097. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  16098. a.IssueDetailID AS DetailID,
  16099. a.Type,
  16100. a.Sequence AS TransSequence,
  16101. a.IssueQuantity AS IssueQuantity,";
  16102. tableNameMerge = @"ICSMOIssue a
  16103. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  16104. columns = @"a.IssueCode AS TransCode,
  16105. a.IssueDetailID AS DetailID,
  16106. a.Type,
  16107. a.Sequence AS TransSequence,
  16108. a.IssueQuantity AS IssueQuantity,";
  16109. tableName = @"ICSMOIssue a ";
  16110. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  16111. }
  16112. #endregion
  16113. #region 开立委外材料出库(合并发料)
  16114. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  16115. {
  16116. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode006' and enable = '1'";
  16117. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  16118. isMerge = true;
  16119. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  16120. a.IssueDetailID AS DetailID,
  16121. a.Type,
  16122. a.Sequence AS TransSequence,
  16123. a.IssueQuantity AS IssueQuantity,";
  16124. tableNameMerge = @"ICSOIssue a
  16125. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  16126. columns = @"a.IssueCode AS TransCode,
  16127. a.IssueDetailID AS DetailID,
  16128. a.Type,
  16129. a.Sequence AS TransSequence,
  16130. a.IssueQuantity AS IssueQuantity,";
  16131. tableName = @"ICSOIssue a ";
  16132. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  16133. }
  16134. #endregion
  16135. #region 开立红字入库单
  16136. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  16137. {
  16138. columns = @"a.RCVCode AS TransCode,
  16139. a.RCVDetailID AS DetailID,
  16140. a.Type,
  16141. a.Sequence AS TransSequence,
  16142. a.RCVQuantity AS IssueQuantity,";
  16143. tableName = @"ICSPurchaseReceive a ";
  16144. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  16145. }
  16146. #endregion
  16147. #region 开立委外红字入库单
  16148. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  16149. {
  16150. columns = @"a.RCVCode AS TransCode,
  16151. a.RCVDetailID AS DetailID,
  16152. a.Type,
  16153. a.Sequence AS TransSequence,
  16154. a.RCVQuantity AS IssueQuantity,";
  16155. tableName = @"ICSOutsourcingReceive a ";
  16156. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  16157. }
  16158. #endregion
  16159. #region 借用(合并发料)
  16160. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  16161. {
  16162. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode011' and enable = '1'";
  16163. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  16164. isMerge = true;
  16165. columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
  16166. a.BrrowDetailID AS DetailID,
  16167. '' AS Type,
  16168. a.Sequence AS TransSequence,
  16169. a.BrrowQuantity AS IssueQuantity,";
  16170. tableNameMerge = @"ICSBrrow a
  16171. INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  16172. columns = @"a.BrrowCode AS TransCode,
  16173. a.BrrowDetailID AS DetailID,
  16174. '' AS Type,
  16175. a.Sequence AS TransSequence,
  16176. a.BrrowQuantity AS IssueQuantity,";
  16177. tableName = @"ICSBrrow a ";
  16178. where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  16179. }
  16180. #endregion
  16181. #region 送货单
  16182. else if (TransType == TransTypeEnum.ASN.GetDescription())
  16183. {
  16184. isDeliveryNotice = true;
  16185. columns = @"asn.ASNCode AS TransCode,
  16186. asn.ID AS DetailID,
  16187. asn.LotNo,
  16188. '' AS Type,
  16189. asn.Sequence AS TransSequence,
  16190. asn.DNQuantity AS IssueQuantity,
  16191. asn.Quantity,
  16192. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  16193. asn.MUSER AS [User],
  16194. asn.MTIME AS [MTime],";
  16195. tableName = @"ICSInventoryLot a
  16196. INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  16197. where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
  16198. }
  16199. #endregion
  16200. #region 委外送货单
  16201. else if (TransType == TransTypeEnum.OASN.GetDescription())
  16202. {
  16203. isDeliveryNotice = true;
  16204. columns = @"asn.OASNCode AS TransCode,
  16205. asn.ID AS DetailID,
  16206. asn.LotNo,
  16207. '' AS Type,
  16208. asn.Sequence AS TransSequence,
  16209. asn.ODNQuantity AS IssueQuantity,
  16210. asn.Quantity,
  16211. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  16212. asn.MUSER AS [User],
  16213. asn.MTIME AS [MTime],";
  16214. tableName = @"ICSInventoryLot a
  16215. INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  16216. where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
  16217. }
  16218. #endregion
  16219. #endregion
  16220. #region 入库
  16221. #region 采购入库
  16222. else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  16223. {
  16224. }
  16225. #endregion
  16226. #region 审核的到货单
  16227. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  16228. {
  16229. }
  16230. #endregion
  16231. #region 采购拒收
  16232. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  16233. {
  16234. }
  16235. #endregion
  16236. #region 审核的委外到货单
  16237. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  16238. {
  16239. }
  16240. #endregion
  16241. #region 委外拒收
  16242. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  16243. {
  16244. }
  16245. #endregion
  16246. #region 委外退料
  16247. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  16248. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  16249. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  16250. {
  16251. }
  16252. #endregion
  16253. #region 委外入库
  16254. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  16255. {
  16256. }
  16257. #endregion
  16258. #region 生产退料
  16259. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  16260. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  16261. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  16262. {
  16263. }
  16264. #endregion
  16265. #region 生产入库
  16266. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  16267. {
  16268. }
  16269. #endregion
  16270. #region 开立的生产入库单
  16271. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  16272. {
  16273. }
  16274. #endregion
  16275. #region 返工工单
  16276. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  16277. {
  16278. }
  16279. #endregion
  16280. #region 销售退货
  16281. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  16282. {
  16283. }
  16284. #endregion
  16285. #region 两步调入
  16286. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  16287. {
  16288. columns = @"a.InCode AS TransCode,
  16289. a.InDetailID AS DetailID,
  16290. '' AS Type,
  16291. a.Sequence AS TransSequence,
  16292. a.InQuantity AS IssueQuantity,";
  16293. tableName = @"ICSOtherIn a
  16294. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  16295. where = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  16296. }
  16297. #endregion
  16298. #region 销售退货-原条码
  16299. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  16300. {
  16301. columns = @"a.SDNCode AS TransCode,
  16302. a.SDNDetailID AS DetailID,
  16303. a.Type,
  16304. a.Sequence AS TransSequence,
  16305. a.SDNQuantity AS IssueQuantity,";
  16306. tableName = @"ICSSDN a ";
  16307. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  16308. }
  16309. #endregion
  16310. #region 其他入库
  16311. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  16312. {
  16313. }
  16314. #endregion
  16315. #region 拆卸单
  16316. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  16317. {
  16318. columns = @"a.DABDOCCode AS TransCode,
  16319. a.DABDOCDetailID AS DetailID,
  16320. a.DABDOCType AS Type,
  16321. a.Sequence AS TransSequence,
  16322. a.DABDOCQuantity AS IssueQuantity,";
  16323. tableName = @"ICSDisassemblyDoc a";
  16324. where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' AND a.Status<>'3' ";
  16325. }
  16326. #endregion
  16327. #region 归还
  16328. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  16329. {
  16330. }
  16331. #endregion
  16332. #endregion
  16333. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
  16334. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  16335. #region 判断是否启用匹配库位
  16336. if (flag != null && flag.Rows.Count > 0)
  16337. //if (true)
  16338. {
  16339. sql = @"select * into #maintemp from (" + sql + @")a
  16340. select * into #resulttemp from #maintemp
  16341. truncate table #resulttemp
  16342. select a.lotno,a.locationcode,a.invcode,(a.quantity-a.lockQuantity) as quantity ,a.mtime,a.warehousecode,isnull(ext.ProjectCode,'')as ProjectCode, isnull(ext.Version,'')as Version,
  16343. isnull(ext.Brand,'')as Brand,
  16344. isnull(ext.cFree1,'')as cFree1,
  16345. isnull(ext.cFree2,'') cFree2,
  16346. isnull(ext.cFree3,'') cFree3,
  16347. isnull(ext.cFree4,'') cFree4,
  16348. isnull(ext.cFree5,'') cFree5,
  16349. isnull(ext.cFree6,'') cFree6,
  16350. isnull(ext.cFree7,'') cFree7,
  16351. isnull(ext.cFree8,'') cFree8,
  16352. isnull(ext.cFree9,'') cFree9,
  16353. isnull(ext.cFree10,'') cFree10,ISNULL(ext.BatchCode, '') BatchCode into #barcodetemp
  16354. from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  16355. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  16356. LEFT JOIN
  16357. (select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp
  16358. group by invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE) b on a.invcode = b.invcode
  16359. where (a.warehousecode = b.whcode or ISNULL(b.whcode,'')='') and a.Quantity-a.lockQuantity>0 and
  16360. isnull(ext.ProjectCode,'') = b.ProjectCode and isnull(ext.Version,'')=b.Version and
  16361. isnull(ext.Brand,'') =b.Brand and
  16362. isnull(ext.cFree1,'')=b.cFree1 and
  16363. isnull(ext.cFree2,'')=b.cFree2 and
  16364. isnull(ext.cFree3,'')=b.cFree3 and
  16365. isnull(ext.cFree4,'')=b.cFree4 and
  16366. isnull(ext.cFree5,'')=b.cFree5 and
  16367. isnull(ext.cFree6,'')=b.cFree6 and
  16368. isnull(ext.cFree7,'')=b.cFree7 and
  16369. isnull(ext.cFree8,'')=b.cFree8 and
  16370. isnull(ext.cFree9,'')=b.cFree9 and
  16371. isnull(ext.cFree10,'')=b.cFree10 and
  16372. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =ext.BatchCode) or isnull(b.BatchCode,'') ='')
  16373. BEGIN
  16374. DECLARE @transSequence VARCHAR(50);--
  16375. DECLARE @qty decimal(18, 4);--
  16376. DECLARE @needqty decimal(18, 4);--
  16377. DECLARE @lotno VARCHAR(50);--
  16378. DECLARE @locationcode VARCHAR(50);--
  16379. DECLARE @WHCode VARCHAR(50);--
  16380. DECLARE @invcode VARCHAR(50);--
  16381. DECLARE @issueQuantity decimal(18, 4);
  16382. DECLARE tempCursor CURSOR FOR (select transSequence from #maintemp); --tempCursor
  16383. OPEN tempCursor; --
  16384. FETCH NEXT FROM tempCursor INTO @transSequence; --
  16385. WHILE @@fetch_status=0
  16386. BEGIN
  16387. select @needqty=Quantity,@issueQuantity=issueQuantity from #maintemp where transSequence = @transSequence
  16388. PRINT @transSequence
  16389. WHILE @needqty>0
  16390. BEGIN
  16391. select top 1 @qty = isnull(a.quantity,0), @locationcode = isnull(a.locationcode,''),@lotno = isnull(a.lotno,''),@WHCode = isnull(a.warehousecode,''),@invcode = b.invcode from #barcodetemp a
  16392. right JOIN(select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp where transSequence=@transSequence)b on a.invcode = b.invcode
  16393. and ((isnull(b.ProjectCode,'')<>'' and b.ProjectCode = a.ProjectCode) or isnull(b.ProjectCode,'') ='') and
  16394. ((isnull(b.Version,'')<>'' and b.Version = a.Version) or isnull(b.Version,'') ='') and
  16395. ((isnull(b.Brand,'')<>'' and b.Brand = a.Brand )or isnull(b.Brand,'') ='') and
  16396. ((isnull(b.cFree1,'')<>'' and b.cFree1 =a.cFree1) or isnull(b.cFree1,'') ='') and
  16397. ((isnull(b.cFree2,'')<>'' and b.cFree2 =a.cFree2 )or isnull(b.cFree2,'') ='') and
  16398. ((isnull(b.cFree3,'')<>'' and b.cFree3 =a.cFree3 )or isnull(b.cFree3,'') ='') and
  16399. ((isnull(b.cFree4,'')<>'' and b.cFree4 =a.cFree4 )or isnull(b.cFree4,'') ='') and
  16400. ((isnull(b.cFree5,'')<>'' and b.cFree5 =a.cFree5) or isnull(b.cFree5,'') ='') and
  16401. ((isnull(b.cFree6,'')<>'' and b.cFree6 =a.cFree6 )or isnull(b.cFree6,'') ='') and
  16402. ((isnull(b.cFree7,'')<>'' and b.cFree7 =a.cFree7) or isnull(b.cFree7,'') ='') and
  16403. ((isnull(b.cFree8,'')<>'' and b.cFree8 =a.cFree8) or isnull(b.cFree8,'') ='') and
  16404. ((isnull(b.cFree9,'')<>'' and b.cFree9 =a.cFree9) or isnull(b.cFree9,'') ='') and
  16405. ((isnull(b.cFree10,'')<>'' and b.cFree10 =a.cFree10) or isnull(b.cFree10,'') ='') and
  16406. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =a.BatchCode) or isnull(b.BatchCode,'') ='')ORDER BY mtime,locationcode
  16407. IF(@needqty-@issueQuantity-@qty>=0 and ISNULL(@lotno, '')<>'')
  16408. BEGIN
  16409. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  16410. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotNo,
  16411. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  16412. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  16413. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),@qty,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  16414. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  16415. delete from #barcodetemp where lotno = @lotno
  16416. SET @needqty=@needqty-@qty
  16417. END
  16418. ELSE if(@needqty-@issueQuantity-@qty<0 and ISNULL(@lotno, '')<>''and @needqty-@issueQuantity>0)
  16419. BEGIN
  16420. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  16421. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  16422. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  16423. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  16424. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),case WHEN ISNULL(@qty, 0)=0 THEN 0 else @needqty-@issueQuantity end ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  16425. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  16426. update #barcodetemp set quantity = @qty-@needqty+-@issueQuantity where lotno = @lotno
  16427. SET @needqty=@needqty-@issueQuantity-@qty
  16428. END
  16429. ELSE
  16430. BEGIN
  16431. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  16432. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  16433. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  16434. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  16435. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),0 ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  16436. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  16437. SET @needqty=0
  16438. END
  16439. END
  16440. FETCH NEXT FROM tempCursor INTO @transSequence;
  16441. END
  16442. CLOSE tempCursor
  16443. DEALLOCATE tempCursor
  16444. END
  16445. select id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  16446. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,sum(LocationQty)as LocationQty,isMatched,AmountUnit,--lotno,
  16447. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #resulttemp GROUP BY id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  16448. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,isMatched,AmountUnit,--lotno,
  16449. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ORDER BY locationcode ASC ,InvCode ASC
  16450. DROP table #maintemp
  16451. DROP table #resulttemp
  16452. DROP table #barcodetemp";
  16453. }
  16454. #endregion
  16455. if (isDeliveryNotice)//送货、到货、含委外
  16456. {
  16457. #region SLQ
  16458. sql = sqlCheck + @"SELECT a.ID,
  16459. {0}
  16460. a.InvCode,
  16461. inv.InvName,
  16462. inv.InvStd,
  16463. inv.InvUnit,
  16464. '' AS WHCode,
  16465. inv.AmountUnit,
  16466. '' AS WHName,
  16467. a.ExtensionID,
  16468. ext.ProjectCode,
  16469. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  16470. ext.Version,
  16471. ext.Brand,
  16472. ext.cFree1,
  16473. ext.cFree2,
  16474. ext.cFree3,
  16475. ext.cFree4,
  16476. ext.cFree5,
  16477. ext.cFree6,
  16478. ext.cFree7,
  16479. ext.cFree8,
  16480. ext.cFree9,
  16481. ext.cFree10
  16482. FROM {1}
  16483. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  16484. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  16485. WHERE {2} ";
  16486. #endregion
  16487. }
  16488. else if (isMerge)//合并发料
  16489. {
  16490. #region SLQ
  16491. string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='" + JsonData.TransCode + "' AND WorkPoint='" + JsonData.WorkPoint + "'";
  16492. DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
  16493. if (sign != null && sign.Rows.Count > 0)
  16494. {
  16495. string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
  16496. sql = string.Format(sql, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, excessQtySql);
  16497. }
  16498. else
  16499. {
  16500. sql = @" BEGIN
  16501. IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
  16502. BEGIN
  16503. RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
  16504. RETURN
  16505. END
  16506. " + sqlCheck + sql + @"
  16507. END";
  16508. }
  16509. #endregion
  16510. }
  16511. else
  16512. {
  16513. sql = sqlCheck + sql;
  16514. }
  16515. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint,JsonData.User,JsonData.TransSequence);
  16516. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode, excessQtySql);
  16517. sqls = string.Format(sqls, JsonData.TransCode, JsonData.WorkPoint);
  16518. Picksql = string.Format(Picksql, sqls, JsonData.WorkPoint);
  16519. //DataTable table2 = DBHelper.SQlReturnData(Picksql, cmd);
  16520. //return table2;
  16521. log.Debug("源头单据信息sql:" + sql);
  16522. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  16523. return table;
  16524. }
  16525. catch (Exception ex)
  16526. {
  16527. log.Error(ex.Message);
  16528. throw new Exception(ex.Message);
  16529. }
  16530. finally
  16531. {
  16532. if (conn.State == ConnectionState.Open)
  16533. {
  16534. conn.Close();
  16535. }
  16536. conn.Dispose();
  16537. }
  16538. }
  16539. }
  16540. #endregion
  16541. /// <summary>
  16542. /// 所有未完成单据号
  16543. /// </summary>
  16544. /// <param name="JsonData"></param>
  16545. /// <returns></returns>
  16546. public static DataTable AMTransCodeGet(WMSSourceDocumentModel JsonData)
  16547. {
  16548. var language = LanguageHelper.GetName("WMSAPIInfo");
  16549. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  16550. {
  16551. conn.Open();
  16552. SqlCommand cmd = new SqlCommand();
  16553. cmd.Connection = conn;
  16554. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  16555. try
  16556. {
  16557. if (string.IsNullOrEmpty(JsonData.TransType))
  16558. {
  16559. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  16560. }
  16561. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  16562. {
  16563. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  16564. }
  16565. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  16566. {
  16567. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  16568. }
  16569. string TransType = JsonData.TransType;
  16570. #region SLQ
  16571. //string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  16572. // BEGIN
  16573. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  16574. // RETURN
  16575. // END
  16576. // ";
  16577. string sql = @"SELECT
  16578. {0}
  16579. FROM {1}
  16580. WHERE {2}
  16581. order by TransCode asc";
  16582. #endregion
  16583. bool isDeliveryNotice = false; //送货、到货、含委外
  16584. bool MOApplyWithBin = false; //生产领料-库位
  16585. bool OtherOutDocWithBin = false; //杂发-库位
  16586. string columns = string.Empty; //查询源头单据表的特殊列名
  16587. string tableName = string.Empty; //查询源头单据表名
  16588. string where = string.Empty; //查询源头单据的过滤条件
  16589. bool isMerge = false; //合并发料
  16590. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  16591. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  16592. #region 出库
  16593. #region 采购退货
  16594. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  16595. {
  16596. columns = @" DISTINCT a.DNCode AS TransCode";
  16597. tableName = @"ICSDeliveryNotice a ";
  16598. where = @" a.WorkPoint='{1}' AND a.DNType='2' AND a.Status='2' AND (a.Quantity-a.RCVQuantity)>0";
  16599. }
  16600. #endregion
  16601. #region 其他出库
  16602. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  16603. {
  16604. columns = @" DISTINCT a.OutCode AS TransCode";
  16605. tableName = @"ICSOtherOut a ";
  16606. where = @" a.Status='1' AND a.WorkPoint='{1}' and a.Quantity>a.OutQuantity";
  16607. }
  16608. #endregion
  16609. #region 一步调拨(合并发料)
  16610. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  16611. {
  16612. columns = @" DISTINCT a.TransferNO AS TransCode";
  16613. tableName = @"ICSTransfer a ";
  16614. where = @" a.WorkPoint='{1}' AND a.Status='1' AND a.Quantity>a.TransferQuantity AND Type='1'";
  16615. }
  16616. #endregion
  16617. #region 生产发料(合并发料)
  16618. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  16619. {
  16620. columns = @" DISTINCT b.MOCode AS TransCode";
  16621. tableName = @" ICSMOPick a
  16622. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  16623. INNER JOIN ICSDepartment c on b.DepCode=c.DepCode and b.WorkPoint=c.WorkPoint";
  16624. where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' and a.Quantity-a.IssueQuantity>0
  16625. AND c.DepName =(SELECT SUBSTRING(F_RealName, 1, 2) FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}') ";
  16626. }
  16627. #endregion
  16628. #region 开立材料出库(合并发料)
  16629. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  16630. {
  16631. columns = @" DISTINCT a.IssueCode AS TransCode";
  16632. tableName = @" ICSMOIssue a ";
  16633. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  16634. }
  16635. #endregion
  16636. #region 生产发料-领料申请单
  16637. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  16638. {
  16639. columns = @" DISTINCT a.ApplyCode AS TransCode";
  16640. tableName = @" ICSMOApply a
  16641. INNER JOIN ICSMO b ON b.MOCode=a.SourceCode and a.SourceSequence = b.Sequence AND a.WorkPoint=b.WorkPoint";
  16642. where = @" a.Status='2' AND a.WorkPoint='{1}' and a.Quantity-a.IssueQuantity>0";
  16643. }
  16644. #endregion
  16645. #region 开立委外材料出库(合并发料)
  16646. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  16647. {
  16648. columns = @" DISTINCT a.IssueCode AS TransCode";
  16649. tableName = @" ICSOIssue a ";
  16650. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  16651. }
  16652. #endregion
  16653. #region 委外领料申请单发料(合并发料)
  16654. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  16655. {
  16656. columns = @" DISTINCT a.ApplyCode AS TransCode";
  16657. tableName = @" ICSOApply a ";
  16658. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  16659. }
  16660. #endregion
  16661. #region 委外发料(合并发料)
  16662. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  16663. {
  16664. columns = @" DISTINCT b.OOCode AS TransCode";
  16665. tableName = @" ICSOOPick a
  16666. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  16667. where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  16668. }
  16669. #endregion
  16670. #region 销售出库(合并发料)
  16671. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  16672. {
  16673. columns = @" DISTINCT a.SDNCode AS TransCode";
  16674. tableName = @"ICSSDN a ";
  16675. where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' and a.Quantity-a.SDNQuantity>0";
  16676. }
  16677. #endregion
  16678. #region 盘点
  16679. else if (TransType == TransTypeEnum.Check.GetDescription())
  16680. {
  16681. columns = @" DISTINCT a.CheckCode AS TransCode";
  16682. tableName = @"ICSCheck a ";
  16683. where = @" a.WorkPoint='{1}' ";
  16684. }
  16685. #endregion
  16686. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint,JsonData.User);
  16687. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode);
  16688. log.Debug("源头单据sql : " + sql);
  16689. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  16690. return table;
  16691. #endregion
  16692. }
  16693. catch (Exception ex)
  16694. {
  16695. log.Error(ex.Message);
  16696. throw new Exception(ex.Message);
  16697. }
  16698. finally
  16699. {
  16700. if (conn.State == ConnectionState.Open)
  16701. {
  16702. conn.Close();
  16703. }
  16704. conn.Dispose();
  16705. }
  16706. }
  16707. }
  16708. public static Result AMBarCodeInformationGet(BarCodeModel JsonData)
  16709. {
  16710. var language = LanguageHelper.GetName("WMSAPIInfo");
  16711. DataTable table = new DataTable();
  16712. DataTable ZLtable = new DataTable();
  16713. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  16714. {
  16715. conn.Open();
  16716. SqlCommand cmd = new SqlCommand();
  16717. cmd.Connection = conn;
  16718. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  16719. try
  16720. {
  16721. string ScanType = DBHelper.ScanTypeCheck(JsonData.Code, JsonData.WorkPoint, cmd);
  16722. if (string.IsNullOrEmpty(JsonData.Code))
  16723. {
  16724. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  16725. }
  16726. else if (string.IsNullOrEmpty(JsonData.TransType))
  16727. {
  16728. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  16729. }
  16730. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  16731. {
  16732. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  16733. }
  16734. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  16735. {
  16736. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  16737. }
  16738. string TransType = JsonData.TransType;
  16739. string sql = "";
  16740. string LotTypesql = "";
  16741. string Losql = "";
  16742. string sqlNew = "";
  16743. string LotType = "";
  16744. string UserName = "";
  16745. string UName = "";
  16746. bool iszl = false;
  16747. string zlqty = "0";
  16748. #region SLQ
  16749. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  16750. {
  16751. //Losql = @"SELECT a.ID,
  16752. // con.ContainerCode,
  16753. // con.ContainerName,
  16754. // a.LotNo,
  16755. // a.InvCode,
  16756. // inv.InvName,
  16757. // inv.InvStd,
  16758. // inv.InvUnit,
  16759. // inv.LotEnable,
  16760. // {0}
  16761. // inv.AmountUnit,
  16762. // ext.ID AS ExtensionID,
  16763. // ext.ProjectCode,
  16764. // ext.Version,
  16765. // ext.Brand,
  16766. // ext.cFree1,
  16767. // ext.cFree2,
  16768. // ext.cFree3,
  16769. // ext.cFree4,
  16770. // ext.cFree5,
  16771. // ext.cFree6,
  16772. // ext.cFree7,
  16773. // ext.cFree8,
  16774. // ext.cFree9,
  16775. // ext.cFree10,
  16776. // a.MUSER AS [User],
  16777. // a.MTIME AS [MTime]
  16778. // FROM {1}
  16779. // LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  16780. // LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  16781. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  16782. // WHERE a.Quantity>0 and a.WorkPoint='{3}'";
  16783. Losql = @" DECLARE @wheresql VARCHAR(MAX)
  16784. DECLARE @groupsql VARCHAR(MAX)
  16785. DECLARE @aa VARCHAR(MAX)
  16786. DECLARE @bb VARCHAR(MAX)
  16787. DECLARE @cc VARCHAR(MAX)
  16788. DECLARE @dd VARCHAR(MAX)
  16789. DECLARE @b VARCHAR(MAX)
  16790. select @aa=id from ICSWareHouseLotInfo where LotNo='{2}'
  16791. IF @aa IS NOT NULL
  16792. BEGIN
  16793. set @wheresql='and a.lotno=''{2}'' and s.invcode IN(SELECT invcode FROM ICSWareHouseLotInfo where LotNo=''{2}'') and a.invcode=s.invcode '
  16794. set @groupsql=' group by inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
  16795. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME'
  16796. END
  16797. select @bb=id from ICSLocation where LocationCode='{2}'
  16798. IF @bb IS not NULL
  16799. BEGIN
  16800. set @wheresql='and a.locationcode=s.locationcode and a.LocationCode=''{2}'' '
  16801. set @groupsql = 'group by inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,a.warehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
  16802. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME'
  16803. END
  16804. select @cc=id from ICSInventory where invcode='{2}'
  16805. IF @cc IS not NULL
  16806. BEGIN
  16807. set @wheresql='and inv.invcode=''{2}'' and a.invcode=s.invcode '
  16808. set @groupsql='group by inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
  16809. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME'
  16810. END
  16811. select @dd=id from ICSInventory where InvStd LIKE '%{2}%'
  16812. IF @dd IS not NULL
  16813. BEGIN
  16814. set @wheresql='and inv.InvStd LIKE ''%{2}%'' '
  16815. set @groupsql='group by inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,a.WarehouseCode,a.LocationCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,a.Quantity,inv.AmountUnit,
  16816. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME'
  16817. END
  16818. IF @aa IS NULL and @bb IS NULL and @cc IS NULL and @dd IS NULL
  16819. BEGIN
  16820. RAISERROR('" + language.GetNameByCode("WMSAPIInfo478") + @"',16,1)
  16821. END
  16822. ELSE
  16823. BEGIN
  16824. set @b =
  16825. 'SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
  16826. inv.InvName,
  16827. inv.InvStd,
  16828. inv.InvUnit,
  16829. inv.LotEnable,
  16830. a.WarehouseCode,a.LocationCode,a.Quantity as Qty,SUM(s.sumQty) sumQty,
  16831. inv.AmountUnit,
  16832. ext.ID AS ExtensionID,
  16833. ext.ProjectCode,
  16834. ext.Version,
  16835. ext.Brand,
  16836. ext.cFree1,
  16837. ext.cFree2,
  16838. ext.cFree3,
  16839. ext.cFree4,
  16840. ext.cFree5,
  16841. ext.cFree6,
  16842. ext.cFree7,
  16843. ext.cFree8,
  16844. ext.cFree9,
  16845. ext.cFree10,
  16846. a.MUSER AS [User],
  16847. a.MTIME AS [MTime]
  16848. FROM ICSWareHouseLotInfo a
  16849. LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  16850. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  16851. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  16852. LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode,LocationCode,workpoint from ICSWareHouseLotInfo where quantity>0 group by WarehouseCode,INVCode,LocationCode,workpoint)s ON a.workpoint=s.workpoint
  16853. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  16854. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  16855. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  16856. WHERE a.Quantity>0 and a.WorkPoint=''{3}'' ' + @wheresql + @groupsql
  16857. END
  16858. exec(@b)
  16859. ";
  16860. }
  16861. else
  16862. {
  16863. if (ScanType == "LOTNO")
  16864. {
  16865. sql = @"SELECT a.ID,
  16866. con.ContainerCode,
  16867. con.ContainerName,
  16868. a.LotNo,
  16869. a.InvCode,
  16870. inv.InvName,
  16871. inv.InvStd,
  16872. inv.InvUnit,
  16873. inv.LotEnable,
  16874. {0}
  16875. inv.AmountUnit,
  16876. inv.AmountEnable,
  16877. ext.ID AS ExtensionID,
  16878. ext.ProjectCode,
  16879. ext.Version,
  16880. ext.Brand,
  16881. ext.cFree1,
  16882. ext.cFree2,
  16883. ext.cFree3,
  16884. ext.cFree4,
  16885. ext.cFree5,
  16886. ext.cFree6,
  16887. ext.cFree7,
  16888. ext.cFree8,
  16889. ext.cFree9,
  16890. ext.cFree10,
  16891. a.MUSER AS [User],
  16892. a.MTIME AS [MTime]
  16893. FROM {1}
  16894. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  16895. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  16896. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  16897. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' ";
  16898. }
  16899. else
  16900. {
  16901. sql = @"SELECT a.ID,
  16902. con.ContainerCode,
  16903. con.ContainerName,
  16904. a.LotNo,
  16905. a.InvCode,
  16906. inv.InvName,
  16907. inv.InvStd,
  16908. inv.InvUnit,
  16909. {0}
  16910. inv.AmountUnit,
  16911. inv.AmountEnable,
  16912. ext.ID AS ExtensionID,
  16913. ext.ProjectCode,
  16914. ext.Version,
  16915. ext.Brand,
  16916. ext.cFree1,
  16917. ext.cFree2,
  16918. ext.cFree3,
  16919. ext.cFree4,
  16920. ext.cFree5,
  16921. ext.cFree6,
  16922. ext.cFree7,
  16923. ext.cFree8,
  16924. ext.cFree9,
  16925. ext.cFree10,
  16926. a.MUSER AS [User],
  16927. a.MTIME AS [MTime]
  16928. FROM {1}
  16929. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  16930. LEFT JOIN ICSBomALL bom ON bom.ID=conlot.ContainerID
  16931. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  16932. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  16933. WHERE bom.TContainerCode='{2}' AND a.WorkPoint='{3}' ";
  16934. }
  16935. }
  16936. #endregion
  16937. bool isOut = false; //出库标记
  16938. string columns = string.Empty; //查询源头单据表的特殊列名
  16939. string columnsLOCODE = string.Empty;
  16940. string columnsLONAME = string.Empty;
  16941. string columnsWHCODE = string.Empty;
  16942. string columnsWHNAME = string.Empty;
  16943. string tableName = string.Empty; //查询源头单据表名
  16944. string where = string.Empty; //排序
  16945. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription() //采购退货
  16946. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() //委外发料
  16947. || TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription() //委外退货
  16948. || TransType == TransTypeEnum.MOIssueDoc.GetDescription() //生产发料
  16949. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() //销售出库
  16950. || TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription() //一步调拨
  16951. || TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription() //调拨申请单
  16952. || TransType == TransTypeEnum.StepTransferDocIn.GetDescription() //调拨
  16953. || TransType == TransTypeEnum.StepNoTransferDocIn.GetDescription() //无源头调拨
  16954. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() //两步调出
  16955. || TransType == TransTypeEnum.OtherOutDoc.GetDescription() //其他出库
  16956. || TransType == TransTypeEnum.Check.GetDescription() //盘点
  16957. || TransType == TransTypeEnum.MOApply.GetDescription() //领料申请单
  16958. || TransType == TransTypeEnum.MOReplenishment.GetDescription() //领料申请单
  16959. || TransType == TransTypeEnum.OOApply.GetDescription() //委外领料申请单
  16960. || TransType == TransTypeEnum.MOIssue.GetDescription() //开立材料出库单
  16961. || TransType == TransTypeEnum.OOIssue.GetDescription() //开立委外材料出库单
  16962. || TransType == TransTypeEnum.PurchaseReceive.GetDescription() //开立红字入库单
  16963. || TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription()//开立委外红字入库单
  16964. || TransType == TransTypeEnum.BrrowDoc.GetDescription() //借用
  16965. || TransType == TransTypeEnum.TransferLibrary.GetDescription() //移库
  16966. //|| TransType == TransTypeEnum.DisassemblyDoc.GetDescription() //拆卸单(散件生成条码入库)
  16967. )
  16968. {
  16969. isOut = true;
  16970. }
  16971. //库位查询
  16972. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  16973. {
  16974. // Losql = @"" + Losql + "group by a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,inv.LotEnable,s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,s.sumQty,inv.AmountUnit,ext.ID,ext.ProjectCode,ext.Version,ext.Brand, " +
  16975. // "ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME";
  16976. // columns = @"s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,sum(a.Quantity) as Qty,s.sumQty,";
  16977. // tableName = @"ICSWareHouseLotInfo a
  16978. //LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  16979. //INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  16980. //INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  16981. //LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode from ICSWareHouseLotInfo group by WarehouseCode,INVCode)s
  16982. //ON a.INVCode=s.INVCode ";
  16983. }
  16984. else
  16985. {
  16986. //两步调入条码
  16987. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  16988. {
  16989. if (string.IsNullOrEmpty(JsonData.TransCode))
  16990. {
  16991. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  16992. }
  16993. if (ScanType == "LOTNO")
  16994. {
  16995. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSOtherIn Otin
  16996. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  16997. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  16998. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  16999. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  17000. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND Otin.InCode = '" + JsonData.TransCode + @"')
  17001. BEGIN
  17002. RAISERROR('" + language.GetNameByCode("WMSAPIInfo036") + @"',16,1);
  17003. RETURN
  17004. END
  17005. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  17006. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  17007. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  17008. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  17009. columns = @"SUM(log.Quantity) AS Quantity,
  17010. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  17011. a.WarehouseCode AS WHCode,
  17012. wh.WarehouseName AS WHName,
  17013. a.LocationCode,
  17014. loc.LocationName,
  17015. 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,";
  17016. tableName = @"ICSOtherIn Otin
  17017. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  17018. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  17019. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  17020. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  17021. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  17022. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  17023. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  17024. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  17025. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  17026. }
  17027. else
  17028. {
  17029. sql = @"WITH ICSBomALL AS
  17030. (
  17031. SELECT
  17032. ContainerCode AS TContainerCode,
  17033. ContainerCode AS PContainerCode,
  17034. ContainerCode AS ContainerCode,
  17035. ID,
  17036. ContainerID,
  17037. 0 AS [Level],
  17038. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  17039. CAST('00001' AS nvarchar(MAX)) AS Sort
  17040. FROM ICSContainer
  17041. WHERE ContainerCode='{2}'
  17042. UNION ALL
  17043. SELECT
  17044. b.TContainerCode,
  17045. b.ContainerCode AS PContainerCode,
  17046. a.ContainerCode,
  17047. a.ID,
  17048. a.ContainerID,
  17049. b.[Level]+1 AS [Level],
  17050. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  17051. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  17052. FROM
  17053. ICSContainer a
  17054. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  17055. )
  17056. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  17057. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  17058. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  17059. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  17060. columns = @"SUM(log.Quantity) AS Quantity,
  17061. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  17062. a.WarehouseCode AS WHCode,
  17063. wh.WarehouseName AS WHName,
  17064. a.LocationCode,
  17065. loc.LocationName,
  17066. 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,";
  17067. tableName = @"ICSOtherIn Otin
  17068. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  17069. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  17070. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  17071. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  17072. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  17073. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  17074. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  17075. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  17076. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  17077. }
  17078. }
  17079. //销售退货-原条码(可支持一个条码多次发货,汇总数量,目前加了限制:785-793行)
  17080. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  17081. {
  17082. if (string.IsNullOrEmpty(JsonData.TransCode))
  17083. {
  17084. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  17085. }
  17086. if (ScanType == "LOTNO")
  17087. {
  17088. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSSDN sdn
  17089. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  17090. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  17091. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1')
  17092. BEGIN
  17093. RAISERROR('" + language.GetNameByCode("WMSAPIInfo037") + @"',16,1);
  17094. RETURN
  17095. END
  17096. IF EXISTS(SELECT log.LotNo FROM ICSSDN sdn
  17097. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  17098. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  17099. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1' AND log.BusinessCode='19'
  17100. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  17101. BEGIN
  17102. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo191"), "{2}") + @"',16,1);
  17103. RETURN
  17104. END
  17105. " + sql + @"AND sdn.Type='1'
  17106. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  17107. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  17108. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  17109. columns = @"SUM(log.Quantity) AS Quantity,
  17110. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  17111. a.WarehouseCode AS WHCode,
  17112. wh.WarehouseName AS WHName,
  17113. a.LocationCode,
  17114. loc.LocationName,
  17115. 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,";
  17116. tableName = @"ICSSDN sdn
  17117. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  17118. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  17119. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  17120. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  17121. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  17122. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  17123. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  17124. }
  17125. else
  17126. {
  17127. sql = @"WITH ICSBomALL AS
  17128. (
  17129. SELECT
  17130. ContainerCode AS TContainerCode,
  17131. ContainerCode AS PContainerCode,
  17132. ContainerCode AS ContainerCode,
  17133. ID,
  17134. ContainerID,
  17135. 0 AS [Level],
  17136. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  17137. CAST('00001' AS nvarchar(MAX)) AS Sort
  17138. FROM ICSContainer
  17139. WHERE ContainerCode='{2}'
  17140. UNION ALL
  17141. SELECT
  17142. b.TContainerCode,
  17143. b.ContainerCode AS PContainerCode,
  17144. a.ContainerCode,
  17145. a.ID,
  17146. a.ContainerID,
  17147. b.[Level]+1 AS [Level],
  17148. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  17149. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  17150. FROM
  17151. ICSContainer a
  17152. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  17153. )
  17154. " + sql + @"AND sdn.Type='1'
  17155. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  17156. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  17157. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME";
  17158. columns = @"SUM(log.Quantity) AS Quantity,
  17159. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  17160. a.WarehouseCode AS WHCode,
  17161. wh.WarehouseName AS WHName,
  17162. a.LocationCode,
  17163. loc.LocationName,
  17164. 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,";
  17165. tableName = @"ICSSDN sdn
  17166. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  17167. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  17168. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  17169. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  17170. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  17171. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  17172. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  17173. }
  17174. }
  17175. //生产(委外)退料-原条码+新条码
  17176. //先校验日志里面是否有原条码(同一种类型的条码只能发一次料才能原条码退,不然更新源头单据数量有问题,根据LogID判断是否原条码退回),如果没有查询新条码
  17177. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  17178. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  17179. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription()
  17180. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  17181. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  17182. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  17183. {
  17184. string type = "13";
  17185. string msglanguage = "WMSAPIInfo185";
  17186. if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  17187. {
  17188. type = "14";
  17189. msglanguage = "WMSAPIInfo186";
  17190. }
  17191. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  17192. {
  17193. type = "15";
  17194. msglanguage = "WMSAPIInfo187";
  17195. }
  17196. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  17197. {
  17198. type = "5";
  17199. msglanguage = "WMSAPIInfo188";
  17200. }
  17201. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  17202. {
  17203. type = "6";
  17204. msglanguage = "WMSAPIInfo189";
  17205. }
  17206. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  17207. {
  17208. type = "7";
  17209. msglanguage = "WMSAPIInfo190";
  17210. }
  17211. #region 新条码
  17212. if (ScanType == "LOTNO")
  17213. {
  17214. sqlNew = @"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  17215. BEGIN
  17216. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  17217. RETURN
  17218. END
  17219. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  17220. BEGIN
  17221. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  17222. RETURN
  17223. END
  17224. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  17225. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  17226. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  17227. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1'AND ins.LotNo IS NULL))
  17228. BEGIN
  17229. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  17230. RETURN
  17231. END
  17232. " + sql;
  17233. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  17234. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  17235. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  17236. {
  17237. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  17238. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  17239. (select negg.WHCode from ICSMOApplyNegDetail neg
  17240. INNER JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  17241. inner join ICSInventoryLotDetail lotdetail on neg.ApplyNegCode=lotdetail.TransCode
  17242. and neg.Sequence=lotdetail.TransSequence
  17243. where lotdetail.LotNo=a.LotNo and lotdetail.WorkPoint=a.WorkPoint) AS WHCode,
  17244. '' AS WHName,
  17245. '' AS LocationCode,
  17246. '' AS LocationName,
  17247. '' AS LogID,
  17248. ext.BatchCode AS BatchCode,";
  17249. }
  17250. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  17251. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  17252. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  17253. {
  17254. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  17255. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  17256. (select negg.WHCode from ICSOApplyNegDetail neg
  17257. INNER JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  17258. inner join ICSInventoryLotDetail lotdetail on neg.OApplyNegCode=lotdetail.TransCode
  17259. and neg.Sequence=lotdetail.TransSequence
  17260. where lotdetail.LotNo=a.LotNo and lotdetail.WorkPoint=a.WorkPoint) AS WHCode,
  17261. '' AS WHName,
  17262. '' AS LocationCode,
  17263. '' AS LocationName,
  17264. '' AS LogID,
  17265. ext.BatchCode AS BatchCode,";
  17266. }
  17267. tableName = @"ICSInventoryLot a
  17268. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  17269. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  17270. }
  17271. else
  17272. {
  17273. sqlNew = @"WITH ICSBomALL AS
  17274. (
  17275. SELECT
  17276. ContainerCode AS TContainerCode,
  17277. ContainerCode AS PContainerCode,
  17278. ContainerCode AS ContainerCode,
  17279. ID,
  17280. ContainerID,
  17281. 0 AS [Level],
  17282. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  17283. CAST('00001' AS nvarchar(MAX)) AS Sort
  17284. FROM ICSContainer
  17285. WHERE ContainerCode='{2}'
  17286. UNION ALL
  17287. SELECT
  17288. b.TContainerCode,
  17289. b.ContainerCode AS PContainerCode,
  17290. a.ContainerCode,
  17291. a.ID,
  17292. a.ContainerID,
  17293. b.[Level]+1 AS [Level],
  17294. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  17295. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  17296. FROM
  17297. ICSContainer a
  17298. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  17299. )
  17300. " + sql;
  17301. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  17302. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  17303. '' AS WHCode,
  17304. '' AS WHName,
  17305. '' AS LocationCode,
  17306. '' AS LocationName,
  17307. ext.BatchCode AS BatchCode,";
  17308. tableName = @"ICSInventoryLot a
  17309. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  17310. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  17311. }
  17312. sqlNew = string.Format(sqlNew, columns, tableName, JsonData.Code, JsonData.WorkPoint, zlqty);
  17313. #endregion
  17314. #region 原条码
  17315. if (ScanType == "LOTNO")
  17316. {
  17317. sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  17318. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN(invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')= '1') OR ISNULL(invBat.BatchEnable, '0')= '1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  17319. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME
  17320. ";
  17321. sql = @"IF EXISTS(" + sql + @")
  17322. BEGIN
  17323. " + sql + @"
  17324. END
  17325. ELSE
  17326. BEGIN
  17327. " + sqlNew + @"
  17328. END";
  17329. //sql = @"IF EXISTS(SELECT log.LotNo FROM ICSWareHouseLotInfoLog log
  17330. // INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  17331. // WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND log.TransCode='{5}' AND log.TransSequence='{6}' AND log.BusinessCode='" + type + @"'
  17332. // GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  17333. //BEGIN
  17334. // RAISERROR('" + string.Format(language.GetNameByCode(msglanguage), "{2}") + @"',16,1);
  17335. // RETURN
  17336. //END
  17337. //" + sql;
  17338. columns = @"SUM(log.Quantity) AS Quantity,
  17339. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  17340. a.WarehouseCode AS WHCode,
  17341. wh.WarehouseName AS WHName,
  17342. a.LocationCode,
  17343. loc.LocationName,
  17344. log.ID AS LogID,
  17345. 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,";
  17346. tableName = @"ICSWareHouseLotInfoLog log
  17347. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  17348. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  17349. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  17350. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  17351. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  17352. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  17353. }
  17354. else
  17355. {
  17356. sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  17357. wh.WarehouseName,a.LocationCode,loc.LocationName,CASE WHEN(invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')= '1') OR ISNULL(invBat.BatchEnable, '0')= '1' THEN ISNULL(ext.BatchCode, '') ELSE '' END,inv.AmountUnit,
  17358. ext.ID,ext.ProjectCode,ext.Version,ext.Brand,ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER,a.MTIME
  17359. ";
  17360. sql = @"IF EXISTS(" + sql + @")
  17361. BEGIN
  17362. " + sql + @"
  17363. END
  17364. ELSE
  17365. BEGIN
  17366. " + sqlNew + @"
  17367. END";
  17368. sql = @"WITH ICSBomALL AS
  17369. (
  17370. SELECT
  17371. ContainerCode AS TContainerCode,
  17372. ContainerCode AS PContainerCode,
  17373. ContainerCode AS ContainerCode,
  17374. ID,
  17375. ContainerID,
  17376. 0 AS [Level],
  17377. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  17378. CAST('00001' AS nvarchar(MAX)) AS Sort
  17379. FROM ICSContainer
  17380. WHERE ContainerCode='{2}'
  17381. UNION ALL
  17382. SELECT
  17383. b.TContainerCode,
  17384. b.ContainerCode AS PContainerCode,
  17385. a.ContainerCode,
  17386. a.ID,
  17387. a.ContainerID,
  17388. b.[Level]+1 AS [Level],
  17389. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  17390. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  17391. FROM
  17392. ICSContainer a
  17393. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  17394. )
  17395. " + sql;
  17396. columns = @"SUM(log.Quantity) AS Quantity,
  17397. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  17398. a.WarehouseCode AS WHCode,
  17399. wh.WarehouseName AS WHName,
  17400. a.LocationCode,
  17401. loc.LocationName,
  17402. log.ID AS LogID,
  17403. 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,";
  17404. tableName = @"ICSWareHouseLotInfoLog log
  17405. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  17406. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  17407. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  17408. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  17409. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  17410. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  17411. }
  17412. #endregion
  17413. }
  17414. //分批
  17415. else if (TransType == TransTypeEnum.LOTSplit.GetDescription() || TransType == TransTypeEnum.LOTMerge.GetDescription())
  17416. {
  17417. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  17418. BEGIN
  17419. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  17420. RETURN
  17421. END
  17422. " + sql;
  17423. columns = @"a.Quantity,
  17424. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  17425. a.WarehouseCode AS WHCode,
  17426. wh.WarehouseName AS WHName,
  17427. a.LocationCode,
  17428. loc.LocationName,
  17429. 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,
  17430. ISNULL(split.SplitLotNo, a.LotNo+'-1') AS SplitLotNo,";
  17431. tableName = @"ICSWareHouseLotInfo a
  17432. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  17433. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  17434. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  17435. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  17436. LEFT JOIN (SELECT EATTRIBUTE1 AS LotNo,WorkPoint,EATTRIBUTE1+'-'+CAST((MAX(CAST(reverse(substring(reverse(LotNo),1,charindex('-',reverse(LotNo)) - 1)) AS INT))+1) AS VARCHAR) AS SplitLotNo FROM ICSInventoryLot GROUP BY EATTRIBUTE1,WorkPoint) split ON a.LotNo=split.LotNo AND a.WorkPoint=split.WorkPoint
  17437. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  17438. }
  17439. //出库条码
  17440. else if (isOut)
  17441. {
  17442. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() || TransType == TransTypeEnum.MOApply.GetDescription()
  17443. || TransType == TransTypeEnum.MOIssue.GetDescription() || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription()
  17444. || TransType == TransTypeEnum.OOApply.GetDescription() || TransType == TransTypeEnum.OOIssue.GetDescription()
  17445. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() || TransType == TransTypeEnum.OtherOutDoc.GetDescription()
  17446. || TransType == TransTypeEnum.BrrowDoc.GetDescription() || TransType == TransTypeEnum.StepTransferDocIn.GetDescription()
  17447. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() || TransType == TransTypeEnum.MOReplenishment.GetDescription())
  17448. {
  17449. string uersql = @"SELECT F_RealName from Sys_SRM_User where F_Account='{0}' AND F_Location='{1}'
  17450. ";
  17451. uersql = string.Format(uersql, JsonData.User, JsonData.WorkPoint);
  17452. DataTable dt = DBHelper.SQlReturnData(uersql, cmd);
  17453. if (dt.Rows.Count == 0)
  17454. {
  17455. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  17456. }
  17457. else
  17458. {
  17459. UserName = dt.Rows[0]["F_RealName"].ToString();
  17460. }
  17461. UName = UserName.Substring(0, 2);
  17462. switch (UName)
  17463. {
  17464. case "L1":
  17465. UName = "021";
  17466. break;
  17467. case "L2":
  17468. UName = "022";
  17469. break;
  17470. case "L3":
  17471. UName = "023";
  17472. break;
  17473. case "L4":
  17474. UName = "024";
  17475. break;
  17476. case "L5":
  17477. UName = "025";
  17478. break;
  17479. case "L6":
  17480. UName = "026";
  17481. break;
  17482. case "L7":
  17483. UName = "025";
  17484. break;
  17485. case "C1":
  17486. UName = "004";
  17487. break;
  17488. }
  17489. ZLtable = ICSControlModeService.GetZL();
  17490. if (ZLtable == null)
  17491. {
  17492. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  17493. }
  17494. for (int i = 0; i < ZLtable.Rows.Count; i++)
  17495. {
  17496. string zlName = ZLtable.Rows[i]["Name"].ToString();
  17497. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  17498. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  17499. if (JsonData.TransType.Equals(zlName))
  17500. {
  17501. if (Enable.Equals("True"))
  17502. {
  17503. string zlsql = @"IF NOT EXISTS(select a.Quantity,c.Name from ICSWareHouseLotInfoLog a
  17504. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
  17505. left join ICSType c on a.BusinessCode=c.Code and c.tablecode='ICSWareHouseLotInfoLog' and c.ColumnCode='BusinessCode'
  17506. where b.LotNo='{0}' and b.WorkPoint='{1}' and a.TransType='15' and c.name='{2}' and (a.TransCode='{3}' or a.MergeID='{3}'))
  17507. BEGIN
  17508. RAISERROR('" + language.GetNameByCode("WMSAPIInfo469") + @"',16,1);
  17509. RETURN
  17510. END
  17511. select SUM(a.Quantity) AS Quantity from ICSWareHouseLotInfoLog a
  17512. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
  17513. --left join ICSType c on a.BusinessCode=c.Code and c.tablecode='ICSWareHouseLotInfoLog' and c.ColumnCode='BusinessCode'
  17514. where b.LotNo='{0}' and b.WorkPoint='{1}' and a.TransType='15' and c.name='{2}' and (a.TransCode='{3}' or a.MergeID='{3}')";
  17515. zlsql = string.Format(zlsql, JsonData.Code, JsonData.WorkPoint, JsonData.TransType, JsonData.TransCode);
  17516. DataTable zlltable = DBHelper.SQlReturnData(zlsql, cmd);
  17517. if (zlltable != null || zlltable.Rows.Count > 0)
  17518. {
  17519. zlqty = zlltable.Rows[0]["Quantity"].ToString();
  17520. iszl = true;
  17521. }
  17522. }
  17523. }
  17524. }
  17525. }
  17526. if (ScanType == "LOTNO")
  17527. {
  17528. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() )
  17529. {
  17530. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  17531. BEGIN
  17532. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  17533. RETURN
  17534. END
  17535. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0 AND a.WareHouseCode='{5}')
  17536. BEGIN
  17537. RAISERROR('线',16,1)
  17538. RETURN
  17539. END
  17540. " + sql;
  17541. }
  17542. if (iszl)
  17543. {
  17544. columns = @"{0} as Quantity,
  17545. {0}*(lot.Amount/lot.Quantity) AS Amount,
  17546. a.id AS LogID,
  17547. a.FromWarehouseCode AS WHCode,
  17548. wh.WarehouseName AS WHName,
  17549. inv.LotEnable,
  17550. a.FromLocationCode,
  17551. lot.ProductDate,
  17552. loc.LocationName,
  17553. 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,";
  17554. columns = string.Format(columns, zlqty);
  17555. tableName = @"ICSWareHouseLotInfoLog a
  17556. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  17557. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  17558. INNER JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  17559. INNER JOIN ICSLocation loc ON a.FromLocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  17560. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  17561. }
  17562. else
  17563. {
  17564. columns = @"(a.Quantity-a.lockQuantity) AS Quantity,
  17565. (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
  17566. '' AS LogID,
  17567. a.WarehouseCode AS WHCode,
  17568. wh.WarehouseName AS WHName,
  17569. inv.LotEnable,
  17570. a.LocationCode,
  17571. lot.ProductDate,
  17572. loc.LocationName,
  17573. 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,";
  17574. tableName = @"ICSWareHouseLotInfo a
  17575. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  17576. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  17577. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  17578. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  17579. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  17580. }
  17581. }
  17582. else
  17583. {
  17584. sql = @"
  17585. WITH ICSBomALL AS
  17586. (
  17587. SELECT
  17588. ContainerCode AS TContainerCode,
  17589. ContainerCode AS PContainerCode,
  17590. ContainerCode AS ContainerCode,
  17591. ID,
  17592. ContainerID,
  17593. 0 AS [Level],
  17594. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  17595. CAST('00001' AS nvarchar(MAX)) AS Sort
  17596. FROM ICSContainer
  17597. WHERE ContainerCode='{2}'
  17598. UNION ALL
  17599. SELECT
  17600. b.TContainerCode,
  17601. b.ContainerCode AS PContainerCode,
  17602. a.ContainerCode,
  17603. a.ID,
  17604. a.ContainerID,
  17605. b.[Level]+1 AS [Level],
  17606. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  17607. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  17608. FROM
  17609. ICSContainer a
  17610. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  17611. )
  17612. " + sql;
  17613. columns = @"(a.Quantity-a.lockQuantity) AS Quantity,
  17614. (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
  17615. a.WarehouseCode AS WHCode,
  17616. wh.WarehouseName AS WHName,
  17617. a.LocationCode,
  17618. lot.ProductDate,
  17619. loc.LocationName,
  17620. 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,";
  17621. tableName = @"ICSWareHouseLotInfo a
  17622. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  17623. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  17624. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  17625. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  17626. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  17627. ";
  17628. }
  17629. }
  17630. //入库条码
  17631. else
  17632. {
  17633. if (ScanType == "LOTNO")
  17634. {
  17635. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  17636. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  17637. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription()
  17638. || TransType == TransTypeEnum.UnqualifiedIN.GetDescription() || TransType == TransTypeEnum.MOStockINByProduct.GetDescription()
  17639. || TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  17640. {
  17641. //联产品入库(有来源单据)不可扫入无来源条码
  17642. if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
  17643. {
  17644. sql = @"
  17645. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}' AND a.Type = 19 )
  17646. BEGIN
  17647. RAISERROR('', 16, 1);
  17648. RETURN;
  17649. END
  17650. " + sql;
  17651. }
  17652. sql = @"
  17653. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  17654. BEGIN
  17655. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  17656. RETURN
  17657. END
  17658. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  17659. BEGIN
  17660. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  17661. RETURN
  17662. END
  17663. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  17664. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  17665. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  17666. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1' AND ins.LotNo IS NULL))
  17667. BEGIN
  17668. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  17669. RETURN
  17670. END
  17671. " + sql;
  17672. }
  17673. else
  17674. {
  17675. sql = @"
  17676. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  17677. BEGIN
  17678. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  17679. RETURN
  17680. END
  17681. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  17682. BEGIN
  17683. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  17684. RETURN
  17685. END
  17686. " + sql;
  17687. }
  17688. ControlMode mode = ICSControlModeService.GetSuLocation();
  17689. //获取条码类型
  17690. LotTypesql = @"IF NOT EXISTS(SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}')
  17691. BEGIN
  17692. RAISERROR('" + language.GetNameByCode("WMSAPIInfo461") + @"',16,1);
  17693. RETURN
  17694. END
  17695. SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}'";
  17696. LotTypesql = string.Format(LotTypesql, JsonData.Code, JsonData.WorkPoint);
  17697. DataTable dt = DBHelper.SQlReturnData(LotTypesql, cmd);
  17698. if (dt != null && dt.Rows.Count > 0)
  17699. {
  17700. LotType = dt.Rows[0]["Type"].ToString();
  17701. }
  17702. if (mode != null)
  17703. {
  17704. if (mode.itemCode.Equals("LocationRemind01"))//固定库位:物料和库位绑定,显示库位名称列表
  17705. {
  17706. columnsLONAME = @"
  17707. (SELECT locat.LocationName from ICSWareHouseLotInfo loinfo
  17708. LEFT JOIN ICSLocation locat on locat.LocationCode=loinfo.LocationCode and loinfo.WorkPoint=locat.WorkPoint
  17709. where loinfo.lotno=a.lotno and loinfo.invcode=a.invcode and a.WorkPoint=loinfo.WorkPoint) AS LocationName,";
  17710. columnsLOCODE = @"
  17711. (SELECT locat.LocationCode from ICSWareHouseLotInfo loinfo
  17712. LEFT JOIN ICSLocation locat on locat.LocationCode=loinfo.LocationCode and loinfo.WorkPoint=locat.WorkPoint
  17713. where loinfo.lotno=a.lotno and loinfo.invcode=a.invcode and a.WorkPoint=loinfo.WorkPoint) AS LocationCode,";
  17714. }
  17715. else if (mode.itemCode.Equals("LocationRemind02"))//在库库位:物料有库存的对应库位,显示库位名称列表
  17716. {
  17717. columnsLONAME = @"
  17718. STUFF(
  17719. (SELECT DISTINCT ',' + LocationName
  17720. from ICSLocation wh
  17721. LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
  17722. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
  17723. FOR xml path('')
  17724. ),1,1,''
  17725. ) AS LocationName,";
  17726. columnsLOCODE = @"
  17727. STUFF(
  17728. (SELECT DISTINCT ',' + LocationCode
  17729. from ICSLocation wh
  17730. LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
  17731. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
  17732. FOR xml path('')
  17733. ),1,1,''
  17734. ) AS LocationCode,";
  17735. }
  17736. else if (mode.itemCode.Equals("LocationRemind03"))//最近一次出入库的库位,显示库位名称
  17737. {
  17738. columnsLONAME = @"
  17739. (SELECT Top 1 locat.LocationName from ICSWareHouseLotInfoLog log
  17740. LEFT JOIN ICSLocation locat on locat.LocationCode=log.ToLocationCode and log.WorkPoint=locat.WorkPoint where log.TransType='2' and a.InvCode=log.InvCode AND a.WorkPoint=log.WorkPoint
  17741. ORDER BY log.Mtime desc) AS LocationName,";
  17742. columnsLOCODE = @"
  17743. (SELECT Top 1 locat.LocationCode from ICSWareHouseLotInfoLog log
  17744. LEFT JOIN ICSLocation locat on locat.LocationCode=log.ToLocationCode and log.WorkPoint=locat.WorkPoint where log.TransType='2' and a.InvCode=log.InvCode AND a.WorkPoint=log.WorkPoint
  17745. ORDER BY log.Mtime desc) AS LocationCode,";
  17746. }
  17747. }
  17748. else
  17749. {
  17750. columnsLONAME = @"
  17751. STUFF(
  17752. (SELECT DISTINCT ',' + LocationName
  17753. from ICSLocation wh
  17754. LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
  17755. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
  17756. FOR xml path('')
  17757. ),1,1,''
  17758. ) AS LocationName,";
  17759. columnsLOCODE = @"
  17760. STUFF(
  17761. (SELECT DISTINCT ',' + LocationCode
  17762. from ICSLocation wh
  17763. LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
  17764. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
  17765. FOR xml path('')
  17766. ),1,1,''
  17767. ) AS LocationCode,";
  17768. }
  17769. #region 根据条码类型找到单据仓库信息
  17770. if (LotType.Equals("1"))
  17771. {//生产退料
  17772. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  17773. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1'),'') AS WHCode";
  17774. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  17775. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
  17776. }
  17777. else if (LotType.Equals("2"))
  17778. {//委外退料
  17779. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  17780. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1'),'') AS WHCode";
  17781. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  17782. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
  17783. }
  17784. else if (LotType.Equals("3"))
  17785. {//工单
  17786. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSMO a WHERE a.MOCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
  17787. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSMO a WHERE a.MOCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
  17788. }
  17789. else if (LotType.Equals("4"))
  17790. {//销售退货
  17791. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSSDN a WHERE a.SDNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
  17792. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSSDN a WHERE a.SDNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
  17793. }
  17794. else if (LotType.Equals("5"))
  17795. {//其他入库
  17796. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSOtherIn a WHERE a.InCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
  17797. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSOtherIn a WHERE a.InCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
  17798. }
  17799. else if (LotType.Equals("6"))
  17800. {//归还单
  17801. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSReturn a WHERE a.ReturnCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
  17802. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSReturn a WHERE a.ReturnCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
  17803. }
  17804. else if (LotType.Equals("7"))
  17805. {//采购到货单
  17806. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='1'),'') AS WHCode";
  17807. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
  17808. }
  17809. else if (LotType.Equals("8"))
  17810. {//委外到货单
  17811. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='1'),'') AS WHCode";
  17812. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='1') AND WorkPoint=a.WorkPoint),'') AS WHName";
  17813. }
  17814. else if (LotType.Equals("9"))
  17815. {//成品入库单
  17816. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSManufactureReceive a WHERE a.RCVCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint),'') AS WHCode";
  17817. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSManufactureReceive a WHERE a.RCVCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName";
  17818. }
  17819. else if (LotType.Equals("10"))
  17820. {//拒收单
  17821. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='3'),'') AS WHCode";
  17822. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSDeliveryNotice a WHERE a.DNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint AND a.DNType='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
  17823. }
  17824. else if (LotType.Equals("11"))
  17825. {//委外拒收单
  17826. columnsWHCODE = @"ISNULL((SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='3'),'') AS WHCode";
  17827. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT a.WHCode FROM ICSODeliveryNotice a WHERE a.ODNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint and a.ODNType='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
  17828. }
  17829. else if (LotType.Equals("12"))
  17830. {//领料申请退料
  17831. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  17832. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2'),'') AS WHCode";
  17833. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  17834. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2') AND WorkPoint=a.WorkPoint),'') AS WHName";
  17835. }
  17836. else if (LotType.Equals("13"))
  17837. {//材料出库退料
  17838. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  17839. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3'),'') AS WHCode";
  17840. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  17841. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
  17842. }
  17843. else if (LotType.Equals("14"))
  17844. {//委外领料申请退料
  17845. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  17846. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2'),'') AS WHCode";
  17847. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  17848. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2') AND WorkPoint=a.WorkPoint),'') AS WHName";
  17849. }
  17850. else if (LotType.Equals("15"))
  17851. {//委外材料出库退料
  17852. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  17853. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3'),'') AS WHCode";
  17854. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  17855. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3') AND WorkPoint=a.WorkPoint),'') AS WHName";
  17856. }
  17857. else if (LotType.Equals("16"))
  17858. {//返工工单
  17859. columnsWHCODE = @"ISNULL((SELECT pick.WHCode FROM ICSMOPick pick LEFT JOIN ICSMO moo ON pick.MODetailID=moo.MODetailID AND pick.WorkPoint=moo.WorkPoint
  17860. WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint),'') AS WHCode ";
  17861. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT pick.WHCode FROM ICSMOPick pick LEFT JOIN ICSMO moo ON pick.MODetailID=moo.MODetailID AND pick.WorkPoint=moo.WorkPoint
  17862. WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName ";
  17863. }
  17864. else
  17865. {
  17866. columnsWHCODE = @"'' AS WHCode";
  17867. columnsWHNAME = @"'' AS WHName";
  17868. }
  17869. #endregion
  17870. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  17871. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  17872. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription()
  17873. || TransType == TransTypeEnum.UnqualifiedIN.GetDescription() || TransType == TransTypeEnum.MOStockINByProduct.GetDescription()
  17874. || TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  17875. {
  17876. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  17877. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  17878. {0},{2},
  17879. lotdd.TransCode,lotdd.TransSequence,
  17880. {3}
  17881. {1}
  17882. ext.BatchCode AS BatchCode,";
  17883. tableName = @"ICSInventoryLot a
  17884. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  17885. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
  17886. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  17887. }
  17888. else
  17889. {
  17890. columns = @"a.Quantity AS Quantity,
  17891. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  17892. {0},{2},
  17893. {3}
  17894. {1}
  17895. ext.BatchCode AS BatchCode,";
  17896. tableName = @"ICSInventoryLot a
  17897. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  17898. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint";
  17899. }
  17900. columns = string.Format(columns, columnsWHCODE, columnsLONAME, columnsWHNAME, columnsLOCODE);
  17901. }
  17902. else
  17903. {
  17904. sql = @"
  17905. WITH ICSBomALL AS
  17906. (
  17907. SELECT
  17908. ContainerCode AS TContainerCode,
  17909. ContainerCode AS PContainerCode,
  17910. ContainerCode AS ContainerCode,
  17911. ID,
  17912. ContainerID,
  17913. 0 AS [Level],
  17914. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  17915. CAST('00001' AS nvarchar(MAX)) AS Sort
  17916. FROM ICSContainer
  17917. WHERE ContainerCode='{2}'
  17918. UNION ALL
  17919. SELECT
  17920. b.TContainerCode,
  17921. b.ContainerCode AS PContainerCode,
  17922. a.ContainerCode,
  17923. a.ID,
  17924. a.ContainerID,
  17925. b.[Level]+1 AS [Level],
  17926. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  17927. CAST(b.Sort+'.'+REPLICATE('0',5-len(row_number() over (order by a.ContainerCode)))+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS nvarchar(MAX)) AS Sort
  17928. FROM
  17929. ICSContainer a
  17930. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  17931. )
  17932. " + sql;
  17933. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  17934. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  17935. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription()
  17936. || TransType == TransTypeEnum.UnqualifiedIN.GetDescription() || TransType == TransTypeEnum.MOStockINByProduct.GetDescription()
  17937. || TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  17938. {
  17939. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  17940. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  17941. '' AS WHCode,
  17942. '' AS WHName,
  17943. '' AS LocationCode,
  17944. '' AS LocationName,
  17945. ext.BatchCode AS BatchCode,";
  17946. tableName = @"ICSInventoryLot a
  17947. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  17948. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  17949. }
  17950. else
  17951. {
  17952. columns = @"a.Quantity AS Quantity,
  17953. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  17954. '' AS WHCode,
  17955. '' AS WHName,
  17956. '' AS LocationCode,
  17957. '' AS LocationName,
  17958. ext.BatchCode AS BatchCode,";
  17959. tableName = @"ICSInventoryLot a
  17960. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint";
  17961. }
  17962. }
  17963. }
  17964. }
  17965. if (TransType != TransTypeEnum.LocationSeatch.GetDescription())
  17966. {
  17967. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName))
  17968. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  17969. }
  17970. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  17971. {
  17972. Losql = string.Format(Losql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  17973. table = DBHelper.SQlReturnData(Losql, cmd);
  17974. }
  17975. else
  17976. {
  17977. sql = string.Format(sql, columns, tableName, JsonData.Code, JsonData.WorkPoint, zlqty, UName,JsonData.TransCode,JsonData.TransSequence);
  17978. table = DBHelper.SQlReturnData(sql, cmd);
  17979. }
  17980. if (table == null || table.Rows.Count <= 0)
  17981. throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
  17982. #region 出库检验是否符合源头单据
  17983. string msg = string.Empty;
  17984. bool isLimit = false;
  17985. string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode' and F_EnabledMark = '1'";
  17986. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  17987. if (isOut) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
  17988. {//&& TransType != TransTypeEnum.TransferLibrary.GetDescription()
  17989. string Lot = "";
  17990. string workP = "";
  17991. if (TransType == TransTypeEnum.TransferLibrary.GetDescription())
  17992. {
  17993. foreach (DataRow drLot in table.Rows)
  17994. {
  17995. Lot = drLot["LotNo"].ToString();
  17996. sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  17997. sql = string.Format(sql, Lot, JsonData.WorkPoint);
  17998. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  17999. if (dt == null || dt.Rows.Count <= 0)
  18000. {
  18001. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), Lot));
  18002. }
  18003. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  18004. if (!JsonData.WHCode.Equals(whcode))
  18005. {
  18006. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo395"), JsonData.WHCode, whcode));
  18007. }
  18008. }
  18009. }
  18010. else if (TransType != TransTypeEnum.LocationSeatch.GetDescription() && TransType != TransTypeEnum.StepNoTransferDocIn.GetDescription())
  18011. {
  18012. if (string.IsNullOrEmpty(JsonData.TransCode))
  18013. {
  18014. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  18015. }
  18016. WMSSourceDocumentModel model = new WMSSourceDocumentModel();
  18017. model.TransCode = JsonData.TransCode;
  18018. model.TransSequence = JsonData.TransSequence;
  18019. model.TransType = JsonData.TransType;
  18020. model.WorkPoint = JsonData.WorkPoint;
  18021. model.User = JsonData.User;
  18022. DataTable TransData = AMTransInformationGet(model);
  18023. DataView dataView = TransData.DefaultView;
  18024. foreach (DataRow drLot in table.Rows)
  18025. {
  18026. Lot = drLot["LotNo"].ToString();
  18027. //盘点不需要对比以下属性
  18028. if (TransType == TransTypeEnum.Check.GetDescription())
  18029. continue;
  18030. string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
  18031. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
  18032. if (TransType != TransTypeEnum.MOIssueDoc.GetDescription())
  18033. {
  18034. rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
  18035. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
  18036. }
  18037. rowFilter += " AND (LEN(ISNULL(ProjectCode,''))<=0 OR (LEN(ISNULL(ProjectCode,''))>0 AND ProjectCode='" + drLot["ProjectCode"] + "'))";
  18038. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["ProjectCode"], GetExtentionName("ProjectCode", JsonData.WorkPoint, cmd, language)));
  18039. rowFilter += "AND (LEN(ISNULL(BatchCode,''))<=0 OR (LEN(ISNULL(BatchCode,''))>0 AND BatchCode='" + drLot["BatchCode"] + "'))";
  18040. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["BatchCode"], GetExtentionName("BatchCode", JsonData.WorkPoint, cmd, language)));
  18041. rowFilter += "AND (LEN(ISNULL(Version,''))<=0 OR (LEN(ISNULL(Version,''))>0 AND Version='" + drLot["Version"] + "'))";
  18042. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["Version"], GetExtentionName("Version", JsonData.WorkPoint, cmd, language)));
  18043. rowFilter += "AND (LEN(ISNULL(Brand,''))<=0 OR (LEN(ISNULL(Brand,''))>0 AND Brand='" + drLot["Brand"] + "'))";
  18044. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["Brand"], GetExtentionName("Brand", JsonData.WorkPoint, cmd, language)));
  18045. rowFilter += "AND (LEN(ISNULL(cFree1,''))<=0 OR (LEN(ISNULL(cFree1,''))>0 AND cFree1='" + drLot["cFree1"] + "'))";
  18046. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree1"], GetExtentionName("cFree1", JsonData.WorkPoint, cmd, language)));
  18047. rowFilter += "AND (LEN(ISNULL(cFree2,''))<=0 OR (LEN(ISNULL(cFree2,''))>0 AND cFree2='" + drLot["cFree2"] + "'))";
  18048. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree2"], GetExtentionName("cFree2", JsonData.WorkPoint, cmd, language)));
  18049. rowFilter += "AND (LEN(ISNULL(cFree3,''))<=0 OR (LEN(ISNULL(cFree3,''))>0 AND cFree3='" + drLot["cFree3"] + "'))";
  18050. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree3"], GetExtentionName("cFree3", JsonData.WorkPoint, cmd, language)));
  18051. rowFilter += "AND (LEN(ISNULL(cFree4,''))<=0 OR (LEN(ISNULL(cFree4,''))>0 AND cFree4='" + drLot["cFree4"] + "'))";
  18052. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree4"], GetExtentionName("cFree4", JsonData.WorkPoint, cmd, language)));
  18053. rowFilter += "AND (LEN(ISNULL(cFree5,''))<=0 OR (LEN(ISNULL(cFree5,''))>0 AND cFree5='" + drLot["cFree5"] + "'))";
  18054. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree5"], GetExtentionName("cFree5", JsonData.WorkPoint, cmd, language)));
  18055. rowFilter += "AND (LEN(ISNULL(cFree6,''))<=0 OR (LEN(ISNULL(cFree6,''))>0 AND cFree6='" + drLot["cFree6"] + "'))";
  18056. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree6"], GetExtentionName("cFree6", JsonData.WorkPoint, cmd, language)));
  18057. rowFilter += "AND (LEN(ISNULL(cFree7,''))<=0 OR (LEN(ISNULL(cFree7,''))>0 AND cFree7='" + drLot["cFree7"] + "'))";
  18058. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree7"], GetExtentionName("cFree7", JsonData.WorkPoint, cmd, language)));
  18059. rowFilter += "AND (LEN(ISNULL(cFree8,''))<=0 OR (LEN(ISNULL(cFree8,''))>0 AND cFree8='" + drLot["cFree8"] + "'))";
  18060. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree8"], GetExtentionName("cFree8", JsonData.WorkPoint, cmd, language)));
  18061. rowFilter += "AND (LEN(ISNULL(cFree9,''))<=0 OR (LEN(ISNULL(cFree9,''))>0 AND cFree9='" + drLot["cFree9"] + "'))";
  18062. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree9"], GetExtentionName("cFree9", JsonData.WorkPoint, cmd, language)));
  18063. rowFilter += "AND (LEN(ISNULL(cFree10,''))<=0 OR (LEN(ISNULL(cFree10,''))>0 AND cFree10='" + drLot["cFree10"] + "'))";
  18064. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree10"], GetExtentionName("cFree10", JsonData.WorkPoint, cmd, language)));
  18065. if (flag != null && flag.Rows.Count > 0)
  18066. {
  18067. rowFilter += " AND LocationCode='" + drLot["LocationCode"] + "'";
  18068. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["LocationCode"]));
  18069. }
  18070. //保质期管理
  18071. var resultEffective = Effective(Lot, JsonData.WorkPoint,JsonData.TransType, cmd, language);
  18072. //0 - 已经是最早的批次
  18073. //1 - 不管控
  18074. //2 - 提醒
  18075. //3 - 限制
  18076. if (resultEffective == "2")
  18077. {
  18078. msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
  18079. }
  18080. else if (resultEffective == "3")
  18081. {
  18082. msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
  18083. isLimit = true;
  18084. }
  18085. string rowFilternew = rowFilter + " AND LEN(ISNULL(ProjectCode,''))>0";
  18086. string sqlnew = CheckTransnew(dataView, rowFilternew, "ProjectCode");
  18087. rowFilternew = rowFilter + " AND LEN(ISNULL(BatchCode,''))>0";
  18088. sqlnew += CheckTransnew(dataView, rowFilternew, "BatchCode");
  18089. rowFilternew = rowFilter + " AND LEN(ISNULL(Version,''))>0";
  18090. sqlnew += CheckTransnew(dataView, rowFilternew, "Version");
  18091. rowFilternew = rowFilter + " AND LEN(ISNULL(Brand,''))>0";
  18092. sqlnew += CheckTransnew(dataView, rowFilternew, "Brand");
  18093. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree1,''))>0";
  18094. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree1");
  18095. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree2,''))>0";
  18096. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree2");
  18097. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree3,''))>0";
  18098. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree3");
  18099. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree4,''))>0";
  18100. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree4");
  18101. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree5,''))>0";
  18102. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree5");
  18103. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree6,''))>0";
  18104. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree6");
  18105. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree7,''))>0";
  18106. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree7");
  18107. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree8,''))>0 ";
  18108. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree8");
  18109. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree9,''))>0";
  18110. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree9");
  18111. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree10,''))>0";
  18112. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree10");
  18113. //先进先出判断
  18114. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, sqlnew, JsonData.TransType, cmd, language);
  18115. //0 - 已经是最早的批次
  18116. //1 - 不管控
  18117. //2 - 提醒
  18118. //3 - 限制
  18119. if (result == "2")
  18120. {
  18121. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  18122. }
  18123. else if (result == "3")
  18124. {
  18125. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  18126. isLimit = true;
  18127. }
  18128. }
  18129. }
  18130. }
  18131. #endregion
  18132. //return table;
  18133. Result res = new Result();
  18134. res.Success = true;
  18135. res.Message = msg;// "接口调用成功!";
  18136. if (!isLimit)
  18137. res.Data = table;
  18138. return res;
  18139. //出库时
  18140. //Message无值、Data有值,可直接处理
  18141. //Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
  18142. //Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
  18143. }
  18144. catch (Exception ex)
  18145. {
  18146. log.Error(ex.Message);
  18147. throw new Exception(ex.Message);
  18148. }
  18149. finally
  18150. {
  18151. if (conn.State == ConnectionState.Open)
  18152. {
  18153. conn.Close();
  18154. }
  18155. conn.Dispose();
  18156. }
  18157. }
  18158. }
  18159. /// <summary>
  18160. /// 拣配
  18161. /// </summary>
  18162. /// <param name="JsonData"></param>
  18163. /// <returns></returns>
  18164. public static DataTable PickMerge(List<LOTStockModel> JsonData)
  18165. {
  18166. String PrintEnable = "";
  18167. var language = LanguageHelper.GetName("WMSAPIInfo");
  18168. if (JsonData.Count <= 0)
  18169. {
  18170. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  18171. }
  18172. List<LOTStockModelList> model = new List<LOTStockModelList>();
  18173. DataTable printTable = new DataTable();
  18174. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  18175. {
  18176. conn.Open();
  18177. SqlTransaction sqlTran = conn.BeginTransaction();
  18178. SqlCommand cmd = new SqlCommand();
  18179. cmd.Transaction = sqlTran;
  18180. cmd.Connection = conn;
  18181. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  18182. string BusinessCode = string.Empty;
  18183. try
  18184. {
  18185. string TransType = string.Empty;
  18186. string pikTbLogsql = "";
  18187. string Identification = Guid.NewGuid().ToString();
  18188. foreach (var item in JsonData)
  18189. {
  18190. TransType = item.TransType;
  18191. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  18192. {
  18193. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  18194. }
  18195. else if (string.IsNullOrEmpty(item.TransCode))
  18196. {
  18197. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  18198. }
  18199. string[] trans = item.TransCode.Split('~');
  18200. string MergeID = "";
  18201. if (trans.Length == 2)
  18202. {
  18203. MergeID = trans[0];
  18204. item.TransCode = trans[1];
  18205. }
  18206. #region 销售出库
  18207. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription()
  18208. || TransType == TransTypeEnum.MOIssueDoc.GetDescription()
  18209. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  18210. {
  18211. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  18212. // //更新源头单据数量
  18213. // pikTbLogsql = @"update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),c.Quantity )
  18214. // from dbo.ICSWareHouseLotInfo b
  18215. // inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog
  18216. // where TransCode ='{0}' AND TransSequence='{1}' and TransType='15' and WorkPoint='{2}' group by LotNo) c
  18217. // on c.LotNo =b.LotNo
  18218. //";
  18219. // pikTbLogsql = string.Format(pikTbLogsql, item.TransCode, item.TransSequence, item.WorkPoint);
  18220. // if (!DBHelper.ExecuteNonQuery(pikTbLogsql, cmd))
  18221. // {
  18222. // throw new Exception("更新库存锁定数量失败!");
  18223. // }
  18224. foreach (var itemInfo in item.detail)
  18225. {
  18226. pikTbLogsql += @"
  18227. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{7}' AND a.WorkPoint='{6}' AND Quantity-LockQuantity-'{3}'<0)
  18228. BEGIN
  18229. RAISERROR(':" +"{7}" + @"',16,1);
  18230. RETURN
  18231. END
  18232. IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{7}' AND WorkPoint='{6}' AND TransType='15')
  18233. BEGIN
  18234. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  18235. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  18236. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  18237. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  18238. MTIME,WorkPoint,EATTRIBUTE1)
  18239. SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
  18240. a.WarehouseCode,a.LocationCode,'','','{3}',
  18241. '','1','15','{4}','0','',
  18242. '','','','{5}' ,(select Top 1 f.F_RealName FROM ICSInventoryLot a INNER JOIN Sys_SRM_User f ON f.F_Account='{5}' AND a.WorkPoint=f.F_Location) ,
  18243. SYSDATETIME() ,'{6}' ,''
  18244. FROM ICSWareHouseLotInfo a
  18245. WHERE a.LotNo='{7}' AND a.WorkPoint='{6}'
  18246. update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{7}' AND WorkPoint='{6}'
  18247. END
  18248. UPDATE ICSMOApply SET MUSER='{5}' WHERE ApplyCode='{1}' and Sequence='{2}' ; ";
  18249. pikTbLogsql = string.Format(pikTbLogsql, Identification, item.TransCode, item.TransSequence, itemInfo.CurrentQuantity
  18250. , BusinessCode, item.User, item.WorkPoint, itemInfo.LotNo);
  18251. log.Debug("1");
  18252. if (!DBHelper.ExecuteNonQuery(pikTbLogsql, cmd))
  18253. {
  18254. throw new Exception("拣料失败!");
  18255. }
  18256. }
  18257. }
  18258. #endregion
  18259. else
  18260. {
  18261. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  18262. }
  18263. }
  18264. DataTable table = null;
  18265. cmd.Transaction.Commit();
  18266. return table;
  18267. }
  18268. catch (Exception ex)
  18269. {
  18270. if (cmd.Transaction != null)
  18271. cmd.Transaction.Rollback();
  18272. log.Error(ex.Message);
  18273. throw new Exception(ex.Message);
  18274. }
  18275. finally
  18276. {
  18277. if (conn.State == ConnectionState.Open)
  18278. {
  18279. conn.Close();
  18280. }
  18281. conn.Dispose();
  18282. }
  18283. }
  18284. }
  18285. /// <summary>
  18286. /// 回撤拣配
  18287. /// </summary>
  18288. /// <param name="JsonData"></param>
  18289. /// <returns></returns>
  18290. public static DataTable BackPickMerge(List<LOTStockModel> JsonData)
  18291. {
  18292. String PrintEnable = "";
  18293. var language = LanguageHelper.GetName("WMSAPIInfo");
  18294. if (JsonData.Count <= 0)
  18295. {
  18296. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  18297. }
  18298. List<LOTStockModelList> model = new List<LOTStockModelList>();
  18299. DataTable printTable = new DataTable();
  18300. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  18301. {
  18302. conn.Open();
  18303. SqlTransaction sqlTran = conn.BeginTransaction();
  18304. SqlCommand cmd = new SqlCommand();
  18305. cmd.Transaction = sqlTran;
  18306. cmd.Connection = conn;
  18307. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  18308. string BusinessCode = string.Empty;
  18309. try
  18310. {
  18311. string TransType = string.Empty;
  18312. string pikTbLogsql = "";
  18313. string Identification = Guid.NewGuid().ToString();
  18314. foreach (var item in JsonData)
  18315. {
  18316. TransType = item.TransType;
  18317. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  18318. {
  18319. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  18320. }
  18321. else if (string.IsNullOrEmpty(item.TransCode))
  18322. {
  18323. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  18324. }
  18325. string[] trans = item.TransCode.Split('~');
  18326. string MergeID = "";
  18327. if (trans.Length == 2)
  18328. {
  18329. MergeID = trans[0];
  18330. item.TransCode = trans[1];
  18331. }
  18332. #region 销售出库
  18333. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription()
  18334. || TransType == TransTypeEnum.MOIssueDoc.GetDescription()
  18335. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  18336. {
  18337. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  18338. //更新源头单据数量
  18339. pikTbLogsql += string.Format(@" update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),c.Quantity )
  18340. from dbo.ICSWareHouseLotInfo b
  18341. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where TransCode ='{0}' AND TransSequence='{1}' and TransType='15' and WorkPoint='{2}' group by LotNo) c
  18342. on c.LotNo =b.LotNo ", item.TransCode, item.TransSequence,item.WorkPoint);
  18343. pikTbLogsql += string.Format(@" delete dbo.ICSWareHouseLotInfoLog where TransCode ='{0}' AND TransSequence='{1}' and TransType='15' and WorkPoint='{2}'", item.TransCode, item.TransSequence, item.WorkPoint);
  18344. if (!DBHelper.ExecuteNonQuery(pikTbLogsql, cmd))
  18345. {
  18346. throw new Exception("回撤拣料失败!");
  18347. }
  18348. }
  18349. #endregion
  18350. else
  18351. {
  18352. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  18353. }
  18354. }
  18355. DataTable table = null;
  18356. cmd.Transaction.Commit();
  18357. return table;
  18358. }
  18359. catch (Exception ex)
  18360. {
  18361. if (cmd.Transaction != null)
  18362. cmd.Transaction.Rollback();
  18363. log.Error(ex.Message);
  18364. throw new Exception(ex.Message);
  18365. }
  18366. finally
  18367. {
  18368. if (conn.State == ConnectionState.Open)
  18369. {
  18370. conn.Close();
  18371. }
  18372. conn.Dispose();
  18373. }
  18374. }
  18375. }
  18376. /// <summary>
  18377. /// 回撤拣配
  18378. /// </summary>
  18379. /// <param name="JsonData"></param>
  18380. /// <returns></returns>
  18381. public static DataTable BackPickMergeALL(List<LOTStockModel> JsonData)
  18382. {
  18383. String PrintEnable = "";
  18384. var language = LanguageHelper.GetName("WMSAPIInfo");
  18385. if (JsonData.Count <= 0)
  18386. {
  18387. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  18388. }
  18389. List<LOTStockModelList> model = new List<LOTStockModelList>();
  18390. DataTable printTable = new DataTable();
  18391. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  18392. {
  18393. conn.Open();
  18394. SqlTransaction sqlTran = conn.BeginTransaction();
  18395. SqlCommand cmd = new SqlCommand();
  18396. cmd.Transaction = sqlTran;
  18397. cmd.Connection = conn;
  18398. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  18399. string BusinessCode = string.Empty;
  18400. try
  18401. {
  18402. string TransType = string.Empty;
  18403. string pikTbLogsql = "";
  18404. string Identification = Guid.NewGuid().ToString();
  18405. foreach (var item in JsonData)
  18406. {
  18407. TransType = item.TransType;
  18408. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  18409. {
  18410. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  18411. }
  18412. else if (string.IsNullOrEmpty(item.TransCode))
  18413. {
  18414. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  18415. }
  18416. string[] trans = item.TransCode.Split('~');
  18417. string MergeID = "";
  18418. if (trans.Length == 2)
  18419. {
  18420. MergeID = trans[0];
  18421. item.TransCode = trans[1];
  18422. }
  18423. #region 销售出库
  18424. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription()
  18425. || TransType == TransTypeEnum.MOIssueDoc.GetDescription()
  18426. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  18427. {
  18428. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  18429. //更新源头单据数量
  18430. pikTbLogsql += string.Format(@" update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),c.Quantity )
  18431. from dbo.ICSWareHouseLotInfo b
  18432. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where TransCode ='{0}' and TransType='15' and WorkPoint='{1}' group by LotNo) c
  18433. on c.LotNo =b.LotNo ", item.TransCode, item.WorkPoint);
  18434. pikTbLogsql += string.Format(@" delete dbo.ICSWareHouseLotInfoLog where TransCode ='{0}' and TransType='15' and WorkPoint='{1}'", item.TransCode, item.WorkPoint);
  18435. if (!DBHelper.ExecuteNonQuery(pikTbLogsql, cmd))
  18436. {
  18437. throw new Exception("整单回撤拣料失败!");
  18438. }
  18439. }
  18440. #endregion
  18441. else
  18442. {
  18443. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  18444. }
  18445. }
  18446. DataTable table = null;
  18447. cmd.Transaction.Commit();
  18448. return table;
  18449. }
  18450. catch (Exception ex)
  18451. {
  18452. if (cmd.Transaction != null)
  18453. cmd.Transaction.Rollback();
  18454. log.Error(ex.Message);
  18455. throw new Exception(ex.Message);
  18456. }
  18457. finally
  18458. {
  18459. if (conn.State == ConnectionState.Open)
  18460. {
  18461. conn.Close();
  18462. }
  18463. conn.Dispose();
  18464. }
  18465. }
  18466. }
  18467. #region 模具(安多诚专用)
  18468. /// <summary>
  18469. /// 获取模具信息(安多诚专用)
  18470. /// </summary>
  18471. /// <param name="JsonData"></param>
  18472. /// <returns></returns>
  18473. public static DataTable MouldGet(BarCodeModel JsonData)
  18474. {
  18475. var language = LanguageHelper.GetName("WMSAPIInfo");
  18476. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  18477. {
  18478. conn.Open();
  18479. SqlTransaction sqlTran = conn.BeginTransaction();
  18480. SqlCommand cmd = new SqlCommand();
  18481. cmd.Transaction = sqlTran;
  18482. cmd.Connection = conn;
  18483. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  18484. string whereSql = "1=1";
  18485. try
  18486. {
  18487. string sql = @"select MouldCode,MouldName,UpperLimit,LowerLimit,DailyUses,UpperLimit-DailyUses as LeftTimes from ICSMouldAccount
  18488. where MouldCode = '{0}' and {1}
  18489. ";
  18490. if(JsonData.TransType == "上机")
  18491. whereSql = "((MajorStates ='启用'and SubStates='下机')or MajorStates ='未启用' or(MajorStates ='禁用'and SubStates='保养'))";
  18492. else
  18493. whereSql = "((MajorStates ='启用'and SubStates='上机'))";
  18494. sql = string.Format(sql, JsonData.Code,whereSql);
  18495. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  18496. cmd.Transaction.Commit();
  18497. return data;
  18498. }
  18499. catch (Exception ex)
  18500. {
  18501. if (cmd.Transaction != null)
  18502. cmd.Transaction.Rollback();
  18503. log.Error(ex.Message);
  18504. throw new Exception(ex.Message);
  18505. }
  18506. finally
  18507. {
  18508. if (conn.State == ConnectionState.Open)
  18509. {
  18510. conn.Close();
  18511. }
  18512. conn.Dispose();
  18513. }
  18514. }
  18515. }
  18516. /// <summary>
  18517. /// 模具领用(安多诚专用)
  18518. /// </summary>
  18519. /// <param name="JsonData"></param>
  18520. /// <returns></returns>
  18521. public static DataTable MouldInOrOut(LOTStockModel JsonData)
  18522. {
  18523. var language = LanguageHelper.GetName("WMSAPIInfo");
  18524. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  18525. {
  18526. conn.Open();
  18527. SqlTransaction sqlTran = conn.BeginTransaction();
  18528. SqlCommand cmd = new SqlCommand();
  18529. cmd.Transaction = sqlTran;
  18530. cmd.Connection = conn;
  18531. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  18532. string setSql = "";
  18533. try
  18534. {
  18535. string sql = @"insert into ICSMouldLog (ID,MouldCode,MouldNumber,status,DailyUses,EOPCode,
  18536. Picture,StartDate,MTIME,MUser,MUSERName,UsageCount)
  18537. select NEWID(),'{0}',MouldNumber,'{1}',DailyUses,'{2}',
  18538. '{3}',GETDATE(),GETDATE(),'{4}',
  18539. (select Top 1 f.F_RealName FROM Sys_SRM_User f where f.F_Account='{4}' ),TotalUses from ICSMouldAccount
  18540. where MouldCode = '{0}'
  18541. update ICSMouldAccount set {5}
  18542. where MouldCode = '{0}'
  18543. {7}
  18544. ";
  18545. string updateStates = @"";
  18546. if (JsonData.TransType == "上机")
  18547. setSql = "MajorStates='启用',SubStates ='上机'";
  18548. else if (JsonData.TransType == "下机")
  18549. setSql = "MajorStates ='启用', SubStates='下机',DailyUses=DailyUses+" + JsonData.TransSequence + ",TotalUses= TotalUses+" + JsonData.TransSequence;
  18550. else if (JsonData.TransType == "维修")
  18551. setSql = "MajorStates ='禁用', SubStates='维修'";
  18552. else if (JsonData.TransType == "保养")
  18553. {
  18554. setSql = "MajorStates ='启用', SubStates='下机',DailyUses=0";
  18555. updateStates = @"if exists(select * from ICSMouldAccount where UpperLimit = DailyUses and MouldCode='{0}')
  18556. update ICSMouldAccount set MajorStates ='' , Substates ='' where UpperLimit = DailyUses and MouldCode='{0}'";
  18557. }
  18558. sql = string.Format(sql, JsonData.TransCode, JsonData.TransType, JsonData.detail[0].LotNo,
  18559. JsonData.detail[0].TransSequence, JsonData.User, setSql, JsonData.TransSequence,updateStates);
  18560. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  18561. {
  18562. throw new Exception("提交失败!");
  18563. }
  18564. DataTable table = null;
  18565. cmd.Transaction.Commit();
  18566. return table;
  18567. }
  18568. catch (Exception ex)
  18569. {
  18570. if (cmd.Transaction != null)
  18571. cmd.Transaction.Rollback();
  18572. log.Error(ex.Message);
  18573. throw new Exception(ex.Message);
  18574. }
  18575. finally
  18576. {
  18577. if (conn.State == ConnectionState.Open)
  18578. {
  18579. conn.Close();
  18580. }
  18581. conn.Dispose();
  18582. }
  18583. }
  18584. }
  18585. #endregion
  18586. #region 周转箱
  18587. public static DataTable WorkingCapitalBoxGet(BarCodeModel JsonData)
  18588. {
  18589. var language = LanguageHelper.GetName("WMSAPIInfo");
  18590. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  18591. {
  18592. conn.Open();
  18593. SqlCommand cmd = new SqlCommand();
  18594. cmd.Connection = conn;
  18595. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  18596. try
  18597. {
  18598. if (string.IsNullOrEmpty(JsonData.WorkPoint))
  18599. {
  18600. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  18601. }
  18602. #region SLQ
  18603. string sql = @"--IF EXISTS(SELECT ID FROM ICSWorkingCapitalBoxAccount WHERE BoxCode='{0}' AND States='禁用')
  18604. -- BEGIN
  18605. -- RAISERROR('" + language.GetNameByCode("WMSAPIInfo900") + @"',16,1);
  18606. -- RETURN
  18607. -- END
  18608. SELECT b.BoxCode,b.BoxName,b.States,b.DailyUses,a.FirstCleanCycle,a.SecondCleanCycle,a.ThirdCleanCycle,
  18609. CASE
  18610. WHEN b.DailyUses<a.FirstCleanCycle THEN a.FirstCleanCycle-b.DailyUses
  18611. WHEN b.DailyUses>a.FirstCleanCycle AND b.DailyUses<a.SecondCleanCycle THEN a.SecondCleanCycle-b.DailyUses
  18612. WHEN b.DailyUses>a.SecondCleanCycle THEN a.ThirdCleanCycle-b.DailyUses
  18613. ELSE 0
  18614. END AS nextClearTimes
  18615. FROM ICSWorkingCapitalBoxAccount b
  18616. INNER JOIN ICSWorkingCapitalBox a ON a.BoxNumber=b.BoxNumber
  18617. WHERE b.BoxCode='{0}'";
  18618. sql = string.Format(sql,JsonData.Code);
  18619. #endregion
  18620. log.Debug("查询周转箱sql : " + sql);
  18621. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  18622. return table;
  18623. }
  18624. catch (Exception ex)
  18625. {
  18626. log.Error(ex.Message);
  18627. throw new Exception(ex.Message);
  18628. }
  18629. finally
  18630. {
  18631. if (conn.State == ConnectionState.Open)
  18632. {
  18633. conn.Close();
  18634. }
  18635. conn.Dispose();
  18636. }
  18637. }
  18638. }
  18639. public static DataTable WorkingCapitalBoxUse(LOTStockModel JsonData)
  18640. {
  18641. var language = LanguageHelper.GetName("WMSAPIInfo");
  18642. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  18643. {
  18644. conn.Open();
  18645. SqlTransaction sqlTran = conn.BeginTransaction();
  18646. SqlCommand cmd = new SqlCommand();
  18647. cmd.Transaction = sqlTran;
  18648. cmd.Connection = conn;
  18649. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  18650. try
  18651. {
  18652. string boxCodes = string.Empty;
  18653. string UserCode = JsonData.User;
  18654. for(int i = 0;i < JsonData.detail.Count; i++)
  18655. {
  18656. if(i == JsonData.detail.Count - 1)
  18657. {
  18658. boxCodes += "'" + JsonData.detail[i].LotNo + "'";
  18659. }
  18660. else
  18661. {
  18662. boxCodes += "'" + JsonData.detail[i].LotNo + "',";
  18663. }
  18664. }
  18665. string sql = @"
  18666. UPDATE ICSWorkingCapitalBoxAccount SET DailyUses=DailyUses+1,TotalUses=TotalUses+1
  18667. WHERE BoxCode IN({0})
  18668. UPDATE acc SET acc.States =
  18669. CASE
  18670. WHEN acc.DailyUses > box.FirstCleanCycle AND acc.DailyUses < box.ThirdCleanCycle THEN ''
  18671. WHEN acc.DailyUses >= box.ThirdCleanCycle THEN ''
  18672. ELSE acc.States
  18673. END
  18674. FROM ICSWorkingCapitalBoxAccount acc
  18675. INNER JOIN ICSWorkingCapitalBox box ON acc.BoxNumber = box.BoxNumber
  18676. WHERE acc.BoxCode IN({0})
  18677. INSERT INTO ICSWorkingCapitalBoxLog(ID,BoxCode,BoxNumber,Status,MTIME,MUser,MUSERName)
  18678. SELECT NEWID(),a.BoxCode,a.BoxNumber,'使',GETDATE(),'{1}',(select Top 1 f.F_RealName FROM Sys_SRM_User f where f.F_Account='{1}')
  18679. FROM ICSWorkingCapitalBoxAccount a
  18680. WHERE a.BoxCode IN({0})";
  18681. sql = string.Format(sql, boxCodes, UserCode);
  18682. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  18683. {
  18684. throw new Exception("提交失败!");
  18685. }
  18686. DataTable table = null;
  18687. cmd.Transaction.Commit();
  18688. return table;
  18689. }
  18690. catch (Exception ex)
  18691. {
  18692. if (cmd.Transaction != null)
  18693. cmd.Transaction.Rollback();
  18694. log.Error(ex.Message);
  18695. throw new Exception(ex.Message);
  18696. }
  18697. finally
  18698. {
  18699. if (conn.State == ConnectionState.Open)
  18700. {
  18701. conn.Close();
  18702. }
  18703. conn.Dispose();
  18704. }
  18705. }
  18706. }
  18707. public static DataTable WorkingCapitalBoxClean(LOTStockModel JsonData)
  18708. {
  18709. var language = LanguageHelper.GetName("WMSAPIInfo");
  18710. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  18711. {
  18712. conn.Open();
  18713. SqlTransaction sqlTran = conn.BeginTransaction();
  18714. SqlCommand cmd = new SqlCommand();
  18715. cmd.Transaction = sqlTran;
  18716. cmd.Connection = conn;
  18717. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  18718. string setSql = "";
  18719. try
  18720. {
  18721. string sql = @"INSERT INTO ICSWorkingCapitalBoxLog(ID,BoxCode,BoxNumber,Status,Picture,MTIME,MUser,MUSERName)
  18722. SELECT NEWID(),a.BoxCode,a.BoxNumber,'','{2}',GETDATE(),'{1}',(select Top 1 f.F_RealName FROM Sys_SRM_User f where f.F_Account='{1}')
  18723. FROM ICSWorkingCapitalBoxAccount a
  18724. WHERE a.BoxCode = '{0}'
  18725. UPDATE ICSWorkingCapitalBoxAccount SET DailyUses=0,TotalClearn=TotalClearn+1
  18726. WHERE BoxCode = '{0}'
  18727. UPDATE acc SET acc.States = ''
  18728. FROM ICSWorkingCapitalBoxAccount acc
  18729. INNER JOIN ICSWorkingCapitalBox box ON acc.BoxNumber = box.BoxNumber
  18730. WHERE acc.BoxCode = '{0}'
  18731. ";
  18732. sql = string.Format(sql, JsonData.detail[0].LotNo, JsonData.User, JsonData.detail[0].TransSequence,
  18733. JsonData.detail[0].TransSequence, JsonData.User, setSql, JsonData.TransSequence);
  18734. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  18735. {
  18736. throw new Exception("提交失败!");
  18737. }
  18738. DataTable table = null;
  18739. cmd.Transaction.Commit();
  18740. return table;
  18741. }
  18742. catch (Exception ex)
  18743. {
  18744. if (cmd.Transaction != null)
  18745. cmd.Transaction.Rollback();
  18746. log.Error(ex.Message);
  18747. throw new Exception(ex.Message);
  18748. }
  18749. finally
  18750. {
  18751. if (conn.State == ConnectionState.Open)
  18752. {
  18753. conn.Close();
  18754. }
  18755. conn.Dispose();
  18756. }
  18757. }
  18758. }
  18759. #endregion
  18760. #region
  18761. /// <summary>
  18762. /// 成品入库单 新建
  18763. /// </summary>
  18764. /// <param name="JsonData"></param>
  18765. /// <returns></returns>
  18766. public static DataTable FinishedProductWarehouseEntryCreate(List<FinishedProductWarehouseEntry> JsonData)
  18767. {
  18768. var language = LanguageHelper.GetName("WMSAPIInfo");
  18769. if (JsonData.Count <= 0)
  18770. {
  18771. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  18772. }
  18773. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  18774. {
  18775. conn.Open();
  18776. SqlTransaction sqlTran = conn.BeginTransaction();
  18777. SqlCommand cmd = new SqlCommand();
  18778. cmd.Transaction = sqlTran;
  18779. cmd.Connection = conn;
  18780. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  18781. try
  18782. {
  18783. string codes = string.Empty;
  18784. string sql = string.Empty;
  18785. foreach (var item in JsonData)
  18786. {
  18787. //获取单号
  18788. sql = @"DECLARE @MaxNO INT,@date varchar(20)='FRWE'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  18789. SELECT @MaxNO=SUBSTRING(MAX(RCVCode),LEN(@date)+1,LEN(MAX(RCVCode))-LEN(@date))+1 FROM ICSWMSManufactureReceive
  18790. WHERE SUBSTRING(RCVCode, 1, LEN(@date))=@date
  18791. IF @MaxNO IS NULL
  18792. BEGIN
  18793. SELECT @date+'00001' AS Code
  18794. END
  18795. ELSE
  18796. BEGIN
  18797. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  18798. END ";
  18799. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  18800. //创建主表
  18801. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  18802. BEGIN
  18803. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  18804. RETURN
  18805. END
  18806. INSERT INTO [dbo].[ICSWMSManufactureReceive]
  18807. ([ID], [RCVCode], [Type], [Status], [WHCode], [CreatePerson], [MUSER], [MUSERName], [CreateDateTime], [MTIME], [WorkPoint], [EATTRIBUTE1], [EATTRIBUTE2], [EATTRIBUTE3], [EATTRIBUTE4], [EATTRIBUTE5], [EATTRIBUTE6], [EATTRIBUTE7], [EATTRIBUTE8], [EATTRIBUTE9], [EATTRIBUTE10], [ExtensionID])
  18808. VALUES
  18809. (NEWID(), '{0}', '{1}', '{2}','{3}', '{4}', '{4}',(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{6}'), '{5}', '{5}', '{6}', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)";
  18810. sql = string.Format(sql, Code, item.Type, item.Status, item.WHCode, item.MUSER,item.MTIME,item.WorkPoint );
  18811. log.Debug("成品入库单主表:" + sql);
  18812. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  18813. {
  18814. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  18815. }
  18816. foreach (var itemInfo in item.detail)
  18817. {
  18818. //创建子表
  18819. sql = @"INSERT INTO [dbo].[ICSWMSManufactureReceiveDetail]
  18820. ([ID], [RCVCode], [Sequence], [LotNo], [SourceCode], [SourceSequence], [InvCode], [Quantity], [ExtensionID], [MUSER], [MUSERName], [MTIME], [WorkPoint], [EATTRIBUTE1], [EATTRIBUTE2], [EATTRIBUTE3], [EATTRIBUTE4], [EATTRIBUTE5], [EATTRIBUTE6], [EATTRIBUTE7], [EATTRIBUTE8], [EATTRIBUTE9], [EATTRIBUTE10])
  18821. VALUES
  18822. (NEWID(), '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', (select F_RealName from Sys_SRM_User where F_Account='{8}' and F_Location='{10}'), '{9}', '{10}', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)";
  18823. sql = string.Format(sql, Code, itemInfo.Sequence,itemInfo.LotNo,itemInfo.SourceCode,itemInfo.SourceSequence,itemInfo.InvCode,itemInfo.Quantity,itemInfo.ExtensionID,item.MUSER,item.MTIME,item.WorkPoint );
  18824. log.Debug("成品入库单子表:" + sql);
  18825. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  18826. {
  18827. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  18828. }
  18829. }
  18830. ////校验退料数量是否超出领料数量
  18831. //sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  18832. //DBHelper.ExecuteNonQuery(sql, cmd);
  18833. codes += "'" + Code + item.WorkPoint + "',";
  18834. }
  18835. if (string.IsNullOrWhiteSpace(codes))
  18836. {
  18837. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  18838. }
  18839. #region 查询返回数据
  18840. sql = @"SELECT a.RCVCode,
  18841. c.WHCode,
  18842. c.Status,
  18843. a.Sequence,
  18844. a.InvCode,
  18845. inv.InvName,
  18846. inv.InvStd,
  18847. a.Quantity,
  18848. inv.InvUnit,
  18849. a.Amount,
  18850. inv.AmountUnit,
  18851. ext.ProjectCode,
  18852. ext.BatchCode,
  18853. ext.Version,
  18854. ext.Brand,
  18855. ext.cFree1,
  18856. ext.cFree2,
  18857. ext.cFree3,
  18858. ext.cFree4,
  18859. ext.cFree5,
  18860. ext.cFree6,
  18861. ext.cFree7,
  18862. ext.cFree8,
  18863. ext.cFree9,
  18864. ext.cFree10,
  18865. a.MUSER AS [User],
  18866. a.MTIME AS [MTime]
  18867. FROM ICSWMSManufactureReceiveDetail a
  18868. INNER JOIN ICSWMSManufactureReceive c ON a.RCVCode=c.RCVCode AND a.WorkPoint=c.WorkPoint
  18869. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  18870. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  18871. WHERE a.RCVCode+a.WorkPoint IN ({0})";
  18872. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  18873. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  18874. #endregion
  18875. cmd.Transaction.Commit();
  18876. return data;
  18877. }
  18878. catch (Exception ex)
  18879. {
  18880. if (cmd.Transaction != null)
  18881. cmd.Transaction.Rollback();
  18882. log.Error(ex.Message);
  18883. throw new Exception(ex.Message);
  18884. }
  18885. finally
  18886. {
  18887. if (conn.State == ConnectionState.Open)
  18888. {
  18889. conn.Close();
  18890. }
  18891. conn.Dispose();
  18892. }
  18893. }
  18894. }
  18895. #endregion
  18896. /// <summary>
  18897. /// 委外订单新增
  18898. /// </summary>
  18899. /// <param name="JsonData"></param>
  18900. /// <returns></returns>
  18901. public static DataTable OutsourcingOrderNoticeCreate(List<ICSOutsourcingOrder> JsonData)
  18902. {
  18903. var language = LanguageHelper.GetName("WMSAPIInfo");
  18904. if (JsonData.Count <= 0)
  18905. {
  18906. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  18907. }
  18908. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  18909. {
  18910. conn.Open();
  18911. SqlTransaction sqlTran = conn.BeginTransaction();
  18912. SqlCommand cmd = new SqlCommand();
  18913. string Colspan = string.Empty;
  18914. string OOCode = string.Empty;
  18915. string WorkPoint = string.Empty;
  18916. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  18917. string IDD = string.Empty;
  18918. cmd.Transaction = sqlTran;
  18919. cmd.Connection = conn;
  18920. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  18921. try
  18922. {
  18923. string sql = string.Empty;
  18924. HashSet<string> uniqueItems = new HashSet<string>();
  18925. foreach (var item in JsonData)
  18926. {
  18927. //检验自由项
  18928. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  18929. + "~" + item.Brand + "~" + item.cFree1
  18930. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  18931. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  18932. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  18933. sql = @"select ID,Colspan from ICSExtension a
  18934. where Colspan='{0}' and WorkPoint='{1}'";
  18935. sql = string.Format(sql, Colspan, item.WorkPoint);
  18936. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  18937. if (dttt.Rows.Count == 0)
  18938. {
  18939. IDD = Guid.NewGuid().ToString();
  18940. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  18941. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  18942. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  18943. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  18944. {
  18945. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  18946. }
  18947. }
  18948. else
  18949. {
  18950. IDD = dttt.Rows[0]["ID"].ToString();
  18951. }
  18952. //获取单号
  18953. string key = item.Sequence + "~" + item.InvCode;
  18954. if (uniqueItems.Contains(key))
  18955. {
  18956. throw new Exception("子件不可重复添加!");
  18957. }
  18958. uniqueItems.Add(key);
  18959. //创建主表
  18960. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{13}' AND F_Location='{17}')
  18961. BEGIN
  18962. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  18963. RETURN
  18964. END
  18965. INSERT INTO [dbo].[ICSOutsourcingOrder]
  18966. ([ID],[OOCode],[Sequence],[VenCode],[DepCode],[PersonCode],[Type],[InvCode],[Quantity],[Amount],[InQuantity],[UnitPrice],[Currency],[Status]
  18967. ,[CreatePerson]
  18968. ,[CreateDateTime]
  18969. ,[ReleaseState]
  18970. ,[ReleaseDate]
  18971. ,[PlanArriveDate]
  18972. ,[ArriveUser]
  18973. ,[ArriveDate]
  18974. ,[DeliveryUser]
  18975. ,[DeliveryDate]
  18976. ,[OOID]
  18977. ,[OODetailID]
  18978. ,[ExtensionID]
  18979. ,[MUSER]
  18980. ,[MUSERName]
  18981. ,[MTIME]
  18982. ,[WorkPoint]
  18983. ,[EATTRIBUTE1])
  18984. VALUES
  18985. (NEWID(),'{0}','{1}','{2}', '{3}','{4}','{5}','{6}',{7},{8},{9},{10},'{11}','{12}',
  18986. (select F_RealName from Sys_SRM_User where F_Account='{13}' and F_Location='{17}')
  18987. ,'{14}','{15}',null,
  18988. '{16}','{19}','{20}',null,null,
  18989. '','','','','','{20}',
  18990. '{17}','{18}')";
  18991. sql = string.Format(sql, item.OOCode, item.Sequence, item.VenCode, item.DepCode, item.PersonCode,
  18992. item.Type, item.InvCode, item.Quantity, item.Amount, item.InQuantity, item.UnitPrice, item.Currency, item.Status,
  18993. item.User, Dates, item.ReleaseState,
  18994. item.PlanArriveDate.ToString("yyyy-MM-dd HH:mm:ss"),
  18995. item.WorkPoint, IDD, item.ArriveUser, Dates);
  18996. OOCode = item.OOCode;
  18997. WorkPoint = item.WorkPoint;
  18998. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  18999. {
  19000. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  19001. }
  19002. }
  19003. #region 查询返回数据
  19004. sql = @"
  19005. select a.ID,a.OOCode,a.Sequence,a.VenCode,a.DepCode,a.PersonCode,a.Type,a.InvCode
  19006. ,a.Amount,a.Quantity,
  19007. a.UnitPrice,a.Currency,a.Status,a.ReleaseState,a.PlanArriveDate,a.CreatePerson,a.CreateDateTime
  19008. from ICSOutsourcingOrder a
  19009. WHERE a.OOCode = '{0}' and a.WorkPoint = '{1}'";
  19010. sql = string.Format(sql, OOCode, WorkPoint);
  19011. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  19012. #endregion
  19013. cmd.Transaction.Commit();
  19014. return data;
  19015. }
  19016. catch (Exception ex)
  19017. {
  19018. if (cmd.Transaction != null)
  19019. cmd.Transaction.Rollback();
  19020. log.Error(ex.Message);
  19021. throw new Exception(ex.Message);
  19022. }
  19023. finally
  19024. {
  19025. if (conn.State == ConnectionState.Open)
  19026. {
  19027. conn.Close();
  19028. }
  19029. conn.Dispose();
  19030. }
  19031. }
  19032. }
  19033. /// <summary>
  19034. /// 委外订单 修改
  19035. /// </summary>
  19036. /// <param name="JsonData"></param>
  19037. /// <returns></returns>
  19038. public static DataTable OutsourcingOrderNoticeUpdate(List<ICSOutsourcingOrder> JsonData)
  19039. {
  19040. var language = LanguageHelper.GetName("WMSAPIInfo");
  19041. if (JsonData.Count <= 0)
  19042. {
  19043. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  19044. }
  19045. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  19046. {
  19047. conn.Open();
  19048. SqlTransaction sqlTran = conn.BeginTransaction();
  19049. SqlCommand cmd = new SqlCommand();
  19050. cmd.Transaction = sqlTran;
  19051. cmd.Connection = conn;
  19052. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  19053. try
  19054. {
  19055. string sql = string.Empty;
  19056. string Checksql = string.Empty;
  19057. string Code = string.Empty;
  19058. string ids = string.Empty;
  19059. string OOCode = string.Empty;
  19060. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19061. string WorkPoint = string.Empty;
  19062. string Colspan = string.Empty;
  19063. string IDD = string.Empty;
  19064. bool deletefalg = false;
  19065. foreach (var item in JsonData)
  19066. {
  19067. //检验自由项
  19068. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  19069. + "~" + item.Brand + "~" + item.cFree1
  19070. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  19071. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  19072. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  19073. sql = @"select ID,Colspan from ICSExtension a
  19074. where Colspan='{0}' and WorkPoint='{1}'";
  19075. sql = string.Format(sql, Colspan, item.WorkPoint);
  19076. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  19077. if (dttt.Rows.Count == 0)
  19078. {
  19079. IDD = Guid.NewGuid().ToString();
  19080. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  19081. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  19082. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  19083. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  19084. {
  19085. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  19086. }
  19087. }
  19088. else
  19089. {
  19090. IDD = dttt.Rows[0]["ID"].ToString();
  19091. }
  19092. //删除逻辑
  19093. if (!deletefalg)
  19094. {
  19095. if (!string.IsNullOrEmpty(item.deleteIDs))
  19096. {
  19097. var did = item.deleteIDs.Substring(0, item.deleteIDs.Length - 1);
  19098. //判断是否被委外领料(ICSOApply)、委外出库(ICSOIssue)、委外到货(ICSODeliveryNotice)、委外入库等引用(ICSOutsourcingReceive)
  19099. sql = @"select abs(isnull(b.Quantity,0))+abs(isnull(c.Quantity,0))+abs(isnull(d.Quantity,0))+abs(isnull(e.Quantity,0))
  19100. from ICSOutsourcingOrder a
  19101. left join ICSOApply b on a.OOCode = b.SourceCode and a.Sequence = b.SourceSequence and a.WorkPoint = b.WorkPoint
  19102. left join ICSOIssue c on a.OOCode = c.SourceCode and a.Sequence = c.SourceSequence and a.WorkPoint = c.WorkPoint
  19103. left join ICSODeliveryNotice d on a.ID = d.OOID and a.WorkPoint = d.WorkPoint
  19104. left join ICSOutsourcingReceive e on a.OOCode = e.SourceCode and a.Sequence = e.SourceSequence and a.WorkPoint = e.WorkPoint
  19105. where a.ID IN ({0}) and a.WorkPoint ='{1}'";
  19106. sql = string.Format(sql, did.TrimEnd(','), item.WorkPoint);
  19107. DataTable cited = DBHelper.SQlReturnData(sql, cmd);
  19108. if (cited.Rows.Count == 0)
  19109. {
  19110. throw new Exception("已被引用,修改失败!");
  19111. }
  19112. Checksql = @"delete from ICSOutsourcingOrder
  19113. where ID IN ({0}) and WorkPoint ='{1}'";
  19114. Checksql = string.Format(Checksql, did.TrimEnd(','), item.WorkPoint);
  19115. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  19116. {
  19117. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  19118. }
  19119. else
  19120. {
  19121. deletefalg = true;
  19122. }
  19123. }
  19124. }
  19125. Checksql = @"select ID,OOCode from ICSOutsourcingOrder a
  19126. where ID ='{0}' and WorkPoint='{1}'";
  19127. Checksql = string.Format(Checksql, item.ID, item.WorkPoint);
  19128. DataTable datas = DBHelper.SQlReturnData(Checksql, cmd);
  19129. if (datas.Rows.Count > 0)
  19130. {
  19131. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{13}' AND F_Location='{17}')
  19132. BEGIN
  19133. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  19134. RETURN
  19135. END
  19136. UPDATE [dbo].[ICSOutsourcingOrder]
  19137. SET [OOCode] = '{0}',[Sequence] = '{1}',[VenCode] = '{2}',[DepCode] = '{3}',[PersonCode] = '{4}' ,[Type] = '{5}' ,[InvCode] = '{6}' ,[Quantity] = '{7}'
  19138. ,[Amount] = '{8}' ,[InQuantity] = '{9}',[UnitPrice] = '{10}',[Currency] = '{11}',[Status] = '{12}'
  19139. ,[ReleaseState] = '{15}' ,[ReleaseDate] = null,[PlanArriveDate] = '{16}'
  19140. ,[ArriveUser] = null,[ArriveDate] = null,[DeliveryUser] = null,[DeliveryDate] = null
  19141. ,[OOID] = '',[OODetailID] ='',[ExtensionID] ='',[MUSER] ='{13}' ,[MUSERName] = (select F_RealName from Sys_SRM_User where F_Account='{13}' and F_Location='{17}')
  19142. ,[MTIME] = '{14}' ,[WorkPoint] = '{17}',[EATTRIBUTE1] = '{18}'
  19143. WHERE ID = '{19}'";
  19144. sql = string.Format(sql, item.OOCode, item.Sequence, item.VenCode, item.DepCode, item.PersonCode,
  19145. item.Type, item.InvCode, item.Quantity, item.Amount, item.InQuantity, item.UnitPrice, item.Currency, item.Status,
  19146. item.User, Dates, item.ReleaseState, item.PlanArriveDate.ToString("yyyy-MM-dd HH:mm:ss"),
  19147. item.WorkPoint, IDD, item.ID);
  19148. OOCode = item.OOCode;
  19149. WorkPoint = item.WorkPoint;
  19150. }
  19151. else
  19152. {
  19153. //创建主表
  19154. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{13}' AND F_Location='{17}')
  19155. BEGIN
  19156. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  19157. RETURN
  19158. END
  19159. INSERT INTO [dbo].[ICSOutsourcingOrder]
  19160. ([ID],[OOCode],[Sequence],[VenCode],[DepCode],[PersonCode],[Type],[InvCode],[Quantity],[Amount],[InQuantity],[UnitPrice],[Currency],[Status]
  19161. ,[CreatePerson]
  19162. ,[CreateDateTime]
  19163. ,[ReleaseState]
  19164. ,[ReleaseDate]
  19165. ,[PlanArriveDate]
  19166. ,[ArriveUser]
  19167. ,[ArriveDate]
  19168. ,[DeliveryUser]
  19169. ,[DeliveryDate]
  19170. ,[OOID]
  19171. ,[OODetailID]
  19172. ,[ExtensionID]
  19173. ,[MUSER]
  19174. ,[MUSERName]
  19175. ,[MTIME]
  19176. ,[WorkPoint]
  19177. ,[EATTRIBUTE1])
  19178. VALUES
  19179. (NEWID(),'{0}','{1}','{2}', '{3}','{4}','{5}','{6}',{7},{8},{9},{10},'{11}','{12}',
  19180. (select F_RealName from Sys_SRM_User where F_Account='{13}' and F_Location='{17}')
  19181. ,'{14}','{15}',null,
  19182. '{16}','{19}','{20}',null,null,
  19183. '','','','','','{20}',
  19184. '{17}','{18}')";
  19185. sql = string.Format(sql, item.OOCode, item.Sequence, item.VenCode, item.DepCode, item.PersonCode,
  19186. item.Type, item.InvCode, item.Quantity, item.Amount, item.InQuantity, item.UnitPrice, item.Currency, item.Status,
  19187. item.User, Dates, item.ReleaseState,
  19188. item.PlanArriveDate.ToString("yyyy-MM-dd HH:mm:ss"),
  19189. item.WorkPoint, IDD, item.ArriveUser, Dates);
  19190. OOCode = item.OOCode;
  19191. WorkPoint = item.WorkPoint;
  19192. }
  19193. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  19194. {
  19195. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  19196. }
  19197. }
  19198. #region 查询返回数据
  19199. sql = @"
  19200. select a.ID,a.OOCode,a.Sequence,a.VenCode,a.DepCode,a.PersonCode,a.Type,a.InvCode
  19201. ,a.Amount,a.Quantity,
  19202. a.UnitPrice,a.Currency,a.Status,a.ReleaseState,a.PlanArriveDate,a.CreatePerson,a.CreateDateTime
  19203. from ICSOutsourcingOrder a
  19204. WHERE a.OOCode = '{0}' and a.WorkPoint = '{1}'";
  19205. sql = string.Format(sql, OOCode, WorkPoint);
  19206. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  19207. #endregion
  19208. cmd.Transaction.Commit();
  19209. return data;
  19210. }
  19211. catch (Exception ex)
  19212. {
  19213. if (cmd.Transaction != null)
  19214. cmd.Transaction.Rollback();
  19215. log.Error(ex.Message);
  19216. throw new Exception(ex.Message);
  19217. }
  19218. finally
  19219. {
  19220. if (conn.State == ConnectionState.Open)
  19221. {
  19222. conn.Close();
  19223. }
  19224. conn.Dispose();
  19225. }
  19226. }
  19227. }
  19228. /// <summary>
  19229. /// 委外订单备料 新增
  19230. /// </summary>
  19231. /// <param name="JsonData"></param>
  19232. /// <returns></returns>
  19233. /// <exception cref="Exception"></exception>
  19234. public static DataTable OOPickNoticeCreate(List<ICSOOPick> JsonData)
  19235. {
  19236. var language = LanguageHelper.GetName("WMSAPIInfo");
  19237. if (JsonData.Count <= 0)
  19238. {
  19239. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  19240. }
  19241. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  19242. {
  19243. conn.Open();
  19244. SqlTransaction sqlTran = conn.BeginTransaction();
  19245. SqlCommand cmd = new SqlCommand();
  19246. string Colspan = string.Empty;
  19247. string Sequence = string.Empty;
  19248. string OODetailID = string.Empty;
  19249. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19250. string WorkPoint = string.Empty;
  19251. string IDD = string.Empty;
  19252. cmd.Transaction = sqlTran;
  19253. cmd.Connection = conn;
  19254. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  19255. try
  19256. {
  19257. string sql = string.Empty;
  19258. HashSet<string> uniqueItems = new HashSet<string>();
  19259. foreach (var item in JsonData)
  19260. {
  19261. //判断当前录入的总数量是否超过了订单数量
  19262. sql = @"select a.OOCode,a.Sequence,sum(ISNULL(b.Quantity,0) - a.Quantity) as DifferenceQty
  19263. ,sum(ISNULL(b.Quantity,0)) as bQty,a.Quantity from ICSOutsourcingOrder a
  19264. left join ICSOOPick b on a.ID = b.OODetailID and a.WorkPoint = b.WorkPoint
  19265. where a.ID = '{0}' and a.WorkPoint='{1}'
  19266. group by a.OOCode,a.Sequence,a.Quantity";
  19267. sql = string.Format(sql, item.OODetailID, item.WorkPoint);
  19268. DataTable qtydata = DBHelper.SQlReturnData(sql, cmd);
  19269. if (qtydata.Rows.Count == 0)
  19270. {
  19271. throw new Exception("未找到委外订单");
  19272. }
  19273. else
  19274. {
  19275. var qtysum = JsonData.Where(q => q.OODetailID == item.OODetailID).Sum(q => Convert.ToDouble(q.Quantity));
  19276. var DifferenceQty = Convert.ToInt32(qtydata.Rows[0]["DifferenceQty"]);
  19277. var Quantity = Convert.ToInt32(qtydata.Rows[0]["Quantity"]);
  19278. var bQty = Convert.ToInt32(qtydata.Rows[0]["bQty"]);
  19279. var OOCode = qtydata.Rows[0]["OOCode"];
  19280. var OOSequence = qtydata.Rows[0]["Sequence"];
  19281. //已入库数量和订单数量的差 小于0 则没有超过订单数量 则超过报错
  19282. if (DifferenceQty > 0)
  19283. {
  19284. throw new Exception("委外订单" + OOCode + "第" + OOSequence + "行的订单数量:" + Quantity.ToString() +
  19285. "。已备料数量:" + bQty.ToString() + "。当前备料总数量:" + qtysum.ToString() + "。已超过订单数量!");
  19286. }
  19287. else
  19288. {
  19289. //录入数量大于已入库数量和订单数量的差 则超过报错
  19290. if (0 - DifferenceQty < qtysum)
  19291. {
  19292. throw new Exception("委外订单" + OOCode + "第" + OOSequence + "行的订单数量:" + Quantity.ToString() +
  19293. "。已备料数量:" + bQty.ToString() + "。当前备料总数量:" + qtysum.ToString() + "。已超过订单数量!");
  19294. }
  19295. }
  19296. }
  19297. //检验自由项
  19298. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  19299. + "~" + item.Brand + "~" + item.cFree1
  19300. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  19301. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  19302. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  19303. sql = @"select ID,Colspan from ICSExtension a
  19304. where Colspan='{0}' and WorkPoint='{1}'";
  19305. sql = string.Format(sql, Colspan, item.WorkPoint);
  19306. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  19307. if (dttt.Rows.Count == 0)
  19308. {
  19309. IDD = Guid.NewGuid().ToString();
  19310. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  19311. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  19312. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  19313. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  19314. {
  19315. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  19316. }
  19317. }
  19318. else
  19319. {
  19320. IDD = dttt.Rows[0]["ID"].ToString();
  19321. }
  19322. //获取单号
  19323. string key = item.Sequence + "~" + item.InvCode;
  19324. if (uniqueItems.Contains(key))
  19325. {
  19326. throw new Exception("子件不可重复添加!");
  19327. }
  19328. uniqueItems.Add(key);
  19329. //创建主表
  19330. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{11}' AND F_Location='{13}')
  19331. BEGIN
  19332. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  19333. RETURN
  19334. END
  19335. INSERT INTO [dbo].[ICSOOPick]
  19336. ([ID]
  19337. ,[OODetailID]
  19338. ,[PickID]
  19339. ,[ParentPickID]
  19340. ,[ParentQuantity]
  19341. ,[ParentAmount]
  19342. ,[Sequence]
  19343. ,[InvCode]
  19344. ,[Quantity]
  19345. ,[Amount]
  19346. ,[IssueQuantity]
  19347. ,[WHCode]
  19348. ,[SupplyType]
  19349. ,[ExtensionID]
  19350. ,[MUSER]
  19351. ,[MUSERName]
  19352. ,[MTIME]
  19353. ,[WorkPoint])
  19354. VALUES
  19355. (NEWID(),'{0}','',null,{1},{2},'{3}','{4}',{5},{6},{7},'{8}','{9}','{10}','{11}'
  19356. ,(select F_RealName from Sys_SRM_User where F_Account='{11}' and F_Location='{13}')
  19357. ,'{12}','{13}')";
  19358. sql = string.Format(sql, item.OODetailID, item.ParentQuantity, item.ParentAmount, item.Sequence, item.InvCode, item.Quantity, item.Amount,
  19359. item.IssueQuantity, item.WHCode, item.SupplyType, IDD, item.User, Dates, item.WorkPoint);
  19360. OODetailID = item.OODetailID;
  19361. Sequence = item.Sequence;
  19362. WorkPoint = item.WorkPoint;
  19363. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  19364. {
  19365. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产订单信息创建失败!");
  19366. }
  19367. }
  19368. #region 查询返回数据
  19369. sql = @"
  19370. select [OODetailID],[PickID],[ParentPickID],[ParentQuantity]
  19371. ,[ParentAmount]
  19372. ,[Sequence]
  19373. ,[InvCode]
  19374. ,[Quantity]
  19375. ,[Amount]
  19376. ,[IssueQuantity]
  19377. ,[WHCode]
  19378. ,[SupplyType]
  19379. ,[ExtensionID]
  19380. ,[MUSER]
  19381. ,[MUSERName]
  19382. ,[MTIME]
  19383. ,[WorkPoint]
  19384. from ICSOOPick a
  19385. WHERE a.OODetailID = '{0}' and Sequence = '{1}' and a.WorkPoint = '{2}'";
  19386. sql = string.Format(sql, OODetailID, Sequence, WorkPoint);
  19387. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  19388. #endregion
  19389. cmd.Transaction.Commit();
  19390. return data;
  19391. }
  19392. catch (Exception ex)
  19393. {
  19394. if (cmd.Transaction != null)
  19395. cmd.Transaction.Rollback();
  19396. log.Error(ex.Message);
  19397. throw new Exception(ex.Message);
  19398. }
  19399. finally
  19400. {
  19401. if (conn.State == ConnectionState.Open)
  19402. {
  19403. conn.Close();
  19404. }
  19405. conn.Dispose();
  19406. }
  19407. }
  19408. }
  19409. /// <summary>
  19410. /// 委外订单备料 修改
  19411. /// </summary>
  19412. /// <param name="JsonData"></param>
  19413. /// <returns></returns>
  19414. public static DataTable OOPickrNoticeUpdate(List<ICSOOPick> JsonData)
  19415. {
  19416. var language = LanguageHelper.GetName("WMSAPIInfo");
  19417. if (JsonData.Count <= 0)
  19418. {
  19419. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  19420. }
  19421. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  19422. {
  19423. conn.Open();
  19424. SqlTransaction sqlTran = conn.BeginTransaction();
  19425. SqlCommand cmd = new SqlCommand();
  19426. cmd.Transaction = sqlTran;
  19427. cmd.Connection = conn;
  19428. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  19429. try
  19430. {
  19431. string sql = string.Empty;
  19432. string Checksql = string.Empty;
  19433. string Code = string.Empty;
  19434. string ids = string.Empty;
  19435. string Sequence = string.Empty;
  19436. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19437. string OODetailID = string.Empty;
  19438. string WorkPoint = string.Empty;
  19439. string Colspan = string.Empty;
  19440. string IDD = string.Empty;
  19441. string dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19442. foreach (var item in JsonData)
  19443. {
  19444. //判断当前录入的总数量是否超过了订单数量
  19445. sql = @"select a.OOCode,a.Sequence,sum(ISNULL(b.Quantity,0) - a.Quantity) as DifferenceQty
  19446. ,sum(ISNULL(b.Quantity,0)) as bQty,a.Quantity from ICSOutsourcingOrder a
  19447. left join ICSOOPick b on a.ID = b.OODetailID and a.WorkPoint = b.WorkPoint
  19448. where a.ID = '{0}' and a.WorkPoint='{1}'
  19449. group by a.OOCode,a.Sequence,a.Quantity";
  19450. sql = string.Format(sql, item.OODetailID, item.WorkPoint);
  19451. DataTable qtydata = DBHelper.SQlReturnData(sql, cmd);
  19452. if (qtydata.Rows.Count == 0)
  19453. {
  19454. throw new Exception("未找到委外订单");
  19455. }
  19456. else
  19457. {
  19458. var qtysum = JsonData.Where(q => q.OODetailID == item.OODetailID).Sum(q => Convert.ToDouble(q.Quantity));
  19459. var DifferenceQty = Convert.ToInt32(qtydata.Rows[0]["DifferenceQty"]);
  19460. var Quantity = Convert.ToInt32(qtydata.Rows[0]["Quantity"]);
  19461. var bQty = Convert.ToInt32(qtydata.Rows[0]["bQty"]);
  19462. var OOCode = qtydata.Rows[0]["OOCode"];
  19463. var OOSequence = qtydata.Rows[0]["Sequence"];
  19464. //已入库数量和订单数量的差 小于0 则没有超过订单数量 则超过报错
  19465. if (DifferenceQty > 0)
  19466. {
  19467. throw new Exception("委外订单" + OOCode + "第" + OOSequence + "行的订单数量:" + Quantity.ToString() +
  19468. "。已备料数量:" + bQty.ToString() + "。当前备料总数量:" + qtysum.ToString() + "。已超过订单数量!");
  19469. }
  19470. else
  19471. {
  19472. //录入数量大于已入库数量和订单数量的差 则超过报错
  19473. if (0 - DifferenceQty < qtysum)
  19474. {
  19475. throw new Exception("委外订单" + OOCode + "第" + OOSequence + "行的订单数量:" + Quantity.ToString() +
  19476. "。已备料数量:" + bQty.ToString() + "。当前备料总数量:" + qtysum.ToString() + "。已超过订单数量!");
  19477. }
  19478. }
  19479. }
  19480. //检验自由项
  19481. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  19482. + "~" + item.Brand + "~" + item.cFree1
  19483. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  19484. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  19485. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  19486. sql = @"select ID,Colspan from ICSExtension a
  19487. where Colspan='{0}' and WorkPoint='{1}'";
  19488. sql = string.Format(sql, Colspan, item.WorkPoint);
  19489. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  19490. if (dttt.Rows.Count == 0)
  19491. {
  19492. IDD = Guid.NewGuid().ToString();
  19493. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  19494. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  19495. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  19496. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  19497. {
  19498. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  19499. }
  19500. }
  19501. else
  19502. {
  19503. IDD = dttt.Rows[0]["ID"].ToString();
  19504. }
  19505. Checksql = @"select ID,OODetailID from ICSOOPick a
  19506. where ID ='{0}' and WorkPoint='{1}'";
  19507. Checksql = string.Format(Checksql, item.ID, item.WorkPoint);
  19508. DataTable datas = DBHelper.SQlReturnData(Checksql, cmd);
  19509. if (datas.Rows.Count > 0)
  19510. {
  19511. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{13}' AND F_Location='{15}')
  19512. BEGIN
  19513. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  19514. RETURN
  19515. END
  19516. UPDATE [dbo].[ICSOOPick]
  19517. SET [OODetailID] = '{0}'
  19518. ,[PickID] = '{1}'
  19519. ,[ParentPickID] = '{2}'
  19520. ,[ParentQuantity] = {3}
  19521. ,[ParentAmount] = {4}
  19522. ,[Sequence] = '{5}'
  19523. ,[InvCode] = '{6}'
  19524. ,[Quantity] = {7}
  19525. ,[Amount] = {8}
  19526. ,[IssueQuantity] = {9}
  19527. ,[WHCode] = '{10}'
  19528. ,[SupplyType] = '{11}'
  19529. ,[ExtensionID] = '{12}'
  19530. ,[MUSER] = '{13}'
  19531. ,[MUSERName] = (select F_RealName from Sys_SRM_User where F_Account='{13}' and F_Location='{15}')
  19532. ,[MTIME] = '{14}'
  19533. ,[WorkPoint] = '{15}'
  19534. WHERE ID = '{16}'";
  19535. sql = string.Format(sql, item.OODetailID, item.PickID, item.ParentPickID, item.ParentQuantity, item.ParentAmount,
  19536. item.Sequence, item.InvCode, item.Quantity, item.Amount, item.IssueQuantity, item.WHCode, item.SupplyType, IDD,
  19537. item.User, dates, item.WorkPoint, item.ID);
  19538. OODetailID = item.OODetailID;
  19539. Sequence = item.Sequence;
  19540. WorkPoint = item.WorkPoint;
  19541. }
  19542. else
  19543. {
  19544. //创建主表
  19545. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{11}' AND F_Location='{13}')
  19546. BEGIN
  19547. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  19548. RETURN
  19549. END
  19550. INSERT INTO [dbo].[ICSOOPick]
  19551. ([ID]
  19552. ,[OODetailID]
  19553. ,[PickID]
  19554. ,[ParentPickID]
  19555. ,[ParentQuantity]
  19556. ,[ParentAmount]
  19557. ,[Sequence]
  19558. ,[InvCode]
  19559. ,[Quantity]
  19560. ,[Amount]
  19561. ,[IssueQuantity]
  19562. ,[WHCode]
  19563. ,[SupplyType]
  19564. ,[ExtensionID]
  19565. ,[MUSER]
  19566. ,[MUSERName]
  19567. ,[MTIME]
  19568. ,[WorkPoint])
  19569. VALUES
  19570. (NEWID(),'{0}','',null,{1},{2},'{3}','{4}',{5},{6},{7},'{8}','{9}','{10}','{11}'
  19571. ,(select F_RealName from Sys_SRM_User where F_Account='{11}' and F_Location='{13}')
  19572. ,'{12}','{13}')";
  19573. sql = string.Format(sql, item.OODetailID, item.ParentQuantity, item.ParentAmount, item.Sequence, item.InvCode, item.Quantity, item.Amount,
  19574. item.IssueQuantity, item.WHCode, item.SupplyType, IDD, item.User, Dates, item.WorkPoint);
  19575. OODetailID = item.OODetailID;
  19576. Sequence = item.Sequence;
  19577. WorkPoint = item.WorkPoint;
  19578. }
  19579. }
  19580. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  19581. {
  19582. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  19583. }
  19584. #region 查询返回数据
  19585. sql = @"
  19586. select [OODetailID],[PickID],[ParentPickID],[ParentQuantity]
  19587. ,[ParentAmount]
  19588. ,[Sequence]
  19589. ,[InvCode]
  19590. ,[Quantity]
  19591. ,[Amount]
  19592. ,[IssueQuantity]
  19593. ,[WHCode]
  19594. ,[SupplyType]
  19595. ,[ExtensionID]
  19596. ,[MUSER]
  19597. ,[MUSERName]
  19598. ,[MTIME]
  19599. ,[WorkPoint]
  19600. from ICSOOPick a
  19601. WHERE a.OODetailID = '{0}' and Sequence = '{1}' and a.WorkPoint = '{2}'";
  19602. sql = string.Format(sql, OODetailID, Sequence, WorkPoint);
  19603. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  19604. #endregion
  19605. cmd.Transaction.Commit();
  19606. return data;
  19607. }
  19608. catch (Exception ex)
  19609. {
  19610. if (cmd.Transaction != null)
  19611. cmd.Transaction.Rollback();
  19612. log.Error(ex.Message);
  19613. throw new Exception(ex.Message);
  19614. }
  19615. finally
  19616. {
  19617. if (conn.State == ConnectionState.Open)
  19618. {
  19619. conn.Close();
  19620. }
  19621. conn.Dispose();
  19622. }
  19623. }
  19624. }
  19625. /// <summary>
  19626. /// 委外领料单 新增
  19627. /// </summary>
  19628. /// <param name="JsonData"></param>
  19629. /// <returns></returns>
  19630. /// <exception cref="Exception"></exception>
  19631. public static DataTable OApplyNoticeCreate(List<ICSOApply> JsonData)
  19632. {
  19633. var language = LanguageHelper.GetName("WMSAPIInfo");
  19634. if (JsonData.Count <= 0)
  19635. {
  19636. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  19637. }
  19638. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  19639. {
  19640. conn.Open();
  19641. SqlTransaction sqlTran = conn.BeginTransaction();
  19642. SqlCommand cmd = new SqlCommand();
  19643. string Colspan = string.Empty;
  19644. string Sequence = string.Empty;
  19645. string ApplyCode = string.Empty;
  19646. string WorkPoint = string.Empty;
  19647. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19648. string IDD = string.Empty;
  19649. cmd.Transaction = sqlTran;
  19650. cmd.Connection = conn;
  19651. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  19652. try
  19653. {
  19654. string sql = string.Empty;
  19655. HashSet<string> uniqueItems = new HashSet<string>();
  19656. foreach (var item in JsonData)
  19657. {
  19658. //检验自由项
  19659. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  19660. + "~" + item.Brand + "~" + item.cFree1
  19661. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  19662. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  19663. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  19664. sql = @"select ID,Colspan from ICSExtension a
  19665. where Colspan='{0}' and WorkPoint='{1}'";
  19666. sql = string.Format(sql, Colspan, item.WorkPoint);
  19667. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  19668. if (dttt.Rows.Count == 0)
  19669. {
  19670. IDD = Guid.NewGuid().ToString();
  19671. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  19672. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  19673. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  19674. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  19675. {
  19676. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  19677. }
  19678. }
  19679. else
  19680. {
  19681. IDD = dttt.Rows[0]["ID"].ToString();
  19682. }
  19683. //获取单号
  19684. string key = item.Sequence + "~" + item.InvCode;
  19685. if (uniqueItems.Contains(key))
  19686. {
  19687. throw new Exception("子件不可重复添加!");
  19688. }
  19689. uniqueItems.Add(key);
  19690. //创建主表
  19691. sql = @"
  19692. INSERT INTO [dbo].[ICSOApply]
  19693. ([ID],[ApplyCode]
  19694. ,[Sequence]
  19695. ,[SourceCode]
  19696. ,[SourceSequence]
  19697. ,[InvCode]
  19698. ,[Quantity]
  19699. ,[Amount]
  19700. ,[IssueQuantity]
  19701. ,[WHCode]
  19702. ,[Type]
  19703. ,[Status]
  19704. ,[CreatePerson]
  19705. ,[CreateDateTime]
  19706. ,[ApplyID]
  19707. ,[ApplyDetailID]
  19708. ,[ExtensionID]
  19709. ,[WorkPoint]
  19710. ,[MUSER]
  19711. ,[MUSERName]
  19712. ,[MTIME])
  19713. VALUES
  19714. (NEWID(),'{0}','{1}',null,null,'{2}',{3},null,null,'{4}','1','1'
  19715. ,'{5}','{6}',NEWID(),NEWID(),'{7}','{8}','','','{9}')";
  19716. sql = string.Format(sql, item.ApplyCode, item.Sequence, item.InvCode, item.Quantity,
  19717. item.WHCode, item.User, Dates, IDD, item.WorkPoint, Dates);
  19718. ApplyCode = item.ApplyCode;
  19719. WorkPoint = item.WorkPoint;
  19720. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  19721. {
  19722. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产订单信息创建失败!");
  19723. }
  19724. }
  19725. #region 查询返回数据
  19726. sql = @"
  19727. select [ApplyCode]
  19728. ,[Sequence]
  19729. ,[SourceCode]
  19730. ,[SourceSequence]
  19731. ,[InvCode]
  19732. ,[Quantity]
  19733. ,[Amount]
  19734. ,[IssueQuantity]
  19735. ,[WHCode]
  19736. ,[Type]
  19737. ,[Status]
  19738. ,[CreatePerson]
  19739. ,[CreateDateTime]
  19740. ,[ApplyID]
  19741. ,[ApplyDetailID]
  19742. ,[ExtensionID]
  19743. from ICSOApply a
  19744. WHERE a.ApplyCode = '{0}' and a.WorkPoint = '{1}'";
  19745. sql = string.Format(sql, ApplyCode, WorkPoint);
  19746. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  19747. #endregion
  19748. cmd.Transaction.Commit();
  19749. return data;
  19750. }
  19751. catch (Exception ex)
  19752. {
  19753. if (cmd.Transaction != null)
  19754. cmd.Transaction.Rollback();
  19755. log.Error(ex.Message);
  19756. throw new Exception(ex.Message);
  19757. }
  19758. finally
  19759. {
  19760. if (conn.State == ConnectionState.Open)
  19761. {
  19762. conn.Close();
  19763. }
  19764. conn.Dispose();
  19765. }
  19766. }
  19767. }
  19768. /// <summary>
  19769. /// 委外领料单 修改
  19770. /// </summary>
  19771. /// <param name="JsonData"></param>
  19772. /// <returns></returns>
  19773. public static DataTable OApplyNoticeUpdate(List<ICSOApply> JsonData)
  19774. {
  19775. var language = LanguageHelper.GetName("WMSAPIInfo");
  19776. if (JsonData.Count <= 0)
  19777. {
  19778. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  19779. }
  19780. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  19781. {
  19782. conn.Open();
  19783. SqlTransaction sqlTran = conn.BeginTransaction();
  19784. SqlCommand cmd = new SqlCommand();
  19785. cmd.Transaction = sqlTran;
  19786. cmd.Connection = conn;
  19787. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  19788. try
  19789. {
  19790. string sql = string.Empty;
  19791. string Checksql = string.Empty;
  19792. string Sequence = string.Empty;
  19793. string ApplyCode = string.Empty;
  19794. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19795. string WorkPoint = string.Empty;
  19796. string Colspan = string.Empty;
  19797. string IDD = string.Empty;
  19798. string dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19799. bool deletefalg = false;
  19800. foreach (var item in JsonData)
  19801. {
  19802. //检验自由项
  19803. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  19804. + "~" + item.Brand + "~" + item.cFree1
  19805. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  19806. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  19807. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  19808. sql = @"select ID,Colspan from ICSExtension a
  19809. where Colspan='{0}' and WorkPoint='{1}'";
  19810. sql = string.Format(sql, Colspan, item.WorkPoint);
  19811. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  19812. if (dttt.Rows.Count == 0)
  19813. {
  19814. IDD = Guid.NewGuid().ToString();
  19815. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  19816. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  19817. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  19818. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  19819. {
  19820. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  19821. }
  19822. }
  19823. else
  19824. {
  19825. IDD = dttt.Rows[0]["ID"].ToString();
  19826. }
  19827. //删除逻辑
  19828. if (!deletefalg)
  19829. {
  19830. if (!string.IsNullOrEmpty(item.deleteIDs))
  19831. {
  19832. var did = item.deleteIDs.Substring(0, item.deleteIDs.Length - 1);
  19833. Checksql = @"delete from ICSOApply
  19834. where ID IN ({0}) and WorkPoint ='{1}'";
  19835. Checksql = string.Format(Checksql, did.TrimEnd(','), item.WorkPoint);
  19836. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  19837. {
  19838. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  19839. }
  19840. else
  19841. {
  19842. deletefalg = true;
  19843. }
  19844. }
  19845. }
  19846. Checksql = @"select ID,ApplyCode from ICSOApply a
  19847. where ID ='{0}' and WorkPoint='{1}'";
  19848. Checksql = string.Format(Checksql, item.ID, item.WorkPoint);
  19849. DataTable datas = DBHelper.SQlReturnData(Checksql, cmd);
  19850. if (datas.Rows.Count > 0)
  19851. {
  19852. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{6}' AND F_Location='{8}')
  19853. BEGIN
  19854. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  19855. RETURN
  19856. END
  19857. UPDATE [dbo].[ICSOApply]
  19858. SET [ApplyCode] = '{0}'
  19859. ,[Sequence] = '{1}'
  19860. ,[InvCode] = '{2}'
  19861. ,[Quantity] = {3}
  19862. ,[WHCode] = '{4}'
  19863. ,[Type] = '1'
  19864. ,[Status] = '1'
  19865. ,[ExtensionID] = '{5}'
  19866. ,[MUSER] = '{6}'
  19867. ,[MUSERName] = (select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{8}')
  19868. ,[MTIME] = '{7}'
  19869. ,[WorkPoint] = '{8}'
  19870. WHERE ID = '{9}'";
  19871. sql = string.Format(sql, item.ApplyCode, item.Sequence, item.InvCode, item.Quantity, item.WHCode,
  19872. IDD, item.User, dates, item.WorkPoint, item.ID);
  19873. ApplyCode = item.ApplyCode;
  19874. Sequence = item.Sequence;
  19875. WorkPoint = item.WorkPoint;
  19876. }
  19877. else
  19878. {
  19879. sql = @"
  19880. INSERT INTO [dbo].[ICSOApply]
  19881. ([ID],[ApplyCode]
  19882. ,[Sequence]
  19883. ,[SourceCode]
  19884. ,[SourceSequence]
  19885. ,[InvCode]
  19886. ,[Quantity]
  19887. ,[Amount]
  19888. ,[IssueQuantity]
  19889. ,[WHCode]
  19890. ,[Type]
  19891. ,[Status]
  19892. ,[CreatePerson]
  19893. ,[CreateDateTime]
  19894. ,[ApplyID]
  19895. ,[ApplyDetailID]
  19896. ,[ExtensionID]
  19897. ,[WorkPoint]
  19898. ,[MUSER]
  19899. ,[MUSERName]
  19900. ,[MTIME])
  19901. VALUES
  19902. (NEWID(),'{0}','{1}',null,null,'{2}',{3},null,null,'{4}','1','1'
  19903. ,'{5}','{6}',NEWID(),NEWID(),'{7}','{8}','','','{9}')";
  19904. sql = string.Format(sql, item.ApplyCode, item.Sequence, item.InvCode, item.Quantity,
  19905. item.WHCode, item.User, Dates, IDD, item.WorkPoint, Dates);
  19906. ApplyCode = item.ApplyCode;
  19907. Sequence = item.Sequence;
  19908. WorkPoint = item.WorkPoint;
  19909. }
  19910. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  19911. {
  19912. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  19913. }
  19914. }
  19915. #region 查询返回数据
  19916. sql = @"
  19917. select [ApplyCode]
  19918. ,[Sequence]
  19919. ,[SourceCode]
  19920. ,[SourceSequence]
  19921. ,[InvCode]
  19922. ,[Quantity]
  19923. ,[Amount]
  19924. ,[IssueQuantity]
  19925. ,[WHCode]
  19926. ,[Type]
  19927. ,[Status]
  19928. ,[CreatePerson]
  19929. ,[CreateDateTime]
  19930. ,[ApplyID]
  19931. ,[ApplyDetailID]
  19932. ,[ExtensionID]
  19933. from ICSOApply a
  19934. WHERE a.ApplyCode = '{0}' and a.WorkPoint = '{1}'";
  19935. sql = string.Format(sql, ApplyCode, WorkPoint);
  19936. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  19937. #endregion
  19938. cmd.Transaction.Commit();
  19939. return data;
  19940. }
  19941. catch (Exception ex)
  19942. {
  19943. if (cmd.Transaction != null)
  19944. cmd.Transaction.Rollback();
  19945. log.Error(ex.Message);
  19946. throw new Exception(ex.Message);
  19947. }
  19948. finally
  19949. {
  19950. if (conn.State == ConnectionState.Open)
  19951. {
  19952. conn.Close();
  19953. }
  19954. conn.Dispose();
  19955. }
  19956. }
  19957. }
  19958. /// <summary>
  19959. /// 委外出库表 新增
  19960. /// </summary>
  19961. /// <param name="JsonData"></param>
  19962. /// <returns></returns>
  19963. /// <exception cref="Exception"></exception>
  19964. public static DataTable OIssueNoticeCreate(List<ICSOIssue> JsonData)
  19965. {
  19966. var language = LanguageHelper.GetName("WMSAPIInfo");
  19967. if (JsonData.Count <= 0)
  19968. {
  19969. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  19970. }
  19971. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  19972. {
  19973. conn.Open();
  19974. SqlTransaction sqlTran = conn.BeginTransaction();
  19975. SqlCommand cmd = new SqlCommand();
  19976. string Colspan = string.Empty;
  19977. string Sequence = string.Empty;
  19978. string IssueCode = string.Empty;
  19979. string WorkPoint = string.Empty;
  19980. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  19981. string IDD = string.Empty;
  19982. cmd.Transaction = sqlTran;
  19983. cmd.Connection = conn;
  19984. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  19985. try
  19986. {
  19987. string sql = string.Empty;
  19988. HashSet<string> uniqueItems = new HashSet<string>();
  19989. foreach (var item in JsonData)
  19990. {
  19991. //检验自由项
  19992. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  19993. + "~" + item.Brand + "~" + item.cFree1
  19994. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  19995. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  19996. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  19997. sql = @"select ID,Colspan from ICSExtension a
  19998. where Colspan='{0}' and WorkPoint='{1}'";
  19999. sql = string.Format(sql, Colspan, item.WorkPoint);
  20000. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  20001. if (dttt.Rows.Count == 0)
  20002. {
  20003. IDD = Guid.NewGuid().ToString();
  20004. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  20005. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  20006. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  20007. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  20008. {
  20009. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  20010. }
  20011. }
  20012. else
  20013. {
  20014. IDD = dttt.Rows[0]["ID"].ToString();
  20015. }
  20016. //获取单号
  20017. string key = item.Sequence + "~" + item.InvCode;
  20018. if (uniqueItems.Contains(key))
  20019. {
  20020. throw new Exception("子件不可重复添加!");
  20021. }
  20022. uniqueItems.Add(key);
  20023. //创建主表
  20024. sql = @"
  20025. INSERT INTO [dbo].[ICSOIssue]
  20026. ([ID]
  20027. ,[IssueCode]
  20028. ,[Sequence]
  20029. ,[SourceCode]
  20030. ,[SourceSequence]
  20031. ,[InvCode]
  20032. ,[Quantity]
  20033. ,[Amount]
  20034. ,[IssueQuantity]
  20035. ,[WHCode]
  20036. ,[Type]
  20037. ,[Status]
  20038. ,[CreatePerson]
  20039. ,[CreateDateTime]
  20040. ,[IssueID]
  20041. ,[IssueDetailID]
  20042. ,[PickID]
  20043. ,[ApplyDetailID]
  20044. ,[ExtensionID]
  20045. ,[MUSER]
  20046. ,[MUSERName]
  20047. ,[MTIME]
  20048. ,[WorkPoint])
  20049. VALUES
  20050. (NEWID(),'{0}','{1}',null,null,'{2}',{3},null,null,'{4}','1','1'
  20051. ,'{5}','{6}',NEWID(),NEWID(),null,null,'{7}','','','{8}','{9}')";
  20052. sql = string.Format(sql, item.IssueCode, item.Sequence, item.InvCode, item.Quantity,
  20053. item.WHCode, item.User, Dates, IDD, Dates, item.WorkPoint);
  20054. IssueCode = item.IssueCode;
  20055. WorkPoint = item.WorkPoint;
  20056. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  20057. {
  20058. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产订单信息创建失败!");
  20059. }
  20060. }
  20061. #region 查询返回数据
  20062. sql = @"
  20063. select
  20064. [IssueCode]
  20065. ,[Sequence]
  20066. ,[SourceCode]
  20067. ,[SourceSequence]
  20068. ,[InvCode]
  20069. ,[Quantity]
  20070. ,[Amount]
  20071. ,[IssueQuantity]
  20072. ,[WHCode]
  20073. ,[Type]
  20074. ,[Status]
  20075. ,[CreatePerson]
  20076. ,[CreateDateTime]
  20077. ,[IssueID]
  20078. ,[IssueDetailID]
  20079. ,[PickID]
  20080. ,[ApplyDetailID]
  20081. ,[ExtensionID]
  20082. ,[MUSER]
  20083. ,[MUSERName]
  20084. ,[MTIME]
  20085. from ICSOIssue a
  20086. WHERE a.IssueCode = '{0}' and a.WorkPoint = '{1}'";
  20087. sql = string.Format(sql, IssueCode, WorkPoint);
  20088. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  20089. #endregion
  20090. cmd.Transaction.Commit();
  20091. return data;
  20092. }
  20093. catch (Exception ex)
  20094. {
  20095. if (cmd.Transaction != null)
  20096. cmd.Transaction.Rollback();
  20097. log.Error(ex.Message);
  20098. throw new Exception(ex.Message);
  20099. }
  20100. finally
  20101. {
  20102. if (conn.State == ConnectionState.Open)
  20103. {
  20104. conn.Close();
  20105. }
  20106. conn.Dispose();
  20107. }
  20108. }
  20109. }
  20110. /// <summary>
  20111. /// 委外出库表 修改
  20112. /// </summary>
  20113. /// <param name="JsonData"></param>
  20114. /// <returns></returns>
  20115. public static DataTable OIssueNoticeUpdate(List<ICSOIssue> JsonData)
  20116. {
  20117. var language = LanguageHelper.GetName("WMSAPIInfo");
  20118. if (JsonData.Count <= 0)
  20119. {
  20120. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  20121. }
  20122. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  20123. {
  20124. conn.Open();
  20125. SqlTransaction sqlTran = conn.BeginTransaction();
  20126. SqlCommand cmd = new SqlCommand();
  20127. cmd.Transaction = sqlTran;
  20128. cmd.Connection = conn;
  20129. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  20130. try
  20131. {
  20132. string sql = string.Empty;
  20133. string Checksql = string.Empty;
  20134. string Sequence = string.Empty;
  20135. string IssueCode = string.Empty;
  20136. string WorkPoint = string.Empty;
  20137. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  20138. string Colspan = string.Empty;
  20139. string IDD = string.Empty;
  20140. string dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  20141. bool deletefalg = false;
  20142. foreach (var item in JsonData)
  20143. {
  20144. //检验自由项
  20145. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  20146. + "~" + item.Brand + "~" + item.cFree1
  20147. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  20148. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  20149. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  20150. sql = @"select ID,Colspan from ICSExtension a
  20151. where Colspan='{0}' and WorkPoint='{1}'";
  20152. sql = string.Format(sql, Colspan, item.WorkPoint);
  20153. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  20154. if (dttt.Rows.Count == 0)
  20155. {
  20156. IDD = Guid.NewGuid().ToString();
  20157. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  20158. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  20159. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  20160. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  20161. {
  20162. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  20163. }
  20164. }
  20165. else
  20166. {
  20167. IDD = dttt.Rows[0]["ID"].ToString();
  20168. }
  20169. //删除逻辑
  20170. if (!deletefalg)
  20171. {
  20172. if (!string.IsNullOrEmpty(item.deleteIDs))
  20173. {
  20174. var did = item.deleteIDs.Substring(0, item.deleteIDs.Length - 1);
  20175. Checksql = @"delete from ICSOApply
  20176. where ID IN ({0}) and WorkPoint ='{1}'";
  20177. Checksql = string.Format(Checksql, did.TrimEnd(','), item.WorkPoint);
  20178. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  20179. {
  20180. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  20181. }
  20182. else
  20183. {
  20184. deletefalg = true;
  20185. }
  20186. }
  20187. }
  20188. Checksql = @"select ID,IssueCode from ICSOIssue a
  20189. where ID ='{0}' and WorkPoint='{1}'";
  20190. Checksql = string.Format(Checksql, item.ID, item.WorkPoint);
  20191. DataTable datas = DBHelper.SQlReturnData(Checksql, cmd);
  20192. if (datas.Rows.Count > 0)
  20193. {
  20194. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{5}' AND F_Location='{6}')
  20195. BEGIN
  20196. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  20197. RETURN
  20198. END
  20199. UPDATE [dbo].[ICSOIssue]
  20200. SET [Sequence] = '{0}'
  20201. ,[InvCode] = '{1}'
  20202. ,[Quantity] = {2}
  20203. ,[WHCode] = '{3}'
  20204. ,[ExtensionID] = '{4}'
  20205. ,[MUSER] = '{5}'
  20206. ,[MUSERName] = (select F_RealName from Sys_SRM_User where F_Account='{5}' and F_Location='{6}')
  20207. ,[MTIME] = '{7}'
  20208. ,[WorkPoint] = '{6}'
  20209. WHERE ID = '{8}'";
  20210. sql = string.Format(sql, item.Sequence, item.InvCode, item.Quantity, item.WHCode,
  20211. IDD, item.User, item.WorkPoint, dates, item.ID);
  20212. IssueCode = item.IssueCode;
  20213. Sequence = item.Sequence;
  20214. WorkPoint = item.WorkPoint;
  20215. }
  20216. else
  20217. {
  20218. sql = @"
  20219. INSERT INTO [dbo].[ICSOIssue]
  20220. ([ID]
  20221. ,[IssueCode]
  20222. ,[Sequence]
  20223. ,[SourceCode]
  20224. ,[SourceSequence]
  20225. ,[InvCode]
  20226. ,[Quantity]
  20227. ,[Amount]
  20228. ,[IssueQuantity]
  20229. ,[WHCode]
  20230. ,[Type]
  20231. ,[Status]
  20232. ,[CreatePerson]
  20233. ,[CreateDateTime]
  20234. ,[IssueID]
  20235. ,[IssueDetailID]
  20236. ,[PickID]
  20237. ,[ApplyDetailID]
  20238. ,[ExtensionID]
  20239. ,[MUSER]
  20240. ,[MUSERName]
  20241. ,[MTIME]
  20242. ,[WorkPoint])
  20243. VALUES
  20244. (NEWID(),'{0}','{1}',null,null,'{2}',{3},null,null,'{4}','1','1'
  20245. ,'{5}','{6}',NEWID(),NEWID(),null,null,'{7}','','','{8}','{9}')";
  20246. sql = string.Format(sql, item.IssueCode, item.Sequence, item.InvCode, item.Quantity,
  20247. item.WHCode, item.User, Dates, IDD, Dates, item.WorkPoint);
  20248. IssueCode = item.IssueCode;
  20249. Sequence = item.Sequence;
  20250. WorkPoint = item.WorkPoint;
  20251. }
  20252. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  20253. {
  20254. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  20255. }
  20256. }
  20257. #region 查询返回数据
  20258. sql = @"
  20259. select
  20260. [IssueCode]
  20261. ,[Sequence]
  20262. ,[SourceCode]
  20263. ,[SourceSequence]
  20264. ,[InvCode]
  20265. ,[Quantity]
  20266. ,[Amount]
  20267. ,[IssueQuantity]
  20268. ,[WHCode]
  20269. ,[Type]
  20270. ,[Status]
  20271. ,[CreatePerson]
  20272. ,[CreateDateTime]
  20273. ,[IssueID]
  20274. ,[IssueDetailID]
  20275. ,[PickID]
  20276. ,[ApplyDetailID]
  20277. ,[ExtensionID]
  20278. ,[MUSER]
  20279. ,[MUSERName]
  20280. ,[MTIME]
  20281. from ICSOIssue a
  20282. WHERE a.IssueCode = '{0}' and a.WorkPoint = '{1}'";
  20283. sql = string.Format(sql, IssueCode, WorkPoint);
  20284. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  20285. #endregion
  20286. cmd.Transaction.Commit();
  20287. return data;
  20288. }
  20289. catch (Exception ex)
  20290. {
  20291. if (cmd.Transaction != null)
  20292. cmd.Transaction.Rollback();
  20293. log.Error(ex.Message);
  20294. throw new Exception(ex.Message);
  20295. }
  20296. finally
  20297. {
  20298. if (conn.State == ConnectionState.Open)
  20299. {
  20300. conn.Close();
  20301. }
  20302. conn.Dispose();
  20303. }
  20304. }
  20305. }
  20306. /// <summary>
  20307. /// 委外到货单 新增
  20308. /// </summary>
  20309. /// <param name="JsonData"></param>
  20310. /// <returns></returns>
  20311. /// <exception cref="Exception"></exception>
  20312. public static DataTable ODeliveryNoticeCreate(List<ICSODeliveryNotice> JsonData)
  20313. {
  20314. var language = LanguageHelper.GetName("WMSAPIInfo");
  20315. if (JsonData.Count <= 0)
  20316. {
  20317. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  20318. }
  20319. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  20320. {
  20321. conn.Open();
  20322. SqlTransaction sqlTran = conn.BeginTransaction();
  20323. SqlCommand cmd = new SqlCommand();
  20324. string Colspan = string.Empty;
  20325. string Sequence = string.Empty;
  20326. string ODNCode = string.Empty;
  20327. string WorkPoint = string.Empty;
  20328. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  20329. string IDD = string.Empty;
  20330. cmd.Transaction = sqlTran;
  20331. cmd.Connection = conn;
  20332. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  20333. try
  20334. {
  20335. string sql = string.Empty;
  20336. HashSet<string> uniqueItems = new HashSet<string>();
  20337. foreach (var item in JsonData)
  20338. {
  20339. //判断当前录入的总数量是否超过了订单数量
  20340. sql = @"select a.OOCode,a.Sequence,sum(ISNULL(b.Quantity,0) - a.Quantity) as DifferenceQty
  20341. ,sum(ISNULL(b.Quantity,0)) as bQty,a.Quantity from ICSOutsourcingOrder a
  20342. left join ICSODeliveryNotice b on a.ID = b.OOID and a.WorkPoint = b.WorkPoint
  20343. where a.ID = '{0}' and a.WorkPoint='{1}'
  20344. group by a.OOCode,a.Sequence,a.Quantity";
  20345. sql = string.Format(sql, item.OOID, item.WorkPoint);
  20346. DataTable qtydata = DBHelper.SQlReturnData(sql, cmd);
  20347. if (qtydata.Rows.Count == 0)
  20348. {
  20349. throw new Exception("未找到委外订单");
  20350. }
  20351. else
  20352. {
  20353. var qtysum = JsonData.Where(q => q.OODetailID == item.OODetailID).Sum(q => Convert.ToInt32(q.Quantity));
  20354. var DifferenceQty = Convert.ToInt32(qtydata.Rows[0]["DifferenceQty"]);
  20355. var Quantity = Convert.ToInt32(qtydata.Rows[0]["Quantity"]);
  20356. var bQty = Convert.ToInt32(qtydata.Rows[0]["bQty"]);
  20357. var OOCode = qtydata.Rows[0]["OOCode"];
  20358. var OOSequence = qtydata.Rows[0]["Sequence"];
  20359. //已入库数量和订单数量的差 小于0 则没有超过订单数量 则超过报错
  20360. if (DifferenceQty > 0)
  20361. {
  20362. throw new Exception("委外订单" + OOCode + "第" + OOSequence + "行的订单数量:" + Quantity.ToString() +
  20363. "。已到货数量:" + bQty.ToString() + "。当前到货总数量:" + qtysum.ToString() + "。已超过订单数量!");
  20364. }
  20365. else
  20366. {
  20367. //录入数量大于已入库数量和订单数量的差 则超过报错
  20368. if (0 - DifferenceQty < qtysum)
  20369. {
  20370. throw new Exception("委外订单" + OOCode + "第" + OOSequence + "行的订单数量:" + Quantity.ToString() +
  20371. "。已到货数量:" + bQty.ToString() + "。当前到货总数量:" + qtysum.ToString() + "。已超过订单数量!");
  20372. }
  20373. }
  20374. }
  20375. //检验自由项
  20376. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  20377. + "~" + item.Brand + "~" + item.cFree1
  20378. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  20379. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  20380. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  20381. sql = @"select ID,Colspan from ICSExtension a
  20382. where Colspan='{0}' and WorkPoint='{1}'";
  20383. sql = string.Format(sql, Colspan, item.WorkPoint);
  20384. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  20385. if (dttt.Rows.Count == 0)
  20386. {
  20387. IDD = Guid.NewGuid().ToString();
  20388. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  20389. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  20390. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  20391. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  20392. {
  20393. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  20394. }
  20395. }
  20396. else
  20397. {
  20398. IDD = dttt.Rows[0]["ID"].ToString();
  20399. }
  20400. //获取单号
  20401. string key = item.Sequence + "~" + item.InvCode;
  20402. if (uniqueItems.Contains(key))
  20403. {
  20404. throw new Exception("子件不可重复添加!");
  20405. }
  20406. uniqueItems.Add(key);
  20407. //直接关联ID新增
  20408. //sql = @"select a.ID,a.OOCode,a.Sequence,a.VenCode,a.DepCode,a.PersonCode,a.InvCode,a.Amount,a.Quantity,
  20409. // a.UnitPrice,a.Currency,a.Status,a.ReleaseState,a.PlanArriveDate,a.CreatePerson,a.CreateDateTime
  20410. // from ICSOutsourcingOrder a
  20411. // where a.ID ='{0}' and WorkPoint='{1}'";
  20412. //sql = string.Format(sql, item.OOID, item.WorkPoint);
  20413. //DataTable oo = DBHelper.SQlReturnData(sql, cmd);
  20414. //创建主表
  20415. sql = @"
  20416. INSERT INTO [dbo].[ICSODeliveryNotice]
  20417. ([ID]
  20418. ,[ODNCode]
  20419. ,[Sequence]
  20420. ,[VenCode]
  20421. ,[DepCode]
  20422. ,[WHCode]
  20423. ,[ODNType]
  20424. ,[InvCode]
  20425. ,[Quantity]
  20426. ,[Amount]
  20427. ,[RCVQuantity]
  20428. ,[UnitPrice]
  20429. ,[Currency]
  20430. ,[Status]
  20431. ,[CreatePerson]
  20432. ,[CreateDateTime]
  20433. ,[OOID]
  20434. ,[OODetailID]
  20435. ,[ODNID]
  20436. ,[ODNDetailID]
  20437. ,[ExtensionID]
  20438. ,[MUSER]
  20439. ,[MUSERName]
  20440. ,[MTIME]
  20441. ,[WorkPoint]
  20442. ,[EATTRIBUTE1])
  20443. SELECT NEWID(),'{0}','{1}',oo.VenCode,oo.DepCode,'{2}','1',oo.InvCode,{3}
  20444. ,null,null,oo.UnitPrice,oo.Currency,'1'
  20445. ,'{4}','{5}',oo.ID,'','',''
  20446. ,'{6}','','','{7}','{8}','{9}' FROM ICSOutsourcingOrder oo WHERE oo.ID = '{10}'";
  20447. sql = string.Format(sql, item.ODNCode, item.Sequence, item.WHCode, item.Quantity,
  20448. item.User, Dates, IDD, Dates, item.WorkPoint, item.EATTRIBUTE1, item.OOID);
  20449. ODNCode = item.ODNCode;
  20450. WorkPoint = item.WorkPoint;
  20451. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  20452. {
  20453. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产订单信息创建失败!");
  20454. }
  20455. }
  20456. #region 查询返回数据
  20457. sql = @"
  20458. select
  20459. [ID]
  20460. ,[ODNCode]
  20461. ,[Sequence]
  20462. ,[VenCode]
  20463. ,[DepCode]
  20464. ,[WHCode]
  20465. ,[ODNType]
  20466. ,[InvCode]
  20467. ,[Quantity]
  20468. ,[Amount]
  20469. ,[RCVQuantity]
  20470. ,[UnitPrice]
  20471. ,[Currency]
  20472. ,[Status]
  20473. ,[CreatePerson]
  20474. ,[CreateDateTime]
  20475. ,[OOID]
  20476. ,[OODetailID]
  20477. ,[ODNID]
  20478. ,[ODNDetailID]
  20479. ,[ExtensionID]
  20480. from ICSODeliveryNotice a
  20481. WHERE a.ODNCode = '{0}' and a.WorkPoint = '{1}'";
  20482. sql = string.Format(sql, ODNCode, WorkPoint);
  20483. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  20484. #endregion
  20485. cmd.Transaction.Commit();
  20486. return data;
  20487. }
  20488. catch (Exception ex)
  20489. {
  20490. if (cmd.Transaction != null)
  20491. cmd.Transaction.Rollback();
  20492. log.Error(ex.Message);
  20493. throw new Exception(ex.Message);
  20494. }
  20495. finally
  20496. {
  20497. if (conn.State == ConnectionState.Open)
  20498. {
  20499. conn.Close();
  20500. }
  20501. conn.Dispose();
  20502. }
  20503. }
  20504. }
  20505. /// <summary>
  20506. /// 委外到货单 修改
  20507. /// </summary>
  20508. /// <param name="JsonData"></param>
  20509. /// <returns></returns>
  20510. public static DataTable ODeliveryNoticeUpdate(List<ICSODeliveryNotice> JsonData)
  20511. {
  20512. var language = LanguageHelper.GetName("WMSAPIInfo");
  20513. if (JsonData.Count <= 0)
  20514. {
  20515. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  20516. }
  20517. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  20518. {
  20519. conn.Open();
  20520. SqlTransaction sqlTran = conn.BeginTransaction();
  20521. SqlCommand cmd = new SqlCommand();
  20522. cmd.Transaction = sqlTran;
  20523. cmd.Connection = conn;
  20524. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  20525. try
  20526. {
  20527. string sql = string.Empty;
  20528. string Checksql = string.Empty;
  20529. string Sequence = string.Empty;
  20530. string ODNCode = string.Empty;
  20531. string WorkPoint = string.Empty;
  20532. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  20533. string Colspan = string.Empty;
  20534. string IDD = string.Empty;
  20535. bool deletefalg = false;
  20536. string dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  20537. foreach (var item in JsonData)
  20538. {
  20539. //判断当前录入的总数量是否超过了订单数量
  20540. sql = @"select a.OOCode,a.Sequence,sum(ISNULL(b.Quantity,0) - a.Quantity) as DifferenceQty
  20541. ,sum(ISNULL(b.Quantity,0)) as bQty,a.Quantity from ICSOutsourcingOrder a
  20542. left join ICSODeliveryNotice b on a.ID = b.OOID and a.WorkPoint = b.WorkPoint
  20543. where a.ID = '{0}' and a.WorkPoint='{1}'
  20544. group by a.OOCode,a.Sequence,a.Quantity";
  20545. sql = string.Format(sql, item.OOID, item.WorkPoint);
  20546. DataTable qtydata = DBHelper.SQlReturnData(sql, cmd);
  20547. if (qtydata.Rows.Count == 0)
  20548. {
  20549. throw new Exception("未找到委外订单");
  20550. }
  20551. else
  20552. {
  20553. var qtysum = JsonData.Where(q => q.OODetailID == item.OODetailID).Sum(q => Convert.ToInt32(q.Quantity));
  20554. var DifferenceQty = Convert.ToInt32(qtydata.Rows[0]["DifferenceQty"]);
  20555. var Quantity = Convert.ToInt32(qtydata.Rows[0]["Quantity"]);
  20556. var bQty = Convert.ToInt32(qtydata.Rows[0]["bQty"]);
  20557. var OOCode = qtydata.Rows[0]["OOCode"];
  20558. var OOSequence = qtydata.Rows[0]["Sequence"];
  20559. //已入库数量和订单数量的差 小于0 则没有超过订单数量 则超过报错
  20560. if (DifferenceQty > 0)
  20561. {
  20562. throw new Exception("委外订单" + OOCode + "第" + OOSequence + "行的订单数量:" + Quantity.ToString() +
  20563. "。已到货数量:" + bQty.ToString() + "。当前到货总数量:" + qtysum.ToString() + "。已超过订单数量!");
  20564. }
  20565. else
  20566. {
  20567. //录入数量大于已入库数量和订单数量的差 则超过报错
  20568. if (0 - DifferenceQty < qtysum)
  20569. {
  20570. throw new Exception("委外订单" + OOCode + "第" + OOSequence + "行的订单数量:" + Quantity.ToString() +
  20571. "。已到货数量:" + bQty.ToString() + "。当前到货总数量:" + qtysum.ToString() + "。已超过订单数量!");
  20572. }
  20573. }
  20574. }
  20575. //检验自由项
  20576. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  20577. + "~" + item.Brand + "~" + item.cFree1
  20578. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  20579. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  20580. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  20581. sql = @"select ID,Colspan from ICSExtension a
  20582. where Colspan='{0}' and WorkPoint='{1}'";
  20583. sql = string.Format(sql, Colspan, item.WorkPoint);
  20584. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  20585. if (dttt.Rows.Count == 0)
  20586. {
  20587. IDD = Guid.NewGuid().ToString();
  20588. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  20589. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  20590. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  20591. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  20592. {
  20593. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  20594. }
  20595. }
  20596. else
  20597. {
  20598. IDD = dttt.Rows[0]["ID"].ToString();
  20599. }
  20600. //删除逻辑
  20601. if (!deletefalg)
  20602. {
  20603. if (!string.IsNullOrEmpty(item.deleteIDs))
  20604. {
  20605. var did = item.deleteIDs.Substring(0, item.deleteIDs.Length - 1);
  20606. Checksql = @"delete from ICSOutsourcingReceive
  20607. where ID IN ({0}) and WorkPoint ='{1}'";
  20608. Checksql = string.Format(Checksql, did.TrimEnd(','), item.WorkPoint);
  20609. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  20610. {
  20611. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  20612. }
  20613. else
  20614. {
  20615. deletefalg = true;
  20616. }
  20617. }
  20618. }
  20619. Checksql = @"select ID,ODNCode from ICSODeliveryNotice a
  20620. where ID ='{0}' and WorkPoint='{1}'";
  20621. Checksql = string.Format(Checksql, item.ID, item.WorkPoint);
  20622. DataTable datas = DBHelper.SQlReturnData(Checksql, cmd);
  20623. if (datas.Rows.Count > 0)
  20624. {
  20625. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  20626. BEGIN
  20627. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  20628. RETURN
  20629. END
  20630. update ICSODeliveryNotice
  20631. set [Sequence] = '{0}'
  20632. ,[VenCode] = b.VenCode
  20633. ,[DepCode] = b.DepCode
  20634. ,[WHCode] = '{1}'
  20635. ,[InvCode] = b.InvCode
  20636. ,[Quantity] = {2}
  20637. ,[UnitPrice] = b.UnitPrice
  20638. ,[Currency] = b.Currency
  20639. ,[OOID] = b.ID
  20640. ,[ExtensionID] = '{3}'
  20641. ,[MUSER] = '{4}'
  20642. ,[MUSERName] = (SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  20643. ,[MTIME] = '{5}'
  20644. ,[WorkPoint] = '{6}'
  20645. ,[EATTRIBUTE1] = '{7}'
  20646. from ICSODeliveryNotice a
  20647. join ICSOutsourcingOrder b on a.OOID = '{9}' and a.WorkPoint = b.WorkPoint
  20648. where a.ID = '{8}'";
  20649. sql = string.Format(sql, item.Sequence, item.WHCode, item.Quantity,
  20650. IDD, item.User, dates, item.WorkPoint, item.EATTRIBUTE1, item.ID, item.OOID);
  20651. ODNCode = item.ODNCode;
  20652. Sequence = item.Sequence;
  20653. WorkPoint = item.WorkPoint;
  20654. }
  20655. else
  20656. {
  20657. sql = @"
  20658. INSERT INTO [dbo].[ICSODeliveryNotice]
  20659. ([ID]
  20660. ,[ODNCode]
  20661. ,[Sequence]
  20662. ,[VenCode]
  20663. ,[DepCode]
  20664. ,[WHCode]
  20665. ,[ODNType]
  20666. ,[InvCode]
  20667. ,[Quantity]
  20668. ,[Amount]
  20669. ,[RCVQuantity]
  20670. ,[UnitPrice]
  20671. ,[Currency]
  20672. ,[Status]
  20673. ,[CreatePerson]
  20674. ,[CreateDateTime]
  20675. ,[OOID]
  20676. ,[OODetailID]
  20677. ,[ODNID]
  20678. ,[ODNDetailID]
  20679. ,[ExtensionID]
  20680. ,[MUSER]
  20681. ,[MUSERName]
  20682. ,[MTIME]
  20683. ,[WorkPoint]
  20684. ,[EATTRIBUTE1])
  20685. SELECT NEWID(),'{0}','{1}',oo.VenCode,oo.DepCode,'{2}','1',oo.InvCode,{3}
  20686. ,null,null,oo.UnitPrice,oo.Currency,'1'
  20687. ,'{4}','{5}',oo.ID,'','',''
  20688. ,'{6}','','','{7}','{8}','{9}' FROM ICSOutsourcingOrder oo WHERE oo.ID = '{10}'";
  20689. sql = string.Format(sql, item.ODNCode, item.Sequence, item.WHCode, item.Quantity,
  20690. item.User, Dates, IDD, Dates, item.WorkPoint, item.EATTRIBUTE1, item.OOID);
  20691. ODNCode = item.ODNCode;
  20692. Sequence = item.Sequence;
  20693. WorkPoint = item.WorkPoint;
  20694. }
  20695. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  20696. {
  20697. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  20698. }
  20699. }
  20700. #region 查询返回数据
  20701. sql = @"
  20702. select
  20703. [ID]
  20704. ,[ODNCode]
  20705. ,[Sequence]
  20706. ,[VenCode]
  20707. ,[DepCode]
  20708. ,[WHCode]
  20709. ,[ODNType]
  20710. ,[InvCode]
  20711. ,[Quantity]
  20712. ,[Amount]
  20713. ,[RCVQuantity]
  20714. ,[UnitPrice]
  20715. ,[Currency]
  20716. ,[Status]
  20717. ,[CreatePerson]
  20718. ,[CreateDateTime]
  20719. ,[OOID]
  20720. ,[OODetailID]
  20721. ,[ODNID]
  20722. ,[ODNDetailID]
  20723. ,[ExtensionID]
  20724. from ICSODeliveryNotice a
  20725. WHERE a.ODNCode = '{0}' and a.WorkPoint = '{1}'";
  20726. sql = string.Format(sql, ODNCode, WorkPoint);
  20727. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  20728. #endregion
  20729. cmd.Transaction.Commit();
  20730. return data;
  20731. }
  20732. catch (Exception ex)
  20733. {
  20734. if (cmd.Transaction != null)
  20735. cmd.Transaction.Rollback();
  20736. log.Error(ex.Message);
  20737. throw new Exception(ex.Message);
  20738. }
  20739. finally
  20740. {
  20741. if (conn.State == ConnectionState.Open)
  20742. {
  20743. conn.Close();
  20744. }
  20745. conn.Dispose();
  20746. }
  20747. }
  20748. }
  20749. /// <summary>
  20750. /// 红字采购入库(委外) 新增
  20751. /// </summary>
  20752. /// <param name="JsonData"></param>
  20753. /// <returns></returns>
  20754. /// <exception cref="Exception"></exception>
  20755. public static DataTable OutsourcingReceiveCreate(List<ICSOutsourcingReceive> JsonData)
  20756. {
  20757. var language = LanguageHelper.GetName("WMSAPIInfo");
  20758. if (JsonData.Count <= 0)
  20759. {
  20760. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  20761. }
  20762. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  20763. {
  20764. conn.Open();
  20765. SqlTransaction sqlTran = conn.BeginTransaction();
  20766. SqlCommand cmd = new SqlCommand();
  20767. string Colspan = string.Empty;
  20768. string Sequence = string.Empty;
  20769. string RCVCode = string.Empty;
  20770. string WorkPoint = string.Empty;
  20771. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  20772. string IDD = string.Empty;
  20773. cmd.Transaction = sqlTran;
  20774. cmd.Connection = conn;
  20775. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  20776. try
  20777. {
  20778. string sql = string.Empty;
  20779. HashSet<string> uniqueItems = new HashSet<string>();
  20780. foreach (var item in JsonData)
  20781. {
  20782. //判断当前录入的总数量是否超过了订单数量
  20783. sql = @"select a.OOCode,a.Sequence,sum(ISNULL(b.Quantity,0) - a.Quantity) as DifferenceQty
  20784. ,sum(ISNULL(b.Quantity,0)) as bQty,a.Quantity from ICSOutsourcingOrder a
  20785. left join ICSOutsourcingReceive b on a.OOCode = b.SourceCode and a.Sequence = b.SourceSequence and a.WorkPoint = b.WorkPoint
  20786. where a.OOCode ='{0}' and a.Sequence = '{1}' and a.WorkPoint='{2}'
  20787. group by a.OOCode,a.Sequence,a.Quantity";
  20788. sql = string.Format(sql, item.SourceCode, item.SourceSequence, item.WorkPoint);
  20789. DataTable qtydata = DBHelper.SQlReturnData(sql, cmd);
  20790. if (qtydata.Rows.Count == 0)
  20791. {
  20792. throw new Exception("未找到委外订单" + item.SourceCode + "第" + item.SourceSequence + "行");
  20793. }
  20794. else
  20795. {
  20796. var qtysum = JsonData.Where(q => q.SourceCode == item.SourceCode && q.SourceSequence == item.SourceSequence).Sum(q => Convert.ToInt32(q.Quantity));
  20797. var DifferenceQty = Convert.ToInt32(qtydata.Rows[0]["DifferenceQty"]);
  20798. var Quantity = Convert.ToInt32(qtydata.Rows[0]["Quantity"]);
  20799. var bQty = Convert.ToInt32(qtydata.Rows[0]["bQty"]);
  20800. //已入库数量和订单数量的差 小于0 则没有超过订单数量 则超过报错
  20801. if (DifferenceQty > 0)
  20802. {
  20803. throw new Exception("委外订单" + item.SourceCode + "第" + item.SourceSequence + "行的订单数量:" + Quantity.ToString() +
  20804. "。已入库数量:" + bQty.ToString() + "。当前入库总数量:" + qtysum.ToString() + "。已超过订单数量!");
  20805. }
  20806. else
  20807. {
  20808. //录入数量大于已入库数量和订单数量的差 则超过报错
  20809. if (0 - DifferenceQty < qtysum)
  20810. {
  20811. throw new Exception("委外订单" + item.SourceCode + "第" + item.SourceSequence + "行的订单数量:" + Quantity.ToString() +
  20812. "。已入库数量:" + bQty.ToString() + "。当前入库总数量:" + qtysum.ToString() + "。已超过订单数量!");
  20813. }
  20814. }
  20815. }
  20816. //检验自由项
  20817. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  20818. + "~" + item.Brand + "~" + item.cFree1
  20819. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  20820. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  20821. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  20822. sql = @"select ID,Colspan from ICSExtension a
  20823. where Colspan='{0}' and WorkPoint='{1}'";
  20824. sql = string.Format(sql, Colspan, item.WorkPoint);
  20825. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  20826. if (dttt.Rows.Count == 0)
  20827. {
  20828. IDD = Guid.NewGuid().ToString();
  20829. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  20830. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  20831. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  20832. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  20833. {
  20834. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  20835. }
  20836. }
  20837. else
  20838. {
  20839. IDD = dttt.Rows[0]["ID"].ToString();
  20840. }
  20841. //获取单号
  20842. string key = item.Sequence + "~" + item.InvCode;
  20843. if (uniqueItems.Contains(key))
  20844. {
  20845. throw new Exception("子件不可重复添加!");
  20846. }
  20847. uniqueItems.Add(key);
  20848. //直接关联ID新增
  20849. //sql = @"select a.ID,a.OOCode,a.Sequence,a.VenCode,a.DepCode,a.PersonCode,a.InvCode,a.Amount,a.Quantity,
  20850. // a.UnitPrice,a.Currency,a.Status,a.ReleaseState,a.PlanArriveDate,a.CreatePerson,a.CreateDateTime
  20851. // from ICSOutsourcingOrder a
  20852. // where a.ID ='{0}' and WorkPoint='{1}'";
  20853. //sql = string.Format(sql, item.OOID, item.WorkPoint);
  20854. //DataTable oo = DBHelper.SQlReturnData(sql, cmd);
  20855. //创建主表
  20856. sql = @"
  20857. INSERT INTO [dbo].[ICSOutsourcingReceive]
  20858. ([ID]
  20859. ,[RCVCode]
  20860. ,[Sequence]
  20861. ,[SourceCode]
  20862. ,[SourceSequence]
  20863. ,[InvCode]
  20864. ,[Quantity]
  20865. ,[Amount]
  20866. ,[RCVQuantity]
  20867. ,[WHCode]
  20868. ,[Type]
  20869. ,[Status]
  20870. ,[CreatePerson]
  20871. ,[CreateDateTime]
  20872. ,[RCVID]
  20873. ,[RCVDetailID]
  20874. ,[ExtensionID]
  20875. ,[MUSER]
  20876. ,[MUSERName]
  20877. ,[MTIME]
  20878. ,[WorkPoint])
  20879. VALUES
  20880. (NEWID(),'{0}','{1}','{2}', '{3}','{4}',{5},null,null,'{6}','2','1','{7}','{8}',
  20881. NEWID(),NEWID(),'{9}','','','{10}','{11}')";
  20882. sql = string.Format(sql, item.RCVCode, item.Sequence, item.SourceCode, item.SourceSequence, item.InvCode, item.Quantity, item.WHCode, item.User, Dates,
  20883. IDD, Dates, item.WorkPoint);
  20884. RCVCode = item.RCVCode;
  20885. WorkPoint = item.WorkPoint;
  20886. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  20887. {
  20888. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产订单信息创建失败!");
  20889. }
  20890. }
  20891. #region 查询返回数据
  20892. sql = @"
  20893. select
  20894. [ID]
  20895. ,[RCVCode]
  20896. ,[Sequence]
  20897. ,[SourceCode]
  20898. ,[SourceSequence]
  20899. ,[InvCode]
  20900. ,[Quantity]
  20901. ,[Amount]
  20902. ,[RCVQuantity]
  20903. ,[WHCode]
  20904. ,[Type]
  20905. ,[Status]
  20906. ,[CreatePerson]
  20907. ,[CreateDateTime]
  20908. ,[RCVID]
  20909. ,[RCVDetailID]
  20910. ,[ExtensionID]
  20911. ,[MUSER]
  20912. ,[MUSERName]
  20913. ,[MTIME]
  20914. ,[WorkPoint]
  20915. from ICSOutsourcingReceive a
  20916. WHERE a.RCVCode = '{0}' and a.WorkPoint = '{1}'";
  20917. sql = string.Format(sql, RCVCode, WorkPoint);
  20918. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  20919. #endregion
  20920. cmd.Transaction.Commit();
  20921. return data;
  20922. }
  20923. catch (Exception ex)
  20924. {
  20925. if (cmd.Transaction != null)
  20926. cmd.Transaction.Rollback();
  20927. log.Error(ex.Message);
  20928. throw new Exception(ex.Message);
  20929. }
  20930. finally
  20931. {
  20932. if (conn.State == ConnectionState.Open)
  20933. {
  20934. conn.Close();
  20935. }
  20936. conn.Dispose();
  20937. }
  20938. }
  20939. }
  20940. /// <summary>
  20941. /// 红字采购入库(委外) 修改
  20942. /// </summary>
  20943. /// <param name="JsonData"></param>
  20944. /// <returns></returns>
  20945. public static DataTable OutsourcingReceiveUpdate(List<ICSOutsourcingReceive> JsonData)
  20946. {
  20947. var language = LanguageHelper.GetName("WMSAPIInfo");
  20948. if (JsonData.Count <= 0)
  20949. {
  20950. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  20951. }
  20952. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  20953. {
  20954. conn.Open();
  20955. SqlTransaction sqlTran = conn.BeginTransaction();
  20956. SqlCommand cmd = new SqlCommand();
  20957. cmd.Transaction = sqlTran;
  20958. cmd.Connection = conn;
  20959. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  20960. try
  20961. {
  20962. string sql = string.Empty;
  20963. string Checksql = string.Empty;
  20964. string Sequence = string.Empty;
  20965. string RCVCode = string.Empty;
  20966. string WorkPoint = string.Empty;
  20967. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  20968. string Colspan = string.Empty;
  20969. string IDD = string.Empty;
  20970. string dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  20971. bool deletefalg = false;
  20972. foreach (var item in JsonData)
  20973. {
  20974. //判断当前录入的总数量是否超过了订单数量
  20975. sql = @"select a.OOCode,a.Sequence,sum(ISNULL(b.Quantity,0) - a.Quantity) as DifferenceQty
  20976. ,sum(ISNULL(b.Quantity,0)) as bQty,a.Quantity from ICSOutsourcingOrder a
  20977. left join ICSOutsourcingReceive b on a.OOCode = b.SourceCode and a.Sequence = b.SourceSequence and a.WorkPoint = b.WorkPoint
  20978. where a.OOCode ='{0}' and a.Sequence = '{1}' and a.WorkPoint='{2}'
  20979. group by a.OOCode,a.Sequence,a.Quantity";
  20980. sql = string.Format(sql, item.SourceCode, item.SourceSequence, item.WorkPoint);
  20981. DataTable qtydata = DBHelper.SQlReturnData(sql, cmd);
  20982. if (qtydata.Rows.Count == 0)
  20983. {
  20984. throw new Exception("未找到委外订单" + item.SourceCode + "第" + item.SourceSequence + "行");
  20985. }
  20986. else
  20987. {
  20988. var qtysum = JsonData.Where(q => q.SourceCode == item.SourceCode && q.SourceSequence == item.SourceSequence).Sum(q => Convert.ToInt32(q.Quantity));
  20989. var DifferenceQty = Convert.ToInt32(qtydata.Rows[0]["DifferenceQty"]);
  20990. var Quantity = Convert.ToInt32(qtydata.Rows[0]["Quantity"]);
  20991. var bQty = Convert.ToInt32(qtydata.Rows[0]["bQty"]);
  20992. //已入库数量和订单数量的差 小于0 则没有超过订单数量 则超过报错
  20993. if (DifferenceQty > 0)
  20994. {
  20995. throw new Exception("委外订单" + item.SourceCode + "第" + item.SourceSequence + "行的订单数量:" + Quantity.ToString() +
  20996. "。已入库数量:" + bQty.ToString() + "。当前入库总数量:" + qtysum.ToString() + "。已超过订单数量!");
  20997. }
  20998. else
  20999. {
  21000. //录入数量大于已入库数量和订单数量的差 则超过报错
  21001. if (0 - DifferenceQty < qtysum)
  21002. {
  21003. throw new Exception("委外订单" + item.SourceCode + "第" + item.SourceSequence + "行的订单数量:" + Quantity.ToString() +
  21004. "。已入库数量:" + bQty.ToString() + "。当前入库总数量:" + qtysum.ToString() + "。已超过订单数量!");
  21005. }
  21006. }
  21007. }
  21008. //检验自由项
  21009. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  21010. + "~" + item.Brand + "~" + item.cFree1
  21011. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  21012. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  21013. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  21014. sql = @"select ID,Colspan from ICSExtension a
  21015. where Colspan='{0}' and WorkPoint='{1}'";
  21016. sql = string.Format(sql, Colspan, item.WorkPoint);
  21017. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  21018. if (dttt.Rows.Count == 0)
  21019. {
  21020. IDD = Guid.NewGuid().ToString();
  21021. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  21022. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  21023. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  21024. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21025. {
  21026. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  21027. }
  21028. }
  21029. else
  21030. {
  21031. IDD = dttt.Rows[0]["ID"].ToString();
  21032. }
  21033. //删除逻辑
  21034. if (!deletefalg)
  21035. {
  21036. if (!string.IsNullOrEmpty(item.deleteIDs))
  21037. {
  21038. var did = item.deleteIDs.Substring(0, item.deleteIDs.Length - 1);
  21039. Checksql = @"delete from ICSOutsourcingReceive
  21040. where ID IN ({0}) and WorkPoint ='{1}'";
  21041. Checksql = string.Format(Checksql, did.TrimEnd(','), item.WorkPoint);
  21042. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  21043. {
  21044. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  21045. }
  21046. else
  21047. {
  21048. deletefalg = true;
  21049. }
  21050. }
  21051. }
  21052. Checksql = @"select ID,RCVCode from ICSOutsourcingReceive a
  21053. where ID ='{0}' and WorkPoint='{1}'";
  21054. Checksql = string.Format(Checksql, item.ID, item.WorkPoint);
  21055. DataTable datas = DBHelper.SQlReturnData(Checksql, cmd);
  21056. if (datas.Rows.Count > 0)
  21057. {
  21058. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{8}' AND F_Location='{10}')
  21059. BEGIN
  21060. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  21061. RETURN
  21062. END
  21063. UPDATE [dbo].[ICSOutsourcingReceive]
  21064. SET [RCVCode] = '{0}'
  21065. ,[Sequence] = '{1}'
  21066. ,[SourceCode] = '{2}'
  21067. ,[SourceSequence] = '{3}'
  21068. ,[InvCode] = '{4}'
  21069. ,[Quantity] = {5}
  21070. ,[WHCode] = '{6}'
  21071. ,[ExtensionID] = '{7}'
  21072. ,[MUSER] = '{8}'
  21073. ,[MUSERName] = (select F_RealName from Sys_SRM_User where F_Account='{8}' and F_Location='{10}')
  21074. ,[MTIME] = '{9}'
  21075. ,[WorkPoint] = '{10}'
  21076. where ID = '{11}'";
  21077. sql = string.Format(sql, item.RCVCode, item.Sequence, item.SourceCode, item.SourceSequence, item.InvCode, item.Quantity,
  21078. item.WHCode, IDD, item.User, dates, item.WorkPoint, item.ID);
  21079. RCVCode = item.RCVCode;
  21080. Sequence = item.Sequence;
  21081. WorkPoint = item.WorkPoint;
  21082. }
  21083. else
  21084. {
  21085. sql = @"
  21086. INSERT INTO [dbo].[ICSOutsourcingReceive]
  21087. ([ID]
  21088. ,[RCVCode]
  21089. ,[Sequence]
  21090. ,[SourceCode]
  21091. ,[SourceSequence]
  21092. ,[InvCode]
  21093. ,[Quantity]
  21094. ,[Amount]
  21095. ,[RCVQuantity]
  21096. ,[WHCode]
  21097. ,[Type]
  21098. ,[Status]
  21099. ,[CreatePerson]
  21100. ,[CreateDateTime]
  21101. ,[RCVID]
  21102. ,[RCVDetailID]
  21103. ,[ExtensionID]
  21104. ,[MUSER]
  21105. ,[MUSERName]
  21106. ,[MTIME]
  21107. ,[WorkPoint])
  21108. VALUES
  21109. (NEWID(),'{0}','{1}','{2}', '{3}','{4}',{5},null,null,'{6}','2','1','{7}','{8}',
  21110. NEWID(),NEWID(),'{9}','','','{10}','{11}')";
  21111. sql = string.Format(sql, item.RCVCode, item.Sequence, item.SourceCode, item.SourceSequence, item.InvCode, item.Quantity, item.WHCode, item.User, Dates,
  21112. IDD, Dates, item.WorkPoint);
  21113. RCVCode = item.RCVCode;
  21114. Sequence = item.Sequence;
  21115. WorkPoint = item.WorkPoint;
  21116. }
  21117. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21118. {
  21119. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  21120. }
  21121. //修改委外订单的入库数量
  21122. }
  21123. #region 查询返回数据
  21124. sql = @"
  21125. select
  21126. [ID]
  21127. ,[RCVCode]
  21128. ,[Sequence]
  21129. ,[SourceCode]
  21130. ,[SourceSequence]
  21131. ,[InvCode]
  21132. ,[Quantity]
  21133. ,[Amount]
  21134. ,[RCVQuantity]
  21135. ,[WHCode]
  21136. ,[Type]
  21137. ,[Status]
  21138. ,[CreatePerson]
  21139. ,[CreateDateTime]
  21140. ,[RCVID]
  21141. ,[RCVDetailID]
  21142. ,[ExtensionID]
  21143. ,[MUSER]
  21144. ,[MUSERName]
  21145. ,[MTIME]
  21146. ,[WorkPoint]
  21147. from ICSOutsourcingReceive a
  21148. WHERE a.RCVCode = '{0}' and a.WorkPoint = '{1}'";
  21149. sql = string.Format(sql, RCVCode, WorkPoint);
  21150. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  21151. #endregion
  21152. cmd.Transaction.Commit();
  21153. return data;
  21154. }
  21155. catch (Exception ex)
  21156. {
  21157. if (cmd.Transaction != null)
  21158. cmd.Transaction.Rollback();
  21159. log.Error(ex.Message);
  21160. throw new Exception(ex.Message);
  21161. }
  21162. finally
  21163. {
  21164. if (conn.State == ConnectionState.Open)
  21165. {
  21166. conn.Close();
  21167. }
  21168. conn.Dispose();
  21169. }
  21170. }
  21171. }
  21172. /// <summary>
  21173. /// 采购到货(退货 包含无源头) 新增
  21174. /// </summary>
  21175. /// <param name="JsonData"></param>
  21176. /// <returns></returns>
  21177. /// <exception cref="Exception"></exception>
  21178. public static DataTable ICSEDeliveryNoticeCreate(List<ICSEDeliveryNotice> JsonData)
  21179. {
  21180. var language = LanguageHelper.GetName("WMSAPIInfo");
  21181. if (JsonData.Count <= 0)
  21182. {
  21183. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  21184. }
  21185. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  21186. {
  21187. conn.Open();
  21188. SqlTransaction sqlTran = conn.BeginTransaction();
  21189. SqlCommand cmd = new SqlCommand();
  21190. string Colspan = string.Empty;
  21191. string Sequence = string.Empty;
  21192. string DNCode = string.Empty;
  21193. string WorkPoint = string.Empty;
  21194. string DNCodes = string.Empty;
  21195. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  21196. string IDD = string.Empty;
  21197. cmd.Transaction = sqlTran;
  21198. cmd.Connection = conn;
  21199. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  21200. try
  21201. {
  21202. string sql = string.Empty;
  21203. HashSet<string> uniqueItems = new HashSet<string>();
  21204. foreach (var item in JsonData)
  21205. {
  21206. var ASNCode = "";
  21207. string Code = "";
  21208. //if (!string.IsNullOrEmpty(item.LotNo))
  21209. //{
  21210. // //判断送货单号是否存在
  21211. // sql = @"select a.ID,a.ASNCode,a.Sequence,a.LotNo,a.Quantity as ASNQty,a.DNQuantity from ICSASNDetail a where a.LotNo = '{0}' and a.WorkPoint='{1}'";
  21212. // sql = string.Format(sql, item.LotNo, item.WorkPoint);
  21213. // DataTable ASNdata = DBHelper.SQlReturnData(sql, cmd);
  21214. // if (ASNdata.Rows.Count == 0)
  21215. // {
  21216. // throw new Exception("未找到送货单" + item.LotNo);
  21217. // }
  21218. // var qtysum = JsonData.Where(q => q.LotNo == item.LotNo).Sum(q => Convert.ToInt32(q.Quantity));
  21219. // var ASNQty = Convert.ToInt32(ASNdata.Rows[0]["ASNQty"]);//送货单数量
  21220. // var DNQuantity = Convert.ToInt32(ASNdata.Rows[0]["DNQuantity"]);//已到货数量
  21221. // //到货数量是否超过送货单子表数量
  21222. // if (ASNQty < qtysum + DNQuantity)
  21223. // {
  21224. // throw new Exception("送货单数量为" + ASNQty + ",已到货数量" + DNQuantity + ",当前采购到货数量" + qtysum + ",已超过送货单数量,请核对。");
  21225. // }
  21226. // ASNCode = ASNdata.Rows[0]["ASNCode"].ToString();
  21227. // sql = @"SELECT a.DNCode FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}'";
  21228. // sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  21229. // DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  21230. // if (dt.Rows.Count > 0)
  21231. // {
  21232. // DNCodes = dt.Rows[0]["DNCode"].ToString();
  21233. // }
  21234. // //获取单号
  21235. // sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  21236. // BEGIN
  21237. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  21238. // RETURN
  21239. // END
  21240. // DECLARE @Status VARCHAR(10)
  21241. // SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  21242. // IF (@Status IS NULL)
  21243. // BEGIN
  21244. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  21245. // RETURN
  21246. // END
  21247. // ELSE IF (@Status!='2')
  21248. // BEGIN
  21249. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  21250. // RETURN
  21251. // END
  21252. // DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  21253. // SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  21254. // WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  21255. // IF @MaxNO IS NULL
  21256. // BEGIN
  21257. // SELECT @date+'00001' AS Code
  21258. // END
  21259. // ELSE
  21260. // BEGIN
  21261. // SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  21262. // END ";
  21263. // sql = string.Format(sql, item.ASNCode, item.WorkPoint, DNCodes);
  21264. // Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  21265. //}
  21266. //else
  21267. //{
  21268. // sql = @"DECLARE @MaxNO INT,@date varchar(20)= 'DN' + SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  21269. // SELECT @MaxNO = SUBSTRING(MAX(DNCode), LEN(@date) + 1, LEN(MAX(DNCode)) - LEN(@date)) + 1 FROM ICSDeliveryNotice
  21270. // WHERE SUBSTRING(DNCode, 1, LEN(@date))= @date
  21271. // IF @MaxNO IS NULL
  21272. // BEGIN
  21273. // SELECT @date + '00001' AS Code
  21274. // END
  21275. // ELSE
  21276. // BEGIN
  21277. // SELECT @date + REPLICATE('0', 5 - LEN(@MaxNO)) + CAST(@MaxNO AS nvarchar(10)) AS Code
  21278. // END ";
  21279. // sql = string.Format(sql, item.ASNCode, item.WorkPoint, DNCodes);
  21280. // Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  21281. //}
  21282. //判断当前录入的总数量是否超过了订单数量
  21283. //检验自由项
  21284. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  21285. + "~" + item.Brand + "~" + item.cFree1
  21286. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  21287. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  21288. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  21289. sql = @"select ID,Colspan from ICSExtension a
  21290. where Colspan='{0}' and WorkPoint='{1}'";
  21291. sql = string.Format(sql, Colspan, item.WorkPoint);
  21292. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  21293. if (dttt.Rows.Count == 0)
  21294. {
  21295. IDD = Guid.NewGuid().ToString();
  21296. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  21297. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  21298. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  21299. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21300. {
  21301. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  21302. }
  21303. }
  21304. else
  21305. {
  21306. IDD = dttt.Rows[0]["ID"].ToString();
  21307. }
  21308. //string key = item.Sequence + "~" + item.InvCode;
  21309. //if (uniqueItems.Contains(key))
  21310. //{
  21311. // throw new Exception("子件不可重复添加!");
  21312. //}
  21313. //uniqueItems.Add(key);
  21314. //直接关联ID新增
  21315. //sql = @"select a.ID,a.OOCode,a.Sequence,a.VenCode,a.DepCode,a.PersonCode,a.InvCode,a.Amount,a.Quantity,
  21316. // a.UnitPrice,a.Currency,a.Status,a.ReleaseState,a.PlanArriveDate,a.CreatePerson,a.CreateDateTime
  21317. // from ICSOutsourcingOrder a
  21318. // where a.ID ='{0}' and WorkPoint='{1}'";
  21319. //sql = string.Format(sql, item.OOID, item.WorkPoint);
  21320. //DataTable oo = DBHelper.SQlReturnData(sql, cmd);
  21321. //创建主表
  21322. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{10}' AND F_Location='{17}')
  21323. BEGIN
  21324. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{10}") + @"',16,1);
  21325. RETURN
  21326. END
  21327. INSERT INTO [dbo].[ICSDeliveryNotice]
  21328. ([ID]
  21329. ,[DNCode]
  21330. ,[Sequence]
  21331. ,[VenCode]
  21332. ,[DepCode]
  21333. ,[WHCode]
  21334. ,[DNType]
  21335. ,[InvCode]
  21336. ,[Quantity]
  21337. ,[Amount]
  21338. ,[RCVQuantity]
  21339. ,[UnitPrice]
  21340. ,[Currency]
  21341. ,[Status]
  21342. ,[CreatePerson]
  21343. ,[CreateDateTime]
  21344. ,[POID]
  21345. ,[PODetailID]
  21346. ,[DNID]
  21347. ,[DNDetailID]
  21348. ,[ExtensionID]
  21349. ,[MUSER]
  21350. ,[MUSERName]
  21351. ,[MTIME]
  21352. ,[WorkPoint]
  21353. ,[EATTRIBUTE1]
  21354. ,[ASNCode])
  21355. VALUES
  21356. (NEWID()
  21357. ,'{18}'
  21358. ,'{0}'
  21359. ,'{1}'
  21360. ,'{2}'
  21361. ,'{3}'
  21362. ,'{4}'
  21363. ,'{5}'
  21364. ,{6}
  21365. ,{7}
  21366. ,0
  21367. ,{8}
  21368. ,'{9}' --Currency
  21369. ,'1'
  21370. ,'{10}'
  21371. ,'{11}'
  21372. ,'{12}'
  21373. ,'{13}'
  21374. ,'{14}'
  21375. ,'{15}' --DNDetailID
  21376. ,'{16}'
  21377. ,'{10}'
  21378. ,(select F_RealName from Sys_SRM_User where F_Account='{10}' and F_Location='{17}')
  21379. ,'{11}'
  21380. ,'{17}'
  21381. ,''
  21382. ,'')";
  21383. sql = string.Format(sql, item.Sequence, item.VenCode, item.DepCode, item.WHCode, item.DNType, item.InvCode, item.Quantity, item.Amount, item.UnitPrice, item.Currency, item.User, Dates,
  21384. item.POID, item.PODetailID, item.DNID, item.DNDetailID, IDD, item.WorkPoint, item.DNCode);
  21385. DNCode = Code;
  21386. WorkPoint = item.WorkPoint;
  21387. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21388. {
  21389. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产订单信息创建失败!");
  21390. }
  21391. }
  21392. #region 查询返回数据
  21393. sql = @"
  21394. select
  21395. ID,
  21396. DNCode,
  21397. Sequence,
  21398. VenCode,
  21399. DepCode,
  21400. WHCode,
  21401. DNType,
  21402. InvCode,
  21403. Quantity,
  21404. Amount,
  21405. RCVQuantity,
  21406. UnitPrice,
  21407. Currency,
  21408. Status,
  21409. CreatePerson,
  21410. CreateDateTime
  21411. from ICSDeliveryNotice a
  21412. WHERE a.DNCode = '{0}' and a.Sequence = '{1}' and a.WorkPoint = '{2}'";
  21413. sql = string.Format(sql, DNCode, Sequence, WorkPoint);
  21414. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  21415. #endregion
  21416. cmd.Transaction.Commit();
  21417. return data;
  21418. }
  21419. catch (Exception ex)
  21420. {
  21421. if (cmd.Transaction != null)
  21422. cmd.Transaction.Rollback();
  21423. log.Error(ex.Message);
  21424. throw new Exception(ex.Message);
  21425. }
  21426. finally
  21427. {
  21428. if (conn.State == ConnectionState.Open)
  21429. {
  21430. conn.Close();
  21431. }
  21432. conn.Dispose();
  21433. }
  21434. }
  21435. }
  21436. /// <summary>
  21437. /// 采购到货(退货 包含无源头) 修改
  21438. /// </summary>
  21439. /// <param name="JsonData"></param>
  21440. /// <returns></returns>
  21441. public static DataTable ICSEDeliveryNoticeUpdate(List<ICSEDeliveryNotice> JsonData)
  21442. {
  21443. var language = LanguageHelper.GetName("WMSAPIInfo");
  21444. if (JsonData.Count <= 0)
  21445. {
  21446. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  21447. }
  21448. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  21449. {
  21450. conn.Open();
  21451. SqlTransaction sqlTran = conn.BeginTransaction();
  21452. SqlCommand cmd = new SqlCommand();
  21453. cmd.Transaction = sqlTran;
  21454. cmd.Connection = conn;
  21455. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  21456. try
  21457. {
  21458. string sql = string.Empty;
  21459. string Checksql = string.Empty;
  21460. string Sequence = string.Empty;
  21461. string DNCode = string.Empty;
  21462. string WorkPoint = string.Empty;
  21463. string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  21464. string Colspan = string.Empty;
  21465. string IDD = string.Empty;
  21466. foreach (var item in JsonData)
  21467. {
  21468. //检验自由项
  21469. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  21470. + "~" + item.Brand + "~" + item.cFree1
  21471. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  21472. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  21473. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  21474. sql = @"select ID,Colspan from ICSExtension a
  21475. where Colspan='{0}' and WorkPoint='{1}'";
  21476. sql = string.Format(sql, Colspan, item.WorkPoint);
  21477. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  21478. if (dttt.Rows.Count == 0)
  21479. {
  21480. IDD = Guid.NewGuid().ToString();
  21481. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  21482. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  21483. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  21484. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21485. {
  21486. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  21487. }
  21488. }
  21489. else
  21490. {
  21491. IDD = dttt.Rows[0]["ID"].ToString();
  21492. }
  21493. //[MUSERName] = (select F_RealName from Sys_SRM_User where F_Account='{5}' and F_Location='{6}')
  21494. Checksql = @"select ID,DNCode from ICSDeliveryNotice a
  21495. where ID ='{0}' and WorkPoint='{1}'";
  21496. Checksql = string.Format(Checksql, item.ID, item.WorkPoint);
  21497. DataTable datas = DBHelper.SQlReturnData(Checksql, cmd);
  21498. if (datas.Rows.Count > 0)
  21499. {
  21500. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{11}' AND F_Location='{13}')
  21501. BEGIN
  21502. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  21503. RETURN
  21504. END
  21505. UPDATE [dbo].[ICSDeliveryNotice]
  21506. SET [VenCode] = '{0}'
  21507. ,[DepCode] = '{1}'
  21508. ,[WHCode] = '{2}'
  21509. ,[DNType] = '{3}'
  21510. ,[InvCode] = '{4}'
  21511. ,[Quantity] = {5}
  21512. ,[Amount] = {6}
  21513. ,[UnitPrice] = {7}
  21514. ,[Currency] = '{8}'
  21515. ,[POID] = '{9}'
  21516. ,[ExtensionID] = '{10}'
  21517. ,[MUSER] = '{11}'
  21518. ,[MUSERName] = (select F_RealName from Sys_SRM_User where F_Account='{11}' and F_Location='{13}')
  21519. ,[MTIME] = '{12}'
  21520. ,[WorkPoint] = '{13}'
  21521. where ID = '{14}'";
  21522. sql = string.Format(sql, item.VenCode, item.DepCode, item.WHCode, item.DNType, item.InvCode, item.Quantity,
  21523. item.Amount, item.UnitPrice, item.Currency, item.POID, IDD, item.User, Dates, item.WorkPoint, item.ID);
  21524. DNCode = item.DNCode;
  21525. Sequence = item.Sequence;
  21526. WorkPoint = item.WorkPoint;
  21527. }
  21528. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21529. {
  21530. throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  21531. }
  21532. //修改委外订单的入库数量
  21533. }
  21534. #region 查询返回数据
  21535. sql = @"
  21536. select
  21537. ID,
  21538. DNCode,
  21539. Sequence,
  21540. VenCode,
  21541. DepCode,
  21542. WHCode,
  21543. DNType,
  21544. InvCode,
  21545. Quantity,
  21546. Amount,
  21547. RCVQuantity,
  21548. UnitPrice,
  21549. Currency,
  21550. Status,
  21551. CreatePerson,
  21552. CreateDateTime
  21553. from ICSDeliveryNotice a
  21554. WHERE a.DNCode = '{0}' and a.Sequence = '{1}' and a.WorkPoint = '{2}'";
  21555. sql = string.Format(sql, DNCode, Sequence, WorkPoint);
  21556. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  21557. #endregion
  21558. cmd.Transaction.Commit();
  21559. return data;
  21560. }
  21561. catch (Exception ex)
  21562. {
  21563. if (cmd.Transaction != null)
  21564. cmd.Transaction.Rollback();
  21565. log.Error(ex.Message);
  21566. throw new Exception(ex.Message);
  21567. }
  21568. finally
  21569. {
  21570. if (conn.State == ConnectionState.Open)
  21571. {
  21572. conn.Close();
  21573. }
  21574. conn.Dispose();
  21575. }
  21576. }
  21577. }
  21578. /// <summary>
  21579. /// 传输产成品信息
  21580. /// </summary>
  21581. /// <param name="JsonData"></param>
  21582. /// <returns></returns>
  21583. public static DataTable ICSFinishedBarCodeCreate(List<ICSFinishedBarCodeModel> JsonData)
  21584. {
  21585. var language = LanguageHelper.GetName("WMSAPIInfo");
  21586. string Identification = Guid.NewGuid().ToString();
  21587. if (JsonData.Count <= 0)
  21588. {
  21589. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  21590. }
  21591. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  21592. {
  21593. conn.Open();
  21594. SqlTransaction sqlTran = conn.BeginTransaction();
  21595. SqlCommand cmd = new SqlCommand();
  21596. string Colspan = string.Empty;
  21597. string IDD = string.Empty;
  21598. cmd.Transaction = sqlTran;
  21599. cmd.Connection = conn;
  21600. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  21601. try
  21602. {
  21603. string codes = string.Empty;
  21604. string sql = string.Empty;
  21605. foreach (var item in JsonData)
  21606. {
  21607. //检验自由项
  21608. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  21609. + "~" + item.Brand + "~" + item.cFree1
  21610. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  21611. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  21612. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  21613. sql = @"select ID,Colspan from ICSExtension a
  21614. where Colspan='{0}' and WorkPoint='{1}'";
  21615. sql = string.Format(sql, Colspan, item.WorkPoint);
  21616. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  21617. if (dttt.Rows.Count == 0)
  21618. {
  21619. IDD = Guid.NewGuid().ToString();
  21620. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  21621. select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  21622. sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.MUSER, item.WorkPoint, IDD);
  21623. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21624. {
  21625. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  21626. }
  21627. }
  21628. else
  21629. {
  21630. IDD = dttt.Rows[0]["ID"].ToString();
  21631. }
  21632. //
  21633. sql = @"-- 查询用户是否存在
  21634. -- IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{8}' AND F_Location='{9}')
  21635. -- BEGIN
  21636. -- RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{8}") + @"',16,1);
  21637. -- RETURN
  21638. -- END
  21639. --
  21640. IF NOT EXISTS(SELECT 1 FROM ICSInventory WHERE InvCode='{4}' AND WorkPoint='{9}')
  21641. BEGIN
  21642. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo524"), "{4}") + @"',16,1)
  21643. RETURN
  21644. END
  21645. --
  21646. IF NOT EXISTS(SELECT 1 FROM ICSMO WHERE MOCode='{1}' AND Sequence='{2}' AND WorkPoint='{9}')
  21647. BEGIN
  21648. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo523"), "{1}", "{2}") + @"',16,1)
  21649. RETURN
  21650. END
  21651. --
  21652. -- IF EXISTS(SELECT 1 FROM ICSInventoryLotDetail WHERE LotNo='{3}' AND WorkPoint='{9}')
  21653. -- BEGIN
  21654. -- RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo527"), "{3}") + @"',16,1)
  21655. -- RETURN
  21656. -- END
  21657. --
  21658. IF NOT EXISTS(SELECT 1 FROM ICSMO WHERE MOCode='{1}' AND Sequence='{2}' AND WorkPoint='{9}' AND InvCode='{4}')
  21659. BEGIN
  21660. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo522"), "{1}", "{2}") + @"',16,1)
  21661. RETURN
  21662. END
  21663. --
  21664. IF EXISTS(SELECT 1 FROM ICSInventoryLot WHERE LotNo='{3}' AND WorkPoint='{9}')
  21665. BEGIN
  21666. --
  21667. IF EXISTS (SELECT 1 FROM ICSWareHouseLotInfo WHERE LotNo='{3}' AND WorkPoint='{9}' AND Quantity>0)
  21668. BEGIN
  21669. RAISERROR('" + @"{3} " + string.Format(language.GetNameByCode("WMSAPIInfo367")) + @"',16,4)
  21670. RETURN
  21671. END
  21672. -- 0
  21673. ELSE IF EXISTS (SELECT 1 FROM ICSWareHouseLotInfo WHERE LotNo='{3}' AND WorkPoint='{9}' AND Quantity=0)
  21674. BEGIN
  21675. --
  21676. UPDATE ICSInventoryLot SET Quantity='{5}' WHERE LotNo='{3}' AND WorkPoint='{9}'
  21677. --
  21678. DELETE FROM ICSWareHouseLotInfo WHERE LotNo='{3}' AND WorkPoint='{9}'
  21679. --
  21680. UPDATE ICSInventoryLotDetail SET TransID=(SELECT ID FROM ICSMO WHERE MOCode='{1}' AND Sequence='{2}' AND WorkPoint='{9}'),TransCode='{1}',TransSequence='{2}',MUSER='{8}',MUSERName='{9}',MTIME=GETDATE()
  21681. --
  21682. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransID,TransCode,TransSequence,LotNo,InvCode,Quantity,Lock,TransType,BusinessCode,MUSER,MUSERName,MTIME,WorkPoint)
  21683. VALUES(NEWID(),'{10}',(SELECT ID FROM ICSMO WHERE MOCode='{1}' AND Sequence='{2}' AND WorkPoint='{9}'),'{1}','{2}','{3}','{4}',{5},0,'17','17','{8}','{8}',GETDATE(),'{9}')
  21684. RETURN
  21685. END
  21686. END
  21687. --
  21688. INSERT INTO ICSInventoryLot(ID,LotNo,InvCode,ProductDate,ExpirationDate,Quantity,Type,MUSER,MUSERName,MTIME,WorkPoint,ExtensionID,EATTRIBUTE10) VALUES('{0}','{3}','{4}','{7}','2999-12-31',{5},'9','{8}','{8}',GETDATE(),'{9}','{11}','{6}')
  21689. --
  21690. INSERT INTO ICSInventoryLotDetail(LotNo,TransID,TransCode,TransSequence,MUSER,MUSERName,MTIME,WorkPoint) VALUES('{3}',(SELECT ID FROM ICSMO WHERE MOCode='{1}' AND Sequence='{2}' AND WorkPoint='{9}'),'{1}','{2}','{8}','{8}',GETDATE(),'{9}')
  21691. --
  21692. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransID,TransCode,TransSequence,LotNo,InvCode,Quantity,Lock,TransType,BusinessCode,MUSER,MUSERName,MTIME,WorkPoint)
  21693. VALUES(NEWID(),'{10}',(SELECT ID FROM ICSMO WHERE MOCode='{1}' AND Sequence='{2}' AND WorkPoint='{9}'),'{1}','{2}','{3}','{4}',{5},0,'17','17','{8}','{8}',GETDATE(),'{9}')";
  21694. sql = string.Format(sql, item.ID, item.MOCode, item.Sequence, item.LotNo, item.InvCode, item.Quantity, item.BatchCode, item.ProductDate, item.MUSER, item.WorkPoint, Identification, IDD);
  21695. log.Debug("同步产成品条码SQL:" + Environment.NewLine + sql);
  21696. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21697. {
  21698. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产订单信息创建失败!");
  21699. }
  21700. if(item.ContainerCode != null && item.ContainerCode.Length > 0)
  21701. {
  21702. string Time = "";
  21703. DateTime dtt;
  21704. DateTime now = DateTime.Now;
  21705. //如果容器不存在直接创建
  21706. string ContainerID = Guid.NewGuid().ToString();
  21707. sql = @"IF NOT EXISTS (SELECT 1 FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}')
  21708. BEGIN
  21709. INSERT INTO dbo.ICSContainer
  21710. ( ID ,ContainerID ,ContainerCODE ,ContainerName,Memo,MTIME,MUSER ,MUSERName ,WorkPoint ,InventoryMixed,ProjectMixed,BatchMixed,Multiplex)
  21711. Values('{3}','','{0}','{4}','',GETDATE(),'{2}','{2}','{1}','1','1','1','1')
  21712. END
  21713. SELECT 1 FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}'";
  21714. sql = string.Format(sql, item.ContainerCode, item.WorkPoint, item.MUSER, ContainerID, item.ContainerName);
  21715. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  21716. if(dt == null || dt.Rows.Count <= 0)
  21717. {
  21718. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo528"), item.ContainerCode));
  21719. }
  21720. sql = @"select 1 FROM ICSContainerLot WHERE LotNo='{0}' AND WorkPoint='{1}'
  21721. ";
  21722. sql = string.Format(sql, item.LotNo, item.WorkPoint);
  21723. DataTable dttte = DBHelper.SQlReturnData(sql, cmd);
  21724. if (dttte.Rows.Count > 0)
  21725. {
  21726. ///修改容器关联表
  21727. sql = @"UPDATE ICSContainerLot SET ContainerID=(SELECT ID FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}' )
  21728. where lotno='{2}' and WorkPoint='{1}'
  21729. ";
  21730. sql = string.Format(sql, item.ContainerCode, item.WorkPoint, item.LotNo);
  21731. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21732. {
  21733. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo525"), item.ContainerCode, item.LotNo));
  21734. }
  21735. }
  21736. else
  21737. {
  21738. sql = @"select 1 from ICSInventoryLot
  21739. where LotNo='{0}' and WorkPoint='{1}'
  21740. ";
  21741. sql = string.Format(sql, item.LotNo, item.WorkPoint);
  21742. DataTable dttaa = DBHelper.SQlReturnData(sql, cmd);
  21743. if (dttaa.Rows.Count > 0)
  21744. {
  21745. ///存入容器条码关联表
  21746. sql = @"INSERT INTO ICSContainerLot(ID,ContainerID,LotNo,MUSER,MUSERName,WorkPoint,MTIME)
  21747. SELECT NEWID(),a.ID,'{3}','{1}','{1}','{2}',GETDATE()
  21748. FROM ICSContainer a
  21749. WHERE a.ContainerCode='{0}' AND WorkPoint='{2}'
  21750. ";
  21751. sql = string.Format(sql, item.ContainerCode, item.MUSER, item.WorkPoint, item.LotNo);
  21752. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21753. {
  21754. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo525"), item.WorkPoint, item.LotNo));
  21755. }
  21756. ///记录日志
  21757. sql = @"INSERT INTO ICSContainerLog(ID,ContainerID,ContainerOrLotNo,Type,MUSER,MUSERName,WorkPoint,MTIME)
  21758. VALUES(NEWID(), (SELECT DISTINCT ID FROM ICSContainer WHERE ContainerCode='{0}'), '{1}', 2, '{2}', (SELECT DISTINCT F_RealName FROM Sys_SRM_User WHERE F_Account='{2}'), '{3}', GETDATE())";
  21759. sql = string.Format(sql, item.ContainerCode, item.LotNo, item.MUSER, item.WorkPoint);
  21760. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21761. {
  21762. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo526"), item.WorkPoint, item.LotNo));
  21763. }
  21764. }
  21765. }
  21766. }
  21767. codes += "'" + item.LotNo + item.WorkPoint + "',";
  21768. }
  21769. #region 查询返回数据
  21770. sql = @"SELECT
  21771. a.TransCode,a.TransSequence,a.LotNo,a.InvCode,a.Quantity,a.MUSER,a.MTIME,a.WorkPoint
  21772. FROM ICSWareHouseLotInfoLog a
  21773. INNER JOIN ICSMO b ON b.MOCode=a.TransCode AND a.TransSequence=b.Sequence AND b.WorkPoint=a.WorkPoint
  21774. WHERE a.Identification='{0}' AND a.LotNo+a.WorkPoint IN ({1})";
  21775. sql = string.Format(sql, Identification, codes.Substring(0, codes.Length - 1));
  21776. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  21777. #endregion
  21778. cmd.Transaction.Commit();
  21779. return data;
  21780. }
  21781. catch (Exception ex)
  21782. {
  21783. if (cmd.Transaction != null)
  21784. cmd.Transaction.Rollback();
  21785. log.Error(ex.Message);
  21786. throw new Exception(ex.Message);
  21787. }
  21788. finally
  21789. {
  21790. if (conn.State == ConnectionState.Open)
  21791. {
  21792. conn.Close();
  21793. }
  21794. conn.Dispose();
  21795. }
  21796. }
  21797. }
  21798. ///// <summary>
  21799. ///// 红字采购入库 新增
  21800. ///// </summary>
  21801. ///// <param name="JsonData"></param>
  21802. ///// <returns></returns>
  21803. ///// <exception cref="Exception"></exception>
  21804. //public static DataTable ICSPurchaseReceiveCreate(List<ICSPurchaseReceive> JsonData)
  21805. //{
  21806. // var language = LanguageHelper.GetName("WMSAPIInfo");
  21807. // if (JsonData.Count <= 0)
  21808. // {
  21809. // throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  21810. // }
  21811. // using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  21812. // {
  21813. // conn.Open();
  21814. // SqlTransaction sqlTran = conn.BeginTransaction();
  21815. // SqlCommand cmd = new SqlCommand();
  21816. // string Colspan = string.Empty;
  21817. // string Sequence = string.Empty;
  21818. // string DNCode = string.Empty;
  21819. // string WorkPoint = string.Empty;
  21820. // string DNCodes = string.Empty;
  21821. // string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  21822. // string IDD = string.Empty;
  21823. // cmd.Transaction = sqlTran;
  21824. // cmd.Connection = conn;
  21825. // cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  21826. // try
  21827. // {
  21828. // string sql = string.Empty;
  21829. // HashSet<string> uniqueItems = new HashSet<string>();
  21830. // foreach (var item in JsonData)
  21831. // {
  21832. // string Code = "";
  21833. // //判断当前录入的总数量是否超过了订单数量
  21834. // //检验自由项
  21835. // Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  21836. // + "~" + item.Brand + "~" + item.cFree1
  21837. // + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  21838. // + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  21839. // + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  21840. // sql = @"select ID,Colspan from ICSExtension a
  21841. // where Colspan='{0}' and WorkPoint='{1}'";
  21842. // sql = string.Format(sql, Colspan, item.WorkPoint);
  21843. // DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  21844. // if (dttt.Rows.Count == 0)
  21845. // {
  21846. // IDD = Guid.NewGuid().ToString();
  21847. // sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  21848. // select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  21849. // sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  21850. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21851. // {
  21852. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  21853. // }
  21854. // }
  21855. // else
  21856. // {
  21857. // IDD = dttt.Rows[0]["ID"].ToString();
  21858. // }
  21859. // sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{10}' AND F_Location='{13}')
  21860. // BEGIN
  21861. // RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{10}") + @"',16,1);
  21862. // RETURN
  21863. // END
  21864. // INSERT INTO [dbo].[ICSPurchaseReceive]
  21865. // ([ID],
  21866. // [RCVCode]
  21867. // ,[Sequence]
  21868. // ,[SourceCode]
  21869. // ,[SourceSequence]
  21870. // ,[InvCode]
  21871. // ,[Quantity]
  21872. // ,[Amount]
  21873. // ,[RCVQuantity]
  21874. // ,[WHCode]
  21875. // ,[Type]
  21876. // ,[Status]
  21877. // ,[CreatePerson]
  21878. // ,[CreateDateTime]
  21879. // ,[RCVID]
  21880. // ,[RCVDetailID]
  21881. // ,[ExtensionID]
  21882. // ,[MUSER]
  21883. // ,[MUSERName]
  21884. // ,[MTIME]
  21885. // ,[WorkPoint])
  21886. // VALUES
  21887. // (NEWID()
  21888. // ,'{0}'
  21889. // ,'{1}'
  21890. // ,'{2}'
  21891. // ,'{3}'
  21892. // ,'{4}'
  21893. // ,{5}
  21894. // ,{6}
  21895. // ,{7}
  21896. // ,'{8}'
  21897. // ,'{9}'
  21898. // ,'1'
  21899. // ,'{10}'
  21900. // ,'{11}'
  21901. // ,''
  21902. // ,''
  21903. // ,'{12}'
  21904. // ,''
  21905. // ,''
  21906. // ,''
  21907. // ,'{13}')";
  21908. // sql = string.Format(sql, item.RCVCode, item.Sequence, item.SourceCode, item.SourceSequence, item.InvCode, item.Quantity, item.Amount,
  21909. // item.RCVQuantity, item.WHCode, item.Type, item.User, Dates, IDD, item.WorkPoint);
  21910. // DNCode = Code;
  21911. // WorkPoint = item.WorkPoint;
  21912. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  21913. // {
  21914. // throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产订单信息创建失败!");
  21915. // }
  21916. // }
  21917. // #region 查询返回数据
  21918. // sql = @"
  21919. // select
  21920. // ID,
  21921. // RCVCode,
  21922. // Sequence,
  21923. // SourceCode,
  21924. // SourceSequence,
  21925. // InvCode,
  21926. // Quantity,
  21927. // Amount,
  21928. // RCVQuantity,
  21929. // WHCode,
  21930. // Type,
  21931. // Status,
  21932. // CreatePerson,
  21933. // CreateDateTime from ICSPurchaseReceive a
  21934. // WHERE a.RCVCode = '{0}' and a.Sequence = '{1}' and a.WorkPoint = '{2}'";
  21935. // sql = string.Format(sql, DNCode, Sequence, WorkPoint);
  21936. // DataTable data = DBHelper.SQlReturnData(sql, cmd);
  21937. // #endregion
  21938. // cmd.Transaction.Commit();
  21939. // return data;
  21940. // }
  21941. // catch (Exception ex)
  21942. // {
  21943. // if (cmd.Transaction != null)
  21944. // cmd.Transaction.Rollback();
  21945. // log.Error(ex.Message);
  21946. // throw new Exception(ex.Message);
  21947. // }
  21948. // finally
  21949. // {
  21950. // if (conn.State == ConnectionState.Open)
  21951. // {
  21952. // conn.Close();
  21953. // }
  21954. // conn.Dispose();
  21955. // }
  21956. // }
  21957. //}
  21958. ///// <summary>
  21959. ///// 红字采购入库 修改
  21960. ///// </summary>
  21961. ///// <param name="JsonData"></param>
  21962. ///// <returns></returns>
  21963. //public static DataTable ICSPurchaseReceiveUpdate(List<ICSPurchaseReceive> JsonData)
  21964. //{
  21965. // var language = LanguageHelper.GetName("WMSAPIInfo");
  21966. // if (JsonData.Count <= 0)
  21967. // {
  21968. // throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  21969. // }
  21970. // using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  21971. // {
  21972. // conn.Open();
  21973. // SqlTransaction sqlTran = conn.BeginTransaction();
  21974. // SqlCommand cmd = new SqlCommand();
  21975. // cmd.Transaction = sqlTran;
  21976. // cmd.Connection = conn;
  21977. // cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  21978. // try
  21979. // {
  21980. // string sql = string.Empty;
  21981. // string Checksql = string.Empty;
  21982. // string Sequence = string.Empty;
  21983. // string DNCode = string.Empty;
  21984. // string WorkPoint = string.Empty;
  21985. // string Dates = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  21986. // string Colspan = string.Empty;
  21987. // string IDD = string.Empty;
  21988. // foreach (var item in JsonData)
  21989. // {
  21990. // //检验自由项
  21991. // Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  21992. // + "~" + item.Brand + "~" + item.cFree1
  21993. // + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  21994. // + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  21995. // + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  21996. // sql = @"select ID,Colspan from ICSExtension a
  21997. // where Colspan='{0}' and WorkPoint='{1}'";
  21998. // sql = string.Format(sql, Colspan, item.WorkPoint);
  21999. // DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  22000. // if (dttt.Rows.Count == 0)
  22001. // {
  22002. // IDD = Guid.NewGuid().ToString();
  22003. // sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  22004. // select '{17}','{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}',GETDATE(),'{15}',f.F_RealName,'{16}'from Sys_SRM_User f where f.F_Account='{15}' and f.F_Location='{16}'";
  22005. // sql = string.Format(sql, Colspan, item.ProjectCode, item.BatchCode, item.Version, item.Brand, item.cFree1, item.cFree2, item.cFree3, item.cFree4, item.cFree5, item.cFree6, item.cFree7, item.cFree8, item.cFree9, item.cFree10, item.User, item.WorkPoint, IDD);
  22006. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  22007. // {
  22008. // throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  22009. // }
  22010. // }
  22011. // else
  22012. // {
  22013. // IDD = dttt.Rows[0]["ID"].ToString();
  22014. // }
  22015. // //[MUSERName] = (select F_RealName from Sys_SRM_User where F_Account='{5}' and F_Location='{6}')
  22016. // sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{6}' AND F_Location='{7}')
  22017. // BEGIN
  22018. // RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{6}") + @"',16,1);
  22019. // RETURN
  22020. // END
  22021. // UPDATE [dbo].[ICSPurchaseReceive]
  22022. // SET [InvCode] = '{0}'
  22023. // ,[Quantity] = {1}
  22024. // ,[Amount] = {2}
  22025. // ,[WHCode] = '{3}'
  22026. // ,[Type] = '{4}'
  22027. // ,[ExtensionID] = '{5}'
  22028. // ,[MUSER] = '{6}'
  22029. // ,[MUSERName] = (select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{7}')
  22030. // ,[MTIME] = '{8}'
  22031. // where ID = '{9}'";
  22032. // sql = string.Format(sql, item.InvCode, item.Quantity, item.Amount, item.WHCode, item.Type, IDD, item.User, item.WorkPoint, Dates, item.ID);
  22033. // DNCode = item.RCVCode;
  22034. // Sequence = item.Sequence;
  22035. // WorkPoint = item.WorkPoint;
  22036. // if (!DBHelper.ExecuteNonQuery(sql, cmd))
  22037. // {
  22038. // throw new Exception(language.GetNameByCode("WMSOur0004"));//"修改失败!");
  22039. // }
  22040. // //修改委外订单的入库数量
  22041. // }
  22042. // #region 查询返回数据
  22043. // sql = @"
  22044. // select
  22045. // ID,
  22046. // RCVCode,
  22047. // Sequence,
  22048. // SourceCode,
  22049. // SourceSequence,
  22050. // InvCode,
  22051. // Quantity,
  22052. // Amount,
  22053. // RCVQuantity,
  22054. // WHCode,
  22055. // Type,
  22056. // Status,
  22057. // CreatePerson,
  22058. // CreateDateTime from ICSPurchaseReceive a
  22059. // WHERE a.RCVCode = '{0}' and a.Sequence = '{1}' and a.WorkPoint = '{2}'";
  22060. // sql = string.Format(sql, DNCode, Sequence, WorkPoint);
  22061. // DataTable data = DBHelper.SQlReturnData(sql, cmd);
  22062. // #endregion
  22063. // cmd.Transaction.Commit();
  22064. // return data;
  22065. // }
  22066. // catch (Exception ex)
  22067. // {
  22068. // if (cmd.Transaction != null)
  22069. // cmd.Transaction.Rollback();
  22070. // log.Error(ex.Message);
  22071. // throw new Exception(ex.Message);
  22072. // }
  22073. // finally
  22074. // {
  22075. // if (conn.State == ConnectionState.Open)
  22076. // {
  22077. // conn.Close();
  22078. // }
  22079. // conn.Dispose();
  22080. // }
  22081. // }
  22082. //}
  22083. /// <summary>
  22084. /// 产成品退库 调用erp接口(铭锋)
  22085. /// </summary>
  22086. /// <param name="JsonData"></param>
  22087. /// <returns></returns>
  22088. /// <exception cref="Exception"></exception>
  22089. public static ResultModel1 ErpApprove(List<ApproveInput> JsonData)
  22090. {
  22091. var language = LanguageHelper.GetName("WMSAPIInfo");
  22092. ResultModel1 results = new ResultModel1();
  22093. if (JsonData.Count <= 0)
  22094. {
  22095. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  22096. }
  22097. string Inputstr = JsonConvert.SerializeObject(JsonData);
  22098. try
  22099. {
  22100. string resultStr = HTTPHelper.HttpPost("产成品退库", ERPUrl.Rd1011Approve, Inputstr);
  22101. Result result = new Result();
  22102. result = JsonConvert.DeserializeObject<Result>(resultStr);
  22103. if (result.Success)
  22104. {
  22105. results.Success = true;
  22106. }
  22107. else
  22108. {
  22109. results.Success = false;
  22110. results.Message = result.Message;
  22111. }
  22112. return results;
  22113. }
  22114. catch (Exception ex)
  22115. {
  22116. log.Debug(ex.ToString());
  22117. throw new Exception("调用接口出现错误。"+ex.Message);
  22118. }
  22119. }
  22120. #region 领料出库条码(东辉专用)
  22121. /// <summary>
  22122. /// 领料出库条码(东辉专用)
  22123. /// </summary>
  22124. /// <param name="JsonData"></param>
  22125. /// <returns></returns>
  22126. public static ResultModel GetOutWarehouseBarcode(OutWarehouseBarCodeModel JsonData)
  22127. {
  22128. var language = LanguageHelper.GetName("WMSAPIInfo");
  22129. DataTable table = new DataTable();
  22130. DataTable ZLtable = new DataTable();
  22131. ResultModel result = new ResultModel();
  22132. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  22133. {
  22134. conn.Open();
  22135. SqlCommand cmd = new SqlCommand();
  22136. cmd.Connection = conn;
  22137. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  22138. try
  22139. {
  22140. //获取工单和超额领料单数据
  22141. string sql = $@"SELECT DISTINCT a.WorkPoint dataAuth,a.TransCode docNO,b.InvCode PitemCode,a.LotNo barCode,a.Quantity as outStockQty,c.InvCode as itemCode,a.MTIME createTime,a.MUSERName createUser,b.MOCode moNumber ,e.BatchCode FLOT,'1' as doctype ,c.Quantity as planQty
  22142. FROM ICSMO b
  22143. inner JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint
  22144. inner JOIN ICSWareHouseLotInfoLog a ON a.TransCode=b.MOCode AND b.WorkPoint=a.WorkPoint AND a.TransSequence=(b.Sequence+'~'+c.Sequence)
  22145. inner JOIN ICSInventoryLot d ON a.LotNo=d.LotNo AND a.WorkPoint=d.WorkPoint
  22146. inner JOIN ICSExtension e ON d.ExtensionID=e.ID
  22147. WHERE a.BusinessCode='13' AND a.MTIME >='{JsonData.Date}'
  22148. UNION ALL
  22149. SELECT DISTINCT a.WorkPoint dataAuth,a.TransCode docNO,b.InvCode PitemCode,a.LotNo barCode,a.Quantity as outStockQty,f.InvCode as itemCode,a.MTIME createTime,a.MUSERName createUser,b.MOCode moNumber,e.BatchCode FLOT,'2' as doctype ,c.Quantity as planQty
  22150. FROM ICSWareHouseLotInfoLog a
  22151. inner JOIN ICSMOIssue c ON c.IssueCode=a.TransCode AND a.WorkPoint=c.WorkPoint AND a.TransSequence=c.Sequence
  22152. inner JOIN ICSMO b ON c.SourceCode=b.MOCode AND b.WorkPoint=a.WorkPoint
  22153. inner JOIN ICSMOPick f ON f.MODetailID=b.MODetailID
  22154. inner JOIN ICSInventoryLot d ON a.LotNo=d.LotNo AND a.WorkPoint=d.WorkPoint
  22155. inner JOIN ICSExtension e ON d.ExtensionID=e.ID
  22156. WHERE a.BusinessCode='15' AND a.MTIME >='{JsonData.Date}'";
  22157. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  22158. string sql2 = $@"SELECT DISTINCT a.WorkPoint dataAuth,a.TransCode docNO,b.MOCode moNumber ,'1' as doctype
  22159. FROM ICSMO b
  22160. inner JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint
  22161. inner JOIN ICSWareHouseLotInfoLog a ON a.TransCode=b.MOCode AND b.WorkPoint=a.WorkPoint AND a.TransSequence=(b.Sequence+'~'+c.Sequence)
  22162. inner JOIN ICSInventoryLot d ON a.LotNo=d.LotNo AND a.WorkPoint=d.WorkPoint
  22163. inner JOIN ICSExtension e ON d.ExtensionID=e.ID
  22164. WHERE a.BusinessCode='13' AND a.MTIME >='{JsonData.Date}'
  22165. UNION ALL
  22166. SELECT DISTINCT a.WorkPoint dataAuth,a.TransCode docNO,b.MOCode moNumber,'2' as doctype
  22167. FROM ICSWareHouseLotInfoLog a
  22168. inner JOIN ICSMOIssue c ON c.IssueCode=a.TransCode AND a.WorkPoint=c.WorkPoint AND a.TransSequence=c.Sequence
  22169. inner JOIN ICSMO b ON c.SourceCode=b.MOCode AND b.WorkPoint=a.WorkPoint
  22170. inner JOIN ICSMOPick f ON f.MODetailID=b.MODetailID
  22171. inner JOIN ICSInventoryLot d ON a.LotNo=d.LotNo AND a.WorkPoint=d.WorkPoint
  22172. inner JOIN ICSExtension e ON d.ExtensionID=e.ID
  22173. WHERE a.BusinessCode='15' AND a.MTIME >='{JsonData.Date}'";
  22174. DataTable dt2 = DBHelper.SQlReturnData(sql2, cmd);
  22175. string sql3 = $@"SELECT DISTINCT a.WorkPoint dataAuth,a.TransCode docNO,b.MOCode moNumber ,'1' as doctype ,b.InvCode PitemCode
  22176. FROM ICSMO b
  22177. inner JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint
  22178. inner JOIN ICSWareHouseLotInfoLog a ON a.TransCode=b.MOCode AND b.WorkPoint=a.WorkPoint AND a.TransSequence=(b.Sequence+'~'+c.Sequence)
  22179. inner JOIN ICSInventoryLot d ON a.LotNo=d.LotNo AND a.WorkPoint=d.WorkPoint
  22180. inner JOIN ICSExtension e ON d.ExtensionID=e.ID
  22181. WHERE a.BusinessCode='13' AND a.MTIME >='{JsonData.Date}'
  22182. UNION ALL
  22183. SELECT DISTINCT a.WorkPoint dataAuth,a.TransCode docNO,b.MOCode moNumber,'2' as doctype ,b.InvCode PitemCode
  22184. FROM ICSWareHouseLotInfoLog a
  22185. inner JOIN ICSMOIssue c ON c.IssueCode=a.TransCode AND a.WorkPoint=c.WorkPoint AND a.TransSequence=c.Sequence
  22186. inner JOIN ICSMO b ON c.SourceCode=b.MOCode AND b.WorkPoint=a.WorkPoint
  22187. inner JOIN ICSMOPick f ON f.MODetailID=b.MODetailID
  22188. inner JOIN ICSInventoryLot d ON a.LotNo=d.LotNo AND a.WorkPoint=d.WorkPoint
  22189. inner JOIN ICSExtension e ON d.ExtensionID=e.ID
  22190. WHERE a.BusinessCode='15' AND a.MTIME >='{JsonData.Date}'";
  22191. DataTable dt3 = DBHelper.SQlReturnData(sql3, cmd);
  22192. string sql4 = $@"SELECT DISTINCT a.WorkPoint dataAuth,a.TransCode docNO,b.MOCode moNumber ,'1' as doctype ,b.InvCode PitemCode,c.InvCode as itemCode,c.Quantity as planQty
  22193. FROM ICSMO b
  22194. inner JOIN ICSMOPick c ON b.MODetailID=c.MODetailID AND b.WorkPoint=c.WorkPoint
  22195. inner JOIN ICSWareHouseLotInfoLog a ON a.TransCode=b.MOCode AND b.WorkPoint=a.WorkPoint AND a.TransSequence=(b.Sequence+'~'+c.Sequence)
  22196. inner JOIN ICSInventoryLot d ON a.LotNo=d.LotNo AND a.WorkPoint=d.WorkPoint
  22197. inner JOIN ICSExtension e ON d.ExtensionID=e.ID
  22198. WHERE a.BusinessCode='13' AND a.MTIME >='{JsonData.Date}'
  22199. UNION ALL
  22200. SELECT DISTINCT a.WorkPoint dataAuth,a.TransCode docNO,b.MOCode moNumber,'2' as doctype ,b.InvCode PitemCode,c.InvCode as itemCode,c.Quantity as planQty
  22201. FROM ICSWareHouseLotInfoLog a
  22202. inner JOIN ICSMOIssue c ON c.IssueCode=a.TransCode AND a.WorkPoint=c.WorkPoint AND a.TransSequence=c.Sequence
  22203. inner JOIN ICSMO b ON c.SourceCode=b.MOCode AND b.WorkPoint=a.WorkPoint
  22204. inner JOIN ICSMOPick f ON f.MODetailID=b.MODetailID
  22205. inner JOIN ICSInventoryLot d ON a.LotNo=d.LotNo AND a.WorkPoint=d.WorkPoint
  22206. inner JOIN ICSExtension e ON d.ExtensionID=e.ID
  22207. WHERE a.BusinessCode='15' AND a.MTIME >='{JsonData.Date}'";
  22208. DataTable dt4 = DBHelper.SQlReturnData(sql4, cmd);
  22209. result.CodeList = new List<CodeList>();
  22210. if (dt2.Rows.Count > 0)
  22211. {
  22212. for (int i = 0; i < dt2.Rows.Count; i++)
  22213. {
  22214. List<PitemCodeList> pitemCodeLists = new List<PitemCodeList>();
  22215. string a = $"dataAuth='{dt2.Rows[i]["dataAuth"]}' and docNO = '{dt2.Rows[i]["docNO"]}' and moNumber = '{dt2.Rows[i]["moNumber"]}' and doctype = '{dt2.Rows[i]["doctype"]}' ";
  22216. var pitemCode = dt3.Select(a).Distinct();
  22217. foreach (DataRow row in pitemCode)
  22218. {
  22219. List<ItemCodeList> itemCodeLists = new List<ItemCodeList>();
  22220. var itemCodes = dt4.Select($"dataAuth='{dt2.Rows[i]["dataAuth"]}' and docNO = '{dt2.Rows[i]["docNO"]}' and moNumber = '{dt2.Rows[i]["moNumber"]}' and doctype = '{dt2.Rows[i]["doctype"]}' and PitemCode = '{row["PitemCode"]}'").Distinct();
  22221. foreach (DataRow itemrow in itemCodes)
  22222. {
  22223. List<LotNoList> lotNoLists = new List<LotNoList>();
  22224. var lotCodes = dt.Select($"dataAuth='{dt2.Rows[i]["dataAuth"]}' and docNO = '{dt2.Rows[i]["docNO"]}' and moNumber = '{dt2.Rows[i]["moNumber"]}' and doctype = '{dt2.Rows[i]["doctype"]}' and PitemCode = '{row["PitemCode"]}' and itemCode = '{itemrow["itemCode"]}'").Distinct();
  22225. foreach (DataRow lotrow in lotCodes)
  22226. {
  22227. LotNoList lotNoList = new LotNoList
  22228. {
  22229. barCode = lotrow["barCode"].ToString(),
  22230. outStockQty = Convert.ToDecimal(lotrow["outStockQty"].ToString()),
  22231. FLOT = lotrow["FLOT"].ToString(),
  22232. createTime = Convert.ToDateTime(lotrow["createTime"].ToString()),
  22233. createUser= lotrow["createUser"].ToString()
  22234. };
  22235. lotNoLists.Add(lotNoList);
  22236. }
  22237. ItemCodeList itemCodeList = new ItemCodeList
  22238. {
  22239. itemCode = itemrow["itemCode"].ToString(),
  22240. planQty = Convert.ToDecimal(itemrow["planQty"].ToString()),
  22241. LotNoList= lotNoLists
  22242. };
  22243. itemCodeLists.Add(itemCodeList);
  22244. }
  22245. PitemCodeList pitemCodeList = new PitemCodeList
  22246. {
  22247. PitemCode = row["PitemCode"].ToString(),
  22248. itemCodeList = itemCodeLists
  22249. };
  22250. pitemCodeLists.Add(pitemCodeList);
  22251. }
  22252. CodeList codeList = new CodeList
  22253. {
  22254. dataAuth = dt2.Rows[i]["dataAuth"].ToString(),
  22255. docNO = dt2.Rows[i]["docNO"].ToString(),
  22256. moNumber = dt2.Rows[i]["moNumber"].ToString(),
  22257. doctype = dt2.Rows[i]["doctype"].ToString(),
  22258. PitemCodeList = pitemCodeLists
  22259. };
  22260. result.CodeList.Add(codeList);
  22261. }
  22262. }
  22263. return result;
  22264. }
  22265. catch (Exception ex)
  22266. {
  22267. log.Error(ex.Message);
  22268. throw new Exception(ex.Message);
  22269. }
  22270. finally
  22271. {
  22272. if (conn.State == ConnectionState.Open)
  22273. {
  22274. conn.Close();
  22275. }
  22276. conn.Dispose();
  22277. }
  22278. }
  22279. }
  22280. #endregion
  22281. #region 生产退料单接口(东辉专用)
  22282. /// <summary>
  22283. /// 生产退料单接口(东辉专用)
  22284. /// </summary>
  22285. /// <param name="JsonData"></param>
  22286. /// <returns></returns>
  22287. public static ResultModel1 GetProductionRejectionDoc(ProductionRejectionModel JsonData)
  22288. {
  22289. var language = LanguageHelper.GetName("WMSAPIInfo");
  22290. ResultModel1 result = new ResultModel1();
  22291. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  22292. {
  22293. conn.Open();
  22294. SqlCommand cmd = new SqlCommand();
  22295. cmd.Connection = conn;
  22296. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  22297. try
  22298. {
  22299. //获取工单和超额领料单数据
  22300. string sql = $@"SELECT DISTINCT a.WorkPoint dataAuth,b.ApplyNegCode docNo,d.InvCode PitemCode,e.InvCode itemCode,b.IssueNegQuantity actQty,d.MOCode moNumber,a.MTIME createTime,a.MUSERName createUser,'1' doctype FROM ICSWareHouseLotInfoLog a
  22301. INNER JOIN ICSMOApplyNegDetail b ON a.TransCode=b.ApplyNegCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  22302. INNER JOIN ICSMOIssue c ON b.SourceDetailID=c.IssueDetailID AND b.WorkPoint=c.WorkPoint
  22303. INNER JOIN ICSMO d ON c.SourceCode=d.MOCode AND c.WorkPoint=d.WorkPoint
  22304. INNER JOIN ICSMOPick e ON d.MODetailID=e.MODetailID AND e.WorkPoint=d.WorkPoint AND e.InvCode=a.InvCode
  22305. WHERE
  22306. a.BusinessCode='16-1' AND a.MTIME>='{JsonData.Date}'";
  22307. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  22308. string sql2 = $@"SELECT DISTINCT a.WorkPoint dataAuth,b.ApplyNegCode docNo,d.MOCode moNumber,'1' doctype
  22309. FROM ICSWareHouseLotInfoLog a
  22310. INNER JOIN ICSMOApplyNegDetail b ON a.TransCode=b.ApplyNegCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  22311. INNER JOIN ICSMOIssue c ON b.SourceDetailID=c.IssueDetailID AND b.WorkPoint=c.WorkPoint
  22312. INNER JOIN ICSMO d ON c.SourceCode=d.MOCode AND c.WorkPoint=d.WorkPoint
  22313. INNER JOIN ICSMOPick e ON d.MODetailID=e.MODetailID AND e.WorkPoint=d.WorkPoint AND e.InvCode=a.InvCode
  22314. WHERE
  22315. a.BusinessCode='16-1' AND a.MTIME>='{JsonData.Date}'";
  22316. DataTable dt2 = DBHelper.SQlReturnData(sql2, cmd);
  22317. string sql3 = $@"SELECT DISTINCT a.WorkPoint dataAuth,b.ApplyNegCode docNo,d.InvCode PitemCode,d.MOCode moNumber,'1' doctype FROM ICSWareHouseLotInfoLog a
  22318. INNER JOIN ICSMOApplyNegDetail b ON a.TransCode=b.ApplyNegCode AND a.TransSequence=b.Sequence AND a.WorkPoint=b.WorkPoint
  22319. INNER JOIN ICSMOIssue c ON b.SourceDetailID=c.IssueDetailID AND b.WorkPoint=c.WorkPoint
  22320. INNER JOIN ICSMO d ON c.SourceCode=d.MOCode AND c.WorkPoint=d.WorkPoint
  22321. INNER JOIN ICSMOPick e ON d.MODetailID=e.MODetailID AND e.WorkPoint=d.WorkPoint AND e.InvCode=a.InvCode
  22322. WHERE
  22323. a.BusinessCode='16-1' AND a.MTIME>='{JsonData.Date}'";
  22324. DataTable dt3 = DBHelper.SQlReturnData(sql3, cmd);
  22325. result.CodeList = new List<CodeList1>();
  22326. if (dt2.Rows.Count > 0)
  22327. {
  22328. for (int i = 0; i < dt2.Rows.Count; i++)
  22329. {
  22330. List<PitemCodeList1> pitemCodeLists = new List<PitemCodeList1>();
  22331. string a = $"dataAuth='{dt3.Rows[i]["dataAuth"]}' and docNO = '{dt2.Rows[i]["docNO"]}' and moNumber = '{dt2.Rows[i]["moNumber"]}' and doctype = '{dt2.Rows[i]["doctype"]}' ";
  22332. var pitemCode = dt3.Select(a).Distinct();
  22333. foreach (DataRow row in pitemCode)
  22334. {
  22335. List<ItemCodeList1> itemCodeLists = new List<ItemCodeList1>();
  22336. var itemCodes = dt.Select($"dataAuth='{dt2.Rows[i]["dataAuth"]}' and docNO = '{dt2.Rows[i]["docNO"]}' and moNumber = '{dt2.Rows[i]["moNumber"]}' and doctype = '{dt2.Rows[i]["doctype"]}' and PitemCode = '{row["PitemCode"]}'").Distinct();
  22337. foreach (DataRow itemrow in itemCodes)
  22338. {
  22339. ItemCodeList1 itemCodeList = new ItemCodeList1
  22340. {
  22341. itemCode = itemrow["itemCode"].ToString(),
  22342. actQty = Convert.ToDecimal(itemrow["actQty"].ToString()),
  22343. createTime = Convert.ToDateTime(itemrow["createTime"].ToString()),
  22344. createUser = itemrow["createUser"].ToString()
  22345. };
  22346. itemCodeLists.Add(itemCodeList);
  22347. }
  22348. PitemCodeList1 pitemCodeList = new PitemCodeList1
  22349. {
  22350. PitemCode = row["PitemCode"].ToString(),
  22351. itemCodeList = itemCodeLists
  22352. };
  22353. pitemCodeLists.Add(pitemCodeList);
  22354. }
  22355. CodeList1 codeList = new CodeList1
  22356. {
  22357. dataAuth = dt2.Rows[i]["dataAuth"].ToString(),
  22358. docNO = dt2.Rows[i]["docNO"].ToString(),
  22359. moNumber = dt2.Rows[i]["moNumber"].ToString(),
  22360. PitemCodeList = pitemCodeLists
  22361. };
  22362. result.CodeList.Add(codeList);
  22363. }
  22364. }
  22365. return result;
  22366. }
  22367. catch (Exception ex)
  22368. {
  22369. log.Error(ex.Message);
  22370. throw new Exception(ex.Message);
  22371. }
  22372. finally
  22373. {
  22374. if (conn.State == ConnectionState.Open)
  22375. {
  22376. conn.Close();
  22377. }
  22378. conn.Dispose();
  22379. }
  22380. }
  22381. }
  22382. #endregion
  22383. public static DataTable ICSMaterialSearchGet(BarCodeModel JsonData)
  22384. {
  22385. var language = LanguageHelper.GetName("WMSAPIInfo");
  22386. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  22387. {
  22388. conn.Open();
  22389. SqlTransaction sqlTran = conn.BeginTransaction();
  22390. SqlCommand cmd = new SqlCommand();
  22391. string Colspan = string.Empty;
  22392. string IDD = string.Empty;
  22393. cmd.Transaction = sqlTran;
  22394. cmd.Connection = conn;
  22395. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  22396. try
  22397. {
  22398. string sql = @"SELECT
  22399. inv.InvCode,inv.InvName,lot.LotNo,fo.Quantity,lo.LocationCode,lo.LocationName,wa.WarehouseCode,wa.WarehouseName
  22400. FROM ICSInventory inv
  22401. INNER JOIN ICSInventoryLot lot ON lot.InvCode=inv.InvCode AND lot.WorkPoint=inv.WorkPoint
  22402. INNER JOIN ICSWareHouseLotInfo fo ON fo.LotNo=lot.LotNo AND fo.WorkPoint=lot.WorkPoint
  22403. LEFT JOIN ICSWarehouse wa ON wa.WarehouseCode=fo.WarehouseCode AND wa.WorkPoint=fo.WorkPoint
  22404. LEFT JOIN ICSLocation lo ON lo.LocationCode=fo.LocationCode AND lo.WorkPoint=fo.WorkPoint
  22405. WHERE inv.InvCode='{0}' AND inv.WorkPoint='{1}'";
  22406. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  22407. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  22408. cmd.Transaction.Commit();
  22409. return data;
  22410. }
  22411. catch (Exception ex)
  22412. {
  22413. if (cmd.Transaction != null)
  22414. cmd.Transaction.Rollback();
  22415. log.Error(ex.Message);
  22416. throw new Exception(ex.Message);
  22417. }
  22418. finally
  22419. {
  22420. if (conn.State == ConnectionState.Open)
  22421. {
  22422. conn.Close();
  22423. }
  22424. conn.Dispose();
  22425. }
  22426. }
  22427. }
  22428. #region 销售出货单绑定快递单号
  22429. public static DataTable SalesBindCourierGet(BarCodeModel JsonData)
  22430. {
  22431. var language = LanguageHelper.GetName("WMSAPIInfo");
  22432. if (JsonData == null)
  22433. {
  22434. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  22435. }
  22436. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  22437. {
  22438. conn.Open();
  22439. SqlTransaction sqlTran = conn.BeginTransaction();
  22440. SqlCommand cmd = new SqlCommand();
  22441. cmd.Transaction = sqlTran;
  22442. cmd.Connection = conn;
  22443. try
  22444. {
  22445. string TransType = string.Empty;
  22446. string sql = @"UPDATE ICSSDN SET EATTRIBUTE3='{2}' WHERE SDNCode='{0}' AND WorkPoint='{1}' AND Type='1'";
  22447. sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint, JsonData.Code);
  22448. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  22449. cmd.Transaction.Commit();
  22450. return table;
  22451. }
  22452. catch (Exception ex)
  22453. {
  22454. if (cmd.Transaction != null)
  22455. cmd.Transaction.Rollback();
  22456. log.Error(ex.Message);
  22457. throw new Exception(ex.Message);
  22458. }
  22459. finally
  22460. {
  22461. if (conn.State == ConnectionState.Open)
  22462. {
  22463. conn.Close();
  22464. }
  22465. conn.Dispose();
  22466. }
  22467. }
  22468. }
  22469. #endregion
  22470. }
  22471. }