17886 lines
1.0 MiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using NFine.Code;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 提交业务处理
  18. /// </summary>
  19. public class ICSSubmitService
  20. {
  21. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  22. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  23. private static string enableCode = "";
  24. private static string excessQtySql = "";
  25. #region 源头单据信息
  26. /// <summary>
  27. /// 源头单据信息
  28. /// </summary>
  29. /// <param name="JsonData"></param>
  30. /// <returns></returns>
  31. public static DataTable TransInformationGet(WMSSourceDocumentModel JsonData)
  32. {
  33. var language = LanguageHelper.GetName("WMSAPIInfo");
  34. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  35. {
  36. conn.Open();
  37. string sql = string.Empty;
  38. SqlCommand cmd = new SqlCommand();
  39. cmd.Connection = conn;
  40. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  41. try
  42. {
  43. if (string.IsNullOrEmpty(JsonData.TransCode))
  44. {
  45. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  46. }
  47. else if (string.IsNullOrEmpty(JsonData.TransType))
  48. {
  49. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  50. }
  51. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  52. {
  53. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  54. }
  55. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  56. {
  57. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  58. }
  59. string TransType = JsonData.TransType;
  60. #region SLQ
  61. string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  62. BEGIN
  63. RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  64. RETURN
  65. END
  66. ";
  67. if (TransType == TransTypeEnum.ASN.GetDescription()|| TransType == TransTypeEnum.OASN.GetDescription())
  68. {
  69. sql = @"SELECT a.ID,
  70. {0}
  71. convert(varchar(100),'') AS LocationCode,
  72. convert(varchar(100),'') AS LotNo,
  73. convert(varchar(10),'') AS ToWarehouseCode,
  74. 0 AS LocationQty,
  75. 0 AS isMatched,
  76. a.InvCode,
  77. inv.InvName,
  78. inv.InvStd,
  79. a.Quantity,
  80. inv.InvUnit,
  81. a.Amount,
  82. --a.WHCode,
  83. inv.AmountUnit,
  84. --wh.WarehouseName AS WHName,
  85. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  86. a.ExtensionID,
  87. --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,
  88. ISNULL(ext.Version, '') AS Version,
  89. ISNULL(ext.Brand, '') AS Brand,
  90. ISNULL(ext.cFree1, '') AS cFree1,
  91. ISNULL(ext.cFree2, '') AS cFree2,
  92. ISNULL(ext.cFree3, '') AS cFree3,
  93. ISNULL(ext.cFree4, '') AS cFree4,
  94. ISNULL(ext.cFree5, '') AS cFree5,
  95. ISNULL(ext.cFree6, '') AS cFree6,
  96. ISNULL(ext.cFree7, '') AS cFree7,
  97. ISNULL(ext.cFree8, '') AS cFree8,
  98. ISNULL(ext.cFree9, '') AS cFree9,
  99. ISNULL(ext.cFree10, '') AS cFree10,
  100. a.MUSER AS [User],
  101. a.MTIME AS [MTime]
  102. {4}
  103. FROM {1}
  104. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  105. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  106. --LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  107. --LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  108. WHERE {2} ";
  109. }
  110. else
  111. {
  112. sql = @"SELECT a.ID,
  113. {0}
  114. convert(varchar(100),'') AS LocationCode,
  115. convert(varchar(100),'') AS LotNo,
  116. convert(varchar(10),'') AS ToWarehouseCode,
  117. 0 AS LocationQty,
  118. 0 AS isMatched,
  119. a.InvCode,
  120. inv.InvName,
  121. inv.InvStd,
  122. a.Quantity,
  123. inv.InvUnit,
  124. a.Amount,
  125. a.WHCode,
  126. inv.AmountUnit,
  127. wh.WarehouseName AS WHName,
  128. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  129. a.ExtensionID,
  130. 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,
  131. ISNULL(ext.Version, '') AS Version,
  132. ISNULL(ext.Brand, '') AS Brand,
  133. ISNULL(ext.cFree1, '') AS cFree1,
  134. ISNULL(ext.cFree2, '') AS cFree2,
  135. ISNULL(ext.cFree3, '') AS cFree3,
  136. ISNULL(ext.cFree4, '') AS cFree4,
  137. ISNULL(ext.cFree5, '') AS cFree5,
  138. ISNULL(ext.cFree6, '') AS cFree6,
  139. ISNULL(ext.cFree7, '') AS cFree7,
  140. ISNULL(ext.cFree8, '') AS cFree8,
  141. ISNULL(ext.cFree9, '') AS cFree9,
  142. ISNULL(ext.cFree10, '') AS cFree10,
  143. a.MUSER AS [User],
  144. a.MTIME AS [MTime]
  145. {4}
  146. FROM {1}
  147. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  148. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  149. LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  150. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  151. WHERE {2} ";
  152. }
  153. string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  154. c.Code,
  155. c.InvCode,
  156. c.InvName,
  157. c.InvStd,
  158. c.InvUnit,
  159. FLOOR(c.iQuantity) AS iQuantity,
  160. d.WarehouseCode,
  161. d.LocationCode,
  162. d.LotNO,
  163. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  164. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  165. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  166. FROM
  167. ({0}) c
  168. 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
  169. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  170. 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
  171. DECLARE @ItemCode VARCHAR(50),
  172. @QTY DECIMAL(18,3),
  173. @ItemCodeCurrent VARCHAR(50),
  174. @QTYCurrent DECIMAL(18,3),
  175. @iQuantityCurrent DECIMAL(18,3),
  176. @CanDelete BIT,
  177. @Row INT,
  178. @rowCurrent INT
  179. SET @Row = @@rowcount
  180. SET @rowCurrent=1
  181. SET @CanDelete=0
  182. SET @ItemCode=''
  183. WHILE @rowCurrent<=@Row
  184. BEGIN
  185. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  186. PRINT(@rowCurrent)
  187. IF @ItemCode<>@ItemCodeCurrent
  188. BEGIN
  189. SET @ItemCode=@ItemCodeCurrent
  190. SET @QTY=0
  191. SET @CanDelete=0
  192. END
  193. IF @CanDelete=1
  194. BEGIN
  195. DELETE FROM #temp WHERE rowNo=@rowCurrent
  196. SET @rowCurrent += 1
  197. CONTINUE
  198. END
  199. SET @QTY += @QTYCurrent
  200. IF @QTY>=@iQuantityCurrent
  201. BEGIN
  202. SET @CanDelete=1
  203. END
  204. SET @rowCurrent += 1
  205. END
  206. SELECT * FROM #temp
  207. DROP TABLE #temp
  208. ";
  209. #endregion
  210. bool isDeliveryNotice = false; //送货、到货、含委外
  211. string columns = string.Empty; //查询源头单据表的特殊列名
  212. string tableName = string.Empty; //查询源头单据表名
  213. string where = string.Empty; //查询源头单据的过滤条件
  214. bool isMerge = false; //合并发料
  215. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  216. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  217. string sqls= string.Empty;
  218. string sqlCheckSign = "";
  219. DataTable flag =null;
  220. #region 检料表信息
  221. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  222. {
  223. enableCode = "Over001";
  224. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, b.Sequence+'~'+a.Sequence, b.MOCode, a.WorkPoint,'"+enableCode+"')) AS excessQty";
  225. #region 工单备料sql
  226. sqls = @" SELECT
  227. c.MOCode as Code,
  228. a.InvCode,
  229. b.InvName,
  230. b.InvStd,
  231. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  232. a.WhCode,
  233. b.InvUnit,
  234. a.ExtensionID
  235. FROM
  236. ICSMOPick a
  237. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  238. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  239. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  240. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  241. #endregion
  242. }
  243. if (TransType == TransTypeEnum.MOApply.GetDescription())
  244. {
  245. enableCode = "Over002";
  246. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Sequence, a.ApplyCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  247. #region 工单领料SQL
  248. sqls = @" select
  249. a.ApplyCode as Code,
  250. a.InvCode,
  251. b.InvName,
  252. b.InvStd,
  253. b.InvUnit,
  254. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  255. a.WhCode,
  256. a.ExtensionID
  257. FROM
  258. ICSMOApply a
  259. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  260. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  261. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  262. #endregion
  263. }
  264. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  265. {
  266. //enableCode = "Over003";
  267. excessQtySql = "";
  268. #region 工单材料出库SQL
  269. sqls = @" select
  270. a.IssueCode as Code,
  271. a.InvCode,
  272. b.InvName,
  273. b.InvStd,
  274. b.InvUnit,
  275. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  276. a.WhCode,
  277. a.ExtensionID
  278. FROM
  279. ICSMOIssue a
  280. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  281. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  282. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  283. #endregion
  284. }
  285. if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  286. {
  287. enableCode = "Over004";
  288. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, b.Sequence+'~'+a.Sequence, b.OOCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  289. #region 委外备料SQL
  290. sqls = @" select
  291. c.OOCode as Code,
  292. a.InvCode,
  293. b.InvName,
  294. b.InvStd,
  295. b.InvUnit,
  296. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  297. a.WhCode,
  298. a.ExtensionID
  299. FROM
  300. ICSOOPick a
  301. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  302. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  303. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  304. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  305. #endregion
  306. }
  307. if (TransType == TransTypeEnum.OOApply.GetDescription())
  308. {
  309. enableCode = "Over005";
  310. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Sequence, a.ApplyCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  311. #region 委外领料SQL
  312. sqls = @" select
  313. a.ApplyCode as Code,
  314. a.InvCode,
  315. b.InvName,
  316. b.InvStd,
  317. b.InvUnit,
  318. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  319. a.WhCode,
  320. a.ExtensionID
  321. FROM
  322. ICSOApply a
  323. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  324. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  325. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  326. #endregion
  327. }
  328. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  329. {
  330. //enableCode = "Over006";
  331. excessQtySql = "";
  332. #region 委外材料出库SQL
  333. sqls = @" select
  334. a.IssueCode as Code,
  335. a.InvCode,
  336. b.InvName,
  337. b.InvStd,
  338. b.InvUnit,
  339. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  340. a.WhCode,
  341. a.ExtensionID
  342. FROM
  343. ICSOIssue a
  344. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  345. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  346. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  347. #endregion
  348. }
  349. if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  350. {
  351. enableCode = "";
  352. excessQtySql = "";
  353. #region 销售发货SQL
  354. sqls = @" select
  355. a.SDNCode as Code,
  356. a.InvCode,
  357. b.InvName,
  358. b.InvStd,
  359. b.InvUnit,
  360. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  361. a.WhCode,
  362. a.ExtensionID
  363. FROM
  364. ICSSDN a
  365. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  366. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  367. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  368. #endregion
  369. }
  370. if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  371. {
  372. enableCode = "";
  373. excessQtySql = "";
  374. #region 其它出库SQL
  375. sqls = @" select
  376. a.OutCode 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. ICSOtherOut a
  386. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  387. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  388. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  389. #endregion
  390. }
  391. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  392. {
  393. enableCode = "";
  394. excessQtySql = "";
  395. #region 借用SQL
  396. sqls = @"select
  397. a.BrrowCode 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. ICSBrrow a
  407. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  408. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  409. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  410. #endregion
  411. }
  412. if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  413. {
  414. enableCode = "";
  415. excessQtySql = "";
  416. #region 物料调拨
  417. sqls = @" select
  418. a.TransferNO as Code,
  419. a.InvCode,
  420. b.InvName,
  421. b.InvStd,
  422. b.InvUnit,
  423. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  424. a.FromWarehouseCode as WhCode,
  425. a.ExtensionID
  426. FROM
  427. ICSTransfer a
  428. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  429. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  430. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  431. #endregion
  432. }
  433. if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  434. {
  435. enableCode = "";
  436. excessQtySql = "";
  437. #region 两步调出
  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 ICSOtherOut a
  448. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  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. #endregion
  455. #region 出库
  456. #region 采购退货
  457. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  458. {
  459. isDeliveryNotice = true;
  460. columns = @"a.DNCode AS TransCode,
  461. a.DNDetailID AS DetailID,
  462. a.DNType AS Type,
  463. a.Sequence AS TransSequence,
  464. a.RCVQuantity AS IssueQuantity,
  465. a.Quantity,
  466. a.Amount,
  467. a.MUSER AS [User],
  468. a.MTIME AS [MTime],";
  469. tableName = @"ICSDeliveryNotice a ";
  470. where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' AND a.Status<>'3'";
  471. }
  472. #endregion
  473. //#region 工单关联
  474. //else if (TransType == TransTypeEnum.ICSMOReceive.GetDescription())
  475. //{
  476. // isDeliveryNotice = true;
  477. // columns = @"a.MOCode AS TransCode,
  478. // a.Sequence AS TransSequence,";
  479. // tableName = @"ICSMO a ";
  480. // where = @" a.MOCode='{0}' AND a.WorkPoint='{1}' and a.ERPStatus<>'3'";
  481. //}
  482. //#endregion
  483. #region 委外发料(合并发料)
  484. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  485. {
  486. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode004' and enable = '1'";
  487. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  488. isMerge = true;
  489. columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
  490. a.PickID AS DetailID,
  491. a.SupplyType AS Type,
  492. b.Sequence+'~'+a.Sequence AS TransSequence,
  493. a.IssueQuantity AS IssueQuantity,";
  494. tableNameMerge = @"ICSOOPick a
  495. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  496. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  497. columns = @"b.OOCode AS TransCode,
  498. a.PickID AS DetailID,
  499. a.SupplyType AS Type,
  500. b.Sequence+'~'+a.Sequence AS TransSequence,
  501. a.IssueQuantity AS IssueQuantity,";
  502. tableName = @"ICSOOPick a
  503. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  504. where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and isnull(a.EATTRIBUTE1,'')<>'1' AND a.Quantity-a.IssueQuantity>0";
  505. }
  506. #endregion
  507. #region 委外退货
  508. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  509. {
  510. isDeliveryNotice = true;
  511. columns = @"a.ODNCode AS TransCode,
  512. a.ODNDetailID AS DetailID,
  513. a.ODNType AS Type,
  514. a.Sequence AS TransSequence,
  515. a.RCVQuantity AS IssueQuantity,
  516. a.Quantity,
  517. a.Amount,
  518. a.MUSER AS [User],
  519. a.MTIME AS [MTime],";
  520. tableName = @"ICSODeliveryNotice a ";
  521. where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' AND a.Status<>'3'";
  522. }
  523. #endregion
  524. #region 生产发料(合并发料)
  525. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  526. {
  527. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
  528. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  529. isMerge = true;
  530. columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  531. a.PickID AS DetailID,
  532. a.SupplyType AS Type,
  533. b.Sequence+'~'+a.Sequence AS TransSequence,
  534. a.IssueQuantity AS IssueQuantity,";
  535. tableNameMerge = @"ICSMOPick a
  536. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  537. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  538. columns = @"b.MOCode AS TransCode,
  539. a.PickID AS DetailID,
  540. a.SupplyType AS Type,
  541. b.Sequence+'~'+a.Sequence AS TransSequence,
  542. a.IssueQuantity AS IssueQuantity,";
  543. tableName = @"ICSMOPick a
  544. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  545. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' AND a.Quantity-a.IssueQuantity>0";
  546. }
  547. #endregion
  548. #region 销售出库(合并发料)
  549. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  550. {
  551. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
  552. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  553. isMerge = true;
  554. columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
  555. a.SDNDetailID AS DetailID,
  556. a.SOCode,
  557. a.Type,
  558. a.Sequence AS TransSequence,
  559. a.SDNQuantity AS IssueQuantity,";
  560. tableNameMerge = @"ICSSDN a
  561. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  562. columns = @"a.SDNCode AS TransCode,
  563. a.SDNDetailID AS DetailID,
  564. a.SOCode,
  565. a.Type,
  566. a.Sequence AS TransSequence,
  567. a.SDNQuantity AS IssueQuantity,";
  568. tableName = @"ICSSDN a ";
  569. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' AND a.Quantity-a.SDNQuantity>0";
  570. }
  571. #endregion
  572. #region 盘点
  573. else if (TransType == TransTypeEnum.Check.GetDescription())
  574. {
  575. #region SLQ
  576. sql = @"SELECT a.ID,
  577. {0}
  578. a.Quantity,
  579. a.SelectLevel AS LocationCode,
  580. a.Amount,
  581. a.MUSER AS [User],
  582. a.MTIME AS [MTime]
  583. FROM {1}
  584. WHERE {2} ";
  585. #endregion
  586. columns = @"a.CheckCode AS TransCode,
  587. a.ID,
  588. '' AS Type,";
  589. tableName = @"ICSCheck a ";
  590. where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' and a.Status='1'";
  591. }
  592. #endregion
  593. #region 一步调拨(合并发料)
  594. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  595. {
  596. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
  597. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  598. isMerge = true;
  599. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  600. a.TransferDetailID AS DetailID,
  601. '' AS Type,
  602. a.Sequence AS TransSequence,
  603. a.TransferQuantity AS IssueQuantity,
  604. a.ToWarehouseCode,";
  605. tableNameMerge = @"ICSTransfer a
  606. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  607. #region SLQ
  608. sql = @"SELECT a.ID,
  609. {0}
  610. convert(varchar(100),'') AS LocationCode,
  611. convert(varchar(100),'') AS LotNo,
  612. 0 AS LocationQty,
  613. 0 AS isMatched,
  614. a.InvCode,
  615. inv.InvName,
  616. inv.InvStd,
  617. a.Quantity,
  618. inv.InvUnit,
  619. a.Amount,
  620. a.FromWarehouseCode AS WHCode,
  621. inv.AmountUnit,
  622. wh.WarehouseName AS WHName,
  623. a.ExtensionID,
  624. ext.ProjectCode,
  625. 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,
  626. ext.Version,
  627. ext.Brand,
  628. ext.cFree1,
  629. ext.cFree2,
  630. ext.cFree3,
  631. ext.cFree4,
  632. ext.cFree5,
  633. ext.cFree6,
  634. ext.cFree7,
  635. ext.cFree8,
  636. ext.cFree9,
  637. ext.cFree10,
  638. a.MUSER AS [User],
  639. a.MTIME AS [MTime]
  640. FROM {1}
  641. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  642. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  643. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  644. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  645. WHERE {2} ";
  646. #endregion
  647. columns = @"a.TransferNO AS TransCode,
  648. a.TransferDetailID AS DetailID,
  649. '' AS Type,
  650. a.Sequence AS TransSequence,
  651. a.TransferQuantity AS IssueQuantity,
  652. a.ToWarehouseCode,";
  653. tableName = @"ICSTransfer a ";
  654. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3'";
  655. }
  656. #endregion
  657. #region 调拨申请单(领料)
  658. else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
  659. {
  660. isMerge = true;
  661. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  662. a.TransferDetailID AS DetailID,
  663. '' AS Type,
  664. a.Sequence AS TransSequence,
  665. a.TransferQuantity AS IssueQuantity,
  666. a.ToWarehouseCode,";
  667. tableNameMerge = @"ICSTransferApplication a
  668. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  669. #region SLQ
  670. sql = @"SELECT a.ID,
  671. {0}
  672. convert(varchar(100),'') AS LocationCode,
  673. convert(varchar(100),'') AS LotNo,
  674. 0 AS LocationQty,
  675. 0 AS isMatched,
  676. a.InvCode,
  677. inv.InvName,
  678. inv.InvStd,
  679. a.Quantity,
  680. inv.InvUnit,
  681. a.Amount,
  682. a.FromWarehouseCode AS WHCode,
  683. inv.AmountUnit,
  684. wh.WarehouseName AS WHName,
  685. a.ExtensionID,
  686. ext.ProjectCode,
  687. 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,
  688. ext.Version,
  689. ext.Brand,
  690. ext.cFree1,
  691. ext.cFree2,
  692. ext.cFree3,
  693. ext.cFree4,
  694. ext.cFree5,
  695. ext.cFree6,
  696. ext.cFree7,
  697. ext.cFree8,
  698. ext.cFree9,
  699. ext.cFree10,
  700. a.MUSER AS [User],
  701. a.MTIME AS [MTime]
  702. FROM {1}
  703. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  704. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  705. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  706. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  707. WHERE {2} ";
  708. #endregion
  709. columns = @"a.TransferNO AS TransCode,
  710. a.TransferDetailID AS DetailID,
  711. '' AS Type,
  712. a.Sequence AS TransSequence,
  713. a.TransferQuantity AS IssueQuantity,
  714. a.ToWarehouseCode,";
  715. tableName = @"ICSTransferApplication a ";
  716. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='2' AND a.Status<>'3'";
  717. }
  718. #endregion
  719. #region 调拨(合并发料)
  720. else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
  721. {
  722. }
  723. #endregion
  724. #region 两步调出(合并发料)
  725. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  726. {
  727. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode010' and enable = '1'";
  728. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  729. isMerge = true;
  730. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  731. a.OutDetailID AS DetailID,
  732. '' AS Type,
  733. a.Sequence AS TransSequence,
  734. a.OutQuantity AS IssueQuantity,";
  735. tableNameMerge = @"ICSOtherOut a
  736. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  737. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  738. columns = @"a.OutCode AS TransCode,
  739. a.OutDetailID AS DetailID,
  740. '' AS Type,
  741. a.Sequence AS TransSequence,
  742. a.OutQuantity AS IssueQuantity,";
  743. tableName = @"ICSOtherOut a
  744. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  745. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.OutQuantity>0";
  746. }
  747. #endregion
  748. #region 其他出库(合并发料)
  749. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  750. {
  751. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
  752. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  753. isMerge = true;
  754. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  755. a.OutDetailID AS DetailID,
  756. '' AS Type,
  757. a.Sequence AS TransSequence,
  758. a.OutQuantity AS IssueQuantity,";
  759. tableNameMerge = @"ICSOtherOut a
  760. INNER JOIN ICSMOPickMerge mer ON a.id=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  761. columns = @"a.OutCode AS TransCode,
  762. a.OutDetailID AS DetailID,
  763. '' AS Type,
  764. a.Sequence AS TransSequence,
  765. a.OutQuantity AS IssueQuantity,";
  766. tableName = @"ICSOtherOut a ";
  767. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.OutQuantity>0";
  768. }
  769. #endregion
  770. #region 领料申请单发料(合并发料)
  771. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  772. {
  773. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode002' and enable = '1'";
  774. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  775. isMerge = true;
  776. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  777. a.ApplyDetailID AS DetailID,
  778. a.Type,
  779. a.Sequence AS TransSequence,
  780. a.IssueQuantity AS IssueQuantity,";
  781. tableNameMerge = @"ICSMOApply a
  782. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  783. columns = @"a.ApplyCode AS TransCode,
  784. a.ApplyDetailID AS DetailID,
  785. a.Type,
  786. a.Sequence AS TransSequence,
  787. a.IssueQuantity AS IssueQuantity,";
  788. tableName = @"ICSMOApply a ";
  789. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.IssueQuantity>0";
  790. }
  791. #endregion
  792. #region 补料申请单发料(合并发料)
  793. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  794. {
  795. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode012' and enable = '1'";
  796. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  797. isMerge = true;
  798. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  799. a.ApplyDetailID AS DetailID,
  800. a.Type,
  801. a.Sequence AS TransSequence,
  802. a.IssueQuantity AS IssueQuantity,";
  803. tableNameMerge = @"ICSMOReplenishment a
  804. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  805. columns = @"a.ReplenishmentCode AS TransCode,
  806. a.ReplenishmentDetailID AS DetailID,
  807. a.Type,
  808. a.Sequence AS TransSequence,
  809. a.IssueQuantity AS IssueQuantity,";
  810. tableName = @"ICSMOReplenishment a ";
  811. where = @" a.ReplenishmentCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.IssueQuantity>0";
  812. }
  813. #endregion
  814. #region 委外领料申请单发料(合并发料)
  815. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  816. {
  817. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode005' and enable = '1'";
  818. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  819. isMerge = true;
  820. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  821. a.ApplyDetailID AS DetailID,
  822. a.Type,
  823. a.Sequence AS TransSequence,
  824. a.IssueQuantity AS IssueQuantity,";
  825. tableNameMerge = @"ICSOApply a
  826. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  827. columns = @"a.ApplyCode AS TransCode,
  828. a.ApplyDetailID AS DetailID,
  829. a.Type,
  830. a.Sequence AS TransSequence,
  831. a.IssueQuantity AS IssueQuantity,";
  832. tableName = @"ICSOApply a ";
  833. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.IssueQuantity>0";
  834. }
  835. #endregion
  836. #region 开立材料出库(合并发料)
  837. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  838. {
  839. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode003' and enable = '1'";
  840. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  841. isMerge = true;
  842. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  843. a.IssueDetailID AS DetailID,
  844. a.Type,
  845. a.Sequence AS TransSequence,
  846. a.IssueQuantity AS IssueQuantity,";
  847. tableNameMerge = @"ICSMOIssue a
  848. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  849. columns = @"a.IssueCode AS TransCode,
  850. a.IssueDetailID AS DetailID,
  851. a.Type,
  852. a.Sequence AS TransSequence,
  853. a.IssueQuantity AS IssueQuantity,";
  854. tableName = @"ICSMOIssue a ";
  855. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.IssueQuantity>0";
  856. }
  857. #endregion
  858. #region 开立委外材料出库(合并发料)
  859. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  860. {
  861. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode006' and enable = '1'";
  862. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  863. isMerge = true;
  864. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  865. a.IssueDetailID AS DetailID,
  866. a.Type,
  867. a.Sequence AS TransSequence,
  868. a.IssueQuantity AS IssueQuantity,";
  869. tableNameMerge = @"ICSOIssue a
  870. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  871. columns = @"a.IssueCode AS TransCode,
  872. a.IssueDetailID AS DetailID,
  873. a.Type,
  874. a.Sequence AS TransSequence,
  875. a.IssueQuantity AS IssueQuantity,";
  876. tableName = @"ICSOIssue a ";
  877. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.IssueQuantity>0";
  878. }
  879. #endregion
  880. #region 开立红字入库单
  881. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  882. {
  883. columns = @"a.RCVCode AS TransCode,
  884. a.RCVDetailID AS DetailID,
  885. a.Type,
  886. a.Sequence AS TransSequence,
  887. a.RCVQuantity AS IssueQuantity,";
  888. tableName = @"ICSPurchaseReceive a ";
  889. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  890. }
  891. #endregion
  892. #region 开立委外红字入库单
  893. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  894. {
  895. columns = @"a.RCVCode AS TransCode,
  896. a.RCVDetailID AS DetailID,
  897. a.Type,
  898. a.Sequence AS TransSequence,
  899. a.RCVQuantity AS IssueQuantity,";
  900. tableName = @"ICSOutsourcingReceive a ";
  901. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  902. }
  903. #endregion
  904. #region 借用(合并发料)
  905. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  906. {
  907. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode011' and enable = '1'";
  908. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  909. isMerge = true;
  910. columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
  911. a.BrrowDetailID AS DetailID,
  912. '' AS Type,
  913. a.Sequence AS TransSequence,
  914. a.BrrowQuantity AS IssueQuantity,";
  915. tableNameMerge = @"ICSBrrow a
  916. INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  917. columns = @"a.BrrowCode AS TransCode,
  918. a.BrrowDetailID AS DetailID,
  919. '' AS Type,
  920. a.Sequence AS TransSequence,
  921. a.BrrowQuantity AS IssueQuantity,";
  922. tableName = @"ICSBrrow a ";
  923. where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3' AND a.Quantity-a.BrrowQuantity>0";
  924. }
  925. #endregion
  926. #region 送货单
  927. else if (TransType == TransTypeEnum.ASN.GetDescription())
  928. {
  929. isDeliveryNotice = true;
  930. columns = @"asn.ASNCode AS TransCode,
  931. asn.ID AS DetailID,
  932. asn.LotNo,
  933. '' AS Type,
  934. asn.Sequence AS TransSequence,
  935. asn.DNQuantity AS IssueQuantity,
  936. asn.Quantity,
  937. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  938. asn.MUSER AS [User],
  939. asn.MTIME AS [MTime],";
  940. tableName = @"ICSInventoryLot a
  941. INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  942. where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
  943. }
  944. #endregion
  945. #region 委外送货单
  946. else if (TransType == TransTypeEnum.OASN.GetDescription())
  947. {
  948. isDeliveryNotice = true;
  949. columns = @"asn.OASNCode AS TransCode,
  950. asn.ID AS DetailID,
  951. asn.LotNo,
  952. '' AS Type,
  953. asn.Sequence AS TransSequence,
  954. asn.ODNQuantity AS IssueQuantity,
  955. asn.Quantity,
  956. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  957. asn.MUSER AS [User],
  958. asn.MTIME AS [MTime],";
  959. tableName = @"ICSInventoryLot a
  960. INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  961. where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
  962. }
  963. #endregion
  964. #endregion
  965. #region 入库
  966. #region 采购入库
  967. else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  968. {
  969. }
  970. #endregion
  971. #region 审核的到货单
  972. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  973. {
  974. }
  975. #endregion
  976. #region 采购拒收
  977. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  978. {
  979. }
  980. #endregion
  981. #region 审核的委外到货单
  982. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  983. {
  984. }
  985. #endregion
  986. #region 委外拒收
  987. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  988. {
  989. }
  990. #endregion
  991. #region 委外入库
  992. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  993. {
  994. }
  995. #endregion
  996. #region 生产退料
  997. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  998. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  999. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1000. {
  1001. }
  1002. #endregion
  1003. #region 委外退料
  1004. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1005. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1006. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1007. {
  1008. #region SLQ
  1009. sql = @"SELECT a.ID,
  1010. {0}
  1011. FROM {1}
  1012. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1013. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1014. WHERE {2} ";
  1015. #endregion
  1016. columns = @"a.OApplyNegCode AS TransCode,
  1017. a.Sequence AS TransSequence";
  1018. tableName = @"ICSOApplyNegDetail a
  1019. INNER JOIN ICSOApplyNeg d ON a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint";
  1020. where = @" a.OApplyNegCode='{0}' AND a.WorkPoint='{1}' AND a.Quantity>a.IssueNegQuantity AND d.Status<>'3'";
  1021. }
  1022. #endregion
  1023. #region 生产入库
  1024. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1025. {
  1026. }
  1027. #endregion
  1028. #region 开立的生产入库单
  1029. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1030. {
  1031. }
  1032. #endregion
  1033. #region 返工工单
  1034. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1035. {
  1036. }
  1037. #endregion
  1038. #region 销售退货
  1039. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1040. {
  1041. }
  1042. #endregion
  1043. #region 两步调入
  1044. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1045. {
  1046. columns = @"a.InCode AS TransCode,
  1047. a.InDetailID AS DetailID,
  1048. '' AS Type,
  1049. a.Sequence AS TransSequence,
  1050. a.InQuantity AS IssueQuantity,";
  1051. tableName = @"ICSOtherIn a
  1052. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  1053. where = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  1054. }
  1055. #endregion
  1056. #region 销售退货-原条码
  1057. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1058. {
  1059. columns = @"a.SDNCode AS TransCode,
  1060. a.SDNDetailID AS DetailID,
  1061. a.Type,
  1062. a.Sequence AS TransSequence,
  1063. a.SDNQuantity AS IssueQuantity,";
  1064. tableName = @"ICSSDN a ";
  1065. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  1066. }
  1067. #endregion
  1068. #region 其他入库
  1069. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1070. {
  1071. }
  1072. #endregion
  1073. #region 拆卸单
  1074. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1075. {
  1076. columns = @"a.DABDOCCode AS TransCode,
  1077. a.DABDOCDetailID AS DetailID,
  1078. a.DABDOCType AS Type,
  1079. a.Sequence AS TransSequence,
  1080. a.DABDOCQuantity AS IssueQuantity,";
  1081. tableName = @"ICSDisassemblyDoc a";
  1082. where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' AND a.Status<>'3' ";
  1083. }
  1084. #endregion
  1085. #region 归还
  1086. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1087. {
  1088. }
  1089. #endregion
  1090. #endregion
  1091. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
  1092. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  1093. #region 判断是否启用匹配库位
  1094. if (flag != null && flag.Rows.Count > 0)
  1095. //if (true)
  1096. {
  1097. sql = @"select * into #maintemp from (" + sql + @")a
  1098. select * into #resulttemp from #maintemp
  1099. truncate table #resulttemp
  1100. 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,
  1101. isnull(ext.Brand,'')as Brand,
  1102. isnull(ext.cFree1,'')as cFree1,
  1103. isnull(ext.cFree2,'') cFree2,
  1104. isnull(ext.cFree3,'') cFree3,
  1105. isnull(ext.cFree4,'') cFree4,
  1106. isnull(ext.cFree5,'') cFree5,
  1107. isnull(ext.cFree6,'') cFree6,
  1108. isnull(ext.cFree7,'') cFree7,
  1109. isnull(ext.cFree8,'') cFree8,
  1110. isnull(ext.cFree9,'') cFree9,
  1111. isnull(ext.cFree10,'') cFree10,ISNULL(ext.BatchCode, '') BatchCode into #barcodetemp
  1112. from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1113. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1114. LEFT JOIN
  1115. (select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp
  1116. group by invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE) b on a.invcode = b.invcode
  1117. where (a.warehousecode = b.whcode or ISNULL(b.whcode,'')='') and a.Quantity-a.lockQuantity>0 and
  1118. ((LEN(ISNULL(b.ProjectCode,''))<=0)or((LEN(ISNULL(b.ProjectCode,''))>0) and ext.ProjectCode = b.ProjectCode))
  1119. and ((LEN(ISNULL(b.Version,''))<=0)or((LEN(ISNULL(b.Version,''))>0) and ext.Version =b.Version)) and
  1120. ((LEN(ISNULL(b.Brand,''))<=0)or ((LEN(ISNULL(b.Brand,''))>0) and ext.Brand =b.Brand)) and
  1121. ((LEN(ISNULL(b.BatchCode,''))<=0)or((LEN(ISNULL(b.BatchCode,''))>0) and ext.BatchCode =b.BatchCode)) and
  1122. ((LEN(ISNULL(b.cFree1,''))<=0)or((LEN(ISNULL(b.cFree1,''))>0) and ext.cFree1 =b.cFree1)) and
  1123. ((LEN(ISNULL(b.cFree2,''))<=0)or((LEN(ISNULL(b.cFree2,''))>0) and ext.cFree2 =b.cFree2)) and
  1124. ((LEN(ISNULL(b.cFree3,''))<=0)or((LEN(ISNULL(b.cFree3,''))>0) and ext.cFree3 =b.cFree3)) and
  1125. ((LEN(ISNULL(b.cFree4,''))<=0)or((LEN(ISNULL(b.cFree4,''))>0) and ext.cFree4 =b.cFree4)) and
  1126. ((LEN(ISNULL(b.cFree5,''))<=0)or((LEN(ISNULL(b.cFree5,''))>0) and ext.cFree5 =b.cFree5)) and
  1127. ((LEN(ISNULL(b.cFree6,''))<=0)or((LEN(ISNULL(b.cFree6,''))>0) and ext.cFree6 =b.cFree6)) and
  1128. ((LEN(ISNULL(b.cFree7,''))<=0)or((LEN(ISNULL(b.cFree7,''))>0) and ext.cFree7 =b.cFree7)) and
  1129. ((LEN(ISNULL(b.cFree8,''))<=0)or((LEN(ISNULL(b.cFree8,''))>0) and ext.cFree8 =b.cFree8)) and
  1130. ((LEN(ISNULL(b.cFree9,''))<=0)or((LEN(ISNULL(b.cFree9,''))>0) and ext.cFree9 =b.cFree9)) and
  1131. ((LEN(ISNULL(b.cFree10,''))<=0)or((LEN(ISNULL(b.cFree10,''))>0) and ext.cFree10 =b.cFree10))
  1132. BEGIN
  1133. DECLARE @transSequence VARCHAR(50);--
  1134. DECLARE @qty decimal(18, 4);--
  1135. DECLARE @needqty decimal(18, 4);--
  1136. DECLARE @lotno VARCHAR(50);--
  1137. DECLARE @locationcode VARCHAR(50);--
  1138. DECLARE @WHCode VARCHAR(50);--
  1139. DECLARE @invcode VARCHAR(50);--
  1140. DECLARE @issueQuantity decimal(18, 4);
  1141. DECLARE tempCursor CURSOR FOR (select transSequence from #maintemp); --tempCursor
  1142. OPEN tempCursor; --
  1143. FETCH NEXT FROM tempCursor INTO @transSequence; --
  1144. WHILE @@fetch_status=0
  1145. BEGIN
  1146. select @needqty=Quantity,@issueQuantity=issueQuantity from #maintemp where transSequence = @transSequence
  1147. PRINT @transSequence
  1148. WHILE @needqty>0
  1149. BEGIN
  1150. 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
  1151. 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
  1152. and ((isnull(b.ProjectCode,'')<>'' and b.ProjectCode = a.ProjectCode) or isnull(b.ProjectCode,'') ='') and
  1153. ((isnull(b.Version,'')<>'' and b.Version = a.Version) or isnull(b.Version,'') ='') and
  1154. ((isnull(b.Brand,'')<>'' and b.Brand = a.Brand )or isnull(b.Brand,'') ='') and
  1155. ((isnull(b.cFree1,'')<>'' and b.cFree1 =a.cFree1) or isnull(b.cFree1,'') ='') and
  1156. ((isnull(b.cFree2,'')<>'' and b.cFree2 =a.cFree2 )or isnull(b.cFree2,'') ='') and
  1157. ((isnull(b.cFree3,'')<>'' and b.cFree3 =a.cFree3 )or isnull(b.cFree3,'') ='') and
  1158. ((isnull(b.cFree4,'')<>'' and b.cFree4 =a.cFree4 )or isnull(b.cFree4,'') ='') and
  1159. ((isnull(b.cFree5,'')<>'' and b.cFree5 =a.cFree5) or isnull(b.cFree5,'') ='') and
  1160. ((isnull(b.cFree6,'')<>'' and b.cFree6 =a.cFree6 )or isnull(b.cFree6,'') ='') and
  1161. ((isnull(b.cFree7,'')<>'' and b.cFree7 =a.cFree7) or isnull(b.cFree7,'') ='') and
  1162. ((isnull(b.cFree8,'')<>'' and b.cFree8 =a.cFree8) or isnull(b.cFree8,'') ='') and
  1163. ((isnull(b.cFree9,'')<>'' and b.cFree9 =a.cFree9) or isnull(b.cFree9,'') ='') and
  1164. ((isnull(b.cFree10,'')<>'' and b.cFree10 =a.cFree10) or isnull(b.cFree10,'') ='') and
  1165. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =a.BatchCode) or isnull(b.BatchCode,'') ='')ORDER BY mtime,locationcode
  1166. IF(@needqty-@issueQuantity-@qty>=0 and ISNULL(@lotno, '')<>'')
  1167. BEGIN
  1168. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1169. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotNo,
  1170. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  1171. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1172. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),@qty,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  1173. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  1174. delete from #barcodetemp where lotno = @lotno
  1175. SET @needqty=@needqty-@qty
  1176. END
  1177. ELSE if(@needqty-@issueQuantity-@qty<0 and ISNULL(@lotno, '')<>''and @needqty-@issueQuantity>0)
  1178. BEGIN
  1179. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1180. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  1181. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  1182. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1183. 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, ''),
  1184. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  1185. update #barcodetemp set quantity = @qty-@needqty+-@issueQuantity where lotno = @lotno
  1186. SET @needqty=@needqty-@issueQuantity-@qty
  1187. END
  1188. ELSE
  1189. BEGIN
  1190. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1191. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  1192. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  1193. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1194. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),0 ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  1195. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  1196. SET @needqty=0
  1197. END
  1198. END
  1199. FETCH NEXT FROM tempCursor INTO @transSequence;
  1200. END
  1201. CLOSE tempCursor
  1202. DEALLOCATE tempCursor
  1203. END
  1204. select id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  1205. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,sum(LocationQty)as LocationQty,isMatched,AmountUnit,--lotno,
  1206. 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,
  1207. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,isMatched,AmountUnit,--lotno,
  1208. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ORDER BY locationcode ASC ,InvCode ASC
  1209. DROP table #maintemp
  1210. DROP table #resulttemp
  1211. DROP table #barcodetemp";
  1212. }
  1213. #endregion
  1214. if (isDeliveryNotice)//送货、到货、含委外
  1215. {
  1216. #region SLQ
  1217. sql = sqlCheck + @"SELECT a.ID,
  1218. {0}
  1219. a.InvCode,
  1220. inv.InvName,
  1221. inv.InvStd,
  1222. inv.InvUnit,
  1223. '' AS WHCode,
  1224. inv.AmountUnit,
  1225. '' AS WHName,
  1226. a.ExtensionID,
  1227. ext.ProjectCode,
  1228. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  1229. ext.Version,
  1230. ext.Brand,
  1231. ext.cFree1,
  1232. ext.cFree2,
  1233. ext.cFree3,
  1234. ext.cFree4,
  1235. ext.cFree5,
  1236. ext.cFree6,
  1237. ext.cFree7,
  1238. ext.cFree8,
  1239. ext.cFree9,
  1240. ext.cFree10
  1241. FROM {1}
  1242. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1243. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1244. WHERE {2} ";
  1245. #endregion
  1246. }
  1247. else if(isMerge)//合并发料
  1248. {
  1249. #region SLQ
  1250. string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='"+ JsonData.TransCode + "' AND WorkPoint='"+ JsonData.WorkPoint + "'";
  1251. DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
  1252. if (sign != null && sign.Rows.Count > 0)
  1253. {
  1254. string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
  1255. sql = string.Format(sql, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, excessQtySql);
  1256. }
  1257. else
  1258. {
  1259. sql = @" BEGIN
  1260. IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
  1261. BEGIN
  1262. RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
  1263. RETURN
  1264. END
  1265. " + sqlCheck + sql + @"
  1266. END";
  1267. }
  1268. #endregion
  1269. }
  1270. else
  1271. {
  1272. sql = sqlCheck + sql;
  1273. }
  1274. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint);
  1275. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode,excessQtySql);
  1276. sqls = string.Format(sqls, JsonData.TransCode, JsonData.WorkPoint);
  1277. Picksql = string.Format(Picksql,sqls,JsonData.WorkPoint);
  1278. //DataTable table2 = DBHelper.SQlReturnData(Picksql, cmd);
  1279. //return table2;
  1280. log.Debug("源头单据sql:" + sql);
  1281. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  1282. return table;
  1283. }
  1284. catch (Exception ex)
  1285. {
  1286. log.Error(ex.Message);
  1287. throw new Exception(ex.Message);
  1288. }
  1289. finally
  1290. {
  1291. if (conn.State == ConnectionState.Open)
  1292. {
  1293. conn.Close();
  1294. }
  1295. conn.Dispose();
  1296. }
  1297. }
  1298. }
  1299. #endregion
  1300. #region 源头单据检料表信息
  1301. /// <summary>
  1302. /// 源头单据信息
  1303. /// </summary>
  1304. /// <param name="JsonData"></param>
  1305. /// <returns></returns>
  1306. public static DataTable TransPickGet(WMSSourceDocumentModel JsonData)
  1307. {
  1308. var language = LanguageHelper.GetName("WMSAPIInfo");
  1309. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1310. {
  1311. conn.Open();
  1312. SqlCommand cmd = new SqlCommand();
  1313. cmd.Connection = conn;
  1314. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  1315. try
  1316. {
  1317. if (string.IsNullOrEmpty(JsonData.TransCode))
  1318. {
  1319. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1320. }
  1321. else if (string.IsNullOrEmpty(JsonData.TransType))
  1322. {
  1323. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  1324. }
  1325. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  1326. {
  1327. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  1328. }
  1329. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  1330. {
  1331. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  1332. }
  1333. string TransType = JsonData.TransType;
  1334. #region SLQ
  1335. string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  1336. c.Code,
  1337. c.InvCode,
  1338. c.InvName,
  1339. c.InvStd,
  1340. c.InvUnit,
  1341. FLOOR(c.iQuantity) AS iQuantity,
  1342. d.WarehouseCode,
  1343. d.LocationCode,
  1344. d.LotNO,
  1345. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  1346. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  1347. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  1348. FROM
  1349. ({0}) c
  1350. 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
  1351. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  1352. 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
  1353. DECLARE @ItemCode VARCHAR(50),
  1354. @QTY DECIMAL(18,3),
  1355. @ItemCodeCurrent VARCHAR(50),
  1356. @QTYCurrent DECIMAL(18,3),
  1357. @iQuantityCurrent DECIMAL(18,3),
  1358. @CanDelete BIT,
  1359. @Row INT,
  1360. @rowCurrent INT
  1361. SET @Row = @@rowcount
  1362. SET @rowCurrent=1
  1363. SET @CanDelete=0
  1364. SET @ItemCode=''
  1365. WHILE @rowCurrent<=@Row
  1366. BEGIN
  1367. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  1368. PRINT(@rowCurrent)
  1369. IF @ItemCode<>@ItemCodeCurrent
  1370. BEGIN
  1371. SET @ItemCode=@ItemCodeCurrent
  1372. SET @QTY=0
  1373. SET @CanDelete=0
  1374. END
  1375. IF @CanDelete=1
  1376. BEGIN
  1377. DELETE FROM #temp WHERE rowNo=@rowCurrent
  1378. SET @rowCurrent += 1
  1379. CONTINUE
  1380. END
  1381. SET @QTY += @QTYCurrent
  1382. IF @QTY>=@iQuantityCurrent
  1383. BEGIN
  1384. SET @CanDelete=1
  1385. END
  1386. SET @rowCurrent += 1
  1387. END
  1388. SELECT * FROM #temp
  1389. DROP TABLE #temp
  1390. ";
  1391. #endregion
  1392. string sqls = string.Empty;
  1393. #region 检料表信息
  1394. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  1395. {
  1396. #region 工单备料sql
  1397. sqls = @" SELECT
  1398. c.MOCode as Code,
  1399. a.InvCode,
  1400. b.InvName,
  1401. b.InvStd,
  1402. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1403. a.WhCode,
  1404. b.InvUnit,
  1405. a.ExtensionID
  1406. FROM
  1407. ICSMOPick a
  1408. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  1409. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1410. WHERE c.MOCode in ('{0}') AND a.WorkPoint = '{1}'
  1411. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1412. #endregion
  1413. }
  1414. if (TransType == TransTypeEnum.MOApply.GetDescription())
  1415. {
  1416. #region 工单领料SQL
  1417. sqls = @" select
  1418. a.ApplyCode as Code,
  1419. a.InvCode,
  1420. b.InvName,
  1421. b.InvStd,
  1422. b.InvUnit,
  1423. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1424. a.WhCode,
  1425. a.ExtensionID
  1426. FROM
  1427. ICSMOApply a
  1428. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1429. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1430. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1431. #endregion
  1432. }
  1433. if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  1434. {
  1435. #region 工单补料SQL
  1436. sqls = @" select
  1437. a.ReplenishmentCode as Code,
  1438. a.InvCode,
  1439. b.InvName,
  1440. b.InvStd,
  1441. b.InvUnit,
  1442. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1443. a.WhCode,
  1444. a.ExtensionID
  1445. FROM
  1446. ICSMOReplenishment a
  1447. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1448. WHERE a.ReplenishmentCode in ({0}) AND a.WorkPoint = '{1}'
  1449. GROUP BY a.ReplenishmentCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1450. #endregion
  1451. }
  1452. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  1453. {
  1454. #region 工单材料出库SQL
  1455. sqls = @" select
  1456. a.IssueCode as Code,
  1457. a.InvCode,
  1458. b.InvName,
  1459. b.InvStd,
  1460. b.InvUnit,
  1461. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1462. a.WhCode,
  1463. a.ExtensionID
  1464. FROM
  1465. ICSMOIssue a
  1466. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1467. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1468. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1469. #endregion
  1470. }
  1471. if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  1472. {
  1473. #region 委外备料SQL
  1474. sqls = @" select
  1475. c.OOCode as Code,
  1476. a.InvCode,
  1477. b.InvName,
  1478. b.InvStd,
  1479. b.InvUnit,
  1480. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1481. a.WhCode,
  1482. a.ExtensionID
  1483. FROM
  1484. ICSOOPick a
  1485. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  1486. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1487. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  1488. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  1489. #endregion
  1490. }
  1491. if (TransType == TransTypeEnum.OOApply.GetDescription())
  1492. {
  1493. #region 委外领料SQL
  1494. sqls = @" select
  1495. a.ApplyCode as Code,
  1496. a.InvCode,
  1497. b.InvName,
  1498. b.InvStd,
  1499. b.InvUnit,
  1500. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1501. a.WhCode,
  1502. a.ExtensionID
  1503. FROM
  1504. ICSOApply a
  1505. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1506. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  1507. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1508. #endregion
  1509. }
  1510. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  1511. {
  1512. #region 委外材料出库SQL
  1513. sqls = @" select
  1514. a.IssueCode as Code,
  1515. a.InvCode,
  1516. b.InvName,
  1517. b.InvStd,
  1518. b.InvUnit,
  1519. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1520. a.WhCode,
  1521. a.ExtensionID
  1522. FROM
  1523. ICSOIssue a
  1524. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1525. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  1526. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1527. #endregion
  1528. }
  1529. if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  1530. {
  1531. #region 销售发货SQL
  1532. sqls = @" select
  1533. a.SDNCode as Code,
  1534. a.InvCode,
  1535. b.InvName,
  1536. b.InvStd,
  1537. b.InvUnit,
  1538. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1539. a.WhCode,
  1540. a.ExtensionID
  1541. FROM
  1542. ICSSDN a
  1543. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1544. WHERE a.SDNCode in ('{0}') AND a.WorkPoint = '{1}'
  1545. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1546. #endregion
  1547. }
  1548. if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  1549. {
  1550. #region 其它出库SQL
  1551. sqls = @" select
  1552. a.OutCode as Code,
  1553. a.InvCode,
  1554. b.InvName,
  1555. b.InvStd,
  1556. b.InvUnit,
  1557. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1558. a.WhCode,
  1559. a.ExtensionID
  1560. FROM
  1561. ICSOtherOut a
  1562. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1563. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1564. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1565. #endregion
  1566. }
  1567. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  1568. {
  1569. #region 借用SQL
  1570. sqls = @"select
  1571. a.BrrowCode as Code,
  1572. a.InvCode,
  1573. b.InvName,
  1574. b.InvStd,
  1575. b.InvUnit,
  1576. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1577. a.WhCode,
  1578. a.ExtensionID
  1579. FROM
  1580. ICSBrrow a
  1581. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1582. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  1583. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  1584. #endregion
  1585. }
  1586. if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1587. {
  1588. #region 物料调拨
  1589. sqls = @" select
  1590. a.TransferNO as Code,
  1591. a.InvCode,
  1592. b.InvName,
  1593. b.InvStd,
  1594. b.InvUnit,
  1595. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1596. a.FromWarehouseCode as WhCode,
  1597. a.ExtensionID
  1598. FROM
  1599. ICSTransfer a
  1600. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1601. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  1602. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  1603. #endregion
  1604. }
  1605. if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  1606. {
  1607. #region 两步调出
  1608. sqls = @"select
  1609. a.OutCode as Code,
  1610. a.InvCode,
  1611. b.InvName,
  1612. b.InvStd,
  1613. b.InvUnit,
  1614. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  1615. a.WHCode ,
  1616. a.ExtensionID
  1617. from ICSOtherOut a
  1618. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  1619. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  1620. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  1621. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  1622. #endregion
  1623. }
  1624. #endregion
  1625. sqls = string.Format(sqls, JsonData.TransCode, JsonData.WorkPoint);
  1626. Picksql = string.Format(Picksql, sqls, JsonData.WorkPoint);
  1627. DataTable table = DBHelper.SQlReturnData(Picksql, cmd);
  1628. return table;
  1629. }
  1630. catch (Exception ex)
  1631. {
  1632. log.Error(ex.Message);
  1633. throw new Exception(ex.Message);
  1634. }
  1635. finally
  1636. {
  1637. if (conn.State == ConnectionState.Open)
  1638. {
  1639. conn.Close();
  1640. }
  1641. conn.Dispose();
  1642. }
  1643. }
  1644. }
  1645. #endregion
  1646. /// <summary>
  1647. /// 所有未完成单据号
  1648. /// </summary>
  1649. /// <param name="JsonData"></param>
  1650. /// <returns></returns>
  1651. public static DataTable TransCodeGet(WMSSourceDocumentModel JsonData)
  1652. {
  1653. var language = LanguageHelper.GetName("WMSAPIInfo");
  1654. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1655. {
  1656. conn.Open();
  1657. SqlCommand cmd = new SqlCommand();
  1658. cmd.Connection = conn;
  1659. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  1660. try
  1661. {
  1662. if (string.IsNullOrEmpty(JsonData.TransType))
  1663. {
  1664. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  1665. }
  1666. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  1667. {
  1668. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  1669. }
  1670. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  1671. {
  1672. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  1673. }
  1674. string TransType = JsonData.TransType;
  1675. #region SLQ
  1676. //string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  1677. // BEGIN
  1678. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  1679. // RETURN
  1680. // END
  1681. // ";
  1682. string sql = @"SELECT
  1683. {0}
  1684. FROM {1}
  1685. WHERE {2}
  1686. order by TransCode asc";
  1687. #endregion
  1688. bool isDeliveryNotice = false; //送货、到货、含委外
  1689. bool MOApplyWithBin = false; //生产领料-库位
  1690. bool OtherOutDocWithBin = false; //杂发-库位
  1691. string columns = string.Empty; //查询源头单据表的特殊列名
  1692. string tableName = string.Empty; //查询源头单据表名
  1693. string where = string.Empty; //查询源头单据的过滤条件
  1694. bool isMerge = false; //合并发料
  1695. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  1696. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  1697. #region 出库
  1698. #region 采购退货
  1699. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  1700. {
  1701. columns = @" DISTINCT a.DNCode AS TransCode";
  1702. tableName = @"ICSDeliveryNotice a ";
  1703. where = @" a.WorkPoint='{1}' AND a.DNType='2' AND a.Status='2' AND (a.Quantity-a.RCVQuantity)>0";
  1704. }
  1705. #endregion
  1706. #region 其他出库
  1707. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  1708. {
  1709. columns = @" DISTINCT a.OutCode AS TransCode";
  1710. tableName = @"ICSOtherOut a ";
  1711. where = @" a.Status='1' AND a.WorkPoint='{1}' and a.Quantity>a.OutQuantity";
  1712. }
  1713. #endregion
  1714. #region 一步调拨(合并发料)
  1715. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1716. {
  1717. columns = @" DISTINCT a.TransferNO AS TransCode";
  1718. tableName = @"ICSTransfer a ";
  1719. where = @" a.WorkPoint='{1}' AND a.Status='1' AND a.Quantity>a.TransferQuantity AND Type='1'";
  1720. }
  1721. #endregion
  1722. #region 调拨申请单(合并发料)
  1723. else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
  1724. {
  1725. columns = @" DISTINCT a.TransferNO AS TransCode";
  1726. tableName = @"ICSTransferApplication a ";
  1727. where = @" a.WorkPoint='{1}' AND a.Status='2' AND a.Quantity>a.TransferQuantity AND Type='1'";
  1728. }
  1729. #endregion
  1730. #region 委外退料
  1731. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  1732. {
  1733. columns = @" DISTINCT a.OApplyNegCode AS TransCode";
  1734. tableName = @"ICSOApplyNegDetail a
  1735. INNER JOIN ICSOApplyNeg d ON a.OApplyNegCode=d.OApplyNegCode AND a.WorkPoint=d.WorkPoint";
  1736. where = @" a.WorkPoint='{1}' AND d.Status='1' AND a.Quantity>a.IssueNegQuantity AND d.Type='1'";
  1737. }
  1738. #endregion
  1739. #region 生产发料(合并发料)
  1740. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  1741. {
  1742. columns = @" DISTINCT b.MOCode AS TransCode";
  1743. tableName = @" ICSMOPick a
  1744. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  1745. where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' and a.Quantity-a.IssueQuantity>0";
  1746. }
  1747. #endregion
  1748. #region 开立材料出库(合并发料)
  1749. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  1750. {
  1751. columns = @" DISTINCT a.IssueCode AS TransCode";
  1752. tableName = @" ICSMOIssue a ";
  1753. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  1754. }
  1755. #endregion
  1756. #region 生产发料-领料申请单
  1757. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  1758. {
  1759. columns = @" DISTINCT a.ApplyCode AS TransCode";
  1760. tableName = @" ICSMOApply a";
  1761. where = @" a.Status='2' AND a.WorkPoint='{1}' and a.Quantity-a.IssueQuantity>0";
  1762. }
  1763. #endregion
  1764. #region 开立委外材料出库(合并发料)
  1765. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  1766. {
  1767. columns = @" DISTINCT a.IssueCode AS TransCode";
  1768. tableName = @" ICSOIssue a ";
  1769. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  1770. }
  1771. #endregion
  1772. #region 委外领料申请单发料(合并发料)
  1773. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  1774. {
  1775. columns = @" DISTINCT a.ApplyCode AS TransCode";
  1776. tableName = @" ICSOApply a ";
  1777. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  1778. }
  1779. #endregion
  1780. #region 委外发料(合并发料)
  1781. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  1782. {
  1783. columns = @" DISTINCT b.OOCode AS TransCode";
  1784. tableName = @" ICSOOPick a
  1785. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  1786. where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and a.EATTRIBUTE1<>'1' and a.Quantity-a.IssueQuantity>0";
  1787. }
  1788. #endregion
  1789. #region 销售出库(合并发料)
  1790. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  1791. {
  1792. columns = @" DISTINCT a.SDNCode AS TransCode";
  1793. tableName = @"ICSSDN a ";
  1794. where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' and a.Quantity-a.SDNQuantity>0";
  1795. }
  1796. #endregion
  1797. #region 盘点
  1798. else if (TransType == TransTypeEnum.Check.GetDescription())
  1799. {
  1800. columns = @" DISTINCT a.CheckCode AS TransCode";
  1801. tableName = @"ICSCheck a ";
  1802. where = @" a.WorkPoint='{1}' and a.Status='1'";
  1803. }
  1804. #endregion
  1805. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint);
  1806. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode);
  1807. log.Debug("源头单据sql : " + sql);
  1808. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  1809. return table;
  1810. #endregion
  1811. }
  1812. catch (Exception ex)
  1813. {
  1814. log.Error(ex.Message);
  1815. throw new Exception(ex.Message);
  1816. }
  1817. finally
  1818. {
  1819. if (conn.State == ConnectionState.Open)
  1820. {
  1821. conn.Close();
  1822. }
  1823. conn.Dispose();
  1824. }
  1825. }
  1826. }
  1827. #region 条码信息
  1828. /// <summary>
  1829. /// 条码信息
  1830. /// </summary>
  1831. /// <param name="JsonData"></param>
  1832. /// <returns></returns>
  1833. public static Result BarCodeInformationGet(BarCodeModel JsonData)
  1834. {
  1835. var language = LanguageHelper.GetName("WMSAPIInfo");
  1836. DataTable table = new DataTable();
  1837. DataTable ZLtable = new DataTable();
  1838. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1839. {
  1840. conn.Open();
  1841. SqlCommand cmd = new SqlCommand();
  1842. cmd.Connection = conn;
  1843. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  1844. try
  1845. {
  1846. string ScanType = DBHelper.ScanTypeCheck(JsonData.Code, JsonData.WorkPoint, cmd);
  1847. if (string.IsNullOrEmpty(JsonData.Code))
  1848. {
  1849. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  1850. }
  1851. else if (string.IsNullOrEmpty(JsonData.TransType))
  1852. {
  1853. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  1854. }
  1855. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  1856. {
  1857. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  1858. }
  1859. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  1860. {
  1861. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  1862. }
  1863. string TransType = JsonData.TransType;
  1864. string sql = "";
  1865. string LotTypesql = "";
  1866. string Losql = "";
  1867. string sqlNew = "";
  1868. string LotType = "";
  1869. bool iszl = false;
  1870. string zlqty = "0";
  1871. bool needIns = ICSControlModeService.GetOrderIns(EnumHelper.GetDBValue(typeof(TransTypeEnum), TransType));
  1872. #region SLQ
  1873. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  1874. {
  1875. //Losql = @"SELECT a.ID,
  1876. // con.ContainerCode,
  1877. // con.ContainerName,
  1878. // a.LotNo,
  1879. // a.InvCode,
  1880. // inv.InvName,
  1881. // inv.InvStd,
  1882. // inv.InvUnit,
  1883. // inv.LotEnable,
  1884. // {0}
  1885. // inv.AmountUnit,
  1886. // ext.ID AS ExtensionID,
  1887. // ext.ProjectCode,
  1888. // ext.Version,
  1889. // ext.Brand,
  1890. // ext.cFree1,
  1891. // ext.cFree2,
  1892. // ext.cFree3,
  1893. // ext.cFree4,
  1894. // ext.cFree5,
  1895. // ext.cFree6,
  1896. // ext.cFree7,
  1897. // ext.cFree8,
  1898. // ext.cFree9,
  1899. // ext.cFree10,
  1900. // a.MUSER AS [User],
  1901. // a.MTIME AS [MTime]
  1902. // FROM {1}
  1903. // LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  1904. // LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  1905. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1906. // WHERE a.Quantity>0 and a.WorkPoint='{3}'";
  1907. Losql = @" DECLARE @wheresql VARCHAR(MAX)
  1908. DECLARE @groupsql VARCHAR(MAX)
  1909. DECLARE @aa VARCHAR(MAX)
  1910. DECLARE @bb VARCHAR(MAX)
  1911. DECLARE @cc VARCHAR(MAX)
  1912. DECLARE @dd VARCHAR(MAX)
  1913. DECLARE @b VARCHAR(MAX)
  1914. select @aa=id from ICSWareHouseLotInfo where LotNo='{2}'
  1915. IF @aa IS NOT NULL
  1916. BEGIN
  1917. set @wheresql='and a.lotno=''{2}'' and s.invcode IN(SELECT invcode FROM ICSWareHouseLotInfo where LotNo=''{2}'') and a.invcode=s.invcode '
  1918. 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,
  1919. 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'
  1920. END
  1921. select @bb=id from ICSLocation where LocationCode like '%{2}%'
  1922. IF @bb IS not NULL
  1923. BEGIN
  1924. set @wheresql='and a.locationcode=s.locationcode and a.LocationCode like ''%{2}%'' '
  1925. 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,
  1926. 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'
  1927. END
  1928. select @cc=id from ICSInventory where invcode='{2}'
  1929. IF @cc IS not NULL
  1930. BEGIN
  1931. set @wheresql='and inv.invcode=''{2}'' and a.invcode=s.invcode '
  1932. 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,
  1933. 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'
  1934. END
  1935. select @dd=id from ICSInventory where InvStd LIKE '%{2}%'
  1936. IF @dd IS not NULL
  1937. BEGIN
  1938. set @wheresql='and inv.InvStd LIKE ''%{2}%'' '
  1939. 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,
  1940. 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'
  1941. END
  1942. IF @aa IS NULL and @bb IS NULL and @cc IS NULL and @dd IS NULL
  1943. BEGIN
  1944. RAISERROR('" + language.GetNameByCode("WMSAPIInfo478") + @"',16,1)
  1945. END
  1946. ELSE
  1947. BEGIN
  1948. set @b =
  1949. 'SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
  1950. inv.InvName,
  1951. inv.InvStd,
  1952. inv.InvUnit,
  1953. inv.LotEnable,
  1954. a.WarehouseCode,a.LocationCode,a.Quantity as Qty,SUM(s.sumQty) sumQty,
  1955. inv.AmountUnit,
  1956. ext.ID AS ExtensionID,
  1957. ext.ProjectCode,
  1958. ext.Version,
  1959. ext.Brand,
  1960. ext.cFree1,
  1961. ext.cFree2,
  1962. ext.cFree3,
  1963. ext.cFree4,
  1964. ext.cFree5,
  1965. ext.cFree6,
  1966. ext.cFree7,
  1967. ext.cFree8,
  1968. ext.cFree9,
  1969. ext.cFree10,
  1970. a.MUSER AS [User],
  1971. a.MTIME AS [MTime]
  1972. FROM ICSWareHouseLotInfo a
  1973. LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  1974. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1975. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1976. 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
  1977. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  1978. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  1979. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1980. WHERE a.Quantity>0 and a.WorkPoint=''{3}'' ' + @wheresql + @groupsql
  1981. END
  1982. exec(@b)
  1983. ";
  1984. }
  1985. else
  1986. {
  1987. if (ScanType == "LOTNO")
  1988. {
  1989. sql = @"SELECT a.ID,
  1990. con.ContainerCode,
  1991. con.ContainerName,
  1992. a.LotNo,
  1993. a.InvCode,
  1994. inv.InvName,
  1995. inv.InvStd,
  1996. inv.InvUnit,
  1997. inv.LotEnable,
  1998. {0}
  1999. inv.AmountUnit,
  2000. ext.ID AS ExtensionID,
  2001. ext.ProjectCode,
  2002. ext.Version,
  2003. ext.Brand,
  2004. ext.cFree1,
  2005. ext.cFree2,
  2006. ext.cFree3,
  2007. ext.cFree4,
  2008. ext.cFree5,
  2009. ext.cFree6,
  2010. ext.cFree7,
  2011. ext.cFree8,
  2012. ext.cFree9,
  2013. ext.cFree10,
  2014. a.MUSER AS [User],
  2015. a.MTIME AS [MTime]
  2016. FROM {1}
  2017. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  2018. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  2019. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2020. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' ";
  2021. }
  2022. else
  2023. {
  2024. sql = @"SELECT a.ID,
  2025. con.ContainerCode,
  2026. con.ContainerName,
  2027. a.LotNo,
  2028. a.InvCode,
  2029. inv.InvName,
  2030. inv.InvStd,
  2031. inv.InvUnit,
  2032. {0}
  2033. inv.AmountUnit,
  2034. ext.ID AS ExtensionID,
  2035. ext.ProjectCode,
  2036. ext.Version,
  2037. ext.Brand,
  2038. ext.cFree1,
  2039. ext.cFree2,
  2040. ext.cFree3,
  2041. ext.cFree4,
  2042. ext.cFree5,
  2043. ext.cFree6,
  2044. ext.cFree7,
  2045. ext.cFree8,
  2046. ext.cFree9,
  2047. ext.cFree10,
  2048. a.MUSER AS [User],
  2049. a.MTIME AS [MTime]
  2050. FROM {1}
  2051. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  2052. LEFT JOIN ICSBomALL bom ON bom.ID=conlot.ContainerID
  2053. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  2054. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2055. WHERE bom.ContainerCode='{2}' AND a.WorkPoint='{3}' ";
  2056. }
  2057. }
  2058. #endregion
  2059. bool isOut = false; //出库标记
  2060. string columns = string.Empty; //查询源头单据表的特殊列名
  2061. string columnsLOCODE = string.Empty;
  2062. string columnsLONAME = string.Empty;
  2063. string columnsWHCODE = string.Empty;
  2064. string columnsWHNAME = string.Empty;
  2065. string tableName = string.Empty; //查询源头单据表名
  2066. string where = string.Empty; //排序
  2067. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription() //采购退货
  2068. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() //委外发料
  2069. || TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription() //委外退货
  2070. || TransType == TransTypeEnum.MOIssueDoc.GetDescription() //生产发料
  2071. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() //销售出库
  2072. || TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription() //一步调拨
  2073. || TransType == TransTypeEnum.StepTransferDocIn.GetDescription() //调拨
  2074. || TransType == TransTypeEnum.StepNoTransferDocIn.GetDescription() //无源头调拨
  2075. || TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription() //调拨申请单
  2076. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() //两步调出
  2077. || TransType == TransTypeEnum.OtherOutDoc.GetDescription() //其他出库
  2078. || TransType == TransTypeEnum.Check.GetDescription() //盘点
  2079. || TransType == TransTypeEnum.MOApply.GetDescription() //领料申请单
  2080. || TransType == TransTypeEnum.MOReplenishment.GetDescription() //领料申请单
  2081. || TransType == TransTypeEnum.OOApply.GetDescription() //委外领料申请单
  2082. || TransType == TransTypeEnum.MOIssue.GetDescription() //开立材料出库单
  2083. || TransType == TransTypeEnum.OOIssue.GetDescription() //开立委外材料出库单
  2084. || TransType == TransTypeEnum.PurchaseReceive.GetDescription() //开立红字入库单
  2085. || TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription()//开立委外红字入库单
  2086. || TransType == TransTypeEnum.BrrowDoc.GetDescription() //借用
  2087. || TransType == TransTypeEnum.TransferLibrary.GetDescription() //移库
  2088. //|| TransType == TransTypeEnum.DisassemblyDoc.GetDescription() //拆卸单(散件生成条码入库)
  2089. )
  2090. {
  2091. isOut = true;
  2092. }
  2093. //库位查询
  2094. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  2095. {
  2096. // 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, " +
  2097. // "ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME";
  2098. // columns = @"s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,sum(a.Quantity) as Qty,s.sumQty,";
  2099. // tableName = @"ICSWareHouseLotInfo a
  2100. //LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  2101. //INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2102. //INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2103. //LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode from ICSWareHouseLotInfo group by WarehouseCode,INVCode)s
  2104. //ON a.INVCode=s.INVCode ";
  2105. }
  2106. else
  2107. {
  2108. //两步调入条码
  2109. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  2110. {
  2111. if (string.IsNullOrEmpty(JsonData.TransCode))
  2112. {
  2113. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2114. }
  2115. if (ScanType == "LOTNO")
  2116. {
  2117. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSOtherIn Otin
  2118. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  2119. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  2120. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  2121. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2122. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND Otin.InCode = '" + JsonData.TransCode + @"')
  2123. BEGIN
  2124. RAISERROR('" + language.GetNameByCode("WMSAPIInfo036") + @"',16,1);
  2125. RETURN
  2126. END
  2127. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  2128. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  2129. 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,
  2130. 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";
  2131. columns = @"SUM(log.Quantity) AS Quantity,
  2132. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  2133. a.WarehouseCode AS WHCode,
  2134. wh.WarehouseName AS WHName,
  2135. a.LocationCode,
  2136. loc.LocationName,
  2137. 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,";
  2138. tableName = @"ICSOtherIn Otin
  2139. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  2140. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  2141. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  2142. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2143. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2144. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2145. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2146. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2147. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2148. }
  2149. else
  2150. {
  2151. sql = @"WITH ICSBomALL AS
  2152. (
  2153. SELECT
  2154. ContainerCode AS TContainerCode,
  2155. ContainerCode AS PContainerCode,
  2156. ContainerCode AS ContainerCode,
  2157. ID,
  2158. ContainerID,
  2159. 0 AS [Level],
  2160. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  2161. CAST('00001' AS nvarchar(MAX)) AS Sort
  2162. FROM ICSContainer
  2163. WHERE ContainerCode='{2}'
  2164. UNION ALL
  2165. SELECT
  2166. b.TContainerCode,
  2167. b.ContainerCode AS PContainerCode,
  2168. a.ContainerCode,
  2169. a.ID,
  2170. a.ContainerID,
  2171. b.[Level]+1 AS [Level],
  2172. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  2173. 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
  2174. FROM
  2175. ICSContainer a
  2176. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  2177. )
  2178. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  2179. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  2180. 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,
  2181. 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";
  2182. columns = @"SUM(log.Quantity) AS Quantity,
  2183. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  2184. a.WarehouseCode AS WHCode,
  2185. wh.WarehouseName AS WHName,
  2186. a.LocationCode,
  2187. loc.LocationName,
  2188. 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,";
  2189. tableName = @"ICSOtherIn Otin
  2190. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  2191. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  2192. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  2193. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2194. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2195. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2196. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2197. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2198. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2199. }
  2200. }
  2201. //销售退货-原条码(可支持一个条码多次发货,汇总数量,目前加了限制:785-793行)
  2202. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  2203. {
  2204. if (string.IsNullOrEmpty(JsonData.TransCode))
  2205. {
  2206. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2207. }
  2208. if (ScanType == "LOTNO")
  2209. {
  2210. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSSDN sdn
  2211. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  2212. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2213. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1')
  2214. BEGIN
  2215. RAISERROR('" + language.GetNameByCode("WMSAPIInfo037") + @"',16,1);
  2216. RETURN
  2217. END
  2218. IF EXISTS(SELECT log.LotNo FROM ICSSDN sdn
  2219. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  2220. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2221. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1' AND log.BusinessCode='19'
  2222. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  2223. BEGIN
  2224. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo191"), "{2}") + @"',16,1);
  2225. RETURN
  2226. END
  2227. " + sql + @"AND sdn.Type='1'
  2228. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  2229. 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,
  2230. 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";
  2231. columns = @"SUM(log.Quantity) AS Quantity,
  2232. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  2233. a.WarehouseCode AS WHCode,
  2234. wh.WarehouseName AS WHName,
  2235. a.LocationCode,
  2236. loc.LocationName,
  2237. 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,";
  2238. tableName = @"ICSSDN sdn
  2239. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  2240. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2241. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2242. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2243. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2244. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2245. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2246. }
  2247. else
  2248. {
  2249. sql = @"WITH ICSBomALL AS
  2250. (
  2251. SELECT
  2252. ContainerCode AS TContainerCode,
  2253. ContainerCode AS PContainerCode,
  2254. ContainerCode AS ContainerCode,
  2255. ID,
  2256. ContainerID,
  2257. 0 AS [Level],
  2258. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  2259. CAST('00001' AS nvarchar(MAX)) AS Sort
  2260. FROM ICSContainer
  2261. WHERE ContainerCode='{2}'
  2262. UNION ALL
  2263. SELECT
  2264. b.TContainerCode,
  2265. b.ContainerCode AS PContainerCode,
  2266. a.ContainerCode,
  2267. a.ID,
  2268. a.ContainerID,
  2269. b.[Level]+1 AS [Level],
  2270. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  2271. 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
  2272. FROM
  2273. ICSContainer a
  2274. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  2275. )
  2276. " + sql + @"AND sdn.Type='1'
  2277. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  2278. 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,
  2279. 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";
  2280. columns = @"SUM(log.Quantity) AS Quantity,
  2281. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  2282. a.WarehouseCode AS WHCode,
  2283. wh.WarehouseName AS WHName,
  2284. a.LocationCode,
  2285. loc.LocationName,
  2286. 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,";
  2287. tableName = @"ICSSDN sdn
  2288. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  2289. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2290. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2291. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2292. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2293. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2294. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2295. }
  2296. }
  2297. //生产(委外)退料-原条码+新条码
  2298. //先校验日志里面是否有原条码(同一种类型的条码只能发一次料才能原条码退,不然更新源头单据数量有问题,根据LogID判断是否原条码退回),如果没有查询新条码
  2299. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  2300. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  2301. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription()
  2302. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  2303. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  2304. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  2305. {
  2306. string type = "13";
  2307. string msglanguage = "WMSAPIInfo185";
  2308. if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  2309. {
  2310. type = "14";
  2311. msglanguage = "WMSAPIInfo186";
  2312. }
  2313. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  2314. {
  2315. type = "15";
  2316. msglanguage = "WMSAPIInfo187";
  2317. }
  2318. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  2319. {
  2320. type = "5";
  2321. msglanguage = "WMSAPIInfo188";
  2322. }
  2323. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  2324. {
  2325. type = "6";
  2326. msglanguage = "WMSAPIInfo189";
  2327. }
  2328. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  2329. {
  2330. type = "7";
  2331. msglanguage = "WMSAPIInfo190";
  2332. }
  2333. #region 新条码
  2334. if (ScanType == "LOTNO")
  2335. {
  2336. sqlNew = @"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  2337. BEGIN
  2338. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  2339. RETURN
  2340. END
  2341. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  2342. BEGIN
  2343. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  2344. RETURN
  2345. END
  2346. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  2347. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  2348. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  2349. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1'AND ins.LotNo IS NULL))
  2350. BEGIN
  2351. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  2352. RETURN
  2353. END
  2354. " + sql;
  2355. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  2356. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  2357. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  2358. {
  2359. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  2360. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  2361. (select negg.WHCode from ICSMOApplyNegDetail neg
  2362. INNER JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  2363. inner join ICSInventoryLotDetail lotdetail on neg.ApplyNegCode=lotdetail.TransCode
  2364. and neg.Sequence=lotdetail.TransSequence
  2365. where lotdetail.LotNo=a.LotNo and lotdetail.WorkPoint=a.WorkPoint) AS WHCode,
  2366. '' AS WHName,
  2367. '' AS LocationCode,
  2368. '' AS LocationName,
  2369. '' AS LogID,
  2370. ext.BatchCode AS BatchCode,";
  2371. }
  2372. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  2373. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  2374. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  2375. {
  2376. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  2377. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  2378. (select negg.WHCode from ICSOApplyNegDetail neg
  2379. INNER JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  2380. inner join ICSInventoryLotDetail lotdetail on neg.OApplyNegCode=lotdetail.TransCode
  2381. and neg.Sequence=lotdetail.TransSequence
  2382. where lotdetail.LotNo=a.LotNo and lotdetail.WorkPoint=a.WorkPoint) AS WHCode,
  2383. '' AS WHName,
  2384. '' AS LocationCode,
  2385. '' AS LocationName,
  2386. '' AS LogID,
  2387. ext.BatchCode AS BatchCode,";
  2388. }
  2389. tableName = @"ICSInventoryLot a
  2390. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2391. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  2392. }
  2393. else
  2394. {
  2395. sqlNew = @"WITH ICSBomALL AS
  2396. (
  2397. SELECT
  2398. ContainerCode AS TContainerCode,
  2399. ContainerCode AS PContainerCode,
  2400. ContainerCode AS ContainerCode,
  2401. ID,
  2402. ContainerID,
  2403. 0 AS [Level],
  2404. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  2405. CAST('00001' AS nvarchar(MAX)) AS Sort
  2406. FROM ICSContainer
  2407. WHERE ContainerCode='{2}'
  2408. UNION ALL
  2409. SELECT
  2410. b.TContainerCode,
  2411. b.ContainerCode AS PContainerCode,
  2412. a.ContainerCode,
  2413. a.ID,
  2414. a.ContainerID,
  2415. b.[Level]+1 AS [Level],
  2416. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  2417. 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
  2418. FROM
  2419. ICSContainer a
  2420. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  2421. )
  2422. " + sql;
  2423. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  2424. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  2425. '' AS WHCode,
  2426. '' AS WHName,
  2427. '' AS LocationCode,
  2428. '' AS LocationName,
  2429. ext.BatchCode AS BatchCode,";
  2430. tableName = @"ICSInventoryLot a
  2431. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2432. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  2433. }
  2434. sqlNew = string.Format(sqlNew, columns, tableName, JsonData.Code, JsonData.WorkPoint, zlqty);
  2435. #endregion
  2436. #region 原条码
  2437. if (ScanType == "LOTNO")
  2438. {
  2439. 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,
  2440. 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,
  2441. 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
  2442. ";
  2443. sql = @"IF EXISTS(" + sql + @")
  2444. BEGIN
  2445. " + sql + @"
  2446. END
  2447. ELSE
  2448. BEGIN
  2449. " + sqlNew + @"
  2450. END";
  2451. sql = @"IF EXISTS(SELECT log.LotNo FROM ICSWareHouseLotInfoLog log
  2452. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2453. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND log.BusinessCode='" + type + @"'
  2454. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  2455. BEGIN
  2456. RAISERROR('" + string.Format(language.GetNameByCode(msglanguage), "{2}") + @"',16,1);
  2457. RETURN
  2458. END
  2459. " + sql;
  2460. columns = @"SUM(log.Quantity) AS Quantity,
  2461. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  2462. a.WarehouseCode AS WHCode,
  2463. wh.WarehouseName AS WHName,
  2464. a.LocationCode,
  2465. loc.LocationName,
  2466. log.ID AS LogID,
  2467. 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,";
  2468. tableName = @"ICSWareHouseLotInfoLog log
  2469. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2470. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2471. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2472. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2473. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2474. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2475. }
  2476. else
  2477. {
  2478. 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,
  2479. 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,
  2480. 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
  2481. ";
  2482. sql = @"IF EXISTS(" + sql + @")
  2483. BEGIN
  2484. " + sql + @"
  2485. END
  2486. ELSE
  2487. BEGIN
  2488. " + sqlNew + @"
  2489. END";
  2490. sql = @"WITH ICSBomALL AS
  2491. (
  2492. SELECT
  2493. ContainerCode AS TContainerCode,
  2494. ContainerCode AS PContainerCode,
  2495. ContainerCode AS ContainerCode,
  2496. ID,
  2497. ContainerID,
  2498. 0 AS [Level],
  2499. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  2500. CAST('00001' AS nvarchar(MAX)) AS Sort
  2501. FROM ICSContainer
  2502. WHERE ContainerCode='{2}'
  2503. UNION ALL
  2504. SELECT
  2505. b.TContainerCode,
  2506. b.ContainerCode AS PContainerCode,
  2507. a.ContainerCode,
  2508. a.ID,
  2509. a.ContainerID,
  2510. b.[Level]+1 AS [Level],
  2511. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  2512. 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
  2513. FROM
  2514. ICSContainer a
  2515. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  2516. )
  2517. " + sql;
  2518. columns = @"SUM(log.Quantity) AS Quantity,
  2519. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  2520. a.WarehouseCode AS WHCode,
  2521. wh.WarehouseName AS WHName,
  2522. a.LocationCode,
  2523. loc.LocationName,
  2524. log.ID AS LogID,
  2525. 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,";
  2526. tableName = @"ICSWareHouseLotInfoLog log
  2527. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  2528. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2529. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2530. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2531. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2532. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2533. }
  2534. #endregion
  2535. }
  2536. //分批
  2537. else if (TransType == TransTypeEnum.LOTSplit.GetDescription() || TransType == TransTypeEnum.LOTMerge.GetDescription())
  2538. {
  2539. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  2540. BEGIN
  2541. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  2542. RETURN
  2543. END
  2544. " + sql;
  2545. columns = @"a.Quantity,
  2546. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  2547. a.WarehouseCode AS WHCode,
  2548. wh.WarehouseName AS WHName,
  2549. a.LocationCode,
  2550. loc.LocationName,
  2551. 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,
  2552. ISNULL(split.SplitLotNo, a.LotNo+'-1') AS SplitLotNo,";
  2553. tableName = @"ICSWareHouseLotInfo a
  2554. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2555. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2556. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2557. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2558. 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
  2559. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2560. }
  2561. //出库条码
  2562. else if (isOut)
  2563. {
  2564. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() || TransType == TransTypeEnum.MOApply.GetDescription()
  2565. || TransType == TransTypeEnum.MOIssue.GetDescription() || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription()
  2566. || TransType == TransTypeEnum.OOApply.GetDescription() || TransType == TransTypeEnum.OOIssue.GetDescription()
  2567. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() || TransType == TransTypeEnum.OtherOutDoc.GetDescription()
  2568. || TransType == TransTypeEnum.BrrowDoc.GetDescription() || TransType == TransTypeEnum.StepTransferDocIn.GetDescription()
  2569. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() || TransType == TransTypeEnum.MOReplenishment.GetDescription())
  2570. {
  2571. if (JsonData.IsPick!="1")
  2572. {
  2573. ZLtable = ICSControlModeService.GetZL();
  2574. if (ZLtable == null)
  2575. {
  2576. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  2577. }
  2578. for (int i = 0; i < ZLtable.Rows.Count; i++)
  2579. {
  2580. string zlName = ZLtable.Rows[i]["Name"].ToString();
  2581. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  2582. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  2583. if (JsonData.TransType.Equals(zlName))
  2584. {
  2585. if (Enable.Equals("True"))
  2586. {
  2587. string zlsql = @"IF NOT EXISTS(select a.Quantity,c.Name from ICSWareHouseLotInfoLog a
  2588. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
  2589. left join ICSType c on a.BusinessCode=c.Code and c.tablecode='ICSWareHouseLotInfoLog' and c.ColumnCode='BusinessCode'
  2590. where b.LotNo='{0}' and b.WorkPoint='{1}' and a.TransType='15' and c.name='{2}' and a.TransCode='{3}')
  2591. BEGIN
  2592. RAISERROR('" + language.GetNameByCode("WMSAPIInfo469") + @"',16,1);
  2593. RETURN
  2594. END
  2595. select a.Quantity,c.Name from ICSWareHouseLotInfoLog a
  2596. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
  2597. left join ICSType c on a.BusinessCode=c.Code and c.tablecode='ICSWareHouseLotInfoLog' and c.ColumnCode='BusinessCode'
  2598. where b.LotNo='{0}' and b.WorkPoint='{1}' and a.TransType='15' and c.name='{2}' and a.TransCode='{3}'";
  2599. zlsql = string.Format(zlsql, JsonData.Code, JsonData.WorkPoint, JsonData.TransType, JsonData.TransCode);
  2600. DataTable zlltable = DBHelper.SQlReturnData(zlsql, cmd);
  2601. if (zlltable != null || zlltable.Rows.Count > 0)
  2602. {
  2603. zlqty = zlltable.Rows[0]["Quantity"].ToString();
  2604. iszl = true;
  2605. }
  2606. }
  2607. }
  2608. }
  2609. }
  2610. }
  2611. if (ScanType == "LOTNO")
  2612. {
  2613. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  2614. BEGIN
  2615. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  2616. RETURN
  2617. END
  2618. " + sql;
  2619. if (iszl)
  2620. {
  2621. columns = @"{0} as Quantity,
  2622. {0}*(lot.Amount/lot.Quantity) AS Amount,
  2623. a.id AS LogID,
  2624. a.FromWarehouseCode AS WHCode,
  2625. wh.WarehouseName AS WHName,
  2626. inv.LotEnable,
  2627. a.FromLocationCode,
  2628. loc.LocationName,
  2629. 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,";
  2630. columns = string.Format(columns, zlqty);
  2631. tableName = @"ICSWareHouseLotInfoLog a
  2632. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2633. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2634. INNER JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2635. INNER JOIN ICSLocation loc ON a.FromLocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2636. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2637. }
  2638. else
  2639. {
  2640. if(TransType == TransTypeEnum.Check.GetDescription())
  2641. {
  2642. columns = @"case when inv.AmountEnable='1' then (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) else (a.Quantity-a.lockQuantity) end AS Quantity,
  2643. (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
  2644. '' AS LogID,
  2645. a.WarehouseCode AS WHCode,
  2646. wh.WarehouseName AS WHName,
  2647. inv.LotEnable,
  2648. a.LocationCode,
  2649. loc.LocationName,
  2650. 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,";
  2651. tableName = @"ICSWareHouseLotInfo a
  2652. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2653. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2654. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2655. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2656. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2657. }
  2658. else
  2659. {
  2660. columns = @"(a.Quantity-a.lockQuantity) AS Quantity,
  2661. (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
  2662. '' AS LogID,
  2663. a.WarehouseCode AS WHCode,
  2664. wh.WarehouseName AS WHName,
  2665. inv.LotEnable,
  2666. a.LocationCode,
  2667. loc.LocationName,
  2668. 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,";
  2669. tableName = @"ICSWareHouseLotInfo a
  2670. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2671. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2672. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2673. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2674. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  2675. }
  2676. }
  2677. }
  2678. else
  2679. {
  2680. sql = @"
  2681. WITH ICSBomALL AS
  2682. (
  2683. SELECT
  2684. ContainerCode AS TContainerCode,
  2685. ContainerCode AS PContainerCode,
  2686. ContainerCode AS ContainerCode,
  2687. ID,
  2688. ContainerID,
  2689. 0 AS [Level],
  2690. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  2691. CAST('00001' AS nvarchar(MAX)) AS Sort
  2692. FROM ICSContainer
  2693. WHERE ContainerCode='{2}'
  2694. UNION ALL
  2695. SELECT
  2696. b.TContainerCode,
  2697. b.ContainerCode AS PContainerCode,
  2698. a.ContainerCode,
  2699. a.ID,
  2700. a.ContainerID,
  2701. b.[Level]+1 AS [Level],
  2702. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  2703. 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
  2704. FROM
  2705. ICSContainer a
  2706. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  2707. )
  2708. " + sql;
  2709. columns = @"(a.Quantity-a.lockQuantity) AS Quantity,
  2710. (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
  2711. a.WarehouseCode AS WHCode,
  2712. wh.WarehouseName AS WHName,
  2713. a.LocationCode,
  2714. loc.LocationName,
  2715. 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,";
  2716. tableName = @"ICSWareHouseLotInfo a
  2717. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  2718. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  2719. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  2720. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  2721. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  2722. ";
  2723. }
  2724. }
  2725. //入库条码
  2726. else
  2727. {
  2728. if (ScanType == "LOTNO")
  2729. {
  2730. if ((TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  2731. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  2732. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription()
  2733. || TransType == TransTypeEnum.MOStockINByProduct.GetDescription() || TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription()
  2734. || TransType == TransTypeEnum.OOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription()) && needIns)
  2735. {
  2736. sql = @"
  2737. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  2738. BEGIN
  2739. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  2740. RETURN
  2741. END
  2742. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  2743. BEGIN
  2744. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  2745. RETURN
  2746. END
  2747. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  2748. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  2749. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  2750. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1' AND ins.LotNo IS NULL))
  2751. BEGIN
  2752. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  2753. RETURN
  2754. END
  2755. " + sql;
  2756. }
  2757. else
  2758. {
  2759. sql = @"
  2760. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  2761. BEGIN
  2762. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  2763. RETURN
  2764. END
  2765. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  2766. BEGIN
  2767. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  2768. RETURN
  2769. END
  2770. " + sql;
  2771. }
  2772. ControlMode mode = ICSControlModeService.GetSuLocation();
  2773. //获取条码类型
  2774. LotTypesql = @"IF NOT EXISTS(SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}')
  2775. BEGIN
  2776. RAISERROR('" + language.GetNameByCode("WMSAPIInfo461") + @"',16,1);
  2777. RETURN
  2778. END
  2779. SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2780. LotTypesql = string.Format(LotTypesql, JsonData.Code, JsonData.WorkPoint);
  2781. DataTable dt = DBHelper.SQlReturnData(LotTypesql, cmd);
  2782. if (dt != null && dt.Rows.Count > 0)
  2783. {
  2784. LotType = dt.Rows[0]["Type"].ToString();
  2785. }
  2786. if (mode != null)
  2787. {
  2788. if (mode.itemCode.Equals("LocationRemind01"))//固定库位:物料和库位绑定,显示库位名称列表
  2789. {
  2790. columnsLONAME = @"
  2791. (SELECT locat.LocationName from ICSWareHouseLotInfo loinfo
  2792. LEFT JOIN ICSLocation locat on locat.LocationCode=loinfo.LocationCode and loinfo.WorkPoint=locat.WorkPoint
  2793. where loinfo.lotno=a.lotno and loinfo.invcode=a.invcode and a.WorkPoint=loinfo.WorkPoint) AS LocationName,";
  2794. columnsLOCODE = @"
  2795. (SELECT locat.LocationCode from ICSWareHouseLotInfo loinfo
  2796. LEFT JOIN ICSLocation locat on locat.LocationCode=loinfo.LocationCode and loinfo.WorkPoint=locat.WorkPoint
  2797. where loinfo.lotno=a.lotno and loinfo.invcode=a.invcode and a.WorkPoint=loinfo.WorkPoint) AS LocationCode,";
  2798. }
  2799. else if (mode.itemCode.Equals("LocationRemind02"))//在库库位:物料有库存的对应库位,显示库位名称列表
  2800. {
  2801. columnsLONAME = @"
  2802. STUFF(
  2803. (SELECT DISTINCT ',' + LocationName
  2804. from ICSLocation wh
  2805. LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
  2806. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
  2807. FOR xml path('')
  2808. ),1,1,''
  2809. ) AS LocationName,";
  2810. columnsLOCODE = @"
  2811. STUFF(
  2812. (SELECT DISTINCT ',' + LocationCode
  2813. from ICSLocation wh
  2814. LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
  2815. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
  2816. FOR xml path('')
  2817. ),1,1,''
  2818. ) AS LocationCode,";
  2819. }
  2820. else if (mode.itemCode.Equals("LocationRemind03"))//最近一次出入库的库位,显示库位名称
  2821. {
  2822. columnsLONAME = @"
  2823. (SELECT Top 1 locat.LocationName from ICSWareHouseLotInfoLog log
  2824. 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
  2825. ORDER BY log.Mtime desc) AS LocationName,";
  2826. columnsLOCODE = @"
  2827. (SELECT Top 1 locat.LocationCode from ICSWareHouseLotInfoLog log
  2828. 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
  2829. ORDER BY log.Mtime desc) AS LocationCode,";
  2830. }
  2831. }
  2832. else
  2833. {
  2834. columnsLONAME = @"
  2835. STUFF(
  2836. (SELECT DISTINCT ',' + LocationName
  2837. from ICSLocation wh
  2838. LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
  2839. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
  2840. FOR xml path('')
  2841. ),1,1,''
  2842. ) AS LocationName,";
  2843. columnsLOCODE = @"
  2844. STUFF(
  2845. (SELECT DISTINCT ',' + LocationCode
  2846. from ICSLocation wh
  2847. LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
  2848. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
  2849. FOR xml path('')
  2850. ),1,1,''
  2851. ) AS LocationCode,";
  2852. }
  2853. #region 根据条码类型找到单据仓库信息
  2854. if (LotType.Equals("1"))
  2855. {//生产退料
  2856. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  2857. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1'),'') AS WHCode";
  2858. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  2859. 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";
  2860. }
  2861. else if (LotType.Equals("2"))
  2862. {//委外退料
  2863. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  2864. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1'),'') AS WHCode";
  2865. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  2866. 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";
  2867. }
  2868. else if (LotType.Equals("3"))
  2869. {//工单
  2870. 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";
  2871. 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";
  2872. }
  2873. else if (LotType.Equals("4"))
  2874. {//销售退货
  2875. 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";
  2876. 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";
  2877. }
  2878. else if (LotType.Equals("5"))
  2879. {//其他入库
  2880. 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";
  2881. 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";
  2882. }
  2883. else if (LotType.Equals("6"))
  2884. {//归还单
  2885. 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";
  2886. 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";
  2887. }
  2888. else if (LotType.Equals("7"))
  2889. {//采购到货单
  2890. 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";
  2891. 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";
  2892. }
  2893. else if (LotType.Equals("8"))
  2894. {//委外到货单
  2895. 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";
  2896. 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";
  2897. }
  2898. else if (LotType.Equals("9"))
  2899. {//成品入库单
  2900. 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";
  2901. 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";
  2902. }
  2903. else if (LotType.Equals("10"))
  2904. {//拒收单
  2905. 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";
  2906. 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";
  2907. }
  2908. else if (LotType.Equals("11"))
  2909. {//委外拒收单
  2910. 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";
  2911. 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";
  2912. }
  2913. else if (LotType.Equals("12"))
  2914. {//领料申请退料
  2915. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  2916. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2'),'') AS WHCode";
  2917. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  2918. 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";
  2919. }
  2920. else if (LotType.Equals("13"))
  2921. {//材料出库退料
  2922. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  2923. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3'),'') AS WHCode";
  2924. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  2925. 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";
  2926. }
  2927. else if (LotType.Equals("14"))
  2928. {//委外领料申请退料
  2929. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  2930. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2'),'') AS WHCode";
  2931. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  2932. 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";
  2933. }
  2934. else if (LotType.Equals("15"))
  2935. {//委外材料出库退料
  2936. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  2937. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3'),'') AS WHCode";
  2938. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  2939. 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";
  2940. }
  2941. else if (LotType.Equals("16"))
  2942. {//返工工单
  2943. columnsWHCODE = @"ISNULL((SELECT pick.WHCode FROM ICSMOPick pick LEFT JOIN ICSMO moo ON pick.MODetailID=moo.MODetailID AND pick.WorkPoint=moo.WorkPoint
  2944. WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint),'') AS WHCode ";
  2945. 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
  2946. WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName ";
  2947. }
  2948. else
  2949. {
  2950. columnsWHCODE = @"'' AS WHCode";
  2951. columnsWHNAME = @"'' AS WHName";
  2952. }
  2953. #endregion
  2954. if ((TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  2955. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  2956. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription()
  2957. || TransType == TransTypeEnum.ManufactureReceive.GetDescription() || TransType == TransTypeEnum.OOStockINByProduct.GetDescription()
  2958. || TransType == TransTypeEnum.MOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription()) && needIns)
  2959. {
  2960. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  2961. a.Quantity*(a.Amount/a.Quantity) AS Amount,a.Type,
  2962. {0},{2},
  2963. lotdd.TransCode,lotdd.TransSequence,
  2964. a.Type,
  2965. {3}
  2966. {1}
  2967. ext.BatchCode AS BatchCode,";
  2968. tableName = @"ICSInventoryLot a
  2969. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2970. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
  2971. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  2972. }
  2973. else
  2974. {
  2975. columns = @"a.Quantity AS Quantity,
  2976. a.Quantity*(a.Amount/a.Quantity) AS Amount,a.Type,
  2977. {0},{2},
  2978. a.Type,
  2979. {3}
  2980. {1}
  2981. ext.BatchCode AS BatchCode,";
  2982. tableName = @"ICSInventoryLot a
  2983. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2984. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint";
  2985. }
  2986. columns = string.Format(columns, columnsWHCODE, columnsLONAME, columnsWHNAME, columnsLOCODE);
  2987. }
  2988. else
  2989. {
  2990. sql = @"
  2991. WITH ICSBomALL AS
  2992. (
  2993. SELECT
  2994. ContainerCode AS TContainerCode,
  2995. ContainerCode AS PContainerCode,
  2996. ContainerCode AS ContainerCode,
  2997. ID,
  2998. ContainerID,
  2999. 0 AS [Level],
  3000. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  3001. CAST('00001' AS nvarchar(MAX)) AS Sort
  3002. FROM ICSContainer
  3003. WHERE ContainerCode='{2}'
  3004. UNION ALL
  3005. SELECT
  3006. b.TContainerCode,
  3007. b.ContainerCode AS PContainerCode,
  3008. a.ContainerCode,
  3009. a.ID,
  3010. a.ContainerID,
  3011. b.[Level]+1 AS [Level],
  3012. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  3013. 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
  3014. FROM
  3015. ICSContainer a
  3016. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  3017. )
  3018. " + sql;
  3019. if ((TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  3020. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  3021. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription()
  3022. || TransType == TransTypeEnum.MOStockINByProduct.GetDescription() || TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription()
  3023. || TransType == TransTypeEnum.OOStockINByProduct.GetDescription() || TransType == TransTypeEnum.OtherInDoc.GetDescription()) && needIns)
  3024. {
  3025. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  3026. a.Quantity*(a.Amount/a.Quantity) AS Amount,a.Type,
  3027. '' AS WHCode,
  3028. '' AS WHName,
  3029. '' AS LocationCode,
  3030. '' AS LocationName,
  3031. ext.BatchCode AS BatchCode,";
  3032. tableName = @"ICSInventoryLot a
  3033. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3034. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  3035. }
  3036. else
  3037. {
  3038. columns = @"a.Quantity AS Quantity,
  3039. a.Quantity*(a.Amount/a.Quantity) AS Amount,a.Type,
  3040. '' AS WHCode,
  3041. '' AS WHName,
  3042. '' AS LocationCode,
  3043. '' AS LocationName,
  3044. ext.BatchCode AS BatchCode,";
  3045. tableName = @"ICSInventoryLot a
  3046. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint";
  3047. }
  3048. }
  3049. }
  3050. }
  3051. if (TransType != TransTypeEnum.LocationSeatch.GetDescription())
  3052. {
  3053. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName))
  3054. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  3055. }
  3056. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  3057. {
  3058. Losql = string.Format(Losql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  3059. table = DBHelper.SQlReturnData(Losql, cmd);
  3060. }
  3061. else
  3062. {
  3063. sql = string.Format(sql, columns, tableName, JsonData.Code, JsonData.WorkPoint,zlqty);
  3064. log.Info("条码sql:" + sql);
  3065. table = DBHelper.SQlReturnData(sql, cmd);
  3066. }
  3067. if (table == null || table.Rows.Count <= 0)
  3068. throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
  3069. #region 出库检验是否符合源头单据
  3070. string msg = string.Empty;
  3071. bool isLimit = false;
  3072. string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode' and F_EnabledMark = '1'";
  3073. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  3074. if (isOut) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
  3075. {//&& TransType != TransTypeEnum.TransferLibrary.GetDescription()
  3076. string Lot = "";
  3077. string workP = "";
  3078. if (TransType == TransTypeEnum.TransferLibrary.GetDescription())
  3079. {
  3080. foreach (DataRow drLot in table.Rows)
  3081. {
  3082. Lot = drLot["LotNo"].ToString();
  3083. sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3084. sql = string.Format(sql, Lot, JsonData.WorkPoint);
  3085. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3086. if (dt == null || dt.Rows.Count <= 0)
  3087. {
  3088. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), Lot));
  3089. }
  3090. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  3091. if (!JsonData.WHCode.Equals(whcode))
  3092. {
  3093. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo395"), JsonData.WHCode, whcode));
  3094. }
  3095. }
  3096. }
  3097. else if(TransType != TransTypeEnum.LocationSeatch.GetDescription() && TransType != TransTypeEnum.StepNoTransferDocIn.GetDescription())
  3098. {
  3099. if (string.IsNullOrEmpty(JsonData.TransCode))
  3100. {
  3101. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3102. }
  3103. WMSSourceDocumentModel model = new WMSSourceDocumentModel();
  3104. model.TransCode = JsonData.TransCode;
  3105. model.TransType = JsonData.TransType;
  3106. model.WorkPoint = JsonData.WorkPoint;
  3107. DataTable TransData = TransInformationGet(model);
  3108. DataView dataView = TransData.DefaultView;
  3109. foreach (DataRow drLot in table.Rows)
  3110. {
  3111. Lot = drLot["LotNo"].ToString();
  3112. //盘点不需要对比以下属性
  3113. if (TransType == TransTypeEnum.Check.GetDescription())
  3114. continue;
  3115. string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
  3116. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
  3117. rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
  3118. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
  3119. rowFilter += " AND (LEN(ISNULL(ProjectCode,''))<=0 OR (LEN(ISNULL(ProjectCode,''))>0 AND ProjectCode='" + drLot["ProjectCode"] + "'))";
  3120. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["ProjectCode"], GetExtentionName("ProjectCode", JsonData.WorkPoint, cmd, language)));
  3121. rowFilter += "AND (LEN(ISNULL(BatchCode,''))<=0 OR (LEN(ISNULL(BatchCode,''))>0 AND BatchCode='" + drLot["BatchCode"] + "'))";
  3122. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["BatchCode"], GetExtentionName("BatchCode", JsonData.WorkPoint, cmd, language)));
  3123. rowFilter += "AND (LEN(ISNULL(Version,''))<=0 OR (LEN(ISNULL(Version,''))>0 AND Version='" + drLot["Version"] + "'))";
  3124. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["Version"], GetExtentionName("Version", JsonData.WorkPoint, cmd, language)));
  3125. rowFilter += "AND (LEN(ISNULL(Brand,''))<=0 OR (LEN(ISNULL(Brand,''))>0 AND Brand='" + drLot["Brand"] + "'))";
  3126. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["Brand"], GetExtentionName("Brand", JsonData.WorkPoint, cmd, language)));
  3127. rowFilter += "AND (LEN(ISNULL(cFree1,''))<=0 OR (LEN(ISNULL(cFree1,''))>0 AND cFree1='" + drLot["cFree1"] + "'))";
  3128. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree1"], GetExtentionName("cFree1", JsonData.WorkPoint, cmd, language)));
  3129. rowFilter += "AND (LEN(ISNULL(cFree2,''))<=0 OR (LEN(ISNULL(cFree2,''))>0 AND cFree2='" + drLot["cFree2"] + "'))";
  3130. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree2"], GetExtentionName("cFree2", JsonData.WorkPoint, cmd, language)));
  3131. rowFilter += "AND (LEN(ISNULL(cFree3,''))<=0 OR (LEN(ISNULL(cFree3,''))>0 AND cFree3='" + drLot["cFree3"] + "'))";
  3132. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree3"], GetExtentionName("cFree3", JsonData.WorkPoint, cmd, language)));
  3133. rowFilter += "AND (LEN(ISNULL(cFree4,''))<=0 OR (LEN(ISNULL(cFree4,''))>0 AND cFree4='" + drLot["cFree4"] + "'))";
  3134. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree4"], GetExtentionName("cFree4", JsonData.WorkPoint, cmd, language)));
  3135. rowFilter += "AND (LEN(ISNULL(cFree5,''))<=0 OR (LEN(ISNULL(cFree5,''))>0 AND cFree5='" + drLot["cFree5"] + "'))";
  3136. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree5"], GetExtentionName("cFree5", JsonData.WorkPoint, cmd, language)));
  3137. rowFilter += "AND (LEN(ISNULL(cFree6,''))<=0 OR (LEN(ISNULL(cFree6,''))>0 AND cFree6='" + drLot["cFree6"] + "'))";
  3138. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree6"], GetExtentionName("cFree6", JsonData.WorkPoint, cmd, language)));
  3139. rowFilter += "AND (LEN(ISNULL(cFree7,''))<=0 OR (LEN(ISNULL(cFree7,''))>0 AND cFree7='" + drLot["cFree7"] + "'))";
  3140. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree7"], GetExtentionName("cFree7", JsonData.WorkPoint, cmd, language)));
  3141. rowFilter += "AND (LEN(ISNULL(cFree8,''))<=0 OR (LEN(ISNULL(cFree8,''))>0 AND cFree8='" + drLot["cFree8"] + "'))";
  3142. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree8"], GetExtentionName("cFree8", JsonData.WorkPoint, cmd, language)));
  3143. rowFilter += "AND (LEN(ISNULL(cFree9,''))<=0 OR (LEN(ISNULL(cFree9,''))>0 AND cFree9='" + drLot["cFree9"] + "'))";
  3144. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree9"], GetExtentionName("cFree9", JsonData.WorkPoint, cmd, language)));
  3145. rowFilter += "AND (LEN(ISNULL(cFree10,''))<=0 OR (LEN(ISNULL(cFree10,''))>0 AND cFree10='" + drLot["cFree10"] + "'))";
  3146. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree10"], GetExtentionName("cFree10", JsonData.WorkPoint, cmd, language)));
  3147. if (flag != null && flag.Rows.Count > 0)
  3148. {
  3149. rowFilter += " AND LocationCode='" + drLot["LocationCode"] + "'";
  3150. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["LocationCode"]));
  3151. }
  3152. //保质期管理
  3153. var resultEffective = Effective(Lot, JsonData.WorkPoint, cmd, language);
  3154. //0 - 已经是最早的批次
  3155. //1 - 不管控
  3156. //2 - 提醒
  3157. //3 - 限制
  3158. if (resultEffective == "2")
  3159. {
  3160. msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
  3161. }
  3162. else if (resultEffective == "3")
  3163. {
  3164. msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
  3165. isLimit = true;
  3166. }
  3167. string rowFilternew = rowFilter+" AND LEN(ISNULL(ProjectCode,''))>0";
  3168. string sqlnew = CheckTransnew(dataView, rowFilternew, "ProjectCode");
  3169. rowFilternew = rowFilter + " AND LEN(ISNULL(BatchCode,''))>0";
  3170. sqlnew += CheckTransnew(dataView, rowFilternew, "BatchCode");
  3171. rowFilternew = rowFilter + " AND LEN(ISNULL(Version,''))>0";
  3172. sqlnew += CheckTransnew(dataView, rowFilternew, "Version");
  3173. rowFilternew = rowFilter + " AND LEN(ISNULL(Brand,''))>0";
  3174. sqlnew += CheckTransnew(dataView, rowFilternew, "Brand");
  3175. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree1,''))>0";
  3176. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree1");
  3177. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree2,''))>0";
  3178. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree2");
  3179. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree3,''))>0";
  3180. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree3");
  3181. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree4,''))>0";
  3182. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree4");
  3183. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree5,''))>0";
  3184. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree5");
  3185. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree6,''))>0";
  3186. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree6");
  3187. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree7,''))>0";
  3188. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree7");
  3189. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree8,''))>0 ";
  3190. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree8");
  3191. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree9,''))>0";
  3192. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree9");
  3193. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree10,''))>0";
  3194. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree10");
  3195. if(TransType != TransTypeEnum.OtherOutDoc.GetDescription())
  3196. {
  3197. //先进先出判断
  3198. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, sqlnew, cmd, language);
  3199. //0 - 已经是最早的批次
  3200. //1 - 不管控
  3201. //2 - 提醒
  3202. //3 - 限制
  3203. if (result == "2")
  3204. {
  3205. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  3206. }
  3207. else if (result == "3")
  3208. {
  3209. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  3210. isLimit = true;
  3211. }
  3212. }
  3213. }
  3214. }
  3215. }
  3216. #endregion
  3217. //return table;
  3218. Result res = new Result();
  3219. res.Success = true;
  3220. res.Message = msg;// "接口调用成功!";
  3221. if (!isLimit)
  3222. res.Data = table;
  3223. return res;
  3224. //出库时
  3225. //Message无值、Data有值,可直接处理
  3226. //Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
  3227. //Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
  3228. }
  3229. catch (Exception ex)
  3230. {
  3231. log.Error(ex.Message);
  3232. throw new Exception(ex.Message);
  3233. }
  3234. finally
  3235. {
  3236. if (conn.State == ConnectionState.Open)
  3237. {
  3238. conn.Close();
  3239. }
  3240. conn.Dispose();
  3241. }
  3242. }
  3243. }
  3244. /// <summary>
  3245. /// 校验条码对应的物料、自由项等信息是否与源头单据匹配
  3246. /// </summary>
  3247. private static DataView CheckTrans(DataView dataView, string rowFilter, string message)
  3248. {
  3249. dataView.RowFilter = rowFilter;
  3250. if (dataView == null || dataView.Count <= 0)
  3251. throw new Exception(message);
  3252. return dataView;
  3253. }
  3254. #endregion
  3255. private static string CheckTransnew(DataView dataView, string rowFilter, string aaa)
  3256. {
  3257. dataView.RowFilter = rowFilter;
  3258. if (dataView == null || dataView.Count <= 0)
  3259. return "";
  3260. return " AND bext."+ aaa + "=yext."+ aaa ;
  3261. }
  3262. /// <summary>
  3263. /// 上架
  3264. /// </summary>BusinessCode,TransType 两个类型
  3265. /// <param name="JsonData"></param>
  3266. /// <returns></returns>
  3267. public static DataTable LOTStockCreate(List<LOTStockUpCreateIModel> JsonData)
  3268. {
  3269. var language = LanguageHelper.GetName("WMSAPIInfo");
  3270. if (JsonData.Count <= 0)
  3271. {
  3272. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3273. }
  3274. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3275. {
  3276. conn.Open();
  3277. SqlTransaction sqlTran = conn.BeginTransaction();
  3278. SqlCommand cmd = new SqlCommand();
  3279. cmd.Transaction = sqlTran;
  3280. cmd.Connection = conn;
  3281. cmd.CommandTimeout= Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  3282. string BusinessCode = string.Empty;
  3283. try
  3284. {
  3285. DataTable dtable = new DataTable();
  3286. string result = string.Empty;
  3287. string TransType = string.Empty;
  3288. string TransTypeOriginal = string.Empty;//记录不合格入库条码的原条码的类型
  3289. string Identification = Guid.NewGuid().ToString();
  3290. foreach (var item in JsonData)
  3291. {
  3292. TransType = item.TransType;
  3293. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  3294. {
  3295. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  3296. }
  3297. string WHTransType = "2";
  3298. foreach (var itemInfo in item.detail)
  3299. {
  3300. #region 两步调入
  3301. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  3302. {
  3303. //更新源头单据数量
  3304. ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3305. //入库
  3306. ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  3307. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  3308. }
  3309. #endregion
  3310. #region 销售退货-原条码
  3311. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  3312. {
  3313. //更新源头单据数量
  3314. ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3315. //入库
  3316. BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription<DBValue>();
  3317. //入库
  3318. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  3319. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode,"","");
  3320. //更新日志表源头单据信息
  3321. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  3322. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' AND TransCode='' AND TransSequence=''";
  3323. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  3324. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3325. {
  3326. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  3327. }
  3328. }
  3329. #endregion
  3330. else
  3331. {
  3332. #region 采购入库
  3333. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  3334. {
  3335. //更新源头单据数量
  3336. ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3337. BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription<DBValue>();
  3338. }
  3339. #endregion
  3340. #region 审核的到货单
  3341. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  3342. {
  3343. //更新源头单据数量
  3344. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3345. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  3346. }
  3347. #endregion
  3348. #region 采购拒收
  3349. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  3350. {
  3351. //更新源头单据数量
  3352. ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3353. BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription<DBValue>();
  3354. }
  3355. #endregion
  3356. #region 审核的委外到货单
  3357. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  3358. {
  3359. //更新源头单据数量
  3360. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3361. BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  3362. }
  3363. #endregion
  3364. #region 委外拒收
  3365. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  3366. {
  3367. //更新源头单据数量
  3368. ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3369. BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription<DBValue>();
  3370. }
  3371. #endregion
  3372. #region 委外退料
  3373. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  3374. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  3375. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  3376. {
  3377. //更新源头单据数量
  3378. ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
  3379. BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  3380. }
  3381. #endregion
  3382. #region 返工工单
  3383. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  3384. {
  3385. //更新源头单据数量
  3386. ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>(), cmd, language);
  3387. BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>();
  3388. }
  3389. #endregion
  3390. #region 委外入库
  3391. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  3392. {
  3393. //更新源头单据数量
  3394. ICSOutsourcingService.OutsourcingReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3395. BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>();
  3396. }
  3397. #endregion
  3398. #region 生产退料
  3399. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  3400. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  3401. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  3402. {
  3403. log.Debug("生产退料1" + TransTypeEnum.MOIssueDocNegative.GetDescription());
  3404. log.Debug("生产退料2" + TransTypeEnum.MOIssueDocNegativeApply.GetDescription());
  3405. log.Debug("生产退料3" + TransTypeEnum.MOIssueDocNegativeIssue.GetDescription());
  3406. log.Debug("生产退料4"+TransType);
  3407. //更新源头单据数量
  3408. ICSManufactureService.MOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3409. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  3410. log.Debug("生产退料5");
  3411. }
  3412. #endregion
  3413. #region 生产入库
  3414. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  3415. {
  3416. log.Debug("生产入库" + TransType);
  3417. //更新源头单据数量
  3418. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3419. BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  3420. }
  3421. #endregion
  3422. #region 开立的生产入库单
  3423. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  3424. {
  3425. //更新源头单据数量
  3426. ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3427. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  3428. }
  3429. #endregion
  3430. #region 销售退货
  3431. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  3432. {
  3433. //更新源头单据数量
  3434. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3435. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  3436. }
  3437. #endregion
  3438. #region 其他入库
  3439. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  3440. {
  3441. //更新源头单据数量
  3442. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3443. BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  3444. }
  3445. #endregion
  3446. #region 拆卸单
  3447. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  3448. {
  3449. ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3450. WHTransType = "11";
  3451. BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription<DBValue>();
  3452. }
  3453. #endregion
  3454. #region 归还
  3455. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  3456. {
  3457. //更新源头单据数量
  3458. ICSWareHouseService.ReturnDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3459. BusinessCode = TransTypeEnum.ReturnDoc.GetDescription<DBValue>();
  3460. }
  3461. #endregion
  3462. #region 不合格入库
  3463. else if (TransType == TransTypeEnum.UnqualifiedIN.GetDescription())
  3464. {
  3465. string sql = @"SELECT b.Type FROM ICSInventoryLot a
  3466. LEFT JOIN ICSInventoryLot b ON a.EATTRIBUTE1=b.LotNo AND b.WorkPoint=a.WorkPoint
  3467. WHERE a.LotNo='{0}' AND a.Type='17' AND a.WorkPoint='{1}'";
  3468. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint);
  3469. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3470. if (dt.Rows.Count != 0)
  3471. {
  3472. TransTypeOriginal = dt.Rows[0]["Type"].ToString();
  3473. }
  3474. if (TransTypeOriginal == string.Empty)
  3475. {
  3476. //throw new Exception(language.GetNameByCode(""));
  3477. throw new Exception("未查询到条码" + itemInfo.LotNo + "的原条码");
  3478. }
  3479. #region 审核的到货单
  3480. else if (TransTypeOriginal == "7")
  3481. {
  3482. //更新源头单据数量
  3483. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3484. //BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  3485. TransTypeOriginal = TransTypeEnum.DeliveryNotice.GetDescription();
  3486. }
  3487. #endregion
  3488. #region 审核的委外到货单
  3489. else if (TransTypeOriginal == "8")
  3490. {
  3491. //更新源头单据数量
  3492. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3493. //BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  3494. TransTypeOriginal = TransTypeEnum.ODeliveryNotice.GetDescription();
  3495. }
  3496. #endregion
  3497. #region 委外退料
  3498. else if (TransTypeOriginal == "2"
  3499. || TransTypeOriginal == "14"
  3500. || TransTypeOriginal == "15")
  3501. {
  3502. //更新源头单据数量
  3503. ICSOutsourcingService.OutsourcingIssueDoNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
  3504. //BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  3505. TransTypeOriginal = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription();
  3506. }
  3507. #endregion
  3508. #region 生产退料
  3509. else if (TransTypeOriginal == "1"
  3510. || TransTypeOriginal == "12"
  3511. || TransTypeOriginal == "13")
  3512. {
  3513. log.Debug("生产退料1" + TransTypeEnum.MOIssueDocNegative.GetDescription());
  3514. log.Debug("生产退料2" + TransTypeEnum.MOIssueDocNegativeApply.GetDescription());
  3515. log.Debug("生产退料3" + TransTypeEnum.MOIssueDocNegativeIssue.GetDescription());
  3516. log.Debug("生产退料4" + TransTypeOriginal);
  3517. //更新源头单据数量
  3518. ICSManufactureService.MOIssueDocNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3519. //BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  3520. TransTypeOriginal = TransTypeEnum.MOIssueDocNegative.GetDescription();
  3521. }
  3522. #endregion
  3523. #region 生产入库
  3524. else if (TransTypeOriginal == "3")
  3525. {
  3526. log.Debug("生产入库" + TransTypeOriginal);
  3527. //更新源头单据数量
  3528. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3529. //BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  3530. TransTypeOriginal = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
  3531. }
  3532. #endregion
  3533. #region 销售退货
  3534. else if (TransTypeOriginal == "4")
  3535. {
  3536. //更新源头单据数量
  3537. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3538. //BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  3539. TransTypeOriginal = TransTypeEnum.SalesShipmentDocNegative.GetDescription();
  3540. }
  3541. #endregion
  3542. #region 其他入库
  3543. else if (TransTypeOriginal == "5")
  3544. {
  3545. //更新源头单据数量
  3546. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3547. //BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  3548. TransTypeOriginal = TransTypeEnum.OtherInDoc.GetDescription();
  3549. }
  3550. #endregion
  3551. BusinessCode = TransTypeEnum.UnqualifiedIN.GetDescription<DBValue>();
  3552. }
  3553. #endregion
  3554. #region 副产品入库
  3555. else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
  3556. {
  3557. log.Debug("副产品入库" + TransType);
  3558. //更新源头单据数量
  3559. ICSManufactureService.MOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3560. BusinessCode = TransTypeEnum.MOStockINByProduct.GetDescription<DBValue>();
  3561. }
  3562. #endregion
  3563. #region 委外副产品入库
  3564. else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  3565. {
  3566. log.Debug("副产品入库" + TransType);
  3567. //更新源头单据数量
  3568. ICSManufactureService.OOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3569. BusinessCode = TransTypeEnum.OOStockINByProduct.GetDescription<DBValue>();
  3570. }
  3571. #endregion
  3572. #region 副产品入库(无源头)
  3573. else if (TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
  3574. {
  3575. log.Debug("无源头副产品入库" + TransType);
  3576. //更新源头单据数量
  3577. //ICSManufactureService.MOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3578. BusinessCode = TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>();
  3579. }
  3580. #endregion
  3581. else
  3582. {
  3583. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  3584. }
  3585. //入库
  3586. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  3587. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language,itemInfo.LogID,itemInfo.InvCode + itemInfo.WarehouseCode, itemInfo.TransCode, itemInfo.TransSequence);
  3588. }
  3589. }
  3590. #region 拆卸单
  3591. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  3592. {
  3593. //更新套件锁定数量
  3594. ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
  3595. }
  3596. #endregion}
  3597. }
  3598. //上传ERP
  3599. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  3600. {
  3601. if (TransTypeOriginal != string.Empty)
  3602. {
  3603. TransType = TransTypeOriginal;
  3604. }
  3605. //采购入库
  3606. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  3607. {
  3608. if (DBHelper.IsU9())
  3609. { ICSPurchaseService.CreatePOArriveERP(TransType, Identification, cmd, language, BusinessCode,"RCV01"); }
  3610. else
  3611. { ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language, BusinessCode); }
  3612. }
  3613. //审核的到货单
  3614. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  3615. dtable = ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  3616. //采购拒收
  3617. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  3618. ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  3619. //审核的委外到货单
  3620. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  3621. ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  3622. //委外拒收
  3623. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  3624. ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  3625. //委外退料
  3626. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  3627. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  3628. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  3629. ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  3630. //委外入库
  3631. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  3632. {
  3633. if (DBHelper.IsU9())
  3634. { ICSOutsourcingService.CreateOOArriveERP(TransType, Identification, cmd, language, BusinessCode, "RCV11"); }
  3635. else { ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language, BusinessCode); }
  3636. }
  3637. //生产退料
  3638. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  3639. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  3640. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  3641. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  3642. //生产入库
  3643. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  3644. ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language,BusinessCode);
  3645. //副产品入库
  3646. else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
  3647. ICSManufactureService.MOStockINByProductDocERP(TransType, Identification, cmd, language,BusinessCode);
  3648. //委外副产品入库
  3649. else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  3650. ICSManufactureService.OOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
  3651. //无源头副产品入库
  3652. else if (TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
  3653. ICSManufactureService.MOStockINByProductNoTransDocERP(TransType, Identification, cmd, language, BusinessCode);
  3654. //开立的生产入库单
  3655. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  3656. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  3657. //返工工单
  3658. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  3659. ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language, BusinessCode);
  3660. //销售退货
  3661. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  3662. ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  3663. //两步调入
  3664. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  3665. ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
  3666. //销售退货-原条码
  3667. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  3668. ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language, BusinessCode);
  3669. //其他入库
  3670. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  3671. {
  3672. if (DBHelper.IsU9())
  3673. ICSWareHouseService.CreateOtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
  3674. else
  3675. ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
  3676. }
  3677. //拆卸单
  3678. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  3679. ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language, BusinessCode);
  3680. //归还
  3681. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  3682. ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language, BusinessCode);
  3683. }
  3684. if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  3685. {
  3686. cmd.Transaction.Commit();
  3687. return dtable;
  3688. }
  3689. else
  3690. {
  3691. DataTable table = GetData(Identification, 1, cmd);
  3692. cmd.Transaction.Commit();
  3693. return table;
  3694. }
  3695. }
  3696. catch (Exception ex)
  3697. {
  3698. if (cmd.Transaction != null)
  3699. cmd.Transaction.Rollback();
  3700. log.Error(ex.Message);
  3701. throw new Exception(ex.Message);
  3702. }
  3703. finally
  3704. {
  3705. if (conn.State == ConnectionState.Open)
  3706. {
  3707. conn.Close();
  3708. }
  3709. conn.Dispose();
  3710. }
  3711. }
  3712. }
  3713. /// <summary>
  3714. /// 上架(奥美专用)
  3715. /// </summary>BusinessCode,TransType 两个类型
  3716. /// <param name="JsonData"></param>
  3717. /// <returns></returns>
  3718. public static DataTable LOTStockCreateAM(List<LOTStockUpCreateIModel> JsonData)
  3719. {
  3720. var language = LanguageHelper.GetName("WMSAPIInfo");
  3721. if (JsonData.Count <= 0)
  3722. {
  3723. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3724. }
  3725. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3726. {
  3727. conn.Open();
  3728. SqlTransaction sqlTran = conn.BeginTransaction();
  3729. SqlCommand cmd = new SqlCommand();
  3730. cmd.Transaction = sqlTran;
  3731. cmd.Connection = conn;
  3732. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  3733. string BusinessCode = string.Empty;
  3734. try
  3735. {
  3736. string TransType = string.Empty;
  3737. DataTable dtable = new DataTable();
  3738. string TransTypeOriginal = string.Empty;//记录不合格入库条码的原条码的类型
  3739. string Identification = Guid.NewGuid().ToString();
  3740. foreach (var item in JsonData)
  3741. {
  3742. TransType = item.TransType;
  3743. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  3744. {
  3745. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  3746. }
  3747. string WHTransType = "2";
  3748. foreach (var itemInfo in item.detail)
  3749. {
  3750. #region 两步调入
  3751. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  3752. {
  3753. //更新源头单据数量
  3754. ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3755. //入库
  3756. ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  3757. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  3758. }
  3759. #endregion
  3760. #region 销售退货-原条码
  3761. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  3762. {
  3763. //更新源头单据数量
  3764. ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3765. //入库
  3766. BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription<DBValue>();
  3767. //入库
  3768. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  3769. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode,"","");
  3770. //更新日志表源头单据信息
  3771. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  3772. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' AND TransCode='' AND TransSequence=''";
  3773. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  3774. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3775. {
  3776. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  3777. }
  3778. }
  3779. #endregion
  3780. else
  3781. {
  3782. #region 采购入库
  3783. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  3784. {
  3785. //更新源头单据数量
  3786. ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3787. BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription<DBValue>();
  3788. }
  3789. #endregion
  3790. #region 审核的到货单
  3791. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  3792. {
  3793. //更新源头单据数量
  3794. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3795. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  3796. }
  3797. #endregion
  3798. #region 采购拒收
  3799. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  3800. {
  3801. //更新源头单据数量
  3802. ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3803. BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription<DBValue>();
  3804. }
  3805. #endregion
  3806. #region 审核的委外到货单
  3807. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  3808. {
  3809. //更新源头单据数量
  3810. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3811. BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  3812. }
  3813. #endregion
  3814. #region 委外拒收
  3815. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  3816. {
  3817. //更新源头单据数量
  3818. ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3819. BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription<DBValue>();
  3820. }
  3821. #endregion
  3822. #region 委外退料
  3823. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  3824. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  3825. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  3826. {
  3827. //更新源头单据数量
  3828. ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
  3829. BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  3830. }
  3831. #endregion
  3832. #region 返工工单
  3833. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  3834. {
  3835. //更新源头单据数量
  3836. ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>(), cmd, language);
  3837. BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>();
  3838. }
  3839. #endregion
  3840. #region 委外入库
  3841. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  3842. {
  3843. //更新源头单据数量
  3844. ICSOutsourcingService.OutsourcingReceiveAMDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3845. BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>();
  3846. }
  3847. #endregion
  3848. #region 生产退料
  3849. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  3850. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  3851. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  3852. {
  3853. //工单行查子件信息
  3854. string chekkksql = @"select a.Sequence,a.InvCode FROM ICSMOPick a
  3855. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  3856. WHERE b.MOCode='{0}' AND b.Sequence='{2}' AND a.WorkPoint='{1}' ";
  3857. chekkksql = string.Format(chekkksql, itemInfo.TransCode, item.WorkPoint, itemInfo.TransSequence);
  3858. log.Debug("工单行查子件信息" + chekkksql);
  3859. DataTable dtaa = DBHelper.SQlReturnData(chekkksql, cmd);
  3860. //查询条码的物料
  3861. string cheklotsql = @"select a.InvCode FROM ICSInventoryLot a
  3862. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' ";
  3863. cheklotsql = string.Format(cheklotsql, itemInfo.LotNo, item.WorkPoint);
  3864. log.Debug("查询条码的物料" + cheklotsql);
  3865. DataTable lotdata = DBHelper.SQlReturnData(cheklotsql, cmd);
  3866. //DataTable ad0=dtaa.Select(a => a.invcode == lotdata.Rows[0]["InvCode"].ToString());
  3867. DataRow[] drs = dtaa.Select("InvCode ='" + lotdata.Rows[0]["InvCode"].ToString() + "'");
  3868. if (drs == null || drs.Length == 0)
  3869. {
  3870. throw new Exception("当前扫描的条码物料和单据子件物料没有匹配的行,请确认!");
  3871. }
  3872. //DataTable ad0 = dtaa.AsEnumerable()
  3873. //.Where(a => a.Field<string>("InvCode") == lotdata.Rows[0]["InvCode"].ToString())
  3874. //.CopyToDataTable();
  3875. //if (ad0 == null || ad0.Rows.Count == 0)
  3876. //{
  3877. // throw new Exception("当前扫描的条码物料和单据子件物料没有匹配的行,请确认!");
  3878. //}
  3879. string seq = itemInfo.TransSequence + "~" + drs[0]["Sequence"].ToString();
  3880. log.Debug("工单子件行号:" + seq);
  3881. string chekksql = @"select c.EATTRIBUTE1 FROM ICSMOPick a
  3882. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  3883. INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  3884. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
  3885. chekksql = string.Format(chekksql, itemInfo.TransCode, item.WorkPoint, itemInfo.Quantity, seq);
  3886. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  3887. if (dta.Rows.Count > 0)
  3888. {
  3889. itemInfo.Quantity = (decimal.Parse(itemInfo.Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  3890. }
  3891. //更新源头单据数量
  3892. ICSManufactureService.AMMOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint,itemInfo.TransCode, seq, cmd, language);
  3893. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  3894. log.Debug("生产退料5");
  3895. }
  3896. #endregion
  3897. #region 生产入库
  3898. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  3899. {
  3900. log.Debug("生产入库" + TransType);
  3901. //更新源头单据数量
  3902. ICSManufactureService.ManufactureReceiveDocAM(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3903. BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  3904. }
  3905. #endregion
  3906. #region 开立的生产入库单
  3907. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  3908. {
  3909. //更新源头单据数量
  3910. ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3911. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  3912. }
  3913. #endregion
  3914. #region 销售退货
  3915. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  3916. {
  3917. //更新源头单据数量
  3918. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3919. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  3920. }
  3921. #endregion
  3922. #region 其他入库
  3923. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  3924. {
  3925. //更新源头单据数量
  3926. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3927. BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  3928. }
  3929. #endregion
  3930. #region 拆卸单
  3931. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  3932. {
  3933. ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3934. WHTransType = "11";
  3935. BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription<DBValue>();
  3936. }
  3937. #endregion
  3938. #region 归还
  3939. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  3940. {
  3941. //更新源头单据数量
  3942. ICSWareHouseService.ReturnDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3943. BusinessCode = TransTypeEnum.ReturnDoc.GetDescription<DBValue>();
  3944. }
  3945. #endregion
  3946. #region 不合格入库
  3947. else if (TransType == TransTypeEnum.UnqualifiedIN.GetDescription())
  3948. {
  3949. string sql = @"SELECT b.Type FROM ICSInventoryLot a
  3950. LEFT JOIN ICSInventoryLot b ON a.EATTRIBUTE1=b.LotNo AND b.WorkPoint=a.WorkPoint
  3951. WHERE a.LotNo='{0}' AND a.Type='17' AND a.WorkPoint='{1}'";
  3952. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint);
  3953. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  3954. if (dt.Rows.Count != 0)
  3955. {
  3956. TransTypeOriginal = dt.Rows[0]["Type"].ToString();
  3957. }
  3958. if (TransTypeOriginal == string.Empty)
  3959. {
  3960. //throw new Exception(language.GetNameByCode(""));
  3961. throw new Exception("未查询到条码" + itemInfo.LotNo + "的原条码");
  3962. }
  3963. #region 审核的到货单
  3964. else if (TransTypeOriginal == "7")
  3965. {
  3966. //更新源头单据数量
  3967. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3968. //BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  3969. TransTypeOriginal = TransTypeEnum.DeliveryNotice.GetDescription();
  3970. }
  3971. #endregion
  3972. #region 审核的委外到货单
  3973. else if (TransTypeOriginal == "8")
  3974. {
  3975. //更新源头单据数量
  3976. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  3977. //BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  3978. TransTypeOriginal = TransTypeEnum.ODeliveryNotice.GetDescription();
  3979. }
  3980. #endregion
  3981. #region 委外退料
  3982. else if (TransTypeOriginal == "2"
  3983. || TransTypeOriginal == "14"
  3984. || TransTypeOriginal == "15")
  3985. {
  3986. //更新源头单据数量
  3987. ICSOutsourcingService.OutsourcingIssueDoNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, itemInfo.TransCode, itemInfo.TransSequence, cmd, language);
  3988. //BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  3989. TransTypeOriginal = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription();
  3990. }
  3991. #endregion
  3992. #region 生产退料
  3993. else if (TransTypeOriginal == "1"
  3994. || TransTypeOriginal == "12"
  3995. || TransTypeOriginal == "13")
  3996. {
  3997. log.Debug("生产退料1" + TransTypeEnum.MOIssueDocNegative.GetDescription());
  3998. log.Debug("生产退料2" + TransTypeEnum.MOIssueDocNegativeApply.GetDescription());
  3999. log.Debug("生产退料3" + TransTypeEnum.MOIssueDocNegativeIssue.GetDescription());
  4000. log.Debug("生产退料4" + TransTypeOriginal);
  4001. //更新源头单据数量
  4002. ICSManufactureService.MOIssueDocNegative(TransTypeOriginal, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4003. //BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  4004. TransTypeOriginal = TransTypeEnum.MOIssueDocNegative.GetDescription();
  4005. }
  4006. #endregion
  4007. #region 生产入库
  4008. else if (TransTypeOriginal == "3")
  4009. {
  4010. log.Debug("生产入库" + TransTypeOriginal);
  4011. //更新源头单据数量
  4012. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4013. //BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  4014. TransTypeOriginal = TransTypeEnum.ManufactureReceiveDoc.GetDescription();
  4015. }
  4016. #endregion
  4017. #region 销售退货
  4018. else if (TransTypeOriginal == "4")
  4019. {
  4020. //更新源头单据数量
  4021. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4022. //BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  4023. TransTypeOriginal = TransTypeEnum.SalesShipmentDocNegative.GetDescription();
  4024. }
  4025. #endregion
  4026. #region 其他入库
  4027. else if (TransTypeOriginal == "5")
  4028. {
  4029. //更新源头单据数量
  4030. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4031. //BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  4032. TransTypeOriginal = TransTypeEnum.OtherInDoc.GetDescription();
  4033. }
  4034. #endregion
  4035. BusinessCode = TransTypeEnum.UnqualifiedIN.GetDescription<DBValue>();
  4036. }
  4037. #endregion
  4038. #region 联副产品入库
  4039. else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
  4040. {
  4041. log.Debug("联副产品入库" + TransType);
  4042. //更新源头单据数量
  4043. ICSManufactureService.MOStockINByProductAMDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4044. BusinessCode = TransTypeEnum.MOStockINByProduct.GetDescription<DBValue>();
  4045. }
  4046. #endregion
  4047. #region 委外副产品入库
  4048. else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  4049. {
  4050. log.Debug("副产品入库" + TransType);
  4051. //更新源头单据数量
  4052. ICSManufactureService.OOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4053. BusinessCode = TransTypeEnum.OOStockINByProduct.GetDescription<DBValue>();
  4054. }
  4055. #endregion
  4056. #region 副产品入库(无源头)
  4057. else if (TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
  4058. {
  4059. log.Debug("无源头副产品入库" + TransType);
  4060. //更新源头单据数量
  4061. //ICSManufactureService.MOStockINByProductDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  4062. BusinessCode = TransTypeEnum.MOStockINByProductNoTrans.GetDescription<DBValue>();
  4063. }
  4064. #endregion
  4065. else
  4066. {
  4067. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  4068. }
  4069. //入库
  4070. ICSWareHouseLotInfoService.WareHouseLotInfoUpAM(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  4071. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, itemInfo.TransCode, itemInfo.TransSequence);
  4072. }
  4073. }
  4074. #region 拆卸单
  4075. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  4076. {
  4077. //更新套件锁定数量
  4078. ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
  4079. }
  4080. #endregion}
  4081. }
  4082. //上传ERP
  4083. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  4084. {
  4085. if (TransTypeOriginal != string.Empty)
  4086. {
  4087. TransType = TransTypeOriginal;
  4088. }
  4089. //采购入库
  4090. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  4091. ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  4092. //审核的到货单
  4093. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  4094. dtable = ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  4095. //采购拒收
  4096. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  4097. ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  4098. //审核的委外到货单
  4099. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  4100. ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  4101. //委外拒收
  4102. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  4103. ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  4104. //委外退料
  4105. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  4106. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  4107. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  4108. ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4109. //委外入库
  4110. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  4111. ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  4112. //生产退料
  4113. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  4114. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  4115. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  4116. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4117. //生产入库
  4118. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  4119. ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  4120. //副产品入库
  4121. else if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
  4122. ICSManufactureService.MOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
  4123. //委外副产品入库
  4124. else if (TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  4125. ICSManufactureService.OOStockINByProductDocERP(TransType, Identification, cmd, language, BusinessCode);
  4126. //无源头副产品入库
  4127. else if (TransType == TransTypeEnum.MOStockINByProductNoTrans.GetDescription())
  4128. ICSManufactureService.MOStockINByProductNoTransDocERP(TransType, Identification, cmd, language, BusinessCode);
  4129. //开立的生产入库单
  4130. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  4131. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  4132. //返工工单
  4133. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  4134. ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language, BusinessCode);
  4135. //销售退货
  4136. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  4137. ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4138. //两步调入
  4139. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  4140. ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
  4141. //销售退货-原条码
  4142. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  4143. ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language, BusinessCode);
  4144. //其他入库
  4145. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  4146. ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
  4147. //拆卸单
  4148. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  4149. ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language, BusinessCode);
  4150. //归还
  4151. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  4152. ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language, BusinessCode);
  4153. }
  4154. if(TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  4155. {
  4156. cmd.Transaction.Commit();
  4157. return dtable;
  4158. }
  4159. else
  4160. {
  4161. DataTable table = GetData(Identification, 1, cmd);
  4162. cmd.Transaction.Commit();
  4163. return table;
  4164. }
  4165. }
  4166. catch (Exception ex)
  4167. {
  4168. if (cmd.Transaction != null)
  4169. cmd.Transaction.Rollback();
  4170. log.Error(ex.Message);
  4171. throw new Exception(ex.Message);
  4172. }
  4173. finally
  4174. {
  4175. if (conn.State == ConnectionState.Open)
  4176. {
  4177. conn.Close();
  4178. }
  4179. conn.Dispose();
  4180. }
  4181. }
  4182. }
  4183. /// <summary>
  4184. /// 下架
  4185. /// </summary>
  4186. /// <param name="JsonData"></param>
  4187. /// <returns></returns>
  4188. public static DataTable LOTStockDownCreate(List<LOTStockModel> JsonData)
  4189. {
  4190. String PrintEnable = "";
  4191. var language = LanguageHelper.GetName("WMSAPIInfo");
  4192. if (JsonData.Count <= 0)
  4193. {
  4194. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4195. }
  4196. List<LOTStockModelList> model = new List<LOTStockModelList>();
  4197. DataTable printTable = new DataTable();
  4198. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4199. {
  4200. conn.Open();
  4201. SqlTransaction sqlTran = conn.BeginTransaction();
  4202. SqlCommand cmd = new SqlCommand();
  4203. cmd.Transaction = sqlTran;
  4204. cmd.Connection = conn;
  4205. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  4206. string BusinessCode = string.Empty;
  4207. try
  4208. {
  4209. string TransType = string.Empty;
  4210. string Identification = Guid.NewGuid().ToString();
  4211. foreach (var item in JsonData)
  4212. {
  4213. TransType = item.TransType;
  4214. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  4215. {
  4216. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  4217. }
  4218. else if (string.IsNullOrEmpty(item.TransCode))
  4219. {
  4220. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  4221. }
  4222. string[] trans = item.TransCode.Split('~');
  4223. string MergeID = "";
  4224. if (trans.Length == 2)
  4225. {
  4226. MergeID = trans[0];
  4227. item.TransCode = trans[1];
  4228. }
  4229. #region 采购退货
  4230. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  4231. {
  4232. BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>();
  4233. //更新源头单据数量
  4234. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4235. foreach (var itemInfo in item.detail)
  4236. {
  4237. //出库
  4238. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4239. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, "");
  4240. }
  4241. }
  4242. #endregion
  4243. #region 委外发料
  4244. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  4245. {
  4246. BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>();
  4247. //更新源头单据数量
  4248. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language,enableCode);
  4249. foreach (var itemInfo in item.detail)
  4250. {
  4251. //出库
  4252. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4253. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4254. }
  4255. }
  4256. #endregion
  4257. #region 委外退货
  4258. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  4259. {
  4260. BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>();
  4261. //更新源头单据数量
  4262. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4263. foreach (var itemInfo in item.detail)
  4264. {
  4265. //出库
  4266. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4267. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, "");
  4268. }
  4269. }
  4270. #endregion
  4271. #region 生产发料
  4272. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  4273. {
  4274. BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription<DBValue>();
  4275. //更新源头单据数量
  4276. ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language,enableCode);
  4277. foreach (var itemInfo in item.detail)
  4278. {
  4279. //出库
  4280. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4281. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4282. }
  4283. }
  4284. #endregion
  4285. #region 销售出库
  4286. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  4287. {
  4288. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  4289. //更新源头单据数量
  4290. ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4291. foreach (var itemInfo in item.detail)
  4292. {
  4293. //出库
  4294. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4295. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4296. }
  4297. }
  4298. #endregion
  4299. #region 两步调出
  4300. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  4301. {
  4302. BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>();
  4303. //更新源头单据数量
  4304. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4305. foreach (var itemInfo in item.detail)
  4306. {
  4307. //出库
  4308. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4309. item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4310. }
  4311. }
  4312. #endregion
  4313. #region 其他出库
  4314. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  4315. {
  4316. BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription<DBValue>();
  4317. //更新源头单据数量
  4318. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4319. foreach (var itemInfo in item.detail)
  4320. {
  4321. //出库
  4322. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4323. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4324. }
  4325. }
  4326. #endregion
  4327. #region 领料申请单发料
  4328. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  4329. {
  4330. BusinessCode = TransTypeEnum.MOApply.GetDescription<DBValue>();
  4331. //更新源头单据数量
  4332. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
  4333. foreach (var itemInfo in item.detail)
  4334. {
  4335. //出库
  4336. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4337. item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4338. }
  4339. }
  4340. #endregion
  4341. #region 补料申请单发料
  4342. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  4343. {
  4344. BusinessCode = TransTypeEnum.MOReplenishment.GetDescription<DBValue>();
  4345. //更新源头单据数量
  4346. ICSManufactureService.MOReplenishment(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
  4347. foreach (var itemInfo in item.detail)
  4348. {
  4349. //出库
  4350. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4351. item.User, item.WorkPoint, "3", TransTypeEnum.MOReplenishment.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4352. }
  4353. }
  4354. #endregion
  4355. #region 委外领料申请单发料
  4356. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  4357. {
  4358. BusinessCode = TransTypeEnum.OOApply.GetDescription<DBValue>();
  4359. //更新源头单据数量
  4360. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language,enableCode);
  4361. foreach (var itemInfo in item.detail)
  4362. {
  4363. //出库
  4364. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4365. item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4366. }
  4367. }
  4368. #endregion
  4369. #region 开立材料出库
  4370. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  4371. {
  4372. BusinessCode = TransTypeEnum.MOIssue.GetDescription<DBValue>();
  4373. //更新源头单据数量
  4374. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4375. foreach (var itemInfo in item.detail)
  4376. {
  4377. //出库
  4378. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4379. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4380. }
  4381. }
  4382. #endregion
  4383. #region 开立委外材料出库
  4384. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  4385. {
  4386. BusinessCode = TransTypeEnum.OOIssue.GetDescription<DBValue>();
  4387. //更新源头单据数量
  4388. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4389. foreach (var itemInfo in item.detail)
  4390. {
  4391. //出库
  4392. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4393. item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4394. }
  4395. }
  4396. #endregion
  4397. #region 开立红字入库单
  4398. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  4399. {
  4400. BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription<DBValue>();
  4401. //更新源头单据数量
  4402. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4403. foreach (var itemInfo in item.detail)
  4404. {
  4405. //出库
  4406. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4407. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, "");
  4408. }
  4409. }
  4410. #endregion
  4411. #region 开立委外红字入库单
  4412. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  4413. {
  4414. BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>();
  4415. //更新源头单据数量
  4416. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4417. foreach (var itemInfo in item.detail)
  4418. {
  4419. //出库
  4420. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4421. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, "");
  4422. }
  4423. }
  4424. #endregion
  4425. #region 借用
  4426. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  4427. {
  4428. BusinessCode = TransTypeEnum.BrrowDoc.GetDescription<DBValue>();
  4429. //更新源头单据数量
  4430. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4431. foreach (var itemInfo in item.detail)
  4432. {
  4433. //出库
  4434. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4435. item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4436. }
  4437. }
  4438. #endregion
  4439. else
  4440. {
  4441. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  4442. }
  4443. }
  4444. //上传ERP
  4445. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  4446. {
  4447. //采购退货
  4448. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  4449. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4450. //委外发料
  4451. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  4452. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  4453. //委外退货
  4454. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  4455. {
  4456. if (DBHelper.IsU9())
  4457. { ICSOutsourcingService.U9OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode); }
  4458. else
  4459. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
  4460. }
  4461. //生产发料
  4462. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  4463. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  4464. //销售出库
  4465. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  4466. {
  4467. if (DBHelper.IsU9())
  4468. { ICSSalesService.U9SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
  4469. else { ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
  4470. }
  4471. //两步调出
  4472. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  4473. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
  4474. //其他出库
  4475. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  4476. {
  4477. if (DBHelper.IsU9())
  4478. {
  4479. ICSWareHouseService.CreateOtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  4480. }
  4481. else
  4482. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  4483. }
  4484. //领料申请单发料
  4485. if (TransType == TransTypeEnum.MOApply.GetDescription())
  4486. {
  4487. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  4488. }
  4489. //补料申请单发料
  4490. if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  4491. ICSManufactureService.MOReplenishmentERP(TransType, Identification, cmd, language, BusinessCode);
  4492. //委外领料申请单发料
  4493. if (TransType == TransTypeEnum.OOApply.GetDescription())
  4494. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  4495. //开立材料出库
  4496. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  4497. {
  4498. if (DBHelper.IsU9())
  4499. { ICSManufactureService.U9MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
  4500. else { ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
  4501. }
  4502. //开立委外材料出库
  4503. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  4504. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  4505. //开立红字入库单
  4506. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  4507. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  4508. //开立委外红字入库单
  4509. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  4510. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4511. //借用
  4512. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  4513. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
  4514. }
  4515. if (!printTable.Equals("{}"))
  4516. {
  4517. cmd.Transaction.Commit();
  4518. return printTable;
  4519. }
  4520. else
  4521. {
  4522. DataTable table = GetData(Identification, 2, cmd);
  4523. cmd.Transaction.Commit();
  4524. return table;
  4525. }
  4526. }
  4527. catch (Exception ex)
  4528. {
  4529. if (cmd.Transaction != null)
  4530. cmd.Transaction.Rollback();
  4531. log.Error(ex.Message);
  4532. throw new Exception(ex.Message);
  4533. }
  4534. finally
  4535. {
  4536. if (conn.State == ConnectionState.Open)
  4537. {
  4538. conn.Close();
  4539. }
  4540. conn.Dispose();
  4541. }
  4542. }
  4543. }
  4544. /// <summary>
  4545. /// 下架
  4546. /// </summary>
  4547. /// <param name="JsonData"></param>
  4548. /// <returns></returns>
  4549. public static DataTable LOTStockDownAMCreate(List<LOTStockModel> JsonData)
  4550. {
  4551. String PrintEnable = "";
  4552. var language = LanguageHelper.GetName("WMSAPIInfo");
  4553. if (JsonData.Count <= 0)
  4554. {
  4555. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4556. }
  4557. List<LOTStockModelList> model = new List<LOTStockModelList>();
  4558. DataTable printTable = new DataTable();
  4559. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4560. {
  4561. conn.Open();
  4562. SqlTransaction sqlTran = conn.BeginTransaction();
  4563. SqlCommand cmd = new SqlCommand();
  4564. cmd.Transaction = sqlTran;
  4565. cmd.Connection = conn;
  4566. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  4567. string BusinessCode = string.Empty;
  4568. try
  4569. {
  4570. string TransType = string.Empty;
  4571. string Identification = Guid.NewGuid().ToString();
  4572. foreach (var item in JsonData)
  4573. {
  4574. TransType = item.TransType;
  4575. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  4576. {
  4577. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  4578. }
  4579. else if (string.IsNullOrEmpty(item.TransCode))
  4580. {
  4581. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  4582. }
  4583. string[] trans = item.TransCode.Split('~');
  4584. string MergeID = "";
  4585. if (trans.Length == 2)
  4586. {
  4587. MergeID = trans[0];
  4588. item.TransCode = trans[1];
  4589. }
  4590. #region 采购退货
  4591. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  4592. {
  4593. BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>();
  4594. //更新源头单据数量
  4595. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4596. foreach (var itemInfo in item.detail)
  4597. {
  4598. //出库
  4599. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4600. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, "");
  4601. }
  4602. }
  4603. #endregion
  4604. #region 委外发料
  4605. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  4606. {
  4607. BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>();
  4608. //更新源头单据数量
  4609. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
  4610. foreach (var itemInfo in item.detail)
  4611. {
  4612. //出库
  4613. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4614. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4615. }
  4616. }
  4617. #endregion
  4618. #region 委外退货
  4619. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  4620. {
  4621. BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>();
  4622. //更新源头单据数量
  4623. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4624. foreach (var itemInfo in item.detail)
  4625. {
  4626. //出库
  4627. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4628. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, "");
  4629. }
  4630. }
  4631. #endregion
  4632. #region 生产发料
  4633. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  4634. {
  4635. BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription<DBValue>();
  4636. //工单行查子件信息
  4637. string chekkksql = @"select a.Sequence,a.InvCode FROM ICSMOPick a
  4638. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  4639. WHERE b.MOCode='{0}' AND b.Sequence='{2}' AND a.WorkPoint='{1}' ";
  4640. chekkksql = string.Format(chekkksql, item.TransCode, item.WorkPoint, item.TransSequence);
  4641. log.Debug("工单行查子件信息" + chekkksql);
  4642. DataTable dtaa = DBHelper.SQlReturnData(chekkksql, cmd);
  4643. //ICSManufactureService.AMMOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
  4644. foreach (var itemInfo in item.detail)
  4645. {
  4646. //查询条码的物料
  4647. string cheklotsql = @"select a.InvCode FROM ICSInventoryLot a
  4648. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' ";
  4649. cheklotsql = string.Format(cheklotsql, itemInfo.LotNo, item.WorkPoint);
  4650. log.Debug("查询条码的物料" + cheklotsql);
  4651. DataTable lotdata = DBHelper.SQlReturnData(cheklotsql, cmd);
  4652. //DataTable ad0=dtaa.Select(a => a.invcode == lotdata.Rows[0]["InvCode"].ToString());
  4653. DataRow[] drs = dtaa.Select("InvCode ='" + lotdata.Rows[0]["InvCode"].ToString() + "'");
  4654. if (drs==null||drs.Length==0)
  4655. {
  4656. throw new Exception("当前扫描的条码物料和单据子件物料没有匹配的行,请确认!");
  4657. }
  4658. //DataTable ad0 = dtaa.AsEnumerable()
  4659. //.Where(a => a.Field<string>("InvCode") == lotdata.Rows[0]["InvCode"].ToString())
  4660. //.CopyToDataTable();
  4661. //if (ad0 == null || ad0.Rows.Count == 0)
  4662. //{
  4663. // throw new Exception("当前扫描的条码物料和单据子件物料没有匹配的行,请确认!");
  4664. //}
  4665. string seq = item.TransSequence + "~" + drs[0]["Sequence"].ToString();
  4666. log.Debug("工单子件行号:" + seq);
  4667. //判断是否开启辅计量,计算辅计量比例
  4668. string chekksql = @"select c.EATTRIBUTE1 FROM ICSMOPick a
  4669. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  4670. INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  4671. WHERE b.MOCode='{0}' AND b.Sequence+'~'+a.Sequence='{3}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
  4672. chekksql = string.Format(chekksql, item.TransCode, item.WorkPoint, itemInfo.CurrentQuantity, seq);
  4673. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  4674. if (dta.Rows.Count > 0)
  4675. {
  4676. itemInfo.CurrentQuantity = (decimal.Parse(itemInfo.CurrentQuantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  4677. }
  4678. //更新源头单据数量
  4679. ICSManufactureService.AMMOIssueDoc(item.TransCode, seq, itemInfo.CurrentQuantity, item.WorkPoint, cmd, language, enableCode);
  4680. //出库
  4681. printTable = ICSWareHouseLotInfoService.AMWareHouseLotInfoDown(Identification, item.TransCode, seq, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4682. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4683. }
  4684. }
  4685. #endregion
  4686. #region 销售出库
  4687. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  4688. {
  4689. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  4690. //出库
  4691. //出库
  4692. string chekkksql = @"select a.Sequence,a.InvCode FROM ICSSDN a
  4693. WHERE a.SDNCode='{0}' AND a.WorkPoint='{1}' ";
  4694. chekkksql = string.Format(chekkksql, item.TransCode, item.WorkPoint);
  4695. log.Debug("销售发货单行信息" + chekkksql);
  4696. DataTable dtaa = DBHelper.SQlReturnData(chekkksql, cmd);
  4697. foreach (var itemInfo in item.detail)
  4698. {
  4699. //查询条码的物料
  4700. string cheklotsql = @"select a.InvCode FROM ICSInventoryLot a
  4701. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' ";
  4702. cheklotsql = string.Format(cheklotsql, itemInfo.LotNo, item.WorkPoint);
  4703. log.Debug("查询条码的物料" + cheklotsql);
  4704. DataTable lotdata = DBHelper.SQlReturnData(cheklotsql, cmd);
  4705. //DataTable ad0=dtaa.Select(a => a.invcode == lotdata.Rows[0]["InvCode"].ToString());
  4706. DataRow[] drs = dtaa.Select("InvCode ='" + lotdata.Rows[0]["InvCode"].ToString() + "'");
  4707. if (drs == null || drs.Length == 0)
  4708. {
  4709. throw new Exception("当前扫描的条码物料和单据物料没有匹配的行,请确认!");
  4710. }
  4711. //DataTable ad0 = dtaa.AsEnumerable()
  4712. //.Where(a => a.Field<string>("InvCode") == lotdata.Rows[0]["InvCode"].ToString())
  4713. //.CopyToDataTable();
  4714. //if (ad0 == null || ad0.Rows.Count == 0)
  4715. //{
  4716. // throw new Exception("当前扫描的条码物料和单据子件物料没有匹配的行,请确认!");
  4717. //}
  4718. string seq = drs[0]["Sequence"].ToString();
  4719. log.Debug("销售发货单行号:" + seq);
  4720. string chekksql = @"select c.EATTRIBUTE1 FROM ICSSDN a
  4721. INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  4722. WHERE a.SDNCode='{0}' AND a.Sequence='{2}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
  4723. chekksql = string.Format(chekksql, item.TransCode, item.WorkPoint, seq);
  4724. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  4725. if (dta.Rows.Count > 0)
  4726. {
  4727. itemInfo.CurrentQuantity = (decimal.Parse(itemInfo.CurrentQuantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  4728. }
  4729. log.Debug("本次数量:" + itemInfo.CurrentQuantity);
  4730. //更新源头单据数量
  4731. ICSSalesService.AMSalesShipmentDoc(item.TransCode, seq, itemInfo.CurrentQuantity, item.WorkPoint, cmd, language);
  4732. printTable = ICSWareHouseLotInfoService.AMWareHouseLotInfoDown(Identification, item.TransCode, seq, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4733. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4734. }
  4735. }
  4736. #endregion
  4737. #region 两步调出
  4738. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  4739. {
  4740. BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>();
  4741. //更新源头单据数量
  4742. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4743. foreach (var itemInfo in item.detail)
  4744. {
  4745. //出库
  4746. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4747. item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4748. }
  4749. }
  4750. #endregion
  4751. #region 其他出库
  4752. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  4753. {
  4754. BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription<DBValue>();
  4755. //更新源头单据数量
  4756. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4757. foreach (var itemInfo in item.detail)
  4758. {
  4759. //出库
  4760. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4761. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4762. }
  4763. }
  4764. #endregion
  4765. #region 领料申请单发料
  4766. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  4767. {
  4768. BusinessCode = TransTypeEnum.MOApply.GetDescription<DBValue>();
  4769. //更新源头单据数量
  4770. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
  4771. foreach (var itemInfo in item.detail)
  4772. {
  4773. //出库
  4774. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4775. item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4776. }
  4777. }
  4778. #endregion
  4779. #region 补料申请单发料
  4780. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  4781. {
  4782. BusinessCode = TransTypeEnum.MOReplenishment.GetDescription<DBValue>();
  4783. //更新源头单据数量
  4784. ICSManufactureService.MOReplenishment(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
  4785. foreach (var itemInfo in item.detail)
  4786. {
  4787. //出库
  4788. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4789. item.User, item.WorkPoint, "3", TransTypeEnum.MOReplenishment.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4790. }
  4791. }
  4792. #endregion
  4793. #region 委外领料申请单发料
  4794. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  4795. {
  4796. BusinessCode = TransTypeEnum.OOApply.GetDescription<DBValue>();
  4797. //更新源头单据数量
  4798. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language, enableCode);
  4799. foreach (var itemInfo in item.detail)
  4800. {
  4801. //出库
  4802. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4803. item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4804. }
  4805. }
  4806. #endregion
  4807. #region 开立材料出库
  4808. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  4809. {
  4810. BusinessCode = TransTypeEnum.MOIssue.GetDescription<DBValue>();
  4811. //更新源头单据数量
  4812. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4813. foreach (var itemInfo in item.detail)
  4814. {
  4815. //出库
  4816. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4817. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4818. }
  4819. }
  4820. #endregion
  4821. #region 开立委外材料出库
  4822. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  4823. {
  4824. BusinessCode = TransTypeEnum.OOIssue.GetDescription<DBValue>();
  4825. //更新源头单据数量
  4826. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4827. foreach (var itemInfo in item.detail)
  4828. {
  4829. //出库
  4830. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4831. item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4832. }
  4833. }
  4834. #endregion
  4835. #region 开立红字入库单
  4836. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  4837. {
  4838. BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription<DBValue>();
  4839. //更新源头单据数量
  4840. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4841. foreach (var itemInfo in item.detail)
  4842. {
  4843. //出库
  4844. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4845. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, "");
  4846. }
  4847. }
  4848. #endregion
  4849. #region 开立委外红字入库单
  4850. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  4851. {
  4852. BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>();
  4853. //更新源头单据数量
  4854. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4855. foreach (var itemInfo in item.detail)
  4856. {
  4857. //出库
  4858. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4859. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, "");
  4860. }
  4861. }
  4862. #endregion
  4863. #region 借用
  4864. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  4865. {
  4866. BusinessCode = TransTypeEnum.BrrowDoc.GetDescription<DBValue>();
  4867. //更新源头单据数量
  4868. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  4869. foreach (var itemInfo in item.detail)
  4870. {
  4871. //出库
  4872. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  4873. item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, itemInfo.LogID, MergeID);
  4874. }
  4875. }
  4876. #endregion
  4877. else
  4878. {
  4879. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  4880. }
  4881. }
  4882. //上传ERP
  4883. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  4884. {
  4885. //采购退货
  4886. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  4887. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4888. //委外发料
  4889. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  4890. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  4891. //委外退货
  4892. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  4893. {
  4894. if (DBHelper.IsU9())
  4895. { ICSOutsourcingService.U9OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode); }
  4896. else
  4897. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
  4898. }
  4899. //生产发料
  4900. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  4901. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  4902. //销售出库
  4903. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  4904. {
  4905. if (DBHelper.IsU9())
  4906. { ICSSalesService.U9SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
  4907. else { ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode); }
  4908. }
  4909. //两步调出
  4910. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  4911. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
  4912. //其他出库
  4913. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  4914. {
  4915. if (DBHelper.IsU9())
  4916. {
  4917. ICSWareHouseService.CreateOtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  4918. }
  4919. else
  4920. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  4921. }
  4922. //领料申请单发料
  4923. if (TransType == TransTypeEnum.MOApply.GetDescription())
  4924. {
  4925. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  4926. }
  4927. //补料申请单发料
  4928. if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  4929. ICSManufactureService.MOReplenishmentERP(TransType, Identification, cmd, language, BusinessCode);
  4930. //委外领料申请单发料
  4931. if (TransType == TransTypeEnum.OOApply.GetDescription())
  4932. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  4933. //开立材料出库
  4934. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  4935. {
  4936. if (DBHelper.IsU9())
  4937. { ICSManufactureService.U9MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
  4938. else { ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode); }
  4939. }
  4940. //开立委外材料出库
  4941. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  4942. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  4943. //开立红字入库单
  4944. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  4945. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  4946. //开立委外红字入库单
  4947. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  4948. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  4949. //借用
  4950. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  4951. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
  4952. }
  4953. if (!printTable.Equals("{}"))
  4954. {
  4955. cmd.Transaction.Commit();
  4956. return printTable;
  4957. }
  4958. else
  4959. {
  4960. DataTable table = GetData(Identification, 2, cmd);
  4961. cmd.Transaction.Commit();
  4962. return table;
  4963. }
  4964. }
  4965. catch (Exception ex)
  4966. {
  4967. if (cmd.Transaction != null)
  4968. cmd.Transaction.Rollback();
  4969. log.Error(ex.Message);
  4970. throw new Exception(ex.Message);
  4971. }
  4972. finally
  4973. {
  4974. if (conn.State == ConnectionState.Open)
  4975. {
  4976. conn.Close();
  4977. }
  4978. conn.Dispose();
  4979. }
  4980. }
  4981. }
  4982. #region 采购
  4983. /// <summary>
  4984. /// 采购到货
  4985. /// </summary>
  4986. /// <param name="JsonData"></param>
  4987. /// <returns></returns>
  4988. public static DataTable DeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  4989. {
  4990. var language = LanguageHelper.GetName("WMSAPIInfo");
  4991. if (JsonData.Count <= 0)
  4992. {
  4993. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4994. }
  4995. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4996. {
  4997. conn.Open();
  4998. SqlTransaction sqlTran = conn.BeginTransaction();
  4999. SqlCommand cmd = new SqlCommand();
  5000. cmd.Transaction = sqlTran;
  5001. cmd.Connection = conn;
  5002. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  5003. try
  5004. {
  5005. string asncodes = string.Empty;
  5006. string sql = string.Empty;
  5007. foreach (var item in JsonData)
  5008. {
  5009. if (string.IsNullOrEmpty(item.ASNCode))
  5010. {
  5011. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
  5012. }
  5013. //获取单号
  5014. sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  5015. BEGIN
  5016. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  5017. RETURN
  5018. END
  5019. DECLARE @Status VARCHAR(10)
  5020. SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  5021. IF (@Status IS NULL)
  5022. BEGIN
  5023. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  5024. RETURN
  5025. END
  5026. ELSE IF (@Status!='2')
  5027. BEGIN
  5028. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  5029. RETURN
  5030. END
  5031. DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  5032. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  5033. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  5034. IF @MaxNO IS NULL
  5035. BEGIN
  5036. SELECT @date+'00001' AS Code
  5037. END
  5038. ELSE
  5039. BEGIN
  5040. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  5041. END ";
  5042. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  5043. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5044. //修改送货单到货数量
  5045. foreach (var itemInfo in item.detail)
  5046. {
  5047. sql = @"UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
  5048. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  5049. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  5050. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5051. {
  5052. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
  5053. }
  5054. sql = @"UPDATE ICSInventoryLot SET Quantity='{2}'
  5055. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  5056. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  5057. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5058. {
  5059. throw new Exception(language.GetNameByCode("WMSAPIInfo462")); //"条码表信息更新失败!");
  5060. }
  5061. }
  5062. //创建到货单信息
  5063. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  5064. BEGIN
  5065. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  5066. RETURN
  5067. END
  5068. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  5069. DNType,InvCode,Quantity,Amount,RCVQuantity,
  5070. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  5071. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  5072. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  5073. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  5074. '1',b.InvCode,SUM(a.DNQuantity),'0','0',
  5075. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  5076. d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,
  5077. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode
  5078. FROM ICSASNDetail a
  5079. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  5080. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  5081. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  5082. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  5083. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}'
  5084. 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";
  5085. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode);
  5086. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5087. {
  5088. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  5089. }
  5090. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  5091. {
  5092. if (!DBHelper.IsU9())
  5093. ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  5094. }
  5095. asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
  5096. }
  5097. if (string.IsNullOrWhiteSpace(asncodes))
  5098. {
  5099. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  5100. }
  5101. #region 查询返回数据
  5102. sql = @"SELECT
  5103. n.POCode,
  5104. n.Sequence AS POSequence,
  5105. a.ASNCode,
  5106. a.DNCode,
  5107. a.Sequence,
  5108. a.VenCode,
  5109. a.DepCode,
  5110. a.InvCode,
  5111. inv.InvName,
  5112. inv.InvStd,
  5113. a.Quantity,
  5114. inv.InvUnit,
  5115. a.Amount,
  5116. inv.AmountUnit,
  5117. a.RCVQuantity,
  5118. a.UnitPrice,
  5119. a.Currency,
  5120. a.POID,
  5121. a.PODetailID,
  5122. a.DNID,
  5123. a.DNDetailID,
  5124. ext.ProjectCode,
  5125. ext.BatchCode,
  5126. ext.Version,
  5127. ext.Brand,
  5128. ext.cFree1,
  5129. ext.cFree2,
  5130. ext.cFree3,
  5131. ext.cFree4,
  5132. ext.cFree5,
  5133. ext.cFree6,
  5134. ext.cFree7,
  5135. ext.cFree8,
  5136. ext.cFree9,
  5137. ext.cFree10,
  5138. a.MUSER AS [User],
  5139. a.MTIME AS [MTime]
  5140. FROM ICSDeliveryNotice a
  5141. INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
  5142. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  5143. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  5144. WHERE a.ASNCode+a.WorkPoint IN ({0})";
  5145. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  5146. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5147. #endregion
  5148. cmd.Transaction.Commit();
  5149. return data;
  5150. }
  5151. catch (Exception ex)
  5152. {
  5153. if (cmd.Transaction != null)
  5154. cmd.Transaction.Rollback();
  5155. log.Error(ex.Message);
  5156. throw new Exception(ex.Message);
  5157. }
  5158. finally
  5159. {
  5160. if (conn.State == ConnectionState.Open)
  5161. {
  5162. conn.Close();
  5163. }
  5164. conn.Dispose();
  5165. }
  5166. }
  5167. }
  5168. /// <summary>
  5169. /// 采购拒收
  5170. /// </summary>
  5171. /// <param name="JsonData"></param>
  5172. /// <returns></returns>
  5173. public static DataTable PurchaseRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  5174. {
  5175. var language = LanguageHelper.GetName("WMSAPIInfo");
  5176. if (JsonData.Count <= 0)
  5177. {
  5178. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5179. }
  5180. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5181. {
  5182. conn.Open();
  5183. SqlTransaction sqlTran = conn.BeginTransaction();
  5184. SqlCommand cmd = new SqlCommand();
  5185. cmd.Transaction = sqlTran;
  5186. cmd.Connection = conn;
  5187. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  5188. try
  5189. {
  5190. string lots = string.Empty;
  5191. string sql = string.Empty;
  5192. foreach (var item in JsonData)
  5193. {
  5194. if (string.IsNullOrEmpty(item.DNCode))
  5195. {
  5196. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  5197. }
  5198. //获取单号
  5199. sql = @"DECLARE @Status VARCHAR(10)
  5200. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  5201. IF (@Status IS NULL)
  5202. BEGIN
  5203. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  5204. RETURN
  5205. END
  5206. ELSE IF (@Status!='2')
  5207. BEGIN
  5208. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  5209. RETURN
  5210. END
  5211. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  5212. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  5213. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  5214. IF @MaxNO IS NULL
  5215. BEGIN
  5216. SELECT @date+'00001' AS Code
  5217. END
  5218. ELSE
  5219. BEGIN
  5220. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  5221. END ";
  5222. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  5223. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5224. //修改送货单到货数量
  5225. foreach (var itemInfo in item.detail)
  5226. {
  5227. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  5228. BEGIN
  5229. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  5230. RETURN
  5231. END
  5232. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  5233. BEGIN
  5234. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  5235. RETURN
  5236. END
  5237. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  5238. DNType,InvCode,Quantity,Amount,RCVQuantity,
  5239. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  5240. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  5241. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  5242. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  5243. '3',d.InvCode,'{7}', '{8}', 0,
  5244. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  5245. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  5246. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, d.LOTNO,''
  5247. FROM ICSDeliveryNotice a
  5248. INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  5249. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  5250. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  5251. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  5252. INNER JOIN ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint
  5253. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  5254. WHERE a.DNCode='{0}' and d.LOTNO='{1}' AND a.WorkPoint='{2}'";
  5255. 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);
  5256. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5257. {
  5258. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  5259. }
  5260. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  5261. }
  5262. //增加了webconfig 判断不是U9,调用U8接口
  5263. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"])&& !DBHelper.IsU9())
  5264. ICSPurchaseService.PurchaseRejectDocInNewERP(item.DNCode, Code, item.WorkPoint, cmd, language);
  5265. }
  5266. if (string.IsNullOrWhiteSpace(lots))
  5267. {
  5268. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  5269. }
  5270. #region 查询返回数据
  5271. sql = @"SELECT
  5272. n.DNCode,
  5273. n.Sequence,
  5274. a.DNCode AS RJTCode,
  5275. a.Sequence AS RJTSequence,
  5276. a.VenCode,
  5277. a.DepCode,
  5278. a.InvCode,
  5279. inv.InvName,
  5280. inv.InvStd,
  5281. a.Quantity,
  5282. inv.InvUnit,
  5283. a.Amount,
  5284. inv.AmountUnit,
  5285. a.RCVQuantity,
  5286. a.UnitPrice,
  5287. a.Currency,
  5288. a.POID,
  5289. a.PODetailID,
  5290. a.DNID,
  5291. a.DNDetailID,
  5292. ext.ProjectCode,
  5293. ext.BatchCode,
  5294. ext.Version,
  5295. ext.Brand,
  5296. ext.cFree1,
  5297. ext.cFree2,
  5298. ext.cFree3,
  5299. ext.cFree4,
  5300. ext.cFree5,
  5301. ext.cFree6,
  5302. ext.cFree7,
  5303. ext.cFree8,
  5304. ext.cFree9,
  5305. ext.cFree10,
  5306. a.MUSER AS [User],
  5307. a.MTIME AS [MTime]
  5308. FROM ICSDeliveryNotice a
  5309. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  5310. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  5311. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  5312. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  5313. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  5314. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5315. #endregion
  5316. cmd.Transaction.Commit();
  5317. return data;
  5318. }
  5319. catch (Exception ex)
  5320. {
  5321. if (cmd.Transaction != null)
  5322. cmd.Transaction.Rollback();
  5323. log.Error(ex.Message);
  5324. throw new Exception(ex.Message);
  5325. }
  5326. finally
  5327. {
  5328. if (conn.State == ConnectionState.Open)
  5329. {
  5330. conn.Close();
  5331. }
  5332. conn.Dispose();
  5333. }
  5334. }
  5335. }
  5336. /// <summary>
  5337. /// 无订单采购拒收
  5338. /// </summary>
  5339. /// <param name="JsonData"></param>
  5340. /// <returns></returns>
  5341. public static DataTable PurchaseRejectDocNoTransCreate(List<ICSDeliveryNotice> JsonData)
  5342. {
  5343. var language = LanguageHelper.GetName("WMSAPIInfo");
  5344. if (JsonData.Count <= 0)
  5345. {
  5346. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5347. }
  5348. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5349. {
  5350. conn.Open();
  5351. SqlTransaction sqlTran = conn.BeginTransaction();
  5352. SqlCommand cmd = new SqlCommand();
  5353. cmd.Transaction = sqlTran;
  5354. cmd.Connection = conn;
  5355. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  5356. try
  5357. {
  5358. string lots = string.Empty;
  5359. string sql = string.Empty;
  5360. foreach (var item in JsonData)
  5361. {
  5362. if (string.IsNullOrEmpty(item.DNCode))
  5363. {
  5364. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  5365. }
  5366. //获取单号
  5367. sql = @"DECLARE @Status VARCHAR(10)
  5368. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  5369. IF (@Status IS NULL)
  5370. BEGIN
  5371. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  5372. RETURN
  5373. END
  5374. ELSE IF (@Status!='2')
  5375. BEGIN
  5376. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  5377. RETURN
  5378. END
  5379. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  5380. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  5381. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  5382. IF @MaxNO IS NULL
  5383. BEGIN
  5384. SELECT @date+'00001' AS Code
  5385. END
  5386. ELSE
  5387. BEGIN
  5388. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  5389. END ";
  5390. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  5391. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5392. //修改送货单到货数量
  5393. foreach (var itemInfo in item.detail)
  5394. {
  5395. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  5396. BEGIN
  5397. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  5398. RETURN
  5399. END
  5400. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  5401. BEGIN
  5402. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  5403. RETURN
  5404. END
  5405. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  5406. DNType,InvCode,Quantity,Amount,RCVQuantity,
  5407. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  5408. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  5409. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  5410. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  5411. '3',d.InvCode,'{7}', '{8}', 0,
  5412. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  5413. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  5414. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, d.LOTNO,''
  5415. FROM ICSDeliveryNotice a
  5416. --INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  5417. INNER JOIN ICSInventoryLotDetail m on a.DNCode=m.TransCode and a.Sequence=m.TransSequence and a.WorkPoint=m.WorkPoint
  5418. INNER JOIN ICSInventoryLot d ON m.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint
  5419. --INNER JOIN ICSPurchaseOrder n ON a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  5420. INNER JOIN ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint
  5421. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  5422. WHERE a.DNCode='{0}' and d.LOTNO='{1}' AND a.WorkPoint='{2}'";
  5423. 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);
  5424. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5425. {
  5426. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  5427. }
  5428. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  5429. }
  5430. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  5431. ICSPurchaseService.PurchaseRejectDocInNewERP(item.DNCode, Code, item.WorkPoint, cmd, language);
  5432. }
  5433. if (string.IsNullOrWhiteSpace(lots))
  5434. {
  5435. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  5436. }
  5437. #region 查询返回数据
  5438. sql = @"SELECT
  5439. n.DNCode,
  5440. n.Sequence,
  5441. a.DNCode AS RJTCode,
  5442. a.Sequence AS RJTSequence,
  5443. a.VenCode,
  5444. a.DepCode,
  5445. a.InvCode,
  5446. inv.InvName,
  5447. inv.InvStd,
  5448. a.Quantity,
  5449. inv.InvUnit,
  5450. a.Amount,
  5451. inv.AmountUnit,
  5452. a.RCVQuantity,
  5453. a.UnitPrice,
  5454. a.Currency,
  5455. a.POID,
  5456. a.PODetailID,
  5457. a.DNID,
  5458. a.DNDetailID,
  5459. ext.ProjectCode,
  5460. ext.BatchCode,
  5461. ext.Version,
  5462. ext.Brand,
  5463. ext.cFree1,
  5464. ext.cFree2,
  5465. ext.cFree3,
  5466. ext.cFree4,
  5467. ext.cFree5,
  5468. ext.cFree6,
  5469. ext.cFree7,
  5470. ext.cFree8,
  5471. ext.cFree9,
  5472. ext.cFree10,
  5473. a.MUSER AS [User],
  5474. a.MTIME AS [MTime]
  5475. FROM ICSDeliveryNotice a
  5476. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  5477. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  5478. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  5479. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  5480. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  5481. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5482. #endregion
  5483. cmd.Transaction.Commit();
  5484. return data;
  5485. }
  5486. catch (Exception ex)
  5487. {
  5488. if (cmd.Transaction != null)
  5489. cmd.Transaction.Rollback();
  5490. log.Error(ex.Message);
  5491. throw new Exception(ex.Message);
  5492. }
  5493. finally
  5494. {
  5495. if (conn.State == ConnectionState.Open)
  5496. {
  5497. conn.Close();
  5498. }
  5499. conn.Dispose();
  5500. }
  5501. }
  5502. }
  5503. /// <summary>
  5504. /// 采购订单
  5505. /// </summary>
  5506. /// <param name="JsonData"></param>
  5507. /// <returns></returns>
  5508. public static DataTable PurOrderCreate(List<ICSPurchaseOrder> JsonData)
  5509. {
  5510. var language = LanguageHelper.GetName("WMSAPIInfo");
  5511. if (JsonData.Count <= 0)
  5512. {
  5513. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5514. }
  5515. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5516. {
  5517. conn.Open();
  5518. SqlTransaction sqlTran = conn.BeginTransaction();
  5519. SqlCommand cmd = new SqlCommand();
  5520. cmd.Transaction = sqlTran;
  5521. cmd.Connection = conn;
  5522. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  5523. try
  5524. {
  5525. string codes = string.Empty;
  5526. string sql = string.Empty;
  5527. string Colspan = string.Empty;
  5528. string IDD = string.Empty;
  5529. //获取单号
  5530. sql = @"DECLARE @MaxNO INT,@date varchar(20)='POIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  5531. SELECT @MaxNO=SUBSTRING(MAX(POCode),LEN(@date)+1,LEN(MAX(POCode))-LEN(@date))+1 FROM ICSPurchaseOrder
  5532. WHERE SUBSTRING(POCode, 1, LEN(@date))=@date
  5533. IF @MaxNO IS NULL
  5534. BEGIN
  5535. SELECT @date+'00001' AS Code
  5536. END
  5537. ELSE
  5538. BEGIN
  5539. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  5540. END ";
  5541. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5542. HashSet<string> uniqueItems = new HashSet<string>();
  5543. foreach (var item in JsonData)
  5544. {
  5545. //检验自由项
  5546. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  5547. + "~" + item.Brand + "~" + item.cFree1
  5548. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  5549. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  5550. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  5551. sql = @"select ID,Colspan from ICSExtension a
  5552. where Colspan='{0}' and WorkPoint='{1}'";
  5553. sql = string.Format(sql, Colspan, item.WorkPoint);
  5554. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  5555. if (dttt.Rows.Count == 0)
  5556. {
  5557. IDD = Guid.NewGuid().ToString();
  5558. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  5559. 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}'";
  5560. 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);
  5561. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5562. {
  5563. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  5564. }
  5565. }
  5566. else
  5567. {
  5568. IDD = dttt.Rows[0]["ID"].ToString();
  5569. }
  5570. string key = item.Sequence + "~" + item.InvCode;
  5571. if (uniqueItems.Contains(key))
  5572. {
  5573. throw new Exception("子件不可重复添加!");
  5574. }
  5575. uniqueItems.Add(key);
  5576. //创建主表
  5577. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{6}' AND F_Location='{4}')
  5578. BEGIN
  5579. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{6}") + @"',16,1);
  5580. RETURN
  5581. END
  5582. INSERT INTO ICSPurchaseOrder(ID,POCode ,Sequence,VenCode,DepCode
  5583. ,PersonCode,POType,InvCode,Quantity,Amount
  5584. ,InQuantity,UnitPrice,Currency ,Status ,CreatePerson
  5585. ,CreateDateTime ,ReleaseState ,ReleaseDate,PlanArriveDate,ArriveUser,ArriveDate
  5586. ,DeliveryUser ,DeliveryDate,PRID ,PRDetailID ,POID
  5587. ,PODetailID ,ExtensionID ,MUSER,MUSERName,MTIME
  5588. ,WorkPoint ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10)
  5589. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  5590. '','1','{5}','{8}',0,
  5591. 0,0,'','1','',
  5592. '{7}','0','','','','',
  5593. '','','0','0','',
  5594. '','{9}','{6}',(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{4}'),'{7}',
  5595. '{4}','','','','','','','','','','')";
  5596. sql = string.Format(sql, Code, item.Sequence, item.VenCode, item.DepCode,item.WorkPoint, item.InvCode, item.User,
  5597. item.MTime, item.Quantity, IDD);
  5598. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5599. {
  5600. throw new Exception(language.GetNameByCode("WMSAPIInfo0206"));//"采购订单信息创建失败!!");
  5601. }
  5602. codes += "'" + Code + item.WorkPoint + "',";
  5603. }
  5604. if (string.IsNullOrWhiteSpace(codes))
  5605. {
  5606. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  5607. }
  5608. #region 查询返回数据
  5609. sql = @"SELECT a.POCode,a.Sequence,
  5610. a.VenCode,a.DepCode,a.PersonCode,
  5611. d.Name AS Status,
  5612. a.Sequence,
  5613. a.InvCode,
  5614. inv.InvName,
  5615. inv.InvStd,
  5616. a.Quantity,
  5617. inv.InvUnit,
  5618. a.Amount,
  5619. inv.AmountUnit,
  5620. a.InQuantity,
  5621. ext.ProjectCode,
  5622. ext.BatchCode,
  5623. ext.Version,
  5624. ext.Brand,
  5625. ext.cFree1,
  5626. ext.cFree2,
  5627. ext.cFree3,
  5628. ext.cFree4,
  5629. ext.cFree5,
  5630. ext.cFree6,
  5631. ext.cFree7,
  5632. ext.cFree8,
  5633. ext.cFree9,
  5634. ext.cFree10,
  5635. a.MUSER AS [User],
  5636. a.MTIME AS [MTime]
  5637. FROM ICSPurchaseOrder a
  5638. LEFT JOIN ICSType d ON d.TableCode='ICSPurchaseOrder' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  5639. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  5640. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  5641. WHERE a.POCode+a.WorkPoint IN ({0})";
  5642. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  5643. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5644. #endregion
  5645. cmd.Transaction.Commit();
  5646. return data;
  5647. }
  5648. catch (Exception ex)
  5649. {
  5650. if (cmd.Transaction != null)
  5651. cmd.Transaction.Rollback();
  5652. log.Error(ex.Message);
  5653. throw new Exception(ex.Message);
  5654. }
  5655. finally
  5656. {
  5657. if (conn.State == ConnectionState.Open)
  5658. {
  5659. conn.Close();
  5660. }
  5661. conn.Dispose();
  5662. }
  5663. }
  5664. }
  5665. /// <summary>
  5666. /// 采购订单 修改
  5667. /// </summary>
  5668. /// <param name="JsonData"></param>
  5669. /// <returns></returns>
  5670. public static DataTable ICSPurOrderUpdate(List<ICSPurchaseOrder> JsonData)
  5671. {
  5672. var language = LanguageHelper.GetName("WMSAPIInfo");
  5673. if (JsonData.Count <= 0)
  5674. {
  5675. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5676. }
  5677. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5678. {
  5679. conn.Open();
  5680. SqlTransaction sqlTran = conn.BeginTransaction();
  5681. SqlCommand cmd = new SqlCommand();
  5682. cmd.Transaction = sqlTran;
  5683. cmd.Connection = conn;
  5684. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  5685. try
  5686. {
  5687. string sql = string.Empty;
  5688. string Checksql = string.Empty;
  5689. string Code = string.Empty;
  5690. string ids = string.Empty;
  5691. string Colspan = string.Empty;
  5692. string IDD = string.Empty;
  5693. foreach (var item in JsonData)
  5694. {
  5695. //检验自由项
  5696. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  5697. + "~" + item.Brand + "~" + item.cFree1
  5698. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  5699. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  5700. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  5701. Checksql = @"select ID,Colspan from ICSExtension a
  5702. where Colspan='{0}' and WorkPoint='{1}'";
  5703. Checksql = string.Format(Checksql, Colspan, item.WorkPoint);
  5704. DataTable dttt = DBHelper.SQlReturnData(Checksql, cmd);
  5705. if (dttt.Rows.Count == 0)
  5706. {
  5707. IDD = Guid.NewGuid().ToString();
  5708. Checksql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  5709. 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}'";
  5710. 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);
  5711. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  5712. {
  5713. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  5714. }
  5715. }
  5716. else
  5717. {
  5718. IDD = dttt.Rows[0]["ID"].ToString();
  5719. }
  5720. //主表修改
  5721. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  5722. BEGIN
  5723. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  5724. RETURN
  5725. END
  5726. DECLARE @Status VARCHAR(10)
  5727. SELECT distinct @Status=Status FROM ICSPurchaseOrder WHERE PoCode='{0}' and WorkPoint='{6}'
  5728. IF (@Status IS NULL)
  5729. BEGIN
  5730. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo0205"), "{0}") + @"',16,1);
  5731. RETURN
  5732. END
  5733. ELSE IF (@Status!='1')
  5734. BEGIN
  5735. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo0202"), "{0}") + @"',16,1);
  5736. RETURN
  5737. END
  5738. ";
  5739. sql = string.Format(sql, item.PoCode, item.Sequence, item.InvCode, item.Quantity, item.User,
  5740. item.MTime, item.WorkPoint);
  5741. if (!string.IsNullOrWhiteSpace(item.Sequence))
  5742. {
  5743. //创建子表
  5744. sql += @"IF EXISTS(Select * from ICSPurchaseOrder where PoCode ='{0}'and Sequence ='{1}')
  5745. Begin
  5746. 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}'
  5747. where PoCode ='{0}'and Sequence ='{1}'
  5748. END
  5749. ELSE
  5750. BEGIN
  5751. INSERT INTO ICSPurchaseOrder
  5752. (ID,POCode ,Sequence,VenCode,DepCode
  5753. ,PersonCode,POType,InvCode,Quantity,Amount
  5754. ,InQuantity,UnitPrice,Currency ,Status ,CreatePerson
  5755. ,CreateDateTime ,ReleaseState ,ReleaseDate,PlanArriveDate,ArriveUser,ArriveDate
  5756. ,DeliveryUser ,DeliveryDate,PRID ,PRDetailID ,POID
  5757. ,PODetailID ,ExtensionID ,MUSER,MUSERName,MTIME
  5758. ,WorkPoint ,EATTRIBUTE1,EATTRIBUTE2,EATTRIBUTE3,EATTRIBUTE4,EATTRIBUTE5,EATTRIBUTE6,EATTRIBUTE7,EATTRIBUTE8,EATTRIBUTE9,EATTRIBUTE10)
  5759. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  5760. '','1','{5}','{8}',0,
  5761. 0,0,'','1','',
  5762. '','0','','','','',
  5763. '','','0','0','',
  5764. '','',(select F_RealName from Sys_SRM_User where F_Account='{6}' and F_Location='{4}'),'{6}','{7}',
  5765. '{4}','','','','','','','','','','')
  5766. END";
  5767. sql = string.Format(sql, item.PoCode, item.Sequence, item.VenCode, item.DepCode, item.WorkPoint, item.InvCode, item.User,
  5768. item.MTime, item.Quantity, IDD);
  5769. }
  5770. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5771. {
  5772. throw new Exception(language.GetNameByCode("WMSAPIInfo0204"));//"采购订单信息修改失败!");
  5773. }
  5774. ids += "'" + item.Sequence + "',";
  5775. Code = item.PoCode;
  5776. }
  5777. sql = @"DELETE from ICSPurchaseOrder where PoCode ='{0}' and Sequence not in ({1})";
  5778. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  5779. DBHelper.ExecuteNonQuery(sql, cmd);
  5780. #region 查询返回数据
  5781. sql = @"SELECT a.POCode,a.Sequence,
  5782. a.VenCode,a.DepCode,a.PersonCode,
  5783. d.Name AS Status,
  5784. a.Sequence,
  5785. a.InvCode,
  5786. inv.InvName,
  5787. inv.InvStd,
  5788. a.Quantity,
  5789. inv.InvUnit,
  5790. a.Amount,
  5791. inv.AmountUnit,
  5792. a.InQuantity,
  5793. ext.ProjectCode,
  5794. ext.BatchCode,
  5795. ext.Version,
  5796. ext.Brand,
  5797. ext.cFree1,
  5798. ext.cFree2,
  5799. ext.cFree3,
  5800. ext.cFree4,
  5801. ext.cFree5,
  5802. ext.cFree6,
  5803. ext.cFree7,
  5804. ext.cFree8,
  5805. ext.cFree9,
  5806. ext.cFree10,
  5807. a.MUSER AS [User],
  5808. a.MTIME AS [MTime]
  5809. FROM ICSPurchaseOrder a
  5810. LEFT JOIN ICSType d ON d.TableCode='ICSPurchaseOrder' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  5811. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  5812. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  5813. WHERE a.POCode+a.WorkPoint IN ('{0}')";
  5814. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  5815. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5816. #endregion
  5817. cmd.Transaction.Commit();
  5818. return data;
  5819. }
  5820. catch (Exception ex)
  5821. {
  5822. if (cmd.Transaction != null)
  5823. cmd.Transaction.Rollback();
  5824. log.Error(ex.Message);
  5825. throw new Exception(ex.Message);
  5826. }
  5827. finally
  5828. {
  5829. if (conn.State == ConnectionState.Open)
  5830. {
  5831. conn.Close();
  5832. }
  5833. conn.Dispose();
  5834. }
  5835. }
  5836. }
  5837. /// <summary>
  5838. /// 采购订单审核
  5839. /// </summary>
  5840. /// <param name="JsonData"></param>
  5841. /// <returns></returns>
  5842. public static DataTable PurOrderApprove(List<ICSUser> JsonData)
  5843. {
  5844. string flag = string.Empty;
  5845. var language = LanguageHelper.GetName("WMSAPIInfo");
  5846. if (JsonData.Count <= 0)
  5847. {
  5848. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5849. }
  5850. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5851. {
  5852. conn.Open();
  5853. SqlTransaction sqlTran = conn.BeginTransaction();
  5854. SqlCommand cmd = new SqlCommand();
  5855. cmd.Transaction = sqlTran;
  5856. cmd.Connection = conn;
  5857. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  5858. try
  5859. {
  5860. string sql = string.Empty;
  5861. string ids = string.Empty;
  5862. foreach (var item in JsonData)
  5863. {
  5864. bool hasApproveFlag = JsonData.Any(u => u.ApproveFlag != null);
  5865. if (hasApproveFlag == true)
  5866. {
  5867. flag = item.ApproveFlag;
  5868. }
  5869. if (string.IsNullOrEmpty(item.ID))
  5870. {
  5871. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  5872. }
  5873. if (string.IsNullOrEmpty(item.User))
  5874. {
  5875. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  5876. }
  5877. if (item.MTime <= new DateTime(2000, 1, 1))
  5878. {
  5879. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  5880. }
  5881. if (flag.Equals("1")|| flag=="")
  5882. {
  5883. //获取单号
  5884. sql = @"DECLARE @Status VARCHAR(10)
  5885. SELECT @Status=Status FROM ICSPurchaseOrder WHERE PoCode='{0}'
  5886. IF (@Status IS NULL)
  5887. BEGIN
  5888. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  5889. RETURN
  5890. END
  5891. ELSE IF (@Status!='1')
  5892. BEGIN
  5893. RAISERROR('" + language.GetNameByCode("WMSAPIInfo0202") + @"',16,1);
  5894. RETURN
  5895. END
  5896. update ICSPurchaseOrder set Status='2',MUSER='{1}',MTIME='{2}' where PoCode='{0}'";
  5897. sql = string.Format(sql, item.ID, item.User, item.MTime);
  5898. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5899. {
  5900. throw new Exception(language.GetNameByCode("WMSAPIInfo0203"));//"采购订单审核失败!");
  5901. }
  5902. ids += "'" + item.ID + "',";
  5903. }
  5904. else
  5905. {
  5906. //获取单号
  5907. sql = @"DECLARE @Status VARCHAR(10)
  5908. SELECT @Status=Status FROM ICSPurchaseOrder WHERE PoCode='{0}'
  5909. IF (@Status IS NULL)
  5910. BEGIN
  5911. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  5912. RETURN
  5913. END
  5914. ELSE IF (@Status!='2')
  5915. BEGIN
  5916. RAISERROR('" + language.GetNameByCode("WMSAPIInfo473") + @"',16,1);
  5917. RETURN
  5918. END
  5919. IF EXISTS (select id from ICSPurchaseOrder where PoCode='{0}' and InQuantity>0)
  5920. BEGIN
  5921. RAISERROR('" + language.GetNameByCode("WMSAPIInfo474") + @"',16,1);
  5922. RETURN
  5923. END
  5924. update ICSPurchaseOrder set Status='1',MUSER='{1}',MTIME='{2}' where PoCode='{0}'";
  5925. sql = string.Format(sql, item.ID, item.User, item.MTime);
  5926. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5927. {
  5928. throw new Exception(language.GetNameByCode("WMSAPIInfo475"));//"采购订单弃审失败!");
  5929. }
  5930. ids += "'" + item.ID + "',";
  5931. }
  5932. }
  5933. if (string.IsNullOrWhiteSpace(ids))
  5934. {
  5935. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  5936. }
  5937. #region 查询返回数据
  5938. sql = @"SELECT a.POCode,a.Sequence,
  5939. a.VenCode,a.DepCode,a.PersonCode,
  5940. d.Name AS Status,
  5941. a.Sequence,
  5942. a.InvCode,
  5943. inv.InvName,
  5944. inv.InvStd,
  5945. a.Quantity,
  5946. inv.InvUnit,
  5947. a.Amount,
  5948. inv.AmountUnit,
  5949. a.InQuantity,
  5950. ext.ProjectCode,
  5951. ext.BatchCode,
  5952. ext.Version,
  5953. ext.Brand,
  5954. ext.cFree1,
  5955. ext.cFree2,
  5956. ext.cFree3,
  5957. ext.cFree4,
  5958. ext.cFree5,
  5959. ext.cFree6,
  5960. ext.cFree7,
  5961. ext.cFree8,
  5962. ext.cFree9,
  5963. ext.cFree10,
  5964. a.MUSER AS [User],
  5965. a.MTIME AS [MTime]
  5966. FROM ICSPurchaseOrder a
  5967. LEFT JOIN ICSType d ON d.TableCode='ICSPurchaseOrder' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  5968. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  5969. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  5970. WHERE a.ID IN ({0})";
  5971. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  5972. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5973. #endregion
  5974. cmd.Transaction.Commit();
  5975. return data;
  5976. }
  5977. catch (Exception ex)
  5978. {
  5979. if (cmd.Transaction != null)
  5980. cmd.Transaction.Rollback();
  5981. log.Error(ex.Message);
  5982. throw new Exception(ex.Message);
  5983. }
  5984. finally
  5985. {
  5986. if (conn.State == ConnectionState.Open)
  5987. {
  5988. conn.Close();
  5989. }
  5990. conn.Dispose();
  5991. }
  5992. }
  5993. }
  5994. /// <summary>
  5995. /// 销售订单审核
  5996. /// </summary>
  5997. /// <param name="JsonData"></param>
  5998. /// <returns></returns>
  5999. public static DataTable SalesOrderApprove(List<ICSUser> JsonData)
  6000. {
  6001. string flag = string.Empty;
  6002. var language = LanguageHelper.GetName("WMSAPIInfo");
  6003. if (JsonData.Count <= 0)
  6004. {
  6005. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6006. }
  6007. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6008. {
  6009. conn.Open();
  6010. SqlTransaction sqlTran = conn.BeginTransaction();
  6011. SqlCommand cmd = new SqlCommand();
  6012. cmd.Transaction = sqlTran;
  6013. cmd.Connection = conn;
  6014. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6015. try
  6016. {
  6017. string sql = string.Empty;
  6018. string ids = string.Empty;
  6019. foreach (var item in JsonData)
  6020. {
  6021. bool hasApproveFlag = JsonData.Any(u => u.ApproveFlag != null);
  6022. if (hasApproveFlag==true)
  6023. {
  6024. flag = item.ApproveFlag;
  6025. }
  6026. if (string.IsNullOrEmpty(item.ID))
  6027. {
  6028. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  6029. }
  6030. if (string.IsNullOrEmpty(item.User))
  6031. {
  6032. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  6033. }
  6034. if (item.MTime <= new DateTime(2000, 1, 1))
  6035. {
  6036. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  6037. }
  6038. if (flag.Equals("1")|| flag=="")
  6039. {
  6040. //获取单号
  6041. sql = @"DECLARE @Status VARCHAR(10)
  6042. SELECT @Status=Status FROM ICSSDN WHERE SDNCode='{0}'
  6043. IF (@Status IS NULL)
  6044. BEGIN
  6045. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  6046. RETURN
  6047. END
  6048. ELSE IF (@Status!='1')
  6049. BEGIN
  6050. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  6051. RETURN
  6052. END
  6053. update ICSSDN set Status='2',MUSER='{1}',MTIME='{2}' where SDNCode='{0}'";
  6054. sql = string.Format(sql, item.ID, item.User, item.MTime);
  6055. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6056. {
  6057. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  6058. }
  6059. ids += "'" + item.ID + "',";
  6060. }
  6061. else
  6062. {
  6063. //获取单号
  6064. sql = @"DECLARE @Status VARCHAR(10)
  6065. SELECT @Status=Status FROM ICSSDN WHERE SDNCode='{0}'
  6066. IF (@Status IS NULL)
  6067. BEGIN
  6068. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  6069. RETURN
  6070. END
  6071. ELSE IF (@Status!='2')
  6072. BEGIN
  6073. RAISERROR('" + language.GetNameByCode("WMSAPIInfo473") + @"',16,1);
  6074. RETURN
  6075. END
  6076. IF EXISTS (select id from ICSSDN where SDNCode='{0}' and SDNQuantity>0)
  6077. BEGIN
  6078. RAISERROR('" + language.GetNameByCode("WMSAPIInfo474") + @"',16,1);
  6079. RETURN
  6080. END
  6081. update ICSSDN set Status='1',MUSER='{1}',MTIME='{2}' where SDNCode='{0}'";
  6082. sql = string.Format(sql, item.ID, item.User, item.MTime);
  6083. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6084. {
  6085. throw new Exception(language.GetNameByCode("WMSAPIInfo475"));//"生产退料申请单审核失败!");
  6086. }
  6087. ids += "'" + item.ID + "',";
  6088. }
  6089. }
  6090. if (string.IsNullOrWhiteSpace(ids))
  6091. {
  6092. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  6093. }
  6094. #region 查询返回数据
  6095. sql = @"SELECT a.SDNCode,a.Sequence,
  6096. d.Name AS Status,
  6097. a.Sequence,
  6098. a.InvCode,
  6099. inv.InvName,
  6100. inv.InvStd,
  6101. a.Quantity,
  6102. inv.InvUnit,
  6103. a.Amount,
  6104. inv.AmountUnit,
  6105. ext.ProjectCode,
  6106. ext.BatchCode,
  6107. ext.Version,
  6108. ext.Brand,
  6109. ext.cFree1,
  6110. ext.cFree2,
  6111. ext.cFree3,
  6112. ext.cFree4,
  6113. ext.cFree5,
  6114. ext.cFree6,
  6115. ext.cFree7,
  6116. ext.cFree8,
  6117. ext.cFree9,
  6118. ext.cFree10,
  6119. a.MUSER AS [User],
  6120. a.MTIME AS [MTime]
  6121. FROM ICSSDN a
  6122. LEFT JOIN ICSType d ON d.TableCode='ICSSDN' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  6123. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  6124. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  6125. WHERE a.SDNCode IN ({0})";
  6126. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  6127. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6128. #endregion
  6129. cmd.Transaction.Commit();
  6130. return data;
  6131. }
  6132. catch (Exception ex)
  6133. {
  6134. if (cmd.Transaction != null)
  6135. cmd.Transaction.Rollback();
  6136. log.Error(ex.Message);
  6137. throw new Exception(ex.Message);
  6138. }
  6139. finally
  6140. {
  6141. if (conn.State == ConnectionState.Open)
  6142. {
  6143. conn.Close();
  6144. }
  6145. conn.Dispose();
  6146. }
  6147. }
  6148. }
  6149. /// <summary>
  6150. /// 生产订单审核
  6151. /// </summary>
  6152. /// <param name="JsonData"></param>
  6153. /// <returns></returns>
  6154. public static DataTable ICSMOApprove(List<ICSUser> JsonData)
  6155. {
  6156. string flag = string.Empty;
  6157. var language = LanguageHelper.GetName("WMSAPIInfo");
  6158. if (JsonData.Count <= 0)
  6159. {
  6160. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6161. }
  6162. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6163. {
  6164. conn.Open();
  6165. SqlTransaction sqlTran = conn.BeginTransaction();
  6166. SqlCommand cmd = new SqlCommand();
  6167. cmd.Transaction = sqlTran;
  6168. cmd.Connection = conn;
  6169. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6170. try
  6171. {
  6172. string sql = string.Empty;
  6173. string ids = string.Empty;
  6174. foreach (var item in JsonData)
  6175. {
  6176. bool hasApproveFlag = JsonData.Any(u => u.ApproveFlag != null);
  6177. if (hasApproveFlag == true)
  6178. {
  6179. flag = item.ApproveFlag;
  6180. }
  6181. if (string.IsNullOrEmpty(item.ID))
  6182. {
  6183. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  6184. }
  6185. if (string.IsNullOrEmpty(item.User))
  6186. {
  6187. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  6188. }
  6189. if (item.MTime <= new DateTime(2000, 1, 1))
  6190. {
  6191. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  6192. }
  6193. if (flag.Equals("1")|| flag=="")
  6194. {
  6195. //获取单号
  6196. sql = @"DECLARE @Status VARCHAR(10)
  6197. SELECT @Status=MOStatus FROM ICSMO WHERE mocode='{0}'
  6198. IF (@Status IS NULL)
  6199. BEGIN
  6200. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  6201. RETURN
  6202. END
  6203. ELSE IF (@Status!='1')
  6204. BEGIN
  6205. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  6206. RETURN
  6207. END
  6208. update ICSMO set MOStatus='2',MUSER='{1}',MTIME='{2}' where mocode='{0}'";
  6209. sql = string.Format(sql, item.ID, item.User, item.MTime);
  6210. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6211. {
  6212. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  6213. }
  6214. ids += "'" + item.ID + "',";
  6215. }
  6216. else
  6217. {
  6218. //获取单号
  6219. sql = @"DECLARE @Status VARCHAR(10)
  6220. SELECT @Status=MOStatus FROM ICSMO WHERE mocode='{0}'
  6221. IF (@Status IS NULL)
  6222. BEGIN
  6223. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  6224. RETURN
  6225. END
  6226. ELSE IF (@Status!='2')
  6227. BEGIN
  6228. RAISERROR('" + language.GetNameByCode("WMSAPIInfo473") + @"',16,1);
  6229. RETURN
  6230. END
  6231. IF EXISTS (select id from ICSMO where MOCode='{0}' and RCVQuantity>0)
  6232. BEGIN
  6233. RAISERROR('" + language.GetNameByCode("WMSAPIInfo474") + @"',16,1);
  6234. RETURN
  6235. END
  6236. update ICSMO set MOStatus='1',MUSER='{1}',MTIME='{2}' where mocode='{0}'";
  6237. sql = string.Format(sql, item.ID, item.User, item.MTime);
  6238. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6239. {
  6240. throw new Exception(language.GetNameByCode("WMSAPIInfo475"));//"生产退料申请单审核失败!");
  6241. }
  6242. ids += "'" + item.ID + "',";
  6243. }
  6244. }
  6245. if (string.IsNullOrWhiteSpace(ids))
  6246. {
  6247. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  6248. }
  6249. #region 查询返回数据
  6250. sql = @"SELECT a.ID, a.MOCode, a.Sequence, a.InvCode, a.Quantity,
  6251. a.Amount, a.RCVQuantity, a.DepCode, a.WHCode, a.StartDate, a.DueDate,
  6252. a.MOStatus, a.MOMemo, a.CreatePerson, a.CreateDateTime, a.ERPStatus, a.MOID, a.MODetailID,
  6253. a.ExtensionID, a.MUSER, a.MUSERName, a.MTIME, a.WorkPoint
  6254. FROM ICSMO a
  6255. WHERE a.mocode IN ({0})";
  6256. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  6257. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6258. #endregion
  6259. cmd.Transaction.Commit();
  6260. return data;
  6261. }
  6262. catch (Exception ex)
  6263. {
  6264. if (cmd.Transaction != null)
  6265. cmd.Transaction.Rollback();
  6266. log.Error(ex.Message);
  6267. throw new Exception(ex.Message);
  6268. }
  6269. finally
  6270. {
  6271. if (conn.State == ConnectionState.Open)
  6272. {
  6273. conn.Close();
  6274. }
  6275. conn.Dispose();
  6276. }
  6277. }
  6278. }
  6279. #endregion
  6280. /// <summary>
  6281. /// 生产订单
  6282. /// </summary>
  6283. /// <param name="JsonData"></param>
  6284. /// <returns></returns>
  6285. public static DataTable ICSMOCreate(List<ICSMO> JsonData)
  6286. {
  6287. var language = LanguageHelper.GetName("WMSAPIInfo");
  6288. if (JsonData.Count <= 0)
  6289. {
  6290. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6291. }
  6292. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6293. {
  6294. conn.Open();
  6295. SqlTransaction sqlTran = conn.BeginTransaction();
  6296. SqlCommand cmd = new SqlCommand();
  6297. string Colspan = string.Empty;
  6298. string IDD = string.Empty;
  6299. cmd.Transaction = sqlTran;
  6300. cmd.Connection = conn;
  6301. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6302. try
  6303. {
  6304. string codes = string.Empty;
  6305. string sql = string.Empty;
  6306. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MO'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  6307. SELECT @MaxNO=SUBSTRING(MAX(MOCODE),LEN(@date)+1,LEN(MAX(MOCODE))-LEN(@date))+1 FROM ICSMO
  6308. WHERE SUBSTRING(MOCODE, 1, LEN(@date))=@date
  6309. IF @MaxNO IS NULL
  6310. BEGIN
  6311. SELECT @date+'00001' AS Code
  6312. END
  6313. ELSE
  6314. BEGIN
  6315. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  6316. END ";
  6317. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  6318. HashSet<string> uniqueItems = new HashSet<string>();
  6319. foreach (var item in JsonData)
  6320. {
  6321. //检验自由项
  6322. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  6323. + "~" + item.Brand + "~" + item.cFree1
  6324. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  6325. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  6326. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  6327. sql = @"select ID,Colspan from ICSExtension a
  6328. where Colspan='{0}' and WorkPoint='{1}'";
  6329. sql = string.Format(sql, Colspan, item.WorkPoint);
  6330. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  6331. if (dttt.Rows.Count == 0)
  6332. {
  6333. IDD = Guid.NewGuid().ToString();
  6334. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  6335. 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}'";
  6336. 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);
  6337. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6338. {
  6339. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  6340. }
  6341. }
  6342. else
  6343. {
  6344. IDD = dttt.Rows[0]["ID"].ToString();
  6345. }
  6346. //获取单号
  6347. string key = item.Sequence + "~" + item.InvCode;
  6348. if (uniqueItems.Contains(key))
  6349. {
  6350. throw new Exception("子件不可重复添加!");
  6351. }
  6352. uniqueItems.Add(key);
  6353. //创建主表
  6354. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  6355. BEGIN
  6356. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  6357. RETURN
  6358. END
  6359. INSERT INTO ICSMO
  6360. (a.ID, a.MOCode, a.Sequence, a.InvCode, a.Quantity,
  6361. a.Amount, a.RCVQuantity, a.DepCode, a.WHCode, a.StartDate, a.DueDate,
  6362. a.MOStatus, a.MOMemo, a.CreatePerson, a.CreateDateTime, a.ERPStatus, a.MOID, a.MODetailID,
  6363. a.ExtensionID, a.MUSER, a.MUSERName, a.MTIME, a.WorkPoint, a.EATTRIBUTE1, a.EATTRIBUTE2,
  6364. a.EATTRIBUTE3, a.EATTRIBUTE4, a.EATTRIBUTE5,
  6365. a.EATTRIBUTE6, a.EATTRIBUTE7, a.EATTRIBUTE8, a.EATTRIBUTE9, a.EATTRIBUTE10)
  6366. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  6367. '0','0','','','{8}',
  6368. '{9}',1,'','{4}','{5}',
  6369. '1','','','{7}',
  6370. '{4}',(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{6}'),'{5}','{6}','',
  6371. '','','','','','','','','')";
  6372. sql = string.Format(sql, Code, item.Sequence, item.InvCode, item.Quantity, item.User,
  6373. item.MTIME, item.WorkPoint,IDD,item.StartDate,item.EndDate,item.WHCODE);
  6374. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6375. {
  6376. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产订单信息创建失败!");
  6377. }
  6378. }
  6379. codes = "'" + Code + "'";
  6380. if (string.IsNullOrWhiteSpace(codes))
  6381. {
  6382. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  6383. }
  6384. #region 查询返回数据
  6385. sql = @"SELECT a.ID, a.MOCode, a.Sequence, a.InvCode, a.Quantity,
  6386. a.Amount, a.RCVQuantity, a.DepCode, a.WHCode, a.StartDate, a.DueDate,
  6387. a.MOStatus, a.MOMemo, a.CreatePerson, a.CreateDateTime, a.ERPStatus, a.MOID, a.MODetailID,
  6388. a.ExtensionID, a.MUSER, a.MUSERName, a.MTIME, a.WorkPoint
  6389. FROM ICSMO a
  6390. WHERE a.MOCODE+a.WorkPoint IN ({0})";
  6391. sql = string.Format(sql, codes);
  6392. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6393. #endregion
  6394. cmd.Transaction.Commit();
  6395. return data;
  6396. }
  6397. catch (Exception ex)
  6398. {
  6399. if (cmd.Transaction != null)
  6400. cmd.Transaction.Rollback();
  6401. log.Error(ex.Message);
  6402. throw new Exception(ex.Message);
  6403. }
  6404. finally
  6405. {
  6406. if (conn.State == ConnectionState.Open)
  6407. {
  6408. conn.Close();
  6409. }
  6410. conn.Dispose();
  6411. }
  6412. }
  6413. }
  6414. #region 销售订单
  6415. /// <summary>
  6416. /// 销售订单创建
  6417. /// </summary>
  6418. /// <returns></returns>
  6419. public static DataTable ICSSalesOrderCreate(List<ICSSalesOrder> JsonData)
  6420. {
  6421. var language = LanguageHelper.GetName("WMSAPIInfo");
  6422. if (JsonData.Count <= 0)
  6423. {
  6424. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6425. }
  6426. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6427. {
  6428. conn.Open();
  6429. SqlTransaction sqlTran = conn.BeginTransaction();
  6430. SqlCommand cmd = new SqlCommand();
  6431. cmd.Transaction = sqlTran;
  6432. cmd.Connection = conn;
  6433. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6434. try
  6435. {
  6436. string codes = string.Empty;
  6437. string sql = string.Empty;
  6438. string Colspan = string.Empty;
  6439. string IDD = string.Empty;
  6440. //获取单号
  6441. sql = @"DECLARE @MaxNO INT,@date varchar(20)='POIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  6442. SELECT @MaxNO=SUBSTRING(MAX(SDNCode),LEN(@date)+1,LEN(MAX(SDNCode))-LEN(@date))+1 FROM ICSSDN
  6443. WHERE SUBSTRING(SDNCode, 1, LEN(@date))=@date
  6444. IF @MaxNO IS NULL
  6445. BEGIN
  6446. SELECT @date+'00001' AS Code
  6447. END
  6448. ELSE
  6449. BEGIN
  6450. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  6451. END ";
  6452. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  6453. HashSet<string> uniqueItems = new HashSet<string>();
  6454. foreach (var item in JsonData)
  6455. {
  6456. //检验自由项
  6457. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  6458. + "~" + item.Brand + "~" + item.cFree1
  6459. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  6460. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  6461. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  6462. sql = @"select ID,Colspan from ICSExtension a
  6463. where Colspan='{0}' and WorkPoint='{1}'";
  6464. sql = string.Format(sql, Colspan, item.WorkPoint);
  6465. DataTable dttt = DBHelper.SQlReturnData(sql, cmd);
  6466. if (dttt.Rows.Count == 0)
  6467. {
  6468. IDD = Guid.NewGuid().ToString();
  6469. sql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  6470. 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}'";
  6471. 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);
  6472. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6473. {
  6474. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  6475. }
  6476. }
  6477. else
  6478. {
  6479. IDD = dttt.Rows[0]["ID"].ToString();
  6480. }
  6481. string key = item.Sequence + "~" + item.InvCode;
  6482. if (uniqueItems.Contains(key))
  6483. {
  6484. throw new Exception("子件不可重复添加!");
  6485. }
  6486. uniqueItems.Add(key);
  6487. //创建主表
  6488. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{7}' AND F_Location='{6}')
  6489. BEGIN
  6490. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{7}") + @"',16,1);
  6491. RETURN
  6492. END
  6493. INSERT INTO ICSSDN(ID,SDNCode,Sequence,SOCode,SOSequence,CusCode,CusName,Type,ArriveDate,WHCode,
  6494. InvCode,Quantity,CreatePerson,CreateDateTime,Status,SDNID,SDNDetailID,ExtensionID,MUSER,MUSERName,MTIME,WorkPoint)
  6495. VALUES(NEWID(),'{0}',{1},'','','{2}','{3}',3,'{8}','{10}',
  6496. '{4}',{5},'{7}','{8}',1,'','','{9}','{7}','{7}','{8}','{6}')
  6497. ";
  6498. sql = string.Format(sql, Code, item.Sequence, item.CusCode, item.CusName, item.InvCode, item.Quantity, item.WorkPoint, item.User,
  6499. item.MTime, IDD, item.WHCode);
  6500. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6501. {
  6502. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"采购订单信息创建失败!");
  6503. }
  6504. codes += "'" + Code + item.WorkPoint + "',";
  6505. }
  6506. if (string.IsNullOrWhiteSpace(codes))
  6507. {
  6508. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  6509. }
  6510. #region 查询返回数据
  6511. sql = @"SELECT a.DNCode,a.Sequence,
  6512. a.VenCode,a.DepCode,
  6513. d.Name AS Status,
  6514. a.Sequence,
  6515. a.InvCode,
  6516. inv.InvName,
  6517. inv.InvStd,
  6518. a.Quantity,
  6519. inv.InvUnit,
  6520. a.Amount,
  6521. inv.AmountUnit,
  6522. ext.ProjectCode,
  6523. ext.BatchCode,
  6524. ext.Version,
  6525. ext.Brand,
  6526. ext.cFree1,
  6527. ext.cFree2,
  6528. ext.cFree3,
  6529. ext.cFree4,
  6530. ext.cFree5,
  6531. ext.cFree6,
  6532. ext.cFree7,
  6533. ext.cFree8,
  6534. ext.cFree9,
  6535. ext.cFree10,
  6536. a.MUSER AS [User],
  6537. a.MTIME AS [MTime]
  6538. FROM ICSDeliveryNotice a
  6539. LEFT JOIN ICSType d ON d.TableCode='ICSDeliveryNotice' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  6540. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  6541. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  6542. WHERE a.DNCode+a.WorkPoint IN ({0})";
  6543. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  6544. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6545. #endregion
  6546. cmd.Transaction.Commit();
  6547. return data;
  6548. }
  6549. catch (Exception ex)
  6550. {
  6551. if (cmd.Transaction != null)
  6552. cmd.Transaction.Rollback();
  6553. log.Error(ex.Message);
  6554. throw new Exception(ex.Message);
  6555. }
  6556. finally
  6557. {
  6558. if (conn.State == ConnectionState.Open)
  6559. {
  6560. conn.Close();
  6561. }
  6562. conn.Dispose();
  6563. }
  6564. }
  6565. }
  6566. /// <summary>
  6567. /// 销售订单 修改
  6568. /// </summary>
  6569. /// <param name="JsonData"></param>
  6570. /// <returns></returns>
  6571. public static DataTable ICSSalesOrderUpdate(List<ICSSalesOrder> JsonData)
  6572. {
  6573. var language = LanguageHelper.GetName("WMSAPIInfo");
  6574. if (JsonData.Count <= 0)
  6575. {
  6576. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6577. }
  6578. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6579. {
  6580. conn.Open();
  6581. SqlTransaction sqlTran = conn.BeginTransaction();
  6582. SqlCommand cmd = new SqlCommand();
  6583. cmd.Transaction = sqlTran;
  6584. cmd.Connection = conn;
  6585. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6586. try
  6587. {
  6588. string sql = string.Empty;
  6589. string Checksql = string.Empty;
  6590. string Code = string.Empty;
  6591. string ids = string.Empty;
  6592. string Colspan = string.Empty;
  6593. string IDD = string.Empty;
  6594. foreach (var item in JsonData)
  6595. {
  6596. //检验自由项
  6597. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  6598. + "~" + item.Brand + "~" + item.cFree1
  6599. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  6600. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  6601. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  6602. Checksql = @"select ID,Colspan from ICSExtension a
  6603. where Colspan='{0}' and WorkPoint='{1}'";
  6604. Checksql = string.Format(Checksql, Colspan, item.WorkPoint);
  6605. DataTable dttt = DBHelper.SQlReturnData(Checksql, cmd);
  6606. if (dttt.Rows.Count == 0)
  6607. {
  6608. IDD = Guid.NewGuid().ToString();
  6609. Checksql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  6610. 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}'";
  6611. 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);
  6612. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  6613. {
  6614. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  6615. }
  6616. }
  6617. else
  6618. {
  6619. IDD = dttt.Rows[0]["ID"].ToString();
  6620. }
  6621. //主表修改
  6622. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  6623. BEGIN
  6624. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  6625. RETURN
  6626. END
  6627. DECLARE @Status VARCHAR(10)
  6628. SELECT distinct @Status=Status FROM ICSSDN WHERE SDNCode='{0}' and WorkPoint='{6}'
  6629. IF (@Status IS NULL)
  6630. BEGIN
  6631. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{0}") + @"',16,1);
  6632. RETURN
  6633. END
  6634. ELSE IF (@Status!='1')
  6635. BEGIN
  6636. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{0}") + @"',16,1);
  6637. RETURN
  6638. END
  6639. ";
  6640. sql = string.Format(sql, item.SDNCode, item.Sequence, item.InvCode, item.Quantity, item.User,
  6641. item.MTime, item.WorkPoint);
  6642. if (!string.IsNullOrWhiteSpace(item.Sequence))
  6643. {
  6644. //创建子表
  6645. sql += @"IF EXISTS(Select * from ICSSDN where SDNCode ='{0}'and Sequence ='{1}')
  6646. Begin
  6647. 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}'
  6648. where SDNCode ='{0}' and Sequence ='{1}'
  6649. END
  6650. ELSE
  6651. BEGIN
  6652. INSERT INTO ICSSDN(ID,SDNCode,Sequence,SOCode,SOSequence,CusCode,CusName,Type,ArriveDate,WHCode,
  6653. InvCode,Quantity,CreatePerson,CreateDateTime,Status,SDNID,SDNDetailID,ExtensionID,MUSER,MUSERName,MTIME,WorkPoint)
  6654. VALUES(NEWID(),'{0}',{1},'','','{2}','{3}',3,'{8}','{10}',
  6655. '{4}',{5},'{7}','{8}',1,'','','{9}','{7}','{7}','{8}','{6}')
  6656. END";
  6657. sql = string.Format(sql, item.SDNCode, item.Sequence, item.CusCode, item.CusName, item.InvCode, item.Quantity, item.WorkPoint, item.User,
  6658. item.MTime, IDD, item.WHCode);
  6659. }
  6660. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6661. {
  6662. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"采购订单信息修改失败!");
  6663. }
  6664. ids += "'" + item.Sequence + "',";
  6665. Code = item.SDNCode;
  6666. }
  6667. sql = @"DELETE from ICSDeliveryNotice where DNCode ='{0}' and Sequence not in ({1})";
  6668. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  6669. DBHelper.ExecuteNonQuery(sql, cmd);
  6670. #region 查询返回数据
  6671. sql = @"SELECT a.DNCode,a.Sequence,
  6672. a.VenCode,a.DepCode,
  6673. d.Name AS Status,
  6674. a.Sequence,
  6675. a.InvCode,
  6676. inv.InvName,
  6677. inv.InvStd,
  6678. a.Quantity,
  6679. inv.InvUnit,
  6680. a.Amount,
  6681. inv.AmountUnit,
  6682. ext.ProjectCode,
  6683. ext.BatchCode,
  6684. ext.Version,
  6685. ext.Brand,
  6686. ext.cFree1,
  6687. ext.cFree2,
  6688. ext.cFree3,
  6689. ext.cFree4,
  6690. ext.cFree5,
  6691. ext.cFree6,
  6692. ext.cFree7,
  6693. ext.cFree8,
  6694. ext.cFree9,
  6695. ext.cFree10,
  6696. a.MUSER AS [User],
  6697. a.MTIME AS [MTime]
  6698. FROM ICSDeliveryNotice a
  6699. LEFT JOIN ICSType d ON d.TableCode='ICSDeliveryNotice' AND d.ColumnCode='Status' AND a.Status=d.Code AND a.WorkPoint=d.WorkPoint
  6700. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  6701. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  6702. WHERE a.DNCode+a.WorkPoint IN ('{0}')";
  6703. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  6704. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6705. #endregion
  6706. cmd.Transaction.Commit();
  6707. return data;
  6708. }
  6709. catch (Exception ex)
  6710. {
  6711. if (cmd.Transaction != null)
  6712. cmd.Transaction.Rollback();
  6713. log.Error(ex.Message);
  6714. throw new Exception(ex.Message);
  6715. }
  6716. finally
  6717. {
  6718. if (conn.State == ConnectionState.Open)
  6719. {
  6720. conn.Close();
  6721. }
  6722. conn.Dispose();
  6723. }
  6724. }
  6725. }
  6726. #endregion
  6727. /// <summary>
  6728. /// 生产退料 修改
  6729. /// </summary>
  6730. /// <param name="JsonData"></param>
  6731. /// <returns></returns>
  6732. public static DataTable ICSMOUpdate(List<ICSMO> JsonData)
  6733. {
  6734. var language = LanguageHelper.GetName("WMSAPIInfo");
  6735. if (JsonData.Count <= 0)
  6736. {
  6737. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6738. }
  6739. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6740. {
  6741. conn.Open();
  6742. SqlTransaction sqlTran = conn.BeginTransaction();
  6743. SqlCommand cmd = new SqlCommand();
  6744. cmd.Transaction = sqlTran;
  6745. cmd.Connection = conn;
  6746. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6747. try
  6748. {
  6749. string sql = string.Empty;
  6750. string Checksql = string.Empty;
  6751. string Code = string.Empty;
  6752. string ids = string.Empty;
  6753. string Colspan = string.Empty;
  6754. string IDD = string.Empty;
  6755. foreach (var item in JsonData)
  6756. {
  6757. //检验自由项
  6758. Colspan = item.ProjectCode + "~" + item.BatchCode + "~" + item.Version
  6759. + "~" + item.Brand + "~" + item.cFree1
  6760. + "~" + item.cFree2 + "~" + item.cFree3 + "~" + item.cFree4
  6761. + "~" + item.cFree5 + "~" + item.cFree6 + "~" + item.cFree7
  6762. + "~" + item.cFree8 + "~" + item.cFree9 + "~" + item.cFree10;
  6763. Checksql = @"select ID,Colspan from ICSExtension a
  6764. where Colspan='{0}' and WorkPoint='{1}'";
  6765. Checksql = string.Format(Checksql, Colspan, item.WorkPoint);
  6766. DataTable dttt = DBHelper.SQlReturnData(Checksql, cmd);
  6767. if (dttt.Rows.Count == 0)
  6768. {
  6769. IDD = Guid.NewGuid().ToString();
  6770. Checksql = @"Insert into ICSExtension(ID, Colspan, ProjectCode, BatchCode, Version, Brand, cFree1, cFree2, cFree3, cFree4, cFree5, cFree6, cFree7, cFree8, cFree9, cFree10, MTIME, MUSER, MUSERName, WorkPoint)
  6771. 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}'";
  6772. 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);
  6773. if (!DBHelper.ExecuteNonQuery(Checksql, cmd))
  6774. {
  6775. throw new Exception(language.GetNameByCode("WMSAPIInfo366"));
  6776. }
  6777. }
  6778. else
  6779. {
  6780. IDD = dttt.Rows[0]["ID"].ToString();
  6781. }
  6782. //主表修改
  6783. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  6784. BEGIN
  6785. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  6786. RETURN
  6787. END
  6788. DECLARE @Status VARCHAR(10)
  6789. SELECT distinct @Status=moStatus FROM ICSMO WHERE MOCODE='{0}' and WorkPoint='{6}'
  6790. IF (@Status IS NULL)
  6791. BEGIN
  6792. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{0}") + @"',16,1);
  6793. RETURN
  6794. END
  6795. ELSE IF (@Status!='1')
  6796. BEGIN
  6797. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{0}") + @"',16,1);
  6798. RETURN
  6799. END
  6800. ";
  6801. sql = string.Format(sql, item.MOCODE, item.Sequence, item.InvCode, item.Quantity, item.User,
  6802. item.MTIME, item.WorkPoint);
  6803. if (!string.IsNullOrWhiteSpace(item.Sequence))
  6804. {
  6805. //创建子表
  6806. sql+= @"IF EXISTS(Select * from icsmo where mocode ='{0}'and Sequence ='{1}')
  6807. Begin
  6808. 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}'
  6809. where mocode ='{0}'and Sequence ='{1}'
  6810. END
  6811. ELSE
  6812. BEGIN
  6813. INSERT INTO ICSMO
  6814. (ID, MOCode, Sequence, InvCode, Quantity,
  6815. Amount, RCVQuantity, DepCode, WHCode, StartDate, DueDate,
  6816. MOStatus, MOMemo, CreatePerson, CreateDateTime, ERPStatus, MOID, MODetailID,
  6817. ExtensionID, MUSER, MUSERName, MTIME, WorkPoint, EATTRIBUTE1, EATTRIBUTE2,
  6818. EATTRIBUTE3, EATTRIBUTE4, EATTRIBUTE5,
  6819. EATTRIBUTE6, EATTRIBUTE7, EATTRIBUTE8, EATTRIBUTE9, EATTRIBUTE10)
  6820. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  6821. '0','0','','','{5}',
  6822. '{5}',1,'','{4}','{5}',
  6823. '1','','','',
  6824. '{4}',(select F_RealName from Sys_SRM_User where F_Account='{4}' and F_Location='{6}'),'{5}','{6}','{7}',
  6825. '','','','','','','','','')
  6826. END";
  6827. sql = string.Format(sql, item.MOCODE, item.Sequence, item.InvCode, item.Quantity, item.User,
  6828. item.MTIME, item.WorkPoint,IDD);
  6829. log.Debug("111"+sql);
  6830. }
  6831. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6832. {
  6833. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  6834. }
  6835. ids += "'" + item.Sequence + "',";
  6836. Code = item.MOCODE;
  6837. }
  6838. sql = @"DELETE from icsmo where mocode ='{0}' and Sequence not in ({1})";
  6839. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  6840. DBHelper.ExecuteNonQuery(sql, cmd);
  6841. #region 查询返回数据
  6842. sql = @"SELECT a.ID, a.MOCode, a.Sequence, a.InvCode, a.Quantity,
  6843. a.Amount, a.RCVQuantity, a.DepCode, a.WHCode, a.StartDate, a.DueDate,
  6844. a.MOStatus, a.MOMemo, a.CreatePerson, a.CreateDateTime, a.ERPStatus, a.MOID, a.MODetailID,
  6845. a.ExtensionID, a.MUSER, a.MUSERName, a.MTIME, a.WorkPoint, a.EATTRIBUTE1, a.EATTRIBUTE2,
  6846. a.EATTRIBUTE3, a.EATTRIBUTE4, a.EATTRIBUTE5,
  6847. a.EATTRIBUTE6, a.EATTRIBUTE7, a.EATTRIBUTE8, a.EATTRIBUTE9, a.EATTRIBUTE10
  6848. FROM ICSMO a
  6849. WHERE mocode ='{0}' and Sequence in ({1})";
  6850. sql = string.Format(sql, Code, ids.Substring(0, ids.Length - 1));
  6851. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6852. #endregion
  6853. cmd.Transaction.Commit();
  6854. return data;
  6855. }
  6856. catch (Exception ex)
  6857. {
  6858. if (cmd.Transaction != null)
  6859. cmd.Transaction.Rollback();
  6860. log.Error(ex.Message);
  6861. throw new Exception(ex.Message);
  6862. }
  6863. finally
  6864. {
  6865. if (conn.State == ConnectionState.Open)
  6866. {
  6867. conn.Close();
  6868. }
  6869. conn.Dispose();
  6870. }
  6871. }
  6872. }
  6873. #region 委外
  6874. /// <summary>
  6875. /// 委外退料 新建
  6876. /// </summary>
  6877. /// <param name="JsonData"></param>
  6878. /// <returns></returns>
  6879. public static DataTable OutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  6880. {
  6881. var language = LanguageHelper.GetName("WMSAPIInfo");
  6882. if (JsonData.Count <= 0)
  6883. {
  6884. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6885. }
  6886. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6887. {
  6888. conn.Open();
  6889. SqlTransaction sqlTran = conn.BeginTransaction();
  6890. SqlCommand cmd = new SqlCommand();
  6891. cmd.Transaction = sqlTran;
  6892. cmd.Connection = conn;
  6893. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  6894. try
  6895. {
  6896. string codes = string.Empty;
  6897. string sql = string.Empty;
  6898. foreach (var item in JsonData)
  6899. {
  6900. //获取单号
  6901. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  6902. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  6903. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  6904. IF @MaxNO IS NULL
  6905. BEGIN
  6906. SELECT @date+'00001' AS Code
  6907. END
  6908. ELSE
  6909. BEGIN
  6910. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  6911. END ";
  6912. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  6913. //创建主表
  6914. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  6915. BEGIN
  6916. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  6917. RETURN
  6918. END
  6919. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  6920. 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}','')";
  6921. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  6922. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6923. {
  6924. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  6925. }
  6926. HashSet<string> uniqueItems = new HashSet<string>();
  6927. foreach (var itemInfo in item.detail)
  6928. {
  6929. string key = itemInfo.Sequence + "~" + itemInfo.InvCode;
  6930. if (uniqueItems.Contains(key))
  6931. {
  6932. throw new Exception("子件不可重复添加!");
  6933. }
  6934. uniqueItems.Add(key);
  6935. // 创建子表
  6936. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  6937. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  6938. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  6939. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  6940. '{4}','{5}',0,'{6}','{7}',
  6941. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  6942. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  6943. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6944. {
  6945. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  6946. }
  6947. }
  6948. //校验退料数量是否超出领料数量
  6949. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  6950. DBHelper.ExecuteNonQuery(sql, cmd);
  6951. codes += "'" + Code + item.WorkPoint + "',";
  6952. }
  6953. if (string.IsNullOrWhiteSpace(codes))
  6954. {
  6955. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  6956. }
  6957. #region 查询返回数据
  6958. sql = @"SELECT a.OApplyNegCode,
  6959. c.WHCode,
  6960. c.Memo,
  6961. d.Name AS Status,
  6962. a.Sequence,
  6963. a.InvCode,
  6964. inv.InvName,
  6965. inv.InvStd,
  6966. a.Quantity,
  6967. inv.InvUnit,
  6968. a.Amount,
  6969. inv.AmountUnit,
  6970. a.IssueNegQuantity,
  6971. ext.ProjectCode,
  6972. ext.BatchCode,
  6973. ext.Version,
  6974. ext.Brand,
  6975. ext.cFree1,
  6976. ext.cFree2,
  6977. ext.cFree3,
  6978. ext.cFree4,
  6979. ext.cFree5,
  6980. ext.cFree6,
  6981. ext.cFree7,
  6982. ext.cFree8,
  6983. ext.cFree9,
  6984. ext.cFree10,
  6985. a.MUSER AS [User],
  6986. a.MTIME AS [MTime]
  6987. FROM ICSOApplyNegDetail a
  6988. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  6989. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  6990. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  6991. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  6992. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  6993. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  6994. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6995. #endregion
  6996. cmd.Transaction.Commit();
  6997. return data;
  6998. }
  6999. catch (Exception ex)
  7000. {
  7001. if (cmd.Transaction != null)
  7002. cmd.Transaction.Rollback();
  7003. log.Error(ex.Message);
  7004. throw new Exception(ex.Message);
  7005. }
  7006. finally
  7007. {
  7008. if (conn.State == ConnectionState.Open)
  7009. {
  7010. conn.Close();
  7011. }
  7012. conn.Dispose();
  7013. }
  7014. }
  7015. }
  7016. /// <summary>
  7017. /// 委外退料 新建
  7018. /// </summary>
  7019. /// <param name="JsonData"></param>
  7020. /// <returns></returns>
  7021. public static DataTable AMOutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  7022. {
  7023. var language = LanguageHelper.GetName("WMSAPIInfo");
  7024. if (JsonData.Count <= 0)
  7025. {
  7026. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7027. }
  7028. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7029. {
  7030. conn.Open();
  7031. SqlTransaction sqlTran = conn.BeginTransaction();
  7032. SqlCommand cmd = new SqlCommand();
  7033. cmd.Transaction = sqlTran;
  7034. cmd.Connection = conn;
  7035. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7036. try
  7037. {
  7038. string codes = string.Empty;
  7039. string sql = string.Empty;
  7040. foreach (var item in JsonData)
  7041. {
  7042. //获取单号
  7043. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  7044. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  7045. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  7046. IF @MaxNO IS NULL
  7047. BEGIN
  7048. SELECT @date+'00001' AS Code
  7049. END
  7050. ELSE
  7051. BEGIN
  7052. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  7053. END ";
  7054. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  7055. //创建主表
  7056. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  7057. BEGIN
  7058. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  7059. RETURN
  7060. END
  7061. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  7062. 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}','')";
  7063. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  7064. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7065. {
  7066. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  7067. }
  7068. HashSet<string> uniqueItems = new HashSet<string>();
  7069. foreach (var itemInfo in item.detail)
  7070. {
  7071. string chekksql = @"select c.EATTRIBUTE1 ICSInventory c
  7072. WHERE c.InvCode='{0}'AND c.WorkPoint='{1}' and c.AmountEnable='1'";
  7073. chekksql = string.Format(chekksql, itemInfo.InvCode, itemInfo.WorkPoint);
  7074. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  7075. if (dta.Rows.Count > 0)
  7076. {
  7077. itemInfo.Quantity = (itemInfo.Quantity * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString()));
  7078. }
  7079. string key = itemInfo.Sequence + "~" + itemInfo.InvCode;
  7080. if (uniqueItems.Contains(key))
  7081. {
  7082. throw new Exception("子件不可重复添加!");
  7083. }
  7084. uniqueItems.Add(key);
  7085. // 创建子表
  7086. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  7087. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  7088. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  7089. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  7090. '{4}','{5}',0,'{6}','{7}',
  7091. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  7092. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  7093. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7094. {
  7095. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  7096. }
  7097. }
  7098. //校验退料数量是否超出领料数量
  7099. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  7100. DBHelper.ExecuteNonQuery(sql, cmd);
  7101. codes += "'" + Code + item.WorkPoint + "',";
  7102. }
  7103. if (string.IsNullOrWhiteSpace(codes))
  7104. {
  7105. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  7106. }
  7107. #region 查询返回数据
  7108. sql = @"SELECT a.OApplyNegCode,
  7109. c.WHCode,
  7110. c.Memo,
  7111. d.Name AS Status,
  7112. a.Sequence,
  7113. a.InvCode,
  7114. inv.InvName,
  7115. inv.InvStd,
  7116. a.Quantity,
  7117. inv.InvUnit,
  7118. a.Amount,
  7119. inv.AmountUnit,
  7120. a.IssueNegQuantity,
  7121. ext.ProjectCode,
  7122. ext.BatchCode,
  7123. ext.Version,
  7124. ext.Brand,
  7125. ext.cFree1,
  7126. ext.cFree2,
  7127. ext.cFree3,
  7128. ext.cFree4,
  7129. ext.cFree5,
  7130. ext.cFree6,
  7131. ext.cFree7,
  7132. ext.cFree8,
  7133. ext.cFree9,
  7134. ext.cFree10,
  7135. a.MUSER AS [User],
  7136. a.MTIME AS [MTime]
  7137. FROM ICSOApplyNegDetail a
  7138. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  7139. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  7140. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  7141. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  7142. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  7143. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  7144. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7145. #endregion
  7146. cmd.Transaction.Commit();
  7147. return data;
  7148. }
  7149. catch (Exception ex)
  7150. {
  7151. if (cmd.Transaction != null)
  7152. cmd.Transaction.Rollback();
  7153. log.Error(ex.Message);
  7154. throw new Exception(ex.Message);
  7155. }
  7156. finally
  7157. {
  7158. if (conn.State == ConnectionState.Open)
  7159. {
  7160. conn.Close();
  7161. }
  7162. conn.Dispose();
  7163. }
  7164. }
  7165. }
  7166. private static string CheckOutsourcingIssueDoc(string Type, string Code, string WorkPoint, Dictionary<string, string> language)
  7167. {
  7168. string sql = string.Empty;
  7169. if (Type == "1")
  7170. {
  7171. sql = @"DECLARE @PickID VARCHAR(10)
  7172. SELECT @PickID=b.PickID
  7173. FROM ICSOApplyNegDetail a
  7174. INNER JOIN ICSOOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  7175. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  7176. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  7177. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  7178. FROM ICSOApplyNegDetail a
  7179. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  7180. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  7181. GROUP BY b.PickID
  7182. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  7183. IF (@PickID IS NOT NULL)
  7184. BEGIN
  7185. DECLARE @InvCode VARCHAR(100)
  7186. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  7187. RAISERROR(@InvCode,16,1);
  7188. RETURN
  7189. END ";
  7190. }
  7191. else if (Type == "2")
  7192. {
  7193. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  7194. SELECT @ApplyDetailID=b.ApplyDetailID
  7195. FROM ICSOApplyNegDetail a
  7196. INNER JOIN ICSOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  7197. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  7198. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  7199. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  7200. FROM ICSOApplyNegDetail a
  7201. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  7202. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  7203. GROUP BY b.ApplyDetailID
  7204. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  7205. IF (@ApplyDetailID IS NOT NULL)
  7206. BEGIN
  7207. DECLARE @InvCode VARCHAR(100)
  7208. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  7209. RAISERROR(@InvCode,16,1);
  7210. RETURN
  7211. END ";
  7212. }
  7213. else if (Type == "3")
  7214. {
  7215. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  7216. SELECT @IssueDetailID=b.IssueDetailID
  7217. FROM ICSOApplyNegDetail a
  7218. INNER JOIN ICSOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  7219. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  7220. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  7221. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  7222. FROM ICSOApplyNegDetail a
  7223. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  7224. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  7225. GROUP BY b.IssueDetailID
  7226. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  7227. IF (@IssueDetailID IS NOT NULL)
  7228. BEGIN
  7229. DECLARE @InvCode VARCHAR(100)
  7230. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  7231. RAISERROR(@InvCode,16,1);
  7232. RETURN
  7233. END ";
  7234. }
  7235. else
  7236. {
  7237. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  7238. }
  7239. sql = string.Format(sql, Code, WorkPoint, Type);
  7240. return sql;
  7241. }
  7242. /// <summary>
  7243. /// 委外退料 修改
  7244. /// </summary>
  7245. /// <param name="JsonData"></param>
  7246. /// <returns></returns>
  7247. public static DataTable OutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  7248. {
  7249. var language = LanguageHelper.GetName("WMSAPIInfo");
  7250. if (JsonData.Count <= 0)
  7251. {
  7252. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7253. }
  7254. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7255. {
  7256. conn.Open();
  7257. SqlTransaction sqlTran = conn.BeginTransaction();
  7258. SqlCommand cmd = new SqlCommand();
  7259. cmd.Transaction = sqlTran;
  7260. cmd.Connection = conn;
  7261. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7262. try
  7263. {
  7264. string sql = string.Empty;
  7265. string Code = string.Empty;
  7266. string ids = string.Empty;
  7267. string idss = string.Empty;
  7268. foreach (var item in JsonData)
  7269. {
  7270. //主表修改
  7271. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  7272. BEGIN
  7273. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  7274. RETURN
  7275. END
  7276. DECLARE @Status VARCHAR(10)
  7277. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  7278. IF (@Status IS NULL)
  7279. BEGIN
  7280. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  7281. RETURN
  7282. END
  7283. ELSE IF (@Status!='1')
  7284. BEGIN
  7285. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  7286. RETURN
  7287. END
  7288. 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}' ";
  7289. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  7290. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7291. {
  7292. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  7293. }
  7294. //var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  7295. //if (detail > 0)
  7296. //{
  7297. // sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  7298. // sql = string.Format(sql, item.id, item.WorkPoint);
  7299. // Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  7300. //}
  7301. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  7302. sql = string.Format(sql, item.id, item.WorkPoint);
  7303. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  7304. foreach (var itemInfo in item.detail)
  7305. {
  7306. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  7307. {
  7308. //创建子表
  7309. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  7310. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  7311. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  7312. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  7313. '{4}','{5}',0,'{6}','{7}',
  7314. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  7315. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  7316. }
  7317. else
  7318. {
  7319. //子表修改
  7320. 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}'";
  7321. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  7322. }
  7323. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7324. {
  7325. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  7326. }
  7327. idss += "'" + itemInfo.DetailID + "',";
  7328. }
  7329. //校验退料数量是否超出领料数量
  7330. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  7331. DBHelper.ExecuteNonQuery(sql, cmd);
  7332. ids += "'" + item.id + "',";
  7333. }
  7334. sql = @"DELETE from ICSOApplyNegDetail where OApplyNegCode ='{0}' and id not in ({1})";
  7335. sql = string.Format(sql, Code, idss.Substring(0, idss.Length - 1));
  7336. DBHelper.ExecuteNonQuery(sql, cmd);
  7337. if (string.IsNullOrWhiteSpace(ids))
  7338. {
  7339. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  7340. }
  7341. #region 查询返回数据
  7342. sql = @"SELECT a.OApplyNegCode,
  7343. c.WHCode,
  7344. c.Memo,
  7345. d.Name AS Status,
  7346. a.Sequence,
  7347. a.InvCode,
  7348. inv.InvName,
  7349. inv.InvStd,
  7350. a.Quantity,
  7351. inv.InvUnit,
  7352. a.Amount,
  7353. inv.AmountUnit,
  7354. a.IssueNegQuantity,
  7355. ext.ProjectCode,
  7356. ext.BatchCode,
  7357. ext.Version,
  7358. ext.Brand,
  7359. ext.cFree1,
  7360. ext.cFree2,
  7361. ext.cFree3,
  7362. ext.cFree4,
  7363. ext.cFree5,
  7364. ext.cFree6,
  7365. ext.cFree7,
  7366. ext.cFree8,
  7367. ext.cFree9,
  7368. ext.cFree10,
  7369. a.MUSER AS [User],
  7370. a.MTIME AS [MTime]
  7371. FROM ICSOApplyNegDetail a
  7372. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  7373. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  7374. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  7375. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  7376. WHERE c.ID IN ({0})";
  7377. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  7378. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7379. #endregion
  7380. cmd.Transaction.Commit();
  7381. return data;
  7382. }
  7383. catch (Exception ex)
  7384. {
  7385. if (cmd.Transaction != null)
  7386. cmd.Transaction.Rollback();
  7387. log.Error(ex.Message);
  7388. throw new Exception(ex.Message);
  7389. }
  7390. finally
  7391. {
  7392. if (conn.State == ConnectionState.Open)
  7393. {
  7394. conn.Close();
  7395. }
  7396. conn.Dispose();
  7397. }
  7398. }
  7399. }
  7400. /// <summary>
  7401. /// 委外退料 修改
  7402. /// </summary>
  7403. /// <param name="JsonData"></param>
  7404. /// <returns></returns>
  7405. public static DataTable AMOutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  7406. {
  7407. var language = LanguageHelper.GetName("WMSAPIInfo");
  7408. if (JsonData.Count <= 0)
  7409. {
  7410. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7411. }
  7412. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7413. {
  7414. conn.Open();
  7415. SqlTransaction sqlTran = conn.BeginTransaction();
  7416. SqlCommand cmd = new SqlCommand();
  7417. cmd.Transaction = sqlTran;
  7418. cmd.Connection = conn;
  7419. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7420. try
  7421. {
  7422. string sql = string.Empty;
  7423. string Code = string.Empty;
  7424. string ids = string.Empty;
  7425. string idss = string.Empty;
  7426. foreach (var item in JsonData)
  7427. {
  7428. //主表修改
  7429. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  7430. BEGIN
  7431. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  7432. RETURN
  7433. END
  7434. DECLARE @Status VARCHAR(10)
  7435. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  7436. IF (@Status IS NULL)
  7437. BEGIN
  7438. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  7439. RETURN
  7440. END
  7441. ELSE IF (@Status!='1')
  7442. BEGIN
  7443. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  7444. RETURN
  7445. END
  7446. 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}' ";
  7447. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  7448. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7449. {
  7450. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  7451. }
  7452. //var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  7453. //if (detail > 0)
  7454. //{
  7455. // sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  7456. // sql = string.Format(sql, item.id, item.WorkPoint);
  7457. // Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  7458. //}
  7459. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  7460. sql = string.Format(sql, item.id, item.WorkPoint);
  7461. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  7462. foreach (var itemInfo in item.detail)
  7463. {
  7464. string chekksql = @"select c.EATTRIBUTE1 ICSInventory c
  7465. WHERE c.InvCode='{0}'AND c.WorkPoint='{1}' and c.AmountEnable='1'";
  7466. chekksql = string.Format(chekksql, itemInfo.InvCode, itemInfo.WorkPoint);
  7467. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  7468. if (dta.Rows.Count > 0)
  7469. {
  7470. itemInfo.Quantity = (itemInfo.Quantity * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString()));
  7471. }
  7472. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  7473. {
  7474. //创建子表
  7475. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  7476. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  7477. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  7478. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  7479. '{4}','{5}',0,'{6}','{7}',
  7480. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  7481. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  7482. }
  7483. else
  7484. {
  7485. //子表修改
  7486. 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}'";
  7487. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  7488. }
  7489. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7490. {
  7491. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  7492. }
  7493. idss += "'" + itemInfo.DetailID + "',";
  7494. }
  7495. //校验退料数量是否超出领料数量
  7496. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  7497. DBHelper.ExecuteNonQuery(sql, cmd);
  7498. ids += "'" + item.id + "',";
  7499. }
  7500. sql = @"DELETE from ICSOApplyNegDetail where OApplyNegCode ='{0}' and id not in ({1})";
  7501. sql = string.Format(sql, Code, idss.Substring(0, idss.Length - 1));
  7502. DBHelper.ExecuteNonQuery(sql, cmd);
  7503. if (string.IsNullOrWhiteSpace(ids))
  7504. {
  7505. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  7506. }
  7507. #region 查询返回数据
  7508. sql = @"SELECT a.OApplyNegCode,
  7509. c.WHCode,
  7510. c.Memo,
  7511. d.Name AS Status,
  7512. a.Sequence,
  7513. a.InvCode,
  7514. inv.InvName,
  7515. inv.InvStd,
  7516. a.Quantity,
  7517. inv.InvUnit,
  7518. a.Amount,
  7519. inv.AmountUnit,
  7520. a.IssueNegQuantity,
  7521. ext.ProjectCode,
  7522. ext.BatchCode,
  7523. ext.Version,
  7524. ext.Brand,
  7525. ext.cFree1,
  7526. ext.cFree2,
  7527. ext.cFree3,
  7528. ext.cFree4,
  7529. ext.cFree5,
  7530. ext.cFree6,
  7531. ext.cFree7,
  7532. ext.cFree8,
  7533. ext.cFree9,
  7534. ext.cFree10,
  7535. a.MUSER AS [User],
  7536. a.MTIME AS [MTime]
  7537. FROM ICSOApplyNegDetail a
  7538. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  7539. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  7540. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  7541. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  7542. WHERE c.ID IN ({0})";
  7543. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  7544. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7545. #endregion
  7546. cmd.Transaction.Commit();
  7547. return data;
  7548. }
  7549. catch (Exception ex)
  7550. {
  7551. if (cmd.Transaction != null)
  7552. cmd.Transaction.Rollback();
  7553. log.Error(ex.Message);
  7554. throw new Exception(ex.Message);
  7555. }
  7556. finally
  7557. {
  7558. if (conn.State == ConnectionState.Open)
  7559. {
  7560. conn.Close();
  7561. }
  7562. conn.Dispose();
  7563. }
  7564. }
  7565. }
  7566. /// <summary>
  7567. /// 委外退料审核
  7568. /// </summary>
  7569. /// <param name="JsonData"></param>
  7570. /// <returns></returns>
  7571. public static DataTable OutsourcingIssueDoNegativeApplyApprove(List<ICSUser> JsonData)
  7572. {
  7573. string flag = string.Empty;
  7574. var language = LanguageHelper.GetName("WMSAPIInfo");
  7575. if (JsonData.Count <= 0)
  7576. {
  7577. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7578. }
  7579. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7580. {
  7581. conn.Open();
  7582. SqlTransaction sqlTran = conn.BeginTransaction();
  7583. SqlCommand cmd = new SqlCommand();
  7584. cmd.Transaction = sqlTran;
  7585. cmd.Connection = conn;
  7586. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7587. try
  7588. {
  7589. string sql = string.Empty;
  7590. string ids = string.Empty;
  7591. foreach (var item in JsonData)
  7592. {
  7593. bool hasApproveFlag = JsonData.Any(u => u.ApproveFlag != null);
  7594. if (hasApproveFlag == true)
  7595. {
  7596. flag = item.ApproveFlag;
  7597. }
  7598. if (string.IsNullOrEmpty(item.ID))
  7599. {
  7600. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  7601. }
  7602. if (string.IsNullOrEmpty(item.User))
  7603. {
  7604. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  7605. }
  7606. if (item.MTime <= new DateTime(2000, 1, 1))
  7607. {
  7608. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  7609. }
  7610. if (flag.Equals("1")|| flag=="")
  7611. {
  7612. //获取单号
  7613. sql = @"DECLARE @Status VARCHAR(10)
  7614. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  7615. IF (@Status IS NULL)
  7616. BEGIN
  7617. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  7618. RETURN
  7619. END
  7620. ELSE IF (@Status!='1')
  7621. BEGIN
  7622. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  7623. RETURN
  7624. END
  7625. update ICSOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  7626. sql = string.Format(sql, item.ID, item.User, item.MTime);
  7627. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7628. {
  7629. throw new Exception(language.GetNameByCode("WMSAPIInfo021"));//"委外退料申请单审核失败!");
  7630. }
  7631. ids += "'" + item.ID + "',";
  7632. }
  7633. else
  7634. {
  7635. //获取单号
  7636. sql = @"DECLARE @Status VARCHAR(10)
  7637. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  7638. IF (@Status IS NULL)
  7639. BEGIN
  7640. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  7641. RETURN
  7642. END
  7643. ELSE IF (@Status!='2')
  7644. BEGIN
  7645. RAISERROR('" + language.GetNameByCode("WMSAPIInfo473") + @"',16,1);
  7646. RETURN
  7647. END
  7648. IF EXISTS (select a.id from ICSOApplyNeg a
  7649. left join ICSOApplyNegDetail b on a.OApplyNegCode=b.OApplyNegCode and a.WorkPoint=b.WorkPoint
  7650. where a.ID='{0}' and b.IssueNegQuantity>0)
  7651. BEGIN
  7652. RAISERROR('" + language.GetNameByCode("WMSAPIInfo474") + @"',16,1);
  7653. RETURN
  7654. END
  7655. update ICSOApplyNeg set Status='1',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  7656. sql = string.Format(sql, item.ID, item.User, item.MTime);
  7657. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7658. {
  7659. throw new Exception(language.GetNameByCode("WMSAPIInfo475"));//"委外退料申请单审核失败!");
  7660. }
  7661. ids += "'" + item.ID + "',";
  7662. }
  7663. }
  7664. if (string.IsNullOrWhiteSpace(ids))
  7665. {
  7666. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  7667. }
  7668. #region 查询返回数据
  7669. sql = @"SELECT a.OApplyNegCode,
  7670. c.WHCode,
  7671. c.Memo,
  7672. d.Name AS Status,
  7673. a.Sequence,
  7674. a.InvCode,
  7675. inv.InvName,
  7676. inv.InvStd,
  7677. a.Quantity,
  7678. inv.InvUnit,
  7679. a.Amount,
  7680. inv.AmountUnit,
  7681. a.IssueNegQuantity,
  7682. ext.ProjectCode,
  7683. ext.BatchCode,
  7684. ext.Version,
  7685. ext.Brand,
  7686. ext.cFree1,
  7687. ext.cFree2,
  7688. ext.cFree3,
  7689. ext.cFree4,
  7690. ext.cFree5,
  7691. ext.cFree6,
  7692. ext.cFree7,
  7693. ext.cFree8,
  7694. ext.cFree9,
  7695. ext.cFree10,
  7696. a.MUSER AS [User],
  7697. a.MTIME AS [MTime]
  7698. FROM ICSOApplyNegDetail a
  7699. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  7700. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  7701. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  7702. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  7703. WHERE c.ID IN ({0})";
  7704. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  7705. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7706. #endregion
  7707. cmd.Transaction.Commit();
  7708. return data;
  7709. }
  7710. catch (Exception ex)
  7711. {
  7712. if (cmd.Transaction != null)
  7713. cmd.Transaction.Rollback();
  7714. log.Error(ex.Message);
  7715. throw new Exception(ex.Message);
  7716. }
  7717. finally
  7718. {
  7719. if (conn.State == ConnectionState.Open)
  7720. {
  7721. conn.Close();
  7722. }
  7723. conn.Dispose();
  7724. }
  7725. }
  7726. }
  7727. /// <summary>
  7728. /// 委外到货
  7729. /// </summary>
  7730. /// <param name="JsonData"></param>
  7731. /// <returns></returns>
  7732. public static DataTable OutsourcingDeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  7733. {
  7734. var language = LanguageHelper.GetName("WMSAPIInfo");
  7735. if (JsonData.Count <= 0)
  7736. {
  7737. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7738. }
  7739. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7740. {
  7741. conn.Open();
  7742. SqlTransaction sqlTran = conn.BeginTransaction();
  7743. SqlCommand cmd = new SqlCommand();
  7744. cmd.Transaction = sqlTran;
  7745. cmd.Connection = conn;
  7746. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7747. try
  7748. {
  7749. string asncodes = string.Empty;
  7750. string sql = string.Empty;
  7751. foreach (var item in JsonData)
  7752. {
  7753. if (string.IsNullOrEmpty(item.OASNCode))
  7754. {
  7755. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!");
  7756. }
  7757. //获取单号
  7758. sql = @"IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.OASNCode='{0}' AND ODNType = '1' AND a.WorkPoint='{1}')
  7759. BEGIN
  7760. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  7761. RETURN
  7762. END
  7763. DECLARE @Status VARCHAR(10)
  7764. SELECT @Status=Status FROM ICSOASN WHERE OASNCode='{0}' and WorkPoint='{1}'
  7765. IF (@Status IS NULL)
  7766. BEGIN
  7767. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  7768. RETURN
  7769. END
  7770. ELSE IF (@Status!='2')
  7771. BEGIN
  7772. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  7773. RETURN
  7774. END
  7775. DECLARE @MaxNO INT,@date varchar(20)='ODN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  7776. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  7777. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  7778. IF @MaxNO IS NULL
  7779. BEGIN
  7780. SELECT @date+'00001' AS Code
  7781. END
  7782. ELSE
  7783. BEGIN
  7784. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  7785. END ";
  7786. sql = string.Format(sql, item.OASNCode, item.WorkPoint);
  7787. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  7788. //修改送货单到货数量
  7789. foreach (var itemInfo in item.detail)
  7790. {
  7791. sql = @"UPDATE ICSOASNDetail SET ODNQuantity=ISNULL(ODNQuantity, 0)+'{2}'
  7792. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  7793. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  7794. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7795. {
  7796. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"委外送货单子表信息更新失败!");
  7797. }
  7798. }
  7799. //创建到货单信息
  7800. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  7801. BEGIN
  7802. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  7803. RETURN
  7804. END
  7805. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  7806. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  7807. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  7808. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  7809. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  7810. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  7811. '1',b.InvCode,SUM(a.ODNQuantity),'0','0',
  7812. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  7813. d.OOID,d.OODetailID,newid(),newid(),b.ExtensionID,
  7814. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.OASNCode
  7815. FROM ICSOASNDetail a
  7816. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  7817. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  7818. INNER JOIN ICSOutsourcingOrder d ON c.TransCode=d.OOCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  7819. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  7820. WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
  7821. 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";
  7822. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.OASNCode);
  7823. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7824. {
  7825. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  7826. }
  7827. if (!DBHelper.IsU9())
  7828. ICSOutsourcingService.OutsourcingDeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  7829. asncodes += "'" + item.OASNCode + item.WorkPoint + "',";
  7830. }
  7831. if (string.IsNullOrWhiteSpace(asncodes))
  7832. {
  7833. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  7834. }
  7835. #region 查询返回数据
  7836. sql = @"SELECT
  7837. n.OOCode,
  7838. n.Sequence AS OOSequence,
  7839. a.OASNCode,
  7840. a.ODNCode,
  7841. a.Sequence,
  7842. a.VenCode,
  7843. a.DepCode,
  7844. a.InvCode,
  7845. inv.InvName,
  7846. inv.InvStd,
  7847. a.Quantity,
  7848. inv.InvUnit,
  7849. a.Amount,
  7850. inv.AmountUnit,
  7851. a.RCVQuantity,
  7852. a.UnitPrice,
  7853. a.Currency,
  7854. a.OOID,
  7855. a.OODetailID,
  7856. a.ODNID,
  7857. a.ODNDetailID,
  7858. ext.ProjectCode,
  7859. ext.BatchCode,
  7860. ext.Version,
  7861. ext.Brand,
  7862. ext.cFree1,
  7863. ext.cFree2,
  7864. ext.cFree3,
  7865. ext.cFree4,
  7866. ext.cFree5,
  7867. ext.cFree6,
  7868. ext.cFree7,
  7869. ext.cFree8,
  7870. ext.cFree9,
  7871. ext.cFree10,
  7872. a.MUSER AS [User],
  7873. a.MTIME AS [MTime]
  7874. FROM ICSODeliveryNotice a
  7875. INNER JOIN ICSOutsourcingOrder n ON a.OOID =n.OOID AND a.OODetailID=n.OODetailID AND a.WorkPoint=n.WorkPoint
  7876. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  7877. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  7878. WHERE a.OASNCode+a.WorkPoint IN ({0})";
  7879. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  7880. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  7881. #endregion
  7882. cmd.Transaction.Commit();
  7883. return data;
  7884. }
  7885. catch (Exception ex)
  7886. {
  7887. if (cmd.Transaction != null)
  7888. cmd.Transaction.Rollback();
  7889. log.Error(ex.Message);
  7890. throw new Exception(ex.Message);
  7891. }
  7892. finally
  7893. {
  7894. if (conn.State == ConnectionState.Open)
  7895. {
  7896. conn.Close();
  7897. }
  7898. conn.Dispose();
  7899. }
  7900. }
  7901. }
  7902. /// <summary>
  7903. /// 委外拒收
  7904. /// </summary>
  7905. /// <param name="JsonData"></param>
  7906. /// <returns></returns>
  7907. public static DataTable OutsourcingRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  7908. {
  7909. var language = LanguageHelper.GetName("WMSAPIInfo");
  7910. if (JsonData.Count <= 0)
  7911. {
  7912. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7913. }
  7914. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7915. {
  7916. conn.Open();
  7917. SqlTransaction sqlTran = conn.BeginTransaction();
  7918. SqlCommand cmd = new SqlCommand();
  7919. cmd.Transaction = sqlTran;
  7920. cmd.Connection = conn;
  7921. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  7922. try
  7923. {
  7924. string lots = string.Empty;
  7925. string sql = string.Empty;
  7926. foreach (var item in JsonData)
  7927. {
  7928. if (string.IsNullOrEmpty(item.ODNCode))
  7929. {
  7930. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  7931. }
  7932. //获取单号
  7933. sql = @"DECLARE @Status VARCHAR(10)
  7934. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  7935. IF (@Status IS NULL)
  7936. BEGIN
  7937. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  7938. RETURN
  7939. END
  7940. ELSE IF (@Status!='2')
  7941. BEGIN
  7942. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  7943. RETURN
  7944. END
  7945. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  7946. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  7947. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  7948. IF @MaxNO IS NULL
  7949. BEGIN
  7950. SELECT @date+'00001' AS Code
  7951. END
  7952. ELSE
  7953. BEGIN
  7954. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  7955. END ";
  7956. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  7957. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  7958. //修改送货单到货数量
  7959. foreach (var itemInfo in item.detail)
  7960. {
  7961. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  7962. BEGIN
  7963. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  7964. RETURN
  7965. END
  7966. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  7967. BEGIN
  7968. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  7969. RETURN
  7970. END
  7971. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  7972. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  7973. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  7974. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  7975. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  7976. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  7977. '3',d.InvCode,'{7}', '{8}', 0,
  7978. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  7979. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  7980. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  7981. FROM ICSODeliveryNotice a
  7982. INNER JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  7983. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  7984. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  7985. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND a.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  7986. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  7987. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  7988. WHERE a.ODNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  7989. 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);
  7990. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  7991. {
  7992. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  7993. }
  7994. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  7995. }
  7996. ICSOutsourcingService.OutsourcingRejectDocInNewERP(item.ODNCode, Code, item.WorkPoint, cmd, language);
  7997. }
  7998. if (string.IsNullOrWhiteSpace(lots))
  7999. {
  8000. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  8001. }
  8002. #region 查询返回数据
  8003. sql = @"SELECT
  8004. n.ODNCode,
  8005. n.Sequence,
  8006. a.ODNCode AS RJTCode,
  8007. a.Sequence AS RJTSequence,
  8008. a.VenCode,
  8009. a.DepCode,
  8010. a.InvCode,
  8011. inv.InvName,
  8012. inv.InvStd,
  8013. a.Quantity,
  8014. inv.InvUnit,
  8015. a.Amount,
  8016. inv.AmountUnit,
  8017. a.RCVQuantity,
  8018. a.UnitPrice,
  8019. a.Currency,
  8020. a.OOID,
  8021. a.OODetailID,
  8022. a.ODNID,
  8023. a.ODNDetailID,
  8024. ext.ProjectCode,
  8025. ext.BatchCode,
  8026. ext.Version,
  8027. ext.Brand,
  8028. ext.cFree1,
  8029. ext.cFree2,
  8030. ext.cFree3,
  8031. ext.cFree4,
  8032. ext.cFree5,
  8033. ext.cFree6,
  8034. ext.cFree7,
  8035. ext.cFree8,
  8036. ext.cFree9,
  8037. ext.cFree10,
  8038. a.MUSER AS [User],
  8039. a.MTIME AS [MTime]
  8040. FROM ICSODeliveryNotice a
  8041. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  8042. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8043. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8044. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  8045. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  8046. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8047. #endregion
  8048. cmd.Transaction.Commit();
  8049. return data;
  8050. }
  8051. catch (Exception ex)
  8052. {
  8053. if (cmd.Transaction != null)
  8054. cmd.Transaction.Rollback();
  8055. log.Error(ex.Message);
  8056. throw new Exception(ex.Message);
  8057. }
  8058. finally
  8059. {
  8060. if (conn.State == ConnectionState.Open)
  8061. {
  8062. conn.Close();
  8063. }
  8064. conn.Dispose();
  8065. }
  8066. }
  8067. }
  8068. /// <summary>
  8069. /// 无订单委外拒收
  8070. /// </summary>
  8071. /// <param name="JsonData"></param>
  8072. /// <returns></returns>
  8073. public static DataTable OutsourcingRejectDocNoTransCreate(List<ICSDeliveryNotice> JsonData)
  8074. {
  8075. var language = LanguageHelper.GetName("WMSAPIInfo");
  8076. if (JsonData.Count <= 0)
  8077. {
  8078. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8079. }
  8080. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8081. {
  8082. conn.Open();
  8083. SqlTransaction sqlTran = conn.BeginTransaction();
  8084. SqlCommand cmd = new SqlCommand();
  8085. cmd.Transaction = sqlTran;
  8086. cmd.Connection = conn;
  8087. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8088. try
  8089. {
  8090. string lots = string.Empty;
  8091. string sql = string.Empty;
  8092. foreach (var item in JsonData)
  8093. {
  8094. if (string.IsNullOrEmpty(item.ODNCode))
  8095. {
  8096. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  8097. }
  8098. //获取单号
  8099. sql = @"DECLARE @Status VARCHAR(10)
  8100. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  8101. IF (@Status IS NULL)
  8102. BEGIN
  8103. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  8104. RETURN
  8105. END
  8106. ELSE IF (@Status!='2')
  8107. BEGIN
  8108. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  8109. RETURN
  8110. END
  8111. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  8112. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  8113. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  8114. IF @MaxNO IS NULL
  8115. BEGIN
  8116. SELECT @date+'00001' AS Code
  8117. END
  8118. ELSE
  8119. BEGIN
  8120. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  8121. END ";
  8122. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  8123. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8124. //修改送货单到货数量
  8125. foreach (var itemInfo in item.detail)
  8126. {
  8127. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  8128. BEGIN
  8129. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  8130. RETURN
  8131. END
  8132. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  8133. BEGIN
  8134. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  8135. RETURN
  8136. END
  8137. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  8138. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  8139. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  8140. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  8141. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  8142. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  8143. '3',d.InvCode,'{7}', '{8}', 0,
  8144. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  8145. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  8146. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, d.LOTNO,''
  8147. FROM ICSODeliveryNotice a
  8148. INNER JOIN ICSInventoryLotDetail m on a.ODNCode=m.TransCode and a.Sequence=m.TransSequence and a.WorkPoint=m.WorkPoint
  8149. INNER JOIN ICSInventoryLot d ON m.LotNo=d.LotNo AND a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint
  8150. INNER JOIN ICSInspection h ON h.LotNo=d.LotNo AND h.WorkPoint=a.WorkPoint
  8151. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  8152. WHERE a.ODNCode='{0}' and d.LOTNO='{1}' AND a.WorkPoint='{2}'";
  8153. 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);
  8154. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8155. {
  8156. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  8157. }
  8158. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  8159. }
  8160. ICSOutsourcingService.OutsourcingRejectDocInNewERP(item.ODNCode, Code, item.WorkPoint, cmd, language);
  8161. }
  8162. if (string.IsNullOrWhiteSpace(lots))
  8163. {
  8164. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  8165. }
  8166. #region 查询返回数据
  8167. sql = @"SELECT
  8168. n.ODNCode,
  8169. n.Sequence,
  8170. a.ODNCode AS RJTCode,
  8171. a.Sequence AS RJTSequence,
  8172. a.VenCode,
  8173. a.DepCode,
  8174. a.InvCode,
  8175. inv.InvName,
  8176. inv.InvStd,
  8177. a.Quantity,
  8178. inv.InvUnit,
  8179. a.Amount,
  8180. inv.AmountUnit,
  8181. a.RCVQuantity,
  8182. a.UnitPrice,
  8183. a.Currency,
  8184. a.OOID,
  8185. a.OODetailID,
  8186. a.ODNID,
  8187. a.ODNDetailID,
  8188. ext.ProjectCode,
  8189. ext.BatchCode,
  8190. ext.Version,
  8191. ext.Brand,
  8192. ext.cFree1,
  8193. ext.cFree2,
  8194. ext.cFree3,
  8195. ext.cFree4,
  8196. ext.cFree5,
  8197. ext.cFree6,
  8198. ext.cFree7,
  8199. ext.cFree8,
  8200. ext.cFree9,
  8201. ext.cFree10,
  8202. a.MUSER AS [User],
  8203. a.MTIME AS [MTime]
  8204. FROM ICSODeliveryNotice a
  8205. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  8206. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8207. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8208. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  8209. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  8210. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8211. #endregion
  8212. cmd.Transaction.Commit();
  8213. return data;
  8214. }
  8215. catch (Exception ex)
  8216. {
  8217. if (cmd.Transaction != null)
  8218. cmd.Transaction.Rollback();
  8219. log.Error(ex.Message);
  8220. throw new Exception(ex.Message);
  8221. }
  8222. finally
  8223. {
  8224. if (conn.State == ConnectionState.Open)
  8225. {
  8226. conn.Close();
  8227. }
  8228. conn.Dispose();
  8229. }
  8230. }
  8231. }
  8232. #endregion
  8233. #region 生产
  8234. /// <summary>
  8235. /// 生产退料 新建
  8236. /// </summary>
  8237. /// <param name="JsonData"></param>
  8238. /// <returns></returns>
  8239. public static DataTable MOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  8240. {
  8241. var language = LanguageHelper.GetName("WMSAPIInfo");
  8242. if (JsonData.Count <= 0)
  8243. {
  8244. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8245. }
  8246. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8247. {
  8248. conn.Open();
  8249. SqlTransaction sqlTran = conn.BeginTransaction();
  8250. SqlCommand cmd = new SqlCommand();
  8251. cmd.Transaction = sqlTran;
  8252. cmd.Connection = conn;
  8253. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8254. try
  8255. {
  8256. string codes = string.Empty;
  8257. string sql = string.Empty;
  8258. foreach (var item in JsonData)
  8259. {
  8260. //获取单号
  8261. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  8262. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  8263. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  8264. IF @MaxNO IS NULL
  8265. BEGIN
  8266. SELECT @date+'00001' AS Code
  8267. END
  8268. ELSE
  8269. BEGIN
  8270. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  8271. END ";
  8272. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8273. //创建主表
  8274. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  8275. BEGIN
  8276. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  8277. RETURN
  8278. END
  8279. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8280. 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}','')";
  8281. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  8282. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8283. {
  8284. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  8285. }
  8286. HashSet<string> addedItems = new HashSet<string>();
  8287. foreach (var itemInfo in item.detail)
  8288. {
  8289. // 创建子表
  8290. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  8291. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  8292. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8293. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  8294. '{4}','{5}',0,'{6}','{7}',
  8295. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  8296. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  8297. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8298. {
  8299. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  8300. }
  8301. string key = itemInfo.Sequence + "~" + itemInfo.InvCode;
  8302. if (addedItems.Contains(key))
  8303. {
  8304. throw new Exception("子件不可重复添加!");
  8305. }
  8306. addedItems.Add(key);
  8307. }
  8308. //校验退料数量是否超出领料数量
  8309. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  8310. DBHelper.ExecuteNonQuery(sql, cmd);
  8311. codes += "'" + Code + item.WorkPoint + "',";
  8312. }
  8313. if (string.IsNullOrWhiteSpace(codes))
  8314. {
  8315. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  8316. }
  8317. #region 查询返回数据
  8318. sql = @"SELECT a.ApplyNegCode,
  8319. c.WHCode,
  8320. c.Memo,
  8321. d.Name AS Status,
  8322. a.Sequence,
  8323. a.InvCode,
  8324. inv.InvName,
  8325. inv.InvStd,
  8326. a.Quantity,
  8327. inv.InvUnit,
  8328. a.Amount,
  8329. inv.AmountUnit,
  8330. a.IssueNegQuantity,
  8331. ext.ProjectCode,
  8332. ext.BatchCode,
  8333. ext.Version,
  8334. ext.Brand,
  8335. ext.cFree1,
  8336. ext.cFree2,
  8337. ext.cFree3,
  8338. ext.cFree4,
  8339. ext.cFree5,
  8340. ext.cFree6,
  8341. ext.cFree7,
  8342. ext.cFree8,
  8343. ext.cFree9,
  8344. ext.cFree10,
  8345. a.MUSER AS [User],
  8346. a.MTIME AS [MTime]
  8347. FROM ICSMOApplyNegDetail a
  8348. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  8349. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  8350. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8351. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8352. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  8353. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  8354. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8355. #endregion
  8356. cmd.Transaction.Commit();
  8357. return data;
  8358. }
  8359. catch (Exception ex)
  8360. {
  8361. if (cmd.Transaction != null)
  8362. cmd.Transaction.Rollback();
  8363. log.Error(ex.Message);
  8364. throw new Exception(ex.Message);
  8365. }
  8366. finally
  8367. {
  8368. if (conn.State == ConnectionState.Open)
  8369. {
  8370. conn.Close();
  8371. }
  8372. conn.Dispose();
  8373. }
  8374. }
  8375. }
  8376. /// <summary>
  8377. /// 生产退料 新建
  8378. /// </summary>
  8379. /// <param name="JsonData"></param>
  8380. /// <returns></returns>
  8381. public static DataTable AMMOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  8382. {
  8383. var language = LanguageHelper.GetName("WMSAPIInfo");
  8384. if (JsonData.Count <= 0)
  8385. {
  8386. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8387. }
  8388. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8389. {
  8390. conn.Open();
  8391. SqlTransaction sqlTran = conn.BeginTransaction();
  8392. SqlCommand cmd = new SqlCommand();
  8393. cmd.Transaction = sqlTran;
  8394. cmd.Connection = conn;
  8395. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8396. try
  8397. {
  8398. string codes = string.Empty;
  8399. string sql = string.Empty;
  8400. foreach (var item in JsonData)
  8401. {
  8402. //获取单号
  8403. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  8404. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  8405. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  8406. IF @MaxNO IS NULL
  8407. BEGIN
  8408. SELECT @date+'00001' AS Code
  8409. END
  8410. ELSE
  8411. BEGIN
  8412. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  8413. END ";
  8414. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8415. //创建主表
  8416. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  8417. BEGIN
  8418. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  8419. RETURN
  8420. END
  8421. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8422. 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}','')";
  8423. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  8424. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8425. {
  8426. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  8427. }
  8428. HashSet<string> addedItems = new HashSet<string>();
  8429. foreach (var itemInfo in item.detail)
  8430. {
  8431. string chekksql = @"select c.EATTRIBUTE1 ICSInventory c
  8432. WHERE c.InvCode='{0}'AND c.WorkPoint='{1}' and c.AmountEnable='1'";
  8433. chekksql = string.Format(chekksql, itemInfo.InvCode, itemInfo.WorkPoint);
  8434. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  8435. if (dta.Rows.Count > 0)
  8436. {
  8437. itemInfo.Quantity = (decimal.Parse(itemInfo.Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  8438. }
  8439. // 创建子表
  8440. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  8441. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  8442. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8443. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  8444. '{4}','{5}',0,'{6}','{7}',
  8445. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  8446. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  8447. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8448. {
  8449. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  8450. }
  8451. string key = itemInfo.Sequence + "~" + itemInfo.InvCode;
  8452. if (addedItems.Contains(key))
  8453. {
  8454. throw new Exception("子件不可重复添加!");
  8455. }
  8456. addedItems.Add(key);
  8457. }
  8458. //校验退料数量是否超出领料数量
  8459. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  8460. DBHelper.ExecuteNonQuery(sql, cmd);
  8461. codes += "'" + Code + item.WorkPoint + "',";
  8462. }
  8463. if (string.IsNullOrWhiteSpace(codes))
  8464. {
  8465. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  8466. }
  8467. #region 查询返回数据
  8468. sql = @"SELECT a.ApplyNegCode,
  8469. c.WHCode,
  8470. c.Memo,
  8471. d.Name AS Status,
  8472. a.Sequence,
  8473. a.InvCode,
  8474. inv.InvName,
  8475. inv.InvStd,
  8476. a.Quantity,
  8477. inv.InvUnit,
  8478. a.Amount,
  8479. inv.AmountUnit,
  8480. a.IssueNegQuantity,
  8481. ext.ProjectCode,
  8482. ext.BatchCode,
  8483. ext.Version,
  8484. ext.Brand,
  8485. ext.cFree1,
  8486. ext.cFree2,
  8487. ext.cFree3,
  8488. ext.cFree4,
  8489. ext.cFree5,
  8490. ext.cFree6,
  8491. ext.cFree7,
  8492. ext.cFree8,
  8493. ext.cFree9,
  8494. ext.cFree10,
  8495. a.MUSER AS [User],
  8496. a.MTIME AS [MTime]
  8497. FROM ICSMOApplyNegDetail a
  8498. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  8499. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  8500. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8501. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8502. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  8503. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  8504. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8505. #endregion
  8506. cmd.Transaction.Commit();
  8507. return data;
  8508. }
  8509. catch (Exception ex)
  8510. {
  8511. if (cmd.Transaction != null)
  8512. cmd.Transaction.Rollback();
  8513. log.Error(ex.Message);
  8514. throw new Exception(ex.Message);
  8515. }
  8516. finally
  8517. {
  8518. if (conn.State == ConnectionState.Open)
  8519. {
  8520. conn.Close();
  8521. }
  8522. conn.Dispose();
  8523. }
  8524. }
  8525. }
  8526. private static string CheckMOIssueDoc(string Type, string ID, string WorkPoint, Dictionary<string, string> language)
  8527. {
  8528. string sql = string.Empty;
  8529. if (Type == "1")
  8530. {
  8531. sql = @"DECLARE @PickID VARCHAR(10)
  8532. SELECT @PickID=b.PickID
  8533. FROM ICSMOApplyNegDetail a
  8534. INNER JOIN ICSMOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  8535. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  8536. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  8537. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  8538. FROM ICSMOApplyNegDetail a
  8539. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  8540. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  8541. GROUP BY b.PickID
  8542. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  8543. IF (@PickID IS NOT NULL)
  8544. BEGIN
  8545. DECLARE @InvCode VARCHAR(100)
  8546. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  8547. RAISERROR(@InvCode,16,1);
  8548. RETURN
  8549. END ";
  8550. }
  8551. else if (Type == "2")
  8552. {
  8553. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  8554. SELECT @ApplyDetailID=b.ApplyDetailID
  8555. FROM ICSMOApplyNegDetail a
  8556. INNER JOIN ICSMOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  8557. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  8558. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  8559. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  8560. FROM ICSMOApplyNegDetail a
  8561. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  8562. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  8563. GROUP BY b.ApplyDetailID
  8564. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  8565. IF (@ApplyDetailID IS NOT NULL)
  8566. BEGIN
  8567. DECLARE @InvCode VARCHAR(100)
  8568. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  8569. RAISERROR(@InvCode,16,1);
  8570. RETURN
  8571. END ";
  8572. }
  8573. else if (Type == "3")
  8574. {
  8575. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  8576. SELECT @IssueDetailID=b.IssueDetailID
  8577. FROM ICSMOApplyNegDetail a
  8578. INNER JOIN ICSMOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  8579. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  8580. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  8581. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  8582. FROM ICSMOApplyNegDetail a
  8583. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  8584. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  8585. GROUP BY b.IssueDetailID
  8586. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  8587. IF (@IssueDetailID IS NOT NULL)
  8588. BEGIN
  8589. DECLARE @InvCode VARCHAR(100)
  8590. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  8591. RAISERROR(@InvCode,16,1);
  8592. RETURN
  8593. END ";
  8594. }
  8595. else
  8596. {
  8597. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  8598. }
  8599. sql = string.Format(sql, ID, WorkPoint, Type);
  8600. return sql;
  8601. }
  8602. /// <summary>
  8603. /// 生产退料 修改
  8604. /// </summary>
  8605. /// <param name="JsonData"></param>
  8606. /// <returns></returns>
  8607. public static DataTable MOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  8608. {
  8609. var language = LanguageHelper.GetName("WMSAPIInfo");
  8610. if (JsonData.Count <= 0)
  8611. {
  8612. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8613. }
  8614. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8615. {
  8616. conn.Open();
  8617. SqlTransaction sqlTran = conn.BeginTransaction();
  8618. SqlCommand cmd = new SqlCommand();
  8619. cmd.Transaction = sqlTran;
  8620. cmd.Connection = conn;
  8621. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8622. try
  8623. {
  8624. string sql = string.Empty;
  8625. string Code = string.Empty;
  8626. string ids = string.Empty;
  8627. string idss = string.Empty;
  8628. foreach (var item in JsonData)
  8629. {
  8630. //主表修改
  8631. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  8632. BEGIN
  8633. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  8634. RETURN
  8635. END
  8636. DECLARE @Status VARCHAR(10)
  8637. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  8638. IF (@Status IS NULL)
  8639. BEGIN
  8640. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  8641. RETURN
  8642. END
  8643. ELSE IF (@Status!='1')
  8644. BEGIN
  8645. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  8646. RETURN
  8647. END
  8648. 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}' ";
  8649. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint);
  8650. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8651. {
  8652. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  8653. }
  8654. //var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  8655. //if (detail > 0)
  8656. //{
  8657. // sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  8658. // sql = string.Format(sql, item.ID, item.WorkPoint);
  8659. // Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8660. //}
  8661. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  8662. sql = string.Format(sql, item.ID, item.WorkPoint);
  8663. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8664. foreach (var itemInfo in item.detail)
  8665. {
  8666. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  8667. {
  8668. //创建子表
  8669. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  8670. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8671. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  8672. '{4}','{5}',0,'{6}','{7}',
  8673. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  8674. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  8675. }
  8676. else
  8677. {
  8678. //子表修改
  8679. 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}'";
  8680. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  8681. }
  8682. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8683. {
  8684. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  8685. }
  8686. idss += "'" + itemInfo.DetailID + "',";
  8687. }
  8688. //校验退料数量是否超出领料数量
  8689. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  8690. DBHelper.ExecuteNonQuery(sql, cmd);
  8691. ids += "'" + item.ID + "',";
  8692. }
  8693. sql = @"DELETE from ICSMOApplyNegDetail where ApplyNegCode ='{0}' and id not in ({1})";
  8694. sql = string.Format(sql, Code, idss.Substring(0, idss.Length - 1));
  8695. DBHelper.ExecuteNonQuery(sql, cmd);
  8696. if (string.IsNullOrWhiteSpace(ids))
  8697. {
  8698. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  8699. }
  8700. #region 查询返回数据
  8701. sql = @"SELECT a.ApplyNegCode,
  8702. c.WHCode,
  8703. c.Memo,
  8704. d.Name AS Status,
  8705. a.Sequence,
  8706. a.InvCode,
  8707. inv.InvName,
  8708. inv.InvStd,
  8709. a.Quantity,
  8710. inv.InvUnit,
  8711. a.Amount,
  8712. inv.AmountUnit,
  8713. a.IssueNegQuantity,
  8714. ext.ProjectCode,
  8715. ext.BatchCode,
  8716. ext.Version,
  8717. ext.Brand,
  8718. ext.cFree1,
  8719. ext.cFree2,
  8720. ext.cFree3,
  8721. ext.cFree4,
  8722. ext.cFree5,
  8723. ext.cFree6,
  8724. ext.cFree7,
  8725. ext.cFree8,
  8726. ext.cFree9,
  8727. ext.cFree10,
  8728. a.MUSER AS [User],
  8729. a.MTIME AS [MTime]
  8730. FROM ICSMOApplyNegDetail a
  8731. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  8732. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  8733. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8734. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8735. WHERE c.ID IN ({0})";
  8736. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  8737. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8738. #endregion
  8739. cmd.Transaction.Commit();
  8740. return data;
  8741. }
  8742. catch (Exception ex)
  8743. {
  8744. if (cmd.Transaction != null)
  8745. cmd.Transaction.Rollback();
  8746. log.Error(ex.Message);
  8747. throw new Exception(ex.Message);
  8748. }
  8749. finally
  8750. {
  8751. if (conn.State == ConnectionState.Open)
  8752. {
  8753. conn.Close();
  8754. }
  8755. conn.Dispose();
  8756. }
  8757. }
  8758. }
  8759. /// <summary>
  8760. /// 生产退料 修改
  8761. /// </summary>
  8762. /// <param name="JsonData"></param>
  8763. /// <returns></returns>
  8764. public static DataTable AMMOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  8765. {
  8766. var language = LanguageHelper.GetName("WMSAPIInfo");
  8767. if (JsonData.Count <= 0)
  8768. {
  8769. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8770. }
  8771. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8772. {
  8773. conn.Open();
  8774. SqlTransaction sqlTran = conn.BeginTransaction();
  8775. SqlCommand cmd = new SqlCommand();
  8776. cmd.Transaction = sqlTran;
  8777. cmd.Connection = conn;
  8778. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8779. try
  8780. {
  8781. string sql = string.Empty;
  8782. string Code = string.Empty;
  8783. string ids = string.Empty;
  8784. string idss = string.Empty;
  8785. foreach (var item in JsonData)
  8786. {
  8787. //主表修改
  8788. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  8789. BEGIN
  8790. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  8791. RETURN
  8792. END
  8793. DECLARE @Status VARCHAR(10)
  8794. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  8795. IF (@Status IS NULL)
  8796. BEGIN
  8797. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  8798. RETURN
  8799. END
  8800. ELSE IF (@Status!='1')
  8801. BEGIN
  8802. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  8803. RETURN
  8804. END
  8805. 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}' ";
  8806. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint);
  8807. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8808. {
  8809. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  8810. }
  8811. //var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  8812. //if (detail > 0)
  8813. //{
  8814. // sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  8815. // sql = string.Format(sql, item.ID, item.WorkPoint);
  8816. // Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8817. //}
  8818. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  8819. sql = string.Format(sql, item.ID, item.WorkPoint);
  8820. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  8821. foreach (var itemInfo in item.detail)
  8822. {
  8823. string chekksql = @"select c.EATTRIBUTE1 ICSInventory c
  8824. WHERE c.InvCode='{0}'AND c.WorkPoint='{1}' and c.AmountEnable='1'";
  8825. chekksql = string.Format(chekksql, itemInfo.InvCode, itemInfo.WorkPoint);
  8826. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  8827. if (dta.Rows.Count > 0)
  8828. {
  8829. itemInfo.Quantity = (decimal.Parse(itemInfo.Quantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  8830. }
  8831. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  8832. {
  8833. //创建子表
  8834. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  8835. MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  8836. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  8837. '{4}','{5}',0,'{6}','{7}',
  8838. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  8839. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  8840. }
  8841. else
  8842. {
  8843. //子表修改
  8844. 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}'";
  8845. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  8846. }
  8847. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8848. {
  8849. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  8850. }
  8851. idss += "'" + itemInfo.DetailID + "',";
  8852. }
  8853. //校验退料数量是否超出领料数量
  8854. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  8855. DBHelper.ExecuteNonQuery(sql, cmd);
  8856. ids += "'" + item.ID + "',";
  8857. }
  8858. sql = @"DELETE from ICSMOApplyNegDetail where ApplyNegCode ='{0}' and id not in ({1})";
  8859. sql = string.Format(sql, Code, idss.Substring(0, idss.Length - 1));
  8860. DBHelper.ExecuteNonQuery(sql, cmd);
  8861. if (string.IsNullOrWhiteSpace(ids))
  8862. {
  8863. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  8864. }
  8865. #region 查询返回数据
  8866. sql = @"SELECT a.ApplyNegCode,
  8867. c.WHCode,
  8868. c.Memo,
  8869. d.Name AS Status,
  8870. a.Sequence,
  8871. a.InvCode,
  8872. inv.InvName,
  8873. inv.InvStd,
  8874. a.Quantity,
  8875. inv.InvUnit,
  8876. a.Amount,
  8877. inv.AmountUnit,
  8878. a.IssueNegQuantity,
  8879. ext.ProjectCode,
  8880. ext.BatchCode,
  8881. ext.Version,
  8882. ext.Brand,
  8883. ext.cFree1,
  8884. ext.cFree2,
  8885. ext.cFree3,
  8886. ext.cFree4,
  8887. ext.cFree5,
  8888. ext.cFree6,
  8889. ext.cFree7,
  8890. ext.cFree8,
  8891. ext.cFree9,
  8892. ext.cFree10,
  8893. a.MUSER AS [User],
  8894. a.MTIME AS [MTime]
  8895. FROM ICSMOApplyNegDetail a
  8896. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  8897. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  8898. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  8899. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  8900. WHERE c.ID IN ({0})";
  8901. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  8902. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  8903. #endregion
  8904. cmd.Transaction.Commit();
  8905. return data;
  8906. }
  8907. catch (Exception ex)
  8908. {
  8909. if (cmd.Transaction != null)
  8910. cmd.Transaction.Rollback();
  8911. log.Error(ex.Message);
  8912. throw new Exception(ex.Message);
  8913. }
  8914. finally
  8915. {
  8916. if (conn.State == ConnectionState.Open)
  8917. {
  8918. conn.Close();
  8919. }
  8920. conn.Dispose();
  8921. }
  8922. }
  8923. }
  8924. /// <summary>
  8925. /// 生产退料审核
  8926. /// </summary>
  8927. /// <param name="JsonData"></param>
  8928. /// <returns></returns>
  8929. public static DataTable MOIssueDocNegativeApplyApprove(List<ICSUser> JsonData)
  8930. {
  8931. string flag = string.Empty;
  8932. var language = LanguageHelper.GetName("WMSAPIInfo");
  8933. if (JsonData.Count <= 0)
  8934. {
  8935. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  8936. }
  8937. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  8938. {
  8939. conn.Open();
  8940. SqlTransaction sqlTran = conn.BeginTransaction();
  8941. SqlCommand cmd = new SqlCommand();
  8942. cmd.Transaction = sqlTran;
  8943. cmd.Connection = conn;
  8944. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  8945. try
  8946. {
  8947. string sql = string.Empty;
  8948. string ids = string.Empty;
  8949. foreach (var item in JsonData)
  8950. {
  8951. bool hasApproveFlag = JsonData.Any(u => u.ApproveFlag != null);
  8952. if (hasApproveFlag == true)
  8953. {
  8954. flag = item.ApproveFlag;
  8955. }
  8956. if (string.IsNullOrEmpty(item.ID))
  8957. {
  8958. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  8959. }
  8960. if (string.IsNullOrEmpty(item.User))
  8961. {
  8962. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  8963. }
  8964. if (item.MTime <= new DateTime(2000, 1, 1))
  8965. {
  8966. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  8967. }
  8968. if (flag.Equals("1")|| flag=="")
  8969. {
  8970. //获取单号
  8971. sql = @"DECLARE @Status VARCHAR(10)
  8972. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  8973. IF (@Status IS NULL)
  8974. BEGIN
  8975. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  8976. RETURN
  8977. END
  8978. ELSE IF (@Status!='1')
  8979. BEGIN
  8980. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  8981. RETURN
  8982. END
  8983. update ICSMOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  8984. sql = string.Format(sql, item.ID, item.User, item.MTime);
  8985. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  8986. {
  8987. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  8988. }
  8989. ids += "'" + item.ID + "',";
  8990. }
  8991. else
  8992. {
  8993. //获取单号
  8994. sql = @"DECLARE @Status VARCHAR(10)
  8995. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  8996. IF (@Status IS NULL)
  8997. BEGIN
  8998. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  8999. RETURN
  9000. END
  9001. ELSE IF (@Status!='2')
  9002. BEGIN
  9003. RAISERROR('" + language.GetNameByCode("WMSAPIInfo473") + @"',16,1);
  9004. RETURN
  9005. END
  9006. IF EXISTS (select a.id from ICSMOApplyNeg a
  9007. left join ICSMOApplyNegDetail b on a.ApplyNegCode=b.ApplyNegCode and a.WorkPoint=b.WorkPoint
  9008. where a.ID='{0}' and b.IssueNegQuantity>0)
  9009. BEGIN
  9010. RAISERROR('" + language.GetNameByCode("WMSAPIInfo474") + @"',16,1);
  9011. RETURN
  9012. END
  9013. update ICSMOApplyNeg set Status='1',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  9014. sql = string.Format(sql, item.ID, item.User, item.MTime);
  9015. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9016. {
  9017. throw new Exception(language.GetNameByCode("WMSAPIInfo475"));//"生产退料申请单弃审失败!");
  9018. }
  9019. ids += "'" + item.ID + "',";
  9020. }
  9021. }
  9022. if (string.IsNullOrWhiteSpace(ids))
  9023. {
  9024. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  9025. }
  9026. #region 查询返回数据
  9027. sql = @"SELECT a.ApplyNegCode,
  9028. c.WHCode,
  9029. c.Memo,
  9030. d.Name AS Status,
  9031. a.Sequence,
  9032. a.InvCode,
  9033. inv.InvName,
  9034. inv.InvStd,
  9035. a.Quantity,
  9036. inv.InvUnit,
  9037. a.Amount,
  9038. inv.AmountUnit,
  9039. a.IssueNegQuantity,
  9040. ext.ProjectCode,
  9041. ext.BatchCode,
  9042. ext.Version,
  9043. ext.Brand,
  9044. ext.cFree1,
  9045. ext.cFree2,
  9046. ext.cFree3,
  9047. ext.cFree4,
  9048. ext.cFree5,
  9049. ext.cFree6,
  9050. ext.cFree7,
  9051. ext.cFree8,
  9052. ext.cFree9,
  9053. ext.cFree10,
  9054. a.MUSER AS [User],
  9055. a.MTIME AS [MTime]
  9056. FROM ICSMOApplyNegDetail a
  9057. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  9058. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  9059. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  9060. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  9061. WHERE c.ID IN ({0})";
  9062. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  9063. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  9064. #endregion
  9065. cmd.Transaction.Commit();
  9066. return data;
  9067. }
  9068. catch (Exception ex)
  9069. {
  9070. if (cmd.Transaction != null)
  9071. cmd.Transaction.Rollback();
  9072. log.Error(ex.Message);
  9073. throw new Exception(ex.Message);
  9074. }
  9075. finally
  9076. {
  9077. if (conn.State == ConnectionState.Open)
  9078. {
  9079. conn.Close();
  9080. }
  9081. conn.Dispose();
  9082. }
  9083. }
  9084. }
  9085. #endregion
  9086. #region 一步调拨(调拨申请单)
  9087. /// <summary>
  9088. /// 一步调拨(调拨申请单)
  9089. /// </summary>
  9090. /// <param name="JsonData"></param>
  9091. /// <returns></returns>
  9092. public static DataTable OneStepTransferApplicationIn(List<TransferApplication> JsonData)
  9093. {
  9094. var language = LanguageHelper.GetName("WMSAPIInfo");
  9095. if (JsonData.Count <= 0)
  9096. {
  9097. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9098. }
  9099. DataTable printTable = new DataTable();
  9100. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9101. {
  9102. conn.Open();
  9103. SqlTransaction sqlTran = conn.BeginTransaction();
  9104. SqlCommand cmd = new SqlCommand();
  9105. cmd.Transaction = sqlTran;
  9106. cmd.Connection = conn;
  9107. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9108. string BusinessCode = string.Empty;
  9109. try
  9110. {
  9111. string sql = string.Empty;
  9112. string Identification = Guid.NewGuid().ToString();
  9113. foreach (var item in JsonData)
  9114. {
  9115. if (string.IsNullOrEmpty(item.TransCode))
  9116. {
  9117. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨申请单号不能为空!");
  9118. }
  9119. string[] trans = item.TransCode.Split('~');
  9120. string MergeID = "";
  9121. if (trans.Length == 2)
  9122. {
  9123. MergeID = trans[0];
  9124. item.TransCode = trans[1];
  9125. }
  9126. //验证信息
  9127. sql = @"DECLARE @Status VARCHAR(10)
  9128. SELECT @Status=Status FROM ICSTransferApplication WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  9129. IF (@Status IS NULL)
  9130. BEGIN
  9131. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  9132. RETURN
  9133. END
  9134. ELSE IF (@Status!='1')
  9135. BEGIN
  9136. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  9137. RETURN
  9138. END";
  9139. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  9140. DBHelper.ExecuteNonQuery(sql, cmd);
  9141. foreach (var itemInfo in item.Detail)
  9142. {
  9143. //验证仓库库位信息
  9144. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  9145. BEGIN
  9146. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  9147. RETURN
  9148. END
  9149. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  9150. BEGIN
  9151. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  9152. RETURN
  9153. END
  9154. IF NOT EXISTS(SELECT a.ID
  9155. FROM ICSWareHouse a
  9156. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  9157. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  9158. BEGIN
  9159. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  9160. RETURN
  9161. END";
  9162. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  9163. DBHelper.ExecuteNonQuery(sql, cmd);
  9164. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  9165. //更新源头单据信息
  9166. ICSWareHouseService.OneStepTransferApplicationIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  9167. //更新条码信息
  9168. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  9169. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  9170. }
  9171. }
  9172. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  9173. if (!printTable.Equals("{}"))
  9174. {
  9175. cmd.Transaction.Commit();
  9176. return printTable;
  9177. }
  9178. else
  9179. {
  9180. DataTable table = GetData(Identification, 3, cmd);
  9181. cmd.Transaction.Commit();
  9182. return table;
  9183. }
  9184. }
  9185. catch (Exception ex)
  9186. {
  9187. if (cmd.Transaction != null)
  9188. cmd.Transaction.Rollback();
  9189. log.Error(ex.Message);
  9190. throw new Exception(ex.Message);
  9191. }
  9192. finally
  9193. {
  9194. if (conn.State == ConnectionState.Open)
  9195. {
  9196. conn.Close();
  9197. }
  9198. conn.Dispose();
  9199. }
  9200. }
  9201. }
  9202. #endregion
  9203. #region 一步调拨
  9204. /// <summary>
  9205. /// 一步调拨
  9206. /// </summary>
  9207. /// <param name="JsonData"></param>
  9208. /// <returns></returns>
  9209. public static DataTable OneStepTransferDocIn(List<TransferDoc> JsonData)
  9210. {
  9211. var language = LanguageHelper.GetName("WMSAPIInfo");
  9212. if (JsonData.Count <= 0)
  9213. {
  9214. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9215. }
  9216. DataTable printTable = new DataTable();
  9217. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9218. {
  9219. conn.Open();
  9220. SqlTransaction sqlTran = conn.BeginTransaction();
  9221. SqlCommand cmd = new SqlCommand();
  9222. cmd.Transaction = sqlTran;
  9223. cmd.Connection = conn;
  9224. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9225. string BusinessCode = string.Empty;
  9226. try
  9227. {
  9228. string sql = string.Empty;
  9229. string Identification = Guid.NewGuid().ToString();
  9230. foreach (var item in JsonData)
  9231. {
  9232. if (string.IsNullOrEmpty(item.TransCode))
  9233. {
  9234. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨单号不能为空!");
  9235. }
  9236. string[] trans = item.TransCode.Split('~');
  9237. string MergeID = "";
  9238. if (trans.Length == 2)
  9239. {
  9240. MergeID = trans[0];
  9241. item.TransCode = trans[1];
  9242. }
  9243. //验证信息
  9244. sql = @"DECLARE @Status VARCHAR(10)
  9245. SELECT @Status=Status FROM ICSTransfer WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  9246. IF (@Status IS NULL)
  9247. BEGIN
  9248. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  9249. RETURN
  9250. END
  9251. ELSE IF (@Status!='1')
  9252. BEGIN
  9253. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  9254. RETURN
  9255. END";
  9256. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  9257. DBHelper.ExecuteNonQuery(sql, cmd);
  9258. foreach (var itemInfo in item.Detail)
  9259. {
  9260. //验证仓库库位信息
  9261. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  9262. BEGIN
  9263. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  9264. RETURN
  9265. END
  9266. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  9267. BEGIN
  9268. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  9269. RETURN
  9270. END
  9271. IF NOT EXISTS(SELECT a.ID
  9272. FROM ICSWareHouse a
  9273. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  9274. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  9275. BEGIN
  9276. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  9277. RETURN
  9278. END";
  9279. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  9280. DBHelper.ExecuteNonQuery(sql, cmd);
  9281. BusinessCode = TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>();
  9282. //更新源头单据信息
  9283. ICSWareHouseService.OneStepTransferDocIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  9284. //更新条码信息
  9285. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  9286. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  9287. }
  9288. }
  9289. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  9290. if (!printTable.Equals("{}"))
  9291. {
  9292. cmd.Transaction.Commit();
  9293. return printTable;
  9294. }
  9295. else
  9296. {
  9297. DataTable table = GetData(Identification, 3, cmd);
  9298. cmd.Transaction.Commit();
  9299. return table;
  9300. }
  9301. }
  9302. catch (Exception ex)
  9303. {
  9304. if (cmd.Transaction != null)
  9305. cmd.Transaction.Rollback();
  9306. log.Error(ex.Message);
  9307. throw new Exception(ex.Message);
  9308. }
  9309. finally
  9310. {
  9311. if (conn.State == ConnectionState.Open)
  9312. {
  9313. conn.Close();
  9314. }
  9315. conn.Dispose();
  9316. }
  9317. }
  9318. }
  9319. #endregion
  9320. #region 调拨
  9321. /// <summary>
  9322. /// 调拨
  9323. /// </summary>
  9324. /// <param name="JsonData"></param>
  9325. /// <returns></returns>
  9326. public static DataTable TransferDocCreate(List<TransferDoc> JsonData)
  9327. {
  9328. var language = LanguageHelper.GetName("WMSAPIInfo");
  9329. if (JsonData.Count <= 0)
  9330. {
  9331. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9332. }
  9333. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9334. {
  9335. conn.Open();
  9336. SqlTransaction sqlTran = conn.BeginTransaction();
  9337. SqlCommand cmd = new SqlCommand();
  9338. cmd.Transaction = sqlTran;
  9339. cmd.Connection = conn;
  9340. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9341. string BusinessCode = string.Empty;
  9342. try
  9343. {
  9344. string sql = string.Empty;
  9345. string Identification = Guid.NewGuid().ToString();
  9346. foreach (var item in JsonData)
  9347. {
  9348. string MergeID = "";
  9349. foreach (var itemInfo in item.Detail)
  9350. {
  9351. //验证仓库库位信息
  9352. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  9353. BEGIN
  9354. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  9355. RETURN
  9356. END
  9357. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  9358. BEGIN
  9359. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  9360. RETURN
  9361. END
  9362. IF NOT EXISTS(SELECT a.ID
  9363. FROM ICSWareHouse a
  9364. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  9365. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  9366. BEGIN
  9367. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  9368. RETURN
  9369. END";
  9370. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  9371. DBHelper.ExecuteNonQuery(sql, cmd);
  9372. BusinessCode = TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>();
  9373. //更新条码信息
  9374. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  9375. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  9376. }
  9377. }
  9378. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  9379. DataTable table = GetData(Identification, 3, cmd);
  9380. cmd.Transaction.Commit();
  9381. return table;
  9382. }
  9383. catch (Exception ex)
  9384. {
  9385. if (cmd.Transaction != null)
  9386. cmd.Transaction.Rollback();
  9387. log.Error(ex.Message);
  9388. throw new Exception(ex.Message);
  9389. }
  9390. finally
  9391. {
  9392. if (conn.State == ConnectionState.Open)
  9393. {
  9394. conn.Close();
  9395. }
  9396. conn.Dispose();
  9397. }
  9398. }
  9399. }
  9400. #endregion
  9401. #region 无源头调拨
  9402. /// <summary>
  9403. /// 无源头调拨
  9404. /// </summary>
  9405. /// <param name="JsonData"></param>
  9406. /// <returns></returns>
  9407. public static DataTable OneStepNoTransferDocIn(List<TransferDoc> JsonData)
  9408. {
  9409. var language = LanguageHelper.GetName("WMSAPIInfo");
  9410. if (JsonData.Count <= 0)
  9411. {
  9412. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9413. }
  9414. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9415. {
  9416. conn.Open();
  9417. SqlTransaction sqlTran = conn.BeginTransaction();
  9418. SqlCommand cmd = new SqlCommand();
  9419. cmd.Transaction = sqlTran;
  9420. DataTable printTable = new DataTable();
  9421. cmd.Connection = conn;
  9422. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9423. try
  9424. {
  9425. string sql = string.Empty;
  9426. string Identification = Guid.NewGuid().ToString();
  9427. string BusinessCode = "";
  9428. foreach (var item in JsonData)
  9429. {
  9430. string MergeID = "";
  9431. foreach (var itemInfo in item.Detail)
  9432. {
  9433. //判断是否开启辅计量,计算辅计量比例
  9434. string chekksql = @"select c.EATTRIBUTE1 FROM ICSInventoryLot a
  9435. INNER JOIN ICSInventory c on a.InvCode=c.InvCode and a.WorkPoint=c.WorkPoint
  9436. WHERE a.lotno='{0}' AND a.WorkPoint='{1}' and c.AmountEnable='1'";
  9437. chekksql = string.Format(chekksql, itemInfo.LotNo, item.WorkPoint, itemInfo.CurrentQuantity);
  9438. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  9439. if (dta.Rows.Count > 0)
  9440. {
  9441. itemInfo.CurrentQuantity = (decimal.Parse(itemInfo.CurrentQuantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  9442. }
  9443. //验证仓库库位信息
  9444. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  9445. BEGIN
  9446. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  9447. RETURN
  9448. END
  9449. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  9450. BEGIN
  9451. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  9452. RETURN
  9453. END
  9454. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{3}' AND a.WorkPoint='{1}' AND a.Quantity>={4})
  9455. BEGIN
  9456. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo368")) + @"',16,1);
  9457. RETURN
  9458. END
  9459. IF NOT EXISTS(SELECT a.ID
  9460. FROM ICSWareHouse a
  9461. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  9462. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  9463. BEGIN
  9464. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  9465. RETURN
  9466. END";
  9467. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.CurrentQuantity);
  9468. DBHelper.ExecuteNonQuery(sql, cmd);
  9469. BusinessCode = TransTypeEnum.StepNoTransferDocIn.GetDescription<DBValue>();
  9470. //更新条码信息
  9471. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoNoTransfer(Identification, itemInfo.WarehouseCode, itemInfo.LocationCode,
  9472. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepNoTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  9473. }
  9474. }
  9475. ICSWareHouseService.OneStepNoTransferDocInERP(TransTypeEnum.StepNoTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  9476. if (!printTable.Equals("{}"))
  9477. {
  9478. cmd.Transaction.Commit();
  9479. return printTable;
  9480. }
  9481. else
  9482. {
  9483. DataTable table = GetData(Identification, 3, cmd);
  9484. cmd.Transaction.Commit();
  9485. return table;
  9486. }
  9487. }
  9488. catch (Exception ex)
  9489. {
  9490. if (cmd.Transaction != null)
  9491. cmd.Transaction.Rollback();
  9492. log.Error(ex.Message);
  9493. throw new Exception(ex.Message);
  9494. }
  9495. finally
  9496. {
  9497. if (conn.State == ConnectionState.Open)
  9498. {
  9499. conn.Close();
  9500. }
  9501. conn.Dispose();
  9502. }
  9503. }
  9504. }
  9505. #endregion
  9506. #region 调拨申请单
  9507. /// <summary>
  9508. /// 调拨
  9509. /// </summary>
  9510. /// <param name="JsonData"></param>
  9511. /// <returns></returns>
  9512. public static DataTable TransferApplicationCreate(List<TransferApplication> JsonData)
  9513. {
  9514. var language = LanguageHelper.GetName("WMSAPIInfo");
  9515. if (JsonData.Count <= 0)
  9516. {
  9517. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9518. }
  9519. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9520. {
  9521. conn.Open();
  9522. SqlTransaction sqlTran = conn.BeginTransaction();
  9523. SqlCommand cmd = new SqlCommand();
  9524. cmd.Transaction = sqlTran;
  9525. cmd.Connection = conn;
  9526. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9527. string BusinessCode = string.Empty;
  9528. try
  9529. {
  9530. string sql = string.Empty;
  9531. string Identification = Guid.NewGuid().ToString();
  9532. foreach (var item in JsonData)
  9533. {
  9534. string MergeID = "";
  9535. foreach (var itemInfo in item.Detail)
  9536. {
  9537. //验证仓库库位信息
  9538. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  9539. BEGIN
  9540. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  9541. RETURN
  9542. END
  9543. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  9544. BEGIN
  9545. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  9546. RETURN
  9547. END
  9548. IF NOT EXISTS(SELECT a.ID
  9549. FROM ICSWareHouse a
  9550. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  9551. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  9552. BEGIN
  9553. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  9554. RETURN
  9555. END";
  9556. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  9557. DBHelper.ExecuteNonQuery(sql, cmd);
  9558. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  9559. //更新条码信息
  9560. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  9561. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  9562. }
  9563. }
  9564. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferApplicationIn.GetDescription(), Identification, cmd, language, BusinessCode);
  9565. DataTable table = GetData(Identification, 3, cmd);
  9566. cmd.Transaction.Commit();
  9567. return table;
  9568. }
  9569. catch (Exception ex)
  9570. {
  9571. if (cmd.Transaction != null)
  9572. cmd.Transaction.Rollback();
  9573. log.Error(ex.Message);
  9574. throw new Exception(ex.Message);
  9575. }
  9576. finally
  9577. {
  9578. if (conn.State == ConnectionState.Open)
  9579. {
  9580. conn.Close();
  9581. }
  9582. conn.Dispose();
  9583. }
  9584. }
  9585. }
  9586. #endregion
  9587. #region 调拨申请单
  9588. /// <summary>
  9589. /// 调拨申请单
  9590. /// </summary>
  9591. /// <param name="JsonData"></param>
  9592. /// <returns></returns>
  9593. public static DataTable TransferApplicationInCreate(List<TransferApplication> JsonData)
  9594. {
  9595. var language = LanguageHelper.GetName("WMSAPIInfo");
  9596. if (JsonData.Count <= 0)
  9597. {
  9598. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9599. }
  9600. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9601. {
  9602. conn.Open();
  9603. SqlTransaction sqlTran = conn.BeginTransaction();
  9604. SqlCommand cmd = new SqlCommand();
  9605. cmd.Transaction = sqlTran;
  9606. cmd.Connection = conn;
  9607. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9608. string BusinessCode = string.Empty;
  9609. try
  9610. {
  9611. DataTable printTable = new DataTable();
  9612. string sql = string.Empty;
  9613. string Identification = Guid.NewGuid().ToString();
  9614. foreach (var item in JsonData)
  9615. {
  9616. string MergeID = "";
  9617. foreach (var itemInfo in item.Detail)
  9618. {
  9619. //验证仓库库位信息
  9620. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  9621. BEGIN
  9622. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  9623. RETURN
  9624. END
  9625. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  9626. BEGIN
  9627. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  9628. RETURN
  9629. END
  9630. IF NOT EXISTS(SELECT a.ID
  9631. FROM ICSWareHouse a
  9632. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  9633. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  9634. BEGIN
  9635. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  9636. RETURN
  9637. END
  9638. IF EXISTS(SELECT ID
  9639. FROM ICSWareHouseLotInfo
  9640. WHERE WarehouseCode='{0}' AND WorkPoint='{1}' AND LotNo='{3}')
  9641. BEGIN
  9642. RAISERROR('" + language.GetNameByCode("WMSAPIInfo355") + @"',16,1);
  9643. RETURN
  9644. END";
  9645. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode, itemInfo.LotNo);
  9646. DBHelper.ExecuteNonQuery(sql, cmd);
  9647. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  9648. //更新源头单据信息
  9649. ICSWareHouseService.OneStepTransferApplicationIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  9650. //更新条码信息
  9651. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  9652. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  9653. }
  9654. }
  9655. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  9656. {
  9657. ICSWareHouseService.StepTransferApplicationERP(TransTypeEnum.StepTransferApplicationIn.GetDescription(), Identification, cmd, language, BusinessCode);
  9658. }
  9659. if (!printTable.Equals("{}"))
  9660. {
  9661. cmd.Transaction.Commit();
  9662. return printTable;
  9663. }
  9664. else
  9665. {
  9666. DataTable table = GetData(Identification, 3, cmd);
  9667. cmd.Transaction.Commit();
  9668. return table;
  9669. }
  9670. }
  9671. catch (Exception ex)
  9672. {
  9673. if (cmd.Transaction != null)
  9674. cmd.Transaction.Rollback();
  9675. log.Error(ex.Message);
  9676. throw new Exception(ex.Message);
  9677. }
  9678. finally
  9679. {
  9680. if (conn.State == ConnectionState.Open)
  9681. {
  9682. conn.Close();
  9683. }
  9684. conn.Dispose();
  9685. }
  9686. }
  9687. }
  9688. #endregion
  9689. //#region 工单关联
  9690. ///// <summary>
  9691. ///// 条码关联工单
  9692. ///// </summary>
  9693. ///// <param name="JsonData"></param>
  9694. ///// <returns></returns>
  9695. //public static DataTable ICSMOReceive(List<LOTStockUpCreateIModel> JsonData)
  9696. //{
  9697. // var language = LanguageHelper.GetName("WMSAPIInfo");
  9698. // if (JsonData.Count <= 0)
  9699. // {
  9700. // throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9701. // }
  9702. // using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9703. // {
  9704. // conn.Open();
  9705. // SqlTransaction sqlTran = conn.BeginTransaction();
  9706. // SqlCommand cmd = new SqlCommand();
  9707. // cmd.Transaction = sqlTran;
  9708. // cmd.Connection = conn;
  9709. // try
  9710. // {
  9711. // string sql = string.Empty;
  9712. // string TransType = string.Empty;
  9713. // string Identification = Guid.NewGuid().ToString();
  9714. // foreach (var item in JsonData)
  9715. // {
  9716. // string MergeID = "";
  9717. // foreach (var itemInfo in item.detail)
  9718. // {
  9719. // ICSWareHouseService.ICSMOReceive(itemInfo.LotNo, itemInfo.Quantity, itemInfo.TransCode, itemInfo.TransSequence, item.WorkPoint, Identification, item.User, itemInfo.SRMLotGroup, itemInfo.ProjectCode,
  9720. // itemInfo.BatchCode, itemInfo.Version, itemInfo.Brand, itemInfo.cFree1, itemInfo.cFree2, itemInfo.cFree3, itemInfo.cFree4, itemInfo.cFree5,
  9721. // itemInfo.cFree6, itemInfo.cFree7, itemInfo.cFree8, itemInfo.cFree9, itemInfo.cFree10, TransTypeEnum.ICSMOReceive.GetDescription<DBValue>(), cmd, language);
  9722. // }
  9723. // }
  9724. // DataTable table = GetData(Identification, 3, cmd);
  9725. // cmd.Transaction.Commit();
  9726. // return table;
  9727. // }
  9728. // catch (Exception ex)
  9729. // {
  9730. // if (cmd.Transaction != null)
  9731. // cmd.Transaction.Rollback();
  9732. // log.Error(ex.Message);
  9733. // throw new Exception(ex.Message);
  9734. // }
  9735. // finally
  9736. // {
  9737. // if (conn.State == ConnectionState.Open)
  9738. // {
  9739. // conn.Close();
  9740. // }
  9741. // conn.Dispose();
  9742. // }
  9743. // }
  9744. //}
  9745. ///// <summary>
  9746. ///// 条码与工单解绑
  9747. ///// </summary>
  9748. ///// <param name="JsonData"></param>
  9749. ///// <returns></returns>
  9750. //public static DataTable ICSMOReceiveUntie(ICSMOReceiveUntieModel JsonData)
  9751. //{
  9752. // var language = LanguageHelper.GetName("WMSAPIInfo");
  9753. // if (JsonData == null)
  9754. // {
  9755. // throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9756. // }
  9757. // using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9758. // {
  9759. // conn.Open();
  9760. // SqlTransaction sqlTran = conn.BeginTransaction();
  9761. // SqlCommand cmd = new SqlCommand();
  9762. // cmd.Transaction = sqlTran;
  9763. // cmd.Connection = conn;
  9764. // try
  9765. // {
  9766. // string sql = string.Empty;
  9767. // string TransType = string.Empty;
  9768. // string Identification = Guid.NewGuid().ToString();
  9769. // string MergeID = "";
  9770. // ICSWareHouseService.ICSMOReceiveUntie(JsonData.LotNo, JsonData.WorkPoint, TransTypeEnum.ICSMOReceive.GetDescription<DBValue>(), cmd, language);
  9771. // DataTable table = GetData(Identification, 3, cmd);
  9772. // cmd.Transaction.Commit();
  9773. // return table;
  9774. // }
  9775. // catch (Exception ex)
  9776. // {
  9777. // if (cmd.Transaction != null)
  9778. // cmd.Transaction.Rollback();
  9779. // log.Error(ex.Message);
  9780. // throw new Exception(ex.Message);
  9781. // }
  9782. // finally
  9783. // {
  9784. // if (conn.State == ConnectionState.Open)
  9785. // {
  9786. // conn.Close();
  9787. // }
  9788. // conn.Dispose();
  9789. // }
  9790. // }
  9791. //}
  9792. //#endregion
  9793. //#region 工单关联条码检验
  9794. ///// <summary>
  9795. ///// 工单关联条码检验
  9796. ///// </summary>
  9797. ///// <param name="JsonData"></param>
  9798. ///// <returns></returns>
  9799. //public static bool ICSMOReceiveLotCheck(BarCodeModel JsonData)
  9800. //{
  9801. // Boolean LotCheck = false;
  9802. // var language = LanguageHelper.GetName("WMSAPIInfo");
  9803. // using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9804. // {
  9805. // conn.Open();
  9806. // SqlTransaction sqlTran = conn.BeginTransaction();
  9807. // SqlCommand cmd = new SqlCommand();
  9808. // cmd.Transaction = sqlTran;
  9809. // cmd.Connection = conn;
  9810. // try
  9811. // {
  9812. // string sql = string.Empty;
  9813. // string TransType = string.Empty;
  9814. // string Identification = Guid.NewGuid().ToString();
  9815. // sql = @"select * from ICSInventoryLotDetail where LotNo='{0}' and WorkPoint='{1}'";
  9816. // sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  9817. // DataTable table = DBHelper.SQlReturnData(sql, cmd);
  9818. // cmd.Transaction.Commit();
  9819. // if (table.Rows.Count > 0)
  9820. // {
  9821. // LotCheck = true;
  9822. // }
  9823. // return LotCheck;
  9824. // }
  9825. // catch (Exception ex)
  9826. // {
  9827. // if (cmd.Transaction != null)
  9828. // cmd.Transaction.Rollback();
  9829. // log.Error(ex.Message);
  9830. // throw new Exception(ex.Message);
  9831. // }
  9832. // finally
  9833. // {
  9834. // if (conn.State == ConnectionState.Open)
  9835. // {
  9836. // conn.Close();
  9837. // }
  9838. // conn.Dispose();
  9839. // }
  9840. // }
  9841. //}
  9842. //#endregion
  9843. #region 容器
  9844. /// <summary>
  9845. /// 查询容器
  9846. /// </summary>
  9847. /// <param name="JsonData"></param>
  9848. /// <returns></returns>
  9849. public static DataTable ICSContainerGet(BarCodeModel JsonData)
  9850. {
  9851. var language = LanguageHelper.GetName("WMSAPIInfo");
  9852. if (JsonData == null)
  9853. {
  9854. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9855. }
  9856. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9857. {
  9858. conn.Open();
  9859. SqlTransaction sqlTran = conn.BeginTransaction();
  9860. SqlCommand cmd = new SqlCommand();
  9861. cmd.Transaction = sqlTran;
  9862. cmd.Connection = conn;
  9863. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9864. try
  9865. {
  9866. string sql = "";
  9867. string TransType = string.Empty;
  9868. string Identification = Guid.NewGuid().ToString();
  9869. // if (JsonData.ifCreateContainer)
  9870. // {
  9871. // sql = @"IF EXISTS(select ContainerCODE from ICSContainer where ContainerCODE='{0}' )
  9872. // BEGIN
  9873. // RAISERROR('容器:{0},已存在!',16,1)
  9874. // RETURN
  9875. // END
  9876. // else
  9877. // BEGIN
  9878. // INSERT INTO dbo.ICSContainer
  9879. // ( ID ,ContainerID ,ContainerCODE ,ContainerName,Memo,MTIME,MUSER ,MUSERName ,WorkPoint
  9880. // ,InventoryMixed,ProjectMixed,BatchMixed,Multiplex)
  9881. // Values(NEWID(),'','{0}','{0}','',GETDATE(),'{2}','{2}','{1}','0','0','0','0')
  9882. // END
  9883. //";
  9884. // }
  9885. sql += @"IF NOT EXISTS(select ContainerCODE from ICSContainer where ContainerCODE='{0}' )
  9886. BEGIN
  9887. RAISERROR('{0}',16,1)
  9888. RETURN
  9889. END
  9890. SELECT ID,ContainerID,ContainerCode,ContainerName,Memo,ContainerType,InventoryMixed,ProjectMixed,BatchMixed,Multiplex,MUSER,MUSERName,MTIME,WorkPoint,
  9891. EATTRIBUTE1 AS cFree1,EATTRIBUTE2 AS cFree2,EATTRIBUTE3 AS cFree3,EATTRIBUTE4 AS cFree4,EATTRIBUTE5 AS cFree5,EATTRIBUTE6 AS cFree6,EATTRIBUTE7 AS cFree7
  9892. ,EATTRIBUTE8 AS cFree8,EATTRIBUTE9 AS cFree9,EATTRIBUTE10 AS cFree10
  9893. FROM ICSContainer WHERE ContainerCode='{0}' AND WorkPoint='{1}'";
  9894. sql = string.Format(sql,JsonData.Code , JsonData.WorkPoint , JsonData.User);
  9895. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  9896. cmd.Transaction.Commit();
  9897. return table;
  9898. }
  9899. catch (Exception ex)
  9900. {
  9901. if (cmd.Transaction != null)
  9902. cmd.Transaction.Rollback();
  9903. log.Error(ex.Message);
  9904. throw new Exception(ex.Message);
  9905. }
  9906. finally
  9907. {
  9908. if (conn.State == ConnectionState.Open)
  9909. {
  9910. conn.Close();
  9911. }
  9912. conn.Dispose();
  9913. }
  9914. }
  9915. }
  9916. #region 盘点审核
  9917. /// <summary>
  9918. /// 多语言查询
  9919. /// </summary>
  9920. /// <param name="JsonData"></param>
  9921. /// <returns></returns>
  9922. public static DataTable CheckApove(List<ICSCheck> JsonData)
  9923. {
  9924. var language = LanguageHelper.GetName("WMSAPIInfo");
  9925. if (JsonData.Count <= 0)
  9926. {
  9927. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  9928. }
  9929. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  9930. {
  9931. conn.Open();
  9932. SqlTransaction sqlTran = conn.BeginTransaction();
  9933. SqlCommand cmd = new SqlCommand();
  9934. cmd.Transaction = sqlTran;
  9935. cmd.Connection = conn;
  9936. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  9937. try
  9938. {
  9939. string lots = string.Empty;
  9940. string sql = string.Empty;
  9941. DataTable dtLotno = new DataTable();
  9942. int result = 0;
  9943. string Identification = Guid.NewGuid().ToString();
  9944. foreach (var item in JsonData)
  9945. {
  9946. sql = @"SELECT b.LotNo FROM ICSCheck a
  9947. INNER JOIN ICSWareHouseLotInfo b ON SUBSTRING(b.LocationCode,1,LEN(a.SelectLevel))=a.SelectLevel
  9948. INNER JOIN ICSWarehouse c on b.WarehouseCode=c.WarehouseCode and b.WorkPoint=c.WorkPoint
  9949. where a.CheckCode='{0}' and a.WorkPoint='{1}'";
  9950. sql = string.Format(sql, item.CheckCode, item.WorkPoint);
  9951. dtLotno = DBHelper.SQlReturnData(sql, cmd);
  9952. //创建盘点单
  9953. foreach (var itemInfo in item.detail)
  9954. {
  9955. for (int i = dtLotno.Rows.Count - 1; i >= 0; i--)
  9956. {
  9957. string lotNo = dtLotno.Rows[i]["LotNo"].ToString();
  9958. // 判断当前 itemInfo.LotNo 是否包含在 dtLotno 中
  9959. if (lotNo.Equals(itemInfo.LotNo))
  9960. {
  9961. // 移除该行记录
  9962. dtLotno.Rows.RemoveAt(i);
  9963. }
  9964. }
  9965. ICSWareHouseLotInfoService.WareHouseLotInfoUpdate(Identification, item.CheckCode, "", itemInfo.LotNo, itemInfo.ActualQuantity, item.User, item.WorkPoint, TransTypeEnum.Check.GetDescription<DBValue>(), item.CheckKind, cmd, language);
  9966. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  9967. }
  9968. for (int i = 0; i < dtLotno.Rows.Count; i++)
  9969. {
  9970. ///更新库存
  9971. sql = @"UPDATE ICSWareHouseLotInfo SET Quantity=0 WHERE LotNo='{0}' AND WorkPoint='{1}'";
  9972. sql = string.Format(sql, dtLotno.Rows[i]["LotNo"].ToString(), item.WorkPoint);
  9973. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9974. {
  9975. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  9976. }
  9977. ///添加日志
  9978. sql = @"INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  9979. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  9980. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  9981. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  9982. MTIME,WorkPoint,EATTRIBUTE1)
  9983. SELECT NEWID(),'{3}','{4}','{5}',a.LotNo ,a.InvCode ,
  9984. a.WarehouseCode,a.LocationCode,'','',a.Quantity,
  9985. '{8}','0','{6}','{7}','0','',
  9986. '','','',f.F_Account ,f.F_RealName ,
  9987. SYSDATETIME() ,a.WorkPoint ,''
  9988. FROM ICSWareHouseLotInfo a
  9989. INNER JOIN Sys_SRM_User f ON f.F_Account='{2}' AND a.WorkPoint=f.F_Location
  9990. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}'
  9991. ";
  9992. sql = string.Format(sql, dtLotno.Rows[i]["LotNo"].ToString(), item.WorkPoint, item.User, Identification, item.CheckCode, "", 8, TransTypeEnum.LOTCheckAfter.GetDescription<DBValue>(), item.CheckKind);
  9993. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  9994. {
  9995. throw new Exception(language.GetNameByCode("WMSAPIInfo166"));
  9996. }
  9997. }
  9998. if (string.IsNullOrWhiteSpace(lots))
  9999. {
  10000. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  10001. }
  10002. //sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  10003. // FROM ICSCheck a
  10004. // 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
  10005. // WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  10006. //sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  10007. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  10008. //{
  10009. // throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  10010. //}
  10011. }
  10012. #region 查询返回数据
  10013. sql = @"SELECT x.ID,x.CheckID,y.WarehouseCode AS WHCode,x.LotNo,
  10014. y.InvCode,
  10015. inv.InvName,
  10016. inv.InvStd,
  10017. x.Quantity,x.PrimaryQuantity,x.PrimaryAmount,x.ReplayQuantity,x.ReplayAmount,x.CheckQuantity,x.CheckAmount,
  10018. inv.InvUnit,
  10019. x.MUSER AS [User],
  10020. x.MTIME AS [MTime]
  10021. FROM ICSCheckDetail x
  10022. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  10023. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  10024. WHERE x.LotNo+x.WorkPoint IN ({0})";
  10025. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  10026. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  10027. #endregion
  10028. cmd.Transaction.Commit();
  10029. return data;
  10030. }
  10031. catch (Exception ex)
  10032. {
  10033. if (cmd.Transaction != null)
  10034. cmd.Transaction.Rollback();
  10035. log.Error(ex.Message);
  10036. throw new Exception(ex.Message);
  10037. }
  10038. finally
  10039. {
  10040. if (conn.State == ConnectionState.Open)
  10041. {
  10042. conn.Close();
  10043. }
  10044. conn.Dispose();
  10045. }
  10046. }
  10047. }
  10048. #endregion
  10049. /// <summary>
  10050. /// 容器关联查询容器
  10051. /// </summary>
  10052. /// <param name="JsonData"></param>
  10053. /// <returns></returns>
  10054. public static DataTable ICSContainerConGet(BarCodeModel JsonData)
  10055. {
  10056. var language = LanguageHelper.GetName("WMSAPIInfo");
  10057. if (JsonData == null)
  10058. {
  10059. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10060. }
  10061. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10062. {
  10063. conn.Open();
  10064. SqlTransaction sqlTran = conn.BeginTransaction();
  10065. SqlCommand cmd = new SqlCommand();
  10066. cmd.Transaction = sqlTran;
  10067. cmd.Connection = conn;
  10068. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10069. try
  10070. {
  10071. string sql = string.Empty;
  10072. string TransType = string.Empty;
  10073. string Identification = Guid.NewGuid().ToString();
  10074. 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.
  10075. 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
  10076. ,con.EATTRIBUTE8 AS cFree8,con.EATTRIBUTE9 AS cFree9,con.EATTRIBUTE10 AS cFree10
  10077. FROM ICSContainer a
  10078. INNER JOIN ICSContainer con ON con.ContainerID=a.ID
  10079. WHERE a.ContainerCode='{0}' AND a.WorkPoint='{1}'";
  10080. sql = string.Format(sql,JsonData.Code , JsonData.WorkPoint);
  10081. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  10082. cmd.Transaction.Commit();
  10083. return table;
  10084. }
  10085. catch (Exception ex)
  10086. {
  10087. if (cmd.Transaction != null)
  10088. cmd.Transaction.Rollback();
  10089. log.Error(ex.Message);
  10090. throw new Exception(ex.Message);
  10091. }
  10092. finally
  10093. {
  10094. if (conn.State == ConnectionState.Open)
  10095. {
  10096. conn.Close();
  10097. }
  10098. conn.Dispose();
  10099. }
  10100. }
  10101. }
  10102. /// <summary>
  10103. /// 条码关联容器——查询容器关联的条码
  10104. /// </summary>
  10105. /// <param name="JsonData"></param>
  10106. /// <returns></returns>
  10107. public static DataTable ICSContainerLotGetCon(BarCodeModel JsonData)
  10108. {
  10109. var language = LanguageHelper.GetName("WMSAPIInfo");
  10110. if (JsonData == null)
  10111. {
  10112. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10113. }
  10114. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10115. {
  10116. conn.Open();
  10117. SqlTransaction sqlTran = conn.BeginTransaction();
  10118. SqlCommand cmd = new SqlCommand();
  10119. cmd.Transaction = sqlTran;
  10120. cmd.Connection = conn;
  10121. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10122. try
  10123. {
  10124. string sql = string.Empty;
  10125. string TransType = string.Empty;
  10126. string Identification = Guid.NewGuid().ToString();
  10127. sql = @"SELECT con.ContainerCode,con.ContainerName,con.ContainerType,inv.InvCode,inv.InvName,lot.LotNo,inv.InvStd,lot.Quantity,inv.InvUnit,
  10128. 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
  10129. FROM ICSContainer con
  10130. LEFT JOIN ICSContainerLot conlot ON conlot.ContainerID=con.ID
  10131. LEFT JOIN ICSInventoryLot lot ON lot.LotNo=conLot.LotNo
  10132. LEFT JOIN ICSInventory inv ON inv.InvCode=lot.InvCode
  10133. LEFT JOIN ICSExtension ext ON ext.ID=lot.ExtensionID
  10134. WHERE con.ContainerCode='{0}' AND con.WorkPoint='{1}'";
  10135. sql = string.Format(sql,JsonData.Code , JsonData.WorkPoint);
  10136. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  10137. cmd.Transaction.Commit();
  10138. return table;
  10139. }
  10140. catch (Exception ex)
  10141. {
  10142. if (cmd.Transaction != null)
  10143. cmd.Transaction.Rollback();
  10144. log.Error(ex.Message);
  10145. throw new Exception(ex.Message);
  10146. }
  10147. finally
  10148. {
  10149. if (conn.State == ConnectionState.Open)
  10150. {
  10151. conn.Close();
  10152. }
  10153. conn.Dispose();
  10154. }
  10155. }
  10156. }
  10157. /// <summary>
  10158. /// 条码关联容器--条码查询
  10159. /// </summary>
  10160. /// <param name="JsonData"></param>
  10161. /// <returns></returns>
  10162. public static DataTable ICSContainerLotCheck(BarCodeModel JsonData)
  10163. {
  10164. Boolean LotCheck = false;
  10165. var language = LanguageHelper.GetName("WMSAPIInfo");
  10166. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10167. {
  10168. conn.Open();
  10169. SqlTransaction sqlTran = conn.BeginTransaction();
  10170. SqlCommand cmd = new SqlCommand();
  10171. cmd.Transaction = sqlTran;
  10172. cmd.Connection = conn;
  10173. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10174. try
  10175. {
  10176. string sql = string.Empty;
  10177. string TransType = string.Empty;
  10178. string Identification = Guid.NewGuid().ToString();
  10179. sql = @"select LotNo,InvCode,Quantity,ExtensionID,Type,
  10180. EATTRIBUTE1 AS cFree1,EATTRIBUTE2 AS cFree2,EATTRIBUTE3 AS cFree3,EATTRIBUTE4 AS cFree4,EATTRIBUTE5 AS cFree5,EATTRIBUTE6 AS cFree6,EATTRIBUTE7 AS cFree7
  10181. ,EATTRIBUTE8 AS cFree8,EATTRIBUTE9 AS cFree9,EATTRIBUTE10 AS cFree10
  10182. from ICSInventoryLot where LotNo='{0}' and WorkPoint='{1}'";
  10183. sql = string.Format(sql, JsonData.Code, JsonData.WorkPoint);
  10184. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  10185. cmd.Transaction.Commit();
  10186. return table;
  10187. }
  10188. catch (Exception ex)
  10189. {
  10190. if (cmd.Transaction != null)
  10191. cmd.Transaction.Rollback();
  10192. log.Error(ex.Message);
  10193. throw new Exception(ex.Message);
  10194. }
  10195. finally
  10196. {
  10197. if (conn.State == ConnectionState.Open)
  10198. {
  10199. conn.Close();
  10200. }
  10201. conn.Dispose();
  10202. }
  10203. }
  10204. }
  10205. /// <summary>
  10206. /// 容器绑定条码
  10207. /// </summary>
  10208. /// <param name="JsonData"></param>
  10209. /// <returns></returns>
  10210. public static string ICSContainerLot(List<ICSContainerLotModel> JsonData)
  10211. {
  10212. var language = LanguageHelper.GetName("WMSAPIInfo");
  10213. Boolean flag;
  10214. if (JsonData.Count <= 0)
  10215. {
  10216. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10217. }
  10218. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10219. {
  10220. conn.Open();
  10221. SqlTransaction sqlTran = conn.BeginTransaction();
  10222. SqlCommand cmd = new SqlCommand();
  10223. cmd.Transaction = sqlTran;
  10224. cmd.Connection = conn;
  10225. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10226. try
  10227. {
  10228. string sql = string.Empty;
  10229. string TransType = string.Empty;
  10230. string Identification = Guid.NewGuid().ToString();
  10231. foreach (var item in JsonData)
  10232. {
  10233. if (item.ifCreateContainer)
  10234. {
  10235. string ContainerID = Guid.NewGuid().ToString();
  10236. string ContainerCode = GetSerialCode(item.WorkPoint, "ICSContainer", "ContainerCode", "Container", 5, cmd);
  10237. sql = @"IF EXISTS(SELECT 1 FROM ICSContainer WHERE ContainerCODE='{0}' AND WorkPoint='{1}')
  10238. BEGIN
  10239. RAISERROR(' " + ContainerCode + @" ',16,1);
  10240. RETURN;
  10241. END
  10242. INSERT INTO dbo.ICSContainer
  10243. ( ID ,ContainerID ,ContainerCODE ,ContainerName,Memo,MTIME,MUSER ,MUSERName ,WorkPoint
  10244. ,InventoryMixed,ProjectMixed,BatchMixed,Multiplex)
  10245. Values('{3}','','{0}','{0}','',GETDATE(),'{2}','{2}','{1}','0','0','0','0')";
  10246. sql = string.Format(sql, ContainerCode, item.WorkPoint, item.User, ContainerID);
  10247. if (!DBHelper.ExecuteNonQuery(sql,cmd))
  10248. {
  10249. throw new Exception("生成箱号失败!");
  10250. }
  10251. foreach (var itemInfo in item.detail)
  10252. {
  10253. flag = ICSWareHouseService.ICSContainerLot(itemInfo.LotNo, ContainerCode, item.WorkPoint, Identification, item.User, itemInfo.ProjectCode,
  10254. itemInfo.BatchCode, itemInfo.Version, itemInfo.Brand, itemInfo.cFree1, itemInfo.cFree2, itemInfo.cFree3, itemInfo.cFree4, itemInfo.cFree5,
  10255. itemInfo.cFree6, itemInfo.cFree7, itemInfo.cFree8, itemInfo.cFree9, itemInfo.cFree10, TransTypeEnum.ICSMOReceive.GetDescription<DBValue>(), cmd, language);
  10256. if (!flag)
  10257. {
  10258. log.Error("容器绑定条码失败");
  10259. throw new Exception("容器 " + ContainerCode + " 绑定条码 " + itemInfo.LotNo + " 失败");
  10260. }
  10261. }
  10262. }
  10263. else
  10264. {
  10265. foreach (var itemInfo in item.detail)
  10266. {
  10267. flag = ICSWareHouseService.ICSContainerLot(itemInfo.LotNo, itemInfo.ContainerCode, item.WorkPoint, Identification, item.User, itemInfo.ProjectCode,
  10268. itemInfo.BatchCode, itemInfo.Version, itemInfo.Brand, itemInfo.cFree1, itemInfo.cFree2, itemInfo.cFree3, itemInfo.cFree4, itemInfo.cFree5,
  10269. itemInfo.cFree6, itemInfo.cFree7, itemInfo.cFree8, itemInfo.cFree9, itemInfo.cFree10, TransTypeEnum.ICSMOReceive.GetDescription<DBValue>(), cmd, language);
  10270. if (!flag)
  10271. {
  10272. log.Error("容器绑定条码失败");
  10273. throw new Exception("容器 "+ itemInfo.ContainerCode + " 绑定条码 "+ itemInfo.LotNo + " 失败");
  10274. }
  10275. }
  10276. }
  10277. }
  10278. cmd.Transaction.Commit();
  10279. return LanguageHelper.GetNameSingle("WMSAPI001");// "接口调用成功!";
  10280. }
  10281. catch (Exception ex)
  10282. {
  10283. if (cmd.Transaction != null)
  10284. cmd.Transaction.Rollback();
  10285. log.Error(ex.Message);
  10286. throw new Exception(ex.Message);
  10287. }
  10288. finally
  10289. {
  10290. if (conn.State == ConnectionState.Open)
  10291. {
  10292. conn.Close();
  10293. }
  10294. conn.Dispose();
  10295. }
  10296. }
  10297. }
  10298. public static string GetSerialCode(string workPointCode, string tbName, string colName, string Pre, int numLen, SqlCommand cmd)
  10299. {
  10300. string sql = "EXEC Addins_GetSerialCode '{0}','{1}','{2}','{3}',{4}";
  10301. sql = string.Format(sql, new object[] { workPointCode, tbName, colName, Pre, numLen });
  10302. return DBHelper.ExecuteScalar(sql,cmd).ToString();
  10303. }
  10304. /// <summary>
  10305. /// 容器与条码解绑
  10306. /// </summary>
  10307. /// <param name="JsonData"></param>
  10308. /// <returns></returns>
  10309. public static bool ICSContainerLotUntie(ICSMOReceiveUntieModel JsonData)
  10310. {
  10311. Boolean flag = false;
  10312. var language = LanguageHelper.GetName("WMSAPIInfo");
  10313. if (JsonData == null)
  10314. {
  10315. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10316. }
  10317. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10318. {
  10319. conn.Open();
  10320. SqlTransaction sqlTran = conn.BeginTransaction();
  10321. SqlCommand cmd = new SqlCommand();
  10322. cmd.Transaction = sqlTran;
  10323. cmd.Connection = conn;
  10324. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10325. try
  10326. {
  10327. string sql = string.Empty;
  10328. string TransType = string.Empty;
  10329. string Identification = Guid.NewGuid().ToString();
  10330. string MergeID = "";
  10331. flag = ICSWareHouseService.ICSContainerLotUntie(JsonData.ContainerCode, JsonData.LotNo, JsonData.WorkPoint, JsonData.User, JsonData.Type, cmd, language);
  10332. cmd.Transaction.Commit();
  10333. return flag;
  10334. }
  10335. catch (Exception ex)
  10336. {
  10337. if (cmd.Transaction != null)
  10338. cmd.Transaction.Rollback();
  10339. log.Error(ex.Message);
  10340. throw new Exception(ex.Message);
  10341. }
  10342. finally
  10343. {
  10344. if (conn.State == ConnectionState.Open)
  10345. {
  10346. conn.Close();
  10347. }
  10348. conn.Dispose();
  10349. }
  10350. }
  10351. }
  10352. /// <summary>
  10353. /// 容器绑定父容器
  10354. /// </summary>
  10355. /// <param name="JsonData"></param>
  10356. /// <returns></returns>
  10357. public static string ICSContainerCon(List<ICSContainerConModel> JsonData)
  10358. {
  10359. var language = LanguageHelper.GetName("WMSAPIInfo");
  10360. Boolean flag;
  10361. if (JsonData.Count <= 0)
  10362. {
  10363. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10364. }
  10365. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10366. {
  10367. conn.Open();
  10368. SqlTransaction sqlTran = conn.BeginTransaction();
  10369. SqlCommand cmd = new SqlCommand();
  10370. cmd.Transaction = sqlTran;
  10371. cmd.Connection = conn;
  10372. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10373. try
  10374. {
  10375. string sql = string.Empty;
  10376. string TransType = string.Empty;
  10377. string Identification = Guid.NewGuid().ToString();
  10378. foreach (var item in JsonData)
  10379. {
  10380. string MergeID = "";
  10381. foreach (var itemInfo in item.detail)
  10382. {
  10383. flag = ICSWareHouseService.ICSContainerCon(item.ContainerCode, itemInfo.ContainerCode, item.WorkPoint, item.User, item.MTime, item.Type, cmd, language);
  10384. if (!flag)
  10385. {
  10386. log.Error("容器绑定条码失败");
  10387. throw new Exception("容器 " + itemInfo.ContainerCode + " 绑定父容器 " + item.ContainerCode + " 失败");
  10388. }
  10389. }
  10390. }
  10391. cmd.Transaction.Commit();
  10392. return LanguageHelper.GetNameSingle("WMSAPI001");// "接口调用成功!";
  10393. }
  10394. catch (Exception ex)
  10395. {
  10396. if (cmd.Transaction != null)
  10397. cmd.Transaction.Rollback();
  10398. log.Error(ex.Message);
  10399. throw new Exception(ex.Message);
  10400. }
  10401. finally
  10402. {
  10403. if (conn.State == ConnectionState.Open)
  10404. {
  10405. conn.Close();
  10406. }
  10407. conn.Dispose();
  10408. }
  10409. }
  10410. }
  10411. /// <summary>
  10412. /// 容器解绑父容器
  10413. /// </summary>
  10414. /// <param name="JsonData"></param>
  10415. /// <returns></returns>
  10416. public static bool ICSContainerConUntie(ICSMOReceiveUntieModel JsonData)
  10417. {
  10418. Boolean flag = false;
  10419. var language = LanguageHelper.GetName("WMSAPIInfo");
  10420. if (JsonData == null)
  10421. {
  10422. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10423. }
  10424. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10425. {
  10426. conn.Open();
  10427. SqlTransaction sqlTran = conn.BeginTransaction();
  10428. SqlCommand cmd = new SqlCommand();
  10429. cmd.Transaction = sqlTran;
  10430. cmd.Connection = conn;
  10431. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10432. try
  10433. {
  10434. string sql = string.Empty;
  10435. string TransType = string.Empty;
  10436. string Identification = Guid.NewGuid().ToString();
  10437. string MergeID = "";
  10438. flag = ICSWareHouseService.ICSContainerConUntie(JsonData.ContainerCode, JsonData.WorkPoint, JsonData.User, JsonData.Type, cmd, language);
  10439. cmd.Transaction.Commit();
  10440. return flag;
  10441. }
  10442. catch (Exception ex)
  10443. {
  10444. if (cmd.Transaction != null)
  10445. cmd.Transaction.Rollback();
  10446. log.Error(ex.Message);
  10447. throw new Exception(ex.Message);
  10448. }
  10449. finally
  10450. {
  10451. if (conn.State == ConnectionState.Open)
  10452. {
  10453. conn.Close();
  10454. }
  10455. conn.Dispose();
  10456. }
  10457. }
  10458. }
  10459. #endregion
  10460. #region 车次
  10461. public static DataTable ICSCartBarCodeGet(BarCodeModel JsonData)
  10462. {
  10463. Boolean LotCheck = false;
  10464. var language = LanguageHelper.GetName("WMSAPIInfo");
  10465. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10466. {
  10467. conn.Open();
  10468. SqlTransaction sqlTran = conn.BeginTransaction();
  10469. SqlCommand cmd = new SqlCommand();
  10470. cmd.Transaction = sqlTran;
  10471. cmd.Connection = conn;
  10472. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10473. try
  10474. {
  10475. string sql = string.Empty;
  10476. string TransType = string.Empty;
  10477. string Identification = Guid.NewGuid().ToString();
  10478. sql = @"IF EXISTS (SELECT *
  10479. FROM ICSCartLotNoCheckList list
  10480. WHERE list.CartNo='{0}' AND list.LotNo='{1}'
  10481. )
  10482. BEGIN
  10483. RAISERROR('"+ language.GetNameByCode("WMSAPIInfo476") + @"',16,1)
  10484. RETURN
  10485. END
  10486. ELSE IF NOT EXISTS(
  10487. SELECT 1 FROM ICSInventoryLot lot WHERE lot.LotNo='{1}'
  10488. )
  10489. BEGIN
  10490. RAISERROR('" + language.GetNameByCode("WMSAPIInfo477") + @"',16,1)
  10491. END
  10492. ELSE IF NOT EXISTS(
  10493. SELECT 1 FROM ICSWareHouseLotInfo info WHERE info.LotNo='{1}' AND info.Quantity>0
  10494. )
  10495. BEGIN
  10496. RAISERROR('" + language.GetNameByCode("WMSAPIInfo479") +@"',16,1)
  10497. END
  10498. ELSE
  10499. BEGIN
  10500. 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
  10501. FROM ICSInventoryLot lot
  10502. LEFT JOIN ICSExtension ext ON ext.ID=lot.ExtensionID
  10503. LEFT JOIN ICSWareHouseLotInfo info ON info.LotNo=lot.LotNo
  10504. WHERE lot.LotNo='{1}'
  10505. END";
  10506. sql = string.Format(sql, JsonData.TransCode, JsonData.Code);
  10507. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  10508. cmd.Transaction.Commit();
  10509. return table;
  10510. }
  10511. catch (Exception ex)
  10512. {
  10513. if (cmd.Transaction != null)
  10514. cmd.Transaction.Rollback();
  10515. log.Error(ex.Message);
  10516. throw new Exception(ex.Message);
  10517. }
  10518. finally
  10519. {
  10520. if (conn.State == ConnectionState.Open)
  10521. {
  10522. conn.Close();
  10523. }
  10524. conn.Dispose();
  10525. }
  10526. }
  10527. }
  10528. public static string ICSCartScheduleCreate(List<CartScheduleModel> JsonData)
  10529. {
  10530. var language = LanguageHelper.GetName("WMSAPIInfo");
  10531. Boolean flag;
  10532. if (JsonData.Count <= 0)
  10533. {
  10534. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10535. }
  10536. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10537. {
  10538. conn.Open();
  10539. SqlTransaction sqlTran = conn.BeginTransaction();
  10540. SqlCommand cmd = new SqlCommand();
  10541. cmd.Transaction = sqlTran;
  10542. cmd.Connection = conn;
  10543. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10544. try
  10545. {
  10546. string sql = string.Empty;
  10547. string TransType = string.Empty;
  10548. string Identification = Guid.NewGuid().ToString();
  10549. foreach (var item in JsonData)
  10550. {
  10551. string MergeID = "";
  10552. foreach (var itemInfo in item.detail)
  10553. {
  10554. flag = ICSWareHouseService.ICSCartScheduleCreate(itemInfo.LotNo,itemInfo.Quantity, item.CartNo, item.User, item.WorkPoint, cmd, language);
  10555. if (!flag)
  10556. {
  10557. log.Error("生成车次条码清单失败");
  10558. throw new Exception("车次 " + item.CartNo + " 与条码 " + itemInfo.LotNo + " 生成清单失败");
  10559. }
  10560. }
  10561. }
  10562. cmd.Transaction.Commit();
  10563. return LanguageHelper.GetNameSingle("WMSAPI001");// "接口调用成功!";
  10564. }
  10565. catch (Exception ex)
  10566. {
  10567. if (cmd.Transaction != null)
  10568. cmd.Transaction.Rollback();
  10569. log.Error(ex.Message);
  10570. throw new Exception(ex.Message);
  10571. }
  10572. finally
  10573. {
  10574. if (conn.State == ConnectionState.Open)
  10575. {
  10576. conn.Close();
  10577. }
  10578. conn.Dispose();
  10579. }
  10580. }
  10581. }
  10582. #endregion
  10583. #region 移库
  10584. /// <summary>
  10585. /// 移库
  10586. /// </summary>
  10587. /// <param name="JsonData"></param>
  10588. /// <returns></returns>
  10589. public static DataTable LibraryUpdate(List<ICSLibraryModel> JsonData)
  10590. {
  10591. var language = LanguageHelper.GetName("WMSAPIInfo");
  10592. if (JsonData.Count <= 0)
  10593. {
  10594. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10595. }
  10596. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10597. {
  10598. conn.Open();
  10599. SqlTransaction sqlTran = conn.BeginTransaction();
  10600. SqlCommand cmd = new SqlCommand();
  10601. cmd.Transaction = sqlTran;
  10602. cmd.Connection = conn;
  10603. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10604. try
  10605. {
  10606. string sql = string.Empty;
  10607. string Identification = Guid.NewGuid().ToString();
  10608. foreach (var item in JsonData)
  10609. {
  10610. if (string.IsNullOrEmpty(item.LotNo))
  10611. {
  10612. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  10613. }
  10614. //验证仓库库位信息
  10615. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  10616. BEGIN
  10617. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  10618. RETURN
  10619. END
  10620. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  10621. BEGIN
  10622. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  10623. RETURN
  10624. END
  10625. IF NOT EXISTS(SELECT a.ID
  10626. FROM ICSWareHouse a
  10627. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  10628. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  10629. BEGIN
  10630. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  10631. RETURN
  10632. END";
  10633. sql = string.Format(sql, item.WarehouseCode, item.WorkPoint, item.LocationCode);
  10634. DBHelper.ExecuteNonQuery(sql, cmd);
  10635. //更新条码信息
  10636. ICSWareHouseLotInfoService.WareHouseLotInfoLibrary(Identification, item.TransCode, item.TransSequence, item.WarehouseCode, item.LocationCode, item.LotNo,
  10637. item.User, item.WorkPoint, "7", "29", cmd, language);
  10638. }
  10639. DataTable table = GetData(Identification, 3, cmd);
  10640. cmd.Transaction.Commit();
  10641. return table;
  10642. }
  10643. catch (Exception ex)
  10644. {
  10645. if (cmd.Transaction != null)
  10646. cmd.Transaction.Rollback();
  10647. log.Error(ex.Message);
  10648. throw new Exception(ex.Message);
  10649. }
  10650. finally
  10651. {
  10652. if (conn.State == ConnectionState.Open)
  10653. {
  10654. conn.Close();
  10655. }
  10656. conn.Dispose();
  10657. }
  10658. }
  10659. }
  10660. #endregion
  10661. #region 合并
  10662. /// <summary>
  10663. /// 合并
  10664. /// </summary>
  10665. /// <param name="JsonData"></param>
  10666. /// <returns></returns>
  10667. public static DataTable LOTMergeCreate(List<LOTCreateIModel> JsonData)
  10668. {
  10669. var language = LanguageHelper.GetName("WMSAPIInfo");
  10670. DataTable printTable = new DataTable();
  10671. if (JsonData.Count <= 0)
  10672. {
  10673. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10674. }
  10675. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10676. {
  10677. conn.Open();
  10678. SqlTransaction sqlTran = conn.BeginTransaction();
  10679. SqlCommand cmd = new SqlCommand();
  10680. cmd.Transaction = sqlTran;
  10681. cmd.Connection = conn;
  10682. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10683. try
  10684. {
  10685. string Identification = Guid.NewGuid().ToString();
  10686. foreach (var item in JsonData)
  10687. {
  10688. if (string.IsNullOrEmpty(item.LotNo))
  10689. {
  10690. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  10691. }
  10692. else if (item.detail.Count <= 0)
  10693. {
  10694. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  10695. }
  10696. //合并前日志
  10697. ICSWareHouseLotInfoService.WareHouseLotInfoLogMerge(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  10698. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(),"", cmd, language);
  10699. foreach (var info in item.detail)
  10700. {
  10701. //合并前日志
  10702. ICSWareHouseLotInfoService.WareHouseLotInfoLogMerge(Identification, info.CurrentLotNo, item.User, item.WorkPoint, "5",
  10703. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(),"", cmd, language);
  10704. //更新条码信息
  10705. ICSWareHouseLotInfoService.WareHouseLotInfoMerge(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "5",
  10706. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  10707. }
  10708. //合并后日志
  10709. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoLogMerge(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  10710. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(),"", cmd, language);
  10711. }
  10712. if (!printTable.Equals("{}"))
  10713. {
  10714. cmd.Transaction.Commit();
  10715. return printTable;
  10716. }
  10717. else
  10718. {
  10719. DataTable table = GetData(Identification, 1, cmd);
  10720. cmd.Transaction.Commit();
  10721. return table;
  10722. }
  10723. }
  10724. catch (Exception ex)
  10725. {
  10726. if (cmd.Transaction != null)
  10727. cmd.Transaction.Rollback();
  10728. log.Error(ex.Message);
  10729. throw new Exception(ex.Message);
  10730. }
  10731. finally
  10732. {
  10733. if (conn.State == ConnectionState.Open)
  10734. {
  10735. conn.Close();
  10736. }
  10737. conn.Dispose();
  10738. }
  10739. }
  10740. }
  10741. #endregion
  10742. #region 拆分
  10743. /// <summary>
  10744. /// 拆分
  10745. /// </summary>
  10746. /// <param name="JsonData"></param>
  10747. /// <returns></returns>
  10748. public static DataTable LOTSplitCreate(List<LOTCreateIModel> JsonData)
  10749. {
  10750. var language = LanguageHelper.GetName("WMSAPIInfo");
  10751. string newlotno = "";
  10752. DataTable printTable = new DataTable();
  10753. if (JsonData.Count <= 0)
  10754. {
  10755. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10756. }
  10757. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10758. {
  10759. conn.Open();
  10760. SqlTransaction sqlTran = conn.BeginTransaction();
  10761. SqlCommand cmd = new SqlCommand();
  10762. cmd.Transaction = sqlTran;
  10763. cmd.Connection = conn;
  10764. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10765. try
  10766. {
  10767. string Identification = Guid.NewGuid().ToString();
  10768. foreach (var item in JsonData)
  10769. {
  10770. if (string.IsNullOrEmpty(item.LotNo))
  10771. {
  10772. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  10773. }
  10774. else if (item.detail.Count <= 0)
  10775. {
  10776. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  10777. }
  10778. //拆分前日志
  10779. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  10780. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(),"", cmd, language);
  10781. foreach (var info in item.detail)
  10782. {
  10783. newlotno = info.CurrentLotNo;
  10784. //更新条码信息
  10785. ICSWareHouseLotInfoService.WareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  10786. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  10787. }
  10788. //拆分后日志
  10789. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  10790. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), newlotno, cmd, language);
  10791. }
  10792. //DataTable table = GetData(Identification, 1, cmd);
  10793. //cmd.Transaction.Commit();
  10794. //return table;
  10795. if (!printTable.Equals("{}"))
  10796. {
  10797. cmd.Transaction.Commit();
  10798. return printTable;
  10799. }
  10800. else
  10801. {
  10802. DataTable table = GetData(Identification, 1, cmd);
  10803. cmd.Transaction.Commit();
  10804. return table;
  10805. }
  10806. }
  10807. catch (Exception ex)
  10808. {
  10809. if (cmd.Transaction != null)
  10810. cmd.Transaction.Rollback();
  10811. log.Error(ex.Message);
  10812. throw new Exception(ex.Message);
  10813. }
  10814. finally
  10815. {
  10816. if (conn.State == ConnectionState.Open)
  10817. {
  10818. conn.Close();
  10819. }
  10820. conn.Dispose();
  10821. }
  10822. }
  10823. }
  10824. /// <summary>
  10825. /// 拆分(奥美)
  10826. /// </summary>
  10827. /// <param name="JsonData"></param>
  10828. /// <returns></returns>
  10829. public static DataTable AMLOTSplitCreate(List<LOTCreateIModel> JsonData)
  10830. {
  10831. var language = LanguageHelper.GetName("WMSAPIInfo");
  10832. string newlotno = "";
  10833. DataTable printTable = new DataTable();
  10834. if (JsonData.Count <= 0)
  10835. {
  10836. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  10837. }
  10838. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  10839. {
  10840. conn.Open();
  10841. SqlTransaction sqlTran = conn.BeginTransaction();
  10842. SqlCommand cmd = new SqlCommand();
  10843. cmd.Transaction = sqlTran;
  10844. cmd.Connection = conn;
  10845. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  10846. try
  10847. {
  10848. string Identification = Guid.NewGuid().ToString();
  10849. foreach (var item in JsonData)
  10850. {
  10851. if (string.IsNullOrEmpty(item.LotNo))
  10852. {
  10853. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  10854. }
  10855. else if (item.detail.Count <= 0)
  10856. {
  10857. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  10858. }
  10859. //拆分前日志
  10860. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  10861. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(), "", cmd, language);
  10862. foreach (var info in item.detail)
  10863. {
  10864. newlotno = info.CurrentLotNo;
  10865. //更新条码信息
  10866. ICSWareHouseLotInfoService.AMWareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  10867. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  10868. }
  10869. //拆分后日志
  10870. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  10871. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), newlotno, cmd, language);
  10872. }
  10873. //DataTable table = GetData(Identification, 1, cmd);
  10874. //cmd.Transaction.Commit();
  10875. //return table;
  10876. if (!printTable.Equals("{}"))
  10877. {
  10878. cmd.Transaction.Commit();
  10879. return printTable;
  10880. }
  10881. else
  10882. {
  10883. DataTable table = GetData(Identification, 1, cmd);
  10884. cmd.Transaction.Commit();
  10885. return table;
  10886. }
  10887. }
  10888. catch (Exception ex)
  10889. {
  10890. if (cmd.Transaction != null)
  10891. cmd.Transaction.Rollback();
  10892. log.Error(ex.Message);
  10893. throw new Exception(ex.Message);
  10894. }
  10895. finally
  10896. {
  10897. if (conn.State == ConnectionState.Open)
  10898. {
  10899. conn.Close();
  10900. }
  10901. conn.Dispose();
  10902. }
  10903. }
  10904. }
  10905. #endregion
  10906. /// <summary>
  10907. /// 获取出入库记录信息
  10908. /// </summary>
  10909. /// <param name="Identification"></param>
  10910. /// <param name="type">1:入库,2:出库,3:调拨</param>
  10911. /// <param name="cmd"></param>
  10912. /// <returns></returns>
  10913. private static DataTable GetData(string Identification, int type, SqlCommand cmd)
  10914. {
  10915. #region SLQ
  10916. string sql = @"SELECT log.ID,
  10917. log.TransCode,
  10918. log.TransSequence,
  10919. log.LotNo,
  10920. log.InvCode,
  10921. inv.InvName,
  10922. inv.InvStd,
  10923. log.Quantity,
  10924. inv.InvUnit,
  10925. log.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  10926. inv.AmountUnit,
  10927. {1}
  10928. ext.ProjectCode,
  10929. 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,
  10930. ext.Version,
  10931. ext.Brand,
  10932. ext.cFree1,
  10933. ext.cFree2,
  10934. ext.cFree3,
  10935. ext.cFree4,
  10936. ext.cFree5,
  10937. ext.cFree6,
  10938. ext.cFree7,
  10939. ext.cFree8,
  10940. ext.cFree9,
  10941. ext.cFree10,
  10942. type.Name AS TransType,
  10943. log.MUSER AS [User],
  10944. log.MTIME AS [MTime]
  10945. FROM ICSWareHouseLotInfoLog log
  10946. LEFT JOIN ICSType type ON type.TableCode='ICSWareHouseLotInfoLog' AND type.ColumnCode='BusinessCode' AND log.BusinessCode=type.Code AND log.WorkPoint=type.WorkPoint
  10947. INNER JOIN ICSInventoryLot lot ON log.LotNo=lot.LotNo AND log.WorkPoint=lot.WorkPoint
  10948. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  10949. INNER JOIN ICSInventory inv ON log.InvCode=inv.InvCode AND log.WorkPoint=inv.WorkPoint
  10950. {2}
  10951. LEFT JOIN ICSInventoryBatchEnable invBat ON log.InvCode=invBat.InvCode AND log.FromWarehouseCode=invBat.WHCode AND log.WorkPoint=invBat.WorkPoint
  10952. WHERE log.Identification='{0}'";
  10953. #endregion
  10954. string columns = @"log.ToWarehouseCode AS WHCode,
  10955. log.ToLocationCode AS LocationCode,
  10956. wh.WarehouseName AS WHName,
  10957. loc.LocationName AS LocationName,";
  10958. string tables = @"INNER JOIN ICSWarehouse wh ON log.ToWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  10959. INNER JOIN ICSLocation loc ON log.ToLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  10960. if (type == 2)//出库
  10961. {
  10962. columns = @"log.FromWarehouseCode AS WHCode,
  10963. log.FromLocationCode AS LocationCode,
  10964. wh.WarehouseName AS WHName,
  10965. loc.LocationName AS LocationName,";
  10966. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  10967. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  10968. }
  10969. else if (type == 3)//调拨
  10970. {
  10971. columns = @"log.FromWarehouseCode AS FromWHCode,
  10972. log.FromLocationCode,
  10973. wh.WarehouseName AS FromWHName,
  10974. loc.LocationName AS FromLocationName,
  10975. log.ToWarehouseCode AS ToWHCode,
  10976. log.ToLocationCode,
  10977. whto.WarehouseName AS ToWHName,
  10978. locto.LocationName AS ToLocationName,";
  10979. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  10980. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint
  10981. INNER JOIN ICSWarehouse whto ON log.ToWarehouseCode=whto.WarehouseCode AND log.WorkPoint=whto.WorkPoint
  10982. INNER JOIN ICSLocation locto ON log.ToLocationCode=locto.LocationCode AND log.WorkPoint=locto.WorkPoint";
  10983. }
  10984. sql = string.Format(sql, Identification, columns, tables);
  10985. return DBHelper.SQlReturnData(sql, cmd);
  10986. }
  10987. /// <summary>
  10988. /// 先进先出批次管控
  10989. /// </summary>
  10990. /// <param name="LotNo"></param>
  10991. /// <param name="WorkPoitCode"></param>
  10992. /// <param name="cmd"></param>
  10993. /// <returns></returns>
  10994. public static string CanOut(string LotNo, string WorkPoitCode, string ScanLotCode, string sqlnew, SqlCommand cmd, Dictionary<string, string> language)
  10995. {
  10996. try
  10997. {
  10998. string sql = "";
  10999. string tsql = @"SELECT Top 1 a.F_ItemName
  11000. FROM Sys_SRM_ItemsDetail a
  11001. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  11002. WHERE b.F_EnCode='MtimeControl' AND a.F_EnabledMark='1'
  11003. ORDER BY a.F_SortCode DESC";
  11004. tsql = string.Format(tsql);
  11005. DataTable dttt = DBHelper.SQlReturnData(tsql, cmd);
  11006. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  11007. sql = @"DECLARE @CountNO INT,@Days INT
  11008. SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
  11009. SET @CountNO=(
  11010. SELECT COUNT(a.LotNO) FROM ICSWareHouseLotInfo a
  11011. INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO AND a.WorkPoint=b.WorkPoint
  11012. INNER JOIN ICSExtension bext on b.ExtensionID=bext.id AND b.WorkPoint=bext.WorkPoint
  11013. WHERE a.WorkPoint='{1}' AND ISNULL(a.Quantity,0)>0 AND 1=1
  11014. AND CONVERT(varchar(100), {2}, 23)<
  11015. (SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), {3}, 23)) FROM ICSWareHouseLotInfo x
  11016. INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
  11017. INNER JOIN ICSExtension yext on y.ExtensionID=yext.id AND b.WorkPoint=yext.WorkPoint
  11018. WHERE x.LotNO='{0}' AND x.WorkPoint='{1}' AND y.INVCode=b.INVCode " + sqlnew + @")
  11019. )
  11020. IF @CountNO>0
  11021. BEGIN
  11022. SELECT TOP 1 CASE a.F_ItemCode WHEN 'FIFO01' THEN '1' WHEN 'FIFO02' THEN '2' ELSE '3' END AS Type
  11023. FROM Sys_SRM_ItemsDetail a
  11024. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  11025. WHERE b.F_EnCode='FIFO' AND a.F_EnabledMark='1'
  11026. ORDER BY a.F_SortCode DESC
  11027. END
  11028. ELSE
  11029. BEGIN
  11030. SELECT @CountNO
  11031. END";
  11032. //0 - 已经是最早的批次
  11033. //1 - 不管控
  11034. //2 - 提醒
  11035. //3 - 限制
  11036. if (dttt.Rows[0]["F_ItemName"].ToString() == "失效日期")
  11037. {
  11038. sql = string.Format(sql, LotNo, WorkPoitCode, "ISNULL(b.ExpirationDate,b.ProductDate)", "ISNULL(y.ExpirationDate,y.ProductDate)");
  11039. }
  11040. else if (dttt.Rows[0]["F_ItemName"].ToString() == "生产日期")
  11041. {
  11042. sql = string.Format(sql, LotNo, WorkPoitCode, "b.ProductDate", "y.ProductDate");
  11043. }
  11044. else
  11045. {
  11046. sql = string.Format(sql, LotNo, WorkPoitCode, "a.InDate", "x.InDate");
  11047. }
  11048. if (!string.IsNullOrWhiteSpace(ScanLotCode))
  11049. {
  11050. sql = sql.Replace("1=1", "a.LotNO NOT IN (" + ScanLotCode + ")");
  11051. }
  11052. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  11053. if (string.IsNullOrWhiteSpace(res))
  11054. {
  11055. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  11056. }
  11057. else
  11058. return res;
  11059. }
  11060. catch (Exception ex)
  11061. {
  11062. throw new Exception(ex.Message);
  11063. }
  11064. }
  11065. /// <summary>
  11066. /// 获取自由项名称
  11067. /// </summary>
  11068. /// <param name="LotNo"></param>
  11069. /// <param name="WorkPoitCode"></param>
  11070. /// <param name="cmd"></param>
  11071. /// <returns></returns>
  11072. public static string GetExtentionName(string Code, string WorkPoitCode, SqlCommand cmd, Dictionary<string, string> language)
  11073. {
  11074. try
  11075. {
  11076. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  11077. string sql = @"select ColName from ICSExtensionEnable where ColCode='{0}' and WorkPoint='{1}'";
  11078. sql = string.Format(sql, Code, WorkPoitCode);
  11079. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  11080. return res;
  11081. }
  11082. catch (Exception ex)
  11083. {
  11084. throw new Exception(ex.Message);
  11085. }
  11086. }
  11087. /// <summary>
  11088. /// 保质期管控
  11089. /// </summary>
  11090. /// <param name="LotNo"></param>
  11091. /// <param name="WorkPoitCode"></param>
  11092. /// <param name="cmd"></param>
  11093. /// <returns></returns>
  11094. public static string Effective(string LotNo, string WorkPoitCode, SqlCommand cmd, Dictionary<string, string> language)
  11095. {
  11096. try
  11097. {
  11098. string sql = @"DECLARE @CountNO INT,@Days INT,@CurrentDays INT
  11099. SELECT @CountNO=EffectiveEnable,@Days=EffectiveDays,@CurrentDays=DATEDIFF(DAY, GETDATE(), b.ExpirationDate) FROM ICSInventory a
  11100. INNER JOIN ICSInventoryLot b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  11101. INNER JOIN ICSWareHouseLotInfo c ON b.LotNO=c.LotNO AND b.WorkPoint=c.WorkPoint
  11102. WHERE b.LotNO='{0}' AND b.WorkPoint='{1}'
  11103. IF @CountNO='1' AND @CurrentDays<0
  11104. BEGIN
  11105. SELECT TOP 1 CASE a.F_ItemCode WHEN 'Effective01' THEN '1' WHEN 'Effective02' THEN '2' ELSE '3' END AS Type
  11106. FROM Sys_SRM_ItemsDetail a
  11107. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  11108. WHERE b.F_EnCode='Effective' AND a.F_EnabledMark='1'
  11109. ORDER BY a.F_SortCode DESC
  11110. END
  11111. ELSE
  11112. BEGIN
  11113. SELECT @CountNO
  11114. END";
  11115. //0 - 已经是最早的批次
  11116. //1 - 不管控
  11117. //2 - 提醒
  11118. //3 - 限制
  11119. sql = string.Format(sql, LotNo, WorkPoitCode);
  11120. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  11121. if (string.IsNullOrWhiteSpace(res))
  11122. {
  11123. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  11124. }
  11125. else
  11126. return res;
  11127. }
  11128. catch (Exception ex)
  11129. {
  11130. throw new Exception(ex.Message);
  11131. }
  11132. }
  11133. #region 包装
  11134. /// <summary>
  11135. /// 查询包装信息
  11136. /// </summary>
  11137. /// <param name="JsonData"></param>
  11138. /// <returns></returns>
  11139. public static object ContainerGet(ICSContainer JsonData)
  11140. {
  11141. var language = LanguageHelper.GetName("WMSAPIInfo");
  11142. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11143. {
  11144. conn.Open();
  11145. SqlTransaction sqlTran = conn.BeginTransaction();
  11146. SqlCommand cmd = new SqlCommand();
  11147. cmd.Transaction = sqlTran;
  11148. cmd.Connection = conn;
  11149. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11150. try
  11151. {
  11152. string sql = string.Empty;
  11153. //目标包装
  11154. if (JsonData.ToContainerCode != null)
  11155. {
  11156. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  11157. BEGIN
  11158. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  11159. RETURN
  11160. END
  11161. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  11162. sql = string.Format(sql, JsonData.ToContainerCode, JsonData.WorkPoint);
  11163. }
  11164. ///原包装
  11165. else if (JsonData.FromContainerCode != null)
  11166. {
  11167. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  11168. BEGIN
  11169. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  11170. RETURN
  11171. END
  11172. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  11173. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  11174. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  11175. BEGIN
  11176. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  11177. RETURN
  11178. END
  11179. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  11180. sql = string.Format(sql, JsonData.FromContainerCode, JsonData.WorkPoint);
  11181. }
  11182. else
  11183. {
  11184. throw new Exception(language.GetNameByCode("WMSAPIInfo029"));//"请传入包装条码!");
  11185. }
  11186. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  11187. cmd.Transaction.Commit();
  11188. return table;
  11189. }
  11190. catch (Exception ex)
  11191. {
  11192. if (cmd.Transaction != null)
  11193. cmd.Transaction.Rollback();
  11194. log.Error(ex.Message);
  11195. throw new Exception(ex.Message);
  11196. }
  11197. finally
  11198. {
  11199. if (conn.State == ConnectionState.Open)
  11200. {
  11201. conn.Close();
  11202. }
  11203. conn.Dispose();
  11204. }
  11205. }
  11206. }
  11207. /// <summary>
  11208. /// 修改包装信息
  11209. /// </summary>
  11210. /// <param name="JsonData"></param>
  11211. /// <returns></returns>
  11212. public static DataTable ContainerUpdate(List<ICSContainer> JsonData)
  11213. {
  11214. var language = LanguageHelper.GetName("WMSAPIInfo");
  11215. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11216. {
  11217. conn.Open();
  11218. SqlTransaction sqlTran = conn.BeginTransaction();
  11219. SqlCommand cmd = new SqlCommand();
  11220. cmd.Transaction = sqlTran;
  11221. cmd.Connection = conn;
  11222. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11223. try
  11224. {
  11225. string sql = string.Empty;
  11226. string codes = string.Empty;
  11227. foreach (ICSContainer container in JsonData)
  11228. {
  11229. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  11230. BEGIN
  11231. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  11232. RETURN
  11233. END
  11234. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  11235. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  11236. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  11237. BEGIN
  11238. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  11239. RETURN
  11240. END
  11241. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{2}' and WorkPoint='{1}')
  11242. BEGIN
  11243. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  11244. RETURN
  11245. END
  11246. UPDATE b SET ContainerID=c.ID
  11247. FROM ICSContainer a
  11248. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  11249. INNER JOIN ICSContainer c ON c.ContainerCODE ='{2}' and a.WorkPoint=c.WorkPoint
  11250. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}'";
  11251. sql = string.Format(sql, container.FromContainerCode, container.WorkPoint, container.ToContainerCode);
  11252. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  11253. {
  11254. throw new Exception(language.GetNameByCode("WMSAPIInfo030"));//"包装更新失败!");
  11255. }
  11256. codes += "'" + container.ToContainerCode + container.WorkPoint + "',";
  11257. }
  11258. sql = @"SELECT a.ContainerCode, a.ContainerName,b.LotNo FROM ICSContainer a
  11259. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  11260. WHERE a.ContainerCODE+a.WorkPoint IN({0})";
  11261. sql = string.Format(sql, codes.Substring(0,codes.Length - 1));
  11262. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  11263. cmd.Transaction.Commit();
  11264. return table;
  11265. }
  11266. catch (Exception ex)
  11267. {
  11268. if (cmd.Transaction != null)
  11269. cmd.Transaction.Rollback();
  11270. log.Error(ex.Message);
  11271. throw new Exception(ex.Message);
  11272. }
  11273. finally
  11274. {
  11275. if (conn.State == ConnectionState.Open)
  11276. {
  11277. conn.Close();
  11278. }
  11279. conn.Dispose();
  11280. }
  11281. }
  11282. }
  11283. #endregion
  11284. #region 盘点
  11285. /// <summary>
  11286. /// 创建盘点单
  11287. /// </summary>
  11288. /// <param name="JsonData"></param>
  11289. /// <returns></returns>
  11290. public static DataTable CheckCreate(List<ICSCheck> JsonData)
  11291. {
  11292. var language = LanguageHelper.GetName("WMSAPIInfo");
  11293. if (JsonData.Count <= 0)
  11294. {
  11295. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11296. }
  11297. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11298. {
  11299. conn.Open();
  11300. SqlTransaction sqlTran = conn.BeginTransaction();
  11301. SqlCommand cmd = new SqlCommand();
  11302. cmd.Transaction = sqlTran;
  11303. cmd.Connection = conn;
  11304. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11305. try
  11306. {
  11307. string Code = string.Empty;
  11308. string sql = string.Empty;
  11309. foreach (var item in JsonData)
  11310. {
  11311. if (string.IsNullOrEmpty(item.User))
  11312. {
  11313. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  11314. }
  11315. if (string.IsNullOrEmpty(item.WorkPoint))
  11316. {
  11317. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  11318. }
  11319. //获取单号
  11320. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  11321. BEGIN
  11322. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  11323. RETURN
  11324. END
  11325. DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  11326. SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck
  11327. WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date
  11328. IF @MaxNO IS NULL
  11329. BEGIN
  11330. SELECT @date+'00001' AS Code
  11331. END
  11332. ELSE
  11333. BEGIN
  11334. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  11335. END ";
  11336. sql = string.Format(sql, item.User, item.WorkPoint);
  11337. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  11338. //创建盘点单
  11339. foreach (var itemInfo in item.detail)
  11340. {
  11341. int len = itemInfo.SelectLevel.Length;
  11342. sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE SUBSTRING(LocationCode,1,{4}) = '{1}')
  11343. BEGIN
  11344. RAISERROR('" + language.GetNameByCode("WMSAPIInfo460") + @"',16,1);
  11345. RETURN
  11346. END
  11347. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint)
  11348. SELECT NEWID(),'{0}','{1}','1',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location
  11349. FROM ICSWareHouseLotInfo a
  11350. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  11351. WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
  11352. GROUP BY b.F_Account,b.F_RealName,b.F_Location";
  11353. sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len);
  11354. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  11355. {
  11356. throw new Exception(language.GetNameByCode("WMSAPIInfo031"));//"盘点单创建失败!");
  11357. }
  11358. }
  11359. }
  11360. if (string.IsNullOrWhiteSpace(Code))
  11361. {
  11362. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单单号不能为空!");
  11363. }
  11364. #region 查询返回数据
  11365. sql = @"SELECT a.ID,a.CheckCode,a.SelectLevel,
  11366. a.Quantity,
  11367. a.Amount,
  11368. a.MUSER AS [User],
  11369. a.MTIME AS [MTime]
  11370. FROM ICSCheck a
  11371. WHERE a.CheckCode='{0}'";
  11372. sql = string.Format(sql, Code);
  11373. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  11374. #endregion
  11375. cmd.Transaction.Commit();
  11376. return data;
  11377. }
  11378. catch (Exception ex)
  11379. {
  11380. if (cmd.Transaction != null)
  11381. cmd.Transaction.Rollback();
  11382. log.Error(ex.Message);
  11383. throw new Exception(ex.Message);
  11384. }
  11385. finally
  11386. {
  11387. if (conn.State == ConnectionState.Open)
  11388. {
  11389. conn.Close();
  11390. }
  11391. conn.Dispose();
  11392. }
  11393. }
  11394. }
  11395. /// <summary>
  11396. /// 盘点扫描
  11397. /// </summary>
  11398. /// <param name="JsonData"></param>
  11399. /// <returns></returns>
  11400. public static DataTable LOTCheckCreate(List<ICSCheck> JsonData)
  11401. {
  11402. var language = LanguageHelper.GetName("WMSAPIInfo");
  11403. if (JsonData.Count <= 0)
  11404. {
  11405. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11406. }
  11407. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11408. {
  11409. conn.Open();
  11410. SqlTransaction sqlTran = conn.BeginTransaction();
  11411. SqlCommand cmd = new SqlCommand();
  11412. cmd.Transaction = sqlTran;
  11413. cmd.Connection = conn;
  11414. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11415. try
  11416. {
  11417. string lots = string.Empty;
  11418. string sql = string.Empty;
  11419. int result = 0;
  11420. string Identification = Guid.NewGuid().ToString();
  11421. foreach (var item in JsonData)
  11422. {
  11423. if (string.IsNullOrEmpty(item.User))
  11424. {
  11425. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  11426. }
  11427. if (string.IsNullOrEmpty(item.WorkPoint))
  11428. {
  11429. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  11430. }
  11431. if (string.IsNullOrEmpty(item.CheckCode))
  11432. {
  11433. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单号不能为空!");
  11434. }
  11435. //校验
  11436. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  11437. BEGIN
  11438. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  11439. RETURN
  11440. END
  11441. IF NOT EXISTS(SELECT ID FROM ICSCheck WHERE CheckCode='{2}' AND WorkPoint='{1}')
  11442. BEGIN
  11443. RAISERROR('" + language.GetNameByCode("WMSAPIInfo075") + @"',16,1);
  11444. RETURN
  11445. END";
  11446. sql = string.Format(sql, item.User, item.WorkPoint, item.CheckCode);
  11447. DBHelper.ExecuteNonQuery(sql, cmd);
  11448. //创建盘点单
  11449. foreach (var itemInfo in item.detail)
  11450. {
  11451. string chekksql = @"select d.EATTRIBUTE1 FROM ICSInventoryLot c
  11452. INNER JOIN ICSInventory d on c.InvCode=d.InvCode and c.WorkPoint=d.WorkPoint
  11453. WHERE c.WorkPoint='{1}' and c.lotno='{2}' and d.AmountEnable='1'";
  11454. chekksql = string.Format(chekksql, item.CheckCode, item.WorkPoint, itemInfo.LotNo);
  11455. DataTable dta = DBHelper.SQlReturnData(chekksql, cmd);
  11456. if (dta.Rows.Count > 0)
  11457. {
  11458. itemInfo.ActualQuantity = (decimal.Parse(itemInfo.ActualQuantity) * decimal.Parse(dta.Rows[0]["EATTRIBUTE1"].ToString())).ToString();
  11459. }
  11460. sql = @"IF NOT EXISTS(SELECT LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{1}' AND WorkPoint='{3}')
  11461. BEGIN
  11462. RAISERROR('" + language.GetNameByCode("WMSAPIInfo076") + @"',16,1);
  11463. RETURN
  11464. END
  11465. IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  11466. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  11467. WHERE b.CheckCode='{0}' AND a.LotNo='{1}' AND a.WorkPoint='{3}')
  11468. BEGIN
  11469. IF ('{5}'='')
  11470. BEGIN
  11471. UPDATE a SET PrimaryQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE(),EATTRIBUTE1='1'
  11472. FROM ICSCheckDetail a
  11473. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  11474. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  11475. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  11476. END
  11477. ELSE IF ('{5}'='')
  11478. BEGIN
  11479. UPDATE a SET CheckQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE(),EATTRIBUTE1='3'
  11480. FROM ICSCheckDetail a
  11481. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  11482. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  11483. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  11484. END
  11485. ELSE
  11486. BEGIN
  11487. UPDATE a SET ReplayQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE(),EATTRIBUTE1='2'
  11488. FROM ICSCheckDetail a
  11489. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  11490. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  11491. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  11492. END
  11493. END
  11494. ELSE
  11495. BEGIN
  11496. IF ('{5}'='')
  11497. BEGIN
  11498. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  11499. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','{4}','0','0','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint,'1'
  11500. FROM ICSWareHouseLotInfo a
  11501. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  11502. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  11503. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  11504. END
  11505. ELSE IF ('{5}'='')
  11506. BEGIN
  11507. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  11508. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','0','0','{4}','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint,'3'
  11509. FROM ICSWareHouseLotInfo a
  11510. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  11511. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  11512. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  11513. END
  11514. ELSE
  11515. BEGIN
  11516. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  11517. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','{4}','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint,'2'
  11518. FROM ICSWareHouseLotInfo a
  11519. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  11520. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  11521. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  11522. END
  11523. END";
  11524. sql = string.Format(sql, item.CheckCode, itemInfo.LotNo, item.User, item.WorkPoint, itemInfo.ActualQuantity, item.CheckKind);
  11525. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  11526. {
  11527. throw new Exception(language.GetNameByCode("WMSAPIInfo033"));//"盘点扫描创建失败!");
  11528. }
  11529. ///更新库存
  11530. sql = @"UPDATE ICSWareHouseLotInfo SET LockQuantity='{2}' WHERE LotNo='{0}' AND WorkPoint='{1}'";
  11531. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.ActualQuantity);
  11532. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  11533. {
  11534. throw new Exception(language.GetNameByCode("WMSAPIInfo168"));//"库存更新失败!");
  11535. }
  11536. #region 更新ICSCheckDetail表
  11537. //string strSql = @"UPDATE ICSCheckDetail Set";
  11538. //if (item.CheckKind == "初盘")
  11539. // strSql += @" PrimaryQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  11540. //else if (item.CheckKind == "复盘")
  11541. // strSql += @" ReplayQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  11542. //else
  11543. // strSql += @" CheckQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  11544. //strSql += @" where ToCheckNO='" + item.CheckCode + "' AND WorkPoint='" + item.WorkPoint + "'";
  11545. //cmd.CommandText = strSql;
  11546. //result = cmd.ExecuteNonQuery();
  11547. //if (result <= 0)
  11548. //{
  11549. // throw new Exception(language.GetNameByCode("WMSAPIInfo296"));//"盘点子表数量增加失败!");
  11550. //}
  11551. #endregion
  11552. #region 更新库存
  11553. //if (item.UpdateWHLI)
  11554. //{
  11555. // ICSWareHouseLotInfoService.WareHouseLotInfoUpdate(Identification, item.CheckCode, "", itemInfo.LotNo, itemInfo.ActualQuantity, item.User, item.WorkPoint, TransTypeEnum.Check.GetDescription<DBValue>(), item.CheckKind, cmd, language);
  11556. //}
  11557. #endregion
  11558. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  11559. }
  11560. if (string.IsNullOrWhiteSpace(lots))
  11561. {
  11562. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  11563. }
  11564. //sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  11565. // FROM ICSCheck a
  11566. // 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
  11567. // WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  11568. //sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  11569. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  11570. //{
  11571. // throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  11572. //}
  11573. }
  11574. #region 查询返回数据
  11575. sql = @"SELECT x.ID,x.CheckID,y.WarehouseCode AS WHCode,x.LotNo,
  11576. y.InvCode,
  11577. inv.InvName,
  11578. inv.InvStd,
  11579. x.Quantity,x.PrimaryQuantity,x.PrimaryAmount,x.ReplayQuantity,x.ReplayAmount,x.CheckQuantity,x.CheckAmount,
  11580. inv.InvUnit,
  11581. x.MUSER AS [User],
  11582. x.MTIME AS [MTime]
  11583. FROM ICSCheckDetail x
  11584. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  11585. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  11586. WHERE x.LotNo+x.WorkPoint IN ({0})";
  11587. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  11588. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  11589. #endregion
  11590. cmd.Transaction.Commit();
  11591. return data;
  11592. }
  11593. catch (Exception ex)
  11594. {
  11595. if (cmd.Transaction != null)
  11596. cmd.Transaction.Rollback();
  11597. log.Error(ex.Message);
  11598. throw new Exception(ex.Message);
  11599. }
  11600. finally
  11601. {
  11602. if (conn.State == ConnectionState.Open)
  11603. {
  11604. conn.Close();
  11605. }
  11606. conn.Dispose();
  11607. }
  11608. }
  11609. }
  11610. #endregion
  11611. #region 多语言
  11612. /// <summary>
  11613. /// 多语言查询
  11614. /// </summary>
  11615. /// <param name="JsonData"></param>
  11616. /// <returns></returns>
  11617. public static DataTable PromptInformationGet(WMSBarCoreModel JsonData)
  11618. {
  11619. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11620. {
  11621. conn.Open();
  11622. SqlCommand cmd = new SqlCommand();
  11623. cmd.Connection = conn;
  11624. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11625. try
  11626. {
  11627. string DefiniteLanguage = ICSDefiniteLanguageService.GetLanguage();
  11628. string sql = @"select " + DefiniteLanguage + " AS Name,Code from Sys_Language where 1=1";
  11629. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  11630. {
  11631. sql += " and Code LIKE '%{0}%'";
  11632. }
  11633. sql = string.Format(sql, JsonData.Code);
  11634. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  11635. return data;
  11636. }
  11637. catch (Exception ex)
  11638. {
  11639. log.Error(ex.Message);
  11640. throw new Exception(ex.Message);
  11641. }
  11642. finally
  11643. {
  11644. if (conn.State == ConnectionState.Open)
  11645. {
  11646. conn.Close();
  11647. }
  11648. conn.Dispose();
  11649. }
  11650. }
  11651. }
  11652. #endregion
  11653. #region 仓库/库位
  11654. /// <summary>
  11655. /// 仓库/库位
  11656. /// </summary>
  11657. /// <param name="JsonData"></param>
  11658. /// <returns></returns>
  11659. public static DataTable LocationGet(ICSLocation JsonData)
  11660. {
  11661. var language = LanguageHelper.GetName("WMSAPIInfo");
  11662. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11663. {
  11664. conn.Open();
  11665. SqlTransaction sqlTran = conn.BeginTransaction();
  11666. SqlCommand cmd = new SqlCommand();
  11667. cmd.Transaction = sqlTran;
  11668. cmd.Connection = conn;
  11669. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11670. try
  11671. {
  11672. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode like '%{0}%' AND a.WorkPoint='{1}')
  11673. BEGIN
  11674. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  11675. RETURN
  11676. END
  11677. 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}')
  11678. BEGIN
  11679. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  11680. RETURN
  11681. END
  11682. 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')
  11683. BEGIN
  11684. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  11685. RETURN
  11686. END
  11687. SELECT
  11688. LocationCode,
  11689. LocationName ,
  11690. WarehouseCode,
  11691. WarehouseName
  11692. FROM ICSLocation a
  11693. 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'";
  11694. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  11695. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  11696. cmd.Transaction.Commit();
  11697. return data;
  11698. }
  11699. catch (Exception ex)
  11700. {
  11701. if (cmd.Transaction != null)
  11702. cmd.Transaction.Rollback();
  11703. log.Error(ex.Message);
  11704. throw new Exception(ex.Message);
  11705. }
  11706. finally
  11707. {
  11708. if (conn.State == ConnectionState.Open)
  11709. {
  11710. conn.Close();
  11711. }
  11712. conn.Dispose();
  11713. }
  11714. }
  11715. }
  11716. /// <summary>
  11717. /// 仓库/库位
  11718. /// </summary>
  11719. /// <param name="JsonData"></param>
  11720. /// <returns></returns>
  11721. public static DataTable AMLocationGet(ICSLocation JsonData)
  11722. {
  11723. var language = LanguageHelper.GetName("WMSAPIInfo");
  11724. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11725. {
  11726. conn.Open();
  11727. SqlTransaction sqlTran = conn.BeginTransaction();
  11728. SqlCommand cmd = new SqlCommand();
  11729. cmd.Transaction = sqlTran;
  11730. cmd.Connection = conn;
  11731. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11732. string UserName = "";
  11733. string WarehouseCode = "";
  11734. try
  11735. {
  11736. //检验是否分批
  11737. string uersql = @"SELECT F_RealName from Sys_SRM_User Where F_Account='{0}' AND F_Location='{1}'
  11738. ";
  11739. uersql = string.Format(uersql, JsonData.User,JsonData.WorkPoint);
  11740. DataTable dt = DBHelper.SQlReturnData(uersql, cmd);
  11741. if (dt.Rows.Count == 0)
  11742. {
  11743. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  11744. }
  11745. else
  11746. {
  11747. UserName = dt.Rows[0]["F_RealName"].ToString();
  11748. }
  11749. string UName = UserName.Substring(0, 2);
  11750. string waresql = @"select WarehouseCode,WarehouseName from ICSWarehouse
  11751. where SUBSTRING(WarehouseName,1,2)='{0}' and WorkPoint='{1}'";
  11752. waresql = string.Format(waresql, UName, JsonData.WorkPoint);
  11753. DataTable dta = DBHelper.SQlReturnData(waresql, cmd);
  11754. if (dta.Rows.Count == 0)
  11755. {
  11756. throw new Exception(language.GetNameByCode("WMSAPIInfo369"));
  11757. }
  11758. else
  11759. {
  11760. UName = dta.Rows[0]["WarehouseCode"].ToString();
  11761. }
  11762. //switch (UName)
  11763. //{
  11764. // case "L1":
  11765. // UName = "021";
  11766. // break;
  11767. // case "L2":
  11768. // UName = "022";
  11769. // break;
  11770. // case "L3":
  11771. // UName = "023";
  11772. // break;
  11773. // case "L4":
  11774. // UName = "024";
  11775. // break;
  11776. // case "L5":
  11777. // UName = "025";
  11778. // break;
  11779. // case "L6":
  11780. // UName = "026";
  11781. // break;
  11782. // case "L7":
  11783. // UName = "025";
  11784. // break;
  11785. // case "C1":
  11786. // UName = "015";
  11787. // break;
  11788. //}
  11789. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode like '%{0}%' AND a.WorkPoint='{1}')
  11790. BEGIN
  11791. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  11792. RETURN
  11793. END
  11794. 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}')
  11795. BEGIN
  11796. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  11797. RETURN
  11798. END
  11799. 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')
  11800. BEGIN
  11801. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  11802. RETURN
  11803. END
  11804. 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}')
  11805. BEGIN
  11806. RAISERROR('线',16,1)
  11807. RETURN
  11808. END
  11809. SELECT
  11810. LocationCode,
  11811. LocationName ,
  11812. WarehouseCode,
  11813. WarehouseName
  11814. FROM ICSLocation a
  11815. 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'";
  11816. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint, UName);
  11817. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  11818. cmd.Transaction.Commit();
  11819. return data;
  11820. }
  11821. catch (Exception ex)
  11822. {
  11823. if (cmd.Transaction != null)
  11824. cmd.Transaction.Rollback();
  11825. log.Error(ex.Message);
  11826. throw new Exception(ex.Message);
  11827. }
  11828. finally
  11829. {
  11830. if (conn.State == ConnectionState.Open)
  11831. {
  11832. conn.Close();
  11833. }
  11834. conn.Dispose();
  11835. }
  11836. }
  11837. }
  11838. #endregion
  11839. #region 登陆
  11840. public static object CheckLogin(Sys_SRM_User userModel)
  11841. {
  11842. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11843. {
  11844. conn.Open();
  11845. SqlCommand cmd = new SqlCommand();
  11846. cmd.Connection = conn;
  11847. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11848. try
  11849. {
  11850. string sql = @"select F_Account from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  11851. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  11852. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  11853. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  11854. {
  11855. sql = @" select a.[F_Id] as UserId
  11856. ,[F_Account] as userCode
  11857. ,[F_RealName] as UserName
  11858. ,[F_NickName]
  11859. ,b.F_UserPassword
  11860. ,b.F_UserSecretkey
  11861. ,[F_HeadIcon]
  11862. ,[F_Gender]
  11863. ,[F_Birthday]
  11864. ,[F_MobilePhone]
  11865. ,[F_Email]
  11866. ,[F_WeChat]
  11867. ,[F_ManagerId]
  11868. ,[F_SecurityLevel]
  11869. ,[F_Signature]
  11870. ,[F_OrganizeId]
  11871. ,[F_DepartmentId]
  11872. ,[F_RoleId]
  11873. ,[F_DutyId]
  11874. ,[F_IsAdministrator]
  11875. ,[F_SortCode]
  11876. ,[F_DeleteMark]
  11877. ,[F_EnabledMark]
  11878. ,[F_Description]
  11879. ,[F_CreatorTime]
  11880. ,[F_CreatorUserId]
  11881. ,[F_LastModifyTime]
  11882. ,[F_LastModifyUserId]
  11883. ,[F_DeleteTime]
  11884. ,[F_DeleteUserId]
  11885. ,[F_Location] as WorkPoint
  11886. ,[F_VenCode]
  11887. from Sys_SRM_User a
  11888. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  11889. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  11890. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  11891. dt = DBHelper.SQlReturnData(sql, cmd);
  11892. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  11893. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  11894. foreach (var item in users)
  11895. {
  11896. //string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
  11897. string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  11898. if (dbPassword == item.F_UserPassword)
  11899. {
  11900. string json = JsonConvert.SerializeObject(dt);
  11901. List<Sys_SRM_User> userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  11902. return userLogOnEntity;
  11903. }
  11904. else
  11905. {
  11906. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI004"));//"密码不正确,请重新输入");
  11907. }
  11908. }
  11909. }
  11910. else
  11911. {
  11912. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI005"));//"用户名不存在,请重新输入!");
  11913. }
  11914. return null;
  11915. }
  11916. catch (Exception ex)
  11917. {
  11918. log.Error(ex.Message);
  11919. throw new Exception(ex.Message);
  11920. }
  11921. finally
  11922. {
  11923. if (conn.State == ConnectionState.Open)
  11924. {
  11925. conn.Close();
  11926. }
  11927. conn.Dispose();
  11928. }
  11929. }
  11930. }
  11931. #endregion
  11932. #region 获取调拨单
  11933. /// <summary>
  11934. /// 获取未发,未发完调拨单
  11935. /// </summary>
  11936. /// <param name="JsonData"></param>
  11937. /// <returns></returns>
  11938. public static DataTable TransCodemationGet(TransferDoc JsonData)
  11939. {
  11940. var language = LanguageHelper.GetName("WMSAPIInfo");
  11941. if (JsonData == null)
  11942. {
  11943. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  11944. }
  11945. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11946. {
  11947. conn.Open();
  11948. SqlTransaction sqlTran = conn.BeginTransaction();
  11949. SqlCommand cmd = new SqlCommand();
  11950. cmd.Transaction = sqlTran;
  11951. cmd.Connection = conn;
  11952. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11953. try
  11954. {
  11955. string Workpoint = "";
  11956. Workpoint = JsonData.WorkPoint;
  11957. string sql = @"SELECT DISTINCT TransferNO as TransCode FROM ICSTransferApplication
  11958. WHERE WorkPoint='{0}' AND Quantity>ISNULL(TransferQuantity, 0) order by TransferNO desc";
  11959. sql = string.Format(sql, Workpoint);
  11960. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  11961. return table;
  11962. }
  11963. catch (Exception ex)
  11964. {
  11965. if (cmd.Transaction != null)
  11966. cmd.Transaction.Rollback();
  11967. log.Error(ex.Message);
  11968. throw new Exception(ex.Message);
  11969. }
  11970. finally
  11971. {
  11972. if (conn.State == ConnectionState.Open)
  11973. {
  11974. conn.Close();
  11975. }
  11976. conn.Dispose();
  11977. }
  11978. }
  11979. }
  11980. #endregion
  11981. #region 源头单据信息(佑伦专用)
  11982. /// <summary>
  11983. /// 源头单据信息(佑伦专用)
  11984. /// </summary>
  11985. /// <param name="JsonData"></param>
  11986. /// <returns></returns>
  11987. public static DataTable YLTransInformationGet(WMSSourceDocumentModel JsonData)
  11988. {
  11989. var language = LanguageHelper.GetName("WMSAPIInfo");
  11990. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  11991. {
  11992. conn.Open();
  11993. SqlCommand cmd = new SqlCommand();
  11994. cmd.Connection = conn;
  11995. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  11996. try
  11997. {
  11998. if (string.IsNullOrEmpty(JsonData.TransCode))
  11999. {
  12000. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  12001. }
  12002. else if (string.IsNullOrEmpty(JsonData.TransType))
  12003. {
  12004. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  12005. }
  12006. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  12007. {
  12008. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  12009. }
  12010. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  12011. {
  12012. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  12013. }
  12014. string TransType = JsonData.TransType;
  12015. #region SLQ
  12016. string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  12017. BEGIN
  12018. RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  12019. RETURN
  12020. END
  12021. ";
  12022. string sql = @"SELECT a.ID,
  12023. {0}
  12024. convert(varchar(100),'') AS LocationCode,
  12025. convert(varchar(100),'') AS LotNo,
  12026. convert(varchar(10),'') AS ToWarehouseCode,
  12027. 0 AS LocationQty,
  12028. 0 AS isMatched,
  12029. a.InvCode,
  12030. inv.InvName,
  12031. inv.InvStd,
  12032. a.Quantity,
  12033. inv.InvUnit,
  12034. a.Amount,
  12035. a.WHCode,
  12036. inv.AmountUnit,
  12037. wh.WarehouseName AS WHName,
  12038. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  12039. a.ExtensionID,
  12040. 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,
  12041. ISNULL(ext.Version, '') AS Version,
  12042. ISNULL(ext.Brand, '') AS Brand,
  12043. ISNULL(ext.cFree1, '') AS cFree1,
  12044. ISNULL(ext.cFree2, '') AS cFree2,
  12045. ISNULL(ext.cFree3, '') AS cFree3,
  12046. ISNULL(ext.cFree4, '') AS cFree4,
  12047. ISNULL(ext.cFree5, '') AS cFree5,
  12048. ISNULL(ext.cFree6, '') AS cFree6,
  12049. ISNULL(ext.cFree7, '') AS cFree7,
  12050. ISNULL(ext.cFree8, '') AS cFree8,
  12051. ISNULL(ext.cFree9, '') AS cFree9,
  12052. ISNULL(ext.cFree10, '') AS cFree10,
  12053. a.MUSER AS [User],
  12054. a.MTIME AS [MTime]
  12055. {4}
  12056. FROM {1}
  12057. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  12058. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  12059. LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  12060. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  12061. WHERE {2} ";
  12062. string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  12063. c.Code,
  12064. c.InvCode,
  12065. c.InvName,
  12066. c.InvStd,
  12067. c.InvUnit,
  12068. FLOOR(c.iQuantity) AS iQuantity,
  12069. d.WarehouseCode,
  12070. d.LocationCode,
  12071. d.LotNO,
  12072. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  12073. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  12074. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  12075. FROM
  12076. ({0}) c
  12077. 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
  12078. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  12079. 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
  12080. DECLARE @ItemCode VARCHAR(50),
  12081. @QTY DECIMAL(18,3),
  12082. @ItemCodeCurrent VARCHAR(50),
  12083. @QTYCurrent DECIMAL(18,3),
  12084. @iQuantityCurrent DECIMAL(18,3),
  12085. @CanDelete BIT,
  12086. @Row INT,
  12087. @rowCurrent INT
  12088. SET @Row = @@rowcount
  12089. SET @rowCurrent=1
  12090. SET @CanDelete=0
  12091. SET @ItemCode=''
  12092. WHILE @rowCurrent<=@Row
  12093. BEGIN
  12094. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  12095. PRINT(@rowCurrent)
  12096. IF @ItemCode<>@ItemCodeCurrent
  12097. BEGIN
  12098. SET @ItemCode=@ItemCodeCurrent
  12099. SET @QTY=0
  12100. SET @CanDelete=0
  12101. END
  12102. IF @CanDelete=1
  12103. BEGIN
  12104. DELETE FROM #temp WHERE rowNo=@rowCurrent
  12105. SET @rowCurrent += 1
  12106. CONTINUE
  12107. END
  12108. SET @QTY += @QTYCurrent
  12109. IF @QTY>=@iQuantityCurrent
  12110. BEGIN
  12111. SET @CanDelete=1
  12112. END
  12113. SET @rowCurrent += 1
  12114. END
  12115. SELECT * FROM #temp
  12116. DROP TABLE #temp
  12117. ";
  12118. #endregion
  12119. bool isDeliveryNotice = false; //送货、到货、含委外
  12120. string columns = string.Empty; //查询源头单据表的特殊列名
  12121. string tableName = string.Empty; //查询源头单据表名
  12122. string where = string.Empty; //查询源头单据的过滤条件
  12123. bool isMerge = false; //合并发料
  12124. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  12125. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  12126. string sqls = string.Empty;
  12127. string sqlCheckSign = "";
  12128. DataTable flag = null;
  12129. #region 检料表信息
  12130. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  12131. {
  12132. enableCode = "Over001";
  12133. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, b.Sequence+'~'+a.Sequence, b.MOCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  12134. #region 工单备料sql
  12135. sqls = @" SELECT
  12136. c.MOCode as Code,
  12137. a.InvCode,
  12138. b.InvName,
  12139. b.InvStd,
  12140. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12141. a.WhCode,
  12142. b.InvUnit,
  12143. a.ExtensionID
  12144. FROM
  12145. ICSMOPick a
  12146. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  12147. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12148. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  12149. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  12150. #endregion
  12151. }
  12152. if (TransType == TransTypeEnum.MOApply.GetDescription())
  12153. {
  12154. enableCode = "Over002";
  12155. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Sequence, a.ApplyCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  12156. #region 工单领料SQL
  12157. sqls = @" select
  12158. a.ApplyCode as Code,
  12159. a.InvCode,
  12160. b.InvName,
  12161. b.InvStd,
  12162. b.InvUnit,
  12163. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12164. a.WhCode,
  12165. a.ExtensionID
  12166. FROM
  12167. ICSMOApply a
  12168. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12169. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  12170. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  12171. #endregion
  12172. }
  12173. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  12174. {
  12175. //enableCode = "Over003";
  12176. excessQtySql = "";
  12177. #region 工单材料出库SQL
  12178. sqls = @" select
  12179. a.IssueCode as Code,
  12180. a.InvCode,
  12181. b.InvName,
  12182. b.InvStd,
  12183. b.InvUnit,
  12184. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12185. a.WhCode,
  12186. a.ExtensionID
  12187. FROM
  12188. ICSMOIssue a
  12189. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12190. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  12191. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  12192. #endregion
  12193. }
  12194. if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  12195. {
  12196. enableCode = "Over004";
  12197. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Sequence, b.OOCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  12198. #region 委外备料SQL
  12199. sqls = @" select
  12200. c.OOCode as Code,
  12201. a.InvCode,
  12202. b.InvName,
  12203. b.InvStd,
  12204. b.InvUnit,
  12205. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12206. a.WhCode,
  12207. a.ExtensionID
  12208. FROM
  12209. ICSOOPick a
  12210. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  12211. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12212. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  12213. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  12214. #endregion
  12215. }
  12216. if (TransType == TransTypeEnum.OOApply.GetDescription())
  12217. {
  12218. enableCode = "Over005";
  12219. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Sequence, a.ApplyCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  12220. #region 委外领料SQL
  12221. sqls = @" select
  12222. a.ApplyCode as Code,
  12223. a.InvCode,
  12224. b.InvName,
  12225. b.InvStd,
  12226. b.InvUnit,
  12227. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12228. a.WhCode,
  12229. a.ExtensionID
  12230. FROM
  12231. ICSOApply a
  12232. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12233. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  12234. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  12235. #endregion
  12236. }
  12237. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  12238. {
  12239. //enableCode = "Over006";
  12240. excessQtySql = "";
  12241. #region 委外材料出库SQL
  12242. sqls = @" select
  12243. a.IssueCode as Code,
  12244. a.InvCode,
  12245. b.InvName,
  12246. b.InvStd,
  12247. b.InvUnit,
  12248. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12249. a.WhCode,
  12250. a.ExtensionID
  12251. FROM
  12252. ICSOIssue a
  12253. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12254. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  12255. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  12256. #endregion
  12257. }
  12258. if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  12259. {
  12260. enableCode = "";
  12261. excessQtySql = "";
  12262. #region 销售发货SQL
  12263. sqls = @" select
  12264. a.SDNCode as Code,
  12265. a.InvCode,
  12266. b.InvName,
  12267. b.InvStd,
  12268. b.InvUnit,
  12269. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12270. a.WhCode,
  12271. a.ExtensionID
  12272. FROM
  12273. ICSSDN a
  12274. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12275. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  12276. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  12277. #endregion
  12278. }
  12279. if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  12280. {
  12281. enableCode = "";
  12282. excessQtySql = "";
  12283. #region 其它出库SQL
  12284. sqls = @" select
  12285. a.OutCode as Code,
  12286. a.InvCode,
  12287. b.InvName,
  12288. b.InvStd,
  12289. b.InvUnit,
  12290. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12291. a.WhCode,
  12292. a.ExtensionID
  12293. FROM
  12294. ICSOtherOut a
  12295. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12296. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  12297. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  12298. #endregion
  12299. }
  12300. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  12301. {
  12302. enableCode = "";
  12303. excessQtySql = "";
  12304. #region 借用SQL
  12305. sqls = @"select
  12306. a.BrrowCode as Code,
  12307. a.InvCode,
  12308. b.InvName,
  12309. b.InvStd,
  12310. b.InvUnit,
  12311. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12312. a.WhCode,
  12313. a.ExtensionID
  12314. FROM
  12315. ICSBrrow a
  12316. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12317. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  12318. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  12319. #endregion
  12320. }
  12321. if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  12322. {
  12323. enableCode = "";
  12324. excessQtySql = "";
  12325. #region 物料调拨
  12326. sqls = @" select
  12327. a.TransferNO as Code,
  12328. a.InvCode,
  12329. b.InvName,
  12330. b.InvStd,
  12331. b.InvUnit,
  12332. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12333. a.FromWarehouseCode as WhCode,
  12334. a.ExtensionID
  12335. FROM
  12336. ICSTransfer a
  12337. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12338. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  12339. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  12340. #endregion
  12341. }
  12342. if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  12343. {
  12344. enableCode = "";
  12345. excessQtySql = "";
  12346. #region 两步调出
  12347. sqls = @"select
  12348. a.OutCode as Code,
  12349. a.InvCode,
  12350. b.InvName,
  12351. b.InvStd,
  12352. b.InvUnit,
  12353. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  12354. a.WHCode ,
  12355. a.ExtensionID
  12356. from ICSOtherOut a
  12357. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  12358. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  12359. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  12360. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  12361. #endregion
  12362. }
  12363. #endregion
  12364. #region 出库
  12365. #region 采购退货
  12366. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  12367. {
  12368. isDeliveryNotice = true;
  12369. columns = @"a.DNCode AS TransCode,
  12370. a.DNDetailID AS DetailID,
  12371. a.DNType AS Type,
  12372. a.Sequence AS TransSequence,
  12373. a.RCVQuantity AS IssueQuantity,
  12374. a.Quantity,
  12375. a.Amount,
  12376. a.MUSER AS [User],
  12377. a.MTIME AS [MTime],";
  12378. tableName = @"ICSDeliveryNotice a ";
  12379. where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' ";
  12380. }
  12381. #endregion
  12382. #region 委外发料(合并发料)
  12383. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  12384. {
  12385. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode004' and enable = '1'";
  12386. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12387. isMerge = true;
  12388. columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
  12389. a.PickID AS DetailID,
  12390. a.SupplyType AS Type,
  12391. b.Sequence+'~'+a.Sequence AS TransSequence,
  12392. a.IssueQuantity AS IssueQuantity,";
  12393. tableNameMerge = @"ICSOOPick a
  12394. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  12395. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12396. columns = @"b.OOCode AS TransCode,
  12397. a.PickID AS DetailID,
  12398. a.SupplyType AS Type,
  12399. b.Sequence+'~'+a.Sequence AS TransSequence,
  12400. a.IssueQuantity AS IssueQuantity,";
  12401. tableName = @"ICSOOPick a
  12402. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  12403. where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' ";
  12404. }
  12405. #endregion
  12406. #region 委外退货
  12407. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  12408. {
  12409. isDeliveryNotice = true;
  12410. columns = @"a.ODNCode AS TransCode,
  12411. a.ODNDetailID AS DetailID,
  12412. a.ODNType AS Type,
  12413. a.Sequence AS TransSequence,
  12414. a.RCVQuantity AS IssueQuantity,
  12415. a.Quantity,
  12416. a.Amount,
  12417. a.MUSER AS [User],
  12418. a.MTIME AS [MTime],";
  12419. tableName = @"ICSODeliveryNotice a ";
  12420. where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' ";
  12421. }
  12422. #endregion
  12423. #region 生产发料(合并发料)
  12424. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  12425. {
  12426. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
  12427. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12428. isMerge = true;
  12429. columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  12430. a.PickID AS DetailID,
  12431. a.SupplyType AS Type,
  12432. ISNULL(a.EATTRIBUTE2,'') AS JIGOU,
  12433. b.Sequence+'~'+a.Sequence AS TransSequence,
  12434. a.IssueQuantity AS IssueQuantity,";
  12435. tableNameMerge = @"ICSMOPick a
  12436. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  12437. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12438. columns = @"b.MOCode AS TransCode,
  12439. a.PickID AS DetailID,
  12440. a.SupplyType AS Type,
  12441. ISNULL(a.EATTRIBUTE2,'') AS JIGOU,
  12442. b.Sequence+'~'+a.Sequence AS TransSequence,
  12443. a.IssueQuantity AS IssueQuantity,";
  12444. tableName = @"ICSMOPick a
  12445. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  12446. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1'";
  12447. }
  12448. #endregion
  12449. #region 销售出库(合并发料)
  12450. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  12451. {
  12452. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
  12453. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12454. isMerge = true;
  12455. columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
  12456. a.SDNDetailID AS DetailID,
  12457. a.SOCode,
  12458. a.Type,
  12459. a.Sequence AS TransSequence,
  12460. a.SDNQuantity AS IssueQuantity,";
  12461. tableNameMerge = @"ICSSDN a
  12462. INNER JOIN ICSMOPickMerge mer ON a.SDNDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12463. columns = @"a.SDNCode AS TransCode,
  12464. a.SDNDetailID AS DetailID,
  12465. a.SOCode,
  12466. a.Type,
  12467. a.Sequence AS TransSequence,
  12468. a.SDNQuantity AS IssueQuantity,";
  12469. tableName = @"ICSSDN a ";
  12470. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' ";
  12471. }
  12472. #endregion
  12473. #region 盘点
  12474. else if (TransType == TransTypeEnum.Check.GetDescription())
  12475. {
  12476. #region SLQ
  12477. sql = @"SELECT a.ID,
  12478. {0}
  12479. a.Quantity,
  12480. a.SelectLevel AS LocationCode,
  12481. a.Amount,
  12482. a.MUSER AS [User],
  12483. a.MTIME AS [MTime]
  12484. FROM {1}
  12485. WHERE {2} ";
  12486. #endregion
  12487. columns = @"a.CheckCode AS TransCode,
  12488. a.ID,
  12489. '' AS Type,";
  12490. tableName = @"ICSCheck a ";
  12491. where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' ";
  12492. }
  12493. #endregion
  12494. #region 一步调拨(合并发料)
  12495. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  12496. {
  12497. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
  12498. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12499. isMerge = true;
  12500. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  12501. a.TransferDetailID AS DetailID,
  12502. '' AS Type,
  12503. a.Sequence AS TransSequence,
  12504. a.TransferQuantity AS IssueQuantity,
  12505. a.ToWarehouseCode,";
  12506. tableNameMerge = @"ICSTransfer a
  12507. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12508. #region SLQ
  12509. sql = @"SELECT a.ID,
  12510. {0}
  12511. convert(varchar(100),'') AS LocationCode,
  12512. convert(varchar(100),'') AS LotNo,
  12513. 0 AS LocationQty,
  12514. 0 AS isMatched,
  12515. a.InvCode,
  12516. inv.InvName,
  12517. inv.InvStd,
  12518. a.Quantity,
  12519. inv.InvUnit,
  12520. a.Amount,
  12521. a.FromWarehouseCode AS WHCode,
  12522. inv.AmountUnit,
  12523. wh.WarehouseName AS WHName,
  12524. a.ExtensionID,
  12525. ext.ProjectCode,
  12526. 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,
  12527. ext.Version,
  12528. ext.Brand,
  12529. ext.cFree1,
  12530. ext.cFree2,
  12531. ext.cFree3,
  12532. ext.cFree4,
  12533. ext.cFree5,
  12534. ext.cFree6,
  12535. ext.cFree7,
  12536. ext.cFree8,
  12537. ext.cFree9,
  12538. ext.cFree10,
  12539. a.MUSER AS [User],
  12540. a.MTIME AS [MTime]
  12541. FROM {1}
  12542. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  12543. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  12544. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  12545. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  12546. WHERE {2} ";
  12547. #endregion
  12548. columns = @"a.TransferNO AS TransCode,
  12549. a.TransferDetailID AS DetailID,
  12550. '' AS Type,
  12551. a.Sequence AS TransSequence,
  12552. a.TransferQuantity AS IssueQuantity,
  12553. a.ToWarehouseCode,";
  12554. tableName = @"ICSTransfer a ";
  12555. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' ";
  12556. }
  12557. #endregion
  12558. #region 调拨申请单(领料)
  12559. else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
  12560. {
  12561. isMerge = true;
  12562. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  12563. a.TransferDetailID AS DetailID,
  12564. '' AS Type,
  12565. a.Sequence AS TransSequence,
  12566. a.TransferQuantity AS IssueQuantity,
  12567. a.ToWarehouseCode,";
  12568. tableNameMerge = @"ICSTransferApplication a
  12569. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12570. #region SLQ
  12571. sql = @"SELECT a.ID,
  12572. {0}
  12573. convert(varchar(100),'') AS LocationCode,
  12574. convert(varchar(100),'') AS LotNo,
  12575. 0 AS LocationQty,
  12576. 0 AS isMatched,
  12577. a.InvCode,
  12578. inv.InvName,
  12579. inv.InvStd,
  12580. a.Quantity,
  12581. inv.InvUnit,
  12582. a.Amount,
  12583. a.FromWarehouseCode AS WHCode,
  12584. inv.AmountUnit,
  12585. wh.WarehouseName AS WHName,
  12586. a.ExtensionID,
  12587. ext.ProjectCode,
  12588. 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,
  12589. ext.Version,
  12590. ext.Brand,
  12591. ext.cFree1,
  12592. ext.cFree2,
  12593. ext.cFree3,
  12594. ext.cFree4,
  12595. ext.cFree5,
  12596. ext.cFree6,
  12597. ext.cFree7,
  12598. ext.cFree8,
  12599. ext.cFree9,
  12600. ext.cFree10,
  12601. a.MUSER AS [User],
  12602. a.MTIME AS [MTime]
  12603. FROM {1}
  12604. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  12605. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  12606. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  12607. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  12608. WHERE {2} ";
  12609. #endregion
  12610. columns = @"a.TransferNO AS TransCode,
  12611. a.TransferDetailID AS DetailID,
  12612. '' AS Type,
  12613. a.Sequence AS TransSequence,
  12614. a.TransferQuantity AS IssueQuantity,
  12615. a.ToWarehouseCode,";
  12616. tableName = @"ICSTransferApplication a ";
  12617. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' ";
  12618. }
  12619. #endregion
  12620. #region 调拨(合并发料)
  12621. else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
  12622. {
  12623. }
  12624. #endregion
  12625. #region 两步调出(合并发料)
  12626. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  12627. {
  12628. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode010' and enable = '1'";
  12629. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12630. isMerge = true;
  12631. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  12632. a.OutDetailID AS DetailID,
  12633. '' AS Type,
  12634. a.Sequence AS TransSequence,
  12635. a.OutQuantity AS IssueQuantity,";
  12636. tableNameMerge = @"ICSOtherOut a
  12637. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  12638. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12639. columns = @"a.OutCode AS TransCode,
  12640. a.OutDetailID AS DetailID,
  12641. '' AS Type,
  12642. a.Sequence AS TransSequence,
  12643. a.OutQuantity AS IssueQuantity,";
  12644. tableName = @"ICSOtherOut a
  12645. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  12646. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' ";
  12647. }
  12648. #endregion
  12649. #region 其他出库(合并发料)
  12650. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  12651. {
  12652. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
  12653. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12654. isMerge = true;
  12655. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  12656. a.OutDetailID AS DetailID,
  12657. '' AS Type,
  12658. a.Sequence AS TransSequence,
  12659. a.OutQuantity AS IssueQuantity,";
  12660. tableNameMerge = @"ICSOtherOut a
  12661. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12662. columns = @"a.OutCode AS TransCode,
  12663. a.OutDetailID AS DetailID,
  12664. '' AS Type,
  12665. a.Sequence AS TransSequence,
  12666. a.OutQuantity AS IssueQuantity,";
  12667. tableName = @"ICSOtherOut a ";
  12668. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' ";
  12669. }
  12670. #endregion
  12671. #region 领料申请单发料(合并发料)
  12672. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  12673. {
  12674. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode002' and enable = '1'";
  12675. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12676. isMerge = true;
  12677. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  12678. a.ApplyDetailID AS DetailID,
  12679. a.Type,
  12680. a.Sequence AS TransSequence,
  12681. a.IssueQuantity AS IssueQuantity,";
  12682. tableNameMerge = @"ICSMOApply a
  12683. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12684. columns = @"a.ApplyCode AS TransCode,
  12685. a.ApplyDetailID AS DetailID,
  12686. a.Type,
  12687. a.Sequence AS TransSequence,
  12688. a.IssueQuantity AS IssueQuantity,";
  12689. tableName = @"ICSMOApply a ";
  12690. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' ";
  12691. }
  12692. #endregion
  12693. #region 补料申请单发料(合并发料)
  12694. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  12695. {
  12696. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode012' and enable = '1'";
  12697. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12698. isMerge = true;
  12699. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  12700. a.ApplyDetailID AS DetailID,
  12701. a.Type,
  12702. a.Sequence AS TransSequence,
  12703. a.IssueQuantity AS IssueQuantity,";
  12704. tableNameMerge = @"ICSMOReplenishment a
  12705. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12706. columns = @"a.ReplenishmentCode AS TransCode,
  12707. a.ReplenishmentDetailID AS DetailID,
  12708. a.Type,
  12709. a.Sequence AS TransSequence,
  12710. a.IssueQuantity AS IssueQuantity,";
  12711. tableName = @"ICSMOReplenishment a ";
  12712. where = @" a.ReplenishmentCode='{0}' AND a.WorkPoint='{1}' ";
  12713. }
  12714. #endregion
  12715. #region 委外领料申请单发料(合并发料)
  12716. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  12717. {
  12718. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode005' and enable = '1'";
  12719. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12720. isMerge = true;
  12721. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  12722. a.ApplyDetailID AS DetailID,
  12723. a.Type,
  12724. a.Sequence AS TransSequence,
  12725. a.IssueQuantity AS IssueQuantity,";
  12726. tableNameMerge = @"ICSOApply a
  12727. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12728. columns = @"a.ApplyCode AS TransCode,
  12729. a.ApplyDetailID AS DetailID,
  12730. a.Type,
  12731. a.Sequence AS TransSequence,
  12732. a.IssueQuantity AS IssueQuantity,";
  12733. tableName = @"ICSOApply a ";
  12734. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' ";
  12735. }
  12736. #endregion
  12737. #region 开立材料出库(合并发料)
  12738. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  12739. {
  12740. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode003' and enable = '1'";
  12741. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12742. isMerge = true;
  12743. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  12744. a.IssueDetailID AS DetailID,
  12745. a.Type,
  12746. a.Sequence AS TransSequence,
  12747. a.IssueQuantity AS IssueQuantity,";
  12748. tableNameMerge = @"ICSMOIssue a
  12749. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12750. columns = @"a.IssueCode AS TransCode,
  12751. a.IssueDetailID AS DetailID,
  12752. a.Type,
  12753. a.Sequence AS TransSequence,
  12754. a.IssueQuantity AS IssueQuantity,";
  12755. tableName = @"ICSMOIssue a ";
  12756. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' ";
  12757. }
  12758. #endregion
  12759. #region 开立委外材料出库(合并发料)
  12760. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  12761. {
  12762. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode006' and enable = '1'";
  12763. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12764. isMerge = true;
  12765. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  12766. a.IssueDetailID AS DetailID,
  12767. a.Type,
  12768. a.Sequence AS TransSequence,
  12769. a.IssueQuantity AS IssueQuantity,";
  12770. tableNameMerge = @"ICSOIssue a
  12771. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12772. columns = @"a.IssueCode AS TransCode,
  12773. a.IssueDetailID AS DetailID,
  12774. a.Type,
  12775. a.Sequence AS TransSequence,
  12776. a.IssueQuantity AS IssueQuantity,";
  12777. tableName = @"ICSOIssue a ";
  12778. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' ";
  12779. }
  12780. #endregion
  12781. #region 开立红字入库单
  12782. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  12783. {
  12784. columns = @"a.RCVCode AS TransCode,
  12785. a.RCVDetailID AS DetailID,
  12786. a.Type,
  12787. a.Sequence AS TransSequence,
  12788. a.RCVQuantity AS IssueQuantity,";
  12789. tableName = @"ICSPurchaseReceive a ";
  12790. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  12791. }
  12792. #endregion
  12793. #region 开立委外红字入库单
  12794. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  12795. {
  12796. columns = @"a.RCVCode AS TransCode,
  12797. a.RCVDetailID AS DetailID,
  12798. a.Type,
  12799. a.Sequence AS TransSequence,
  12800. a.RCVQuantity AS IssueQuantity,";
  12801. tableName = @"ICSOutsourcingReceive a ";
  12802. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  12803. }
  12804. #endregion
  12805. #region 借用(合并发料)
  12806. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  12807. {
  12808. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode011' and enable = '1'";
  12809. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  12810. isMerge = true;
  12811. columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
  12812. a.BrrowDetailID AS DetailID,
  12813. '' AS Type,
  12814. a.Sequence AS TransSequence,
  12815. a.BrrowQuantity AS IssueQuantity,";
  12816. tableNameMerge = @"ICSBrrow a
  12817. INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  12818. columns = @"a.BrrowCode AS TransCode,
  12819. a.BrrowDetailID AS DetailID,
  12820. '' AS Type,
  12821. a.Sequence AS TransSequence,
  12822. a.BrrowQuantity AS IssueQuantity,";
  12823. tableName = @"ICSBrrow a ";
  12824. where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' ";
  12825. }
  12826. #endregion
  12827. #region 送货单
  12828. else if (TransType == TransTypeEnum.ASN.GetDescription())
  12829. {
  12830. isDeliveryNotice = true;
  12831. columns = @"asn.ASNCode AS TransCode,
  12832. asn.ID AS DetailID,
  12833. asn.LotNo,
  12834. '' AS Type,
  12835. asn.Sequence AS TransSequence,
  12836. asn.DNQuantity AS IssueQuantity,
  12837. asn.Quantity,
  12838. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  12839. asn.MUSER AS [User],
  12840. asn.MTIME AS [MTime],";
  12841. tableName = @"ICSInventoryLot a
  12842. INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  12843. where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
  12844. }
  12845. #endregion
  12846. #region 委外送货单
  12847. else if (TransType == TransTypeEnum.OASN.GetDescription())
  12848. {
  12849. isDeliveryNotice = true;
  12850. columns = @"asn.OASNCode AS TransCode,
  12851. asn.ID AS DetailID,
  12852. asn.LotNo,
  12853. '' AS Type,
  12854. asn.Sequence AS TransSequence,
  12855. asn.ODNQuantity AS IssueQuantity,
  12856. asn.Quantity,
  12857. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  12858. asn.MUSER AS [User],
  12859. asn.MTIME AS [MTime],";
  12860. tableName = @"ICSInventoryLot a
  12861. INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  12862. where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
  12863. }
  12864. #endregion
  12865. #endregion
  12866. #region 入库
  12867. #region 采购入库
  12868. else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  12869. {
  12870. }
  12871. #endregion
  12872. #region 审核的到货单
  12873. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  12874. {//扫描到货单 带出检验合格条码数量 且不再库存的条码 --东辉扫描到货单入库 cjw
  12875. isDeliveryNotice = true;
  12876. columns = @"DN.DNCode AS TransCode,
  12877. ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  12878. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  12879. a.LotNo,
  12880. '' AS Type,
  12881. DN.Sequence AS TransSequence,
  12882. DN.DNQuantity AS IssueQuantity,
  12883. DN.Quantity,
  12884. DN.MUSER AS [User],
  12885. DN.MTIME AS [MTime],";
  12886. tableName = @"ICSInventoryLot a
  12887. inner join ICSInventoryLotDetail det on a.lotno = det.lotno AND a.WorkPoint=det.WorkPoint
  12888. inner join ICSDeliveryNotice on DN.DNCode= det.TransCode and DN.Sequence = det.TransSequence aND DN.WorkPoint=det.WorkPoint AND DN.DNTYPE =1
  12889. inner join ICSInspection ins on INS.lotno = a.lotno and a.workpoint = ins.workpoint
  12890. LEFT JOIN ICSWareHouseLotInfo lotinfo on a.lotno = lotinfo.lotno AND a.WorkPoint=lotinfo.WorkPoint
  12891. ";
  12892. where = @" DN.DNCode='{0}' AND a.WorkPoint='{1}' and lotinfo.id is null ";
  12893. }
  12894. #endregion
  12895. #region 采购拒收
  12896. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  12897. {
  12898. }
  12899. #endregion
  12900. #region 审核的委外到货单
  12901. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  12902. {
  12903. }
  12904. #endregion
  12905. #region 委外拒收
  12906. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  12907. {
  12908. }
  12909. #endregion
  12910. #region 委外退料
  12911. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  12912. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  12913. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  12914. {
  12915. }
  12916. #endregion
  12917. #region 委外入库
  12918. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  12919. {
  12920. }
  12921. #endregion
  12922. #region 生产退料
  12923. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  12924. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  12925. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  12926. {
  12927. }
  12928. #endregion
  12929. #region 生产入库
  12930. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  12931. {
  12932. }
  12933. #endregion
  12934. #region 开立的生产入库单
  12935. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  12936. {
  12937. }
  12938. #endregion
  12939. #region 返工工单
  12940. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  12941. {
  12942. }
  12943. #endregion
  12944. #region 销售退货
  12945. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  12946. {
  12947. }
  12948. #endregion
  12949. #region 两步调入
  12950. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  12951. {
  12952. columns = @"a.InCode AS TransCode,
  12953. a.InDetailID AS DetailID,
  12954. '' AS Type,
  12955. a.Sequence AS TransSequence,
  12956. a.InQuantity AS IssueQuantity,";
  12957. tableName = @"ICSOtherIn a
  12958. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  12959. where = @" a.InCode='{0}' AND a.WorkPoint='{1}' ";
  12960. }
  12961. #endregion
  12962. #region 销售退货-原条码
  12963. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  12964. {
  12965. columns = @"a.SDNCode AS TransCode,
  12966. a.SDNDetailID AS DetailID,
  12967. a.Type,
  12968. a.Sequence AS TransSequence,
  12969. a.SDNQuantity AS IssueQuantity,";
  12970. tableName = @"ICSSDN a ";
  12971. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  12972. }
  12973. #endregion
  12974. #region 其他入库
  12975. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  12976. {
  12977. }
  12978. #endregion
  12979. #region 拆卸单
  12980. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  12981. {
  12982. columns = @"a.DABDOCCode AS TransCode,
  12983. a.DABDOCDetailID AS DetailID,
  12984. a.DABDOCType AS Type,
  12985. a.Sequence AS TransSequence,
  12986. a.DABDOCQuantity AS IssueQuantity,";
  12987. tableName = @"ICSDisassemblyDoc a";
  12988. where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' ";
  12989. }
  12990. #endregion
  12991. #region 归还
  12992. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  12993. {
  12994. }
  12995. #endregion
  12996. #endregion
  12997. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
  12998. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  12999. #region 判断是否启用匹配库位
  13000. if (flag != null && flag.Rows.Count > 0)
  13001. //if (true)
  13002. {
  13003. sql = @"select * into #maintemp from (" + sql + @")a
  13004. select * into #resulttemp from #maintemp
  13005. truncate table #resulttemp
  13006. 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,
  13007. isnull(ext.Brand,'')as Brand,
  13008. isnull(ext.cFree1,'')as cFree1,
  13009. isnull(ext.cFree2,'') cFree2,
  13010. isnull(ext.cFree3,'') cFree3,
  13011. isnull(ext.cFree4,'') cFree4,
  13012. isnull(ext.cFree5,'') cFree5,
  13013. isnull(ext.cFree6,'') cFree6,
  13014. isnull(ext.cFree7,'') cFree7,
  13015. isnull(ext.cFree8,'') cFree8,
  13016. isnull(ext.cFree9,'') cFree9,
  13017. isnull(ext.cFree10,'') cFree10,ISNULL(ext.BatchCode, '') BatchCode into #barcodetemp
  13018. from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  13019. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  13020. LEFT JOIN
  13021. (select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp
  13022. group by invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE) b on a.invcode = b.invcode
  13023. where (a.warehousecode = b.whcode or ISNULL(b.whcode,'')='') and a.Quantity-a.lockQuantity>0 and
  13024. isnull(ext.ProjectCode,'') = b.ProjectCode and isnull(ext.Version,'')=b.Version and
  13025. isnull(ext.Brand,'') =b.Brand and
  13026. isnull(ext.cFree1,'')=b.cFree1 and
  13027. isnull(ext.cFree2,'')=b.cFree2 and
  13028. isnull(ext.cFree3,'')=b.cFree3 and
  13029. isnull(ext.cFree4,'')=b.cFree4 and
  13030. isnull(ext.cFree5,'')=b.cFree5 and
  13031. isnull(ext.cFree6,'')=b.cFree6 and
  13032. isnull(ext.cFree7,'')=b.cFree7 and
  13033. isnull(ext.cFree8,'')=b.cFree8 and
  13034. isnull(ext.cFree9,'')=b.cFree9 and
  13035. isnull(ext.cFree10,'')=b.cFree10 and
  13036. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =ext.BatchCode) or isnull(b.BatchCode,'') ='')
  13037. BEGIN
  13038. DECLARE @transSequence VARCHAR(50);--
  13039. DECLARE @qty decimal(18, 4);--
  13040. DECLARE @needqty decimal(18, 4);--
  13041. DECLARE @lotno VARCHAR(50);--
  13042. DECLARE @locationcode VARCHAR(50);--
  13043. DECLARE @WHCode VARCHAR(50);--
  13044. DECLARE @invcode VARCHAR(50);--
  13045. DECLARE @issueQuantity decimal(18, 4);
  13046. DECLARE tempCursor CURSOR FOR (select transSequence from #maintemp); --tempCursor
  13047. OPEN tempCursor; --
  13048. FETCH NEXT FROM tempCursor INTO @transSequence; --
  13049. WHILE @@fetch_status=0
  13050. BEGIN
  13051. select @needqty=Quantity,@issueQuantity=issueQuantity from #maintemp where transSequence = @transSequence
  13052. PRINT @transSequence
  13053. WHILE @needqty>0
  13054. BEGIN
  13055. 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
  13056. 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
  13057. and ((isnull(b.ProjectCode,'')<>'' and b.ProjectCode = a.ProjectCode) or isnull(b.ProjectCode,'') ='') and
  13058. ((isnull(b.Version,'')<>'' and b.Version = a.Version) or isnull(b.Version,'') ='') and
  13059. ((isnull(b.Brand,'')<>'' and b.Brand = a.Brand )or isnull(b.Brand,'') ='') and
  13060. ((isnull(b.cFree1,'')<>'' and b.cFree1 =a.cFree1) or isnull(b.cFree1,'') ='') and
  13061. ((isnull(b.cFree2,'')<>'' and b.cFree2 =a.cFree2 )or isnull(b.cFree2,'') ='') and
  13062. ((isnull(b.cFree3,'')<>'' and b.cFree3 =a.cFree3 )or isnull(b.cFree3,'') ='') and
  13063. ((isnull(b.cFree4,'')<>'' and b.cFree4 =a.cFree4 )or isnull(b.cFree4,'') ='') and
  13064. ((isnull(b.cFree5,'')<>'' and b.cFree5 =a.cFree5) or isnull(b.cFree5,'') ='') and
  13065. ((isnull(b.cFree6,'')<>'' and b.cFree6 =a.cFree6 )or isnull(b.cFree6,'') ='') and
  13066. ((isnull(b.cFree7,'')<>'' and b.cFree7 =a.cFree7) or isnull(b.cFree7,'') ='') and
  13067. ((isnull(b.cFree8,'')<>'' and b.cFree8 =a.cFree8) or isnull(b.cFree8,'') ='') and
  13068. ((isnull(b.cFree9,'')<>'' and b.cFree9 =a.cFree9) or isnull(b.cFree9,'') ='') and
  13069. ((isnull(b.cFree10,'')<>'' and b.cFree10 =a.cFree10) or isnull(b.cFree10,'') ='') and
  13070. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =a.BatchCode) or isnull(b.BatchCode,'') ='')ORDER BY mtime,locationcode
  13071. IF(@needqty-@issueQuantity-@qty>=0 and ISNULL(@lotno, '')<>'')
  13072. BEGIN
  13073. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  13074. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotNo,
  13075. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  13076. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  13077. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),@qty,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  13078. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  13079. delete from #barcodetemp where lotno = @lotno
  13080. SET @needqty=@needqty-@qty
  13081. END
  13082. ELSE if(@needqty-@issueQuantity-@qty<0 and ISNULL(@lotno, '')<>''and @needqty-@issueQuantity>0)
  13083. BEGIN
  13084. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  13085. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  13086. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  13087. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  13088. 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, ''),
  13089. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  13090. update #barcodetemp set quantity = @qty-@needqty+-@issueQuantity where lotno = @lotno
  13091. SET @needqty=@needqty-@issueQuantity-@qty
  13092. END
  13093. ELSE
  13094. BEGIN
  13095. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  13096. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  13097. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  13098. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  13099. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),0 ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  13100. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  13101. SET @needqty=0
  13102. END
  13103. END
  13104. FETCH NEXT FROM tempCursor INTO @transSequence;
  13105. END
  13106. CLOSE tempCursor
  13107. DEALLOCATE tempCursor
  13108. END
  13109. select id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  13110. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,sum(LocationQty)as LocationQty,isMatched,AmountUnit,--lotno,
  13111. 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,
  13112. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,isMatched,AmountUnit,--lotno,
  13113. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ORDER BY locationcode ASC ,InvCode ASC
  13114. DROP table #maintemp
  13115. DROP table #resulttemp
  13116. DROP table #barcodetemp";
  13117. }
  13118. #endregion
  13119. if (isDeliveryNotice)//送货、到货、含委外
  13120. {
  13121. #region SLQ
  13122. sql = sqlCheck + @"SELECT a.ID,
  13123. {0}
  13124. a.InvCode,
  13125. inv.InvName,
  13126. inv.InvStd,
  13127. inv.InvUnit,
  13128. '' AS WHCode,
  13129. inv.AmountUnit,
  13130. '' AS WHName,
  13131. a.ExtensionID,
  13132. ext.ProjectCode,
  13133. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  13134. ext.Version,
  13135. ext.Brand,
  13136. ext.cFree1,
  13137. ext.cFree2,
  13138. ext.cFree3,
  13139. ext.cFree4,
  13140. ext.cFree5,
  13141. ext.cFree6,
  13142. ext.cFree7,
  13143. ext.cFree8,
  13144. ext.cFree9,
  13145. ext.cFree10
  13146. FROM {1}
  13147. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  13148. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  13149. WHERE {2} ";
  13150. #endregion
  13151. }
  13152. else if (isMerge)//合并发料
  13153. {
  13154. #region SLQ
  13155. string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='" + JsonData.TransCode + "' AND WorkPoint='" + JsonData.WorkPoint + "'";
  13156. DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
  13157. if (sign != null && sign.Rows.Count > 0)
  13158. {
  13159. string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
  13160. sql = string.Format(sql, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, excessQtySql);
  13161. }
  13162. else
  13163. {
  13164. sql = @" BEGIN
  13165. IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
  13166. BEGIN
  13167. RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
  13168. RETURN
  13169. END
  13170. " + sqlCheck + sql + @"
  13171. END";
  13172. }
  13173. #endregion
  13174. }
  13175. else
  13176. {
  13177. sql = sqlCheck + sql;
  13178. }
  13179. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint);
  13180. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode, excessQtySql);
  13181. sqls = string.Format(sqls, JsonData.TransCode, JsonData.WorkPoint);
  13182. Picksql = string.Format(Picksql, sqls, JsonData.WorkPoint);
  13183. //DataTable table2 = DBHelper.SQlReturnData(Picksql, cmd);
  13184. //return table2;
  13185. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  13186. return table;
  13187. }
  13188. catch (Exception ex)
  13189. {
  13190. log.Error(ex.Message);
  13191. throw new Exception(ex.Message);
  13192. }
  13193. finally
  13194. {
  13195. if (conn.State == ConnectionState.Open)
  13196. {
  13197. conn.Close();
  13198. }
  13199. conn.Dispose();
  13200. }
  13201. }
  13202. }
  13203. #endregion
  13204. #region 源头单据信息(奥美专用)
  13205. /// <summary>
  13206. /// 源头单据信息(奥美专用)
  13207. /// </summary>
  13208. /// <param name="JsonData"></param>
  13209. /// <returns></returns>
  13210. public static DataTable AMTransInformationGet(WMSSourceDocumentModel JsonData)
  13211. {
  13212. var language = LanguageHelper.GetName("WMSAPIInfo");
  13213. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  13214. {
  13215. conn.Open();
  13216. SqlCommand cmd = new SqlCommand();
  13217. cmd.Connection = conn;
  13218. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  13219. try
  13220. {
  13221. if (string.IsNullOrEmpty(JsonData.TransCode))
  13222. {
  13223. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  13224. }
  13225. else if (string.IsNullOrEmpty(JsonData.TransType))
  13226. {
  13227. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  13228. }
  13229. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  13230. {
  13231. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  13232. }
  13233. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  13234. {
  13235. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  13236. }
  13237. string TransType = JsonData.TransType;
  13238. #region SLQ
  13239. string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  13240. BEGIN
  13241. RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  13242. RETURN
  13243. END
  13244. ";
  13245. string sql = @"SELECT a.ID,
  13246. {0}
  13247. convert(varchar(100),'') AS LocationCode,
  13248. convert(varchar(100),'') AS LotNo,
  13249. convert(varchar(10),'') AS ToWarehouseCode,
  13250. 0 AS LocationQty,
  13251. 0 AS isMatched,
  13252. a.InvCode,
  13253. inv.InvName,
  13254. inv.InvStd,
  13255. a.Quantity,
  13256. inv.InvUnit,
  13257. a.Amount,
  13258. a.WHCode,
  13259. inv.AmountUnit,
  13260. wh.WarehouseName AS WHName,
  13261. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  13262. a.ExtensionID,
  13263. 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,
  13264. ISNULL(ext.Version, '') AS Version,
  13265. ISNULL(ext.Brand, '') AS Brand,
  13266. ISNULL(ext.cFree1, '') AS cFree1,
  13267. ISNULL(ext.cFree2, '') AS cFree2,
  13268. ISNULL(ext.cFree3, '') AS cFree3,
  13269. ISNULL(ext.cFree4, '') AS cFree4,
  13270. ISNULL(ext.cFree5, '') AS cFree5,
  13271. ISNULL(ext.cFree6, '') AS cFree6,
  13272. ISNULL(ext.cFree7, '') AS cFree7,
  13273. ISNULL(ext.cFree8, '') AS cFree8,
  13274. ISNULL(ext.cFree9, '') AS cFree9,
  13275. ISNULL(ext.cFree10, '') AS cFree10,
  13276. a.MUSER AS [User],
  13277. a.MTIME AS [MTime]
  13278. {4}
  13279. FROM {1}
  13280. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  13281. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  13282. LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  13283. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  13284. WHERE {2} ";
  13285. string Picksql = @"SELECT row_number() over (order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  13286. c.Code,
  13287. c.InvCode,
  13288. c.InvName,
  13289. c.InvStd,
  13290. c.InvUnit,
  13291. FLOOR(c.iQuantity) AS iQuantity,
  13292. d.WarehouseCode,
  13293. d.LocationCode,
  13294. d.LotNO,
  13295. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  13296. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  13297. FLOOR(f.QTYTotal) QTYTotal INTO #temp
  13298. FROM
  13299. ({0}) c
  13300. 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
  13301. left join ICSInventoryLot m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint and c.ExtensionID=m.ExtensionID
  13302. 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
  13303. DECLARE @ItemCode VARCHAR(50),
  13304. @QTY DECIMAL(18,3),
  13305. @ItemCodeCurrent VARCHAR(50),
  13306. @QTYCurrent DECIMAL(18,3),
  13307. @iQuantityCurrent DECIMAL(18,3),
  13308. @CanDelete BIT,
  13309. @Row INT,
  13310. @rowCurrent INT
  13311. SET @Row = @@rowcount
  13312. SET @rowCurrent=1
  13313. SET @CanDelete=0
  13314. SET @ItemCode=''
  13315. WHILE @rowCurrent<=@Row
  13316. BEGIN
  13317. SELECT @ItemCodeCurrent=InvCode,@QTYCurrent=QTY,@iQuantityCurrent=iQuantity FROM #temp WHERE rowNo=@rowCurrent
  13318. PRINT(@rowCurrent)
  13319. IF @ItemCode<>@ItemCodeCurrent
  13320. BEGIN
  13321. SET @ItemCode=@ItemCodeCurrent
  13322. SET @QTY=0
  13323. SET @CanDelete=0
  13324. END
  13325. IF @CanDelete=1
  13326. BEGIN
  13327. DELETE FROM #temp WHERE rowNo=@rowCurrent
  13328. SET @rowCurrent += 1
  13329. CONTINUE
  13330. END
  13331. SET @QTY += @QTYCurrent
  13332. IF @QTY>=@iQuantityCurrent
  13333. BEGIN
  13334. SET @CanDelete=1
  13335. END
  13336. SET @rowCurrent += 1
  13337. END
  13338. SELECT * FROM #temp
  13339. DROP TABLE #temp
  13340. ";
  13341. #endregion
  13342. bool isDeliveryNotice = false; //送货、到货、含委外
  13343. string columns = string.Empty; //查询源头单据表的特殊列名
  13344. string tableName = string.Empty; //查询源头单据表名
  13345. string where = string.Empty; //查询源头单据的过滤条件
  13346. bool isMerge = false; //合并发料
  13347. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  13348. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  13349. string sqls = string.Empty;
  13350. string sqlCheckSign = "";
  13351. DataTable flag = null;
  13352. #region 检料表信息
  13353. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  13354. {
  13355. enableCode = "Over001";
  13356. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, b.Sequence+'~'+a.Sequence, b.MOCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  13357. #region 工单备料sql
  13358. sqls = @" SELECT
  13359. c.MOCode as Code,
  13360. a.InvCode,
  13361. b.InvName,
  13362. b.InvStd,
  13363. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13364. a.WhCode,
  13365. b.InvUnit,
  13366. a.ExtensionID
  13367. FROM
  13368. ICSMOPick a
  13369. inner join ICSMO c on a.MODetailID=c.MODetailID and a.WorkPoint=c.WorkPoint
  13370. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13371. WHERE c.MOCode in ({0}) AND a.WorkPoint = '{1}'
  13372. GROUP BY c.MOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  13373. #endregion
  13374. }
  13375. if (TransType == TransTypeEnum.MOApply.GetDescription())
  13376. {
  13377. enableCode = "Over002";
  13378. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Sequence, a.ApplyCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  13379. #region 工单领料SQL
  13380. sqls = @" select
  13381. a.ApplyCode as Code,
  13382. a.InvCode,
  13383. b.InvName,
  13384. b.InvStd,
  13385. b.InvUnit,
  13386. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13387. a.WhCode,
  13388. a.ExtensionID
  13389. FROM
  13390. ICSMOApply a
  13391. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13392. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  13393. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  13394. #endregion
  13395. }
  13396. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  13397. {
  13398. //enableCode = "Over003";
  13399. excessQtySql = "";
  13400. #region 工单材料出库SQL
  13401. sqls = @" select
  13402. a.IssueCode as Code,
  13403. a.InvCode,
  13404. b.InvName,
  13405. b.InvStd,
  13406. b.InvUnit,
  13407. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13408. a.WhCode,
  13409. a.ExtensionID
  13410. FROM
  13411. ICSMOIssue a
  13412. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13413. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  13414. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  13415. #endregion
  13416. }
  13417. if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  13418. {
  13419. enableCode = "Over004";
  13420. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Sequence, b.OOCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  13421. #region 委外备料SQL
  13422. sqls = @" select
  13423. c.OOCode as Code,
  13424. a.InvCode,
  13425. b.InvName,
  13426. b.InvStd,
  13427. b.InvUnit,
  13428. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13429. a.WhCode,
  13430. a.ExtensionID
  13431. FROM
  13432. ICSOOPick a
  13433. left join ICSOutsourcingOrder c on a.OODetailID=c.OODetailID and a.WorkPoint=c.WorkPoint
  13434. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13435. WHERE c.OOCode in ({0}) AND a.WorkPoint = '{1}'
  13436. GROUP BY c.OOCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode, a.ExtensionID";
  13437. #endregion
  13438. }
  13439. if (TransType == TransTypeEnum.OOApply.GetDescription())
  13440. {
  13441. enableCode = "Over005";
  13442. excessQtySql = ",(dbo.GetExcessQty(a.InvCode, a.Sequence, a.ApplyCode, a.WorkPoint,'" + enableCode + "')) AS excessQty";
  13443. #region 委外领料SQL
  13444. sqls = @" select
  13445. a.ApplyCode as Code,
  13446. a.InvCode,
  13447. b.InvName,
  13448. b.InvStd,
  13449. b.InvUnit,
  13450. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13451. a.WhCode,
  13452. a.ExtensionID
  13453. FROM
  13454. ICSOApply a
  13455. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13456. WHERE a.ApplyCode in ({0}) AND a.WorkPoint = '{1}'
  13457. GROUP BY a.ApplyCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  13458. #endregion
  13459. }
  13460. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  13461. {
  13462. //enableCode = "Over006";
  13463. excessQtySql = "";
  13464. #region 委外材料出库SQL
  13465. sqls = @" select
  13466. a.IssueCode as Code,
  13467. a.InvCode,
  13468. b.InvName,
  13469. b.InvStd,
  13470. b.InvUnit,
  13471. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13472. a.WhCode,
  13473. a.ExtensionID
  13474. FROM
  13475. ICSOIssue a
  13476. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13477. WHERE a.IssueCode in ({0}) AND a.WorkPoint = '{1}'
  13478. GROUP BY a.IssueCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  13479. #endregion
  13480. }
  13481. if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  13482. {
  13483. enableCode = "";
  13484. excessQtySql = "";
  13485. #region 销售发货SQL
  13486. sqls = @" select
  13487. a.SDNCode as Code,
  13488. a.InvCode,
  13489. b.InvName,
  13490. b.InvStd,
  13491. b.InvUnit,
  13492. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13493. a.WhCode,
  13494. a.ExtensionID
  13495. FROM
  13496. ICSSDN a
  13497. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13498. WHERE a.SDNCode in ({0}) AND a.WorkPoint = '{1}'
  13499. GROUP BY a.SDNCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  13500. #endregion
  13501. }
  13502. if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  13503. {
  13504. enableCode = "";
  13505. excessQtySql = "";
  13506. #region 其它出库SQL
  13507. sqls = @" select
  13508. a.OutCode as Code,
  13509. a.InvCode,
  13510. b.InvName,
  13511. b.InvStd,
  13512. b.InvUnit,
  13513. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13514. a.WhCode,
  13515. a.ExtensionID
  13516. FROM
  13517. ICSOtherOut a
  13518. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13519. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  13520. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  13521. #endregion
  13522. }
  13523. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  13524. {
  13525. enableCode = "";
  13526. excessQtySql = "";
  13527. #region 借用SQL
  13528. sqls = @"select
  13529. a.BrrowCode as Code,
  13530. a.InvCode,
  13531. b.InvName,
  13532. b.InvStd,
  13533. b.InvUnit,
  13534. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13535. a.WhCode,
  13536. a.ExtensionID
  13537. FROM
  13538. ICSBrrow a
  13539. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13540. WHERE a.BrrowCode in ({0}) AND a.WorkPoint = '{1}'
  13541. GROUP BY a.BrrowCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID";
  13542. #endregion
  13543. }
  13544. if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  13545. {
  13546. enableCode = "";
  13547. excessQtySql = "";
  13548. #region 物料调拨
  13549. sqls = @" select
  13550. a.TransferNO as Code,
  13551. a.InvCode,
  13552. b.InvName,
  13553. b.InvStd,
  13554. b.InvUnit,
  13555. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13556. a.FromWarehouseCode as WhCode,
  13557. a.ExtensionID
  13558. FROM
  13559. ICSTransfer a
  13560. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13561. WHERE a.TransferNO in ({0}) AND a.WorkPoint = '{1}'
  13562. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID";
  13563. #endregion
  13564. }
  13565. if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  13566. {
  13567. enableCode = "";
  13568. excessQtySql = "";
  13569. #region 两步调出
  13570. sqls = @"select
  13571. a.OutCode as Code,
  13572. a.InvCode,
  13573. b.InvName,
  13574. b.InvStd,
  13575. b.InvUnit,
  13576. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  13577. a.WHCode ,
  13578. a.ExtensionID
  13579. from ICSOtherOut a
  13580. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  13581. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  13582. WHERE a.OutCode in ({0}) AND a.WorkPoint = '{1}'
  13583. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WHCode,a.ExtensionID";
  13584. #endregion
  13585. }
  13586. #endregion
  13587. #region 出库
  13588. #region 采购退货
  13589. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  13590. {
  13591. isDeliveryNotice = true;
  13592. columns = @"a.DNCode AS TransCode,
  13593. a.DNDetailID AS DetailID,
  13594. a.DNType AS Type,
  13595. a.Sequence AS TransSequence,
  13596. a.RCVQuantity AS IssueQuantity,
  13597. a.Quantity,
  13598. a.Amount,
  13599. a.MUSER AS [User],
  13600. a.MTIME AS [MTime],";
  13601. tableName = @"ICSDeliveryNotice a ";
  13602. where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' AND a.Status<>'3'";
  13603. }
  13604. #endregion
  13605. //#region 工单关联
  13606. //else if (TransType == TransTypeEnum.ICSMOReceive.GetDescription())
  13607. //{
  13608. // isDeliveryNotice = true;
  13609. // columns = @"a.MOCode AS TransCode,
  13610. // a.Sequence AS TransSequence,";
  13611. // tableName = @"ICSMO a ";
  13612. // where = @" a.MOCode='{0}' AND a.WorkPoint='{1}' and a.ERPStatus<>'3'";
  13613. //}
  13614. //#endregion
  13615. #region 委外发料(合并发料)
  13616. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  13617. {
  13618. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode004' and enable = '1'";
  13619. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  13620. isMerge = true;
  13621. columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
  13622. a.PickID AS DetailID,
  13623. a.SupplyType AS Type,
  13624. b.Sequence+'~'+a.Sequence AS TransSequence,
  13625. a.IssueQuantity AS IssueQuantity,";
  13626. tableNameMerge = @"ICSOOPick a
  13627. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  13628. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  13629. columns = @"b.OOCode AS TransCode,
  13630. a.PickID AS DetailID,
  13631. a.SupplyType AS Type,
  13632. b.Sequence+'~'+a.Sequence AS TransSequence,
  13633. ISNULL((select Sum(log.Quantity) from ICSOOPick a
  13634. INNER JOIN ICSOutsourcingOrder m ON a.OODetailID=m.OODetailID AND a.WorkPoint=m.WorkPoint
  13635. INNER JOIN ICSWareHouseLotInfoLog log on m.oocode=log.transcode and m.Sequence=log.TransSequence
  13636. where m.oocode=b.oocode and m.Sequence=b.Sequence and log.TransType='15'),0) AS IssueQuantity,";
  13637. tableName = @"ICSOOPick a
  13638. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  13639. where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3'";
  13640. }
  13641. #endregion
  13642. #region 委外退货
  13643. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  13644. {
  13645. isDeliveryNotice = true;
  13646. columns = @"a.ODNCode AS TransCode,
  13647. a.ODNDetailID AS DetailID,
  13648. a.ODNType AS Type,
  13649. a.Sequence AS TransSequence,
  13650. a.RCVQuantity AS IssueQuantity,
  13651. a.Quantity,
  13652. a.Amount,
  13653. a.MUSER AS [User],
  13654. a.MTIME AS [MTime],";
  13655. tableName = @"ICSODeliveryNotice a ";
  13656. where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' AND a.Status<>'3'";
  13657. }
  13658. #endregion
  13659. #region 生产发料(合并发料)
  13660. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  13661. {
  13662. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode001' and enable = '1'";
  13663. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  13664. isMerge = true;
  13665. columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  13666. a.PickID AS DetailID,
  13667. a.SupplyType AS Type,
  13668. b.Sequence+'~'+a.Sequence AS TransSequence,
  13669. a.IssueQuantity AS IssueQuantity,";
  13670. tableNameMerge = @"ICSMOPick a
  13671. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  13672. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint
  13673. INNER JOIN ICSDepartment c on b.DepCode=c.DepCode and b.WorkPoint=c.WorkPoint";
  13674. columns = @"b.MOCode AS TransCode,
  13675. a.PickID AS DetailID,
  13676. a.SupplyType AS Type,
  13677. b.Sequence+'~'+a.Sequence AS TransSequence,
  13678. ISNULL((select Sum(log.Quantity) from ICSMOPick a
  13679. INNER JOIN ICSMO m ON a.MODetailID=m.MODetailID AND a.WorkPoint=m.WorkPoint
  13680. INNER JOIN ICSWareHouseLotInfoLog log on m.mocode=log.transcode and m.Sequence=log.TransSequence
  13681. where m.mocode=b.mocode and m.Sequence=b.Sequence and log.TransType='15'),0) AS IssueQuantity,";
  13682. tableName = @"ICSMOPick a
  13683. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  13684. INNER JOIN ICSDepartment dd on b.DepCode=dd.DepCode and b.WorkPoint=dd.WorkPoint";
  13685. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' AND dd.DepName =(SELECT SUBSTRING(F_RealName, 1, 2) FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}')";
  13686. }
  13687. #endregion
  13688. #region 销售出库(合并发料)
  13689. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  13690. {
  13691. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode007' and enable = '1'";
  13692. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  13693. isMerge = true;
  13694. columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
  13695. a.SDNDetailID AS DetailID,
  13696. a.SOCode,
  13697. a.Type,
  13698. a.Sequence AS TransSequence,
  13699. a.SDNQuantity AS IssueQuantity,";
  13700. tableNameMerge = @"ICSSDN a
  13701. INNER JOIN ICSMOPickMerge mer ON a.SDNDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  13702. columns = @"a.SDNCode AS TransCode,
  13703. a.SDNDetailID AS DetailID,
  13704. a.SOCode,
  13705. a.Type,
  13706. a.Sequence AS TransSequence,
  13707. ISNULL((select Sum(b.Quantity) from ICSSDN sdn
  13708. INNER JOIN ICSWareHouseLotInfoLog b on sdn.sdncode=b.transcode and sdn.Sequence=b.TransSequence
  13709. where sdn.sdncode=a.sdncode and sdn.Sequence=a.Sequence and b.TransType='15'),0) AS IssueQuantity,";
  13710. tableName = @"ICSSDN a ";
  13711. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3'";
  13712. }
  13713. #endregion
  13714. #region 盘点
  13715. else if (TransType == TransTypeEnum.Check.GetDescription())
  13716. {
  13717. #region SLQ
  13718. sql = @"SELECT a.ID,
  13719. {0}
  13720. a.Quantity,
  13721. a.SelectLevel AS LocationCode,
  13722. a.Amount,
  13723. a.MUSER AS [User],
  13724. a.MTIME AS [MTime]
  13725. FROM {1}
  13726. WHERE {2} ";
  13727. #endregion
  13728. columns = @"a.CheckCode AS TransCode,
  13729. a.ID,
  13730. '' AS Type,";
  13731. tableName = @"ICSCheck a ";
  13732. where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' ";
  13733. }
  13734. #endregion
  13735. #region 一步调拨(合并发料)
  13736. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  13737. {
  13738. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode009' and enable = '1'";
  13739. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  13740. isMerge = true;
  13741. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  13742. a.TransferDetailID AS DetailID,
  13743. '' AS Type,
  13744. a.Sequence AS TransSequence,
  13745. a.TransferQuantity AS IssueQuantity,
  13746. a.ToWarehouseCode,";
  13747. tableNameMerge = @"ICSTransfer a
  13748. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  13749. #region SLQ
  13750. sql = @"SELECT a.ID,
  13751. {0}
  13752. convert(varchar(100),'') AS LocationCode,
  13753. convert(varchar(100),'') AS LotNo,
  13754. 0 AS LocationQty,
  13755. 0 AS isMatched,
  13756. a.InvCode,
  13757. inv.InvName,
  13758. inv.InvStd,
  13759. a.Quantity,
  13760. inv.InvUnit,
  13761. a.Amount,
  13762. a.FromWarehouseCode AS WHCode,
  13763. inv.AmountUnit,
  13764. wh.WarehouseName AS WHName,
  13765. a.ExtensionID,
  13766. ext.ProjectCode,
  13767. 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,
  13768. ext.Version,
  13769. ext.Brand,
  13770. ext.cFree1,
  13771. ext.cFree2,
  13772. ext.cFree3,
  13773. ext.cFree4,
  13774. ext.cFree5,
  13775. ext.cFree6,
  13776. ext.cFree7,
  13777. ext.cFree8,
  13778. ext.cFree9,
  13779. ext.cFree10,
  13780. a.MUSER AS [User],
  13781. a.MTIME AS [MTime]
  13782. FROM {1}
  13783. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  13784. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  13785. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  13786. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  13787. WHERE {2} ";
  13788. #endregion
  13789. columns = @"a.TransferNO AS TransCode,
  13790. a.TransferDetailID AS DetailID,
  13791. '' AS Type,
  13792. a.Sequence AS TransSequence,
  13793. a.TransferQuantity AS IssueQuantity,
  13794. a.ToWarehouseCode,";
  13795. tableName = @"ICSTransfer a ";
  13796. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3'";
  13797. }
  13798. #endregion
  13799. #region 调拨申请单(领料)
  13800. else if (TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription())
  13801. {
  13802. isMerge = true;
  13803. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  13804. a.TransferDetailID AS DetailID,
  13805. '' AS Type,
  13806. a.Sequence AS TransSequence,
  13807. a.TransferQuantity AS IssueQuantity,
  13808. a.ToWarehouseCode,";
  13809. tableNameMerge = @"ICSTransferApplication a
  13810. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  13811. #region SLQ
  13812. sql = @"SELECT a.ID,
  13813. {0}
  13814. convert(varchar(100),'') AS LocationCode,
  13815. convert(varchar(100),'') AS LotNo,
  13816. 0 AS LocationQty,
  13817. 0 AS isMatched,
  13818. a.InvCode,
  13819. inv.InvName,
  13820. inv.InvStd,
  13821. a.Quantity,
  13822. inv.InvUnit,
  13823. a.Amount,
  13824. a.FromWarehouseCode AS WHCode,
  13825. inv.AmountUnit,
  13826. wh.WarehouseName AS WHName,
  13827. a.ExtensionID,
  13828. ext.ProjectCode,
  13829. 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,
  13830. ext.Version,
  13831. ext.Brand,
  13832. ext.cFree1,
  13833. ext.cFree2,
  13834. ext.cFree3,
  13835. ext.cFree4,
  13836. ext.cFree5,
  13837. ext.cFree6,
  13838. ext.cFree7,
  13839. ext.cFree8,
  13840. ext.cFree9,
  13841. ext.cFree10,
  13842. a.MUSER AS [User],
  13843. a.MTIME AS [MTime]
  13844. FROM {1}
  13845. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  13846. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  13847. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  13848. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  13849. WHERE {2} ";
  13850. #endregion
  13851. columns = @"a.TransferNO AS TransCode,
  13852. a.TransferDetailID AS DetailID,
  13853. '' AS Type,
  13854. a.Sequence AS TransSequence,
  13855. a.TransferQuantity AS IssueQuantity,
  13856. a.ToWarehouseCode,";
  13857. tableName = @"ICSTransferApplication a ";
  13858. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' AND a.Status<>'3'";
  13859. }
  13860. #endregion
  13861. #region 调拨(合并发料)
  13862. else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
  13863. {
  13864. }
  13865. #endregion
  13866. #region 两步调出(合并发料)
  13867. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  13868. {
  13869. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode010' and enable = '1'";
  13870. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  13871. isMerge = true;
  13872. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  13873. a.OutDetailID AS DetailID,
  13874. '' AS Type,
  13875. a.Sequence AS TransSequence,
  13876. a.OutQuantity AS IssueQuantity,";
  13877. tableNameMerge = @"ICSOtherOut a
  13878. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  13879. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  13880. columns = @"a.OutCode AS TransCode,
  13881. a.OutDetailID AS DetailID,
  13882. '' AS Type,
  13883. a.Sequence AS TransSequence,
  13884. a.OutQuantity AS IssueQuantity,";
  13885. tableName = @"ICSOtherOut a
  13886. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  13887. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  13888. }
  13889. #endregion
  13890. #region 其他出库(合并发料)
  13891. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  13892. {
  13893. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode008' and enable = '1'";
  13894. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  13895. isMerge = true;
  13896. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  13897. a.OutDetailID AS DetailID,
  13898. '' AS Type,
  13899. a.Sequence AS TransSequence,
  13900. a.OutQuantity AS IssueQuantity,";
  13901. tableNameMerge = @"ICSOtherOut a
  13902. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  13903. columns = @"a.OutCode AS TransCode,
  13904. a.OutDetailID AS DetailID,
  13905. '' AS Type,
  13906. a.Sequence AS TransSequence,
  13907. a.OutQuantity AS IssueQuantity,";
  13908. tableName = @"ICSOtherOut a ";
  13909. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  13910. }
  13911. #endregion
  13912. #region 领料申请单发料(合并发料)
  13913. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  13914. {
  13915. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode002' and enable = '1'";
  13916. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  13917. isMerge = true;
  13918. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  13919. a.ApplyDetailID AS DetailID,
  13920. a.Type,
  13921. a.Sequence AS TransSequence,
  13922. a.IssueQuantity AS IssueQuantity,";
  13923. tableNameMerge = @"ICSMOApply a
  13924. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  13925. columns = @"a.ApplyCode AS TransCode,
  13926. a.ApplyDetailID AS DetailID,
  13927. a.Type,
  13928. a.Sequence AS TransSequence,
  13929. a.IssueQuantity AS IssueQuantity,";
  13930. tableName = @"ICSMOApply a ";
  13931. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  13932. }
  13933. #endregion
  13934. #region 补料申请单发料(合并发料)
  13935. else if (TransType == TransTypeEnum.MOReplenishment.GetDescription())
  13936. {
  13937. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode012' and enable = '1'";
  13938. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  13939. isMerge = true;
  13940. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  13941. a.ApplyDetailID AS DetailID,
  13942. a.Type,
  13943. a.Sequence AS TransSequence,
  13944. a.IssueQuantity AS IssueQuantity,";
  13945. tableNameMerge = @"ICSMOReplenishment a
  13946. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  13947. columns = @"a.ReplenishmentCode AS TransCode,
  13948. a.ReplenishmentDetailID AS DetailID,
  13949. a.Type,
  13950. a.Sequence AS TransSequence,
  13951. a.IssueQuantity AS IssueQuantity,";
  13952. tableName = @"ICSMOReplenishment a ";
  13953. where = @" a.ReplenishmentCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  13954. }
  13955. #endregion
  13956. #region 委外领料申请单发料(合并发料)
  13957. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  13958. {
  13959. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode005' and enable = '1'";
  13960. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  13961. isMerge = true;
  13962. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  13963. a.ApplyDetailID AS DetailID,
  13964. a.Type,
  13965. a.Sequence AS TransSequence,
  13966. a.IssueQuantity AS IssueQuantity,";
  13967. tableNameMerge = @"ICSOApply a
  13968. INNER JOIN ICSMOPickMerge mer ON a.ID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  13969. columns = @"a.ApplyCode AS TransCode,
  13970. a.ApplyDetailID AS DetailID,
  13971. a.Type,
  13972. a.Sequence AS TransSequence,
  13973. a.IssueQuantity AS IssueQuantity,";
  13974. tableName = @"ICSOApply a ";
  13975. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  13976. }
  13977. #endregion
  13978. #region 开立材料出库(合并发料)
  13979. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  13980. {
  13981. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode003' and enable = '1'";
  13982. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  13983. isMerge = true;
  13984. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  13985. a.IssueDetailID AS DetailID,
  13986. a.Type,
  13987. a.Sequence AS TransSequence,
  13988. a.IssueQuantity AS IssueQuantity,";
  13989. tableNameMerge = @"ICSMOIssue a
  13990. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  13991. columns = @"a.IssueCode AS TransCode,
  13992. a.IssueDetailID AS DetailID,
  13993. a.Type,
  13994. a.Sequence AS TransSequence,
  13995. a.IssueQuantity AS IssueQuantity,";
  13996. tableName = @"ICSMOIssue a ";
  13997. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  13998. }
  13999. #endregion
  14000. #region 开立委外材料出库(合并发料)
  14001. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  14002. {
  14003. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode006' and enable = '1'";
  14004. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14005. isMerge = true;
  14006. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  14007. a.IssueDetailID AS DetailID,
  14008. a.Type,
  14009. a.Sequence AS TransSequence,
  14010. a.IssueQuantity AS IssueQuantity,";
  14011. tableNameMerge = @"ICSOIssue a
  14012. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14013. columns = @"a.IssueCode AS TransCode,
  14014. a.IssueDetailID AS DetailID,
  14015. a.Type,
  14016. a.Sequence AS TransSequence,
  14017. a.IssueQuantity AS IssueQuantity,";
  14018. tableName = @"ICSOIssue a ";
  14019. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  14020. }
  14021. #endregion
  14022. #region 开立红字入库单
  14023. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  14024. {
  14025. columns = @"a.RCVCode AS TransCode,
  14026. a.RCVDetailID AS DetailID,
  14027. a.Type,
  14028. a.Sequence AS TransSequence,
  14029. a.RCVQuantity AS IssueQuantity,";
  14030. tableName = @"ICSPurchaseReceive a ";
  14031. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  14032. }
  14033. #endregion
  14034. #region 开立委外红字入库单
  14035. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  14036. {
  14037. columns = @"a.RCVCode AS TransCode,
  14038. a.RCVDetailID AS DetailID,
  14039. a.Type,
  14040. a.Sequence AS TransSequence,
  14041. a.RCVQuantity AS IssueQuantity,";
  14042. tableName = @"ICSOutsourcingReceive a ";
  14043. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  14044. }
  14045. #endregion
  14046. #region 借用(合并发料)
  14047. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  14048. {
  14049. sqlCheckSign = @"select * from ICSConfiguration where code = 'OutWithLocationCode011' and enable = '1'";
  14050. flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  14051. isMerge = true;
  14052. columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
  14053. a.BrrowDetailID AS DetailID,
  14054. '' AS Type,
  14055. a.Sequence AS TransSequence,
  14056. a.BrrowQuantity AS IssueQuantity,";
  14057. tableNameMerge = @"ICSBrrow a
  14058. INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  14059. columns = @"a.BrrowCode AS TransCode,
  14060. a.BrrowDetailID AS DetailID,
  14061. '' AS Type,
  14062. a.Sequence AS TransSequence,
  14063. a.BrrowQuantity AS IssueQuantity,";
  14064. tableName = @"ICSBrrow a ";
  14065. where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  14066. }
  14067. #endregion
  14068. #region 送货单
  14069. else if (TransType == TransTypeEnum.ASN.GetDescription())
  14070. {
  14071. isDeliveryNotice = true;
  14072. columns = @"asn.ASNCode AS TransCode,
  14073. asn.ID AS DetailID,
  14074. asn.LotNo,
  14075. '' AS Type,
  14076. asn.Sequence AS TransSequence,
  14077. asn.DNQuantity AS IssueQuantity,
  14078. asn.Quantity,
  14079. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  14080. asn.MUSER AS [User],
  14081. asn.MTIME AS [MTime],";
  14082. tableName = @"ICSInventoryLot a
  14083. INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  14084. where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
  14085. }
  14086. #endregion
  14087. #region 委外送货单
  14088. else if (TransType == TransTypeEnum.OASN.GetDescription())
  14089. {
  14090. isDeliveryNotice = true;
  14091. columns = @"asn.OASNCode AS TransCode,
  14092. asn.ID AS DetailID,
  14093. asn.LotNo,
  14094. '' AS Type,
  14095. asn.Sequence AS TransSequence,
  14096. asn.ODNQuantity AS IssueQuantity,
  14097. asn.Quantity,
  14098. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  14099. asn.MUSER AS [User],
  14100. asn.MTIME AS [MTime],";
  14101. tableName = @"ICSInventoryLot a
  14102. INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  14103. where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
  14104. }
  14105. #endregion
  14106. #endregion
  14107. #region 入库
  14108. #region 采购入库
  14109. else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  14110. {
  14111. }
  14112. #endregion
  14113. #region 审核的到货单
  14114. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  14115. {
  14116. }
  14117. #endregion
  14118. #region 采购拒收
  14119. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  14120. {
  14121. }
  14122. #endregion
  14123. #region 审核的委外到货单
  14124. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  14125. {
  14126. }
  14127. #endregion
  14128. #region 委外拒收
  14129. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  14130. {
  14131. }
  14132. #endregion
  14133. #region 委外退料
  14134. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  14135. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  14136. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  14137. {
  14138. }
  14139. #endregion
  14140. #region 委外入库
  14141. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  14142. {
  14143. }
  14144. #endregion
  14145. #region 生产退料
  14146. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  14147. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  14148. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  14149. {
  14150. }
  14151. #endregion
  14152. #region 生产入库
  14153. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  14154. {
  14155. }
  14156. #endregion
  14157. #region 开立的生产入库单
  14158. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  14159. {
  14160. }
  14161. #endregion
  14162. #region 返工工单
  14163. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  14164. {
  14165. }
  14166. #endregion
  14167. #region 销售退货
  14168. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  14169. {
  14170. }
  14171. #endregion
  14172. #region 两步调入
  14173. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  14174. {
  14175. columns = @"a.InCode AS TransCode,
  14176. a.InDetailID AS DetailID,
  14177. '' AS Type,
  14178. a.Sequence AS TransSequence,
  14179. a.InQuantity AS IssueQuantity,";
  14180. tableName = @"ICSOtherIn a
  14181. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  14182. where = @" a.InCode='{0}' AND a.WorkPoint='{1}' AND a.Status<>'3'";
  14183. }
  14184. #endregion
  14185. #region 销售退货-原条码
  14186. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  14187. {
  14188. columns = @"a.SDNCode AS TransCode,
  14189. a.SDNDetailID AS DetailID,
  14190. a.Type,
  14191. a.Sequence AS TransSequence,
  14192. a.SDNQuantity AS IssueQuantity,";
  14193. tableName = @"ICSSDN a ";
  14194. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' AND a.Status<>'3'";
  14195. }
  14196. #endregion
  14197. #region 其他入库
  14198. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  14199. {
  14200. }
  14201. #endregion
  14202. #region 拆卸单
  14203. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  14204. {
  14205. columns = @"a.DABDOCCode AS TransCode,
  14206. a.DABDOCDetailID AS DetailID,
  14207. a.DABDOCType AS Type,
  14208. a.Sequence AS TransSequence,
  14209. a.DABDOCQuantity AS IssueQuantity,";
  14210. tableName = @"ICSDisassemblyDoc a";
  14211. where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' AND a.Status<>'3' ";
  14212. }
  14213. #endregion
  14214. #region 归还
  14215. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  14216. {
  14217. }
  14218. #endregion
  14219. #endregion
  14220. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
  14221. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  14222. #region 判断是否启用匹配库位
  14223. if (flag != null && flag.Rows.Count > 0)
  14224. //if (true)
  14225. {
  14226. sql = @"select * into #maintemp from (" + sql + @")a
  14227. select * into #resulttemp from #maintemp
  14228. truncate table #resulttemp
  14229. 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,
  14230. isnull(ext.Brand,'')as Brand,
  14231. isnull(ext.cFree1,'')as cFree1,
  14232. isnull(ext.cFree2,'') cFree2,
  14233. isnull(ext.cFree3,'') cFree3,
  14234. isnull(ext.cFree4,'') cFree4,
  14235. isnull(ext.cFree5,'') cFree5,
  14236. isnull(ext.cFree6,'') cFree6,
  14237. isnull(ext.cFree7,'') cFree7,
  14238. isnull(ext.cFree8,'') cFree8,
  14239. isnull(ext.cFree9,'') cFree9,
  14240. isnull(ext.cFree10,'') cFree10,ISNULL(ext.BatchCode, '') BatchCode into #barcodetemp
  14241. from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  14242. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  14243. LEFT JOIN
  14244. (select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp
  14245. group by invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE) b on a.invcode = b.invcode
  14246. where (a.warehousecode = b.whcode or ISNULL(b.whcode,'')='') and a.Quantity-a.lockQuantity>0 and
  14247. isnull(ext.ProjectCode,'') = b.ProjectCode and isnull(ext.Version,'')=b.Version and
  14248. isnull(ext.Brand,'') =b.Brand and
  14249. isnull(ext.cFree1,'')=b.cFree1 and
  14250. isnull(ext.cFree2,'')=b.cFree2 and
  14251. isnull(ext.cFree3,'')=b.cFree3 and
  14252. isnull(ext.cFree4,'')=b.cFree4 and
  14253. isnull(ext.cFree5,'')=b.cFree5 and
  14254. isnull(ext.cFree6,'')=b.cFree6 and
  14255. isnull(ext.cFree7,'')=b.cFree7 and
  14256. isnull(ext.cFree8,'')=b.cFree8 and
  14257. isnull(ext.cFree9,'')=b.cFree9 and
  14258. isnull(ext.cFree10,'')=b.cFree10 and
  14259. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =ext.BatchCode) or isnull(b.BatchCode,'') ='')
  14260. BEGIN
  14261. DECLARE @transSequence VARCHAR(50);--
  14262. DECLARE @qty decimal(18, 4);--
  14263. DECLARE @needqty decimal(18, 4);--
  14264. DECLARE @lotno VARCHAR(50);--
  14265. DECLARE @locationcode VARCHAR(50);--
  14266. DECLARE @WHCode VARCHAR(50);--
  14267. DECLARE @invcode VARCHAR(50);--
  14268. DECLARE @issueQuantity decimal(18, 4);
  14269. DECLARE tempCursor CURSOR FOR (select transSequence from #maintemp); --tempCursor
  14270. OPEN tempCursor; --
  14271. FETCH NEXT FROM tempCursor INTO @transSequence; --
  14272. WHILE @@fetch_status=0
  14273. BEGIN
  14274. select @needqty=Quantity,@issueQuantity=issueQuantity from #maintemp where transSequence = @transSequence
  14275. PRINT @transSequence
  14276. WHILE @needqty>0
  14277. BEGIN
  14278. 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
  14279. 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
  14280. and ((isnull(b.ProjectCode,'')<>'' and b.ProjectCode = a.ProjectCode) or isnull(b.ProjectCode,'') ='') and
  14281. ((isnull(b.Version,'')<>'' and b.Version = a.Version) or isnull(b.Version,'') ='') and
  14282. ((isnull(b.Brand,'')<>'' and b.Brand = a.Brand )or isnull(b.Brand,'') ='') and
  14283. ((isnull(b.cFree1,'')<>'' and b.cFree1 =a.cFree1) or isnull(b.cFree1,'') ='') and
  14284. ((isnull(b.cFree2,'')<>'' and b.cFree2 =a.cFree2 )or isnull(b.cFree2,'') ='') and
  14285. ((isnull(b.cFree3,'')<>'' and b.cFree3 =a.cFree3 )or isnull(b.cFree3,'') ='') and
  14286. ((isnull(b.cFree4,'')<>'' and b.cFree4 =a.cFree4 )or isnull(b.cFree4,'') ='') and
  14287. ((isnull(b.cFree5,'')<>'' and b.cFree5 =a.cFree5) or isnull(b.cFree5,'') ='') and
  14288. ((isnull(b.cFree6,'')<>'' and b.cFree6 =a.cFree6 )or isnull(b.cFree6,'') ='') and
  14289. ((isnull(b.cFree7,'')<>'' and b.cFree7 =a.cFree7) or isnull(b.cFree7,'') ='') and
  14290. ((isnull(b.cFree8,'')<>'' and b.cFree8 =a.cFree8) or isnull(b.cFree8,'') ='') and
  14291. ((isnull(b.cFree9,'')<>'' and b.cFree9 =a.cFree9) or isnull(b.cFree9,'') ='') and
  14292. ((isnull(b.cFree10,'')<>'' and b.cFree10 =a.cFree10) or isnull(b.cFree10,'') ='') and
  14293. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =a.BatchCode) or isnull(b.BatchCode,'') ='')ORDER BY mtime,locationcode
  14294. IF(@needqty-@issueQuantity-@qty>=0 and ISNULL(@lotno, '')<>'')
  14295. BEGIN
  14296. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  14297. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotNo,
  14298. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  14299. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  14300. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),@qty,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  14301. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  14302. delete from #barcodetemp where lotno = @lotno
  14303. SET @needqty=@needqty-@qty
  14304. END
  14305. ELSE if(@needqty-@issueQuantity-@qty<0 and ISNULL(@lotno, '')<>''and @needqty-@issueQuantity>0)
  14306. BEGIN
  14307. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  14308. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  14309. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  14310. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  14311. 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, ''),
  14312. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  14313. update #barcodetemp set quantity = @qty-@needqty+-@issueQuantity where lotno = @lotno
  14314. SET @needqty=@needqty-@issueQuantity-@qty
  14315. END
  14316. ELSE
  14317. BEGIN
  14318. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  14319. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  14320. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  14321. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  14322. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),0 ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  14323. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  14324. SET @needqty=0
  14325. END
  14326. END
  14327. FETCH NEXT FROM tempCursor INTO @transSequence;
  14328. END
  14329. CLOSE tempCursor
  14330. DEALLOCATE tempCursor
  14331. END
  14332. select id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  14333. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,sum(LocationQty)as LocationQty,isMatched,AmountUnit,--lotno,
  14334. 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,
  14335. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,isMatched,AmountUnit,--lotno,
  14336. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ORDER BY locationcode ASC ,InvCode ASC
  14337. DROP table #maintemp
  14338. DROP table #resulttemp
  14339. DROP table #barcodetemp";
  14340. }
  14341. #endregion
  14342. if (isDeliveryNotice)//送货、到货、含委外
  14343. {
  14344. #region SLQ
  14345. sql = sqlCheck + @"SELECT a.ID,
  14346. {0}
  14347. a.InvCode,
  14348. inv.InvName,
  14349. inv.InvStd,
  14350. inv.InvUnit,
  14351. '' AS WHCode,
  14352. inv.AmountUnit,
  14353. '' AS WHName,
  14354. a.ExtensionID,
  14355. ext.ProjectCode,
  14356. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  14357. ext.Version,
  14358. ext.Brand,
  14359. ext.cFree1,
  14360. ext.cFree2,
  14361. ext.cFree3,
  14362. ext.cFree4,
  14363. ext.cFree5,
  14364. ext.cFree6,
  14365. ext.cFree7,
  14366. ext.cFree8,
  14367. ext.cFree9,
  14368. ext.cFree10
  14369. FROM {1}
  14370. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  14371. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  14372. WHERE {2} ";
  14373. #endregion
  14374. }
  14375. else if (isMerge)//合并发料
  14376. {
  14377. #region SLQ
  14378. string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='" + JsonData.TransCode + "' AND WorkPoint='" + JsonData.WorkPoint + "'";
  14379. DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
  14380. if (sign != null && sign.Rows.Count > 0)
  14381. {
  14382. string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
  14383. sql = string.Format(sql, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, excessQtySql);
  14384. }
  14385. else
  14386. {
  14387. sql = @" BEGIN
  14388. IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
  14389. BEGIN
  14390. RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
  14391. RETURN
  14392. END
  14393. " + sqlCheck + sql + @"
  14394. END";
  14395. }
  14396. #endregion
  14397. }
  14398. else
  14399. {
  14400. sql = sqlCheck + sql;
  14401. }
  14402. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint,JsonData.User,JsonData.TransSequence);
  14403. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode, excessQtySql);
  14404. sqls = string.Format(sqls, JsonData.TransCode, JsonData.WorkPoint);
  14405. Picksql = string.Format(Picksql, sqls, JsonData.WorkPoint);
  14406. //DataTable table2 = DBHelper.SQlReturnData(Picksql, cmd);
  14407. //return table2;
  14408. log.Debug("源头单据信息sql:" + sql);
  14409. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  14410. return table;
  14411. }
  14412. catch (Exception ex)
  14413. {
  14414. log.Error(ex.Message);
  14415. throw new Exception(ex.Message);
  14416. }
  14417. finally
  14418. {
  14419. if (conn.State == ConnectionState.Open)
  14420. {
  14421. conn.Close();
  14422. }
  14423. conn.Dispose();
  14424. }
  14425. }
  14426. }
  14427. #endregion
  14428. /// <summary>
  14429. /// 所有未完成单据号
  14430. /// </summary>
  14431. /// <param name="JsonData"></param>
  14432. /// <returns></returns>
  14433. public static DataTable AMTransCodeGet(WMSSourceDocumentModel JsonData)
  14434. {
  14435. var language = LanguageHelper.GetName("WMSAPIInfo");
  14436. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  14437. {
  14438. conn.Open();
  14439. SqlCommand cmd = new SqlCommand();
  14440. cmd.Connection = conn;
  14441. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  14442. try
  14443. {
  14444. if (string.IsNullOrEmpty(JsonData.TransType))
  14445. {
  14446. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  14447. }
  14448. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  14449. {
  14450. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  14451. }
  14452. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  14453. {
  14454. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  14455. }
  14456. string TransType = JsonData.TransType;
  14457. #region SLQ
  14458. //string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  14459. // BEGIN
  14460. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  14461. // RETURN
  14462. // END
  14463. // ";
  14464. string sql = @"SELECT
  14465. {0}
  14466. FROM {1}
  14467. WHERE {2}
  14468. order by TransCode asc";
  14469. #endregion
  14470. bool isDeliveryNotice = false; //送货、到货、含委外
  14471. bool MOApplyWithBin = false; //生产领料-库位
  14472. bool OtherOutDocWithBin = false; //杂发-库位
  14473. string columns = string.Empty; //查询源头单据表的特殊列名
  14474. string tableName = string.Empty; //查询源头单据表名
  14475. string where = string.Empty; //查询源头单据的过滤条件
  14476. bool isMerge = false; //合并发料
  14477. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  14478. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  14479. #region 出库
  14480. #region 采购退货
  14481. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  14482. {
  14483. columns = @" DISTINCT a.DNCode AS TransCode";
  14484. tableName = @"ICSDeliveryNotice a ";
  14485. where = @" a.WorkPoint='{1}' AND a.DNType='2' AND a.Status='2' AND (a.Quantity-a.RCVQuantity)>0";
  14486. }
  14487. #endregion
  14488. #region 其他出库
  14489. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  14490. {
  14491. columns = @" DISTINCT a.OutCode AS TransCode";
  14492. tableName = @"ICSOtherOut a ";
  14493. where = @" a.Status='1' AND a.WorkPoint='{1}' and a.Quantity>a.OutQuantity";
  14494. }
  14495. #endregion
  14496. #region 一步调拨(合并发料)
  14497. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  14498. {
  14499. columns = @" DISTINCT a.TransferNO AS TransCode";
  14500. tableName = @"ICSTransfer a ";
  14501. where = @" a.WorkPoint='{1}' AND a.Status='1' AND a.Quantity>a.TransferQuantity AND Type='1'";
  14502. }
  14503. #endregion
  14504. #region 生产发料(合并发料)
  14505. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  14506. {
  14507. columns = @" DISTINCT b.MOCode AS TransCode";
  14508. tableName = @" ICSMOPick a
  14509. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  14510. INNER JOIN ICSDepartment c on b.DepCode=c.DepCode and b.WorkPoint=c.WorkPoint";
  14511. where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.MOStatus<>'3' and a.EATTRIBUTE1<>'1' and a.Quantity-a.IssueQuantity>0
  14512. AND c.DepName =(SELECT SUBSTRING(F_RealName, 1, 2) FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{1}') ";
  14513. }
  14514. #endregion
  14515. #region 开立材料出库(合并发料)
  14516. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  14517. {
  14518. columns = @" DISTINCT a.IssueCode AS TransCode";
  14519. tableName = @" ICSMOIssue a ";
  14520. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  14521. }
  14522. #endregion
  14523. #region 生产发料-领料申请单
  14524. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  14525. {
  14526. columns = @" DISTINCT a.ApplyCode AS TransCode";
  14527. tableName = @" ICSMOApply a
  14528. INNER JOIN ICSMO b ON b.MOCode=a.SourceCode and a.SourceSequence = b.Sequence AND a.WorkPoint=b.WorkPoint";
  14529. where = @" a.Status='2' AND a.WorkPoint='{1}' and a.Quantity-a.IssueQuantity>0";
  14530. }
  14531. #endregion
  14532. #region 开立委外材料出库(合并发料)
  14533. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  14534. {
  14535. columns = @" DISTINCT a.IssueCode AS TransCode";
  14536. tableName = @" ICSOIssue a ";
  14537. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  14538. }
  14539. #endregion
  14540. #region 委外领料申请单发料(合并发料)
  14541. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  14542. {
  14543. columns = @" DISTINCT a.ApplyCode AS TransCode";
  14544. tableName = @" ICSOApply a ";
  14545. where = @" a.WorkPoint='{1}' AND a.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  14546. }
  14547. #endregion
  14548. #region 委外发料(合并发料)
  14549. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  14550. {
  14551. columns = @" DISTINCT b.OOCode AS TransCode";
  14552. tableName = @" ICSOOPick a
  14553. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  14554. where = @" a.WorkPoint='{1}' AND a.SupplyType='3' AND b.Status<>'3' and a.Quantity-a.IssueQuantity>0";
  14555. }
  14556. #endregion
  14557. #region 销售出库(合并发料)
  14558. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  14559. {
  14560. columns = @" DISTINCT a.SDNCode AS TransCode";
  14561. tableName = @"ICSSDN a ";
  14562. where = @" a.WorkPoint='{1}' AND a.Type='1' AND a.Status<>'3' and a.Quantity-a.SDNQuantity>0";
  14563. }
  14564. #endregion
  14565. #region 盘点
  14566. else if (TransType == TransTypeEnum.Check.GetDescription())
  14567. {
  14568. columns = @" DISTINCT a.CheckCode AS TransCode";
  14569. tableName = @"ICSCheck a ";
  14570. where = @" a.WorkPoint='{1}' ";
  14571. }
  14572. #endregion
  14573. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint,JsonData.User);
  14574. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode);
  14575. log.Debug("源头单据sql : " + sql);
  14576. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  14577. return table;
  14578. #endregion
  14579. }
  14580. catch (Exception ex)
  14581. {
  14582. log.Error(ex.Message);
  14583. throw new Exception(ex.Message);
  14584. }
  14585. finally
  14586. {
  14587. if (conn.State == ConnectionState.Open)
  14588. {
  14589. conn.Close();
  14590. }
  14591. conn.Dispose();
  14592. }
  14593. }
  14594. }
  14595. public static Result AMBarCodeInformationGet(BarCodeModel JsonData)
  14596. {
  14597. var language = LanguageHelper.GetName("WMSAPIInfo");
  14598. DataTable table = new DataTable();
  14599. DataTable ZLtable = new DataTable();
  14600. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  14601. {
  14602. conn.Open();
  14603. SqlCommand cmd = new SqlCommand();
  14604. cmd.Connection = conn;
  14605. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  14606. try
  14607. {
  14608. string ScanType = DBHelper.ScanTypeCheck(JsonData.Code, JsonData.WorkPoint, cmd);
  14609. if (string.IsNullOrEmpty(JsonData.Code))
  14610. {
  14611. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  14612. }
  14613. else if (string.IsNullOrEmpty(JsonData.TransType))
  14614. {
  14615. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  14616. }
  14617. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  14618. {
  14619. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  14620. }
  14621. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  14622. {
  14623. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  14624. }
  14625. string TransType = JsonData.TransType;
  14626. string sql = "";
  14627. string LotTypesql = "";
  14628. string Losql = "";
  14629. string sqlNew = "";
  14630. string LotType = "";
  14631. string UserName = "";
  14632. string UName = "";
  14633. bool iszl = false;
  14634. string zlqty = "0";
  14635. #region SLQ
  14636. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  14637. {
  14638. //Losql = @"SELECT a.ID,
  14639. // con.ContainerCode,
  14640. // con.ContainerName,
  14641. // a.LotNo,
  14642. // a.InvCode,
  14643. // inv.InvName,
  14644. // inv.InvStd,
  14645. // inv.InvUnit,
  14646. // inv.LotEnable,
  14647. // {0}
  14648. // inv.AmountUnit,
  14649. // ext.ID AS ExtensionID,
  14650. // ext.ProjectCode,
  14651. // ext.Version,
  14652. // ext.Brand,
  14653. // ext.cFree1,
  14654. // ext.cFree2,
  14655. // ext.cFree3,
  14656. // ext.cFree4,
  14657. // ext.cFree5,
  14658. // ext.cFree6,
  14659. // ext.cFree7,
  14660. // ext.cFree8,
  14661. // ext.cFree9,
  14662. // ext.cFree10,
  14663. // a.MUSER AS [User],
  14664. // a.MTIME AS [MTime]
  14665. // FROM {1}
  14666. // LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  14667. // LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  14668. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  14669. // WHERE a.Quantity>0 and a.WorkPoint='{3}'";
  14670. Losql = @" DECLARE @wheresql VARCHAR(MAX)
  14671. DECLARE @groupsql VARCHAR(MAX)
  14672. DECLARE @aa VARCHAR(MAX)
  14673. DECLARE @bb VARCHAR(MAX)
  14674. DECLARE @cc VARCHAR(MAX)
  14675. DECLARE @dd VARCHAR(MAX)
  14676. DECLARE @b VARCHAR(MAX)
  14677. select @aa=id from ICSWareHouseLotInfo where LotNo='{2}'
  14678. IF @aa IS NOT NULL
  14679. BEGIN
  14680. set @wheresql='and a.lotno=''{2}'' and s.invcode IN(SELECT invcode FROM ICSWareHouseLotInfo where LotNo=''{2}'') and a.invcode=s.invcode '
  14681. 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,
  14682. 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'
  14683. END
  14684. select @bb=id from ICSLocation where LocationCode='{2}'
  14685. IF @bb IS not NULL
  14686. BEGIN
  14687. set @wheresql='and a.locationcode=s.locationcode and a.LocationCode=''{2}'' '
  14688. 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,
  14689. 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'
  14690. END
  14691. select @cc=id from ICSInventory where invcode='{2}'
  14692. IF @cc IS not NULL
  14693. BEGIN
  14694. set @wheresql='and inv.invcode=''{2}'' and a.invcode=s.invcode '
  14695. 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,
  14696. 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'
  14697. END
  14698. select @dd=id from ICSInventory where InvStd LIKE '%{2}%'
  14699. IF @dd IS not NULL
  14700. BEGIN
  14701. set @wheresql='and inv.InvStd LIKE ''%{2}%'' '
  14702. 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,
  14703. 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'
  14704. END
  14705. IF @aa IS NULL and @bb IS NULL and @cc IS NULL and @dd IS NULL
  14706. BEGIN
  14707. RAISERROR('" + language.GetNameByCode("WMSAPIInfo478") + @"',16,1)
  14708. END
  14709. ELSE
  14710. BEGIN
  14711. set @b =
  14712. 'SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
  14713. inv.InvName,
  14714. inv.InvStd,
  14715. inv.InvUnit,
  14716. inv.LotEnable,
  14717. a.WarehouseCode,a.LocationCode,a.Quantity as Qty,SUM(s.sumQty) sumQty,
  14718. inv.AmountUnit,
  14719. ext.ID AS ExtensionID,
  14720. ext.ProjectCode,
  14721. ext.Version,
  14722. ext.Brand,
  14723. ext.cFree1,
  14724. ext.cFree2,
  14725. ext.cFree3,
  14726. ext.cFree4,
  14727. ext.cFree5,
  14728. ext.cFree6,
  14729. ext.cFree7,
  14730. ext.cFree8,
  14731. ext.cFree9,
  14732. ext.cFree10,
  14733. a.MUSER AS [User],
  14734. a.MTIME AS [MTime]
  14735. FROM ICSWareHouseLotInfo a
  14736. LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  14737. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  14738. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  14739. 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
  14740. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  14741. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  14742. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  14743. WHERE a.Quantity>0 and a.WorkPoint=''{3}'' ' + @wheresql + @groupsql
  14744. END
  14745. exec(@b)
  14746. ";
  14747. }
  14748. else
  14749. {
  14750. if (ScanType == "LOTNO")
  14751. {
  14752. sql = @"SELECT a.ID,
  14753. con.ContainerCode,
  14754. con.ContainerName,
  14755. a.LotNo,
  14756. a.InvCode,
  14757. inv.InvName,
  14758. inv.InvStd,
  14759. inv.InvUnit,
  14760. inv.LotEnable,
  14761. {0}
  14762. inv.AmountUnit,
  14763. inv.AmountEnable,
  14764. ext.ID AS ExtensionID,
  14765. ext.ProjectCode,
  14766. ext.Version,
  14767. ext.Brand,
  14768. ext.cFree1,
  14769. ext.cFree2,
  14770. ext.cFree3,
  14771. ext.cFree4,
  14772. ext.cFree5,
  14773. ext.cFree6,
  14774. ext.cFree7,
  14775. ext.cFree8,
  14776. ext.cFree9,
  14777. ext.cFree10,
  14778. a.MUSER AS [User],
  14779. a.MTIME AS [MTime]
  14780. FROM {1}
  14781. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  14782. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  14783. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  14784. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' ";
  14785. }
  14786. else
  14787. {
  14788. sql = @"SELECT a.ID,
  14789. con.ContainerCode,
  14790. con.ContainerName,
  14791. a.LotNo,
  14792. a.InvCode,
  14793. inv.InvName,
  14794. inv.InvStd,
  14795. inv.InvUnit,
  14796. {0}
  14797. inv.AmountUnit,
  14798. inv.AmountEnable,
  14799. ext.ID AS ExtensionID,
  14800. ext.ProjectCode,
  14801. ext.Version,
  14802. ext.Brand,
  14803. ext.cFree1,
  14804. ext.cFree2,
  14805. ext.cFree3,
  14806. ext.cFree4,
  14807. ext.cFree5,
  14808. ext.cFree6,
  14809. ext.cFree7,
  14810. ext.cFree8,
  14811. ext.cFree9,
  14812. ext.cFree10,
  14813. a.MUSER AS [User],
  14814. a.MTIME AS [MTime]
  14815. FROM {1}
  14816. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  14817. LEFT JOIN ICSBomALL bom ON bom.ID=conlot.ContainerID
  14818. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  14819. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  14820. WHERE bom.ContainerCode='{2}' AND a.WorkPoint='{3}' ";
  14821. }
  14822. }
  14823. #endregion
  14824. bool isOut = false; //出库标记
  14825. string columns = string.Empty; //查询源头单据表的特殊列名
  14826. string columnsLOCODE = string.Empty;
  14827. string columnsLONAME = string.Empty;
  14828. string columnsWHCODE = string.Empty;
  14829. string columnsWHNAME = string.Empty;
  14830. string tableName = string.Empty; //查询源头单据表名
  14831. string where = string.Empty; //排序
  14832. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription() //采购退货
  14833. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() //委外发料
  14834. || TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription() //委外退货
  14835. || TransType == TransTypeEnum.MOIssueDoc.GetDescription() //生产发料
  14836. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() //销售出库
  14837. || TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription() //一步调拨
  14838. || TransType == TransTypeEnum.StepTransferApplicationIn.GetDescription() //调拨申请单
  14839. || TransType == TransTypeEnum.StepTransferDocIn.GetDescription() //调拨
  14840. || TransType == TransTypeEnum.StepNoTransferDocIn.GetDescription() //无源头调拨
  14841. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() //两步调出
  14842. || TransType == TransTypeEnum.OtherOutDoc.GetDescription() //其他出库
  14843. || TransType == TransTypeEnum.Check.GetDescription() //盘点
  14844. || TransType == TransTypeEnum.MOApply.GetDescription() //领料申请单
  14845. || TransType == TransTypeEnum.MOReplenishment.GetDescription() //领料申请单
  14846. || TransType == TransTypeEnum.OOApply.GetDescription() //委外领料申请单
  14847. || TransType == TransTypeEnum.MOIssue.GetDescription() //开立材料出库单
  14848. || TransType == TransTypeEnum.OOIssue.GetDescription() //开立委外材料出库单
  14849. || TransType == TransTypeEnum.PurchaseReceive.GetDescription() //开立红字入库单
  14850. || TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription()//开立委外红字入库单
  14851. || TransType == TransTypeEnum.BrrowDoc.GetDescription() //借用
  14852. || TransType == TransTypeEnum.TransferLibrary.GetDescription() //移库
  14853. //|| TransType == TransTypeEnum.DisassemblyDoc.GetDescription() //拆卸单(散件生成条码入库)
  14854. )
  14855. {
  14856. isOut = true;
  14857. }
  14858. //库位查询
  14859. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  14860. {
  14861. // 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, " +
  14862. // "ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME";
  14863. // columns = @"s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,sum(a.Quantity) as Qty,s.sumQty,";
  14864. // tableName = @"ICSWareHouseLotInfo a
  14865. //LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  14866. //INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  14867. //INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  14868. //LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode from ICSWareHouseLotInfo group by WarehouseCode,INVCode)s
  14869. //ON a.INVCode=s.INVCode ";
  14870. }
  14871. else
  14872. {
  14873. //两步调入条码
  14874. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  14875. {
  14876. if (string.IsNullOrEmpty(JsonData.TransCode))
  14877. {
  14878. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  14879. }
  14880. if (ScanType == "LOTNO")
  14881. {
  14882. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSOtherIn Otin
  14883. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  14884. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  14885. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  14886. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  14887. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND Otin.InCode = '" + JsonData.TransCode + @"')
  14888. BEGIN
  14889. RAISERROR('" + language.GetNameByCode("WMSAPIInfo036") + @"',16,1);
  14890. RETURN
  14891. END
  14892. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  14893. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  14894. 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,
  14895. 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";
  14896. columns = @"SUM(log.Quantity) AS Quantity,
  14897. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  14898. a.WarehouseCode AS WHCode,
  14899. wh.WarehouseName AS WHName,
  14900. a.LocationCode,
  14901. loc.LocationName,
  14902. 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,";
  14903. tableName = @"ICSOtherIn Otin
  14904. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  14905. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  14906. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  14907. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  14908. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  14909. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  14910. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  14911. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  14912. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  14913. }
  14914. else
  14915. {
  14916. sql = @"WITH ICSBomALL AS
  14917. (
  14918. SELECT
  14919. ContainerCode AS TContainerCode,
  14920. ContainerCode AS PContainerCode,
  14921. ContainerCode AS ContainerCode,
  14922. ID,
  14923. ContainerID,
  14924. 0 AS [Level],
  14925. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  14926. CAST('00001' AS nvarchar(MAX)) AS Sort
  14927. FROM ICSContainer
  14928. WHERE ContainerCode='{2}'
  14929. UNION ALL
  14930. SELECT
  14931. b.TContainerCode,
  14932. b.ContainerCode AS PContainerCode,
  14933. a.ContainerCode,
  14934. a.ID,
  14935. a.ContainerID,
  14936. b.[Level]+1 AS [Level],
  14937. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  14938. 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
  14939. FROM
  14940. ICSContainer a
  14941. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  14942. )
  14943. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  14944. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  14945. 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,
  14946. 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";
  14947. columns = @"SUM(log.Quantity) AS Quantity,
  14948. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  14949. a.WarehouseCode AS WHCode,
  14950. wh.WarehouseName AS WHName,
  14951. a.LocationCode,
  14952. loc.LocationName,
  14953. 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,";
  14954. tableName = @"ICSOtherIn Otin
  14955. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  14956. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  14957. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  14958. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  14959. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  14960. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  14961. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  14962. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  14963. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  14964. }
  14965. }
  14966. //销售退货-原条码(可支持一个条码多次发货,汇总数量,目前加了限制:785-793行)
  14967. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  14968. {
  14969. if (string.IsNullOrEmpty(JsonData.TransCode))
  14970. {
  14971. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  14972. }
  14973. if (ScanType == "LOTNO")
  14974. {
  14975. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSSDN sdn
  14976. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  14977. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  14978. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1')
  14979. BEGIN
  14980. RAISERROR('" + language.GetNameByCode("WMSAPIInfo037") + @"',16,1);
  14981. RETURN
  14982. END
  14983. IF EXISTS(SELECT log.LotNo FROM ICSSDN sdn
  14984. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  14985. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  14986. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1' AND log.BusinessCode='19'
  14987. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  14988. BEGIN
  14989. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo191"), "{2}") + @"',16,1);
  14990. RETURN
  14991. END
  14992. " + sql + @"AND sdn.Type='1'
  14993. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  14994. 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,
  14995. 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";
  14996. columns = @"SUM(log.Quantity) AS Quantity,
  14997. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  14998. a.WarehouseCode AS WHCode,
  14999. wh.WarehouseName AS WHName,
  15000. a.LocationCode,
  15001. loc.LocationName,
  15002. 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,";
  15003. tableName = @"ICSSDN sdn
  15004. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  15005. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  15006. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  15007. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  15008. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15009. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  15010. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  15011. }
  15012. else
  15013. {
  15014. sql = @"WITH ICSBomALL AS
  15015. (
  15016. SELECT
  15017. ContainerCode AS TContainerCode,
  15018. ContainerCode AS PContainerCode,
  15019. ContainerCode AS ContainerCode,
  15020. ID,
  15021. ContainerID,
  15022. 0 AS [Level],
  15023. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  15024. CAST('00001' AS nvarchar(MAX)) AS Sort
  15025. FROM ICSContainer
  15026. WHERE ContainerCode='{2}'
  15027. UNION ALL
  15028. SELECT
  15029. b.TContainerCode,
  15030. b.ContainerCode AS PContainerCode,
  15031. a.ContainerCode,
  15032. a.ID,
  15033. a.ContainerID,
  15034. b.[Level]+1 AS [Level],
  15035. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  15036. 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
  15037. FROM
  15038. ICSContainer a
  15039. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  15040. )
  15041. " + sql + @"AND sdn.Type='1'
  15042. GROUP BY inv.LotEnable,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  15043. 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,
  15044. 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";
  15045. columns = @"SUM(log.Quantity) AS Quantity,
  15046. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  15047. a.WarehouseCode AS WHCode,
  15048. wh.WarehouseName AS WHName,
  15049. a.LocationCode,
  15050. loc.LocationName,
  15051. 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,";
  15052. tableName = @"ICSSDN sdn
  15053. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  15054. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  15055. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  15056. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  15057. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15058. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  15059. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  15060. }
  15061. }
  15062. //生产(委外)退料-原条码+新条码
  15063. //先校验日志里面是否有原条码(同一种类型的条码只能发一次料才能原条码退,不然更新源头单据数量有问题,根据LogID判断是否原条码退回),如果没有查询新条码
  15064. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  15065. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  15066. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription()
  15067. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  15068. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  15069. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  15070. {
  15071. string type = "13";
  15072. string msglanguage = "WMSAPIInfo185";
  15073. if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  15074. {
  15075. type = "14";
  15076. msglanguage = "WMSAPIInfo186";
  15077. }
  15078. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  15079. {
  15080. type = "15";
  15081. msglanguage = "WMSAPIInfo187";
  15082. }
  15083. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  15084. {
  15085. type = "5";
  15086. msglanguage = "WMSAPIInfo188";
  15087. }
  15088. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  15089. {
  15090. type = "6";
  15091. msglanguage = "WMSAPIInfo189";
  15092. }
  15093. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  15094. {
  15095. type = "7";
  15096. msglanguage = "WMSAPIInfo190";
  15097. }
  15098. #region 新条码
  15099. if (ScanType == "LOTNO")
  15100. {
  15101. sqlNew = @"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  15102. BEGIN
  15103. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  15104. RETURN
  15105. END
  15106. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  15107. BEGIN
  15108. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  15109. RETURN
  15110. END
  15111. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  15112. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  15113. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  15114. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1'AND ins.LotNo IS NULL))
  15115. BEGIN
  15116. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  15117. RETURN
  15118. END
  15119. " + sql;
  15120. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  15121. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  15122. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  15123. {
  15124. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  15125. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  15126. (select negg.WHCode from ICSMOApplyNegDetail neg
  15127. INNER JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  15128. inner join ICSInventoryLotDetail lotdetail on neg.ApplyNegCode=lotdetail.TransCode
  15129. and neg.Sequence=lotdetail.TransSequence
  15130. where lotdetail.LotNo=a.LotNo and lotdetail.WorkPoint=a.WorkPoint) AS WHCode,
  15131. '' AS WHName,
  15132. '' AS LocationCode,
  15133. '' AS LocationName,
  15134. '' AS LogID,
  15135. ext.BatchCode AS BatchCode,";
  15136. }
  15137. if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  15138. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  15139. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  15140. {
  15141. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  15142. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  15143. (select negg.WHCode from ICSOApplyNegDetail neg
  15144. INNER JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  15145. inner join ICSInventoryLotDetail lotdetail on neg.OApplyNegCode=lotdetail.TransCode
  15146. and neg.Sequence=lotdetail.TransSequence
  15147. where lotdetail.LotNo=a.LotNo and lotdetail.WorkPoint=a.WorkPoint) AS WHCode,
  15148. '' AS WHName,
  15149. '' AS LocationCode,
  15150. '' AS LocationName,
  15151. '' AS LogID,
  15152. ext.BatchCode AS BatchCode,";
  15153. }
  15154. tableName = @"ICSInventoryLot a
  15155. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  15156. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  15157. }
  15158. else
  15159. {
  15160. sqlNew = @"WITH ICSBomALL AS
  15161. (
  15162. SELECT
  15163. ContainerCode AS TContainerCode,
  15164. ContainerCode AS PContainerCode,
  15165. ContainerCode AS ContainerCode,
  15166. ID,
  15167. ContainerID,
  15168. 0 AS [Level],
  15169. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  15170. CAST('00001' AS nvarchar(MAX)) AS Sort
  15171. FROM ICSContainer
  15172. WHERE ContainerCode='{2}'
  15173. UNION ALL
  15174. SELECT
  15175. b.TContainerCode,
  15176. b.ContainerCode AS PContainerCode,
  15177. a.ContainerCode,
  15178. a.ID,
  15179. a.ContainerID,
  15180. b.[Level]+1 AS [Level],
  15181. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  15182. 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
  15183. FROM
  15184. ICSContainer a
  15185. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  15186. )
  15187. " + sql;
  15188. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  15189. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  15190. '' AS WHCode,
  15191. '' AS WHName,
  15192. '' AS LocationCode,
  15193. '' AS LocationName,
  15194. ext.BatchCode AS BatchCode,";
  15195. tableName = @"ICSInventoryLot a
  15196. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  15197. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  15198. }
  15199. sqlNew = string.Format(sqlNew, columns, tableName, JsonData.Code, JsonData.WorkPoint, zlqty);
  15200. #endregion
  15201. #region 原条码
  15202. if (ScanType == "LOTNO")
  15203. {
  15204. sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY inv.AmountEnable,inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  15205. 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,
  15206. 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
  15207. ";
  15208. sql = @"IF EXISTS(" + sql + @")
  15209. BEGIN
  15210. " + sql + @"
  15211. END
  15212. ELSE
  15213. BEGIN
  15214. " + sqlNew + @"
  15215. END";
  15216. //sql = @"IF EXISTS(SELECT log.LotNo FROM ICSWareHouseLotInfoLog log
  15217. // INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  15218. // WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND log.TransCode='{5}' AND log.TransSequence='{6}' AND log.BusinessCode='" + type + @"'
  15219. // GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  15220. //BEGIN
  15221. // RAISERROR('" + string.Format(language.GetNameByCode(msglanguage), "{2}") + @"',16,1);
  15222. // RETURN
  15223. //END
  15224. //" + sql;
  15225. columns = @"SUM(log.Quantity) AS Quantity,
  15226. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  15227. a.WarehouseCode AS WHCode,
  15228. wh.WarehouseName AS WHName,
  15229. a.LocationCode,
  15230. loc.LocationName,
  15231. log.ID AS LogID,
  15232. 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,";
  15233. tableName = @"ICSWareHouseLotInfoLog log
  15234. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  15235. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  15236. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  15237. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15238. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  15239. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  15240. }
  15241. else
  15242. {
  15243. sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY inv.AmountEnable,inv.LotEnable,log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  15244. 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,
  15245. 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
  15246. ";
  15247. sql = @"IF EXISTS(" + sql + @")
  15248. BEGIN
  15249. " + sql + @"
  15250. END
  15251. ELSE
  15252. BEGIN
  15253. " + sqlNew + @"
  15254. END";
  15255. sql = @"WITH ICSBomALL AS
  15256. (
  15257. SELECT
  15258. ContainerCode AS TContainerCode,
  15259. ContainerCode AS PContainerCode,
  15260. ContainerCode AS ContainerCode,
  15261. ID,
  15262. ContainerID,
  15263. 0 AS [Level],
  15264. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  15265. CAST('00001' AS nvarchar(MAX)) AS Sort
  15266. FROM ICSContainer
  15267. WHERE ContainerCode='{2}'
  15268. UNION ALL
  15269. SELECT
  15270. b.TContainerCode,
  15271. b.ContainerCode AS PContainerCode,
  15272. a.ContainerCode,
  15273. a.ID,
  15274. a.ContainerID,
  15275. b.[Level]+1 AS [Level],
  15276. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  15277. 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
  15278. FROM
  15279. ICSContainer a
  15280. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  15281. )
  15282. " + sql;
  15283. columns = @"SUM(log.Quantity) AS Quantity,
  15284. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  15285. a.WarehouseCode AS WHCode,
  15286. wh.WarehouseName AS WHName,
  15287. a.LocationCode,
  15288. loc.LocationName,
  15289. log.ID AS LogID,
  15290. 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,";
  15291. tableName = @"ICSWareHouseLotInfoLog log
  15292. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  15293. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  15294. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  15295. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15296. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  15297. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  15298. }
  15299. #endregion
  15300. }
  15301. //分批
  15302. else if (TransType == TransTypeEnum.LOTSplit.GetDescription() || TransType == TransTypeEnum.LOTMerge.GetDescription())
  15303. {
  15304. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  15305. BEGIN
  15306. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  15307. RETURN
  15308. END
  15309. " + sql;
  15310. columns = @"a.Quantity,
  15311. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  15312. a.WarehouseCode AS WHCode,
  15313. wh.WarehouseName AS WHName,
  15314. a.LocationCode,
  15315. loc.LocationName,
  15316. 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,
  15317. ISNULL(split.SplitLotNo, a.LotNo+'-1') AS SplitLotNo,";
  15318. tableName = @"ICSWareHouseLotInfo a
  15319. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  15320. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  15321. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15322. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  15323. 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
  15324. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  15325. }
  15326. //出库条码
  15327. else if (isOut)
  15328. {
  15329. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() || TransType == TransTypeEnum.MOApply.GetDescription()
  15330. || TransType == TransTypeEnum.MOIssue.GetDescription() || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription()
  15331. || TransType == TransTypeEnum.OOApply.GetDescription() || TransType == TransTypeEnum.OOIssue.GetDescription()
  15332. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() || TransType == TransTypeEnum.OtherOutDoc.GetDescription()
  15333. || TransType == TransTypeEnum.BrrowDoc.GetDescription() || TransType == TransTypeEnum.StepTransferDocIn.GetDescription()
  15334. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() || TransType == TransTypeEnum.MOReplenishment.GetDescription())
  15335. {
  15336. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription()&& JsonData.User!="admin")
  15337. {
  15338. string uersql = @"SELECT F_RealName from Sys_SRM_User Where F_Account='{0}' AND F_Location='{1}'
  15339. ";
  15340. uersql = string.Format(uersql, JsonData.User, JsonData.WorkPoint);
  15341. DataTable dt = DBHelper.SQlReturnData(uersql, cmd);
  15342. if (dt.Rows.Count >= 0)
  15343. {
  15344. UserName = dt.Rows[0]["F_RealName"].ToString();
  15345. }
  15346. UName = UserName.Substring(0, 2);
  15347. string waresql = @"select WarehouseCode,WarehouseName from ICSWarehouse
  15348. where SUBSTRING(WarehouseName,1,2)='{0}' and WorkPoint='{1}'";
  15349. waresql = string.Format(waresql, UName, JsonData.WorkPoint);
  15350. DataTable dta = DBHelper.SQlReturnData(waresql, cmd);
  15351. if (dta.Rows.Count >= 0)
  15352. {
  15353. UName = dta.Rows[0]["WarehouseCode"].ToString();
  15354. }
  15355. }
  15356. //switch (UName)
  15357. //{
  15358. // case "L1":
  15359. // UName = "021";
  15360. // break;
  15361. // case "L2":
  15362. // UName = "022";
  15363. // break;
  15364. // case "L3":
  15365. // UName = "023";
  15366. // break;
  15367. // case "L4":
  15368. // UName = "024";
  15369. // break;
  15370. // case "L5":
  15371. // UName = "025";
  15372. // break;
  15373. // case "L6":
  15374. // UName = "026";
  15375. // break;
  15376. // case "L7":
  15377. // UName = "025";
  15378. // break;
  15379. // case "C1":
  15380. // UName = "015";
  15381. // break;
  15382. //}
  15383. ZLtable = ICSControlModeService.GetZL();
  15384. if (ZLtable == null)
  15385. {
  15386. throw new Exception(language.GetNameByCode("WMSAPIInfo471"));
  15387. }
  15388. for (int i = 0; i < ZLtable.Rows.Count; i++)
  15389. {
  15390. string zlName = ZLtable.Rows[i]["Name"].ToString();
  15391. string zlTransCode = ZLtable.Rows[i]["BusinessCode"].ToString();
  15392. string Enable = ZLtable.Rows[i]["Enable"].ToString();
  15393. if (JsonData.TransType.Equals(zlName))
  15394. {
  15395. if (Enable.Equals("True"))
  15396. {
  15397. string zlsql = @"IF NOT EXISTS(select a.Quantity,c.Name from ICSWareHouseLotInfoLog a
  15398. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
  15399. left join ICSType c on a.BusinessCode=c.Code and c.tablecode='ICSWareHouseLotInfoLog' and c.ColumnCode='BusinessCode'
  15400. where b.LotNo='{0}' and b.WorkPoint='{1}' and a.TransType='15' and c.name='{2}' and a.TransCode='{3}')
  15401. BEGIN
  15402. RAISERROR('" + language.GetNameByCode("WMSAPIInfo469") + @"',16,1);
  15403. RETURN
  15404. END
  15405. select a.Quantity,c.Name from ICSWareHouseLotInfoLog a
  15406. left join ICSInventoryLot b on a.LotNo=b.LotNo and a.WorkPoint=b.WorkPoint and a.InvCode=b.InvCode
  15407. left join ICSType c on a.BusinessCode=c.Code and c.tablecode='ICSWareHouseLotInfoLog' and c.ColumnCode='BusinessCode'
  15408. where b.LotNo='{0}' and b.WorkPoint='{1}' and a.TransType='15' and c.name='{2}' and a.TransCode='{3}'";
  15409. zlsql = string.Format(zlsql, JsonData.Code, JsonData.WorkPoint, JsonData.TransType, JsonData.TransCode);
  15410. DataTable zlltable = DBHelper.SQlReturnData(zlsql, cmd);
  15411. if (zlltable != null || zlltable.Rows.Count > 0)
  15412. {
  15413. zlqty = zlltable.Rows[0]["Quantity"].ToString();
  15414. iszl = true;
  15415. }
  15416. }
  15417. }
  15418. }
  15419. }
  15420. if (ScanType == "LOTNO")
  15421. {
  15422. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription() )
  15423. {
  15424. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  15425. BEGIN
  15426. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  15427. RETURN
  15428. END
  15429. 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}')
  15430. BEGIN
  15431. RAISERROR('线',16,1)
  15432. RETURN
  15433. END
  15434. " + sql;
  15435. }
  15436. if (TransType == TransTypeEnum.Check.GetDescription())
  15437. {
  15438. sql = @"IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  15439. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  15440. WHERE b.CheckCode='{6}' AND a.LotNo='{2}' AND a.WorkPoint='{3}')
  15441. BEGIN
  15442. IF ('{8}'='')
  15443. BEGIN
  15444. IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  15445. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  15446. WHERE b.CheckCode='{6}' AND a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.PrimaryQuantity>0)
  15447. BEGIN
  15448. RAISERROR('', 16, 1);
  15449. RETURN;
  15450. END
  15451. END
  15452. ELSE IF ('{8}'='')
  15453. BEGIN
  15454. IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  15455. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  15456. WHERE b.CheckCode='{6}' AND a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.CheckQuantity>0)
  15457. BEGIN
  15458. RAISERROR('', 16, 1);
  15459. RETURN;
  15460. END
  15461. END
  15462. ELSE
  15463. BEGIN
  15464. IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  15465. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  15466. WHERE b.CheckCode='{6}' AND a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.ReplayQuantity>0)
  15467. BEGIN
  15468. RAISERROR('', 16, 1);
  15469. RETURN;
  15470. END
  15471. END
  15472. END
  15473. " + sql;
  15474. }
  15475. if (iszl)
  15476. {
  15477. columns = @"{0} as Quantity,
  15478. {0}*(lot.Amount/lot.Quantity) AS Amount,
  15479. a.id AS LogID,
  15480. a.FromWarehouseCode AS WHCode,
  15481. wh.WarehouseName AS WHName,
  15482. inv.LotEnable,
  15483. a.FromLocationCode,
  15484. lot.ProductDate,
  15485. loc.LocationName,
  15486. 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,";
  15487. columns = string.Format(columns, zlqty);
  15488. tableName = @"ICSWareHouseLotInfoLog a
  15489. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  15490. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  15491. INNER JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15492. INNER JOIN ICSLocation loc ON a.FromLocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  15493. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  15494. }
  15495. else
  15496. {
  15497. if (TransType == TransTypeEnum.Check.GetDescription())
  15498. {
  15499. columns = @"case when inv.AmountEnable='1' then (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) else (a.Quantity-a.lockQuantity) end AS Quantity,
  15500. (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
  15501. '' AS LogID,
  15502. a.WarehouseCode AS WHCode,
  15503. wh.WarehouseName AS WHName,
  15504. inv.LotEnable,
  15505. a.LocationCode,
  15506. loc.LocationName,
  15507. 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,";
  15508. tableName = @"ICSWareHouseLotInfo a
  15509. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  15510. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  15511. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15512. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  15513. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  15514. }
  15515. else
  15516. {
  15517. columns = @"(a.Quantity-a.lockQuantity) AS Quantity,
  15518. (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
  15519. '' AS LogID,
  15520. a.WarehouseCode AS WHCode,
  15521. wh.WarehouseName AS WHName,
  15522. inv.LotEnable,
  15523. a.LocationCode,
  15524. loc.LocationName,
  15525. 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,";
  15526. tableName = @"ICSWareHouseLotInfo a
  15527. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  15528. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  15529. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15530. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  15531. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  15532. }
  15533. }
  15534. }
  15535. else
  15536. {
  15537. sql = @"
  15538. WITH ICSBomALL AS
  15539. (
  15540. SELECT
  15541. ContainerCode AS TContainerCode,
  15542. ContainerCode AS PContainerCode,
  15543. ContainerCode AS ContainerCode,
  15544. ID,
  15545. ContainerID,
  15546. 0 AS [Level],
  15547. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  15548. CAST('00001' AS nvarchar(MAX)) AS Sort
  15549. FROM ICSContainer
  15550. WHERE ContainerCode='{2}'
  15551. UNION ALL
  15552. SELECT
  15553. b.TContainerCode,
  15554. b.ContainerCode AS PContainerCode,
  15555. a.ContainerCode,
  15556. a.ID,
  15557. a.ContainerID,
  15558. b.[Level]+1 AS [Level],
  15559. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  15560. 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
  15561. FROM
  15562. ICSContainer a
  15563. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  15564. )
  15565. " + sql;
  15566. columns = @"(a.Quantity-a.lockQuantity) AS Quantity,
  15567. (a.Quantity-a.lockQuantity)*(lot.Amount/lot.Quantity) AS Amount,
  15568. a.WarehouseCode AS WHCode,
  15569. wh.WarehouseName AS WHName,
  15570. a.LocationCode,
  15571. lot.ProductDate,
  15572. loc.LocationName,
  15573. 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,";
  15574. tableName = @"ICSWareHouseLotInfo a
  15575. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  15576. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  15577. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  15578. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  15579. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  15580. ";
  15581. }
  15582. }
  15583. //入库条码
  15584. else
  15585. {
  15586. if (ScanType == "LOTNO")
  15587. {
  15588. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  15589. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  15590. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription()
  15591. || TransType == TransTypeEnum.UnqualifiedIN.GetDescription() || TransType == TransTypeEnum.MOStockINByProduct.GetDescription()
  15592. || TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  15593. {
  15594. //联产品入库(有来源单据)不可扫入无来源条码
  15595. if (TransType == TransTypeEnum.MOStockINByProduct.GetDescription())
  15596. {
  15597. sql = @"
  15598. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}' AND a.Type = 19 )
  15599. BEGIN
  15600. RAISERROR('', 16, 1);
  15601. RETURN;
  15602. END
  15603. " + sql;
  15604. }
  15605. sql = @"
  15606. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  15607. BEGIN
  15608. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  15609. RETURN
  15610. END
  15611. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  15612. BEGIN
  15613. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  15614. RETURN
  15615. END
  15616. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  15617. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  15618. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  15619. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1' AND ins.LotNo IS NULL))
  15620. BEGIN
  15621. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  15622. RETURN
  15623. END
  15624. " + sql;
  15625. }
  15626. else
  15627. {
  15628. sql = @"
  15629. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  15630. BEGIN
  15631. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  15632. RETURN
  15633. END
  15634. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  15635. BEGIN
  15636. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  15637. RETURN
  15638. END
  15639. " + sql;
  15640. }
  15641. ControlMode mode = ICSControlModeService.GetSuLocation();
  15642. //获取条码类型
  15643. LotTypesql = @"IF NOT EXISTS(SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}')
  15644. BEGIN
  15645. RAISERROR('" + language.GetNameByCode("WMSAPIInfo461") + @"',16,1);
  15646. RETURN
  15647. END
  15648. SELECT Type FROM ICSInventoryLot WHERE LotNo='{0}' AND WorkPoint='{1}'";
  15649. LotTypesql = string.Format(LotTypesql, JsonData.Code, JsonData.WorkPoint);
  15650. DataTable dt = DBHelper.SQlReturnData(LotTypesql, cmd);
  15651. if (dt != null && dt.Rows.Count > 0)
  15652. {
  15653. LotType = dt.Rows[0]["Type"].ToString();
  15654. }
  15655. if (mode != null)
  15656. {
  15657. if (mode.itemCode.Equals("LocationRemind01"))//固定库位:物料和库位绑定,显示库位名称列表
  15658. {
  15659. columnsLONAME = @"
  15660. (SELECT locat.LocationName from ICSWareHouseLotInfo loinfo
  15661. LEFT JOIN ICSLocation locat on locat.LocationCode=loinfo.LocationCode and loinfo.WorkPoint=locat.WorkPoint
  15662. where loinfo.lotno=a.lotno and loinfo.invcode=a.invcode and a.WorkPoint=loinfo.WorkPoint) AS LocationName,";
  15663. columnsLOCODE = @"
  15664. (SELECT locat.LocationCode from ICSWareHouseLotInfo loinfo
  15665. LEFT JOIN ICSLocation locat on locat.LocationCode=loinfo.LocationCode and loinfo.WorkPoint=locat.WorkPoint
  15666. where loinfo.lotno=a.lotno and loinfo.invcode=a.invcode and a.WorkPoint=loinfo.WorkPoint) AS LocationCode,";
  15667. }
  15668. else if (mode.itemCode.Equals("LocationRemind02"))//在库库位:物料有库存的对应库位,显示库位名称列表
  15669. {
  15670. columnsLONAME = @"
  15671. STUFF(
  15672. (SELECT DISTINCT ',' + LocationName
  15673. from ICSLocation wh
  15674. LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
  15675. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
  15676. FOR xml path('')
  15677. ),1,1,''
  15678. ) AS LocationName,";
  15679. columnsLOCODE = @"
  15680. STUFF(
  15681. (SELECT DISTINCT ',' + LocationCode
  15682. from ICSLocation wh
  15683. LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
  15684. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
  15685. FOR xml path('')
  15686. ),1,1,''
  15687. ) AS LocationCode,";
  15688. }
  15689. else if (mode.itemCode.Equals("LocationRemind03"))//最近一次出入库的库位,显示库位名称
  15690. {
  15691. columnsLONAME = @"
  15692. (SELECT Top 1 locat.LocationName from ICSWareHouseLotInfoLog log
  15693. 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
  15694. ORDER BY log.Mtime desc) AS LocationName,";
  15695. columnsLOCODE = @"
  15696. (SELECT Top 1 locat.LocationCode from ICSWareHouseLotInfoLog log
  15697. 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
  15698. ORDER BY log.Mtime desc) AS LocationCode,";
  15699. }
  15700. }
  15701. else
  15702. {
  15703. columnsLONAME = @"
  15704. STUFF(
  15705. (SELECT DISTINCT ',' + LocationName
  15706. from ICSLocation wh
  15707. LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
  15708. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
  15709. FOR xml path('')
  15710. ),1,1,''
  15711. ) AS LocationName,";
  15712. columnsLOCODE = @"
  15713. STUFF(
  15714. (SELECT DISTINCT ',' + LocationCode
  15715. from ICSLocation wh
  15716. LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
  15717. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
  15718. FOR xml path('')
  15719. ),1,1,''
  15720. ) AS LocationCode,";
  15721. }
  15722. #region 根据条码类型找到单据仓库信息
  15723. if (LotType.Equals("1"))
  15724. {//生产退料
  15725. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  15726. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1'),'') AS WHCode";
  15727. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  15728. 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";
  15729. }
  15730. else if (LotType.Equals("2"))
  15731. {//委外退料
  15732. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  15733. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1'),'') AS WHCode";
  15734. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  15735. 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";
  15736. }
  15737. else if (LotType.Equals("3"))
  15738. {//工单
  15739. 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";
  15740. 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";
  15741. }
  15742. else if (LotType.Equals("4"))
  15743. {//销售退货
  15744. 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";
  15745. 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";
  15746. }
  15747. else if (LotType.Equals("5"))
  15748. {//其他入库
  15749. 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";
  15750. 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";
  15751. }
  15752. else if (LotType.Equals("6"))
  15753. {//归还单
  15754. 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";
  15755. 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";
  15756. }
  15757. else if (LotType.Equals("7"))
  15758. {//采购到货单
  15759. 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";
  15760. 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";
  15761. }
  15762. else if (LotType.Equals("8"))
  15763. {//委外到货单
  15764. 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";
  15765. 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";
  15766. }
  15767. else if (LotType.Equals("9"))
  15768. {//成品入库单
  15769. 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";
  15770. 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";
  15771. }
  15772. else if (LotType.Equals("10"))
  15773. {//拒收单
  15774. 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";
  15775. 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";
  15776. }
  15777. else if (LotType.Equals("11"))
  15778. {//委外拒收单
  15779. 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";
  15780. 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";
  15781. }
  15782. else if (LotType.Equals("12"))
  15783. {//领料申请退料
  15784. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  15785. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2'),'') AS WHCode";
  15786. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  15787. 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";
  15788. }
  15789. else if (LotType.Equals("13"))
  15790. {//材料出库退料
  15791. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  15792. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3'),'') AS WHCode";
  15793. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  15794. 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";
  15795. }
  15796. else if (LotType.Equals("14"))
  15797. {//委外领料申请退料
  15798. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  15799. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2'),'') AS WHCode";
  15800. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  15801. 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";
  15802. }
  15803. else if (LotType.Equals("15"))
  15804. {//委外材料出库退料
  15805. columnsWHCODE = @"ISNULL((SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  15806. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3'),'') AS WHCode";
  15807. columnsWHNAME = @"ISNULL((SELECT WarehouseName from ICSWareHouse where WarehouseCode in (SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  15808. 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";
  15809. }
  15810. else if (LotType.Equals("16"))
  15811. {//返工工单
  15812. columnsWHCODE = @"ISNULL((SELECT pick.WHCode FROM ICSMOPick pick LEFT JOIN ICSMO moo ON pick.MODetailID=moo.MODetailID AND pick.WorkPoint=moo.WorkPoint
  15813. WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint),'') AS WHCode ";
  15814. 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
  15815. WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint) AND WorkPoint=a.WorkPoint),'') AS WHName ";
  15816. }
  15817. else
  15818. {
  15819. columnsWHCODE = @"'' AS WHCode";
  15820. columnsWHNAME = @"'' AS WHName";
  15821. }
  15822. #endregion
  15823. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  15824. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  15825. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription()
  15826. || TransType == TransTypeEnum.UnqualifiedIN.GetDescription() || TransType == TransTypeEnum.MOStockINByProduct.GetDescription()
  15827. || TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  15828. {
  15829. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  15830. a.Quantity*(a.Amount/a.Quantity) AS Amount,a.Type,
  15831. {0},{2},
  15832. lotdd.TransCode,lotdd.TransSequence,
  15833. {3}
  15834. {1}
  15835. ext.BatchCode AS BatchCode,";
  15836. tableName = @"ICSInventoryLot a
  15837. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  15838. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
  15839. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  15840. }
  15841. else
  15842. {
  15843. columns = @"a.Quantity AS Quantity,
  15844. a.Quantity*(a.Amount/a.Quantity) AS Amount,a.Type,
  15845. {0},{2},
  15846. {3}
  15847. {1}
  15848. ext.BatchCode AS BatchCode,";
  15849. tableName = @"ICSInventoryLot a
  15850. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  15851. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint";
  15852. }
  15853. columns = string.Format(columns, columnsWHCODE, columnsLONAME, columnsWHNAME, columnsLOCODE);
  15854. }
  15855. else
  15856. {
  15857. sql = @"
  15858. WITH ICSBomALL AS
  15859. (
  15860. SELECT
  15861. ContainerCode AS TContainerCode,
  15862. ContainerCode AS PContainerCode,
  15863. ContainerCode AS ContainerCode,
  15864. ID,
  15865. ContainerID,
  15866. 0 AS [Level],
  15867. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  15868. CAST('00001' AS nvarchar(MAX)) AS Sort
  15869. FROM ICSContainer
  15870. WHERE ContainerCode='{2}'
  15871. UNION ALL
  15872. SELECT
  15873. b.TContainerCode,
  15874. b.ContainerCode AS PContainerCode,
  15875. a.ContainerCode,
  15876. a.ID,
  15877. a.ContainerID,
  15878. b.[Level]+1 AS [Level],
  15879. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  15880. 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
  15881. FROM
  15882. ICSContainer a
  15883. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  15884. )
  15885. " + sql;
  15886. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription() || TransType == TransTypeEnum.DeliveryNotice.GetDescription()
  15887. || TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription() || TransType == TransTypeEnum.ODeliveryNotice.GetDescription()
  15888. || TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription() || TransType == TransTypeEnum.ManufactureReceive.GetDescription()
  15889. || TransType == TransTypeEnum.UnqualifiedIN.GetDescription() || TransType == TransTypeEnum.MOStockINByProduct.GetDescription()
  15890. || TransType == TransTypeEnum.OOStockINByProduct.GetDescription())
  15891. {
  15892. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  15893. a.Quantity*(a.Amount/a.Quantity) AS Amount,a.Type,
  15894. '' AS WHCode,
  15895. '' AS WHName,
  15896. '' AS LocationCode,
  15897. '' AS LocationName,
  15898. ext.BatchCode AS BatchCode,";
  15899. tableName = @"ICSInventoryLot a
  15900. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  15901. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  15902. }
  15903. else
  15904. {
  15905. columns = @"a.Quantity AS Quantity,
  15906. a.Quantity*(a.Amount/a.Quantity) AS Amount,a.Type,
  15907. '' AS WHCode,
  15908. '' AS WHName,
  15909. '' AS LocationCode,
  15910. '' AS LocationName,
  15911. ext.BatchCode AS BatchCode,";
  15912. tableName = @"ICSInventoryLot a
  15913. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint";
  15914. }
  15915. }
  15916. }
  15917. }
  15918. if (TransType != TransTypeEnum.LocationSeatch.GetDescription())
  15919. {
  15920. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName))
  15921. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  15922. }
  15923. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  15924. {
  15925. Losql = string.Format(Losql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  15926. table = DBHelper.SQlReturnData(Losql, cmd);
  15927. }
  15928. else
  15929. {
  15930. sql = string.Format(sql, columns, tableName, JsonData.Code, JsonData.WorkPoint, zlqty, UName,JsonData.TransCode,JsonData.TransSequence,JsonData.CheckKind);
  15931. log.Debug("条码sql:" + sql);
  15932. table = DBHelper.SQlReturnData(sql, cmd);
  15933. }
  15934. if (table == null || table.Rows.Count <= 0)
  15935. throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
  15936. #region 出库检验是否符合源头单据
  15937. string msg = string.Empty;
  15938. bool isLimit = false;
  15939. string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode' and F_EnabledMark = '1'";
  15940. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  15941. if (isOut) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
  15942. {//&& TransType != TransTypeEnum.TransferLibrary.GetDescription()
  15943. string Lot = "";
  15944. string workP = "";
  15945. if (TransType == TransTypeEnum.TransferLibrary.GetDescription())
  15946. {
  15947. foreach (DataRow drLot in table.Rows)
  15948. {
  15949. Lot = drLot["LotNo"].ToString();
  15950. sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  15951. sql = string.Format(sql, Lot, JsonData.WorkPoint);
  15952. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  15953. if (dt == null || dt.Rows.Count <= 0)
  15954. {
  15955. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), Lot));
  15956. }
  15957. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  15958. if (!JsonData.WHCode.Equals(whcode))
  15959. {
  15960. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo395"), JsonData.WHCode, whcode));
  15961. }
  15962. }
  15963. }
  15964. else if (TransType != TransTypeEnum.LocationSeatch.GetDescription() && TransType != TransTypeEnum.StepNoTransferDocIn.GetDescription())
  15965. {
  15966. string seq = string.Empty;
  15967. if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  15968. {
  15969. string chekkksql = @"select a.Sequence,a.InvCode FROM ICSMOPick a
  15970. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  15971. WHERE b.MOCode='{0}' AND b.Sequence='{2}' AND a.WorkPoint='{1}' ";
  15972. chekkksql = string.Format(chekkksql, JsonData.TransCode, JsonData.WorkPoint, JsonData.TransSequence);
  15973. log.Debug("工单行查子件信息" + chekkksql);
  15974. DataTable dtaa = DBHelper.SQlReturnData(chekkksql, cmd);
  15975. //查询条码的物料
  15976. string cheklotsql = @"select a.InvCode FROM ICSInventoryLot a
  15977. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' ";
  15978. cheklotsql = string.Format(cheklotsql, table.Rows[0]["LotNo"].ToString(), JsonData.WorkPoint);
  15979. log.Debug("查询条码的物料" + cheklotsql);
  15980. DataTable lotdata = DBHelper.SQlReturnData(cheklotsql, cmd);
  15981. //DataTable ad0=dtaa.Select(a => a.invcode == lotdata.Rows[0]["InvCode"].ToString());
  15982. DataRow[] drs = dtaa.Select("InvCode ='" + lotdata.Rows[0]["InvCode"].ToString() + "'");
  15983. if (drs == null || drs.Length == 0)
  15984. {
  15985. throw new Exception("当前扫描的条码物料和单据子件物料没有匹配的行,请确认!");
  15986. }
  15987. //DataTable ad0 = dtaa.AsEnumerable()
  15988. //.Where(a => a.Field<string>("InvCode") == lotdata.Rows[0]["InvCode"].ToString())
  15989. //.CopyToDataTable();
  15990. //if (ad0 == null || ad0.Rows.Count == 0)
  15991. //{
  15992. // throw new Exception("当前扫描的条码物料和单据子件物料没有匹配的行,请确认!");
  15993. //}
  15994. seq= JsonData.TransSequence + "~" + drs[0]["Sequence"].ToString();
  15995. log.Debug("工单子件行号:" + seq);
  15996. if (string.IsNullOrEmpty(JsonData.TransCode))
  15997. {
  15998. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  15999. }
  16000. }
  16001. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  16002. {
  16003. string chekkksql = @"select a.Sequence,a.InvCode FROM ICSSDN a
  16004. WHERE a.SDNCode='{0}' AND a.WorkPoint='{1}' ";
  16005. chekkksql = string.Format(chekkksql, JsonData.TransCode, JsonData.WorkPoint);
  16006. log.Debug("销售发货单行信息" + chekkksql);
  16007. DataTable dtaa = DBHelper.SQlReturnData(chekkksql, cmd);
  16008. //查询条码的物料
  16009. string cheklotsql = @"select a.InvCode FROM ICSInventoryLot a
  16010. WHERE a.LotNo='{0}' AND a.WorkPoint='{1}' ";
  16011. cheklotsql = string.Format(cheklotsql, table.Rows[0]["LotNo"].ToString(), JsonData.WorkPoint);
  16012. log.Debug("查询条码的物料" + cheklotsql);
  16013. DataTable lotdata = DBHelper.SQlReturnData(cheklotsql, cmd);
  16014. //DataTable ad0=dtaa.Select(a => a.invcode == lotdata.Rows[0]["InvCode"].ToString());
  16015. DataRow[] drs = dtaa.Select("InvCode ='" + lotdata.Rows[0]["InvCode"].ToString() + "'");
  16016. if (drs == null || drs.Length == 0)
  16017. {
  16018. throw new Exception("当前扫描的条码物料和单据物料没有匹配的行,请确认!");
  16019. }
  16020. //DataTable ad0 = dtaa.AsEnumerable()
  16021. //.Where(a => a.Field<string>("InvCode") == lotdata.Rows[0]["InvCode"].ToString())
  16022. //.CopyToDataTable();
  16023. //if (ad0 == null || ad0.Rows.Count == 0)
  16024. //{
  16025. // throw new Exception("当前扫描的条码物料和单据子件物料没有匹配的行,请确认!");
  16026. //}
  16027. seq = drs[0]["Sequence"].ToString();
  16028. log.Debug("销售发货单行号:" + seq);
  16029. if (string.IsNullOrEmpty(JsonData.TransCode))
  16030. {
  16031. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  16032. }
  16033. }
  16034. WMSSourceDocumentModel model = new WMSSourceDocumentModel();
  16035. model.TransCode = JsonData.TransCode;
  16036. model.TransSequence = seq;
  16037. model.TransType = JsonData.TransType;
  16038. model.WorkPoint = JsonData.WorkPoint;
  16039. model.User = JsonData.User;
  16040. DataTable TransData = AMTransInformationGet(model);
  16041. DataView dataView = TransData.DefaultView;
  16042. foreach (DataRow drLot in table.Rows)
  16043. {
  16044. Lot = drLot["LotNo"].ToString();
  16045. //盘点不需要对比以下属性
  16046. if (TransType == TransTypeEnum.Check.GetDescription())
  16047. continue;
  16048. string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
  16049. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
  16050. if (TransType != TransTypeEnum.MOIssueDoc.GetDescription())
  16051. {
  16052. rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
  16053. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
  16054. }
  16055. rowFilter += " AND (LEN(ISNULL(ProjectCode,''))<=0 OR (LEN(ISNULL(ProjectCode,''))>0 AND ProjectCode='" + drLot["ProjectCode"] + "'))";
  16056. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["ProjectCode"], GetExtentionName("ProjectCode", JsonData.WorkPoint, cmd, language)));
  16057. rowFilter += "AND (LEN(ISNULL(BatchCode,''))<=0 OR (LEN(ISNULL(BatchCode,''))>0 AND BatchCode='" + drLot["BatchCode"] + "'))";
  16058. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["BatchCode"], GetExtentionName("BatchCode", JsonData.WorkPoint, cmd, language)));
  16059. rowFilter += "AND (LEN(ISNULL(Version,''))<=0 OR (LEN(ISNULL(Version,''))>0 AND Version='" + drLot["Version"] + "'))";
  16060. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["Version"], GetExtentionName("Version", JsonData.WorkPoint, cmd, language)));
  16061. rowFilter += "AND (LEN(ISNULL(Brand,''))<=0 OR (LEN(ISNULL(Brand,''))>0 AND Brand='" + drLot["Brand"] + "'))";
  16062. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["Brand"], GetExtentionName("Brand", JsonData.WorkPoint, cmd, language)));
  16063. rowFilter += "AND (LEN(ISNULL(cFree1,''))<=0 OR (LEN(ISNULL(cFree1,''))>0 AND cFree1='" + drLot["cFree1"] + "'))";
  16064. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree1"], GetExtentionName("cFree1", JsonData.WorkPoint, cmd, language)));
  16065. rowFilter += "AND (LEN(ISNULL(cFree2,''))<=0 OR (LEN(ISNULL(cFree2,''))>0 AND cFree2='" + drLot["cFree2"] + "'))";
  16066. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree2"], GetExtentionName("cFree2", JsonData.WorkPoint, cmd, language)));
  16067. rowFilter += "AND (LEN(ISNULL(cFree3,''))<=0 OR (LEN(ISNULL(cFree3,''))>0 AND cFree3='" + drLot["cFree3"] + "'))";
  16068. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree3"], GetExtentionName("cFree3", JsonData.WorkPoint, cmd, language)));
  16069. rowFilter += "AND (LEN(ISNULL(cFree4,''))<=0 OR (LEN(ISNULL(cFree4,''))>0 AND cFree4='" + drLot["cFree4"] + "'))";
  16070. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree4"], GetExtentionName("cFree4", JsonData.WorkPoint, cmd, language)));
  16071. rowFilter += "AND (LEN(ISNULL(cFree5,''))<=0 OR (LEN(ISNULL(cFree5,''))>0 AND cFree5='" + drLot["cFree5"] + "'))";
  16072. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree5"], GetExtentionName("cFree5", JsonData.WorkPoint, cmd, language)));
  16073. rowFilter += "AND (LEN(ISNULL(cFree6,''))<=0 OR (LEN(ISNULL(cFree6,''))>0 AND cFree6='" + drLot["cFree6"] + "'))";
  16074. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree6"], GetExtentionName("cFree6", JsonData.WorkPoint, cmd, language)));
  16075. rowFilter += "AND (LEN(ISNULL(cFree7,''))<=0 OR (LEN(ISNULL(cFree7,''))>0 AND cFree7='" + drLot["cFree7"] + "'))";
  16076. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree7"], GetExtentionName("cFree7", JsonData.WorkPoint, cmd, language)));
  16077. rowFilter += "AND (LEN(ISNULL(cFree8,''))<=0 OR (LEN(ISNULL(cFree8,''))>0 AND cFree8='" + drLot["cFree8"] + "'))";
  16078. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree8"], GetExtentionName("cFree8", JsonData.WorkPoint, cmd, language)));
  16079. rowFilter += "AND (LEN(ISNULL(cFree9,''))<=0 OR (LEN(ISNULL(cFree9,''))>0 AND cFree9='" + drLot["cFree9"] + "'))";
  16080. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree9"], GetExtentionName("cFree9", JsonData.WorkPoint, cmd, language)));
  16081. rowFilter += "AND (LEN(ISNULL(cFree10,''))<=0 OR (LEN(ISNULL(cFree10,''))>0 AND cFree10='" + drLot["cFree10"] + "'))";
  16082. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo500"), Lot, drLot["cFree10"], GetExtentionName("cFree10", JsonData.WorkPoint, cmd, language)));
  16083. if (flag != null && flag.Rows.Count > 0)
  16084. {
  16085. rowFilter += " AND LocationCode='" + drLot["LocationCode"] + "'";
  16086. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["LocationCode"]));
  16087. }
  16088. //保质期管理
  16089. var resultEffective = Effective(Lot, JsonData.WorkPoint, cmd, language);
  16090. //0 - 已经是最早的批次
  16091. //1 - 不管控
  16092. //2 - 提醒
  16093. //3 - 限制
  16094. if (resultEffective == "2")
  16095. {
  16096. msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
  16097. }
  16098. else if (resultEffective == "3")
  16099. {
  16100. msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
  16101. isLimit = true;
  16102. }
  16103. string rowFilternew = rowFilter + " AND LEN(ISNULL(ProjectCode,''))>0";
  16104. string sqlnew = CheckTransnew(dataView, rowFilternew, "ProjectCode");
  16105. rowFilternew = rowFilter + " AND LEN(ISNULL(BatchCode,''))>0";
  16106. sqlnew += CheckTransnew(dataView, rowFilternew, "BatchCode");
  16107. rowFilternew = rowFilter + " AND LEN(ISNULL(Version,''))>0";
  16108. sqlnew += CheckTransnew(dataView, rowFilternew, "Version");
  16109. rowFilternew = rowFilter + " AND LEN(ISNULL(Brand,''))>0";
  16110. sqlnew += CheckTransnew(dataView, rowFilternew, "Brand");
  16111. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree1,''))>0";
  16112. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree1");
  16113. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree2,''))>0";
  16114. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree2");
  16115. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree3,''))>0";
  16116. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree3");
  16117. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree4,''))>0";
  16118. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree4");
  16119. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree5,''))>0";
  16120. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree5");
  16121. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree6,''))>0";
  16122. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree6");
  16123. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree7,''))>0";
  16124. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree7");
  16125. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree8,''))>0 ";
  16126. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree8");
  16127. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree9,''))>0";
  16128. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree9");
  16129. rowFilternew = rowFilter + " AND LEN(ISNULL(cFree10,''))>0";
  16130. sqlnew += CheckTransnew(dataView, rowFilternew, "cFree10");
  16131. //先进先出判断
  16132. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, sqlnew, cmd, language);
  16133. //0 - 已经是最早的批次
  16134. //1 - 不管控
  16135. //2 - 提醒
  16136. //3 - 限制
  16137. if (result == "2")
  16138. {
  16139. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  16140. }
  16141. else if (result == "3")
  16142. {
  16143. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  16144. isLimit = true;
  16145. }
  16146. }
  16147. }
  16148. }
  16149. #endregion
  16150. //return table;
  16151. Result res = new Result();
  16152. res.Success = true;
  16153. res.Message = msg;// "接口调用成功!";
  16154. if (!isLimit)
  16155. res.Data = table;
  16156. return res;
  16157. //出库时
  16158. //Message无值、Data有值,可直接处理
  16159. //Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
  16160. //Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
  16161. }
  16162. catch (Exception ex)
  16163. {
  16164. log.Error(ex.Message);
  16165. throw new Exception(ex.Message);
  16166. }
  16167. finally
  16168. {
  16169. if (conn.State == ConnectionState.Open)
  16170. {
  16171. conn.Close();
  16172. }
  16173. conn.Dispose();
  16174. }
  16175. }
  16176. }
  16177. /// <summary>
  16178. /// 拣配
  16179. /// </summary>
  16180. /// <param name="JsonData"></param>
  16181. /// <returns></returns>
  16182. public static DataTable PickMerge(List<LOTStockModel> JsonData)
  16183. {
  16184. String PrintEnable = "";
  16185. var language = LanguageHelper.GetName("WMSAPIInfo");
  16186. if (JsonData.Count <= 0)
  16187. {
  16188. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  16189. }
  16190. List<LOTStockModelList> model = new List<LOTStockModelList>();
  16191. DataTable printTable = new DataTable();
  16192. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  16193. {
  16194. conn.Open();
  16195. SqlTransaction sqlTran = conn.BeginTransaction();
  16196. SqlCommand cmd = new SqlCommand();
  16197. cmd.Transaction = sqlTran;
  16198. cmd.Connection = conn;
  16199. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  16200. string BusinessCode = string.Empty;
  16201. try
  16202. {
  16203. string TransType = string.Empty;
  16204. string pikTbLogsql = "";
  16205. string Identification = Guid.NewGuid().ToString();
  16206. foreach (var item in JsonData)
  16207. {
  16208. TransType = item.TransType;
  16209. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  16210. {
  16211. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  16212. }
  16213. else if (string.IsNullOrEmpty(item.TransCode))
  16214. {
  16215. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  16216. }
  16217. string[] trans = item.TransCode.Split('~');
  16218. string MergeID = "";
  16219. if (trans.Length == 2)
  16220. {
  16221. MergeID = trans[0];
  16222. item.TransCode = trans[1];
  16223. }
  16224. #region 销售出库
  16225. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  16226. {
  16227. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  16228. foreach (var itemInfo in item.detail)
  16229. {
  16230. pikTbLogsql = @"
  16231. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{7}' AND a.WorkPoint='{6}' AND Quantity-LockQuantity-'{3}'<0)
  16232. BEGIN
  16233. RAISERROR(':" + "{7}" + @"',16,1);
  16234. RETURN
  16235. END
  16236. IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{7}' AND WorkPoint='{6}' AND TransType='15')
  16237. BEGIN
  16238. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  16239. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  16240. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  16241. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  16242. MTIME,WorkPoint,EATTRIBUTE1)
  16243. SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
  16244. a.WarehouseCode,a.LocationCode,'','','{3}',
  16245. '','1','15','{4}','0','',
  16246. '','','','{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) ,
  16247. SYSDATETIME() ,'{6}' ,''
  16248. FROM ICSWareHouseLotInfo a
  16249. WHERE a.LotNo='{7}' AND a.WorkPoint='{6}'
  16250. update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{7}' AND WorkPoint='{6}'
  16251. END ";
  16252. pikTbLogsql = string.Format(pikTbLogsql, Identification, item.TransCode, item.TransSequence, itemInfo.CurrentQuantity
  16253. , BusinessCode, item.User, item.WorkPoint, itemInfo.LotNo);
  16254. log.Debug("1");
  16255. if (!DBHelper.ExecuteNonQuery(pikTbLogsql, cmd))
  16256. {
  16257. throw new Exception("拣料失败!");
  16258. }
  16259. }
  16260. }
  16261. #endregion
  16262. #region 材料出库
  16263. else if ( TransType == TransTypeEnum.MOIssueDoc.GetDescription()
  16264. )
  16265. {
  16266. BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription<DBValue>();
  16267. foreach (var itemInfo in item.detail)
  16268. {
  16269. pikTbLogsql = @"
  16270. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{7}' AND a.WorkPoint='{6}' AND Quantity-LockQuantity-'{3}'<0)
  16271. BEGIN
  16272. RAISERROR(':" + "{7}" + @"',16,1);
  16273. RETURN
  16274. END
  16275. IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{7}' AND WorkPoint='{6}' AND TransType='15')
  16276. BEGIN
  16277. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  16278. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  16279. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  16280. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  16281. MTIME,WorkPoint,EATTRIBUTE1)
  16282. SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
  16283. a.WarehouseCode,a.LocationCode,'','','{3}',
  16284. '','1','15','{4}','0','',
  16285. '','','','{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) ,
  16286. SYSDATETIME() ,'{6}' ,''
  16287. FROM ICSWareHouseLotInfo a
  16288. WHERE a.LotNo='{7}' AND a.WorkPoint='{6}'
  16289. update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{7}' AND WorkPoint='{6}'
  16290. END ";
  16291. pikTbLogsql = string.Format(pikTbLogsql, Identification, item.TransCode, item.TransSequence, itemInfo.CurrentQuantity
  16292. , BusinessCode, item.User, item.WorkPoint, itemInfo.LotNo);
  16293. log.Debug("1");
  16294. if (!DBHelper.ExecuteNonQuery(pikTbLogsql, cmd))
  16295. {
  16296. throw new Exception("拣料失败!");
  16297. }
  16298. }
  16299. }
  16300. #endregion
  16301. #region 委外发料
  16302. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  16303. {
  16304. BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>();
  16305. foreach (var itemInfo in item.detail)
  16306. {
  16307. pikTbLogsql = @"
  16308. IF EXISTS(SELECT a.LotNo FROM ICSWareHouseLotInfo a WHERE a.LotNo='{7}' AND a.WorkPoint='{6}' AND Quantity-LockQuantity-'{3}'<0)
  16309. BEGIN
  16310. RAISERROR(':" + "{7}" + @"',16,1);
  16311. RETURN
  16312. END
  16313. IF NOT EXISTS(SELECT TransCode FROM ICSWareHouseLotInfoLog WHERE TransCode='{1}' AND TransSequence='{2}' AND LotNo='{7}' AND WorkPoint='{6}' AND TransType='15')
  16314. BEGIN
  16315. INSERT INTO ICSWareHouseLotInfoLog(ID,Identification,TransCode,TransSequence,LotNo,InvCode,
  16316. FromWarehouseCode,FromLocationCode,ToWarehouseCode,ToLocationCode,Quantity,
  16317. Memo,Lock,TransType,BusinessCode,ERPUpload,ERPID,
  16318. ERPDetailID,ERPCode,ERPSequence,MUSER,MUSERName,
  16319. MTIME,WorkPoint,EATTRIBUTE1)
  16320. SELECT NEWID(),'{0}','{1}','{2}',a.LotNo ,a.InvCode ,
  16321. a.WarehouseCode,a.LocationCode,'','','{3}',
  16322. '','1','15','{4}','0','',
  16323. '','','','{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) ,
  16324. SYSDATETIME() ,'{6}' ,''
  16325. FROM ICSWareHouseLotInfo a
  16326. WHERE a.LotNo='{7}' AND a.WorkPoint='{6}'
  16327. update ICSWareHouseLotInfo set LockQuantity=LockQuantity+'{3}' where LotNo='{7}' AND WorkPoint='{6}'
  16328. END ";
  16329. pikTbLogsql = string.Format(pikTbLogsql, Identification, item.TransCode, item.TransSequence, itemInfo.CurrentQuantity
  16330. , BusinessCode, item.User, item.WorkPoint, itemInfo.LotNo);
  16331. log.Debug("1");
  16332. if (!DBHelper.ExecuteNonQuery(pikTbLogsql, cmd))
  16333. {
  16334. throw new Exception("拣料失败!");
  16335. }
  16336. }
  16337. }
  16338. #endregion
  16339. else
  16340. {
  16341. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  16342. }
  16343. }
  16344. DataTable table = null;
  16345. cmd.Transaction.Commit();
  16346. return table;
  16347. }
  16348. catch (Exception ex)
  16349. {
  16350. if (cmd.Transaction != null)
  16351. cmd.Transaction.Rollback();
  16352. log.Error(ex.Message);
  16353. throw new Exception(ex.Message);
  16354. }
  16355. finally
  16356. {
  16357. if (conn.State == ConnectionState.Open)
  16358. {
  16359. conn.Close();
  16360. }
  16361. conn.Dispose();
  16362. }
  16363. }
  16364. }
  16365. /// <summary>
  16366. /// 回撤拣配
  16367. /// </summary>
  16368. /// <param name="JsonData"></param>
  16369. /// <returns></returns>
  16370. public static DataTable BackPickMerge(WMSSourceDocumentModel JsonData)
  16371. {
  16372. String PrintEnable = "";
  16373. var language = LanguageHelper.GetName("WMSAPIInfo");
  16374. //if (JsonData.Count <= 0)
  16375. //{
  16376. // throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  16377. //}
  16378. List<LOTStockModelList> model = new List<LOTStockModelList>();
  16379. DataTable printTable = new DataTable();
  16380. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  16381. {
  16382. conn.Open();
  16383. SqlTransaction sqlTran = conn.BeginTransaction();
  16384. SqlCommand cmd = new SqlCommand();
  16385. cmd.Transaction = sqlTran;
  16386. cmd.Connection = conn;
  16387. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  16388. string BusinessCode = string.Empty;
  16389. try
  16390. {
  16391. string TransType = string.Empty;
  16392. string pikTbLogsql = "";
  16393. string Identification = Guid.NewGuid().ToString();
  16394. //foreach (var item in JsonData)
  16395. //{
  16396. //TransType = item.TransType;
  16397. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  16398. {
  16399. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  16400. }
  16401. else if (string.IsNullOrEmpty(JsonData.TransCode))
  16402. {
  16403. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  16404. }
  16405. //string[] trans = item.TransCode.Split('~');
  16406. //string MergeID = "";
  16407. //if (trans.Length == 2)
  16408. //{
  16409. // MergeID = trans[0];
  16410. // item.TransCode = trans[1];
  16411. //}
  16412. #region 销售出库
  16413. else if (JsonData.TransType == TransTypeEnum.SalesShipmentDoc.GetDescription()
  16414. || JsonData.TransType == TransTypeEnum.MOIssueDoc.GetDescription()
  16415. || JsonData.TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  16416. {
  16417. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  16418. //更新源头单据数量
  16419. pikTbLogsql += string.Format(@" update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),c.Quantity )
  16420. from dbo.ICSWareHouseLotInfo b
  16421. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where TransCode ='{0}' and TransType='15' and WorkPoint='{1}' group by LotNo) c
  16422. on c.LotNo =b.LotNo ", JsonData.TransCode, JsonData.WorkPoint);
  16423. pikTbLogsql += string.Format(@" delete dbo.ICSWareHouseLotInfoLog where TransCode ='{0}' and TransType='15' and WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
  16424. if (!DBHelper.ExecuteNonQuery(pikTbLogsql, cmd))
  16425. {
  16426. throw new Exception("回撤拣料失败!");
  16427. }
  16428. }
  16429. #endregion
  16430. else
  16431. {
  16432. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  16433. }
  16434. //}
  16435. DataTable table = null;
  16436. cmd.Transaction.Commit();
  16437. return table;
  16438. }
  16439. catch (Exception ex)
  16440. {
  16441. if (cmd.Transaction != null)
  16442. cmd.Transaction.Rollback();
  16443. log.Error(ex.Message);
  16444. throw new Exception(ex.Message);
  16445. }
  16446. finally
  16447. {
  16448. if (conn.State == ConnectionState.Open)
  16449. {
  16450. conn.Close();
  16451. }
  16452. conn.Dispose();
  16453. }
  16454. }
  16455. }
  16456. /// <summary>
  16457. /// 回撤拣配
  16458. /// </summary>
  16459. /// <param name="JsonData"></param>
  16460. /// <returns></returns>
  16461. public static DataTable BackPickMergeALL(List<LOTStockModel> JsonData)
  16462. {
  16463. String PrintEnable = "";
  16464. var language = LanguageHelper.GetName("WMSAPIInfo");
  16465. if (JsonData.Count <= 0)
  16466. {
  16467. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  16468. }
  16469. List<LOTStockModelList> model = new List<LOTStockModelList>();
  16470. DataTable printTable = new DataTable();
  16471. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  16472. {
  16473. conn.Open();
  16474. SqlTransaction sqlTran = conn.BeginTransaction();
  16475. SqlCommand cmd = new SqlCommand();
  16476. cmd.Transaction = sqlTran;
  16477. cmd.Connection = conn;
  16478. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  16479. string BusinessCode = string.Empty;
  16480. try
  16481. {
  16482. string TransType = string.Empty;
  16483. string pikTbLogsql = "";
  16484. string Identification = Guid.NewGuid().ToString();
  16485. foreach (var item in JsonData)
  16486. {
  16487. TransType = item.TransType;
  16488. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  16489. {
  16490. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  16491. }
  16492. else if (string.IsNullOrEmpty(item.TransCode))
  16493. {
  16494. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  16495. }
  16496. string[] trans = item.TransCode.Split('~');
  16497. string MergeID = "";
  16498. if (trans.Length == 2)
  16499. {
  16500. MergeID = trans[0];
  16501. item.TransCode = trans[1];
  16502. }
  16503. #region 销售出库
  16504. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription()
  16505. || TransType == TransTypeEnum.MOIssueDoc.GetDescription()
  16506. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  16507. {
  16508. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  16509. //更新源头单据数量
  16510. pikTbLogsql += string.Format(@" update b set b.LockQuantity=convert(decimal(18,6),b.LockQuantity)-convert(decimal(18,6),c.Quantity )
  16511. from dbo.ICSWareHouseLotInfo b
  16512. inner join (select sum(Quantity) as Quantity, LotNo from ICSWareHouseLotInfolog where TransCode ='{0}' and TransType='15' and WorkPoint='{1}' group by LotNo) c
  16513. on c.LotNo =b.LotNo ", item.TransCode, item.WorkPoint);
  16514. pikTbLogsql += string.Format(@" delete dbo.ICSWareHouseLotInfoLog where TransCode ='{0}' and TransType='15' and WorkPoint='{1}'", item.TransCode, item.WorkPoint);
  16515. if (!DBHelper.ExecuteNonQuery(pikTbLogsql, cmd))
  16516. {
  16517. throw new Exception("整单回撤拣料失败!");
  16518. }
  16519. }
  16520. #endregion
  16521. else
  16522. {
  16523. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  16524. }
  16525. }
  16526. DataTable table = null;
  16527. cmd.Transaction.Commit();
  16528. return table;
  16529. }
  16530. catch (Exception ex)
  16531. {
  16532. if (cmd.Transaction != null)
  16533. cmd.Transaction.Rollback();
  16534. log.Error(ex.Message);
  16535. throw new Exception(ex.Message);
  16536. }
  16537. finally
  16538. {
  16539. if (conn.State == ConnectionState.Open)
  16540. {
  16541. conn.Close();
  16542. }
  16543. conn.Dispose();
  16544. }
  16545. }
  16546. }
  16547. /// <summary>
  16548. /// 获取周转箱信息(安多诚专用)
  16549. /// </summary>
  16550. /// <param name="JsonData"></param>
  16551. /// <returns></returns>
  16552. public static DataTable WorkingCapitalBoxGet(BarCodeModel JsonData)
  16553. {
  16554. var language = LanguageHelper.GetName("WMSAPIInfo");
  16555. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  16556. {
  16557. conn.Open();
  16558. SqlCommand cmd = new SqlCommand();
  16559. cmd.Connection = conn;
  16560. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  16561. try
  16562. {
  16563. if (string.IsNullOrEmpty(JsonData.WorkPoint))
  16564. {
  16565. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  16566. }
  16567. #region SLQ
  16568. string sql = @"";
  16569. #endregion
  16570. log.Debug("查询周转箱sql : " + sql);
  16571. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  16572. return table;
  16573. }
  16574. catch (Exception ex)
  16575. {
  16576. log.Error(ex.Message);
  16577. throw new Exception(ex.Message);
  16578. }
  16579. finally
  16580. {
  16581. if (conn.State == ConnectionState.Open)
  16582. {
  16583. conn.Close();
  16584. }
  16585. conn.Dispose();
  16586. }
  16587. }
  16588. }
  16589. #region
  16590. /// <summary>
  16591. /// 成品入库单 新建
  16592. /// </summary>
  16593. /// <param name="JsonData"></param>
  16594. /// <returns></returns>
  16595. public static DataTable FinishedProductWarehouseEntryCreate(List<FinishedProductWarehouseEntry> JsonData)
  16596. {
  16597. var language = LanguageHelper.GetName("WMSAPIInfo");
  16598. if (JsonData.Count <= 0)
  16599. {
  16600. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  16601. }
  16602. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  16603. {
  16604. conn.Open();
  16605. SqlTransaction sqlTran = conn.BeginTransaction();
  16606. SqlCommand cmd = new SqlCommand();
  16607. cmd.Transaction = sqlTran;
  16608. cmd.Connection = conn;
  16609. cmd.CommandTimeout = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["TimeOut"]);
  16610. try
  16611. {
  16612. string codes = string.Empty;
  16613. string sql = string.Empty;
  16614. foreach (var item in JsonData)
  16615. {
  16616. //获取单号
  16617. sql = @"DECLARE @MaxNO INT,@date varchar(20)='FRWE'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  16618. SELECT @MaxNO=SUBSTRING(MAX(RCVCode),LEN(@date)+1,LEN(MAX(RCVCode))-LEN(@date))+1 FROM ICSWMSManufactureReceive
  16619. WHERE SUBSTRING(RCVCode, 1, LEN(@date))=@date
  16620. IF @MaxNO IS NULL
  16621. BEGIN
  16622. SELECT @date+'00001' AS Code
  16623. END
  16624. ELSE
  16625. BEGIN
  16626. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  16627. END ";
  16628. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  16629. //创建主表
  16630. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{4}' AND F_Location='{6}')
  16631. BEGIN
  16632. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{4}") + @"',16,1);
  16633. RETURN
  16634. END
  16635. INSERT INTO [dbo].[ICSWMSManufactureReceive]
  16636. ([ID], [RCVCode], [Type], [Status], [WHCode], [CreatePerson], [MUSER], [MUSERName], [CreateDateTime], [MTIME], [WorkPoint], [EATTRIBUTE1], [EATTRIBUTE2], [EATTRIBUTE3], [EATTRIBUTE4], [EATTRIBUTE5], [EATTRIBUTE6], [EATTRIBUTE7], [EATTRIBUTE8], [EATTRIBUTE9], [EATTRIBUTE10], [ExtensionID])
  16637. VALUES
  16638. (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)";
  16639. sql = string.Format(sql, Code, item.Type, item.Status, item.WHCode, item.MUSER,item.MTIME,item.WorkPoint );
  16640. log.Debug("成品入库单主表:" + sql);
  16641. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  16642. {
  16643. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  16644. }
  16645. foreach (var itemInfo in item.detail)
  16646. {
  16647. //创建子表
  16648. sql = @"INSERT INTO [dbo].[ICSWMSManufactureReceiveDetail]
  16649. ([ID], [RCVCode], [Sequence], [LotNo], [SourceCode], [SourceSequence], [InvCode], [Quantity], [ExtensionID], [MUSER], [MUSERName], [MTIME], [WorkPoint], [EATTRIBUTE1], [EATTRIBUTE2], [EATTRIBUTE3], [EATTRIBUTE4], [EATTRIBUTE5], [EATTRIBUTE6], [EATTRIBUTE7], [EATTRIBUTE8], [EATTRIBUTE9], [EATTRIBUTE10])
  16650. VALUES
  16651. (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)";
  16652. 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 );
  16653. log.Debug("成品入库单子表:" + sql);
  16654. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  16655. {
  16656. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  16657. }
  16658. }
  16659. ////校验退料数量是否超出领料数量
  16660. //sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  16661. //DBHelper.ExecuteNonQuery(sql, cmd);
  16662. codes += "'" + Code + item.WorkPoint + "',";
  16663. }
  16664. if (string.IsNullOrWhiteSpace(codes))
  16665. {
  16666. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  16667. }
  16668. #region 查询返回数据
  16669. sql = @"SELECT a.RCVCode,
  16670. c.WHCode,
  16671. c.Status,
  16672. a.Sequence,
  16673. a.InvCode,
  16674. inv.InvName,
  16675. inv.InvStd,
  16676. a.Quantity,
  16677. inv.InvUnit,
  16678. a.Amount,
  16679. inv.AmountUnit,
  16680. ext.ProjectCode,
  16681. ext.BatchCode,
  16682. ext.Version,
  16683. ext.Brand,
  16684. ext.cFree1,
  16685. ext.cFree2,
  16686. ext.cFree3,
  16687. ext.cFree4,
  16688. ext.cFree5,
  16689. ext.cFree6,
  16690. ext.cFree7,
  16691. ext.cFree8,
  16692. ext.cFree9,
  16693. ext.cFree10,
  16694. a.MUSER AS [User],
  16695. a.MTIME AS [MTime]
  16696. FROM ICSWMSManufactureReceiveDetail a
  16697. INNER JOIN ICSWMSManufactureReceive c ON a.RCVCode=c.RCVCode AND a.WorkPoint=c.WorkPoint
  16698. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  16699. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  16700. WHERE a.RCVCode+a.WorkPoint IN ({0})";
  16701. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  16702. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  16703. #endregion
  16704. cmd.Transaction.Commit();
  16705. return data;
  16706. }
  16707. catch (Exception ex)
  16708. {
  16709. if (cmd.Transaction != null)
  16710. cmd.Transaction.Rollback();
  16711. log.Error(ex.Message);
  16712. throw new Exception(ex.Message);
  16713. }
  16714. finally
  16715. {
  16716. if (conn.State == ConnectionState.Open)
  16717. {
  16718. conn.Close();
  16719. }
  16720. conn.Dispose();
  16721. }
  16722. }
  16723. }
  16724. #endregion
  16725. }
  16726. }