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

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