爱思开
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5437 lines
303 KiB

2 years 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. #region 源头单据信息
  24. /// <summary>
  25. /// 源头单据信息
  26. /// </summary>
  27. /// <param name="JsonData"></param>
  28. /// <returns></returns>
  29. public static DataTable TransInformationGet(WMSSourceDocumentModel JsonData)
  30. {
  31. var language = LanguageHelper.GetName("WMSAPIInfo");
  32. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  33. {
  34. conn.Open();
  35. SqlCommand cmd = new SqlCommand();
  36. cmd.Connection = conn;
  37. try
  38. {
  39. if (string.IsNullOrEmpty(JsonData.TransCode))
  40. {
  41. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  42. }
  43. else if (string.IsNullOrEmpty(JsonData.TransType))
  44. {
  45. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  46. }
  47. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  48. {
  49. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  50. }
  51. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  52. {
  53. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  54. }
  55. string TransType = JsonData.TransType;
  56. #region SLQ
  57. string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  58. BEGIN
  59. RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  60. RETURN
  61. END
  62. ";
  63. string sql = @"SELECT a.ID,
  64. {0}
  65. a.InvCode,
  66. inv.InvName,
  67. inv.InvStd,
  68. a.Quantity,
  69. inv.InvUnit,
  70. a.Amount,
  71. a.WHCode,
  72. inv.AmountUnit,
  73. wh.WarehouseName AS WHName,
  74. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  75. a.ExtensionID,
  76. 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,
  77. ISNULL(ext.Version, '') AS Version,
  78. ISNULL(ext.Brand, '') AS Brand,
  79. ISNULL(ext.cFree1, '') AS cFree1,
  80. ISNULL(ext.cFree2, '') AS cFree2,
  81. ISNULL(ext.cFree3, '') AS cFree3,
  82. ISNULL(ext.cFree4, '') AS cFree4,
  83. ISNULL(ext.cFree5, '') AS cFree5,
  84. ISNULL(ext.cFree6, '') AS cFree6,
  85. ISNULL(ext.cFree7, '') AS cFree7,
  86. ISNULL(ext.cFree8, '') AS cFree8,
  87. ISNULL(ext.cFree9, '') AS cFree9,
  88. ISNULL(ext.cFree10, '') AS cFree10,
  89. a.MUSER AS [User],
  90. a.MTIME AS [MTime]
  91. FROM {1}
  92. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  93. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  94. LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  95. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  96. WHERE {2} ";
  97. #endregion
  98. bool isDeliveryNotice = false; //送货、到货、含委外
  99. string columns = string.Empty; //查询源头单据表的特殊列名
  100. string tableName = string.Empty; //查询源头单据表名
  101. string where = string.Empty; //查询源头单据的过滤条件
  102. bool isMerge = false; //合并发料
  103. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  104. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  105. #region 出库
  106. #region 采购退货
  107. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  108. {
  109. isDeliveryNotice = true;
  110. columns = @"a.DNCode AS TransCode,
  111. a.DNDetailID AS DetailID,
  112. a.DNType AS Type,
  113. a.Sequence AS TransSequence,
  114. a.RCVQuantity AS IssueQuantity,
  115. a.Quantity,
  116. a.Amount,
  117. a.MUSER AS [User],
  118. a.MTIME AS [MTime],";
  119. tableName = @"ICSDeliveryNotice a ";
  120. where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' ";
  121. }
  122. #endregion
  123. #region 委外发料(合并发料)
  124. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  125. {
  126. isMerge = true;
  127. columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
  128. a.PickID AS DetailID,
  129. a.SupplyType AS Type,
  130. b.Sequence+'~'+a.Sequence AS TransSequence,
  131. a.IssueQuantity AS IssueQuantity,";
  132. tableNameMerge = @"ICSOOPick a
  133. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  134. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  135. columns = @"b.OOCode AS TransCode,
  136. a.PickID AS DetailID,
  137. a.SupplyType AS Type,
  138. b.Sequence+'~'+a.Sequence AS TransSequence,
  139. a.IssueQuantity AS IssueQuantity,";
  140. tableName = @"ICSOOPick a
  141. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  142. where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' ";
  143. }
  144. #endregion
  145. #region 委外退货
  146. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  147. {
  148. isDeliveryNotice = true;
  149. columns = @"a.ODNCode AS TransCode,
  150. a.ODNDetailID AS DetailID,
  151. a.ODNType AS Type,
  152. a.Sequence AS TransSequence,
  153. a.RCVQuantity AS IssueQuantity,
  154. a.Quantity,
  155. a.Amount,
  156. a.MUSER AS [User],
  157. a.MTIME AS [MTime],";
  158. tableName = @"ICSODeliveryNotice a ";
  159. where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' ";
  160. }
  161. #endregion
  162. #region 生产发料(合并发料)
  163. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  164. {
  165. isMerge = true;
  166. columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  167. a.PickID AS DetailID,
  168. a.SupplyType AS Type,
  169. b.Sequence+'~'+a.Sequence AS TransSequence,
  170. a.IssueQuantity AS IssueQuantity,";
  171. tableNameMerge = @"ICSMOPick a
  172. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  173. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  174. columns = @"b.MOCode AS TransCode,
  175. a.PickID AS DetailID,
  176. a.SupplyType AS Type,
  177. b.Sequence+'~'+a.Sequence AS TransSequence,
  178. a.IssueQuantity AS IssueQuantity,";
  179. tableName = @"ICSMOPick a
  180. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  181. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' ";
  182. }
  183. #endregion
  184. #region 销售出库(合并发料)
  185. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  186. {
  187. isMerge = true;
  188. columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
  189. a.SDNDetailID AS DetailID,
  190. a.Type,
  191. a.Sequence AS TransSequence,
  192. a.SDNQuantity AS IssueQuantity,";
  193. tableNameMerge = @"ICSSDN a
  194. INNER JOIN ICSMOPickMerge mer ON a.SDNDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  195. columns = @"a.SDNCode AS TransCode,
  196. a.SDNDetailID AS DetailID,
  197. a.Type,
  198. a.Sequence AS TransSequence,
  199. a.SDNQuantity AS IssueQuantity,";
  200. tableName = @"ICSSDN a ";
  201. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' ";
  202. }
  203. #endregion
  204. #region 盘点
  205. else if (TransType == TransTypeEnum.Check.GetDescription())
  206. {
  207. #region SLQ
  208. sql = @"SELECT a.ID,
  209. {0}
  210. a.Quantity,
  211. a.SelectLevel AS LocationCode,
  212. a.Amount,
  213. a.MUSER AS [User],
  214. a.MTIME AS [MTime],
  215. a.InvCode,
  216. a.SelectLevel as WHCode,
  217. a.BatchCode
  218. FROM {1}
  219. WHERE {2} ";
  220. #endregion
  221. columns = @"a.CheckCode AS TransCode,
  222. a.ID,
  223. '' AS Type,";
  224. tableName = @"ICSCheck a ";
  225. where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' ";
  226. }
  227. #endregion
  228. #region 一步调拨(合并发料)
  229. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  230. {
  231. isMerge = true;
  232. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  233. a.TransferDetailID AS DetailID,
  234. '' AS Type,
  235. a.Sequence AS TransSequence,
  236. a.TransferQuantity AS IssueQuantity,
  237. a.ToWarehouseCode,";
  238. tableNameMerge = @"ICSTransfer a
  239. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  240. #region SLQ
  241. sql = @"SELECT a.ID,
  242. {0}
  243. a.InvCode,
  244. inv.InvName,
  245. inv.InvStd,
  246. a.Quantity,
  247. inv.InvUnit,
  248. a.Amount,
  249. a.FromWarehouseCode AS WHCode,
  250. inv.AmountUnit,
  251. wh.WarehouseName AS WHName,
  252. a.ExtensionID,
  253. ext.ProjectCode,
  254. 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,
  255. ext.Version,
  256. ext.Brand,
  257. ext.cFree1,
  258. ext.cFree2,
  259. ext.cFree3,
  260. ext.cFree4,
  261. ext.cFree5,
  262. ext.cFree6,
  263. ext.cFree7,
  264. ext.cFree8,
  265. ext.cFree9,
  266. ext.cFree10,
  267. a.MUSER AS [User],
  268. a.MTIME AS [MTime]
  269. FROM {1}
  270. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  271. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  272. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  273. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  274. WHERE {2} ";
  275. #endregion
  276. columns = @"a.TransferNO AS TransCode,
  277. a.TransferDetailID AS DetailID,
  278. '' AS Type,
  279. a.Sequence AS TransSequence,
  280. a.TransferQuantity AS IssueQuantity,
  281. a.ToWarehouseCode,";
  282. tableName = @"ICSTransfer a ";
  283. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='2' ";
  284. }
  285. #endregion
  286. #region 调拨(合并发料)
  287. else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
  288. {
  289. }
  290. #endregion
  291. #region 两步调出(合并发料)
  292. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  293. {
  294. isMerge = true;
  295. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  296. a.OutDetailID AS DetailID,
  297. '' AS Type,
  298. a.Sequence AS TransSequence,
  299. a.OutQuantity AS IssueQuantity,";
  300. tableNameMerge = @"ICSOtherOut a
  301. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  302. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  303. columns = @"a.OutCode AS TransCode,
  304. a.OutDetailID AS DetailID,
  305. '' AS Type,
  306. a.Sequence AS TransSequence,
  307. a.OutQuantity AS IssueQuantity,";
  308. tableName = @"ICSOtherOut a
  309. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  310. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' ";
  311. }
  312. #endregion
  313. #region 其他出库(合并发料)
  314. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  315. {
  316. isMerge = true;
  317. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  318. a.OutDetailID AS DetailID,
  319. '' AS Type,
  320. a.Sequence AS TransSequence,
  321. a.OutQuantity AS IssueQuantity,";
  322. tableNameMerge = @"ICSOtherOut a
  323. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  324. columns = @"a.OutCode AS TransCode,
  325. a.OutDetailID AS DetailID,
  326. '' AS Type,
  327. a.Sequence AS TransSequence,
  328. a.OutQuantity AS IssueQuantity,";
  329. tableName = @"ICSOtherOut a ";
  330. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' ";
  331. }
  332. #endregion
  333. #region 领料申请单发料(合并发料)
  334. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  335. {
  336. isMerge = true;
  337. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  338. a.ApplyDetailID AS DetailID,
  339. a.Type,
  340. a.Sequence AS TransSequence,
  341. a.IssueQuantity AS IssueQuantity,";
  342. tableNameMerge = @"ICSMOApply a
  343. INNER JOIN ICSMOPickMerge mer ON a.ApplyDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  344. columns = @"a.ApplyCode AS TransCode,
  345. a.ApplyDetailID AS DetailID,
  346. a.Type,
  347. a.Sequence AS TransSequence,
  348. a.IssueQuantity AS IssueQuantity,";
  349. tableName = @"ICSMOApply a ";
  350. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' ";
  351. }
  352. #endregion
  353. #region 委外领料申请单发料(合并发料)
  354. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  355. {
  356. isMerge = true;
  357. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  358. a.ApplyDetailID AS DetailID,
  359. a.Type,
  360. a.Sequence AS TransSequence,
  361. a.IssueQuantity AS IssueQuantity,";
  362. tableNameMerge = @"ICSOApply a
  363. INNER JOIN ICSMOPickMerge mer ON a.ApplyDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  364. columns = @"a.ApplyCode AS TransCode,
  365. a.ApplyDetailID AS DetailID,
  366. a.Type,
  367. a.Sequence AS TransSequence,
  368. a.IssueQuantity AS IssueQuantity,";
  369. tableName = @"ICSOApply a ";
  370. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' ";
  371. }
  372. #endregion
  373. #region 开立材料出库(合并发料)
  374. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  375. {
  376. isMerge = true;
  377. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  378. a.IssueDetailID AS DetailID,
  379. a.Type,
  380. a.Sequence AS TransSequence,
  381. a.IssueQuantity AS IssueQuantity,";
  382. tableNameMerge = @"ICSMOIssue a
  383. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  384. columns = @"a.IssueCode AS TransCode,
  385. a.IssueDetailID AS DetailID,
  386. a.Type,
  387. a.Sequence AS TransSequence,
  388. a.IssueQuantity AS IssueQuantity,";
  389. tableName = @"ICSMOIssue a ";
  390. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' ";
  391. }
  392. #endregion
  393. #region 开立委外材料出库(合并发料)
  394. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  395. {
  396. isMerge = true;
  397. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  398. a.IssueDetailID AS DetailID,
  399. a.Type,
  400. a.Sequence AS TransSequence,
  401. a.IssueQuantity AS IssueQuantity,";
  402. tableNameMerge = @"ICSOIssue a
  403. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  404. columns = @"a.IssueCode AS TransCode,
  405. a.IssueDetailID AS DetailID,
  406. a.Type,
  407. a.Sequence AS TransSequence,
  408. a.IssueQuantity AS IssueQuantity,";
  409. tableName = @"ICSOIssue a ";
  410. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' ";
  411. }
  412. #endregion
  413. #region 开立红字入库单
  414. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  415. {
  416. columns = @"a.RCVCode AS TransCode,
  417. a.RCVDetailID AS DetailID,
  418. a.Type,
  419. a.Sequence AS TransSequence,
  420. a.RCVQuantity AS IssueQuantity,";
  421. tableName = @"ICSPurchaseReceive a ";
  422. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  423. }
  424. #endregion
  425. #region 开立委外红字入库单
  426. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  427. {
  428. columns = @"a.RCVCode AS TransCode,
  429. a.RCVDetailID AS DetailID,
  430. a.Type,
  431. a.Sequence AS TransSequence,
  432. a.RCVQuantity AS IssueQuantity,";
  433. tableName = @"ICSOutsourcingReceive a ";
  434. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  435. }
  436. #endregion
  437. #region 借用(合并发料)
  438. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  439. {
  440. isMerge = true;
  441. columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
  442. a.BrrowDetailID AS DetailID,
  443. '' AS Type,
  444. a.Sequence AS TransSequence,
  445. a.BrrowQuantity AS IssueQuantity,";
  446. tableNameMerge = @"ICSBrrow a
  447. INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  448. columns = @"a.BrrowCode AS TransCode,
  449. a.BrrowDetailID AS DetailID,
  450. '' AS Type,
  451. a.Sequence AS TransSequence,
  452. a.BrrowQuantity AS IssueQuantity,";
  453. tableName = @"ICSBrrow a ";
  454. where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' ";
  455. }
  456. #endregion
  457. #region 送货单
  458. else if (TransType == TransTypeEnum.ASN.GetDescription())
  459. {
  460. isDeliveryNotice = true;
  461. columns = @"asn.ASNCode AS TransCode,
  462. asn.ID AS DetailID,
  463. asn.LotNo,
  464. '' AS Type,
  465. asn.Sequence AS TransSequence,
  466. asn.DNQuantity AS IssueQuantity,
  467. asn.Quantity,
  468. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  469. asn.MUSER AS [User],
  470. asn.MTIME AS [MTime],";
  471. tableName = @"ICSInventoryLot a
  472. INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  473. where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
  474. }
  475. #endregion
  476. #region 委外送货单
  477. else if (TransType == TransTypeEnum.OASN.GetDescription())
  478. {
  479. isDeliveryNotice = true;
  480. columns = @"asn.OASNCode AS TransCode,
  481. asn.ID AS DetailID,
  482. asn.LotNo,
  483. '' AS Type,
  484. asn.Sequence AS TransSequence,
  485. asn.ODNQuantity AS IssueQuantity,
  486. asn.Quantity,
  487. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  488. asn.MUSER AS [User],
  489. asn.MTIME AS [MTime],";
  490. tableName = @"ICSInventoryLot a
  491. INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  492. where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
  493. }
  494. #endregion
  495. #endregion
  496. #region 入库
  497. #region 采购入库
  498. else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  499. {
  500. // isMerge = true;
  501. // columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  502. // a.PickID AS DetailID,
  503. // a.SupplyType AS Type,
  504. // b.Sequence+'~'+a.Sequence AS TransSequence,
  505. // a.IssueQuantity AS IssueQuantity,";
  506. // tableNameMerge = @"ICSMOPick a
  507. // INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  508. // INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  509. // columns = @"b.MOCode AS TransCode,
  510. // a.PickID AS DetailID,
  511. // a.SupplyType AS Type,
  512. // b.Sequence+'~'+a.Sequence AS TransSequence,
  513. // a.IssueQuantity AS IssueQuantity,";
  514. // tableName = @"ICSMOPick a
  515. // INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  516. // where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' ";
  517. }
  518. #endregion
  519. #region 审核的到货单
  520. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  521. {
  522. }
  523. #endregion
  524. #region 采购拒收
  525. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  526. {
  527. }
  528. #endregion
  529. #region 审核的委外到货单
  530. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  531. {
  532. }
  533. #endregion
  534. #region 委外拒收
  535. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  536. {
  537. }
  538. #endregion
  539. #region 委外退料
  540. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  541. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  542. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  543. {
  544. }
  545. #endregion
  546. #region 委外入库
  547. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  548. {
  549. }
  550. #endregion
  551. #region 生产退料
  552. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  553. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  554. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  555. {
  556. }
  557. #endregion
  558. #region 生产入库
  559. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  560. {
  561. }
  562. #endregion
  563. #region 开立的生产入库单
  564. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  565. {
  566. }
  567. #endregion
  568. #region 返工工单
  569. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  570. {
  571. }
  572. #endregion
  573. #region 销售退货
  574. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  575. {
  576. columns = @"a.SDNCode AS TransCode,
  577. a.SDNDetailID AS DetailID,
  578. a.Type,
  579. a.Sequence AS TransSequence,
  580. a.SDNQuantity AS IssueQuantity,";
  581. tableName = @"ICSSDN a ";
  582. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  583. }
  584. #endregion
  585. #region 两步调入
  586. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  587. {
  588. columns = @"a.InCode AS TransCode,
  589. a.InDetailID AS DetailID,
  590. '' AS Type,
  591. a.Sequence AS TransSequence,
  592. a.InQuantity AS IssueQuantity,";
  593. tableName = @"ICSOtherIn a
  594. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  595. where = @" a.InCode='{0}' AND a.WorkPoint='{1}' ";
  596. }
  597. #endregion
  598. #region 销售退货-原条码
  599. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  600. {
  601. columns = @"a.SDNCode AS TransCode,
  602. a.SDNDetailID AS DetailID,
  603. a.Type,
  604. a.Sequence AS TransSequence,
  605. a.SDNQuantity AS IssueQuantity,";
  606. tableName = @"ICSSDN a ";
  607. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  608. }
  609. #endregion
  610. #region 其他入库
  611. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  612. {
  613. }
  614. #endregion
  615. #region 拆卸单
  616. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  617. {
  618. columns = @"a.DABDOCCode AS TransCode,
  619. a.DABDOCDetailID AS DetailID,
  620. a.DABDOCType AS Type,
  621. a.Sequence AS TransSequence,
  622. a.DABDOCQuantity AS IssueQuantity,";
  623. tableName = @"ICSDisassemblyDoc a";
  624. where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' ";
  625. }
  626. #endregion
  627. #region 归还
  628. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  629. {
  630. }
  631. #endregion
  632. #endregion
  633. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
  634. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  635. if (isDeliveryNotice)//送货、到货、含委外
  636. {
  637. #region SLQ
  638. sql = sqlCheck + @"SELECT a.ID,
  639. {0}
  640. a.InvCode,
  641. inv.InvName,
  642. inv.InvStd,
  643. inv.InvUnit,
  644. '' AS WHCode,
  645. inv.AmountUnit,
  646. '' AS WHName,
  647. a.ExtensionID,
  648. ext.ProjectCode,
  649. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  650. ext.Version,
  651. ext.Brand,
  652. ext.cFree1,
  653. ext.cFree2,
  654. ext.cFree3,
  655. ext.cFree4,
  656. ext.cFree5,
  657. ext.cFree6,
  658. ext.cFree7,
  659. ext.cFree8,
  660. ext.cFree9,
  661. ext.cFree10
  662. FROM {1}
  663. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  664. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  665. WHERE {2} ";
  666. #endregion
  667. }
  668. else if (isMerge)//合并发料
  669. {
  670. #region SLQ
  671. string sqlMerge = @"IF EXISTS(SELECT ID FROM ICSMOPickMerge WHERE MergeID='{3}' AND WorkPoint='{4}' )
  672. BEGIN
  673. " + sql;
  674. string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
  675. sqlMerge = string.Format(sqlMerge, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, JsonData.WorkPoint);
  676. sql = sqlMerge + @"
  677. END
  678. ELSE
  679. BEGIN
  680. IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
  681. BEGIN
  682. RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
  683. RETURN
  684. END
  685. " + sqlCheck + sql + @"
  686. END";
  687. #endregion
  688. }
  689. else
  690. {
  691. sql = sqlCheck + sql;
  692. }
  693. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint);
  694. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode);
  695. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  696. return table;
  697. }
  698. catch (Exception ex)
  699. {
  700. log.Error(ex.Message);
  701. throw new Exception(ex.Message);
  702. }
  703. finally
  704. {
  705. if (conn.State == ConnectionState.Open)
  706. {
  707. conn.Close();
  708. }
  709. conn.Dispose();
  710. }
  711. }
  712. }
  713. #endregion
  714. #region 条码信息
  715. /// <summary>
  716. /// 条码信息
  717. /// </summary>
  718. /// <param name="JsonData"></param>
  719. /// <returns></returns>
  720. public static Result BarCodeInformationGet(BarCodeModel JsonData)
  721. {
  722. var language = LanguageHelper.GetName("WMSAPIInfo");
  723. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  724. {
  725. conn.Open();
  726. SqlCommand cmd = new SqlCommand();
  727. cmd.Connection = conn;
  728. try
  729. {
  730. string ScanType = DBHelper.ScanTypeCheck(JsonData.Code, JsonData.WorkPoint, cmd);
  731. if (string.IsNullOrEmpty(JsonData.Code))
  732. {
  733. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  734. }
  735. else if (string.IsNullOrEmpty(JsonData.TransType))
  736. {
  737. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  738. }
  739. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  740. {
  741. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  742. }
  743. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  744. {
  745. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  746. }
  747. string TransType = JsonData.TransType;
  748. string sql = "";
  749. string sqlNew = "";
  750. #region SLQ
  751. if (ScanType == "LOTNO")
  752. {
  753. sql = @"SELECT a.ID,
  754. con.ContainerCode,
  755. con.ContainerName,
  756. a.LotNo,
  757. a.InvCode,
  758. inv.InvName,
  759. inv.InvStd,
  760. inv.InvUnit,
  761. {0}
  762. inv.AmountUnit,
  763. ext.ID AS ExtensionID,
  764. ext.ProjectCode,
  765. ext.Version,
  766. ext.Brand,
  767. ext.cFree1,
  768. ext.cFree2,
  769. ext.cFree3,
  770. ext.cFree4,
  771. ext.cFree5,
  772. ext.cFree6,
  773. ext.cFree7,
  774. ext.cFree8,
  775. ext.cFree9,
  776. ext.cFree10,
  777. a.MUSER AS [User],
  778. a.MTIME AS [MTime]
  779. FROM {1}
  780. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  781. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  782. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  783. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' ";
  784. }
  785. else
  786. {
  787. sql = @"SELECT a.ID,
  788. con.ContainerCode,
  789. con.ContainerName,
  790. a.LotNo,
  791. a.InvCode,
  792. inv.InvName,
  793. inv.InvStd,
  794. inv.InvUnit,
  795. {0}
  796. inv.AmountUnit,
  797. ext.ID AS ExtensionID,
  798. ext.ProjectCode,
  799. ext.Version,
  800. ext.Brand,
  801. ext.cFree1,
  802. ext.cFree2,
  803. ext.cFree3,
  804. ext.cFree4,
  805. ext.cFree5,
  806. ext.cFree6,
  807. ext.cFree7,
  808. ext.cFree8,
  809. ext.cFree9,
  810. ext.cFree10,
  811. a.MUSER AS [User],
  812. a.MTIME AS [MTime]
  813. FROM {1}
  814. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  815. LEFT JOIN ICSBomALL bom ON bom.ID=conlot.ContainerID
  816. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  817. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  818. WHERE bom.ContainerCode='{2}' AND a.WorkPoint='{3}' ";
  819. }
  820. #endregion
  821. bool isOut = false; //出库标记
  822. string columns = string.Empty; //查询源头单据表的特殊列名
  823. string tableName = string.Empty; //查询源头单据表名
  824. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription() //采购退货
  825. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() //委外发料
  826. || TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription() //委外退货
  827. || TransType == TransTypeEnum.MOIssueDoc.GetDescription() //生产发料
  828. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() //销售出库
  829. || TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription() //一步调拨
  830. || TransType == TransTypeEnum.StepTransferDocIn.GetDescription() //调拨
  831. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() //两步调出
  832. || TransType == TransTypeEnum.OtherOutDoc.GetDescription() //其他出库
  833. || TransType == TransTypeEnum.Check.GetDescription() //盘点
  834. || TransType == TransTypeEnum.MOApply.GetDescription() //领料申请单
  835. || TransType == TransTypeEnum.OOApply.GetDescription() //委外领料申请单
  836. || TransType == TransTypeEnum.MOIssue.GetDescription() //开立材料出库单
  837. || TransType == TransTypeEnum.OOIssue.GetDescription() //开立委外材料出库单
  838. || TransType == TransTypeEnum.PurchaseReceive.GetDescription() //开立红字入库单
  839. || TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription()//开立委外红字入库单
  840. || TransType == TransTypeEnum.BrrowDoc.GetDescription() //借用
  841. || TransType == TransTypeEnum.TransferLibrary.GetDescription() //移库
  842. //|| TransType == TransTypeEnum.DisassemblyDoc.GetDescription() //拆卸单(散件生成条码入库)
  843. )
  844. {
  845. isOut = true;
  846. }
  847. //两步调入条码
  848. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  849. {
  850. if (string.IsNullOrEmpty(JsonData.TransCode))
  851. {
  852. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  853. }
  854. if (ScanType == "LOTNO")
  855. {
  856. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSOtherIn Otin
  857. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  858. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  859. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  860. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  861. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND Otin.InCode = '" + JsonData.TransCode + @"')
  862. BEGIN
  863. RAISERROR('" + language.GetNameByCode("WMSAPIInfo036") + @"',16,1);
  864. RETURN
  865. END
  866. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  867. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  868. 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,
  869. 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";
  870. columns = @"SUM(log.Quantity) AS Quantity,
  871. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  872. a.WarehouseCode AS WHCode,
  873. wh.WarehouseName AS WHName,
  874. a.LocationCode,
  875. loc.LocationName,
  876. 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,";
  877. tableName = @"ICSOtherIn Otin
  878. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  879. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  880. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  881. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  882. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  883. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  884. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  885. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  886. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  887. }
  888. else
  889. {
  890. sql = @"WITH ICSBomALL AS
  891. (
  892. SELECT
  893. ContainerCode AS TContainerCode,
  894. ContainerCode AS PContainerCode,
  895. ContainerCode AS ContainerCode,
  896. ID,
  897. ContainerID,
  898. 0 AS [Level],
  899. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  900. CAST('00001' AS nvarchar(MAX)) AS Sort
  901. FROM ICSContainer
  902. WHERE ContainerCode='{2}'
  903. UNION ALL
  904. SELECT
  905. b.TContainerCode,
  906. b.ContainerCode AS PContainerCode,
  907. a.ContainerCode,
  908. a.ID,
  909. a.ContainerID,
  910. b.[Level]+1 AS [Level],
  911. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  912. 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
  913. FROM
  914. ICSContainer a
  915. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  916. )
  917. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  918. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  919. 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,
  920. 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";
  921. columns = @"SUM(log.Quantity) AS Quantity,
  922. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  923. a.WarehouseCode AS WHCode,
  924. wh.WarehouseName AS WHName,
  925. a.LocationCode,
  926. loc.LocationName,
  927. 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,";
  928. tableName = @"ICSOtherIn Otin
  929. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  930. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  931. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  932. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  933. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  934. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  935. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  936. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  937. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  938. }
  939. }
  940. //销售退货-原条码(可支持一个条码多次发货,汇总数量,目前加了限制:785-793行)
  941. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  942. {
  943. if (string.IsNullOrEmpty(JsonData.TransCode))
  944. {
  945. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  946. }
  947. if (ScanType == "LOTNO")
  948. {
  949. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSSDN sdn
  950. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  951. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  952. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1')
  953. BEGIN
  954. RAISERROR('" + language.GetNameByCode("WMSAPIInfo037") + @"',16,1);
  955. RETURN
  956. END
  957. IF EXISTS(SELECT log.LotNo FROM ICSSDN sdn
  958. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  959. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  960. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1' AND log.BusinessCode='19'
  961. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  962. BEGIN
  963. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo191"), "{2}") + @"',16,1);
  964. RETURN
  965. END
  966. " + sql + @"AND sdn.Type='1'
  967. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  968. 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,
  969. 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";
  970. columns = @"SUM(log.Quantity) AS Quantity,
  971. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  972. a.WarehouseCode AS WHCode,
  973. wh.WarehouseName AS WHName,
  974. a.LocationCode,
  975. loc.LocationName,
  976. 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,";
  977. tableName = @"ICSSDN sdn
  978. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  979. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  980. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  981. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  982. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  983. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  984. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  985. }
  986. else
  987. {
  988. sql = @"WITH ICSBomALL AS
  989. (
  990. SELECT
  991. ContainerCode AS TContainerCode,
  992. ContainerCode AS PContainerCode,
  993. ContainerCode AS ContainerCode,
  994. ID,
  995. ContainerID,
  996. 0 AS [Level],
  997. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  998. CAST('00001' AS nvarchar(MAX)) AS Sort
  999. FROM ICSContainer
  1000. WHERE ContainerCode='{2}'
  1001. UNION ALL
  1002. SELECT
  1003. b.TContainerCode,
  1004. b.ContainerCode AS PContainerCode,
  1005. a.ContainerCode,
  1006. a.ID,
  1007. a.ContainerID,
  1008. b.[Level]+1 AS [Level],
  1009. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1010. 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
  1011. FROM
  1012. ICSContainer a
  1013. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1014. )
  1015. " + sql + @"AND sdn.Type='1'
  1016. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1017. 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,
  1018. 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";
  1019. columns = @"SUM(log.Quantity) AS Quantity,
  1020. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1021. a.WarehouseCode AS WHCode,
  1022. wh.WarehouseName AS WHName,
  1023. a.LocationCode,
  1024. loc.LocationName,
  1025. 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,";
  1026. tableName = @"ICSSDN sdn
  1027. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  1028. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1029. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1030. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1031. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1032. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1033. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1034. }
  1035. }
  1036. //生产(委外)退料-原条码+新条码
  1037. //先校验日志里面是否有原条码(同一种类型的条码只能发一次料才能原条码退,不然更新源头单据数量有问题,根据LogID判断是否原条码退回),如果没有查询新条码
  1038. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1039. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1040. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription()
  1041. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1042. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1043. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1044. {
  1045. string type = "13";
  1046. string msglanguage = "WMSAPIInfo185";
  1047. if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  1048. {
  1049. type = "14";
  1050. msglanguage = "WMSAPIInfo186";
  1051. }
  1052. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1053. {
  1054. type = "15";
  1055. msglanguage = "WMSAPIInfo187";
  1056. }
  1057. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  1058. {
  1059. type = "5";
  1060. msglanguage = "WMSAPIInfo188";
  1061. }
  1062. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  1063. {
  1064. type = "6";
  1065. msglanguage = "WMSAPIInfo189";
  1066. }
  1067. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1068. {
  1069. type = "7";
  1070. msglanguage = "WMSAPIInfo190";
  1071. }
  1072. #region 新条码
  1073. if (ScanType == "LOTNO")
  1074. {
  1075. sqlNew = @"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1076. BEGIN
  1077. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  1078. RETURN
  1079. END
  1080. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1081. BEGIN
  1082. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  1083. RETURN
  1084. END
  1085. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  1086. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1087. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  1088. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1'AND ins.LotNo IS NULL))
  1089. BEGIN
  1090. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  1091. RETURN
  1092. END
  1093. " + sql;
  1094. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1095. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1096. '' AS WHCode,
  1097. '' AS WHName,
  1098. '' AS LocationCode,
  1099. '' AS LocationName,
  1100. ext.BatchCode AS BatchCode,";
  1101. tableName = @"ICSInventoryLot a
  1102. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1103. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1104. }
  1105. else
  1106. {
  1107. sqlNew = @"WITH ICSBomALL AS
  1108. (
  1109. SELECT
  1110. ContainerCode AS TContainerCode,
  1111. ContainerCode AS PContainerCode,
  1112. ContainerCode AS ContainerCode,
  1113. ID,
  1114. ContainerID,
  1115. 0 AS [Level],
  1116. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1117. CAST('00001' AS nvarchar(MAX)) AS Sort
  1118. FROM ICSContainer
  1119. WHERE ContainerCode='{2}'
  1120. UNION ALL
  1121. SELECT
  1122. b.TContainerCode,
  1123. b.ContainerCode AS PContainerCode,
  1124. a.ContainerCode,
  1125. a.ID,
  1126. a.ContainerID,
  1127. b.[Level]+1 AS [Level],
  1128. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1129. 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
  1130. FROM
  1131. ICSContainer a
  1132. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1133. )
  1134. " + sql;
  1135. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1136. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1137. '' AS WHCode,
  1138. '' AS WHName,
  1139. '' AS LocationCode,
  1140. '' AS LocationName,
  1141. ext.BatchCode AS BatchCode,";
  1142. tableName = @"ICSInventoryLot a
  1143. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1144. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1145. }
  1146. sqlNew = string.Format(sqlNew, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  1147. #endregion
  1148. #region 原条码
  1149. if (ScanType == "LOTNO")
  1150. {
  1151. sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1152. 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,
  1153. 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
  1154. ";
  1155. sql = @"IF EXISTS(" + sql + @")
  1156. BEGIN
  1157. " + sql + @"
  1158. END
  1159. ELSE
  1160. BEGIN
  1161. " + sqlNew + @"
  1162. END";
  1163. sql = @"IF EXISTS(SELECT log.LotNo FROM ICSWareHouseLotInfoLog log
  1164. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1165. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND log.BusinessCode='" + type + @"'
  1166. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  1167. BEGIN
  1168. RAISERROR('" + string.Format(language.GetNameByCode(msglanguage), "{2}") + @"',16,1);
  1169. RETURN
  1170. END
  1171. " + sql;
  1172. columns = @"SUM(log.Quantity) AS Quantity,
  1173. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1174. a.WarehouseCode AS WHCode,
  1175. wh.WarehouseName AS WHName,
  1176. a.LocationCode,
  1177. loc.LocationName,
  1178. log.ID AS LogID,
  1179. 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,";
  1180. tableName = @"ICSWareHouseLotInfoLog log
  1181. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1182. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1183. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1184. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1185. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1186. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1187. }
  1188. else
  1189. {
  1190. sql = sql + @" AND log.BusinessCode IN('" + type + @"') GROUP BY log.ID,a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1191. 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,
  1192. 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
  1193. ";
  1194. sql = @"IF EXISTS(" + sql + @")
  1195. BEGIN
  1196. " + sql + @"
  1197. END
  1198. ELSE
  1199. BEGIN
  1200. " + sqlNew + @"
  1201. END";
  1202. sql = @"WITH ICSBomALL AS
  1203. (
  1204. SELECT
  1205. ContainerCode AS TContainerCode,
  1206. ContainerCode AS PContainerCode,
  1207. ContainerCode AS ContainerCode,
  1208. ID,
  1209. ContainerID,
  1210. 0 AS [Level],
  1211. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1212. CAST('00001' AS nvarchar(MAX)) AS Sort
  1213. FROM ICSContainer
  1214. WHERE ContainerCode='{2}'
  1215. UNION ALL
  1216. SELECT
  1217. b.TContainerCode,
  1218. b.ContainerCode AS PContainerCode,
  1219. a.ContainerCode,
  1220. a.ID,
  1221. a.ContainerID,
  1222. b.[Level]+1 AS [Level],
  1223. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1224. 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
  1225. FROM
  1226. ICSContainer a
  1227. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1228. )
  1229. " + sql;
  1230. columns = @"SUM(log.Quantity) AS Quantity,
  1231. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1232. a.WarehouseCode AS WHCode,
  1233. wh.WarehouseName AS WHName,
  1234. a.LocationCode,
  1235. loc.LocationName,
  1236. log.ID AS LogID,
  1237. 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,";
  1238. tableName = @"ICSWareHouseLotInfoLog log
  1239. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1240. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1241. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1242. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1243. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1244. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1245. }
  1246. #endregion
  1247. }
  1248. //分批
  1249. else if (TransType == TransTypeEnum.LOTSplit.GetDescription() || TransType == TransTypeEnum.LOTMerge.GetDescription())
  1250. {
  1251. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  1252. BEGIN
  1253. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  1254. RETURN
  1255. END
  1256. " + sql;
  1257. columns = @"a.Quantity,
  1258. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  1259. a.WarehouseCode AS WHCode,
  1260. wh.WarehouseName AS WHName,
  1261. a.LocationCode,
  1262. loc.LocationName,
  1263. 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,
  1264. ISNULL(split.SplitLotNo, a.LotNo+'-1') AS SplitLotNo,";
  1265. tableName = @"ICSWareHouseLotInfo a
  1266. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1267. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1268. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1269. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1270. LEFT JOIN (SELECT EATTRIBUTE1 AS LotNo,WorkPoint,EATTRIBUTE1+'-'+CAST((MAX(CAST(SUBSTRING(LotNo, CHARINDEX('-', LotNo)+1, LEN(LotNo)-CHARINDEX('-', LotNo)) AS INT))+1) AS VARCHAR) AS SplitLotNo FROM ICSInventoryLot GROUP BY EATTRIBUTE1,WorkPoint) split ON a.LotNo=split.LotNo AND a.WorkPoint=split.WorkPoint
  1271. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1272. }
  1273. //出库条码
  1274. else if (isOut)
  1275. {
  1276. if (ScanType == "LOTNO")
  1277. {
  1278. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  1279. BEGIN
  1280. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  1281. RETURN
  1282. END
  1283. " + sql;
  1284. columns = @"a.Quantity,
  1285. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  1286. a.WarehouseCode AS WHCode,
  1287. wh.WarehouseName AS WHName,
  1288. a.LocationCode,
  1289. loc.LocationName,
  1290. 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,";
  1291. tableName = @"ICSWareHouseLotInfo a
  1292. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1293. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1294. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1295. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1296. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1297. }
  1298. else
  1299. {
  1300. sql = @"
  1301. WITH ICSBomALL AS
  1302. (
  1303. SELECT
  1304. ContainerCode AS TContainerCode,
  1305. ContainerCode AS PContainerCode,
  1306. ContainerCode AS ContainerCode,
  1307. ID,
  1308. ContainerID,
  1309. 0 AS [Level],
  1310. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1311. CAST('00001' AS nvarchar(MAX)) AS Sort
  1312. FROM ICSContainer
  1313. WHERE ContainerCode='{2}'
  1314. UNION ALL
  1315. SELECT
  1316. b.TContainerCode,
  1317. b.ContainerCode AS PContainerCode,
  1318. a.ContainerCode,
  1319. a.ID,
  1320. a.ContainerID,
  1321. b.[Level]+1 AS [Level],
  1322. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1323. 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
  1324. FROM
  1325. ICSContainer a
  1326. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1327. )
  1328. " + sql;
  1329. columns = @"a.Quantity,
  1330. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  1331. a.WarehouseCode AS WHCode,
  1332. wh.WarehouseName AS WHName,
  1333. a.LocationCode,
  1334. loc.LocationName,
  1335. 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,";
  1336. tableName = @"ICSWareHouseLotInfo a
  1337. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1338. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1339. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1340. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1341. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1342. ";
  1343. }
  1344. }
  1345. //入库条码
  1346. else
  1347. {
  1348. if (ScanType == "LOTNO")
  1349. {
  1350. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1351. BEGIN
  1352. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  1353. RETURN
  1354. END
  1355. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1356. BEGIN
  1357. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  1358. RETURN
  1359. END
  1360. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  1361. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1362. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  1363. LEFT JOIN ICSInventoryLotDetail c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1364. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1'AND ins.LotNo IS NULL) AND c.TransCode NOT LIKE 'RD%')
  1365. BEGIN
  1366. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  1367. RETURN
  1368. END
  1369. " + sql;
  1370. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1371. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1372. '' AS WHCode,
  1373. '' AS WHName,
  1374. '' AS LocationCode,
  1375. '' AS LocationName,
  1376. ext.BatchCode AS BatchCode,";
  1377. tableName = @"ICSInventoryLot a
  1378. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1379. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1380. }
  1381. else
  1382. {
  1383. sql = @"
  1384. WITH ICSBomALL AS
  1385. (
  1386. SELECT
  1387. ContainerCode AS TContainerCode,
  1388. ContainerCode AS PContainerCode,
  1389. ContainerCode AS ContainerCode,
  1390. ID,
  1391. ContainerID,
  1392. 0 AS [Level],
  1393. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1394. CAST('00001' AS nvarchar(MAX)) AS Sort
  1395. FROM ICSContainer
  1396. WHERE ContainerCode='{2}'
  1397. UNION ALL
  1398. SELECT
  1399. b.TContainerCode,
  1400. b.ContainerCode AS PContainerCode,
  1401. a.ContainerCode,
  1402. a.ID,
  1403. a.ContainerID,
  1404. b.[Level]+1 AS [Level],
  1405. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1406. 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
  1407. FROM
  1408. ICSContainer a
  1409. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1410. )
  1411. " + sql;
  1412. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1413. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1414. '' AS WHCode,
  1415. '' AS WHName,
  1416. '' AS LocationCode,
  1417. '' AS LocationName,
  1418. ext.BatchCode AS BatchCode,";
  1419. tableName = @"ICSInventoryLot a
  1420. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1421. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1422. }
  1423. }
  1424. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName))
  1425. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  1426. sql = string.Format(sql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  1427. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  1428. if (table == null || table.Rows.Count <= 0)
  1429. throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
  1430. #region 出库检验是否符合源头单据
  1431. string msg = string.Empty;
  1432. bool isLimit = false;
  1433. if (isOut && TransType != TransTypeEnum.TransferLibrary.GetDescription()) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
  1434. {
  1435. string Lot = "";
  1436. string workP = "";
  1437. if (TransType == TransTypeEnum.TransferLibrary.GetDescription())
  1438. {
  1439. foreach (DataRow drLot in table.Rows)
  1440. {
  1441. Lot = drLot["LotNo"].ToString();
  1442. sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  1443. sql = string.Format(sql, Lot, JsonData.WorkPoint);
  1444. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1445. if (dt == null || dt.Rows.Count <= 0)
  1446. {
  1447. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), Lot));
  1448. }
  1449. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  1450. if (!JsonData.WHCode.Equals(whcode))
  1451. {
  1452. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo395"), JsonData.WHCode, whcode));
  1453. }
  1454. }
  1455. }
  1456. else if (string.IsNullOrEmpty(JsonData.TransCode) && TransType != TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1457. {
  1458. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1459. }
  1460. WMSSourceDocumentModel model = new WMSSourceDocumentModel();
  1461. model.TransCode = JsonData.TransCode;
  1462. model.TransType = JsonData.TransType;
  1463. model.WorkPoint = JsonData.WorkPoint;
  1464. DataTable TransData = new DataTable();
  1465. //if (!string.IsNullOrEmpty(JsonData.TransCode) && TransType != TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1466. if (!string.IsNullOrEmpty(JsonData.TransCode))
  1467. {
  1468. TransData = TransInformationGet(model);
  1469. }
  1470. DataView dataView = TransData.DefaultView;
  1471. foreach (DataRow drLot in table.Rows)
  1472. {
  1473. Lot = drLot["LotNo"].ToString();
  1474. //无源头的调拨不需要对比以下属性
  1475. if (string.IsNullOrEmpty(JsonData.TransCode) && TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1476. continue;
  1477. string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
  1478. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
  1479. rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
  1480. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
  1481. //rowFilter += " AND ProjectCode='" + drLot["ProjectCode"] + "'";
  1482. //CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo043"), Lot, drLot["ProjectCode"]));
  1483. if (TransType != TransTypeEnum.SalesShipmentDoc.GetDescription() && drLot["BatchCode"] != null && TransType != TransTypeEnum.OneStepTransferDocIn.GetDescription())
  1484. {
  1485. rowFilter += " AND BatchCode='" + drLot["BatchCode"] + "'";
  1486. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo044"), Lot, drLot["BatchCode"]));
  1487. }
  1488. //盘点不需要对比以下属性
  1489. if (TransType == TransTypeEnum.Check.GetDescription())
  1490. continue;
  1491. rowFilter += " AND Version='" + drLot["Version"] + "'";
  1492. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo045"), Lot, drLot["Version"]));
  1493. rowFilter += " AND Brand='" + drLot["Brand"] + "'";
  1494. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo046"), Lot, drLot["Brand"]));
  1495. rowFilter += " AND cFree1='" + drLot["cFree1"] + "'";
  1496. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo047"), Lot, drLot["cFree1"]));
  1497. rowFilter += " AND cFree2='" + drLot["cFree2"] + "'";
  1498. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo048"), Lot, drLot["cFree2"]));
  1499. rowFilter += " AND cFree3='" + drLot["cFree3"] + "'";
  1500. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo049"), Lot, drLot["cFree3"]));
  1501. rowFilter += " AND cFree4='" + drLot["cFree4"] + "'";
  1502. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo050"), Lot, drLot["cFree4"]));
  1503. rowFilter += " AND cFree5='" + drLot["cFree5"] + "'";
  1504. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo051"), Lot, drLot["cFree5"]));
  1505. rowFilter += " AND cFree6='" + drLot["cFree6"] + "'";
  1506. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo052"), Lot, drLot["cFree6"]));
  1507. rowFilter += " AND cFree7='" + drLot["cFree7"] + "'";
  1508. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo053"), Lot, drLot["cFree7"]));
  1509. rowFilter += " AND cFree8='" + drLot["cFree8"] + "'";
  1510. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo054"), Lot, drLot["cFree8"]));
  1511. rowFilter += " AND cFree9='" + drLot["cFree9"] + "'";
  1512. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo055"), Lot, drLot["cFree9"]));
  1513. rowFilter += " AND cFree10='" + drLot["cFree10"] + "'";
  1514. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo056"), Lot, drLot["cFree10"]));
  1515. //保质期管理
  1516. var resultEffective = Effective(Lot, JsonData.WorkPoint, cmd, language);
  1517. //0 - 已经是最早的批次
  1518. //1 - 不管控
  1519. //2 - 提醒
  1520. //3 - 限制
  1521. if (resultEffective == "2")
  1522. {
  1523. msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
  1524. }
  1525. else if (resultEffective == "3")
  1526. {
  1527. msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
  1528. isLimit = true;
  1529. }
  1530. //先进先出判断
  1531. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, cmd, language);
  1532. //0 - 已经是最早的批次
  1533. //1 - 不管控
  1534. //2 - 提醒
  1535. //3 - 限制
  1536. if (result == "2")
  1537. {
  1538. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  1539. }
  1540. else if (result == "3")
  1541. {
  1542. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  1543. isLimit = true;
  1544. }
  1545. }
  1546. }
  1547. #endregion
  1548. //return table;
  1549. Result res = new Result();
  1550. res.Success = true;
  1551. res.Message = msg;// "接口调用成功!";
  1552. if (!isLimit)
  1553. res.Data = table;
  1554. return res;
  1555. //出库时
  1556. //Message无值、Data有值,可直接处理
  1557. //Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
  1558. //Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
  1559. }
  1560. catch (Exception ex)
  1561. {
  1562. log.Error(ex.Message);
  1563. throw new Exception(ex.Message);
  1564. }
  1565. finally
  1566. {
  1567. if (conn.State == ConnectionState.Open)
  1568. {
  1569. conn.Close();
  1570. }
  1571. conn.Dispose();
  1572. }
  1573. }
  1574. }
  1575. /// <summary>
  1576. /// 校验条码对应的物料、自由项等信息是否与源头单据匹配
  1577. /// </summary>
  1578. private static void CheckTrans(DataView dataView, string rowFilter, string message)
  1579. {
  1580. dataView.RowFilter = rowFilter;
  1581. if (dataView == null || dataView.Count <= 0)
  1582. throw new Exception(message);
  1583. }
  1584. #endregion
  1585. /// <summary>
  1586. /// 上架
  1587. /// </summary>BusinessCode,TransType 两个类型
  1588. /// <param name="JsonData"></param>
  1589. /// <returns></returns>
  1590. public static DataTable LOTStockCreate(List<LOTStockUpCreateIModel> JsonData)
  1591. {
  1592. var language = LanguageHelper.GetName("WMSAPIInfo");
  1593. if (JsonData.Count <= 0)
  1594. {
  1595. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  1596. }
  1597. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1598. {
  1599. conn.Open();
  1600. SqlTransaction sqlTran = conn.BeginTransaction();
  1601. SqlCommand cmd = new SqlCommand();
  1602. cmd.Transaction = sqlTran;
  1603. cmd.Connection = conn;
  1604. try
  1605. {
  1606. string TransType = string.Empty;
  1607. string Identification = Guid.NewGuid().ToString();
  1608. foreach (var item in JsonData)
  1609. {
  1610. TransType = item.TransType;
  1611. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  1612. {
  1613. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  1614. }
  1615. string WHTransType = "2";
  1616. string BusinessCode = string.Empty;
  1617. foreach (var itemInfo in item.detail)
  1618. {
  1619. #region 两步调入
  1620. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1621. {
  1622. //更新源头单据数量
  1623. ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1624. //入库
  1625. ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  1626. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  1627. }
  1628. #endregion
  1629. #region 销售退货-原条码
  1630. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1631. {
  1632. //更新源头单据数量
  1633. ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1634. //入库
  1635. BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription<DBValue>();
  1636. //入库
  1637. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  1638. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode);
  1639. //更新日志表源头单据信息
  1640. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  1641. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' AND TransCode='' AND TransSequence=''";
  1642. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  1643. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1644. {
  1645. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  1646. }
  1647. }
  1648. #endregion
  1649. else
  1650. {
  1651. #region 采购入库
  1652. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1653. {
  1654. //更新源头单据数量
  1655. ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1656. BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription<DBValue>();
  1657. }
  1658. #endregion
  1659. #region 审核的到货单
  1660. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1661. {
  1662. //更新源头单据数量
  1663. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1664. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  1665. }
  1666. #endregion
  1667. #region 采购拒收
  1668. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1669. {
  1670. //更新源头单据数量
  1671. ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1672. BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription<DBValue>();
  1673. }
  1674. #endregion
  1675. #region 审核的委外到货单
  1676. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1677. {
  1678. //更新源头单据数量
  1679. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1680. BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  1681. }
  1682. #endregion
  1683. #region 委外拒收
  1684. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1685. {
  1686. //更新源头单据数量
  1687. ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1688. BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription<DBValue>();
  1689. }
  1690. #endregion
  1691. #region 委外退料
  1692. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1693. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1694. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1695. {
  1696. //更新源头单据数量
  1697. ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1698. BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  1699. }
  1700. #endregion
  1701. #region 返工工单
  1702. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1703. {
  1704. //更新源头单据数量
  1705. ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>(), cmd, language);
  1706. BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>();
  1707. }
  1708. #endregion
  1709. #region 委外入库
  1710. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1711. {
  1712. //更新源头单据数量
  1713. ICSOutsourcingService.OutsourcingReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1714. BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>();
  1715. }
  1716. #endregion
  1717. #region 生产退料
  1718. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1719. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1720. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1721. {
  1722. //更新源头单据数量
  1723. ICSManufactureService.MOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1724. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  1725. }
  1726. #endregion
  1727. #region 生产入库
  1728. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1729. {
  1730. //更新源头单据数量
  1731. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1732. BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  1733. }
  1734. #endregion
  1735. #region 开立的生产入库单
  1736. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1737. {
  1738. //更新源头单据数量
  1739. ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1740. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  1741. }
  1742. #endregion
  1743. #region 销售退货
  1744. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1745. {
  1746. //更新源头单据数量
  1747. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1748. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  1749. }
  1750. #endregion
  1751. #region 其他入库
  1752. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1753. {
  1754. //更新源头单据数量
  1755. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1756. BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  1757. }
  1758. #endregion
  1759. #region 拆卸单
  1760. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1761. {
  1762. ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1763. WHTransType = "11";
  1764. BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription<DBValue>();
  1765. }
  1766. #endregion
  1767. #region 归还
  1768. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1769. {
  1770. //更新源头单据数量
  1771. ICSWareHouseService.ReturnDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1772. BusinessCode = TransTypeEnum.ReturnDoc.GetDescription<DBValue>();
  1773. }
  1774. #endregion
  1775. else
  1776. {
  1777. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  1778. }
  1779. //入库
  1780. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  1781. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode);
  1782. }
  1783. }
  1784. #region 拆卸单
  1785. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1786. {
  1787. //更新套件锁定数量
  1788. ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
  1789. }
  1790. #endregion}
  1791. }
  1792. //上传ERP
  1793. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  1794. {
  1795. //采购入库
  1796. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1797. ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language);
  1798. //审核的到货单
  1799. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1800. ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language);
  1801. //采购拒收
  1802. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1803. ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language);
  1804. //审核的委外到货单
  1805. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1806. ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language);
  1807. //委外拒收
  1808. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1809. ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language);
  1810. //委外退料
  1811. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1812. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1813. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1814. ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language);
  1815. //委外入库
  1816. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1817. ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language);
  1818. //生产退料
  1819. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1820. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1821. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1822. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language);
  1823. //生产入库
  1824. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1825. ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language);
  1826. //开立的生产入库单
  1827. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1828. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language);
  1829. //返工工单
  1830. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1831. ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language);
  1832. //销售退货
  1833. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1834. ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language);
  1835. //两步调入
  1836. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1837. ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language);
  1838. //销售退货-原条码
  1839. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1840. ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language);
  1841. //其他入库
  1842. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1843. ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language);
  1844. //拆卸单
  1845. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1846. ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language);
  1847. //归还
  1848. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1849. ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language);
  1850. }
  1851. DataTable table = GetData(Identification, 1, cmd);
  1852. cmd.Transaction.Commit();
  1853. return table;
  1854. }
  1855. catch (Exception ex)
  1856. {
  1857. if (cmd.Transaction != null)
  1858. cmd.Transaction.Rollback();
  1859. log.Error(ex.Message);
  1860. throw new Exception(ex.Message);
  1861. }
  1862. finally
  1863. {
  1864. if (conn.State == ConnectionState.Open)
  1865. {
  1866. conn.Close();
  1867. }
  1868. conn.Dispose();
  1869. }
  1870. }
  1871. }
  1872. /// <summary>
  1873. /// 下架
  1874. /// </summary>
  1875. /// <param name="JsonData"></param>
  1876. /// <returns></returns>
  1877. public static DataTable LOTStockDownCreate(List<LOTStockModel> JsonData)
  1878. {
  1879. String PrintEnable = "";
  1880. var language = LanguageHelper.GetName("WMSAPIInfo");
  1881. if (JsonData.Count <= 0)
  1882. {
  1883. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  1884. }
  1885. List<LOTStockModelList> model = new List<LOTStockModelList>();
  1886. DataTable printTable = new DataTable();
  1887. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1888. {
  1889. conn.Open();
  1890. SqlTransaction sqlTran = conn.BeginTransaction();
  1891. SqlCommand cmd = new SqlCommand();
  1892. cmd.Transaction = sqlTran;
  1893. cmd.Connection = conn;
  1894. try
  1895. {
  1896. string TransType = string.Empty;
  1897. string Identification = Guid.NewGuid().ToString();
  1898. foreach (var item in JsonData)
  1899. {
  1900. TransType = item.TransType;
  1901. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  1902. {
  1903. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  1904. }
  1905. else if (string.IsNullOrEmpty(item.TransCode))
  1906. {
  1907. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1908. }
  1909. string[] trans = item.TransCode.Split('~');
  1910. string MergeID = "";
  1911. if (trans.Length == 2)
  1912. {
  1913. MergeID = trans[0];
  1914. item.TransCode = trans[1];
  1915. }
  1916. #region 采购退货
  1917. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  1918. {
  1919. //更新源头单据数量
  1920. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1921. foreach (var itemInfo in item.detail)
  1922. {
  1923. //出库
  1924. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  1925. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language);
  1926. }
  1927. }
  1928. #endregion
  1929. #region 委外发料
  1930. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  1931. {
  1932. //更新源头单据数量
  1933. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1934. foreach (var itemInfo in item.detail)
  1935. {
  1936. //出库
  1937. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  1938. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  1939. }
  1940. }
  1941. #endregion
  1942. #region 委外退货
  1943. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  1944. {
  1945. //更新源头单据数量
  1946. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1947. foreach (var itemInfo in item.detail)
  1948. {
  1949. //出库
  1950. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  1951. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language);
  1952. }
  1953. }
  1954. #endregion
  1955. #region 生产发料
  1956. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  1957. {
  1958. //更新源头单据数量
  1959. ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1960. foreach (var itemInfo in item.detail)
  1961. {
  1962. //出库v
  1963. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  1964. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  1965. }
  1966. }
  1967. #endregion
  1968. #region 销售出库
  1969. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  1970. {
  1971. //更新源头单据数量
  1972. ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1973. foreach (var itemInfo in item.detail)
  1974. {
  1975. //出库
  1976. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  1977. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  1978. }
  1979. }
  1980. #endregion
  1981. #region 两步调出
  1982. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  1983. {
  1984. //更新源头单据数量
  1985. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1986. foreach (var itemInfo in item.detail)
  1987. {
  1988. //出库
  1989. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  1990. item.User, item.WorkPoint, "6", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, MergeID);
  1991. }
  1992. }
  1993. #endregion
  1994. #region 其他出库
  1995. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  1996. {
  1997. //更新源头单据数量
  1998. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1999. foreach (var itemInfo in item.detail)
  2000. {
  2001. //出库
  2002. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  2003. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2004. }
  2005. }
  2006. #endregion
  2007. #region 领料申请单发料
  2008. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  2009. {
  2010. //更新源头单据数量
  2011. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2012. foreach (var itemInfo in item.detail)
  2013. {
  2014. //出库
  2015. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  2016. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  2017. }
  2018. }
  2019. #endregion
  2020. #region 委外领料申请单发料
  2021. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  2022. {
  2023. //更新源头单据数量
  2024. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2025. foreach (var itemInfo in item.detail)
  2026. {
  2027. //出库
  2028. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  2029. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  2030. }
  2031. }
  2032. #endregion
  2033. #region 开立材料出库
  2034. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2035. {
  2036. //更新源头单据数量
  2037. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2038. foreach (var itemInfo in item.detail)
  2039. {
  2040. //出库
  2041. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  2042. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  2043. }
  2044. }
  2045. #endregion
  2046. #region 开立委外材料出库
  2047. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2048. {
  2049. //更新源头单据数量
  2050. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2051. foreach (var itemInfo in item.detail)
  2052. {
  2053. //出库
  2054. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  2055. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  2056. }
  2057. }
  2058. #endregion
  2059. #region 开立红字入库单
  2060. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2061. {
  2062. //更新源头单据数量
  2063. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2064. foreach (var itemInfo in item.detail)
  2065. {
  2066. //出库
  2067. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  2068. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language);
  2069. }
  2070. }
  2071. #endregion
  2072. #region 开立委外红字入库单
  2073. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2074. {
  2075. //更新源头单据数量
  2076. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2077. foreach (var itemInfo in item.detail)
  2078. {
  2079. //出库
  2080. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  2081. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language);
  2082. }
  2083. }
  2084. #endregion
  2085. #region 借用
  2086. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2087. {
  2088. //更新源头单据数量
  2089. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2090. foreach (var itemInfo in item.detail)
  2091. {
  2092. //出库
  2093. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity, item.Quantity,
  2094. item.User, item.WorkPoint, "3", itemInfo.LotNo, itemInfo.LotNo, itemInfo.LotNo, TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2095. }
  2096. }
  2097. #endregion
  2098. else
  2099. {
  2100. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2101. }
  2102. }
  2103. //上传ERP
  2104. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2105. {
  2106. //采购退货
  2107. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2108. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language);
  2109. //委外发料
  2110. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2111. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language);
  2112. //委外退货
  2113. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2114. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language);
  2115. //生产发料
  2116. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2117. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language);
  2118. //销售出库
  2119. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2120. ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language);
  2121. //两步调出
  2122. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2123. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language);
  2124. //其他出库
  2125. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2126. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language);
  2127. //领料申请单发料
  2128. if (TransType == TransTypeEnum.MOApply.GetDescription())
  2129. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language);
  2130. //委外领料申请单发料
  2131. if (TransType == TransTypeEnum.OOApply.GetDescription())
  2132. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language);
  2133. //开立材料出库
  2134. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2135. ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language);
  2136. //开立委外材料出库
  2137. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2138. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language);
  2139. //开立红字入库单
  2140. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2141. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language);
  2142. //开立委外红字入库单
  2143. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2144. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language);
  2145. //借用
  2146. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2147. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language);
  2148. }
  2149. if (!printTable.Equals("{}"))
  2150. {
  2151. cmd.Transaction.Commit();
  2152. return printTable;
  2153. }
  2154. else
  2155. {
  2156. DataTable table = GetData(Identification, 2, cmd);
  2157. cmd.Transaction.Commit();
  2158. return table;
  2159. }
  2160. }
  2161. catch (Exception ex)
  2162. {
  2163. if (cmd.Transaction != null)
  2164. cmd.Transaction.Rollback();
  2165. log.Error(ex.Message);
  2166. throw new Exception(ex.Message);
  2167. }
  2168. finally
  2169. {
  2170. if (conn.State == ConnectionState.Open)
  2171. {
  2172. conn.Close();
  2173. }
  2174. conn.Dispose();
  2175. }
  2176. }
  2177. }
  2178. #region 采购
  2179. /// <summary>
  2180. /// 采购到货
  2181. /// </summary>
  2182. /// <param name="JsonData"></param>
  2183. /// <returns></returns>
  2184. public static DataTable DeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  2185. {
  2186. var language = LanguageHelper.GetName("WMSAPIInfo");
  2187. if (JsonData.Count <= 0)
  2188. {
  2189. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2190. }
  2191. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2192. {
  2193. conn.Open();
  2194. SqlTransaction sqlTran = conn.BeginTransaction();
  2195. SqlCommand cmd = new SqlCommand();
  2196. cmd.Transaction = sqlTran;
  2197. cmd.Connection = conn;
  2198. try
  2199. {
  2200. string asncodes = string.Empty;
  2201. string sql = string.Empty;
  2202. foreach (var item in JsonData)
  2203. {
  2204. if (string.IsNullOrEmpty(item.ASNCode))
  2205. {
  2206. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
  2207. }
  2208. //获取单号
  2209. sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  2210. BEGIN
  2211. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  2212. RETURN
  2213. END
  2214. DECLARE @Status VARCHAR(10)
  2215. SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  2216. IF (@Status IS NULL)
  2217. BEGIN
  2218. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  2219. RETURN
  2220. END
  2221. ELSE IF (@Status!='2')
  2222. BEGIN
  2223. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  2224. RETURN
  2225. END
  2226. DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2227. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2228. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2229. IF @MaxNO IS NULL
  2230. BEGIN
  2231. SELECT @date+'00001' AS Code
  2232. END
  2233. ELSE
  2234. BEGIN
  2235. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2236. END ";
  2237. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  2238. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2239. //修改送货单到货数量
  2240. foreach (var itemInfo in item.detail)
  2241. {
  2242. sql = @"UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
  2243. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2244. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  2245. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2246. {
  2247. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
  2248. }
  2249. }
  2250. //创建到货单信息
  2251. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  2252. BEGIN
  2253. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  2254. RETURN
  2255. END
  2256. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2257. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2258. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2259. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2260. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2261. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  2262. '1',b.InvCode,SUM(a.DNQuantity),'0','0',
  2263. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  2264. d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,
  2265. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode
  2266. FROM ICSASNDetail a
  2267. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2268. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  2269. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  2270. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  2271. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}'
  2272. 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";
  2273. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode);
  2274. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2275. {
  2276. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  2277. }
  2278. ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  2279. asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
  2280. }
  2281. if (string.IsNullOrWhiteSpace(asncodes))
  2282. {
  2283. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  2284. }
  2285. #region 查询返回数据
  2286. sql = @"SELECT
  2287. n.POCode,
  2288. n.Sequence AS POSequence,
  2289. a.ASNCode,
  2290. a.DNCode,
  2291. a.Sequence,
  2292. a.VenCode,
  2293. a.DepCode,
  2294. a.InvCode,
  2295. inv.InvName,
  2296. inv.InvStd,
  2297. a.Quantity,
  2298. inv.InvUnit,
  2299. a.Amount,
  2300. inv.AmountUnit,
  2301. a.RCVQuantity,
  2302. a.UnitPrice,
  2303. a.Currency,
  2304. a.POID,
  2305. a.PODetailID,
  2306. a.DNID,
  2307. a.DNDetailID,
  2308. ext.ProjectCode,
  2309. ext.BatchCode,
  2310. ext.Version,
  2311. ext.Brand,
  2312. ext.cFree1,
  2313. ext.cFree2,
  2314. ext.cFree3,
  2315. ext.cFree4,
  2316. ext.cFree5,
  2317. ext.cFree6,
  2318. ext.cFree7,
  2319. ext.cFree8,
  2320. ext.cFree9,
  2321. ext.cFree10,
  2322. a.MUSER AS [User],
  2323. a.MTIME AS [MTime]
  2324. FROM ICSDeliveryNotice a
  2325. INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
  2326. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2327. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2328. WHERE a.ASNCode+a.WorkPoint IN ({0})";
  2329. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  2330. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2331. #endregion
  2332. cmd.Transaction.Commit();
  2333. return data;
  2334. }
  2335. catch (Exception ex)
  2336. {
  2337. if (cmd.Transaction != null)
  2338. cmd.Transaction.Rollback();
  2339. log.Error(ex.Message);
  2340. throw new Exception(ex.Message);
  2341. }
  2342. finally
  2343. {
  2344. if (conn.State == ConnectionState.Open)
  2345. {
  2346. conn.Close();
  2347. }
  2348. conn.Dispose();
  2349. }
  2350. }
  2351. }
  2352. /// <summary>
  2353. /// 采购拒收
  2354. /// </summary>
  2355. /// <param name="JsonData"></param>
  2356. /// <returns></returns>
  2357. public static DataTable PurchaseRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  2358. {
  2359. var language = LanguageHelper.GetName("WMSAPIInfo");
  2360. if (JsonData.Count <= 0)
  2361. {
  2362. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2363. }
  2364. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2365. {
  2366. conn.Open();
  2367. SqlTransaction sqlTran = conn.BeginTransaction();
  2368. SqlCommand cmd = new SqlCommand();
  2369. cmd.Transaction = sqlTran;
  2370. cmd.Connection = conn;
  2371. try
  2372. {
  2373. string lots = string.Empty;
  2374. string sql = string.Empty;
  2375. foreach (var item in JsonData)
  2376. {
  2377. if (string.IsNullOrEmpty(item.DNCode))
  2378. {
  2379. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  2380. }
  2381. //获取单号
  2382. sql = @"DECLARE @Status VARCHAR(10)
  2383. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  2384. IF (@Status IS NULL)
  2385. BEGIN
  2386. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  2387. RETURN
  2388. END
  2389. ELSE IF (@Status!='2')
  2390. BEGIN
  2391. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  2392. RETURN
  2393. END
  2394. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2395. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2396. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2397. IF @MaxNO IS NULL
  2398. BEGIN
  2399. SELECT @date+'00001' AS Code
  2400. END
  2401. ELSE
  2402. BEGIN
  2403. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2404. END ";
  2405. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  2406. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2407. //修改送货单到货数量
  2408. foreach (var itemInfo in item.detail)
  2409. {
  2410. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  2411. BEGIN
  2412. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  2413. RETURN
  2414. END
  2415. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  2416. BEGIN
  2417. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  2418. RETURN
  2419. END
  2420. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2421. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2422. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2423. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2424. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2425. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  2426. '3',d.InvCode,'{7}', '{8}', 0,
  2427. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  2428. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  2429. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  2430. FROM ICSDeliveryNotice a
  2431. INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  2432. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  2433. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  2434. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  2435. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  2436. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  2437. WHERE a.DNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  2438. 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);
  2439. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2440. {
  2441. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  2442. }
  2443. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  2444. }
  2445. }
  2446. if (string.IsNullOrWhiteSpace(lots))
  2447. {
  2448. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  2449. }
  2450. #region 查询返回数据
  2451. sql = @"SELECT
  2452. n.DNCode,
  2453. n.Sequence,
  2454. a.DNCode AS RJTCode,
  2455. a.Sequence AS RJTSequence,
  2456. a.VenCode,
  2457. a.DepCode,
  2458. a.InvCode,
  2459. inv.InvName,
  2460. inv.InvStd,
  2461. a.Quantity,
  2462. inv.InvUnit,
  2463. a.Amount,
  2464. inv.AmountUnit,
  2465. a.RCVQuantity,
  2466. a.UnitPrice,
  2467. a.Currency,
  2468. a.POID,
  2469. a.PODetailID,
  2470. a.DNID,
  2471. a.DNDetailID,
  2472. ext.ProjectCode,
  2473. ext.BatchCode,
  2474. ext.Version,
  2475. ext.Brand,
  2476. ext.cFree1,
  2477. ext.cFree2,
  2478. ext.cFree3,
  2479. ext.cFree4,
  2480. ext.cFree5,
  2481. ext.cFree6,
  2482. ext.cFree7,
  2483. ext.cFree8,
  2484. ext.cFree9,
  2485. ext.cFree10,
  2486. a.MUSER AS [User],
  2487. a.MTIME AS [MTime]
  2488. FROM ICSDeliveryNotice a
  2489. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  2490. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2491. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2492. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  2493. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  2494. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2495. #endregion
  2496. cmd.Transaction.Commit();
  2497. return data;
  2498. }
  2499. catch (Exception ex)
  2500. {
  2501. if (cmd.Transaction != null)
  2502. cmd.Transaction.Rollback();
  2503. log.Error(ex.Message);
  2504. throw new Exception(ex.Message);
  2505. }
  2506. finally
  2507. {
  2508. if (conn.State == ConnectionState.Open)
  2509. {
  2510. conn.Close();
  2511. }
  2512. conn.Dispose();
  2513. }
  2514. }
  2515. }
  2516. #endregion
  2517. #region 委外
  2518. /// <summary>
  2519. /// 委外退料 新建
  2520. /// </summary>
  2521. /// <param name="JsonData"></param>
  2522. /// <returns></returns>
  2523. public static DataTable OutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  2524. {
  2525. var language = LanguageHelper.GetName("WMSAPIInfo");
  2526. if (JsonData.Count <= 0)
  2527. {
  2528. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2529. }
  2530. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2531. {
  2532. conn.Open();
  2533. SqlTransaction sqlTran = conn.BeginTransaction();
  2534. SqlCommand cmd = new SqlCommand();
  2535. cmd.Transaction = sqlTran;
  2536. cmd.Connection = conn;
  2537. try
  2538. {
  2539. string codes = string.Empty;
  2540. string sql = string.Empty;
  2541. foreach (var item in JsonData)
  2542. {
  2543. //获取单号
  2544. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2545. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  2546. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  2547. IF @MaxNO IS NULL
  2548. BEGIN
  2549. SELECT @date+'00001' AS Code
  2550. END
  2551. ELSE
  2552. BEGIN
  2553. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2554. END ";
  2555. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2556. //创建主表
  2557. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  2558. BEGIN
  2559. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2560. RETURN
  2561. END
  2562. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2563. 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}','')";
  2564. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  2565. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2566. {
  2567. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  2568. }
  2569. foreach (var itemInfo in item.detail)
  2570. {
  2571. //创建子表
  2572. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  2573. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  2574. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  2575. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  2576. '{4}','{5}',0,'{6}','{7}',
  2577. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  2578. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  2579. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2580. {
  2581. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  2582. }
  2583. }
  2584. //校验退料数量是否超出领料数量
  2585. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  2586. DBHelper.ExecuteNonQuery(sql, cmd);
  2587. codes += "'" + Code + item.WorkPoint + "',";
  2588. }
  2589. if (string.IsNullOrWhiteSpace(codes))
  2590. {
  2591. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2592. }
  2593. #region 查询返回数据
  2594. sql = @"SELECT a.OApplyNegCode,
  2595. c.WHCode,
  2596. c.Memo,
  2597. d.Name AS Status,
  2598. a.Sequence,
  2599. a.InvCode,
  2600. inv.InvName,
  2601. inv.InvStd,
  2602. a.Quantity,
  2603. inv.InvUnit,
  2604. a.Amount,
  2605. inv.AmountUnit,
  2606. a.IssueNegQuantity,
  2607. ext.ProjectCode,
  2608. ext.BatchCode,
  2609. ext.Version,
  2610. ext.Brand,
  2611. ext.cFree1,
  2612. ext.cFree2,
  2613. ext.cFree3,
  2614. ext.cFree4,
  2615. ext.cFree5,
  2616. ext.cFree6,
  2617. ext.cFree7,
  2618. ext.cFree8,
  2619. ext.cFree9,
  2620. ext.cFree10,
  2621. a.MUSER AS [User],
  2622. a.MTIME AS [MTime]
  2623. FROM ICSOApplyNegDetail a
  2624. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2625. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  2626. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2627. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2628. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  2629. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  2630. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2631. #endregion
  2632. cmd.Transaction.Commit();
  2633. return data;
  2634. }
  2635. catch (Exception ex)
  2636. {
  2637. if (cmd.Transaction != null)
  2638. cmd.Transaction.Rollback();
  2639. log.Error(ex.Message);
  2640. throw new Exception(ex.Message);
  2641. }
  2642. finally
  2643. {
  2644. if (conn.State == ConnectionState.Open)
  2645. {
  2646. conn.Close();
  2647. }
  2648. conn.Dispose();
  2649. }
  2650. }
  2651. }
  2652. private static string CheckOutsourcingIssueDoc(string Type, string Code, string WorkPoint, Dictionary<string, string> language)
  2653. {
  2654. string sql = string.Empty;
  2655. if (Type == "1")
  2656. {
  2657. sql = @"DECLARE @PickID VARCHAR(10)
  2658. SELECT @PickID=b.PickID
  2659. FROM ICSOApplyNegDetail a
  2660. INNER JOIN ICSOOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  2661. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2662. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2663. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2664. FROM ICSOApplyNegDetail a
  2665. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2666. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2667. GROUP BY b.PickID
  2668. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2669. IF (@PickID IS NOT NULL)
  2670. BEGIN
  2671. DECLARE @InvCode VARCHAR(100)
  2672. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  2673. RAISERROR(@InvCode,16,1);
  2674. RETURN
  2675. END ";
  2676. }
  2677. else if (Type == "2")
  2678. {
  2679. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  2680. SELECT @ApplyDetailID=b.ApplyDetailID
  2681. FROM ICSOApplyNegDetail a
  2682. INNER JOIN ICSOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  2683. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2684. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2685. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2686. FROM ICSOApplyNegDetail a
  2687. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2688. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2689. GROUP BY b.ApplyDetailID
  2690. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2691. IF (@ApplyDetailID IS NOT NULL)
  2692. BEGIN
  2693. DECLARE @InvCode VARCHAR(100)
  2694. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  2695. RAISERROR(@InvCode,16,1);
  2696. RETURN
  2697. END ";
  2698. }
  2699. else if (Type == "3")
  2700. {
  2701. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  2702. SELECT @IssueDetailID=b.IssueDetailID
  2703. FROM ICSOApplyNegDetail a
  2704. INNER JOIN ICSOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  2705. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2706. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2707. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2708. FROM ICSOApplyNegDetail a
  2709. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2710. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2711. GROUP BY b.IssueDetailID
  2712. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2713. IF (@IssueDetailID IS NOT NULL)
  2714. BEGIN
  2715. DECLARE @InvCode VARCHAR(100)
  2716. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  2717. RAISERROR(@InvCode,16,1);
  2718. RETURN
  2719. END ";
  2720. }
  2721. else
  2722. {
  2723. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  2724. }
  2725. sql = string.Format(sql, Code, WorkPoint, Type);
  2726. return sql;
  2727. }
  2728. /// <summary>
  2729. /// 委外退料 修改
  2730. /// </summary>
  2731. /// <param name="JsonData"></param>
  2732. /// <returns></returns>
  2733. public static DataTable OutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  2734. {
  2735. var language = LanguageHelper.GetName("WMSAPIInfo");
  2736. if (JsonData.Count <= 0)
  2737. {
  2738. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2739. }
  2740. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2741. {
  2742. conn.Open();
  2743. SqlTransaction sqlTran = conn.BeginTransaction();
  2744. SqlCommand cmd = new SqlCommand();
  2745. cmd.Transaction = sqlTran;
  2746. cmd.Connection = conn;
  2747. try
  2748. {
  2749. string sql = string.Empty;
  2750. string Code = string.Empty;
  2751. string ids = string.Empty;
  2752. foreach (var item in JsonData)
  2753. {
  2754. //主表修改
  2755. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  2756. BEGIN
  2757. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  2758. RETURN
  2759. END
  2760. DECLARE @Status VARCHAR(10)
  2761. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  2762. IF (@Status IS NULL)
  2763. BEGIN
  2764. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  2765. RETURN
  2766. END
  2767. ELSE IF (@Status!='1')
  2768. BEGIN
  2769. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  2770. RETURN
  2771. END
  2772. 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}' ";
  2773. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  2774. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2775. {
  2776. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  2777. }
  2778. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  2779. if (detail > 0)
  2780. {
  2781. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  2782. sql = string.Format(sql, item.id, item.WorkPoint);
  2783. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2784. }
  2785. foreach (var itemInfo in item.detail)
  2786. {
  2787. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  2788. {
  2789. //创建子表
  2790. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  2791. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  2792. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  2793. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  2794. '{4}','{5}',0,'{6}','{7}',
  2795. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  2796. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  2797. }
  2798. else
  2799. {
  2800. //子表修改
  2801. 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}'";
  2802. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  2803. }
  2804. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2805. {
  2806. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  2807. }
  2808. }
  2809. //校验退料数量是否超出领料数量
  2810. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  2811. DBHelper.ExecuteNonQuery(sql, cmd);
  2812. ids += "'" + item.id + "',";
  2813. }
  2814. if (string.IsNullOrWhiteSpace(ids))
  2815. {
  2816. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  2817. }
  2818. #region 查询返回数据
  2819. sql = @"SELECT a.OApplyNegCode,
  2820. c.WHCode,
  2821. c.Memo,
  2822. d.Name AS Status,
  2823. a.Sequence,
  2824. a.InvCode,
  2825. inv.InvName,
  2826. inv.InvStd,
  2827. a.Quantity,
  2828. inv.InvUnit,
  2829. a.Amount,
  2830. inv.AmountUnit,
  2831. a.IssueNegQuantity,
  2832. ext.ProjectCode,
  2833. ext.BatchCode,
  2834. ext.Version,
  2835. ext.Brand,
  2836. ext.cFree1,
  2837. ext.cFree2,
  2838. ext.cFree3,
  2839. ext.cFree4,
  2840. ext.cFree5,
  2841. ext.cFree6,
  2842. ext.cFree7,
  2843. ext.cFree8,
  2844. ext.cFree9,
  2845. ext.cFree10,
  2846. a.MUSER AS [User],
  2847. a.MTIME AS [MTime]
  2848. FROM ICSOApplyNegDetail a
  2849. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2850. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  2851. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2852. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2853. WHERE c.ID IN ({0})";
  2854. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  2855. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2856. #endregion
  2857. cmd.Transaction.Commit();
  2858. return data;
  2859. }
  2860. catch (Exception ex)
  2861. {
  2862. if (cmd.Transaction != null)
  2863. cmd.Transaction.Rollback();
  2864. log.Error(ex.Message);
  2865. throw new Exception(ex.Message);
  2866. }
  2867. finally
  2868. {
  2869. if (conn.State == ConnectionState.Open)
  2870. {
  2871. conn.Close();
  2872. }
  2873. conn.Dispose();
  2874. }
  2875. }
  2876. }
  2877. /// <summary>
  2878. /// 委外退料审核
  2879. /// </summary>
  2880. /// <param name="JsonData"></param>
  2881. /// <returns></returns>
  2882. public static DataTable OutsourcingIssueDoNegativeApplyApprove(List<ICSUser> JsonData)
  2883. {
  2884. var language = LanguageHelper.GetName("WMSAPIInfo");
  2885. if (JsonData.Count <= 0)
  2886. {
  2887. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2888. }
  2889. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2890. {
  2891. conn.Open();
  2892. SqlTransaction sqlTran = conn.BeginTransaction();
  2893. SqlCommand cmd = new SqlCommand();
  2894. cmd.Transaction = sqlTran;
  2895. cmd.Connection = conn;
  2896. try
  2897. {
  2898. string sql = string.Empty;
  2899. string ids = string.Empty;
  2900. foreach (var item in JsonData)
  2901. {
  2902. if (string.IsNullOrEmpty(item.ID))
  2903. {
  2904. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  2905. }
  2906. if (string.IsNullOrEmpty(item.User))
  2907. {
  2908. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  2909. }
  2910. if (item.MTime <= new DateTime(2000, 1, 1))
  2911. {
  2912. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  2913. }
  2914. //获取单号
  2915. sql = @"DECLARE @Status VARCHAR(10)
  2916. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  2917. IF (@Status IS NULL)
  2918. BEGIN
  2919. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  2920. RETURN
  2921. END
  2922. ELSE IF (@Status!='1')
  2923. BEGIN
  2924. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  2925. RETURN
  2926. END
  2927. update ICSOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  2928. sql = string.Format(sql, item.ID, item.User, item.MTime);
  2929. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2930. {
  2931. throw new Exception(language.GetNameByCode("WMSAPIInfo021"));//"委外退料申请单审核失败!");
  2932. }
  2933. ids += "'" + item.ID + "',";
  2934. }
  2935. if (string.IsNullOrWhiteSpace(ids))
  2936. {
  2937. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  2938. }
  2939. #region 查询返回数据
  2940. sql = @"SELECT a.OApplyNegCode,
  2941. c.WHCode,
  2942. c.Memo,
  2943. d.Name AS Status,
  2944. a.Sequence,
  2945. a.InvCode,
  2946. inv.InvName,
  2947. inv.InvStd,
  2948. a.Quantity,
  2949. inv.InvUnit,
  2950. a.Amount,
  2951. inv.AmountUnit,
  2952. a.IssueNegQuantity,
  2953. ext.ProjectCode,
  2954. ext.BatchCode,
  2955. ext.Version,
  2956. ext.Brand,
  2957. ext.cFree1,
  2958. ext.cFree2,
  2959. ext.cFree3,
  2960. ext.cFree4,
  2961. ext.cFree5,
  2962. ext.cFree6,
  2963. ext.cFree7,
  2964. ext.cFree8,
  2965. ext.cFree9,
  2966. ext.cFree10,
  2967. a.MUSER AS [User],
  2968. a.MTIME AS [MTime]
  2969. FROM ICSOApplyNegDetail a
  2970. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2971. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  2972. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2973. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2974. WHERE c.ID IN ({0})";
  2975. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  2976. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2977. #endregion
  2978. cmd.Transaction.Commit();
  2979. return data;
  2980. }
  2981. catch (Exception ex)
  2982. {
  2983. if (cmd.Transaction != null)
  2984. cmd.Transaction.Rollback();
  2985. log.Error(ex.Message);
  2986. throw new Exception(ex.Message);
  2987. }
  2988. finally
  2989. {
  2990. if (conn.State == ConnectionState.Open)
  2991. {
  2992. conn.Close();
  2993. }
  2994. conn.Dispose();
  2995. }
  2996. }
  2997. }
  2998. /// <summary>
  2999. /// 委外到货
  3000. /// </summary>
  3001. /// <param name="JsonData"></param>
  3002. /// <returns></returns>
  3003. public static DataTable OutsourcingDeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  3004. {
  3005. var language = LanguageHelper.GetName("WMSAPIInfo");
  3006. if (JsonData.Count <= 0)
  3007. {
  3008. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3009. }
  3010. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3011. {
  3012. conn.Open();
  3013. SqlTransaction sqlTran = conn.BeginTransaction();
  3014. SqlCommand cmd = new SqlCommand();
  3015. cmd.Transaction = sqlTran;
  3016. cmd.Connection = conn;
  3017. try
  3018. {
  3019. string asncodes = string.Empty;
  3020. string sql = string.Empty;
  3021. foreach (var item in JsonData)
  3022. {
  3023. if (string.IsNullOrEmpty(item.OASNCode))
  3024. {
  3025. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!");
  3026. }
  3027. //获取单号
  3028. sql = @"IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.OASNCode='{0}' AND ODNType = '1' AND a.WorkPoint='{1}')
  3029. BEGIN
  3030. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  3031. RETURN
  3032. END
  3033. DECLARE @Status VARCHAR(10)
  3034. SELECT @Status=Status FROM ICSOASN WHERE OASNCode='{0}' and WorkPoint='{1}'
  3035. IF (@Status IS NULL)
  3036. BEGIN
  3037. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  3038. RETURN
  3039. END
  3040. ELSE IF (@Status!='2')
  3041. BEGIN
  3042. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  3043. RETURN
  3044. END
  3045. DECLARE @MaxNO INT,@date varchar(20)='ODN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3046. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3047. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3048. IF @MaxNO IS NULL
  3049. BEGIN
  3050. SELECT @date+'00001' AS Code
  3051. END
  3052. ELSE
  3053. BEGIN
  3054. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3055. END ";
  3056. sql = string.Format(sql, item.OASNCode, item.WorkPoint);
  3057. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3058. //修改送货单到货数量
  3059. foreach (var itemInfo in item.detail)
  3060. {
  3061. sql = @"UPDATE ICSOASNDetail SET ODNQuantity=ISNULL(ODNQuantity, 0)+'{2}'
  3062. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3063. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  3064. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3065. {
  3066. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"委外送货单子表信息更新失败!");
  3067. }
  3068. }
  3069. //创建到货单信息
  3070. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  3071. BEGIN
  3072. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  3073. RETURN
  3074. END
  3075. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3076. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3077. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3078. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3079. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3080. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  3081. '1',b.InvCode,SUM(a.ODNQuantity),'0','0',
  3082. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  3083. d.OOID,d.OODetailID,newid(),newid(),b.ExtensionID,
  3084. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.OASNCode
  3085. FROM ICSOASNDetail a
  3086. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3087. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  3088. INNER JOIN ICSOutsourcingOrder d ON c.TransCode=d.OOCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  3089. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  3090. WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
  3091. 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";
  3092. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.OASNCode);
  3093. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3094. {
  3095. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  3096. }
  3097. ICSOutsourcingService.OutsourcingDeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  3098. asncodes += "'" + item.OASNCode + item.WorkPoint + "',";
  3099. }
  3100. if (string.IsNullOrWhiteSpace(asncodes))
  3101. {
  3102. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  3103. }
  3104. #region 查询返回数据
  3105. sql = @"SELECT
  3106. n.OOCode,
  3107. n.Sequence AS OOSequence,
  3108. a.OASNCode,
  3109. a.ODNCode,
  3110. a.Sequence,
  3111. a.VenCode,
  3112. a.DepCode,
  3113. a.InvCode,
  3114. inv.InvName,
  3115. inv.InvStd,
  3116. a.Quantity,
  3117. inv.InvUnit,
  3118. a.Amount,
  3119. inv.AmountUnit,
  3120. a.RCVQuantity,
  3121. a.UnitPrice,
  3122. a.Currency,
  3123. a.OOID,
  3124. a.OODetailID,
  3125. a.ODNID,
  3126. a.ODNDetailID,
  3127. ext.ProjectCode,
  3128. ext.BatchCode,
  3129. ext.Version,
  3130. ext.Brand,
  3131. ext.cFree1,
  3132. ext.cFree2,
  3133. ext.cFree3,
  3134. ext.cFree4,
  3135. ext.cFree5,
  3136. ext.cFree6,
  3137. ext.cFree7,
  3138. ext.cFree8,
  3139. ext.cFree9,
  3140. ext.cFree10,
  3141. a.MUSER AS [User],
  3142. a.MTIME AS [MTime]
  3143. FROM ICSODeliveryNotice a
  3144. INNER JOIN ICSOutsourcingOrder n ON a.OOID =n.OOID AND a.OODetailID=n.OODetailID AND a.WorkPoint=n.WorkPoint
  3145. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3146. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3147. WHERE a.OASNCode+a.WorkPoint IN ({0})";
  3148. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  3149. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3150. #endregion
  3151. cmd.Transaction.Commit();
  3152. return data;
  3153. }
  3154. catch (Exception ex)
  3155. {
  3156. if (cmd.Transaction != null)
  3157. cmd.Transaction.Rollback();
  3158. log.Error(ex.Message);
  3159. throw new Exception(ex.Message);
  3160. }
  3161. finally
  3162. {
  3163. if (conn.State == ConnectionState.Open)
  3164. {
  3165. conn.Close();
  3166. }
  3167. conn.Dispose();
  3168. }
  3169. }
  3170. }
  3171. /// <summary>
  3172. /// 委外拒收
  3173. /// </summary>
  3174. /// <param name="JsonData"></param>
  3175. /// <returns></returns>
  3176. public static DataTable OutsourcingRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  3177. {
  3178. var language = LanguageHelper.GetName("WMSAPIInfo");
  3179. if (JsonData.Count <= 0)
  3180. {
  3181. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3182. }
  3183. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3184. {
  3185. conn.Open();
  3186. SqlTransaction sqlTran = conn.BeginTransaction();
  3187. SqlCommand cmd = new SqlCommand();
  3188. cmd.Transaction = sqlTran;
  3189. cmd.Connection = conn;
  3190. try
  3191. {
  3192. string lots = string.Empty;
  3193. string sql = string.Empty;
  3194. foreach (var item in JsonData)
  3195. {
  3196. if (string.IsNullOrEmpty(item.ODNCode))
  3197. {
  3198. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  3199. }
  3200. //获取单号
  3201. sql = @"DECLARE @Status VARCHAR(10)
  3202. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  3203. IF (@Status IS NULL)
  3204. BEGIN
  3205. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  3206. RETURN
  3207. END
  3208. ELSE IF (@Status!='2')
  3209. BEGIN
  3210. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  3211. RETURN
  3212. END
  3213. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3214. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3215. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3216. IF @MaxNO IS NULL
  3217. BEGIN
  3218. SELECT @date+'00001' AS Code
  3219. END
  3220. ELSE
  3221. BEGIN
  3222. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3223. END ";
  3224. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  3225. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3226. //修改送货单到货数量
  3227. foreach (var itemInfo in item.detail)
  3228. {
  3229. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  3230. BEGIN
  3231. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  3232. RETURN
  3233. END
  3234. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  3235. BEGIN
  3236. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  3237. RETURN
  3238. END
  3239. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3240. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3241. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3242. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3243. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3244. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  3245. '3',d.InvCode,'{7}', '{8}', 0,
  3246. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  3247. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  3248. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  3249. FROM ICSODeliveryNotice a
  3250. INNER JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  3251. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  3252. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  3253. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND a.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  3254. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  3255. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  3256. WHERE a.ODNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  3257. 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);
  3258. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3259. {
  3260. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  3261. }
  3262. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  3263. }
  3264. }
  3265. if (string.IsNullOrWhiteSpace(lots))
  3266. {
  3267. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  3268. }
  3269. #region 查询返回数据
  3270. sql = @"SELECT
  3271. n.ODNCode,
  3272. n.Sequence,
  3273. a.ODNCode AS RJTCode,
  3274. a.Sequence AS RJTSequence,
  3275. a.VenCode,
  3276. a.DepCode,
  3277. a.InvCode,
  3278. inv.InvName,
  3279. inv.InvStd,
  3280. a.Quantity,
  3281. inv.InvUnit,
  3282. a.Amount,
  3283. inv.AmountUnit,
  3284. a.RCVQuantity,
  3285. a.UnitPrice,
  3286. a.Currency,
  3287. a.OOID,
  3288. a.OODetailID,
  3289. a.ODNID,
  3290. a.ODNDetailID,
  3291. ext.ProjectCode,
  3292. ext.BatchCode,
  3293. ext.Version,
  3294. ext.Brand,
  3295. ext.cFree1,
  3296. ext.cFree2,
  3297. ext.cFree3,
  3298. ext.cFree4,
  3299. ext.cFree5,
  3300. ext.cFree6,
  3301. ext.cFree7,
  3302. ext.cFree8,
  3303. ext.cFree9,
  3304. ext.cFree10,
  3305. a.MUSER AS [User],
  3306. a.MTIME AS [MTime]
  3307. FROM ICSODeliveryNotice a
  3308. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  3309. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3310. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3311. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  3312. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  3313. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3314. #endregion
  3315. cmd.Transaction.Commit();
  3316. return data;
  3317. }
  3318. catch (Exception ex)
  3319. {
  3320. if (cmd.Transaction != null)
  3321. cmd.Transaction.Rollback();
  3322. log.Error(ex.Message);
  3323. throw new Exception(ex.Message);
  3324. }
  3325. finally
  3326. {
  3327. if (conn.State == ConnectionState.Open)
  3328. {
  3329. conn.Close();
  3330. }
  3331. conn.Dispose();
  3332. }
  3333. }
  3334. }
  3335. #endregion
  3336. #region 生产
  3337. /// <summary>
  3338. /// 生产退料 新建
  3339. /// </summary>
  3340. /// <param name="JsonData"></param>
  3341. /// <returns></returns>
  3342. public static DataTable MOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  3343. {
  3344. var language = LanguageHelper.GetName("WMSAPIInfo");
  3345. if (JsonData.Count <= 0)
  3346. {
  3347. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3348. }
  3349. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3350. {
  3351. conn.Open();
  3352. SqlTransaction sqlTran = conn.BeginTransaction();
  3353. SqlCommand cmd = new SqlCommand();
  3354. cmd.Transaction = sqlTran;
  3355. cmd.Connection = conn;
  3356. try
  3357. {
  3358. string codes = string.Empty;
  3359. string sql = string.Empty;
  3360. foreach (var item in JsonData)
  3361. {
  3362. //获取单号
  3363. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3364. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  3365. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  3366. IF @MaxNO IS NULL
  3367. BEGIN
  3368. SELECT @date+'00001' AS Code
  3369. END
  3370. ELSE
  3371. BEGIN
  3372. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3373. END ";
  3374. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3375. //创建主表
  3376. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  3377. BEGIN
  3378. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3379. RETURN
  3380. END
  3381. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3382. 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}','')";
  3383. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  3384. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3385. {
  3386. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  3387. }
  3388. foreach (var itemInfo in item.detail)
  3389. {
  3390. //创建子表
  3391. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  3392. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3393. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3394. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3395. '{4}','{5}',0,'{6}','{7}',
  3396. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3397. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3398. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3399. {
  3400. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  3401. }
  3402. }
  3403. //校验退料数量是否超出领料数量
  3404. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  3405. DBHelper.ExecuteNonQuery(sql, cmd);
  3406. codes += "'" + Code + item.WorkPoint + "',";
  3407. }
  3408. if (string.IsNullOrWhiteSpace(codes))
  3409. {
  3410. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3411. }
  3412. #region 查询返回数据
  3413. sql = @"SELECT a.ApplyNegCode,
  3414. c.WHCode,
  3415. c.Memo,
  3416. d.Name AS Status,
  3417. a.Sequence,
  3418. a.InvCode,
  3419. inv.InvName,
  3420. inv.InvStd,
  3421. a.Quantity,
  3422. inv.InvUnit,
  3423. a.Amount,
  3424. inv.AmountUnit,
  3425. a.IssueNegQuantity,
  3426. ext.ProjectCode,
  3427. ext.BatchCode,
  3428. ext.Version,
  3429. ext.Brand,
  3430. ext.cFree1,
  3431. ext.cFree2,
  3432. ext.cFree3,
  3433. ext.cFree4,
  3434. ext.cFree5,
  3435. ext.cFree6,
  3436. ext.cFree7,
  3437. ext.cFree8,
  3438. ext.cFree9,
  3439. ext.cFree10,
  3440. a.MUSER AS [User],
  3441. a.MTIME AS [MTime]
  3442. FROM ICSMOApplyNegDetail a
  3443. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3444. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3445. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3446. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3447. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  3448. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  3449. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3450. #endregion
  3451. cmd.Transaction.Commit();
  3452. return data;
  3453. }
  3454. catch (Exception ex)
  3455. {
  3456. if (cmd.Transaction != null)
  3457. cmd.Transaction.Rollback();
  3458. log.Error(ex.Message);
  3459. throw new Exception(ex.Message);
  3460. }
  3461. finally
  3462. {
  3463. if (conn.State == ConnectionState.Open)
  3464. {
  3465. conn.Close();
  3466. }
  3467. conn.Dispose();
  3468. }
  3469. }
  3470. }
  3471. private static string CheckMOIssueDoc(string Type, string ID, string WorkPoint, Dictionary<string, string> language)
  3472. {
  3473. string sql = string.Empty;
  3474. if (Type == "1")
  3475. {
  3476. sql = @"DECLARE @PickID VARCHAR(10)
  3477. SELECT @PickID=b.PickID
  3478. FROM ICSMOApplyNegDetail a
  3479. INNER JOIN ICSMOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  3480. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3481. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3482. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3483. FROM ICSMOApplyNegDetail a
  3484. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3485. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3486. GROUP BY b.PickID
  3487. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3488. IF (@PickID IS NOT NULL)
  3489. BEGIN
  3490. DECLARE @InvCode VARCHAR(100)
  3491. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  3492. RAISERROR(@InvCode,16,1);
  3493. RETURN
  3494. END ";
  3495. }
  3496. else if (Type == "2")
  3497. {
  3498. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  3499. SELECT @ApplyDetailID=b.ApplyDetailID
  3500. FROM ICSMOApplyNegDetail a
  3501. INNER JOIN ICSMOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  3502. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3503. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3504. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3505. FROM ICSMOApplyNegDetail a
  3506. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3507. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3508. GROUP BY b.ApplyDetailID
  3509. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3510. IF (@ApplyDetailID IS NOT NULL)
  3511. BEGIN
  3512. DECLARE @InvCode VARCHAR(100)
  3513. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  3514. RAISERROR(@InvCode,16,1);
  3515. RETURN
  3516. END ";
  3517. }
  3518. else if (Type == "3")
  3519. {
  3520. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  3521. SELECT @IssueDetailID=b.IssueDetailID
  3522. FROM ICSMOApplyNegDetail a
  3523. INNER JOIN ICSMOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  3524. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3525. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3526. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3527. FROM ICSMOApplyNegDetail a
  3528. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3529. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3530. GROUP BY b.IssueDetailID
  3531. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3532. IF (@IssueDetailID IS NOT NULL)
  3533. BEGIN
  3534. DECLARE @InvCode VARCHAR(100)
  3535. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  3536. RAISERROR(@InvCode,16,1);
  3537. RETURN
  3538. END ";
  3539. }
  3540. else
  3541. {
  3542. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  3543. }
  3544. sql = string.Format(sql, ID, WorkPoint, Type);
  3545. return sql;
  3546. }
  3547. /// <summary>
  3548. /// 生产退料 修改
  3549. /// </summary>
  3550. /// <param name="JsonData"></param>
  3551. /// <returns></returns>
  3552. public static DataTable MOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  3553. {
  3554. var language = LanguageHelper.GetName("WMSAPIInfo");
  3555. if (JsonData.Count <= 0)
  3556. {
  3557. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3558. }
  3559. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3560. {
  3561. conn.Open();
  3562. SqlTransaction sqlTran = conn.BeginTransaction();
  3563. SqlCommand cmd = new SqlCommand();
  3564. cmd.Transaction = sqlTran;
  3565. cmd.Connection = conn;
  3566. try
  3567. {
  3568. string sql = string.Empty;
  3569. string Code = string.Empty;
  3570. string ids = string.Empty;
  3571. foreach (var item in JsonData)
  3572. {
  3573. //主表修改
  3574. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  3575. BEGIN
  3576. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  3577. RETURN
  3578. END
  3579. DECLARE @Status VARCHAR(10)
  3580. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  3581. IF (@Status IS NULL)
  3582. BEGIN
  3583. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  3584. RETURN
  3585. END
  3586. ELSE IF (@Status!='1')
  3587. BEGIN
  3588. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  3589. RETURN
  3590. END
  3591. 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}' ";
  3592. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint);
  3593. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3594. {
  3595. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  3596. }
  3597. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  3598. if (detail > 0)
  3599. {
  3600. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  3601. sql = string.Format(sql, item.ID, item.WorkPoint);
  3602. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3603. }
  3604. foreach (var itemInfo in item.detail)
  3605. {
  3606. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  3607. {
  3608. //创建子表
  3609. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3610. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3611. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3612. '{4}','{5}',0,'{6}','{7}',
  3613. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3614. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3615. }
  3616. else
  3617. {
  3618. //子表修改
  3619. 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}'";
  3620. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  3621. }
  3622. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3623. {
  3624. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  3625. }
  3626. }
  3627. //校验退料数量是否超出领料数量
  3628. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  3629. DBHelper.ExecuteNonQuery(sql, cmd);
  3630. ids += "'" + item.ID + "',";
  3631. }
  3632. if (string.IsNullOrWhiteSpace(ids))
  3633. {
  3634. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3635. }
  3636. #region 查询返回数据
  3637. sql = @"SELECT a.ApplyNegCode,
  3638. c.WHCode,
  3639. c.Memo,
  3640. d.Name AS Status,
  3641. a.Sequence,
  3642. a.InvCode,
  3643. inv.InvName,
  3644. inv.InvStd,
  3645. a.Quantity,
  3646. inv.InvUnit,
  3647. a.Amount,
  3648. inv.AmountUnit,
  3649. a.IssueNegQuantity,
  3650. ext.ProjectCode,
  3651. ext.BatchCode,
  3652. ext.Version,
  3653. ext.Brand,
  3654. ext.cFree1,
  3655. ext.cFree2,
  3656. ext.cFree3,
  3657. ext.cFree4,
  3658. ext.cFree5,
  3659. ext.cFree6,
  3660. ext.cFree7,
  3661. ext.cFree8,
  3662. ext.cFree9,
  3663. ext.cFree10,
  3664. a.MUSER AS [User],
  3665. a.MTIME AS [MTime]
  3666. FROM ICSMOApplyNegDetail a
  3667. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3668. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3669. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3670. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3671. WHERE c.ID IN ({0})";
  3672. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3673. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3674. #endregion
  3675. cmd.Transaction.Commit();
  3676. return data;
  3677. }
  3678. catch (Exception ex)
  3679. {
  3680. if (cmd.Transaction != null)
  3681. cmd.Transaction.Rollback();
  3682. log.Error(ex.Message);
  3683. throw new Exception(ex.Message);
  3684. }
  3685. finally
  3686. {
  3687. if (conn.State == ConnectionState.Open)
  3688. {
  3689. conn.Close();
  3690. }
  3691. conn.Dispose();
  3692. }
  3693. }
  3694. }
  3695. /// <summary>
  3696. /// 生产退料审核
  3697. /// </summary>
  3698. /// <param name="JsonData"></param>
  3699. /// <returns></returns>
  3700. public static DataTable MOIssueDocNegativeApplyApprove(List<ICSUser> JsonData)
  3701. {
  3702. var language = LanguageHelper.GetName("WMSAPIInfo");
  3703. if (JsonData.Count <= 0)
  3704. {
  3705. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3706. }
  3707. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3708. {
  3709. conn.Open();
  3710. SqlTransaction sqlTran = conn.BeginTransaction();
  3711. SqlCommand cmd = new SqlCommand();
  3712. cmd.Transaction = sqlTran;
  3713. cmd.Connection = conn;
  3714. try
  3715. {
  3716. string sql = string.Empty;
  3717. string ids = string.Empty;
  3718. foreach (var item in JsonData)
  3719. {
  3720. if (string.IsNullOrEmpty(item.ID))
  3721. {
  3722. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  3723. }
  3724. if (string.IsNullOrEmpty(item.User))
  3725. {
  3726. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  3727. }
  3728. if (item.MTime <= new DateTime(2000, 1, 1))
  3729. {
  3730. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  3731. }
  3732. //获取单号
  3733. sql = @"DECLARE @Status VARCHAR(10)
  3734. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  3735. IF (@Status IS NULL)
  3736. BEGIN
  3737. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  3738. RETURN
  3739. END
  3740. ELSE IF (@Status!='1')
  3741. BEGIN
  3742. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  3743. RETURN
  3744. END
  3745. update ICSMOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  3746. sql = string.Format(sql, item.ID, item.User, item.MTime);
  3747. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3748. {
  3749. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  3750. }
  3751. ids += "'" + item.ID + "',";
  3752. }
  3753. if (string.IsNullOrWhiteSpace(ids))
  3754. {
  3755. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3756. }
  3757. #region 查询返回数据
  3758. sql = @"SELECT a.ApplyNegCode,
  3759. c.WHCode,
  3760. c.Memo,
  3761. d.Name AS Status,
  3762. a.Sequence,
  3763. a.InvCode,
  3764. inv.InvName,
  3765. inv.InvStd,
  3766. a.Quantity,
  3767. inv.InvUnit,
  3768. a.Amount,
  3769. inv.AmountUnit,
  3770. a.IssueNegQuantity,
  3771. ext.ProjectCode,
  3772. ext.BatchCode,
  3773. ext.Version,
  3774. ext.Brand,
  3775. ext.cFree1,
  3776. ext.cFree2,
  3777. ext.cFree3,
  3778. ext.cFree4,
  3779. ext.cFree5,
  3780. ext.cFree6,
  3781. ext.cFree7,
  3782. ext.cFree8,
  3783. ext.cFree9,
  3784. ext.cFree10,
  3785. a.MUSER AS [User],
  3786. a.MTIME AS [MTime]
  3787. FROM ICSMOApplyNegDetail a
  3788. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3789. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3790. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3791. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3792. WHERE c.ID IN ({0})";
  3793. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3794. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3795. #endregion
  3796. cmd.Transaction.Commit();
  3797. return data;
  3798. }
  3799. catch (Exception ex)
  3800. {
  3801. if (cmd.Transaction != null)
  3802. cmd.Transaction.Rollback();
  3803. log.Error(ex.Message);
  3804. throw new Exception(ex.Message);
  3805. }
  3806. finally
  3807. {
  3808. if (conn.State == ConnectionState.Open)
  3809. {
  3810. conn.Close();
  3811. }
  3812. conn.Dispose();
  3813. }
  3814. }
  3815. }
  3816. #endregion
  3817. #region 一步调拨
  3818. /// <summary>
  3819. /// 一步调拨
  3820. /// </summary>
  3821. /// <param name="JsonData"></param>
  3822. /// <returns></returns>
  3823. public static DataTable OneStepTransferDocIn(List<TransferDoc> JsonData)
  3824. {
  3825. var language = LanguageHelper.GetName("WMSAPIInfo");
  3826. if (JsonData.Count <= 0)
  3827. {
  3828. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3829. }
  3830. DataTable printTable = new DataTable();
  3831. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3832. {
  3833. conn.Open();
  3834. SqlTransaction sqlTran = conn.BeginTransaction();
  3835. SqlCommand cmd = new SqlCommand();
  3836. cmd.Transaction = sqlTran;
  3837. cmd.Connection = conn;
  3838. try
  3839. {
  3840. string sql = string.Empty;
  3841. string Identification = Guid.NewGuid().ToString();
  3842. foreach (var item in JsonData)
  3843. {
  3844. if (string.IsNullOrEmpty(item.TransCode) )
  3845. {
  3846. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨单号不能为空!");
  3847. }
  3848. string[] trans = item.TransCode.Split('~');
  3849. string MergeID = "";
  3850. if (trans.Length == 2)
  3851. {
  3852. MergeID = trans[0];
  3853. item.TransCode = trans[1];
  3854. }
  3855. //验证信息
  3856. sql = @"DECLARE @Status VARCHAR(10)
  3857. SELECT @Status=Status FROM ICSTransfer WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  3858. IF (@Status IS NULL)
  3859. BEGIN
  3860. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  3861. RETURN
  3862. END
  3863. ELSE IF (@Status!='1')
  3864. BEGIN
  3865. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  3866. RETURN
  3867. END";
  3868. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  3869. DBHelper.ExecuteNonQuery(sql, cmd);
  3870. foreach (var itemInfo in item.Detail)
  3871. {
  3872. //验证仓库库位信息
  3873. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  3874. BEGIN
  3875. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  3876. RETURN
  3877. END
  3878. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  3879. BEGIN
  3880. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  3881. RETURN
  3882. END
  3883. IF NOT EXISTS(SELECT a.ID
  3884. FROM ICSWareHouse a
  3885. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  3886. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  3887. BEGIN
  3888. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  3889. RETURN
  3890. END";
  3891. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  3892. DBHelper.ExecuteNonQuery(sql, cmd);
  3893. //更新源头单据信息
  3894. ICSWareHouseService.OneStepTransferDocIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  3895. //更新条码信息
  3896. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  3897. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  3898. }
  3899. }
  3900. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language);
  3901. if (!printTable.Equals("{}"))
  3902. {
  3903. cmd.Transaction.Commit();
  3904. return printTable;
  3905. }
  3906. else
  3907. {
  3908. DataTable table = GetData(Identification, 3, cmd);
  3909. cmd.Transaction.Commit();
  3910. return table;
  3911. }
  3912. }
  3913. catch (Exception ex)
  3914. {
  3915. if (cmd.Transaction != null)
  3916. cmd.Transaction.Rollback();
  3917. log.Error(ex.Message);
  3918. throw new Exception(ex.Message);
  3919. }
  3920. finally
  3921. {
  3922. if (conn.State == ConnectionState.Open)
  3923. {
  3924. conn.Close();
  3925. }
  3926. conn.Dispose();
  3927. }
  3928. }
  3929. }
  3930. #endregion
  3931. #region 调拨(无来源)
  3932. /// <summary>
  3933. /// 调拨
  3934. /// </summary>
  3935. /// <param name="JsonData"></param>
  3936. /// <returns></returns>
  3937. public static DataTable TransferDocCreate(List<TransferDoc> JsonData)
  3938. {
  3939. var language = LanguageHelper.GetName("WMSAPIInfo");
  3940. if (JsonData.Count <= 0)
  3941. {
  3942. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3943. }
  3944. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3945. {
  3946. conn.Open();
  3947. SqlTransaction sqlTran = conn.BeginTransaction();
  3948. SqlCommand cmd = new SqlCommand();
  3949. cmd.Transaction = sqlTran;
  3950. cmd.Connection = conn;
  3951. try
  3952. {
  3953. string sql = string.Empty;
  3954. string Identification = Guid.NewGuid().ToString();
  3955. foreach (var item in JsonData)
  3956. {
  3957. string MergeID = "";
  3958. foreach (var itemInfo in item.Detail)
  3959. {
  3960. //验证仓库库位信息
  3961. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  3962. BEGIN
  3963. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  3964. RETURN
  3965. END
  3966. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  3967. BEGIN
  3968. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  3969. RETURN
  3970. END
  3971. IF NOT EXISTS(SELECT a.ID
  3972. FROM ICSWareHouse a
  3973. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  3974. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  3975. BEGIN
  3976. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  3977. RETURN
  3978. END";
  3979. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  3980. DBHelper.ExecuteNonQuery(sql, cmd);
  3981. //更新条码信息
  3982. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  3983. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  3984. }
  3985. }
  3986. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferDocIn.GetDescription(), Identification, cmd, language);
  3987. DataTable table = GetData(Identification, 3, cmd);
  3988. cmd.Transaction.Commit();
  3989. return table;
  3990. }
  3991. catch (Exception ex)
  3992. {
  3993. if (cmd.Transaction != null)
  3994. cmd.Transaction.Rollback();
  3995. log.Error(ex.Message);
  3996. throw new Exception(ex.Message);
  3997. }
  3998. finally
  3999. {
  4000. if (conn.State == ConnectionState.Open)
  4001. {
  4002. conn.Close();
  4003. }
  4004. conn.Dispose();
  4005. }
  4006. }
  4007. }
  4008. #endregion
  4009. #region 调拨
  4010. /// <summary>
  4011. /// 调拨
  4012. /// </summary>
  4013. /// <param name="JsonData"></param>
  4014. /// <returns></returns>
  4015. public static DataTable TransferDocInCreate(List<TransferDoc> JsonData)
  4016. {
  4017. var language = LanguageHelper.GetName("WMSAPIInfo");
  4018. if (JsonData.Count <= 0)
  4019. {
  4020. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4021. }
  4022. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4023. {
  4024. conn.Open();
  4025. SqlTransaction sqlTran = conn.BeginTransaction();
  4026. SqlCommand cmd = new SqlCommand();
  4027. cmd.Transaction = sqlTran;
  4028. cmd.Connection = conn;
  4029. try
  4030. {
  4031. string sql = string.Empty;
  4032. string Identification = Guid.NewGuid().ToString();
  4033. foreach (var item in JsonData)
  4034. {
  4035. string MergeID = "";
  4036. foreach (var itemInfo in item.Detail)
  4037. {
  4038. //验证仓库库位信息
  4039. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4040. BEGIN
  4041. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4042. RETURN
  4043. END
  4044. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4045. BEGIN
  4046. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4047. RETURN
  4048. END
  4049. IF NOT EXISTS(SELECT a.ID
  4050. FROM ICSWareHouse a
  4051. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4052. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4053. BEGIN
  4054. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4055. RETURN
  4056. END
  4057. IF EXISTS(SELECT ID
  4058. FROM ICSWareHouseLotInfo
  4059. WHERE WarehouseCode='{0}' AND WorkPoint='{1}' AND LotNo='{3}')
  4060. BEGIN
  4061. RAISERROR('" + language.GetNameByCode("WMSAPIInfo355") + @"',16,1);
  4062. RETURN
  4063. END";
  4064. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode, itemInfo.LotNo);
  4065. DBHelper.ExecuteNonQuery(sql, cmd);
  4066. //更新源头单据信息
  4067. ICSWareHouseService.OneStepTransferDocIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  4068. //更新条码信息
  4069. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4070. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4071. }
  4072. }
  4073. ICSWareHouseService.StepTransferDocERP(TransTypeEnum.StepTransferDocIn.GetDescription(), Identification, cmd, language);
  4074. DataTable table = GetData(Identification, 3, cmd);
  4075. cmd.Transaction.Commit();
  4076. return table;
  4077. }
  4078. catch (Exception ex)
  4079. {
  4080. if (cmd.Transaction != null)
  4081. cmd.Transaction.Rollback();
  4082. log.Error(ex.Message);
  4083. throw new Exception(ex.Message);
  4084. }
  4085. finally
  4086. {
  4087. if (conn.State == ConnectionState.Open)
  4088. {
  4089. conn.Close();
  4090. }
  4091. conn.Dispose();
  4092. }
  4093. }
  4094. }
  4095. #endregion
  4096. #region 移库
  4097. /// <summary>
  4098. /// 移库
  4099. /// </summary>
  4100. /// <param name="JsonData"></param>
  4101. /// <returns></returns>
  4102. public static DataTable LibraryUpdate(List<ICSLibraryModel> JsonData)
  4103. {
  4104. var language = LanguageHelper.GetName("WMSAPIInfo");
  4105. if (JsonData.Count <= 0)
  4106. {
  4107. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4108. }
  4109. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4110. {
  4111. conn.Open();
  4112. SqlTransaction sqlTran = conn.BeginTransaction();
  4113. SqlCommand cmd = new SqlCommand();
  4114. cmd.Transaction = sqlTran;
  4115. cmd.Connection = conn;
  4116. try
  4117. {
  4118. string sql = string.Empty;
  4119. string Identification = Guid.NewGuid().ToString();
  4120. foreach (var item in JsonData)
  4121. {
  4122. if (string.IsNullOrEmpty(item.LotNo))
  4123. {
  4124. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4125. }
  4126. //验证仓库库位信息
  4127. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4128. BEGIN
  4129. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4130. RETURN
  4131. END
  4132. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4133. BEGIN
  4134. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  4135. RETURN
  4136. END
  4137. IF NOT EXISTS(SELECT a.ID
  4138. FROM ICSWareHouse a
  4139. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4140. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4141. BEGIN
  4142. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4143. RETURN
  4144. END";
  4145. sql = string.Format(sql, item.WarehouseCode, item.WorkPoint, item.LocationCode);
  4146. DBHelper.ExecuteNonQuery(sql, cmd);
  4147. //更新条码信息
  4148. ICSWareHouseLotInfoService.WareHouseLotInfoLibrary(Identification, item.TransCode, item.TransSequence, item.WarehouseCode, item.LocationCode, item.LotNo,
  4149. item.User, item.WorkPoint, "7", "29", cmd, language);
  4150. }
  4151. DataTable table = GetData(Identification, 3, cmd);
  4152. cmd.Transaction.Commit();
  4153. return table;
  4154. }
  4155. catch (Exception ex)
  4156. {
  4157. if (cmd.Transaction != null)
  4158. cmd.Transaction.Rollback();
  4159. log.Error(ex.Message);
  4160. throw new Exception(ex.Message);
  4161. }
  4162. finally
  4163. {
  4164. if (conn.State == ConnectionState.Open)
  4165. {
  4166. conn.Close();
  4167. }
  4168. conn.Dispose();
  4169. }
  4170. }
  4171. }
  4172. #endregion
  4173. #region 合并
  4174. /// <summary>
  4175. /// 合并
  4176. /// </summary>
  4177. /// <param name="JsonData"></param>
  4178. /// <returns></returns>
  4179. public static DataTable LOTMergeCreate(List<LOTCreateIModel> JsonData)
  4180. {
  4181. var language = LanguageHelper.GetName("WMSAPIInfo");
  4182. if (JsonData.Count <= 0)
  4183. {
  4184. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4185. }
  4186. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4187. {
  4188. conn.Open();
  4189. SqlTransaction sqlTran = conn.BeginTransaction();
  4190. SqlCommand cmd = new SqlCommand();
  4191. cmd.Transaction = sqlTran;
  4192. cmd.Connection = conn;
  4193. try
  4194. {
  4195. string Identification = Guid.NewGuid().ToString();
  4196. foreach (var item in JsonData)
  4197. {
  4198. if (string.IsNullOrEmpty(item.LotNo))
  4199. {
  4200. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4201. }
  4202. else if (item.detail.Count <= 0)
  4203. {
  4204. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  4205. }
  4206. //合并前日志
  4207. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  4208. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  4209. foreach (var info in item.detail)
  4210. {
  4211. //合并前日志
  4212. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, info.CurrentLotNo, item.User, item.WorkPoint, "5",
  4213. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  4214. //更新条码信息
  4215. ICSWareHouseLotInfoService.WareHouseLotInfoMerge(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "5",
  4216. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  4217. }
  4218. //合并后日志
  4219. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  4220. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  4221. }
  4222. DataTable table = GetData(Identification, 1, cmd);
  4223. cmd.Transaction.Commit();
  4224. return table;
  4225. }
  4226. catch (Exception ex)
  4227. {
  4228. if (cmd.Transaction != null)
  4229. cmd.Transaction.Rollback();
  4230. log.Error(ex.Message);
  4231. throw new Exception(ex.Message);
  4232. }
  4233. finally
  4234. {
  4235. if (conn.State == ConnectionState.Open)
  4236. {
  4237. conn.Close();
  4238. }
  4239. conn.Dispose();
  4240. }
  4241. }
  4242. }
  4243. #endregion
  4244. #region 拆分
  4245. /// <summary>
  4246. /// 拆分
  4247. /// </summary>
  4248. /// <param name="JsonData"></param>
  4249. /// <returns></returns>
  4250. public static DataTable LOTSplitCreate(List<LOTCreateIModel> JsonData)
  4251. {
  4252. var language = LanguageHelper.GetName("WMSAPIInfo");
  4253. if (JsonData.Count <= 0)
  4254. {
  4255. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4256. }
  4257. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4258. {
  4259. conn.Open();
  4260. SqlTransaction sqlTran = conn.BeginTransaction();
  4261. SqlCommand cmd = new SqlCommand();
  4262. cmd.Transaction = sqlTran;
  4263. cmd.Connection = conn;
  4264. try
  4265. {
  4266. string Identification = Guid.NewGuid().ToString();
  4267. foreach (var item in JsonData)
  4268. {
  4269. if (string.IsNullOrEmpty(item.LotNo))
  4270. {
  4271. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4272. }
  4273. else if (item.detail.Count <= 0)
  4274. {
  4275. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  4276. }
  4277. //拆分前日志
  4278. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  4279. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(), cmd, language);
  4280. foreach (var info in item.detail)
  4281. {
  4282. //更新条码信息
  4283. ICSWareHouseLotInfoService.WareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  4284. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  4285. }
  4286. //拆分后日志
  4287. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  4288. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  4289. }
  4290. DataTable table = GetData(Identification, 1, cmd);
  4291. cmd.Transaction.Commit();
  4292. return table;
  4293. }
  4294. catch (Exception ex)
  4295. {
  4296. if (cmd.Transaction != null)
  4297. cmd.Transaction.Rollback();
  4298. log.Error(ex.Message);
  4299. throw new Exception(ex.Message);
  4300. }
  4301. finally
  4302. {
  4303. if (conn.State == ConnectionState.Open)
  4304. {
  4305. conn.Close();
  4306. }
  4307. conn.Dispose();
  4308. }
  4309. }
  4310. }
  4311. #endregion
  4312. /// <summary>
  4313. /// 获取出入库记录信息
  4314. /// </summary>
  4315. /// <param name="Identification"></param>
  4316. /// <param name="type">1:入库,2:出库,3:调拨</param>
  4317. /// <param name="cmd"></param>
  4318. /// <returns></returns>
  4319. private static DataTable GetData(string Identification, int type, SqlCommand cmd)
  4320. {
  4321. #region SLQ
  4322. string sql = @"SELECT log.ID,
  4323. log.TransCode,
  4324. log.TransSequence,
  4325. log.LotNo,
  4326. log.InvCode,
  4327. inv.InvName,
  4328. inv.InvStd,
  4329. log.Quantity,
  4330. inv.InvUnit,
  4331. log.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  4332. inv.AmountUnit,
  4333. {1}
  4334. ext.ProjectCode,
  4335. 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,
  4336. ext.Version,
  4337. ext.Brand,
  4338. ext.cFree1,
  4339. ext.cFree2,
  4340. ext.cFree3,
  4341. ext.cFree4,
  4342. ext.cFree5,
  4343. ext.cFree6,
  4344. ext.cFree7,
  4345. ext.cFree8,
  4346. ext.cFree9,
  4347. ext.cFree10,
  4348. type.Name AS TransType,
  4349. log.MUSER AS [User],
  4350. log.MTIME AS [MTime]
  4351. FROM ICSWareHouseLotInfoLog log
  4352. LEFT JOIN ICSType type ON type.TableCode='ICSWareHouseLotInfoLog' AND type.ColumnCode='BusinessCode' AND log.BusinessCode=type.Code AND log.WorkPoint=type.WorkPoint
  4353. INNER JOIN ICSInventoryLot lot ON log.LotNo=lot.LotNo AND log.WorkPoint=lot.WorkPoint
  4354. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4355. INNER JOIN ICSInventory inv ON log.InvCode=inv.InvCode AND log.WorkPoint=inv.WorkPoint
  4356. {2}
  4357. LEFT JOIN ICSInventoryBatchEnable invBat ON log.InvCode=invBat.InvCode AND log.FromWarehouseCode=invBat.WHCode AND log.WorkPoint=invBat.WorkPoint
  4358. WHERE log.Identification='{0}'";
  4359. #endregion
  4360. string columns = @"log.ToWarehouseCode AS WHCode,
  4361. log.ToLocationCode AS LocationCode,
  4362. wh.WarehouseName AS WHName,
  4363. loc.LocationName AS LocationName,";
  4364. string tables = @"INNER JOIN ICSWarehouse wh ON log.ToWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4365. INNER JOIN ICSLocation loc ON log.ToLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  4366. if (type == 2)//出库
  4367. {
  4368. columns = @"log.FromWarehouseCode AS WHCode,
  4369. log.FromLocationCode AS LocationCode,
  4370. wh.WarehouseName AS WHName,
  4371. loc.LocationName AS LocationName,";
  4372. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4373. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  4374. }
  4375. else if (type == 3)//调拨
  4376. {
  4377. columns = @"log.FromWarehouseCode AS FromWHCode,
  4378. log.FromLocationCode,
  4379. wh.WarehouseName AS FromWHName,
  4380. loc.LocationName AS FromLocationName,
  4381. log.ToWarehouseCode AS ToWHCode,
  4382. log.ToLocationCode,
  4383. whto.WarehouseName AS ToWHName,
  4384. locto.LocationName AS ToLocationName,";
  4385. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4386. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint
  4387. INNER JOIN ICSWarehouse whto ON log.ToWarehouseCode=whto.WarehouseCode AND log.WorkPoint=whto.WorkPoint
  4388. INNER JOIN ICSLocation locto ON log.ToLocationCode=locto.LocationCode AND log.WorkPoint=locto.WorkPoint";
  4389. }
  4390. sql = string.Format(sql, Identification, columns, tables);
  4391. return DBHelper.SQlReturnData(sql, cmd);
  4392. }
  4393. /// <summary>
  4394. /// 先进先出批次管控
  4395. /// </summary>
  4396. /// <param name="LotNo"></param>
  4397. /// <param name="WorkPoitCode"></param>
  4398. /// <param name="cmd"></param>
  4399. /// <returns></returns>
  4400. public static string CanOut(string LotNo, string WorkPoitCode, string ScanLotCode, SqlCommand cmd, Dictionary<string, string> language)
  4401. {
  4402. try
  4403. {
  4404. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  4405. string sql = @"DECLARE @CountNO INT,@Days INT
  4406. SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
  4407. SET @CountNO=(
  4408. SELECT COUNT(a.LotNO) FROM ICSWareHouseLotInfo a
  4409. INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO AND a.WorkPoint=b.WorkPoint
  4410. WHERE a.WorkPoint='{1}' AND ISNULL(a.Quantity,0)>0 AND 1=1
  4411. AND CONVERT(varchar(100), a.InDate, 23)<
  4412. (SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), x.InDate, 23)) FROM ICSWareHouseLotInfo x
  4413. INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
  4414. WHERE x.LotNO='{0}' AND x.WorkPoint='{1}' AND y.INVCode=b.INVCode AND y.ExtensionID=b.ExtensionID)
  4415. )
  4416. IF @CountNO>0
  4417. BEGIN
  4418. SELECT TOP 1 CASE a.F_ItemCode WHEN 'FIFO01' THEN '1' WHEN 'FIFO02' THEN '2' ELSE '3' END AS Type
  4419. FROM Sys_SRM_ItemsDetail a
  4420. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  4421. WHERE b.F_EnCode='FIFO' AND a.F_EnabledMark='1'
  4422. ORDER BY a.F_SortCode DESC
  4423. END
  4424. ELSE
  4425. BEGIN
  4426. SELECT @CountNO
  4427. END";
  4428. //0 - 已经是最早的批次
  4429. //1 - 不管控
  4430. //2 - 提醒
  4431. //3 - 限制
  4432. sql = string.Format(sql, LotNo, WorkPoitCode);
  4433. if (!string.IsNullOrWhiteSpace(ScanLotCode))
  4434. {
  4435. sql = sql.Replace("1=1", "a.LotNO NOT IN (" + ScanLotCode + ")");
  4436. }
  4437. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4438. if (string.IsNullOrWhiteSpace(res))
  4439. {
  4440. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  4441. }
  4442. else
  4443. return res;
  4444. }
  4445. catch (Exception ex)
  4446. {
  4447. throw new Exception(ex.Message);
  4448. }
  4449. }
  4450. /// <summary>
  4451. /// 保质期管控
  4452. /// </summary>
  4453. /// <param name="LotNo"></param>
  4454. /// <param name="WorkPoitCode"></param>
  4455. /// <param name="cmd"></param>
  4456. /// <returns></returns>
  4457. public static string Effective(string LotNo, string WorkPoitCode, SqlCommand cmd, Dictionary<string, string> language)
  4458. {
  4459. try
  4460. {
  4461. string sql = @"DECLARE @CountNO INT,@Days INT,@CurrentDays INT
  4462. SELECT @CountNO=EffectiveEnable,@Days=EffectiveDays,@CurrentDays=DATEDIFF(DAY, GETDATE(), b.ExpirationDate) FROM ICSInventory a
  4463. INNER JOIN ICSInventoryLot b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  4464. INNER JOIN ICSWareHouseLotInfo c ON b.LotNO=c.LotNO AND b.WorkPoint=c.WorkPoint
  4465. WHERE b.LotNO='{0}' AND b.WorkPoint='{1}'
  4466. IF @CountNO='1' AND @CurrentDays<0
  4467. BEGIN
  4468. SELECT TOP 1 CASE a.F_ItemCode WHEN 'Effective01' THEN '1' WHEN 'Effective02' THEN '2' ELSE '3' END AS Type
  4469. FROM Sys_SRM_ItemsDetail a
  4470. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  4471. WHERE b.F_EnCode='Effective' AND a.F_EnabledMark='1'
  4472. ORDER BY a.F_SortCode DESC
  4473. END
  4474. ELSE
  4475. BEGIN
  4476. SELECT @CountNO
  4477. END";
  4478. //0 - 已经是最早的批次
  4479. //1 - 不管控
  4480. //2 - 提醒
  4481. //3 - 限制
  4482. sql = string.Format(sql, LotNo, WorkPoitCode);
  4483. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4484. if (string.IsNullOrWhiteSpace(res))
  4485. {
  4486. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  4487. }
  4488. else
  4489. return res;
  4490. }
  4491. catch (Exception ex)
  4492. {
  4493. throw new Exception(ex.Message);
  4494. }
  4495. }
  4496. #region 包装
  4497. /// <summary>
  4498. /// 查询包装信息
  4499. /// </summary>
  4500. /// <param name="JsonData"></param>
  4501. /// <returns></returns>
  4502. public static object ContainerGet(ICSContainer JsonData)
  4503. {
  4504. var language = LanguageHelper.GetName("WMSAPIInfo");
  4505. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4506. {
  4507. conn.Open();
  4508. SqlTransaction sqlTran = conn.BeginTransaction();
  4509. SqlCommand cmd = new SqlCommand();
  4510. cmd.Transaction = sqlTran;
  4511. cmd.Connection = conn;
  4512. try
  4513. {
  4514. string sql = string.Empty;
  4515. //目标包装
  4516. if (JsonData.ToContainerCode != null)
  4517. {
  4518. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4519. BEGIN
  4520. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4521. RETURN
  4522. END
  4523. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  4524. sql = string.Format(sql, JsonData.ToContainerCode, JsonData.WorkPoint);
  4525. }
  4526. ///原包装
  4527. else if (JsonData.FromContainerCode != null)
  4528. {
  4529. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4530. BEGIN
  4531. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4532. RETURN
  4533. END
  4534. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  4535. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4536. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  4537. BEGIN
  4538. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  4539. RETURN
  4540. END
  4541. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  4542. sql = string.Format(sql, JsonData.FromContainerCode, JsonData.WorkPoint);
  4543. }
  4544. else
  4545. {
  4546. throw new Exception(language.GetNameByCode("WMSAPIInfo029"));//"请传入包装条码!");
  4547. }
  4548. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  4549. cmd.Transaction.Commit();
  4550. return table;
  4551. }
  4552. catch (Exception ex)
  4553. {
  4554. if (cmd.Transaction != null)
  4555. cmd.Transaction.Rollback();
  4556. log.Error(ex.Message);
  4557. throw new Exception(ex.Message);
  4558. }
  4559. finally
  4560. {
  4561. if (conn.State == ConnectionState.Open)
  4562. {
  4563. conn.Close();
  4564. }
  4565. conn.Dispose();
  4566. }
  4567. }
  4568. }
  4569. /// <summary>
  4570. /// 修改包装信息
  4571. /// </summary>
  4572. /// <param name="JsonData"></param>
  4573. /// <returns></returns>
  4574. public static DataTable ContainerUpdate(List<ICSContainer> JsonData)
  4575. {
  4576. var language = LanguageHelper.GetName("WMSAPIInfo");
  4577. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4578. {
  4579. conn.Open();
  4580. SqlTransaction sqlTran = conn.BeginTransaction();
  4581. SqlCommand cmd = new SqlCommand();
  4582. cmd.Transaction = sqlTran;
  4583. cmd.Connection = conn;
  4584. try
  4585. {
  4586. string sql = string.Empty;
  4587. string codes = string.Empty;
  4588. foreach (ICSContainer container in JsonData)
  4589. {
  4590. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4591. BEGIN
  4592. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4593. RETURN
  4594. END
  4595. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  4596. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4597. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  4598. BEGIN
  4599. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  4600. RETURN
  4601. END
  4602. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{2}' and WorkPoint='{1}')
  4603. BEGIN
  4604. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  4605. RETURN
  4606. END
  4607. UPDATE b SET ContainerID=c.ID
  4608. FROM ICSContainer a
  4609. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4610. INNER JOIN ICSContainer c ON c.ContainerCODE ='{2}' and a.WorkPoint=c.WorkPoint
  4611. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}'";
  4612. sql = string.Format(sql, container.FromContainerCode, container.WorkPoint, container.ToContainerCode);
  4613. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4614. {
  4615. throw new Exception(language.GetNameByCode("WMSAPIInfo030"));//"包装更新失败!");
  4616. }
  4617. codes += "'" + container.ToContainerCode + container.WorkPoint + "',";
  4618. }
  4619. sql = @"SELECT a.ContainerCode, a.ContainerName,b.LotNo FROM ICSContainer a
  4620. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4621. WHERE a.ContainerCODE+a.WorkPoint IN({0})";
  4622. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  4623. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  4624. cmd.Transaction.Commit();
  4625. return table;
  4626. }
  4627. catch (Exception ex)
  4628. {
  4629. if (cmd.Transaction != null)
  4630. cmd.Transaction.Rollback();
  4631. log.Error(ex.Message);
  4632. throw new Exception(ex.Message);
  4633. }
  4634. finally
  4635. {
  4636. if (conn.State == ConnectionState.Open)
  4637. {
  4638. conn.Close();
  4639. }
  4640. conn.Dispose();
  4641. }
  4642. }
  4643. }
  4644. #endregion
  4645. #region 盘点
  4646. /// <summary>
  4647. /// 创建盘点单
  4648. /// </summary>
  4649. /// <param name="JsonData"></param>
  4650. /// <returns></returns>
  4651. public static DataTable CheckCreate(List<ICSCheck> JsonData)
  4652. {
  4653. var language = LanguageHelper.GetName("WMSAPIInfo");
  4654. if (JsonData.Count <= 0)
  4655. {
  4656. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4657. }
  4658. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4659. {
  4660. conn.Open();
  4661. SqlTransaction sqlTran = conn.BeginTransaction();
  4662. SqlCommand cmd = new SqlCommand();
  4663. cmd.Transaction = sqlTran;
  4664. cmd.Connection = conn;
  4665. try
  4666. {
  4667. string Code = string.Empty;
  4668. string sql = string.Empty;
  4669. foreach (var item in JsonData)
  4670. {
  4671. if (string.IsNullOrEmpty(item.User))
  4672. {
  4673. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  4674. }
  4675. if (string.IsNullOrEmpty(item.WorkPoint))
  4676. {
  4677. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  4678. }
  4679. //获取单号
  4680. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  4681. BEGIN
  4682. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  4683. RETURN
  4684. END
  4685. DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  4686. SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck
  4687. WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date
  4688. IF @MaxNO IS NULL
  4689. BEGIN
  4690. SELECT @date+'00001' AS Code
  4691. END
  4692. ELSE
  4693. BEGIN
  4694. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  4695. END ";
  4696. sql = string.Format(sql, item.User, item.WorkPoint);
  4697. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4698. //创建盘点单
  4699. foreach (var itemInfo in item.detail)
  4700. {
  4701. int len = itemInfo.SelectLevel.Length;
  4702. sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSWareHouseLotInfo WHERE SUBSTRING(LocationCode,1,{4}) = '{1}' )
  4703. BEGIN
  4704. RAISERROR('" + language.GetNameByCode("WMSAPIInfo367") + @"',16,1);
  4705. RETURN
  4706. END
  4707. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint,InvCode,BatchCode)
  4708. SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,a.InvCode,ext.BatchCode
  4709. FROM ICSWareHouseLotInfo a
  4710. INNER JOIN ICSInventoryLot lot on a.lotno=lot.lotno and a.WorkPoint=lot.WorkPoint
  4711. LEFT JOIN ICSExtension ext on lot.ExtensionID=ext.ID and a.WorkPoint=ext.WorkPoint
  4712. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4713. WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
  4714. GROUP BY a.WarehouseCode,a.InvCode,BatchCode,b.F_Account,b.F_RealName,b.F_Location";
  4715. // sql = @"INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint,InvCode)
  4716. // SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location,a.InvCode
  4717. // FROM ICSWareHouseLotInfo a
  4718. // INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4719. // WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
  4720. // GROUP BY b.F_Account,b.F_RealName,b.F_Location";
  4721. sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len);
  4722. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4723. {
  4724. throw new Exception(language.GetNameByCode("WMSAPIInfo031"));//"盘点单创建失败!");
  4725. }
  4726. }
  4727. }
  4728. if (string.IsNullOrWhiteSpace(Code))
  4729. {
  4730. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单单号不能为空!");
  4731. }
  4732. #region 查询返回数据
  4733. sql = @"SELECT a.ID,a.CheckCode,a.SelectLevel,
  4734. a.Quantity,
  4735. a.Amount,
  4736. a.MUSER AS [User],
  4737. a.MTIME AS [MTime]
  4738. FROM ICSCheck a
  4739. WHERE a.CheckCode='{0}'";
  4740. sql = string.Format(sql, Code);
  4741. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4742. #endregion
  4743. cmd.Transaction.Commit();
  4744. return data;
  4745. }
  4746. catch (Exception ex)
  4747. {
  4748. if (cmd.Transaction != null)
  4749. cmd.Transaction.Rollback();
  4750. log.Error(ex.Message);
  4751. throw new Exception(ex.Message);
  4752. }
  4753. finally
  4754. {
  4755. if (conn.State == ConnectionState.Open)
  4756. {
  4757. conn.Close();
  4758. }
  4759. conn.Dispose();
  4760. }
  4761. }
  4762. }
  4763. /// <summary>
  4764. /// 盘点扫描
  4765. /// </summary>
  4766. /// <param name="JsonData"></param>
  4767. /// <returns></returns>
  4768. public static DataTable LOTCheckCreate(List<ICSCheck> JsonData)
  4769. {
  4770. var language = LanguageHelper.GetName("WMSAPIInfo");
  4771. if (JsonData.Count <= 0)
  4772. {
  4773. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4774. }
  4775. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4776. {
  4777. conn.Open();
  4778. SqlTransaction sqlTran = conn.BeginTransaction();
  4779. SqlCommand cmd = new SqlCommand();
  4780. cmd.Transaction = sqlTran;
  4781. cmd.Connection = conn;
  4782. try
  4783. {
  4784. string lots = string.Empty;
  4785. string sql = string.Empty;
  4786. int result = 0;
  4787. string Identification = Guid.NewGuid().ToString();
  4788. foreach (var item in JsonData)
  4789. {
  4790. if (string.IsNullOrEmpty(item.User))
  4791. {
  4792. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  4793. }
  4794. if (string.IsNullOrEmpty(item.WorkPoint))
  4795. {
  4796. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  4797. }
  4798. if (string.IsNullOrEmpty(item.CheckCode))
  4799. {
  4800. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单号不能为空!");
  4801. }
  4802. //校验
  4803. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  4804. BEGIN
  4805. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  4806. RETURN
  4807. END
  4808. IF NOT EXISTS(SELECT ID FROM ICSCheck WHERE CheckCode='{2}' AND WorkPoint='{1}')
  4809. BEGIN
  4810. RAISERROR('" + language.GetNameByCode("WMSAPIInfo075") + @"',16,1);
  4811. RETURN
  4812. END";
  4813. sql = string.Format(sql, item.User, item.WorkPoint, item.CheckCode);
  4814. DBHelper.ExecuteNonQuery(sql, cmd);
  4815. //创建盘点单
  4816. foreach (var itemInfo in item.detail)
  4817. {
  4818. sql = @"IF NOT EXISTS(SELECT LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{1}' AND WorkPoint='{3}')
  4819. BEGIN
  4820. RAISERROR('" + language.GetNameByCode("WMSAPIInfo076") + @"',16,1);
  4821. RETURN
  4822. END
  4823. IF EXISTS(SELECT LotNo FROM ICSCheckDetail WHERE CheckCode='{0}' AND LotNo='{1}' AND WorkPoint='{3}')
  4824. BEGIN
  4825. UPDATE a SET Quantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  4826. FROM ICSCheckDetail a
  4827. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4828. WHERE a.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  4829. END
  4830. ELSE
  4831. BEGIN
  4832. INSERT INTO ICSCheckDetail (ID,CheckCode,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,CheckAmount,ReplayAmount,CheckQuantity,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,BatchCode)
  4833. SELECT NEWID(),'{0}',a.LotNo,'{4}',0,0,0,0,0,0,0,b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint,'',ext.BatchCode
  4834. FROM ICSWareHouseLotInfo a
  4835. INNER JOIN ICSInventoryLot lot on a.lotno=lot.lotno and a.WorkPoint=lot.WorkPoint
  4836. LEFT JOIN ICSExtension ext on lot.ExtensionID=ext.ID and a.WorkPoint=ext.WorkPoint
  4837. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4838. WHERE a.LotNo='{1}' and a.WorkPoint='{3}'
  4839. END";
  4840. sql = string.Format(sql, item.CheckCode, itemInfo.LotNo, item.User, item.WorkPoint, itemInfo.ActualQuantity);
  4841. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4842. {
  4843. throw new Exception(language.GetNameByCode("WMSAPIInfo033"));//"盘点扫描创建失败!");
  4844. }
  4845. #region 更新ICSCheckDetail表
  4846. //string strSql = @"UPDATE ICSCheckDetail Set";
  4847. //if (item.CheckKind == "初盘")
  4848. // strSql += @" PrimaryQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  4849. //else if (item.CheckKind == "复盘")
  4850. // strSql += @" ReplayQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  4851. //else
  4852. // strSql += @" CheckQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  4853. //strSql += @" where ToCheckNO='" + item.CheckCode + "' AND WorkPoint='" + item.WorkPoint + "'";
  4854. //cmd.CommandText = strSql;
  4855. //result = cmd.ExecuteNonQuery();
  4856. //if (result <= 0)
  4857. //{
  4858. // throw new Exception(language.GetNameByCode("WMSAPIInfo296"));//"盘点子表数量增加失败!");
  4859. //}
  4860. #endregion
  4861. #region 更新库存
  4862. if (item.UpdateWHLI)
  4863. {
  4864. ICSWareHouseLotInfoService.WareHouseLotInfoUpdate(Identification, item.CheckCode, "", itemInfo.LotNo, itemInfo.ActualQuantity, item.User, item.WorkPoint, "9", cmd, language);
  4865. }
  4866. #endregion
  4867. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  4868. }
  4869. if (string.IsNullOrWhiteSpace(lots))
  4870. {
  4871. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  4872. }
  4873. //sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  4874. // FROM ICSCheck a
  4875. // 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
  4876. // WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  4877. //sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  4878. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4879. //{
  4880. // throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  4881. //}
  4882. }
  4883. #region 查询返回数据
  4884. sql = @"SELECT x.ID,x.CheckCode,y.WarehouseCode AS WHCode,x.LotNo,
  4885. y.InvCode,
  4886. inv.InvName,
  4887. inv.InvStd,
  4888. x.Quantity,x.PrimaryQuantity,x.PrimaryAmount,x.ReplayQuantity,x.ReplayAmount,x.CheckQuantity,x.CheckAmount,
  4889. inv.InvUnit,
  4890. x.MUSER AS [User],
  4891. x.MTIME AS [MTime]
  4892. FROM ICSCheckDetail x
  4893. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  4894. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  4895. WHERE x.LotNo+x.WorkPoint IN ({0})";
  4896. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  4897. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4898. #endregion
  4899. cmd.Transaction.Commit();
  4900. return data;
  4901. }
  4902. catch (Exception ex)
  4903. {
  4904. if (cmd.Transaction != null)
  4905. cmd.Transaction.Rollback();
  4906. log.Error(ex.Message);
  4907. throw new Exception(ex.Message);
  4908. }
  4909. finally
  4910. {
  4911. if (conn.State == ConnectionState.Open)
  4912. {
  4913. conn.Close();
  4914. }
  4915. conn.Dispose();
  4916. }
  4917. }
  4918. }
  4919. #endregion
  4920. #region 多语言
  4921. /// <summary>
  4922. /// 多语言查询
  4923. /// </summary>
  4924. /// <param name="JsonData"></param>
  4925. /// <returns></returns>
  4926. public static DataTable PromptInformationGet(WMSBarCoreModel JsonData)
  4927. {
  4928. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4929. {
  4930. conn.Open();
  4931. SqlCommand cmd = new SqlCommand();
  4932. cmd.Connection = conn;
  4933. try
  4934. {
  4935. string sql = @"select cnValue AS Name,Code from Sys_Language where 1=1";
  4936. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  4937. {
  4938. sql += " and Code LIKE '%{0}%'";
  4939. }
  4940. sql = string.Format(sql, JsonData.Code);
  4941. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4942. return data;
  4943. }
  4944. catch (Exception ex)
  4945. {
  4946. log.Error(ex.Message);
  4947. throw new Exception(ex.Message);
  4948. }
  4949. finally
  4950. {
  4951. if (conn.State == ConnectionState.Open)
  4952. {
  4953. conn.Close();
  4954. }
  4955. conn.Dispose();
  4956. }
  4957. }
  4958. }
  4959. #endregion
  4960. #region 仓库/库位
  4961. /// <summary>
  4962. /// 仓库/库位
  4963. /// </summary>
  4964. /// <param name="JsonData"></param>
  4965. /// <returns></returns>
  4966. public static Result LocationGet(ICSLocation JsonData)
  4967. {
  4968. //HttpResponseMessage result = new HttpResponseMessage();
  4969. Result res = new Result();
  4970. var language = LanguageHelper.GetName("WMSAPIInfo");
  4971. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4972. {
  4973. conn.Open();
  4974. SqlTransaction sqlTran = conn.BeginTransaction();
  4975. SqlCommand cmd = new SqlCommand();
  4976. cmd.Transaction = sqlTran;
  4977. cmd.Connection = conn;
  4978. try
  4979. {
  4980. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode='{0}' AND a.WorkPoint='{1}')
  4981. BEGIN
  4982. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  4983. RETURN
  4984. END
  4985. IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' AND a.WorkPoint='{1}')
  4986. BEGIN
  4987. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  4988. RETURN
  4989. END
  4990. IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' AND a.WorkPoint='{1}' and b.Enable='1')
  4991. BEGIN
  4992. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  4993. RETURN
  4994. END
  4995. SELECT
  4996. LocationCode,
  4997. LocationName ,
  4998. WarehouseCode,
  4999. WarehouseName
  5000. FROM ICSLocation a
  5001. INNER JOIN ICSWarehouse b on a.WHID=b.ID and a.WorkPoint=b.WorkPoint where LocationCode='{0}' AND a.WorkPoint='{1}' and b.Enable='1'";
  5002. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  5003. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5004. cmd.Transaction.Commit();
  5005. sql = @"SELECT a.LocationCode FROM ICSLocation a INNER JOIN ICSWareHouseLotInfo b on a.LocationCode=b.LocationCode and a.WorkPoint=b.WorkPoint where a.LocationCode='{0}' AND a.WorkPoint='{1}'";
  5006. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  5007. DataTable datamsg = DBHelper.SQlReturnData(sql, cmd);
  5008. if (datamsg != null && datamsg.Rows.Count > 0)
  5009. {
  5010. res.Message = "该库位已有库存!";
  5011. }
  5012. res.Data = data;
  5013. return res;
  5014. }
  5015. catch (Exception ex)
  5016. {
  5017. if (cmd.Transaction != null)
  5018. cmd.Transaction.Rollback();
  5019. log.Error(ex.Message);
  5020. throw new Exception(ex.Message);
  5021. }
  5022. finally
  5023. {
  5024. if (conn.State == ConnectionState.Open)
  5025. {
  5026. conn.Close();
  5027. }
  5028. conn.Dispose();
  5029. }
  5030. }
  5031. }
  5032. #endregion
  5033. #region 登陆
  5034. public static object CheckLogin(Sys_SRM_User userModel)
  5035. {
  5036. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5037. {
  5038. conn.Open();
  5039. SqlCommand cmd = new SqlCommand();
  5040. cmd.Connection = conn;
  5041. try
  5042. {
  5043. string sql = @"select F_Account from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  5044. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  5045. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  5046. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  5047. {
  5048. sql = @" select a.[F_Id] as UserId
  5049. ,[F_Account] as userCode
  5050. ,[F_RealName] as UserName
  5051. ,[F_NickName]
  5052. ,b.F_UserPassword
  5053. ,b.F_UserSecretkey
  5054. ,[F_HeadIcon]
  5055. ,[F_Gender]
  5056. ,[F_Birthday]
  5057. ,[F_MobilePhone]
  5058. ,[F_Email]
  5059. ,[F_WeChat]
  5060. ,[F_ManagerId]
  5061. ,[F_SecurityLevel]
  5062. ,[F_Signature]
  5063. ,[F_OrganizeId]
  5064. ,[F_DepartmentId]
  5065. ,[F_RoleId]
  5066. ,[F_DutyId]
  5067. ,[F_IsAdministrator]
  5068. ,[F_SortCode]
  5069. ,[F_DeleteMark]
  5070. ,[F_EnabledMark]
  5071. ,[F_Description]
  5072. ,[F_CreatorTime]
  5073. ,[F_CreatorUserId]
  5074. ,[F_LastModifyTime]
  5075. ,[F_LastModifyUserId]
  5076. ,[F_DeleteTime]
  5077. ,[F_DeleteUserId]
  5078. ,[F_Location] as WorkPoint
  5079. ,[F_VenCode]
  5080. from Sys_SRM_User a
  5081. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  5082. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  5083. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  5084. dt = DBHelper.SQlReturnData(sql, cmd);
  5085. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  5086. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  5087. foreach (var item in users)
  5088. {
  5089. //string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
  5090. string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  5091. if (dbPassword == item.F_UserPassword)
  5092. {
  5093. string json = JsonConvert.SerializeObject(dt);
  5094. List<Sys_SRM_User> userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  5095. return userLogOnEntity;
  5096. }
  5097. else
  5098. {
  5099. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI004"));//"密码不正确,请重新输入");
  5100. }
  5101. }
  5102. }
  5103. else
  5104. {
  5105. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI005"));//"用户名不存在,请重新输入!");
  5106. }
  5107. return null;
  5108. }
  5109. catch (Exception ex)
  5110. {
  5111. log.Error(ex.Message);
  5112. throw new Exception(ex.Message);
  5113. }
  5114. finally
  5115. {
  5116. if (conn.State == ConnectionState.Open)
  5117. {
  5118. conn.Close();
  5119. }
  5120. conn.Dispose();
  5121. }
  5122. }
  5123. }
  5124. #endregion
  5125. #region 获取调拨单
  5126. /// <summary>
  5127. /// 获取未发,未发完调拨单
  5128. /// </summary>
  5129. /// <param name="JsonData"></param>
  5130. /// <returns></returns>
  5131. public static DataTable TransCodemationGet(TransferDoc JsonData)
  5132. {
  5133. var language = LanguageHelper.GetName("WMSAPIInfo");
  5134. if (JsonData==null)
  5135. {
  5136. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5137. }
  5138. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5139. {
  5140. conn.Open();
  5141. SqlTransaction sqlTran = conn.BeginTransaction();
  5142. SqlCommand cmd = new SqlCommand();
  5143. cmd.Transaction = sqlTran;
  5144. cmd.Connection = conn;
  5145. try
  5146. {
  5147. string Workpoint = "";
  5148. Workpoint = JsonData.WorkPoint;
  5149. string sql = @"SELECT DISTINCT TransferNO as TransCode FROM ICSTransfer
  5150. WHERE WorkPoint='{0}' AND Quantity>ISNULL(TransferQuantity, 0) order by TransferNO desc";
  5151. sql = string.Format(sql, Workpoint);
  5152. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  5153. return table;
  5154. }
  5155. catch (Exception ex)
  5156. {
  5157. if (cmd.Transaction != null)
  5158. cmd.Transaction.Rollback();
  5159. log.Error(ex.Message);
  5160. throw new Exception(ex.Message);
  5161. }
  5162. finally
  5163. {
  5164. if (conn.State == ConnectionState.Open)
  5165. {
  5166. conn.Close();
  5167. }
  5168. conn.Dispose();
  5169. }
  5170. }
  5171. }
  5172. #endregion
  5173. }
  5174. }