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

5439 lines
311 KiB

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