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

6525 lines
369 KiB

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