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

6508 lines
368 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
2 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
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
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
3 years ago
3 years ago
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
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
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,c.TransCode 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.itemCode.Equals("LocationRemind01"))
  1899. {
  1900. columnsWHNAME = @"
  1901. (SELECT Top 1 locat.LocationName from ICSWareHouseLotInfoLog log
  1902. 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
  1903. ORDER BY log.Mtime desc) AS LocationName,";
  1904. }
  1905. else if (mode.itemCode.Equals("LocationRemind02"))
  1906. {
  1907. columnsWHNAME = @"
  1908. STUFF(
  1909. (SELECT DISTINCT ',' + LocationName
  1910. from ICSLocation wh
  1911. LEFT JOIN ICSWareHouseLotInfo lotinfo on wh.LocationCode=lotinfo.LocationCode and wh.WorkPoint=lotinfo.WorkPoint
  1912. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and lotinfo.Quantity>0
  1913. FOR xml path('')
  1914. ),1,1,''
  1915. ) AS LocationName,";
  1916. }
  1917. else
  1918. {
  1919. columnsWHNAME = @"
  1920. STUFF(
  1921. (SELECT DISTINCT ',' + LocationName
  1922. from ICSLocation wh
  1923. LEFT JOIN ICSWareHouseLotInfoLog lotinfo on wh.LocationCode=lotinfo.ToLocationCode and wh.WorkPoint=lotinfo.WorkPoint
  1924. WHERE a.InvCode=lotinfo.InvCode AND a.WorkPoint=lotinfo.WorkPoint and (lotinfo.TransType='2' OR lotinfo.TransType='3')
  1925. FOR xml path('')
  1926. ),1,1,''
  1927. ) AS LocationName,";
  1928. }
  1929. #region 根据条码类型找到单据仓库信息
  1930. if (LotType.Equals("1"))
  1931. {//生产退料
  1932. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  1933. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1') AS WHCode";
  1934. }
  1935. else if (LotType.Equals("2"))
  1936. {//委外退料
  1937. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  1938. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='1') AS WHCode";
  1939. }
  1940. else if (LotType.Equals("3"))
  1941. {//工单
  1942. columnsWHCODE = @"(SELECT a.WHCode FROM ICSMO a WHERE a.MOCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AS WHCode";
  1943. }
  1944. else if (LotType.Equals("4"))
  1945. {//销售退货
  1946. columnsWHCODE = @"(SELECT a.WHCode FROM ICSSDN a WHERE a.SDNCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AS WHCode";
  1947. }
  1948. else if (LotType.Equals("5"))
  1949. {//其他入库
  1950. columnsWHCODE = @"(SELECT a.WHCode FROM ICSOtherIn a WHERE a.InCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AS WHCode";
  1951. }
  1952. else if (LotType.Equals("6"))
  1953. {//归还单
  1954. columnsWHCODE = @"(SELECT a.WHCode FROM ICSReturn a WHERE a.ReturnCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AS WHCode";
  1955. }
  1956. else if (LotType.Equals("7"))
  1957. {//采购到货单
  1958. 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";
  1959. }
  1960. else if (LotType.Equals("8"))
  1961. {//委外到货单
  1962. 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";
  1963. }
  1964. else if (LotType.Equals("9"))
  1965. {//成品入库单
  1966. columnsWHCODE = @"(SELECT a.WHCode FROM ICSManufactureReceive a WHERE a.RCVCode=lotdd.TransCode AND a.Sequence=lotdd.TransSequence AND a.WorkPoint=lotdd.WorkPoint) AS WHCode";
  1967. }
  1968. else if (LotType.Equals("10"))
  1969. {//拒收单
  1970. 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";
  1971. }
  1972. else if (LotType.Equals("11"))
  1973. {//委外拒收单
  1974. 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";
  1975. }
  1976. else if (LotType.Equals("12"))
  1977. {//领料申请退料
  1978. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  1979. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2') AS WHCode";
  1980. }
  1981. else if (LotType.Equals("13"))
  1982. {//材料出库退料
  1983. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSMOApplyNegDetail neg LEFT JOIN ICSMOApplyNeg negg ON neg.ApplyNegCode=negg.ApplyNegCode
  1984. WHERE lotdd.TransCode=neg.ApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3') AS WHCode";
  1985. }
  1986. else if (LotType.Equals("14"))
  1987. {//委外领料申请退料
  1988. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  1989. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='2') AS WHCode";
  1990. }
  1991. else if (LotType.Equals("15"))
  1992. {//委外材料出库退料
  1993. columnsWHCODE = @"(SELECT negg.WHCODE FROM ICSOApplyNegDetail neg LEFT JOIN ICSOApplyNeg negg ON neg.OApplyNegCode=negg.OApplyNegCode
  1994. WHERE lotdd.TransCode=neg.OApplyNegCode AND lotdd.TransSequence=neg.Sequence AND lotdd.WorkPoint=neg.WorkPoint and negg.Type='3') AS WHCode";
  1995. }
  1996. else if (LotType.Equals("16"))
  1997. {//返工工单
  1998. columnsWHCODE = @"(SELECT pick.WHCode FROM ICSMOPick pick LEFT JOIN ICSMO moo ON pick.MODetailID=moo.MODetailID AND pick.WorkPoint=moo.WorkPoint
  1999. WHERE moo.MOCode=lotdd.TransCode AND pick.Sequence=lotdd.TransSequence AND pick.WorkPoint=lotdd.WorkPoint) AS WHCode ";
  2000. }
  2001. #endregion
  2002. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  2003. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  2004. {0},'' AS WHName,
  2005. '' AS LocationCode,
  2006. {1}
  2007. ext.BatchCode AS BatchCode,";
  2008. tableName = @"ICSInventoryLot a
  2009. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2010. LEFT JOIN ICSInventoryLotDetail lotdd ON lotdd.LotNo=a.LotNo AND a.WorkPoint=lotdd.WorkPoint
  2011. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  2012. columns = string.Format(columns, columnsWHCODE, columnsWHNAME);
  2013. }
  2014. else
  2015. {
  2016. sql = @"
  2017. WITH ICSBomALL AS
  2018. (
  2019. SELECT
  2020. ContainerCode AS TContainerCode,
  2021. ContainerCode AS PContainerCode,
  2022. ContainerCode AS ContainerCode,
  2023. ID,
  2024. ContainerID,
  2025. 0 AS [Level],
  2026. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  2027. CAST('00001' AS nvarchar(MAX)) AS Sort
  2028. FROM ICSContainer
  2029. WHERE ContainerCode='{2}'
  2030. UNION ALL
  2031. SELECT
  2032. b.TContainerCode,
  2033. b.ContainerCode AS PContainerCode,
  2034. a.ContainerCode,
  2035. a.ID,
  2036. a.ContainerID,
  2037. b.[Level]+1 AS [Level],
  2038. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  2039. 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
  2040. FROM
  2041. ICSContainer a
  2042. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  2043. )
  2044. " + sql;
  2045. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  2046. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  2047. '' AS WHCode,
  2048. '' AS WHName,
  2049. '' AS LocationCode,
  2050. '' AS LocationName,
  2051. ext.BatchCode AS BatchCode,";
  2052. tableName = @"ICSInventoryLot a
  2053. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2054. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  2055. }
  2056. }
  2057. }
  2058. if (TransType != TransTypeEnum.LocationSeatch.GetDescription())
  2059. {
  2060. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName))
  2061. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  2062. }
  2063. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  2064. {
  2065. Losql = string.Format(Losql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  2066. table = DBHelper.SQlReturnData(Losql, cmd);
  2067. }
  2068. else
  2069. {
  2070. sql = string.Format(sql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  2071. log.Info("条码sql:" + sql);
  2072. table = DBHelper.SQlReturnData(sql, cmd);
  2073. }
  2074. if (table == null || table.Rows.Count <= 0)
  2075. throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
  2076. #region 出库检验是否符合源头单据
  2077. string msg = string.Empty;
  2078. bool isLimit = false;
  2079. string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode' and F_EnabledMark = '1'";
  2080. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  2081. if (isOut) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
  2082. {//&& TransType != TransTypeEnum.TransferLibrary.GetDescription()
  2083. string Lot = "";
  2084. string workP = "";
  2085. if (TransType == TransTypeEnum.TransferLibrary.GetDescription())
  2086. {
  2087. foreach (DataRow drLot in table.Rows)
  2088. {
  2089. Lot = drLot["LotNo"].ToString();
  2090. sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2091. sql = string.Format(sql, Lot, JsonData.WorkPoint);
  2092. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  2093. if (dt == null || dt.Rows.Count <= 0)
  2094. {
  2095. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), Lot));
  2096. }
  2097. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  2098. if (!JsonData.WHCode.Equals(whcode))
  2099. {
  2100. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo395"), JsonData.WHCode, whcode));
  2101. }
  2102. }
  2103. }
  2104. else if (TransType != TransTypeEnum.LocationSeatch.GetDescription())
  2105. {
  2106. if (string.IsNullOrEmpty(JsonData.TransCode))
  2107. {
  2108. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2109. }
  2110. WMSSourceDocumentModel model = new WMSSourceDocumentModel();
  2111. model.TransCode = JsonData.TransCode;
  2112. model.TransType = JsonData.TransType;
  2113. model.WorkPoint = JsonData.WorkPoint;
  2114. DataTable TransData = TransInformationGet(model);
  2115. DataView dataView = TransData.DefaultView;
  2116. foreach (DataRow drLot in table.Rows)
  2117. {
  2118. Lot = drLot["LotNo"].ToString();
  2119. //盘点不需要对比以下属性
  2120. if (TransType == TransTypeEnum.Check.GetDescription())
  2121. continue;
  2122. string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
  2123. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
  2124. rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
  2125. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
  2126. rowFilter += " AND (LEN(ISNULL(ProjectCode,''))<=0 OR (LEN(ISNULL(ProjectCode,''))>0 AND ProjectCode='" + drLot["ProjectCode"] + "'))";
  2127. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo043"), Lot, drLot["ProjectCode"]));
  2128. rowFilter += "AND (LEN(ISNULL(BatchCode,''))<=0 OR (LEN(ISNULL(BatchCode,''))>0 AND BatchCode='" + drLot["BatchCode"] + "'))";
  2129. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo044"), Lot, drLot["BatchCode"]));
  2130. rowFilter += "AND (LEN(ISNULL(Version,''))<=0 OR (LEN(ISNULL(Version,''))>0 AND Version='" + drLot["Version"] + "'))";
  2131. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo045"), Lot, drLot["Version"]));
  2132. rowFilter += "AND (LEN(ISNULL(Brand,''))<=0 OR (LEN(ISNULL(Brand,''))>0 AND Brand='" + drLot["Brand"] + "'))";
  2133. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo046"), Lot, drLot["Brand"]));
  2134. rowFilter += "AND (LEN(ISNULL(cFree1,''))<=0 OR (LEN(ISNULL(cFree1,''))>0 AND cFree1='" + drLot["cFree1"] + "'))";
  2135. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo047"), Lot, drLot["cFree1"]));
  2136. rowFilter += "AND (LEN(ISNULL(cFree2,''))<=0 OR (LEN(ISNULL(cFree2,''))>0 AND cFree2='" + drLot["cFree2"] + "'))";
  2137. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo048"), Lot, drLot["cFree2"]));
  2138. rowFilter += "AND (LEN(ISNULL(cFree3,''))<=0 OR (LEN(ISNULL(cFree3,''))>0 AND cFree3='" + drLot["cFree3"] + "'))";
  2139. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo049"), Lot, drLot["cFree3"]));
  2140. rowFilter += "AND (LEN(ISNULL(cFree4,''))<=0 OR (LEN(ISNULL(cFree4,''))>0 AND cFree4='" + drLot["cFree4"] + "'))";
  2141. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo050"), Lot, drLot["cFree4"]));
  2142. rowFilter += "AND (LEN(ISNULL(cFree5,''))<=0 OR (LEN(ISNULL(cFree5,''))>0 AND cFree5='" + drLot["cFree5"] + "'))";
  2143. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo051"), Lot, drLot["cFree5"]));
  2144. rowFilter += "AND (LEN(ISNULL(cFree6,''))<=0 OR (LEN(ISNULL(cFree6,''))>0 AND cFree6='" + drLot["cFree6"] + "'))";
  2145. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo052"), Lot, drLot["cFree6"]));
  2146. rowFilter += "AND (LEN(ISNULL(cFree7,''))<=0 OR (LEN(ISNULL(cFree7,''))>0 AND cFree7='" + drLot["cFree7"] + "'))";
  2147. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo053"), Lot, drLot["cFree7"]));
  2148. rowFilter += "AND (LEN(ISNULL(cFree8,''))<=0 OR (LEN(ISNULL(cFree8,''))>0 AND cFree8='" + drLot["cFree8"] + "'))";
  2149. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo054"), Lot, drLot["cFree8"]));
  2150. rowFilter += "AND (LEN(ISNULL(cFree9,''))<=0 OR (LEN(ISNULL(cFree9,''))>0 AND cFree9='" + drLot["cFree9"] + "'))";
  2151. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo055"), Lot, drLot["cFree9"]));
  2152. rowFilter += "AND (LEN(ISNULL(cFree10,''))<=0 OR (LEN(ISNULL(cFree10,''))>0 AND cFree10='" + drLot["cFree10"] + "'))";
  2153. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo056"), Lot, drLot["cFree10"]));
  2154. if (flag != null && flag.Rows.Count > 0)
  2155. {
  2156. rowFilter += " AND LocationCode='" + drLot["LocationCode"] + "'";
  2157. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["LocationCode"]));
  2158. }
  2159. //保质期管理
  2160. var resultEffective = Effective(Lot, JsonData.WorkPoint, cmd, language);
  2161. //0 - 已经是最早的批次
  2162. //1 - 不管控
  2163. //2 - 提醒
  2164. //3 - 限制
  2165. if (resultEffective == "2")
  2166. {
  2167. msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
  2168. }
  2169. else if (resultEffective == "3")
  2170. {
  2171. msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
  2172. isLimit = true;
  2173. }
  2174. //先进先出判断
  2175. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, cmd, language);
  2176. //0 - 已经是最早的批次
  2177. //1 - 不管控
  2178. //2 - 提醒
  2179. //3 - 限制
  2180. if (result == "2")
  2181. {
  2182. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  2183. }
  2184. else if (result == "3")
  2185. {
  2186. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  2187. isLimit = true;
  2188. }
  2189. }
  2190. }
  2191. }
  2192. #endregion
  2193. //return table;
  2194. Result res = new Result();
  2195. res.Success = true;
  2196. res.Message = msg;// "接口调用成功!";
  2197. if (!isLimit)
  2198. res.Data = table;
  2199. return res;
  2200. //出库时
  2201. //Message无值、Data有值,可直接处理
  2202. //Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
  2203. //Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
  2204. }
  2205. catch (Exception ex)
  2206. {
  2207. log.Error(ex.Message);
  2208. throw new Exception(ex.Message);
  2209. }
  2210. finally
  2211. {
  2212. if (conn.State == ConnectionState.Open)
  2213. {
  2214. conn.Close();
  2215. }
  2216. conn.Dispose();
  2217. }
  2218. }
  2219. }
  2220. /// <summary>
  2221. /// 校验条码对应的物料、自由项等信息是否与源头单据匹配
  2222. /// </summary>
  2223. private static void CheckTrans(DataView dataView, string rowFilter, string message)
  2224. {
  2225. dataView.RowFilter = rowFilter;
  2226. if (dataView == null || dataView.Count <= 0)
  2227. throw new Exception(message);
  2228. }
  2229. #endregion
  2230. /// <summary>
  2231. /// 上架
  2232. /// </summary>BusinessCode,TransType 两个类型
  2233. /// <param name="JsonData"></param>
  2234. /// <returns></returns>
  2235. public static DataTable LOTStockCreate(List<LOTStockUpCreateIModel> JsonData)
  2236. {
  2237. var language = LanguageHelper.GetName("WMSAPIInfo");
  2238. if (JsonData.Count <= 0)
  2239. {
  2240. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2241. }
  2242. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2243. {
  2244. conn.Open();
  2245. SqlTransaction sqlTran = conn.BeginTransaction();
  2246. SqlCommand cmd = new SqlCommand();
  2247. cmd.Transaction = sqlTran;
  2248. cmd.Connection = conn;
  2249. string BusinessCode = string.Empty;
  2250. try
  2251. {
  2252. string TransType = string.Empty;
  2253. string Identification = Guid.NewGuid().ToString();
  2254. foreach (var item in JsonData)
  2255. {
  2256. TransType = item.TransType;
  2257. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  2258. {
  2259. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2260. }
  2261. string WHTransType = "2";
  2262. foreach (var itemInfo in item.detail)
  2263. {
  2264. #region 两步调入
  2265. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  2266. {
  2267. //更新源头单据数量
  2268. ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2269. //入库
  2270. ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  2271. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  2272. }
  2273. #endregion
  2274. #region 销售退货-原条码
  2275. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  2276. {
  2277. //更新源头单据数量
  2278. ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2279. //入库
  2280. BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription<DBValue>();
  2281. //入库
  2282. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  2283. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode);
  2284. //更新日志表源头单据信息
  2285. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  2286. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' AND TransCode='' AND TransSequence=''";
  2287. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  2288. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2289. {
  2290. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  2291. }
  2292. }
  2293. #endregion
  2294. else
  2295. {
  2296. #region 采购入库
  2297. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  2298. {
  2299. //更新源头单据数量
  2300. ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2301. BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription<DBValue>();
  2302. }
  2303. #endregion
  2304. #region 审核的到货单
  2305. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  2306. {
  2307. //更新源头单据数量
  2308. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2309. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  2310. }
  2311. #endregion
  2312. #region 采购拒收
  2313. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  2314. {
  2315. //更新源头单据数量
  2316. ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2317. BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription<DBValue>();
  2318. }
  2319. #endregion
  2320. #region 审核的委外到货单
  2321. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  2322. {
  2323. //更新源头单据数量
  2324. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2325. BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  2326. }
  2327. #endregion
  2328. #region 委外拒收
  2329. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  2330. {
  2331. //更新源头单据数量
  2332. ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2333. BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription<DBValue>();
  2334. }
  2335. #endregion
  2336. #region 委外退料
  2337. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  2338. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  2339. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  2340. {
  2341. //更新源头单据数量
  2342. ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2343. BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  2344. }
  2345. #endregion
  2346. #region 返工工单
  2347. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  2348. {
  2349. //更新源头单据数量
  2350. ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>(), cmd, language);
  2351. BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>();
  2352. }
  2353. #endregion
  2354. #region 委外入库
  2355. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  2356. {
  2357. //更新源头单据数量
  2358. ICSOutsourcingService.OutsourcingReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2359. BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>();
  2360. }
  2361. #endregion
  2362. #region 生产退料
  2363. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  2364. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  2365. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  2366. {
  2367. //更新源头单据数量
  2368. ICSManufactureService.MOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2369. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  2370. }
  2371. #endregion
  2372. #region 生产入库
  2373. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  2374. {
  2375. //更新源头单据数量
  2376. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2377. BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  2378. }
  2379. #endregion
  2380. #region 开立的生产入库单
  2381. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  2382. {
  2383. //更新源头单据数量
  2384. ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2385. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  2386. }
  2387. #endregion
  2388. #region 销售退货
  2389. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  2390. {
  2391. //更新源头单据数量
  2392. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2393. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  2394. }
  2395. #endregion
  2396. #region 其他入库
  2397. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  2398. {
  2399. //更新源头单据数量
  2400. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2401. BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  2402. }
  2403. #endregion
  2404. #region 拆卸单
  2405. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  2406. {
  2407. ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2408. WHTransType = "11";
  2409. BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription<DBValue>();
  2410. }
  2411. #endregion
  2412. #region 归还
  2413. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  2414. {
  2415. //更新源头单据数量
  2416. ICSWareHouseService.ReturnDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2417. BusinessCode = TransTypeEnum.ReturnDoc.GetDescription<DBValue>();
  2418. }
  2419. #endregion
  2420. else
  2421. {
  2422. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2423. }
  2424. //入库
  2425. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  2426. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode);
  2427. }
  2428. }
  2429. #region 拆卸单
  2430. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  2431. {
  2432. //更新套件锁定数量
  2433. ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
  2434. }
  2435. #endregion}
  2436. }
  2437. //上传ERP
  2438. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2439. {
  2440. //采购入库
  2441. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  2442. ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  2443. //审核的到货单
  2444. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  2445. ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  2446. //采购拒收
  2447. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  2448. ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  2449. //审核的委外到货单
  2450. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  2451. ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  2452. //委外拒收
  2453. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  2454. ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  2455. //委外退料
  2456. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  2457. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  2458. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  2459. ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2460. //委外入库
  2461. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  2462. ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  2463. //生产退料
  2464. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  2465. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  2466. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  2467. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2468. //生产入库
  2469. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  2470. ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  2471. //开立的生产入库单
  2472. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  2473. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  2474. //返工工单
  2475. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  2476. ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language, BusinessCode);
  2477. //销售退货
  2478. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  2479. ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2480. //两步调入
  2481. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  2482. ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
  2483. //销售退货-原条码
  2484. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  2485. ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language, BusinessCode);
  2486. //其他入库
  2487. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  2488. ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
  2489. //拆卸单
  2490. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  2491. ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language, BusinessCode);
  2492. //归还
  2493. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  2494. ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language, BusinessCode);
  2495. }
  2496. DataTable table = GetData(Identification, 1, cmd);
  2497. cmd.Transaction.Commit();
  2498. return table;
  2499. }
  2500. catch (Exception ex)
  2501. {
  2502. if (cmd.Transaction != null)
  2503. cmd.Transaction.Rollback();
  2504. log.Error(ex.Message);
  2505. throw new Exception(ex.Message);
  2506. }
  2507. finally
  2508. {
  2509. if (conn.State == ConnectionState.Open)
  2510. {
  2511. conn.Close();
  2512. }
  2513. conn.Dispose();
  2514. }
  2515. }
  2516. }
  2517. /// <summary>
  2518. /// 下架
  2519. /// </summary>
  2520. /// <param name="JsonData"></param>
  2521. /// <returns></returns>
  2522. public static DataTable LOTStockDownCreate(List<LOTStockModel> JsonData)
  2523. {
  2524. String PrintEnable = "";
  2525. var language = LanguageHelper.GetName("WMSAPIInfo");
  2526. if (JsonData.Count <= 0)
  2527. {
  2528. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2529. }
  2530. List<LOTStockModelList> model = new List<LOTStockModelList>();
  2531. DataTable printTable = new DataTable();
  2532. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2533. {
  2534. conn.Open();
  2535. SqlTransaction sqlTran = conn.BeginTransaction();
  2536. SqlCommand cmd = new SqlCommand();
  2537. cmd.Transaction = sqlTran;
  2538. cmd.Connection = conn;
  2539. string BusinessCode = string.Empty;
  2540. try
  2541. {
  2542. string TransType = string.Empty;
  2543. string Identification = Guid.NewGuid().ToString();
  2544. foreach (var item in JsonData)
  2545. {
  2546. TransType = item.TransType;
  2547. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  2548. {
  2549. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2550. }
  2551. else if (string.IsNullOrEmpty(item.TransCode))
  2552. {
  2553. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2554. }
  2555. string[] trans = item.TransCode.Split('~');
  2556. string MergeID = "";
  2557. if (trans.Length == 2)
  2558. {
  2559. MergeID = trans[0];
  2560. item.TransCode = trans[1];
  2561. }
  2562. #region 采购退货
  2563. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2564. {
  2565. BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>();
  2566. //更新源头单据数量
  2567. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2568. foreach (var itemInfo in item.detail)
  2569. {
  2570. //出库
  2571. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2572. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language);
  2573. }
  2574. }
  2575. #endregion
  2576. #region 委外发料
  2577. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2578. {
  2579. BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>();
  2580. //更新源头单据数量
  2581. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2582. foreach (var itemInfo in item.detail)
  2583. {
  2584. //出库
  2585. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2586. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2587. }
  2588. }
  2589. #endregion
  2590. #region 委外退货
  2591. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2592. {
  2593. BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>();
  2594. //更新源头单据数量
  2595. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2596. foreach (var itemInfo in item.detail)
  2597. {
  2598. //出库
  2599. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2600. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language);
  2601. }
  2602. }
  2603. #endregion
  2604. #region 生产发料
  2605. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2606. {
  2607. BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription<DBValue>();
  2608. //更新源头单据数量
  2609. ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2610. foreach (var itemInfo in item.detail)
  2611. {
  2612. //出库
  2613. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2614. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2615. }
  2616. }
  2617. #endregion
  2618. #region 销售出库
  2619. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2620. {
  2621. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  2622. //更新源头单据数量
  2623. ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2624. foreach (var itemInfo in item.detail)
  2625. {
  2626. //出库
  2627. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2628. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2629. }
  2630. }
  2631. #endregion
  2632. #region 两步调出
  2633. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2634. {
  2635. BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>();
  2636. //更新源头单据数量
  2637. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2638. foreach (var itemInfo in item.detail)
  2639. {
  2640. //出库
  2641. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2642. item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, MergeID);
  2643. }
  2644. }
  2645. #endregion
  2646. #region 其他出库
  2647. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2648. {
  2649. BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription<DBValue>();
  2650. //更新源头单据数量
  2651. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2652. foreach (var itemInfo in item.detail)
  2653. {
  2654. //出库
  2655. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2656. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2657. }
  2658. }
  2659. #endregion
  2660. #region 领料申请单发料
  2661. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  2662. {
  2663. BusinessCode = TransTypeEnum.MOApply.GetDescription<DBValue>();
  2664. //更新源头单据数量
  2665. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2666. foreach (var itemInfo in item.detail)
  2667. {
  2668. //出库
  2669. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2670. item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  2671. }
  2672. }
  2673. #endregion
  2674. #region 委外领料申请单发料
  2675. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  2676. {
  2677. BusinessCode = TransTypeEnum.OOApply.GetDescription<DBValue>();
  2678. //更新源头单据数量
  2679. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2680. foreach (var itemInfo in item.detail)
  2681. {
  2682. //出库
  2683. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2684. item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  2685. }
  2686. }
  2687. #endregion
  2688. #region 开立材料出库
  2689. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2690. {
  2691. BusinessCode = TransTypeEnum.MOIssue.GetDescription<DBValue>();
  2692. //更新源头单据数量
  2693. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2694. foreach (var itemInfo in item.detail)
  2695. {
  2696. //出库
  2697. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2698. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  2699. }
  2700. }
  2701. #endregion
  2702. #region 开立委外材料出库
  2703. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2704. {
  2705. BusinessCode = TransTypeEnum.OOIssue.GetDescription<DBValue>();
  2706. //更新源头单据数量
  2707. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2708. foreach (var itemInfo in item.detail)
  2709. {
  2710. //出库
  2711. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2712. item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  2713. }
  2714. }
  2715. #endregion
  2716. #region 开立红字入库单
  2717. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2718. {
  2719. BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription<DBValue>();
  2720. //更新源头单据数量
  2721. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2722. foreach (var itemInfo in item.detail)
  2723. {
  2724. //出库
  2725. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2726. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language);
  2727. }
  2728. }
  2729. #endregion
  2730. #region 开立委外红字入库单
  2731. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2732. {
  2733. BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>();
  2734. //更新源头单据数量
  2735. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2736. foreach (var itemInfo in item.detail)
  2737. {
  2738. //出库
  2739. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2740. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language);
  2741. }
  2742. }
  2743. #endregion
  2744. #region 借用
  2745. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2746. {
  2747. BusinessCode = TransTypeEnum.BrrowDoc.GetDescription<DBValue>();
  2748. //更新源头单据数量
  2749. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2750. foreach (var itemInfo in item.detail)
  2751. {
  2752. //出库
  2753. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2754. item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2755. }
  2756. }
  2757. #endregion
  2758. else
  2759. {
  2760. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2761. }
  2762. }
  2763. //上传ERP
  2764. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2765. {
  2766. //采购退货
  2767. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2768. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2769. //委外发料
  2770. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2771. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  2772. //委外退货
  2773. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2774. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
  2775. //生产发料
  2776. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2777. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  2778. //销售出库
  2779. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2780. ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode);
  2781. //两步调出
  2782. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2783. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
  2784. //其他出库
  2785. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2786. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  2787. //领料申请单发料
  2788. if (TransType == TransTypeEnum.MOApply.GetDescription())
  2789. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  2790. //委外领料申请单发料
  2791. if (TransType == TransTypeEnum.OOApply.GetDescription())
  2792. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  2793. //开立材料出库
  2794. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2795. ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  2796. //开立委外材料出库
  2797. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2798. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  2799. //开立红字入库单
  2800. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2801. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  2802. //开立委外红字入库单
  2803. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2804. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2805. //借用
  2806. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2807. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
  2808. }
  2809. if (!printTable.Equals("{}"))
  2810. {
  2811. cmd.Transaction.Commit();
  2812. return printTable;
  2813. }
  2814. else
  2815. {
  2816. DataTable table = GetData(Identification, 2, cmd);
  2817. cmd.Transaction.Commit();
  2818. return table;
  2819. }
  2820. }
  2821. catch (Exception ex)
  2822. {
  2823. if (cmd.Transaction != null)
  2824. cmd.Transaction.Rollback();
  2825. log.Error(ex.Message);
  2826. throw new Exception(ex.Message);
  2827. }
  2828. finally
  2829. {
  2830. if (conn.State == ConnectionState.Open)
  2831. {
  2832. conn.Close();
  2833. }
  2834. conn.Dispose();
  2835. }
  2836. }
  2837. }
  2838. #region 采购
  2839. /// <summary>
  2840. /// 采购到货
  2841. /// </summary>
  2842. /// <param name="JsonData"></param>
  2843. /// <returns></returns>
  2844. public static DataTable DeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  2845. {
  2846. var language = LanguageHelper.GetName("WMSAPIInfo");
  2847. if (JsonData.Count <= 0)
  2848. {
  2849. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2850. }
  2851. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2852. {
  2853. conn.Open();
  2854. SqlTransaction sqlTran = conn.BeginTransaction();
  2855. SqlCommand cmd = new SqlCommand();
  2856. cmd.Transaction = sqlTran;
  2857. cmd.Connection = conn;
  2858. try
  2859. {
  2860. string asncodes = string.Empty;
  2861. string sql = string.Empty;
  2862. foreach (var item in JsonData)
  2863. {
  2864. if (string.IsNullOrEmpty(item.ASNCode))
  2865. {
  2866. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
  2867. }
  2868. //获取单号
  2869. sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  2870. BEGIN
  2871. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  2872. RETURN
  2873. END
  2874. DECLARE @Status VARCHAR(10)
  2875. SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  2876. IF (@Status IS NULL)
  2877. BEGIN
  2878. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  2879. RETURN
  2880. END
  2881. ELSE IF (@Status!='2')
  2882. BEGIN
  2883. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  2884. RETURN
  2885. END
  2886. DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2887. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2888. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2889. IF @MaxNO IS NULL
  2890. BEGIN
  2891. SELECT @date+'00001' AS Code
  2892. END
  2893. ELSE
  2894. BEGIN
  2895. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2896. END ";
  2897. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  2898. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2899. //修改送货单到货数量
  2900. foreach (var itemInfo in item.detail)
  2901. {
  2902. sql = @"UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
  2903. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2904. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  2905. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2906. {
  2907. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
  2908. }
  2909. sql = @"UPDATE ICSInventoryLot SET Quantity='{2}'
  2910. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2911. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  2912. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2913. {
  2914. throw new Exception(language.GetNameByCode("WMSAPIInfo462")); //"条码表信息更新失败!");
  2915. }
  2916. }
  2917. //创建到货单信息
  2918. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  2919. BEGIN
  2920. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  2921. RETURN
  2922. END
  2923. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2924. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2925. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2926. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2927. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2928. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  2929. '1',b.InvCode,SUM(a.DNQuantity),'0','0',
  2930. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  2931. d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,
  2932. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode
  2933. FROM ICSASNDetail a
  2934. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2935. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  2936. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  2937. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  2938. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}'
  2939. 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";
  2940. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode);
  2941. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2942. {
  2943. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  2944. }
  2945. ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  2946. asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
  2947. }
  2948. if (string.IsNullOrWhiteSpace(asncodes))
  2949. {
  2950. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  2951. }
  2952. #region 查询返回数据
  2953. sql = @"SELECT
  2954. n.POCode,
  2955. n.Sequence AS POSequence,
  2956. a.ASNCode,
  2957. a.DNCode,
  2958. a.Sequence,
  2959. a.VenCode,
  2960. a.DepCode,
  2961. a.InvCode,
  2962. inv.InvName,
  2963. inv.InvStd,
  2964. a.Quantity,
  2965. inv.InvUnit,
  2966. a.Amount,
  2967. inv.AmountUnit,
  2968. a.RCVQuantity,
  2969. a.UnitPrice,
  2970. a.Currency,
  2971. a.POID,
  2972. a.PODetailID,
  2973. a.DNID,
  2974. a.DNDetailID,
  2975. ext.ProjectCode,
  2976. ext.BatchCode,
  2977. ext.Version,
  2978. ext.Brand,
  2979. ext.cFree1,
  2980. ext.cFree2,
  2981. ext.cFree3,
  2982. ext.cFree4,
  2983. ext.cFree5,
  2984. ext.cFree6,
  2985. ext.cFree7,
  2986. ext.cFree8,
  2987. ext.cFree9,
  2988. ext.cFree10,
  2989. a.MUSER AS [User],
  2990. a.MTIME AS [MTime]
  2991. FROM ICSDeliveryNotice a
  2992. INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
  2993. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2994. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2995. WHERE a.ASNCode+a.WorkPoint IN ({0})";
  2996. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  2997. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2998. #endregion
  2999. cmd.Transaction.Commit();
  3000. return data;
  3001. }
  3002. catch (Exception ex)
  3003. {
  3004. if (cmd.Transaction != null)
  3005. cmd.Transaction.Rollback();
  3006. log.Error(ex.Message);
  3007. throw new Exception(ex.Message);
  3008. }
  3009. finally
  3010. {
  3011. if (conn.State == ConnectionState.Open)
  3012. {
  3013. conn.Close();
  3014. }
  3015. conn.Dispose();
  3016. }
  3017. }
  3018. }
  3019. /// <summary>
  3020. /// 采购拒收
  3021. /// </summary>
  3022. /// <param name="JsonData"></param>
  3023. /// <returns></returns>
  3024. public static DataTable PurchaseRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  3025. {
  3026. var language = LanguageHelper.GetName("WMSAPIInfo");
  3027. if (JsonData.Count <= 0)
  3028. {
  3029. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3030. }
  3031. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3032. {
  3033. conn.Open();
  3034. SqlTransaction sqlTran = conn.BeginTransaction();
  3035. SqlCommand cmd = new SqlCommand();
  3036. cmd.Transaction = sqlTran;
  3037. cmd.Connection = conn;
  3038. try
  3039. {
  3040. string lots = string.Empty;
  3041. string sql = string.Empty;
  3042. foreach (var item in JsonData)
  3043. {
  3044. if (string.IsNullOrEmpty(item.DNCode))
  3045. {
  3046. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  3047. }
  3048. //获取单号
  3049. sql = @"DECLARE @Status VARCHAR(10)
  3050. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  3051. IF (@Status IS NULL)
  3052. BEGIN
  3053. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  3054. RETURN
  3055. END
  3056. ELSE IF (@Status!='2')
  3057. BEGIN
  3058. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  3059. RETURN
  3060. END
  3061. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3062. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  3063. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  3064. IF @MaxNO IS NULL
  3065. BEGIN
  3066. SELECT @date+'00001' AS Code
  3067. END
  3068. ELSE
  3069. BEGIN
  3070. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3071. END ";
  3072. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  3073. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3074. //修改送货单到货数量
  3075. foreach (var itemInfo in item.detail)
  3076. {
  3077. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  3078. BEGIN
  3079. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  3080. RETURN
  3081. END
  3082. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  3083. BEGIN
  3084. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  3085. RETURN
  3086. END
  3087. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  3088. DNType,InvCode,Quantity,Amount,RCVQuantity,
  3089. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3090. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  3091. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  3092. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  3093. '3',d.InvCode,'{7}', '{8}', 0,
  3094. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  3095. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  3096. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  3097. FROM ICSDeliveryNotice a
  3098. INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  3099. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  3100. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  3101. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  3102. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  3103. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  3104. WHERE a.DNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  3105. 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);
  3106. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3107. {
  3108. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  3109. }
  3110. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  3111. }
  3112. ICSPurchaseService.PurchaseRejectDocInNewERP(item.DNCode, Code, item.WorkPoint, cmd, language);
  3113. }
  3114. if (string.IsNullOrWhiteSpace(lots))
  3115. {
  3116. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  3117. }
  3118. #region 查询返回数据
  3119. sql = @"SELECT
  3120. n.DNCode,
  3121. n.Sequence,
  3122. a.DNCode AS RJTCode,
  3123. a.Sequence AS RJTSequence,
  3124. a.VenCode,
  3125. a.DepCode,
  3126. a.InvCode,
  3127. inv.InvName,
  3128. inv.InvStd,
  3129. a.Quantity,
  3130. inv.InvUnit,
  3131. a.Amount,
  3132. inv.AmountUnit,
  3133. a.RCVQuantity,
  3134. a.UnitPrice,
  3135. a.Currency,
  3136. a.POID,
  3137. a.PODetailID,
  3138. a.DNID,
  3139. a.DNDetailID,
  3140. ext.ProjectCode,
  3141. ext.BatchCode,
  3142. ext.Version,
  3143. ext.Brand,
  3144. ext.cFree1,
  3145. ext.cFree2,
  3146. ext.cFree3,
  3147. ext.cFree4,
  3148. ext.cFree5,
  3149. ext.cFree6,
  3150. ext.cFree7,
  3151. ext.cFree8,
  3152. ext.cFree9,
  3153. ext.cFree10,
  3154. a.MUSER AS [User],
  3155. a.MTIME AS [MTime]
  3156. FROM ICSDeliveryNotice a
  3157. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  3158. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3159. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3160. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  3161. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  3162. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3163. #endregion
  3164. cmd.Transaction.Commit();
  3165. return data;
  3166. }
  3167. catch (Exception ex)
  3168. {
  3169. if (cmd.Transaction != null)
  3170. cmd.Transaction.Rollback();
  3171. log.Error(ex.Message);
  3172. throw new Exception(ex.Message);
  3173. }
  3174. finally
  3175. {
  3176. if (conn.State == ConnectionState.Open)
  3177. {
  3178. conn.Close();
  3179. }
  3180. conn.Dispose();
  3181. }
  3182. }
  3183. }
  3184. #endregion
  3185. #region 委外
  3186. /// <summary>
  3187. /// 委外退料 新建
  3188. /// </summary>
  3189. /// <param name="JsonData"></param>
  3190. /// <returns></returns>
  3191. public static DataTable OutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  3192. {
  3193. var language = LanguageHelper.GetName("WMSAPIInfo");
  3194. if (JsonData.Count <= 0)
  3195. {
  3196. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3197. }
  3198. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3199. {
  3200. conn.Open();
  3201. SqlTransaction sqlTran = conn.BeginTransaction();
  3202. SqlCommand cmd = new SqlCommand();
  3203. cmd.Transaction = sqlTran;
  3204. cmd.Connection = conn;
  3205. try
  3206. {
  3207. string codes = string.Empty;
  3208. string sql = string.Empty;
  3209. foreach (var item in JsonData)
  3210. {
  3211. //获取单号
  3212. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3213. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  3214. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  3215. IF @MaxNO IS NULL
  3216. BEGIN
  3217. SELECT @date+'00001' AS Code
  3218. END
  3219. ELSE
  3220. BEGIN
  3221. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3222. END ";
  3223. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3224. //创建主表
  3225. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  3226. BEGIN
  3227. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3228. RETURN
  3229. END
  3230. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3231. 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}','')";
  3232. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  3233. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3234. {
  3235. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  3236. }
  3237. foreach (var itemInfo in item.detail)
  3238. {
  3239. //创建子表
  3240. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  3241. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3242. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3243. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3244. '{4}','{5}',0,'{6}','{7}',
  3245. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3246. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3247. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3248. {
  3249. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  3250. }
  3251. }
  3252. //校验退料数量是否超出领料数量
  3253. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  3254. DBHelper.ExecuteNonQuery(sql, cmd);
  3255. codes += "'" + Code + item.WorkPoint + "',";
  3256. }
  3257. if (string.IsNullOrWhiteSpace(codes))
  3258. {
  3259. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3260. }
  3261. #region 查询返回数据
  3262. sql = @"SELECT a.OApplyNegCode,
  3263. c.WHCode,
  3264. c.Memo,
  3265. d.Name AS Status,
  3266. a.Sequence,
  3267. a.InvCode,
  3268. inv.InvName,
  3269. inv.InvStd,
  3270. a.Quantity,
  3271. inv.InvUnit,
  3272. a.Amount,
  3273. inv.AmountUnit,
  3274. a.IssueNegQuantity,
  3275. ext.ProjectCode,
  3276. ext.BatchCode,
  3277. ext.Version,
  3278. ext.Brand,
  3279. ext.cFree1,
  3280. ext.cFree2,
  3281. ext.cFree3,
  3282. ext.cFree4,
  3283. ext.cFree5,
  3284. ext.cFree6,
  3285. ext.cFree7,
  3286. ext.cFree8,
  3287. ext.cFree9,
  3288. ext.cFree10,
  3289. a.MUSER AS [User],
  3290. a.MTIME AS [MTime]
  3291. FROM ICSOApplyNegDetail a
  3292. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3293. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3294. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3295. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3296. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  3297. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  3298. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3299. #endregion
  3300. cmd.Transaction.Commit();
  3301. return data;
  3302. }
  3303. catch (Exception ex)
  3304. {
  3305. if (cmd.Transaction != null)
  3306. cmd.Transaction.Rollback();
  3307. log.Error(ex.Message);
  3308. throw new Exception(ex.Message);
  3309. }
  3310. finally
  3311. {
  3312. if (conn.State == ConnectionState.Open)
  3313. {
  3314. conn.Close();
  3315. }
  3316. conn.Dispose();
  3317. }
  3318. }
  3319. }
  3320. private static string CheckOutsourcingIssueDoc(string Type, string Code, string WorkPoint, Dictionary<string, string> language)
  3321. {
  3322. string sql = string.Empty;
  3323. if (Type == "1")
  3324. {
  3325. sql = @"DECLARE @PickID VARCHAR(10)
  3326. SELECT @PickID=b.PickID
  3327. FROM ICSOApplyNegDetail a
  3328. INNER JOIN ICSOOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  3329. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3330. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3331. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3332. FROM ICSOApplyNegDetail a
  3333. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3334. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3335. GROUP BY b.PickID
  3336. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3337. IF (@PickID IS NOT NULL)
  3338. BEGIN
  3339. DECLARE @InvCode VARCHAR(100)
  3340. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  3341. RAISERROR(@InvCode,16,1);
  3342. RETURN
  3343. END ";
  3344. }
  3345. else if (Type == "2")
  3346. {
  3347. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  3348. SELECT @ApplyDetailID=b.ApplyDetailID
  3349. FROM ICSOApplyNegDetail a
  3350. INNER JOIN ICSOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  3351. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3352. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3353. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3354. FROM ICSOApplyNegDetail a
  3355. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3356. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3357. GROUP BY b.ApplyDetailID
  3358. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3359. IF (@ApplyDetailID IS NOT NULL)
  3360. BEGIN
  3361. DECLARE @InvCode VARCHAR(100)
  3362. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  3363. RAISERROR(@InvCode,16,1);
  3364. RETURN
  3365. END ";
  3366. }
  3367. else if (Type == "3")
  3368. {
  3369. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  3370. SELECT @IssueDetailID=b.IssueDetailID
  3371. FROM ICSOApplyNegDetail a
  3372. INNER JOIN ICSOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  3373. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3374. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3375. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3376. FROM ICSOApplyNegDetail a
  3377. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3378. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3379. GROUP BY b.IssueDetailID
  3380. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3381. IF (@IssueDetailID IS NOT NULL)
  3382. BEGIN
  3383. DECLARE @InvCode VARCHAR(100)
  3384. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  3385. RAISERROR(@InvCode,16,1);
  3386. RETURN
  3387. END ";
  3388. }
  3389. else
  3390. {
  3391. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  3392. }
  3393. sql = string.Format(sql, Code, WorkPoint, Type);
  3394. return sql;
  3395. }
  3396. /// <summary>
  3397. /// 委外退料 修改
  3398. /// </summary>
  3399. /// <param name="JsonData"></param>
  3400. /// <returns></returns>
  3401. public static DataTable OutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  3402. {
  3403. var language = LanguageHelper.GetName("WMSAPIInfo");
  3404. if (JsonData.Count <= 0)
  3405. {
  3406. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3407. }
  3408. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3409. {
  3410. conn.Open();
  3411. SqlTransaction sqlTran = conn.BeginTransaction();
  3412. SqlCommand cmd = new SqlCommand();
  3413. cmd.Transaction = sqlTran;
  3414. cmd.Connection = conn;
  3415. try
  3416. {
  3417. string sql = string.Empty;
  3418. string Code = string.Empty;
  3419. string ids = string.Empty;
  3420. foreach (var item in JsonData)
  3421. {
  3422. //主表修改
  3423. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  3424. BEGIN
  3425. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  3426. RETURN
  3427. END
  3428. DECLARE @Status VARCHAR(10)
  3429. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  3430. IF (@Status IS NULL)
  3431. BEGIN
  3432. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  3433. RETURN
  3434. END
  3435. ELSE IF (@Status!='1')
  3436. BEGIN
  3437. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  3438. RETURN
  3439. END
  3440. 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}' ";
  3441. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  3442. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3443. {
  3444. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  3445. }
  3446. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  3447. if (detail > 0)
  3448. {
  3449. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  3450. sql = string.Format(sql, item.id, item.WorkPoint);
  3451. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3452. }
  3453. foreach (var itemInfo in item.detail)
  3454. {
  3455. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  3456. {
  3457. //创建子表
  3458. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  3459. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3460. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3461. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3462. '{4}','{5}',0,'{6}','{7}',
  3463. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3464. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3465. }
  3466. else
  3467. {
  3468. //子表修改
  3469. 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}'";
  3470. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  3471. }
  3472. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3473. {
  3474. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  3475. }
  3476. }
  3477. //校验退料数量是否超出领料数量
  3478. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  3479. DBHelper.ExecuteNonQuery(sql, cmd);
  3480. ids += "'" + item.id + "',";
  3481. }
  3482. if (string.IsNullOrWhiteSpace(ids))
  3483. {
  3484. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3485. }
  3486. #region 查询返回数据
  3487. sql = @"SELECT a.OApplyNegCode,
  3488. c.WHCode,
  3489. c.Memo,
  3490. d.Name AS Status,
  3491. a.Sequence,
  3492. a.InvCode,
  3493. inv.InvName,
  3494. inv.InvStd,
  3495. a.Quantity,
  3496. inv.InvUnit,
  3497. a.Amount,
  3498. inv.AmountUnit,
  3499. a.IssueNegQuantity,
  3500. ext.ProjectCode,
  3501. ext.BatchCode,
  3502. ext.Version,
  3503. ext.Brand,
  3504. ext.cFree1,
  3505. ext.cFree2,
  3506. ext.cFree3,
  3507. ext.cFree4,
  3508. ext.cFree5,
  3509. ext.cFree6,
  3510. ext.cFree7,
  3511. ext.cFree8,
  3512. ext.cFree9,
  3513. ext.cFree10,
  3514. a.MUSER AS [User],
  3515. a.MTIME AS [MTime]
  3516. FROM ICSOApplyNegDetail a
  3517. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3518. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3519. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3520. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3521. WHERE c.ID IN ({0})";
  3522. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3523. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3524. #endregion
  3525. cmd.Transaction.Commit();
  3526. return data;
  3527. }
  3528. catch (Exception ex)
  3529. {
  3530. if (cmd.Transaction != null)
  3531. cmd.Transaction.Rollback();
  3532. log.Error(ex.Message);
  3533. throw new Exception(ex.Message);
  3534. }
  3535. finally
  3536. {
  3537. if (conn.State == ConnectionState.Open)
  3538. {
  3539. conn.Close();
  3540. }
  3541. conn.Dispose();
  3542. }
  3543. }
  3544. }
  3545. /// <summary>
  3546. /// 委外退料审核
  3547. /// </summary>
  3548. /// <param name="JsonData"></param>
  3549. /// <returns></returns>
  3550. public static DataTable OutsourcingIssueDoNegativeApplyApprove(List<ICSUser> JsonData)
  3551. {
  3552. var language = LanguageHelper.GetName("WMSAPIInfo");
  3553. if (JsonData.Count <= 0)
  3554. {
  3555. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3556. }
  3557. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3558. {
  3559. conn.Open();
  3560. SqlTransaction sqlTran = conn.BeginTransaction();
  3561. SqlCommand cmd = new SqlCommand();
  3562. cmd.Transaction = sqlTran;
  3563. cmd.Connection = conn;
  3564. try
  3565. {
  3566. string sql = string.Empty;
  3567. string ids = string.Empty;
  3568. foreach (var item in JsonData)
  3569. {
  3570. if (string.IsNullOrEmpty(item.ID))
  3571. {
  3572. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  3573. }
  3574. if (string.IsNullOrEmpty(item.User))
  3575. {
  3576. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  3577. }
  3578. if (item.MTime <= new DateTime(2000, 1, 1))
  3579. {
  3580. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  3581. }
  3582. //获取单号
  3583. sql = @"DECLARE @Status VARCHAR(10)
  3584. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  3585. IF (@Status IS NULL)
  3586. BEGIN
  3587. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  3588. RETURN
  3589. END
  3590. ELSE IF (@Status!='1')
  3591. BEGIN
  3592. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  3593. RETURN
  3594. END
  3595. update ICSOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  3596. sql = string.Format(sql, item.ID, item.User, item.MTime);
  3597. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3598. {
  3599. throw new Exception(language.GetNameByCode("WMSAPIInfo021"));//"委外退料申请单审核失败!");
  3600. }
  3601. ids += "'" + item.ID + "',";
  3602. }
  3603. if (string.IsNullOrWhiteSpace(ids))
  3604. {
  3605. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3606. }
  3607. #region 查询返回数据
  3608. sql = @"SELECT a.OApplyNegCode,
  3609. c.WHCode,
  3610. c.Memo,
  3611. d.Name AS Status,
  3612. a.Sequence,
  3613. a.InvCode,
  3614. inv.InvName,
  3615. inv.InvStd,
  3616. a.Quantity,
  3617. inv.InvUnit,
  3618. a.Amount,
  3619. inv.AmountUnit,
  3620. a.IssueNegQuantity,
  3621. ext.ProjectCode,
  3622. ext.BatchCode,
  3623. ext.Version,
  3624. ext.Brand,
  3625. ext.cFree1,
  3626. ext.cFree2,
  3627. ext.cFree3,
  3628. ext.cFree4,
  3629. ext.cFree5,
  3630. ext.cFree6,
  3631. ext.cFree7,
  3632. ext.cFree8,
  3633. ext.cFree9,
  3634. ext.cFree10,
  3635. a.MUSER AS [User],
  3636. a.MTIME AS [MTime]
  3637. FROM ICSOApplyNegDetail a
  3638. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3639. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3640. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3641. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3642. WHERE c.ID IN ({0})";
  3643. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3644. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3645. #endregion
  3646. cmd.Transaction.Commit();
  3647. return data;
  3648. }
  3649. catch (Exception ex)
  3650. {
  3651. if (cmd.Transaction != null)
  3652. cmd.Transaction.Rollback();
  3653. log.Error(ex.Message);
  3654. throw new Exception(ex.Message);
  3655. }
  3656. finally
  3657. {
  3658. if (conn.State == ConnectionState.Open)
  3659. {
  3660. conn.Close();
  3661. }
  3662. conn.Dispose();
  3663. }
  3664. }
  3665. }
  3666. /// <summary>
  3667. /// 委外到货
  3668. /// </summary>
  3669. /// <param name="JsonData"></param>
  3670. /// <returns></returns>
  3671. public static DataTable OutsourcingDeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  3672. {
  3673. var language = LanguageHelper.GetName("WMSAPIInfo");
  3674. if (JsonData.Count <= 0)
  3675. {
  3676. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3677. }
  3678. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3679. {
  3680. conn.Open();
  3681. SqlTransaction sqlTran = conn.BeginTransaction();
  3682. SqlCommand cmd = new SqlCommand();
  3683. cmd.Transaction = sqlTran;
  3684. cmd.Connection = conn;
  3685. try
  3686. {
  3687. string asncodes = string.Empty;
  3688. string sql = string.Empty;
  3689. foreach (var item in JsonData)
  3690. {
  3691. if (string.IsNullOrEmpty(item.OASNCode))
  3692. {
  3693. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!");
  3694. }
  3695. //获取单号
  3696. sql = @"IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.OASNCode='{0}' AND ODNType = '1' AND a.WorkPoint='{1}')
  3697. BEGIN
  3698. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  3699. RETURN
  3700. END
  3701. DECLARE @Status VARCHAR(10)
  3702. SELECT @Status=Status FROM ICSOASN WHERE OASNCode='{0}' and WorkPoint='{1}'
  3703. IF (@Status IS NULL)
  3704. BEGIN
  3705. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  3706. RETURN
  3707. END
  3708. ELSE IF (@Status!='2')
  3709. BEGIN
  3710. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  3711. RETURN
  3712. END
  3713. DECLARE @MaxNO INT,@date varchar(20)='ODN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3714. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3715. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3716. IF @MaxNO IS NULL
  3717. BEGIN
  3718. SELECT @date+'00001' AS Code
  3719. END
  3720. ELSE
  3721. BEGIN
  3722. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3723. END ";
  3724. sql = string.Format(sql, item.OASNCode, item.WorkPoint);
  3725. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3726. //修改送货单到货数量
  3727. foreach (var itemInfo in item.detail)
  3728. {
  3729. sql = @"UPDATE ICSOASNDetail SET ODNQuantity=ISNULL(ODNQuantity, 0)+'{2}'
  3730. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3731. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  3732. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3733. {
  3734. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"委外送货单子表信息更新失败!");
  3735. }
  3736. }
  3737. //创建到货单信息
  3738. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  3739. BEGIN
  3740. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  3741. RETURN
  3742. END
  3743. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3744. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3745. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3746. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3747. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3748. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  3749. '1',b.InvCode,SUM(a.ODNQuantity),'0','0',
  3750. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  3751. d.OOID,d.OODetailID,newid(),newid(),b.ExtensionID,
  3752. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.OASNCode
  3753. FROM ICSOASNDetail a
  3754. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3755. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  3756. INNER JOIN ICSOutsourcingOrder d ON c.TransCode=d.OOCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  3757. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  3758. WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
  3759. 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";
  3760. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.OASNCode);
  3761. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3762. {
  3763. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  3764. }
  3765. ICSOutsourcingService.OutsourcingDeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  3766. asncodes += "'" + item.OASNCode + item.WorkPoint + "',";
  3767. }
  3768. if (string.IsNullOrWhiteSpace(asncodes))
  3769. {
  3770. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  3771. }
  3772. #region 查询返回数据
  3773. sql = @"SELECT
  3774. n.OOCode,
  3775. n.Sequence AS OOSequence,
  3776. a.OASNCode,
  3777. a.ODNCode,
  3778. a.Sequence,
  3779. a.VenCode,
  3780. a.DepCode,
  3781. a.InvCode,
  3782. inv.InvName,
  3783. inv.InvStd,
  3784. a.Quantity,
  3785. inv.InvUnit,
  3786. a.Amount,
  3787. inv.AmountUnit,
  3788. a.RCVQuantity,
  3789. a.UnitPrice,
  3790. a.Currency,
  3791. a.OOID,
  3792. a.OODetailID,
  3793. a.ODNID,
  3794. a.ODNDetailID,
  3795. ext.ProjectCode,
  3796. ext.BatchCode,
  3797. ext.Version,
  3798. ext.Brand,
  3799. ext.cFree1,
  3800. ext.cFree2,
  3801. ext.cFree3,
  3802. ext.cFree4,
  3803. ext.cFree5,
  3804. ext.cFree6,
  3805. ext.cFree7,
  3806. ext.cFree8,
  3807. ext.cFree9,
  3808. ext.cFree10,
  3809. a.MUSER AS [User],
  3810. a.MTIME AS [MTime]
  3811. FROM ICSODeliveryNotice a
  3812. INNER JOIN ICSOutsourcingOrder n ON a.OOID =n.OOID AND a.OODetailID=n.OODetailID AND a.WorkPoint=n.WorkPoint
  3813. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3814. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3815. WHERE a.OASNCode+a.WorkPoint IN ({0})";
  3816. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  3817. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3818. #endregion
  3819. cmd.Transaction.Commit();
  3820. return data;
  3821. }
  3822. catch (Exception ex)
  3823. {
  3824. if (cmd.Transaction != null)
  3825. cmd.Transaction.Rollback();
  3826. log.Error(ex.Message);
  3827. throw new Exception(ex.Message);
  3828. }
  3829. finally
  3830. {
  3831. if (conn.State == ConnectionState.Open)
  3832. {
  3833. conn.Close();
  3834. }
  3835. conn.Dispose();
  3836. }
  3837. }
  3838. }
  3839. /// <summary>
  3840. /// 委外拒收
  3841. /// </summary>
  3842. /// <param name="JsonData"></param>
  3843. /// <returns></returns>
  3844. public static DataTable OutsourcingRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  3845. {
  3846. var language = LanguageHelper.GetName("WMSAPIInfo");
  3847. if (JsonData.Count <= 0)
  3848. {
  3849. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3850. }
  3851. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3852. {
  3853. conn.Open();
  3854. SqlTransaction sqlTran = conn.BeginTransaction();
  3855. SqlCommand cmd = new SqlCommand();
  3856. cmd.Transaction = sqlTran;
  3857. cmd.Connection = conn;
  3858. try
  3859. {
  3860. string lots = string.Empty;
  3861. string sql = string.Empty;
  3862. foreach (var item in JsonData)
  3863. {
  3864. if (string.IsNullOrEmpty(item.ODNCode))
  3865. {
  3866. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  3867. }
  3868. //获取单号
  3869. sql = @"DECLARE @Status VARCHAR(10)
  3870. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  3871. IF (@Status IS NULL)
  3872. BEGIN
  3873. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  3874. RETURN
  3875. END
  3876. ELSE IF (@Status!='2')
  3877. BEGIN
  3878. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  3879. RETURN
  3880. END
  3881. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3882. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3883. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3884. IF @MaxNO IS NULL
  3885. BEGIN
  3886. SELECT @date+'00001' AS Code
  3887. END
  3888. ELSE
  3889. BEGIN
  3890. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3891. END ";
  3892. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  3893. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3894. //修改送货单到货数量
  3895. foreach (var itemInfo in item.detail)
  3896. {
  3897. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  3898. BEGIN
  3899. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  3900. RETURN
  3901. END
  3902. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  3903. BEGIN
  3904. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  3905. RETURN
  3906. END
  3907. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3908. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3909. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3910. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3911. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3912. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  3913. '3',d.InvCode,'{7}', '{8}', 0,
  3914. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  3915. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  3916. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  3917. FROM ICSODeliveryNotice a
  3918. INNER JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  3919. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  3920. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  3921. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND a.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  3922. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  3923. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  3924. WHERE a.ODNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  3925. 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);
  3926. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3927. {
  3928. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  3929. }
  3930. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  3931. }
  3932. ICSOutsourcingService.OutsourcingRejectDocInNewERP(item.ODNCode, Code, item.WorkPoint, cmd, language);
  3933. }
  3934. if (string.IsNullOrWhiteSpace(lots))
  3935. {
  3936. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  3937. }
  3938. #region 查询返回数据
  3939. sql = @"SELECT
  3940. n.ODNCode,
  3941. n.Sequence,
  3942. a.ODNCode AS RJTCode,
  3943. a.Sequence AS RJTSequence,
  3944. a.VenCode,
  3945. a.DepCode,
  3946. a.InvCode,
  3947. inv.InvName,
  3948. inv.InvStd,
  3949. a.Quantity,
  3950. inv.InvUnit,
  3951. a.Amount,
  3952. inv.AmountUnit,
  3953. a.RCVQuantity,
  3954. a.UnitPrice,
  3955. a.Currency,
  3956. a.OOID,
  3957. a.OODetailID,
  3958. a.ODNID,
  3959. a.ODNDetailID,
  3960. ext.ProjectCode,
  3961. ext.BatchCode,
  3962. ext.Version,
  3963. ext.Brand,
  3964. ext.cFree1,
  3965. ext.cFree2,
  3966. ext.cFree3,
  3967. ext.cFree4,
  3968. ext.cFree5,
  3969. ext.cFree6,
  3970. ext.cFree7,
  3971. ext.cFree8,
  3972. ext.cFree9,
  3973. ext.cFree10,
  3974. a.MUSER AS [User],
  3975. a.MTIME AS [MTime]
  3976. FROM ICSODeliveryNotice a
  3977. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  3978. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3979. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3980. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  3981. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  3982. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3983. #endregion
  3984. cmd.Transaction.Commit();
  3985. return data;
  3986. }
  3987. catch (Exception ex)
  3988. {
  3989. if (cmd.Transaction != null)
  3990. cmd.Transaction.Rollback();
  3991. log.Error(ex.Message);
  3992. throw new Exception(ex.Message);
  3993. }
  3994. finally
  3995. {
  3996. if (conn.State == ConnectionState.Open)
  3997. {
  3998. conn.Close();
  3999. }
  4000. conn.Dispose();
  4001. }
  4002. }
  4003. }
  4004. #endregion
  4005. #region 生产
  4006. /// <summary>
  4007. /// 生产退料 新建
  4008. /// </summary>
  4009. /// <param name="JsonData"></param>
  4010. /// <returns></returns>
  4011. public static DataTable MOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  4012. {
  4013. var language = LanguageHelper.GetName("WMSAPIInfo");
  4014. if (JsonData.Count <= 0)
  4015. {
  4016. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4017. }
  4018. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4019. {
  4020. conn.Open();
  4021. SqlTransaction sqlTran = conn.BeginTransaction();
  4022. SqlCommand cmd = new SqlCommand();
  4023. cmd.Transaction = sqlTran;
  4024. cmd.Connection = conn;
  4025. try
  4026. {
  4027. string codes = string.Empty;
  4028. string sql = string.Empty;
  4029. foreach (var item in JsonData)
  4030. {
  4031. //获取单号
  4032. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  4033. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  4034. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  4035. IF @MaxNO IS NULL
  4036. BEGIN
  4037. SELECT @date+'00001' AS Code
  4038. END
  4039. ELSE
  4040. BEGIN
  4041. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  4042. END ";
  4043. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4044. //创建主表
  4045. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  4046. BEGIN
  4047. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  4048. RETURN
  4049. END
  4050. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  4051. 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}','')";
  4052. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  4053. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4054. {
  4055. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  4056. }
  4057. foreach (var itemInfo in item.detail)
  4058. {
  4059. //创建子表
  4060. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  4061. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  4062. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  4063. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  4064. '{4}','{5}',0,'{6}','{7}',
  4065. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  4066. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  4067. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4068. {
  4069. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  4070. }
  4071. }
  4072. //校验退料数量是否超出领料数量
  4073. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  4074. DBHelper.ExecuteNonQuery(sql, cmd);
  4075. codes += "'" + Code + item.WorkPoint + "',";
  4076. }
  4077. if (string.IsNullOrWhiteSpace(codes))
  4078. {
  4079. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  4080. }
  4081. #region 查询返回数据
  4082. sql = @"SELECT a.ApplyNegCode,
  4083. c.WHCode,
  4084. c.Memo,
  4085. d.Name AS Status,
  4086. a.Sequence,
  4087. a.InvCode,
  4088. inv.InvName,
  4089. inv.InvStd,
  4090. a.Quantity,
  4091. inv.InvUnit,
  4092. a.Amount,
  4093. inv.AmountUnit,
  4094. a.IssueNegQuantity,
  4095. ext.ProjectCode,
  4096. ext.BatchCode,
  4097. ext.Version,
  4098. ext.Brand,
  4099. ext.cFree1,
  4100. ext.cFree2,
  4101. ext.cFree3,
  4102. ext.cFree4,
  4103. ext.cFree5,
  4104. ext.cFree6,
  4105. ext.cFree7,
  4106. ext.cFree8,
  4107. ext.cFree9,
  4108. ext.cFree10,
  4109. a.MUSER AS [User],
  4110. a.MTIME AS [MTime]
  4111. FROM ICSMOApplyNegDetail a
  4112. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4113. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4114. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4115. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4116. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  4117. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  4118. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4119. #endregion
  4120. cmd.Transaction.Commit();
  4121. return data;
  4122. }
  4123. catch (Exception ex)
  4124. {
  4125. if (cmd.Transaction != null)
  4126. cmd.Transaction.Rollback();
  4127. log.Error(ex.Message);
  4128. throw new Exception(ex.Message);
  4129. }
  4130. finally
  4131. {
  4132. if (conn.State == ConnectionState.Open)
  4133. {
  4134. conn.Close();
  4135. }
  4136. conn.Dispose();
  4137. }
  4138. }
  4139. }
  4140. private static string CheckMOIssueDoc(string Type, string ID, string WorkPoint, Dictionary<string, string> language)
  4141. {
  4142. string sql = string.Empty;
  4143. if (Type == "1")
  4144. {
  4145. sql = @"DECLARE @PickID VARCHAR(10)
  4146. SELECT @PickID=b.PickID
  4147. FROM ICSMOApplyNegDetail a
  4148. INNER JOIN ICSMOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  4149. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4150. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  4151. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  4152. FROM ICSMOApplyNegDetail a
  4153. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4154. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  4155. GROUP BY b.PickID
  4156. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  4157. IF (@PickID IS NOT NULL)
  4158. BEGIN
  4159. DECLARE @InvCode VARCHAR(100)
  4160. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  4161. RAISERROR(@InvCode,16,1);
  4162. RETURN
  4163. END ";
  4164. }
  4165. else if (Type == "2")
  4166. {
  4167. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  4168. SELECT @ApplyDetailID=b.ApplyDetailID
  4169. FROM ICSMOApplyNegDetail a
  4170. INNER JOIN ICSMOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  4171. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4172. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  4173. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  4174. FROM ICSMOApplyNegDetail a
  4175. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4176. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  4177. GROUP BY b.ApplyDetailID
  4178. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  4179. IF (@ApplyDetailID IS NOT NULL)
  4180. BEGIN
  4181. DECLARE @InvCode VARCHAR(100)
  4182. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  4183. RAISERROR(@InvCode,16,1);
  4184. RETURN
  4185. END ";
  4186. }
  4187. else if (Type == "3")
  4188. {
  4189. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  4190. SELECT @IssueDetailID=b.IssueDetailID
  4191. FROM ICSMOApplyNegDetail a
  4192. INNER JOIN ICSMOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  4193. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4194. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  4195. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  4196. FROM ICSMOApplyNegDetail a
  4197. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4198. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  4199. GROUP BY b.IssueDetailID
  4200. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  4201. IF (@IssueDetailID IS NOT NULL)
  4202. BEGIN
  4203. DECLARE @InvCode VARCHAR(100)
  4204. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  4205. RAISERROR(@InvCode,16,1);
  4206. RETURN
  4207. END ";
  4208. }
  4209. else
  4210. {
  4211. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  4212. }
  4213. sql = string.Format(sql, ID, WorkPoint, Type);
  4214. return sql;
  4215. }
  4216. /// <summary>
  4217. /// 生产退料 修改
  4218. /// </summary>
  4219. /// <param name="JsonData"></param>
  4220. /// <returns></returns>
  4221. public static DataTable MOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  4222. {
  4223. var language = LanguageHelper.GetName("WMSAPIInfo");
  4224. if (JsonData.Count <= 0)
  4225. {
  4226. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4227. }
  4228. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4229. {
  4230. conn.Open();
  4231. SqlTransaction sqlTran = conn.BeginTransaction();
  4232. SqlCommand cmd = new SqlCommand();
  4233. cmd.Transaction = sqlTran;
  4234. cmd.Connection = conn;
  4235. try
  4236. {
  4237. string sql = string.Empty;
  4238. string Code = string.Empty;
  4239. string ids = string.Empty;
  4240. foreach (var item in JsonData)
  4241. {
  4242. //主表修改
  4243. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  4244. BEGIN
  4245. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  4246. RETURN
  4247. END
  4248. DECLARE @Status VARCHAR(10)
  4249. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  4250. IF (@Status IS NULL)
  4251. BEGIN
  4252. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  4253. RETURN
  4254. END
  4255. ELSE IF (@Status!='1')
  4256. BEGIN
  4257. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  4258. RETURN
  4259. END
  4260. 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}' ";
  4261. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint);
  4262. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4263. {
  4264. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  4265. }
  4266. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  4267. if (detail > 0)
  4268. {
  4269. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  4270. sql = string.Format(sql, item.ID, item.WorkPoint);
  4271. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4272. }
  4273. foreach (var itemInfo in item.detail)
  4274. {
  4275. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  4276. {
  4277. //创建子表
  4278. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  4279. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  4280. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  4281. '{4}','{5}',0,'{6}','{7}',
  4282. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  4283. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  4284. }
  4285. else
  4286. {
  4287. //子表修改
  4288. 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}'";
  4289. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  4290. }
  4291. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4292. {
  4293. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  4294. }
  4295. }
  4296. //校验退料数量是否超出领料数量
  4297. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  4298. DBHelper.ExecuteNonQuery(sql, cmd);
  4299. ids += "'" + item.ID + "',";
  4300. }
  4301. if (string.IsNullOrWhiteSpace(ids))
  4302. {
  4303. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  4304. }
  4305. #region 查询返回数据
  4306. sql = @"SELECT a.ApplyNegCode,
  4307. c.WHCode,
  4308. c.Memo,
  4309. d.Name AS Status,
  4310. a.Sequence,
  4311. a.InvCode,
  4312. inv.InvName,
  4313. inv.InvStd,
  4314. a.Quantity,
  4315. inv.InvUnit,
  4316. a.Amount,
  4317. inv.AmountUnit,
  4318. a.IssueNegQuantity,
  4319. ext.ProjectCode,
  4320. ext.BatchCode,
  4321. ext.Version,
  4322. ext.Brand,
  4323. ext.cFree1,
  4324. ext.cFree2,
  4325. ext.cFree3,
  4326. ext.cFree4,
  4327. ext.cFree5,
  4328. ext.cFree6,
  4329. ext.cFree7,
  4330. ext.cFree8,
  4331. ext.cFree9,
  4332. ext.cFree10,
  4333. a.MUSER AS [User],
  4334. a.MTIME AS [MTime]
  4335. FROM ICSMOApplyNegDetail a
  4336. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4337. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4338. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4339. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4340. WHERE c.ID IN ({0})";
  4341. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  4342. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4343. #endregion
  4344. cmd.Transaction.Commit();
  4345. return data;
  4346. }
  4347. catch (Exception ex)
  4348. {
  4349. if (cmd.Transaction != null)
  4350. cmd.Transaction.Rollback();
  4351. log.Error(ex.Message);
  4352. throw new Exception(ex.Message);
  4353. }
  4354. finally
  4355. {
  4356. if (conn.State == ConnectionState.Open)
  4357. {
  4358. conn.Close();
  4359. }
  4360. conn.Dispose();
  4361. }
  4362. }
  4363. }
  4364. /// <summary>
  4365. /// 生产退料审核
  4366. /// </summary>
  4367. /// <param name="JsonData"></param>
  4368. /// <returns></returns>
  4369. public static DataTable MOIssueDocNegativeApplyApprove(List<ICSUser> JsonData)
  4370. {
  4371. var language = LanguageHelper.GetName("WMSAPIInfo");
  4372. if (JsonData.Count <= 0)
  4373. {
  4374. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4375. }
  4376. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4377. {
  4378. conn.Open();
  4379. SqlTransaction sqlTran = conn.BeginTransaction();
  4380. SqlCommand cmd = new SqlCommand();
  4381. cmd.Transaction = sqlTran;
  4382. cmd.Connection = conn;
  4383. try
  4384. {
  4385. string sql = string.Empty;
  4386. string ids = string.Empty;
  4387. foreach (var item in JsonData)
  4388. {
  4389. if (string.IsNullOrEmpty(item.ID))
  4390. {
  4391. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  4392. }
  4393. if (string.IsNullOrEmpty(item.User))
  4394. {
  4395. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  4396. }
  4397. if (item.MTime <= new DateTime(2000, 1, 1))
  4398. {
  4399. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  4400. }
  4401. //获取单号
  4402. sql = @"DECLARE @Status VARCHAR(10)
  4403. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  4404. IF (@Status IS NULL)
  4405. BEGIN
  4406. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  4407. RETURN
  4408. END
  4409. ELSE IF (@Status!='1')
  4410. BEGIN
  4411. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  4412. RETURN
  4413. END
  4414. update ICSMOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  4415. sql = string.Format(sql, item.ID, item.User, item.MTime);
  4416. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4417. {
  4418. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  4419. }
  4420. ids += "'" + item.ID + "',";
  4421. }
  4422. if (string.IsNullOrWhiteSpace(ids))
  4423. {
  4424. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  4425. }
  4426. #region 查询返回数据
  4427. sql = @"SELECT a.ApplyNegCode,
  4428. c.WHCode,
  4429. c.Memo,
  4430. d.Name AS Status,
  4431. a.Sequence,
  4432. a.InvCode,
  4433. inv.InvName,
  4434. inv.InvStd,
  4435. a.Quantity,
  4436. inv.InvUnit,
  4437. a.Amount,
  4438. inv.AmountUnit,
  4439. a.IssueNegQuantity,
  4440. ext.ProjectCode,
  4441. ext.BatchCode,
  4442. ext.Version,
  4443. ext.Brand,
  4444. ext.cFree1,
  4445. ext.cFree2,
  4446. ext.cFree3,
  4447. ext.cFree4,
  4448. ext.cFree5,
  4449. ext.cFree6,
  4450. ext.cFree7,
  4451. ext.cFree8,
  4452. ext.cFree9,
  4453. ext.cFree10,
  4454. a.MUSER AS [User],
  4455. a.MTIME AS [MTime]
  4456. FROM ICSMOApplyNegDetail a
  4457. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4458. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4459. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4460. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4461. WHERE c.ID IN ({0})";
  4462. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  4463. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4464. #endregion
  4465. cmd.Transaction.Commit();
  4466. return data;
  4467. }
  4468. catch (Exception ex)
  4469. {
  4470. if (cmd.Transaction != null)
  4471. cmd.Transaction.Rollback();
  4472. log.Error(ex.Message);
  4473. throw new Exception(ex.Message);
  4474. }
  4475. finally
  4476. {
  4477. if (conn.State == ConnectionState.Open)
  4478. {
  4479. conn.Close();
  4480. }
  4481. conn.Dispose();
  4482. }
  4483. }
  4484. }
  4485. #endregion
  4486. #region 一步调拨(调拨申请单)
  4487. /// <summary>
  4488. /// 一步调拨(调拨申请单)
  4489. /// </summary>
  4490. /// <param name="JsonData"></param>
  4491. /// <returns></returns>
  4492. public static DataTable OneStepTransferApplicationIn(List<TransferApplication> JsonData)
  4493. {
  4494. var language = LanguageHelper.GetName("WMSAPIInfo");
  4495. if (JsonData.Count <= 0)
  4496. {
  4497. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4498. }
  4499. DataTable printTable = new DataTable();
  4500. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4501. {
  4502. conn.Open();
  4503. SqlTransaction sqlTran = conn.BeginTransaction();
  4504. SqlCommand cmd = new SqlCommand();
  4505. cmd.Transaction = sqlTran;
  4506. cmd.Connection = conn;
  4507. string BusinessCode = string.Empty;
  4508. try
  4509. {
  4510. string sql = string.Empty;
  4511. string Identification = Guid.NewGuid().ToString();
  4512. foreach (var item in JsonData)
  4513. {
  4514. if (string.IsNullOrEmpty(item.TransCode))
  4515. {
  4516. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨申请单号不能为空!");
  4517. }
  4518. string[] trans = item.TransCode.Split('~');
  4519. string MergeID = "";
  4520. if (trans.Length == 2)
  4521. {
  4522. MergeID = trans[0];
  4523. item.TransCode = trans[1];
  4524. }
  4525. //验证信息
  4526. sql = @"DECLARE @Status VARCHAR(10)
  4527. SELECT @Status=Status FROM ICSTransferApplication WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  4528. IF (@Status IS NULL)
  4529. BEGIN
  4530. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  4531. RETURN
  4532. END
  4533. ELSE IF (@Status!='1')
  4534. BEGIN
  4535. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  4536. RETURN
  4537. END";
  4538. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  4539. DBHelper.ExecuteNonQuery(sql, cmd);
  4540. foreach (var itemInfo in item.Detail)
  4541. {
  4542. //验证仓库库位信息
  4543. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4544. BEGIN
  4545. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4546. RETURN
  4547. END
  4548. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4549. BEGIN
  4550. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4551. RETURN
  4552. END
  4553. IF NOT EXISTS(SELECT a.ID
  4554. FROM ICSWareHouse a
  4555. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4556. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4557. BEGIN
  4558. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4559. RETURN
  4560. END";
  4561. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4562. DBHelper.ExecuteNonQuery(sql, cmd);
  4563. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  4564. //更新源头单据信息
  4565. ICSWareHouseService.OneStepTransferApplicationIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  4566. //更新条码信息
  4567. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4568. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4569. }
  4570. }
  4571. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4572. if (!printTable.Equals("{}"))
  4573. {
  4574. cmd.Transaction.Commit();
  4575. return printTable;
  4576. }
  4577. else
  4578. {
  4579. DataTable table = GetData(Identification, 3, cmd);
  4580. cmd.Transaction.Commit();
  4581. return table;
  4582. }
  4583. }
  4584. catch (Exception ex)
  4585. {
  4586. if (cmd.Transaction != null)
  4587. cmd.Transaction.Rollback();
  4588. log.Error(ex.Message);
  4589. throw new Exception(ex.Message);
  4590. }
  4591. finally
  4592. {
  4593. if (conn.State == ConnectionState.Open)
  4594. {
  4595. conn.Close();
  4596. }
  4597. conn.Dispose();
  4598. }
  4599. }
  4600. }
  4601. #endregion
  4602. #region 一步调拨
  4603. /// <summary>
  4604. /// 一步调拨
  4605. /// </summary>
  4606. /// <param name="JsonData"></param>
  4607. /// <returns></returns>
  4608. public static DataTable OneStepTransferDocIn(List<TransferDoc> JsonData)
  4609. {
  4610. var language = LanguageHelper.GetName("WMSAPIInfo");
  4611. if (JsonData.Count <= 0)
  4612. {
  4613. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4614. }
  4615. DataTable printTable = new DataTable();
  4616. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4617. {
  4618. conn.Open();
  4619. SqlTransaction sqlTran = conn.BeginTransaction();
  4620. SqlCommand cmd = new SqlCommand();
  4621. cmd.Transaction = sqlTran;
  4622. cmd.Connection = conn;
  4623. string BusinessCode = string.Empty;
  4624. try
  4625. {
  4626. string sql = string.Empty;
  4627. string Identification = Guid.NewGuid().ToString();
  4628. foreach (var item in JsonData)
  4629. {
  4630. if (string.IsNullOrEmpty(item.TransCode))
  4631. {
  4632. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨单号不能为空!");
  4633. }
  4634. string[] trans = item.TransCode.Split('~');
  4635. string MergeID = "";
  4636. if (trans.Length == 2)
  4637. {
  4638. MergeID = trans[0];
  4639. item.TransCode = trans[1];
  4640. }
  4641. //验证信息
  4642. sql = @"DECLARE @Status VARCHAR(10)
  4643. SELECT @Status=Status FROM ICSTransfer WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  4644. IF (@Status IS NULL)
  4645. BEGIN
  4646. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  4647. RETURN
  4648. END
  4649. ELSE IF (@Status!='1')
  4650. BEGIN
  4651. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  4652. RETURN
  4653. END";
  4654. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  4655. DBHelper.ExecuteNonQuery(sql, cmd);
  4656. foreach (var itemInfo in item.Detail)
  4657. {
  4658. //验证仓库库位信息
  4659. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4660. BEGIN
  4661. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4662. RETURN
  4663. END
  4664. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4665. BEGIN
  4666. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4667. RETURN
  4668. END
  4669. IF NOT EXISTS(SELECT a.ID
  4670. FROM ICSWareHouse a
  4671. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4672. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4673. BEGIN
  4674. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4675. RETURN
  4676. END";
  4677. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4678. DBHelper.ExecuteNonQuery(sql, cmd);
  4679. BusinessCode = TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>();
  4680. //更新源头单据信息
  4681. ICSWareHouseService.OneStepTransferDocIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  4682. //更新条码信息
  4683. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4684. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4685. }
  4686. }
  4687. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4688. if (!printTable.Equals("{}"))
  4689. {
  4690. cmd.Transaction.Commit();
  4691. return printTable;
  4692. }
  4693. else
  4694. {
  4695. DataTable table = GetData(Identification, 3, cmd);
  4696. cmd.Transaction.Commit();
  4697. return table;
  4698. }
  4699. }
  4700. catch (Exception ex)
  4701. {
  4702. if (cmd.Transaction != null)
  4703. cmd.Transaction.Rollback();
  4704. log.Error(ex.Message);
  4705. throw new Exception(ex.Message);
  4706. }
  4707. finally
  4708. {
  4709. if (conn.State == ConnectionState.Open)
  4710. {
  4711. conn.Close();
  4712. }
  4713. conn.Dispose();
  4714. }
  4715. }
  4716. }
  4717. #endregion
  4718. #region 调拨
  4719. /// <summary>
  4720. /// 调拨
  4721. /// </summary>
  4722. /// <param name="JsonData"></param>
  4723. /// <returns></returns>
  4724. public static DataTable TransferDocCreate(List<TransferDoc> JsonData)
  4725. {
  4726. var language = LanguageHelper.GetName("WMSAPIInfo");
  4727. if (JsonData.Count <= 0)
  4728. {
  4729. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4730. }
  4731. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4732. {
  4733. conn.Open();
  4734. SqlTransaction sqlTran = conn.BeginTransaction();
  4735. SqlCommand cmd = new SqlCommand();
  4736. cmd.Transaction = sqlTran;
  4737. cmd.Connection = conn;
  4738. string BusinessCode = string.Empty;
  4739. try
  4740. {
  4741. string sql = string.Empty;
  4742. string Identification = Guid.NewGuid().ToString();
  4743. foreach (var item in JsonData)
  4744. {
  4745. string MergeID = "";
  4746. foreach (var itemInfo in item.Detail)
  4747. {
  4748. //验证仓库库位信息
  4749. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4750. BEGIN
  4751. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4752. RETURN
  4753. END
  4754. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4755. BEGIN
  4756. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4757. RETURN
  4758. END
  4759. IF NOT EXISTS(SELECT a.ID
  4760. FROM ICSWareHouse a
  4761. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4762. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4763. BEGIN
  4764. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4765. RETURN
  4766. END";
  4767. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4768. DBHelper.ExecuteNonQuery(sql, cmd);
  4769. BusinessCode = TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>();
  4770. //更新条码信息
  4771. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4772. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4773. }
  4774. }
  4775. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4776. DataTable table = GetData(Identification, 3, cmd);
  4777. cmd.Transaction.Commit();
  4778. return table;
  4779. }
  4780. catch (Exception ex)
  4781. {
  4782. if (cmd.Transaction != null)
  4783. cmd.Transaction.Rollback();
  4784. log.Error(ex.Message);
  4785. throw new Exception(ex.Message);
  4786. }
  4787. finally
  4788. {
  4789. if (conn.State == ConnectionState.Open)
  4790. {
  4791. conn.Close();
  4792. }
  4793. conn.Dispose();
  4794. }
  4795. }
  4796. }
  4797. #endregion
  4798. #region 调拨申请单
  4799. /// <summary>
  4800. /// 调拨
  4801. /// </summary>
  4802. /// <param name="JsonData"></param>
  4803. /// <returns></returns>
  4804. public static DataTable TransferApplicationCreate(List<TransferApplication> JsonData)
  4805. {
  4806. var language = LanguageHelper.GetName("WMSAPIInfo");
  4807. if (JsonData.Count <= 0)
  4808. {
  4809. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4810. }
  4811. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4812. {
  4813. conn.Open();
  4814. SqlTransaction sqlTran = conn.BeginTransaction();
  4815. SqlCommand cmd = new SqlCommand();
  4816. cmd.Transaction = sqlTran;
  4817. cmd.Connection = conn;
  4818. string BusinessCode = string.Empty;
  4819. try
  4820. {
  4821. string sql = string.Empty;
  4822. string Identification = Guid.NewGuid().ToString();
  4823. foreach (var item in JsonData)
  4824. {
  4825. string MergeID = "";
  4826. foreach (var itemInfo in item.Detail)
  4827. {
  4828. //验证仓库库位信息
  4829. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4830. BEGIN
  4831. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4832. RETURN
  4833. END
  4834. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4835. BEGIN
  4836. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4837. RETURN
  4838. END
  4839. IF NOT EXISTS(SELECT a.ID
  4840. FROM ICSWareHouse a
  4841. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4842. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4843. BEGIN
  4844. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4845. RETURN
  4846. END";
  4847. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4848. DBHelper.ExecuteNonQuery(sql, cmd);
  4849. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  4850. //更新条码信息
  4851. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4852. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4853. }
  4854. }
  4855. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferApplicationIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4856. DataTable table = GetData(Identification, 3, cmd);
  4857. cmd.Transaction.Commit();
  4858. return table;
  4859. }
  4860. catch (Exception ex)
  4861. {
  4862. if (cmd.Transaction != null)
  4863. cmd.Transaction.Rollback();
  4864. log.Error(ex.Message);
  4865. throw new Exception(ex.Message);
  4866. }
  4867. finally
  4868. {
  4869. if (conn.State == ConnectionState.Open)
  4870. {
  4871. conn.Close();
  4872. }
  4873. conn.Dispose();
  4874. }
  4875. }
  4876. }
  4877. #endregion
  4878. #region 调拨申请单
  4879. /// <summary>
  4880. /// 调拨申请单
  4881. /// </summary>
  4882. /// <param name="JsonData"></param>
  4883. /// <returns></returns>
  4884. public static DataTable TransferApplicationInCreate(List<TransferApplication> JsonData)
  4885. {
  4886. var language = LanguageHelper.GetName("WMSAPIInfo");
  4887. if (JsonData.Count <= 0)
  4888. {
  4889. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4890. }
  4891. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4892. {
  4893. conn.Open();
  4894. SqlTransaction sqlTran = conn.BeginTransaction();
  4895. SqlCommand cmd = new SqlCommand();
  4896. cmd.Transaction = sqlTran;
  4897. cmd.Connection = conn;
  4898. string BusinessCode = string.Empty;
  4899. try
  4900. {
  4901. string sql = string.Empty;
  4902. string Identification = Guid.NewGuid().ToString();
  4903. foreach (var item in JsonData)
  4904. {
  4905. string MergeID = "";
  4906. foreach (var itemInfo in item.Detail)
  4907. {
  4908. //验证仓库库位信息
  4909. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4910. BEGIN
  4911. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4912. RETURN
  4913. END
  4914. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4915. BEGIN
  4916. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4917. RETURN
  4918. END
  4919. IF NOT EXISTS(SELECT a.ID
  4920. FROM ICSWareHouse a
  4921. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4922. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4923. BEGIN
  4924. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4925. RETURN
  4926. END
  4927. IF EXISTS(SELECT ID
  4928. FROM ICSWareHouseLotInfo
  4929. WHERE WarehouseCode='{0}' AND WorkPoint='{1}' AND LotNo='{3}')
  4930. BEGIN
  4931. RAISERROR('" + language.GetNameByCode("WMSAPIInfo355") + @"',16,1);
  4932. RETURN
  4933. END";
  4934. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode, itemInfo.LotNo);
  4935. DBHelper.ExecuteNonQuery(sql, cmd);
  4936. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  4937. //更新源头单据信息
  4938. ICSWareHouseService.OneStepTransferApplicationIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  4939. //更新条码信息
  4940. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4941. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4942. }
  4943. }
  4944. ICSWareHouseService.StepTransferApplicationERP(TransTypeEnum.StepTransferApplicationIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4945. DataTable table = GetData(Identification, 3, cmd);
  4946. cmd.Transaction.Commit();
  4947. return table;
  4948. }
  4949. catch (Exception ex)
  4950. {
  4951. if (cmd.Transaction != null)
  4952. cmd.Transaction.Rollback();
  4953. log.Error(ex.Message);
  4954. throw new Exception(ex.Message);
  4955. }
  4956. finally
  4957. {
  4958. if (conn.State == ConnectionState.Open)
  4959. {
  4960. conn.Close();
  4961. }
  4962. conn.Dispose();
  4963. }
  4964. }
  4965. }
  4966. #endregion
  4967. #region 移库
  4968. /// <summary>
  4969. /// 移库
  4970. /// </summary>
  4971. /// <param name="JsonData"></param>
  4972. /// <returns></returns>
  4973. public static DataTable LibraryUpdate(List<ICSLibraryModel> JsonData)
  4974. {
  4975. var language = LanguageHelper.GetName("WMSAPIInfo");
  4976. if (JsonData.Count <= 0)
  4977. {
  4978. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4979. }
  4980. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4981. {
  4982. conn.Open();
  4983. SqlTransaction sqlTran = conn.BeginTransaction();
  4984. SqlCommand cmd = new SqlCommand();
  4985. cmd.Transaction = sqlTran;
  4986. cmd.Connection = conn;
  4987. try
  4988. {
  4989. string sql = string.Empty;
  4990. string Identification = Guid.NewGuid().ToString();
  4991. foreach (var item in JsonData)
  4992. {
  4993. if (string.IsNullOrEmpty(item.LotNo))
  4994. {
  4995. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4996. }
  4997. //验证仓库库位信息
  4998. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4999. BEGIN
  5000. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  5001. RETURN
  5002. END
  5003. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  5004. BEGIN
  5005. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  5006. RETURN
  5007. END
  5008. IF NOT EXISTS(SELECT a.ID
  5009. FROM ICSWareHouse a
  5010. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  5011. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  5012. BEGIN
  5013. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  5014. RETURN
  5015. END";
  5016. sql = string.Format(sql, item.WarehouseCode, item.WorkPoint, item.LocationCode);
  5017. DBHelper.ExecuteNonQuery(sql, cmd);
  5018. //更新条码信息
  5019. ICSWareHouseLotInfoService.WareHouseLotInfoLibrary(Identification, item.TransCode, item.TransSequence, item.WarehouseCode, item.LocationCode, item.LotNo,
  5020. item.User, item.WorkPoint, "7", "29", cmd, language);
  5021. }
  5022. DataTable table = GetData(Identification, 3, cmd);
  5023. cmd.Transaction.Commit();
  5024. return table;
  5025. }
  5026. catch (Exception ex)
  5027. {
  5028. if (cmd.Transaction != null)
  5029. cmd.Transaction.Rollback();
  5030. log.Error(ex.Message);
  5031. throw new Exception(ex.Message);
  5032. }
  5033. finally
  5034. {
  5035. if (conn.State == ConnectionState.Open)
  5036. {
  5037. conn.Close();
  5038. }
  5039. conn.Dispose();
  5040. }
  5041. }
  5042. }
  5043. #endregion
  5044. #region 合并
  5045. /// <summary>
  5046. /// 合并
  5047. /// </summary>
  5048. /// <param name="JsonData"></param>
  5049. /// <returns></returns>
  5050. public static DataTable LOTMergeCreate(List<LOTCreateIModel> JsonData)
  5051. {
  5052. var language = LanguageHelper.GetName("WMSAPIInfo");
  5053. if (JsonData.Count <= 0)
  5054. {
  5055. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5056. }
  5057. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5058. {
  5059. conn.Open();
  5060. SqlTransaction sqlTran = conn.BeginTransaction();
  5061. SqlCommand cmd = new SqlCommand();
  5062. cmd.Transaction = sqlTran;
  5063. cmd.Connection = conn;
  5064. try
  5065. {
  5066. string Identification = Guid.NewGuid().ToString();
  5067. foreach (var item in JsonData)
  5068. {
  5069. if (string.IsNullOrEmpty(item.LotNo))
  5070. {
  5071. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  5072. }
  5073. else if (item.detail.Count <= 0)
  5074. {
  5075. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  5076. }
  5077. //合并前日志
  5078. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  5079. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  5080. foreach (var info in item.detail)
  5081. {
  5082. //合并前日志
  5083. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, info.CurrentLotNo, item.User, item.WorkPoint, "5",
  5084. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  5085. //更新条码信息
  5086. ICSWareHouseLotInfoService.WareHouseLotInfoMerge(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "5",
  5087. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  5088. }
  5089. //合并后日志
  5090. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  5091. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  5092. }
  5093. DataTable table = GetData(Identification, 1, cmd);
  5094. cmd.Transaction.Commit();
  5095. return table;
  5096. }
  5097. catch (Exception ex)
  5098. {
  5099. if (cmd.Transaction != null)
  5100. cmd.Transaction.Rollback();
  5101. log.Error(ex.Message);
  5102. throw new Exception(ex.Message);
  5103. }
  5104. finally
  5105. {
  5106. if (conn.State == ConnectionState.Open)
  5107. {
  5108. conn.Close();
  5109. }
  5110. conn.Dispose();
  5111. }
  5112. }
  5113. }
  5114. #endregion
  5115. #region 拆分
  5116. /// <summary>
  5117. /// 拆分
  5118. /// </summary>
  5119. /// <param name="JsonData"></param>
  5120. /// <returns></returns>
  5121. public static DataTable LOTSplitCreate(List<LOTCreateIModel> JsonData)
  5122. {
  5123. var language = LanguageHelper.GetName("WMSAPIInfo");
  5124. if (JsonData.Count <= 0)
  5125. {
  5126. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5127. }
  5128. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5129. {
  5130. conn.Open();
  5131. SqlTransaction sqlTran = conn.BeginTransaction();
  5132. SqlCommand cmd = new SqlCommand();
  5133. cmd.Transaction = sqlTran;
  5134. cmd.Connection = conn;
  5135. try
  5136. {
  5137. string Identification = Guid.NewGuid().ToString();
  5138. foreach (var item in JsonData)
  5139. {
  5140. if (string.IsNullOrEmpty(item.LotNo))
  5141. {
  5142. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  5143. }
  5144. else if (item.detail.Count <= 0)
  5145. {
  5146. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  5147. }
  5148. //拆分前日志
  5149. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  5150. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(), cmd, language);
  5151. foreach (var info in item.detail)
  5152. {
  5153. //更新条码信息
  5154. ICSWareHouseLotInfoService.WareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  5155. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  5156. }
  5157. //拆分后日志
  5158. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  5159. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  5160. }
  5161. DataTable table = GetData(Identification, 1, cmd);
  5162. cmd.Transaction.Commit();
  5163. return table;
  5164. }
  5165. catch (Exception ex)
  5166. {
  5167. if (cmd.Transaction != null)
  5168. cmd.Transaction.Rollback();
  5169. log.Error(ex.Message);
  5170. throw new Exception(ex.Message);
  5171. }
  5172. finally
  5173. {
  5174. if (conn.State == ConnectionState.Open)
  5175. {
  5176. conn.Close();
  5177. }
  5178. conn.Dispose();
  5179. }
  5180. }
  5181. }
  5182. #endregion
  5183. /// <summary>
  5184. /// 获取出入库记录信息
  5185. /// </summary>
  5186. /// <param name="Identification"></param>
  5187. /// <param name="type">1:入库,2:出库,3:调拨</param>
  5188. /// <param name="cmd"></param>
  5189. /// <returns></returns>
  5190. private static DataTable GetData(string Identification, int type, SqlCommand cmd)
  5191. {
  5192. #region SLQ
  5193. string sql = @"SELECT log.ID,
  5194. log.TransCode,
  5195. log.TransSequence,
  5196. log.LotNo,
  5197. log.InvCode,
  5198. inv.InvName,
  5199. inv.InvStd,
  5200. log.Quantity,
  5201. inv.InvUnit,
  5202. log.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  5203. inv.AmountUnit,
  5204. {1}
  5205. ext.ProjectCode,
  5206. 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,
  5207. ext.Version,
  5208. ext.Brand,
  5209. ext.cFree1,
  5210. ext.cFree2,
  5211. ext.cFree3,
  5212. ext.cFree4,
  5213. ext.cFree5,
  5214. ext.cFree6,
  5215. ext.cFree7,
  5216. ext.cFree8,
  5217. ext.cFree9,
  5218. ext.cFree10,
  5219. type.Name AS TransType,
  5220. log.MUSER AS [User],
  5221. log.MTIME AS [MTime]
  5222. FROM ICSWareHouseLotInfoLog log
  5223. LEFT JOIN ICSType type ON type.TableCode='ICSWareHouseLotInfoLog' AND type.ColumnCode='BusinessCode' AND log.BusinessCode=type.Code AND log.WorkPoint=type.WorkPoint
  5224. INNER JOIN ICSInventoryLot lot ON log.LotNo=lot.LotNo AND log.WorkPoint=lot.WorkPoint
  5225. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  5226. INNER JOIN ICSInventory inv ON log.InvCode=inv.InvCode AND log.WorkPoint=inv.WorkPoint
  5227. {2}
  5228. LEFT JOIN ICSInventoryBatchEnable invBat ON log.InvCode=invBat.InvCode AND log.FromWarehouseCode=invBat.WHCode AND log.WorkPoint=invBat.WorkPoint
  5229. WHERE log.Identification='{0}'";
  5230. #endregion
  5231. string columns = @"log.ToWarehouseCode AS WHCode,
  5232. log.ToLocationCode AS LocationCode,
  5233. wh.WarehouseName AS WHName,
  5234. loc.LocationName AS LocationName,";
  5235. string tables = @"INNER JOIN ICSWarehouse wh ON log.ToWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  5236. INNER JOIN ICSLocation loc ON log.ToLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  5237. if (type == 2)//出库
  5238. {
  5239. columns = @"log.FromWarehouseCode AS WHCode,
  5240. log.FromLocationCode AS LocationCode,
  5241. wh.WarehouseName AS WHName,
  5242. loc.LocationName AS LocationName,";
  5243. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  5244. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  5245. }
  5246. else if (type == 3)//调拨
  5247. {
  5248. columns = @"log.FromWarehouseCode AS FromWHCode,
  5249. log.FromLocationCode,
  5250. wh.WarehouseName AS FromWHName,
  5251. loc.LocationName AS FromLocationName,
  5252. log.ToWarehouseCode AS ToWHCode,
  5253. log.ToLocationCode,
  5254. whto.WarehouseName AS ToWHName,
  5255. locto.LocationName AS ToLocationName,";
  5256. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  5257. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint
  5258. INNER JOIN ICSWarehouse whto ON log.ToWarehouseCode=whto.WarehouseCode AND log.WorkPoint=whto.WorkPoint
  5259. INNER JOIN ICSLocation locto ON log.ToLocationCode=locto.LocationCode AND log.WorkPoint=locto.WorkPoint";
  5260. }
  5261. sql = string.Format(sql, Identification, columns, tables);
  5262. return DBHelper.SQlReturnData(sql, cmd);
  5263. }
  5264. /// <summary>
  5265. /// 先进先出批次管控
  5266. /// </summary>
  5267. /// <param name="LotNo"></param>
  5268. /// <param name="WorkPoitCode"></param>
  5269. /// <param name="cmd"></param>
  5270. /// <returns></returns>
  5271. public static string CanOut(string LotNo, string WorkPoitCode, string ScanLotCode, SqlCommand cmd, Dictionary<string, string> language)
  5272. {
  5273. try
  5274. {
  5275. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  5276. string sql = @"DECLARE @CountNO INT,@Days INT
  5277. SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
  5278. SET @CountNO=(
  5279. SELECT COUNT(a.LotNO) FROM ICSWareHouseLotInfo a
  5280. INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO AND a.WorkPoint=b.WorkPoint
  5281. WHERE a.WorkPoint='{1}' AND ISNULL(a.Quantity,0)>0 AND 1=1
  5282. AND CONVERT(varchar(100), a.InDate, 23)<
  5283. (SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), x.InDate, 23)) FROM ICSWareHouseLotInfo x
  5284. INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
  5285. WHERE x.LotNO='{0}' AND x.WorkPoint='{1}' AND y.INVCode=b.INVCode AND y.ExtensionID=b.ExtensionID)
  5286. )
  5287. IF @CountNO>0
  5288. BEGIN
  5289. SELECT TOP 1 CASE a.F_ItemCode WHEN 'FIFO01' THEN '1' WHEN 'FIFO02' THEN '2' ELSE '3' END AS Type
  5290. FROM Sys_SRM_ItemsDetail a
  5291. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  5292. WHERE b.F_EnCode='FIFO' AND a.F_EnabledMark='1'
  5293. ORDER BY a.F_SortCode DESC
  5294. END
  5295. ELSE
  5296. BEGIN
  5297. SELECT @CountNO
  5298. END";
  5299. //0 - 已经是最早的批次
  5300. //1 - 不管控
  5301. //2 - 提醒
  5302. //3 - 限制
  5303. sql = string.Format(sql, LotNo, WorkPoitCode);
  5304. if (!string.IsNullOrWhiteSpace(ScanLotCode))
  5305. {
  5306. sql = sql.Replace("1=1", "a.LotNO NOT IN (" + ScanLotCode + ")");
  5307. }
  5308. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5309. if (string.IsNullOrWhiteSpace(res))
  5310. {
  5311. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  5312. }
  5313. else
  5314. return res;
  5315. }
  5316. catch (Exception ex)
  5317. {
  5318. throw new Exception(ex.Message);
  5319. }
  5320. }
  5321. /// <summary>
  5322. /// 保质期管控
  5323. /// </summary>
  5324. /// <param name="LotNo"></param>
  5325. /// <param name="WorkPoitCode"></param>
  5326. /// <param name="cmd"></param>
  5327. /// <returns></returns>
  5328. public static string Effective(string LotNo, string WorkPoitCode, SqlCommand cmd, Dictionary<string, string> language)
  5329. {
  5330. try
  5331. {
  5332. string sql = @"DECLARE @CountNO INT,@Days INT,@CurrentDays INT
  5333. SELECT @CountNO=EffectiveEnable,@Days=EffectiveDays,@CurrentDays=DATEDIFF(DAY, GETDATE(), b.ExpirationDate) FROM ICSInventory a
  5334. INNER JOIN ICSInventoryLot b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  5335. INNER JOIN ICSWareHouseLotInfo c ON b.LotNO=c.LotNO AND b.WorkPoint=c.WorkPoint
  5336. WHERE b.LotNO='{0}' AND b.WorkPoint='{1}'
  5337. IF @CountNO='1' AND @CurrentDays<0
  5338. BEGIN
  5339. SELECT TOP 1 CASE a.F_ItemCode WHEN 'Effective01' THEN '1' WHEN 'Effective02' THEN '2' ELSE '3' END AS Type
  5340. FROM Sys_SRM_ItemsDetail a
  5341. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  5342. WHERE b.F_EnCode='Effective' AND a.F_EnabledMark='1'
  5343. ORDER BY a.F_SortCode DESC
  5344. END
  5345. ELSE
  5346. BEGIN
  5347. SELECT @CountNO
  5348. END";
  5349. //0 - 已经是最早的批次
  5350. //1 - 不管控
  5351. //2 - 提醒
  5352. //3 - 限制
  5353. sql = string.Format(sql, LotNo, WorkPoitCode);
  5354. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5355. if (string.IsNullOrWhiteSpace(res))
  5356. {
  5357. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  5358. }
  5359. else
  5360. return res;
  5361. }
  5362. catch (Exception ex)
  5363. {
  5364. throw new Exception(ex.Message);
  5365. }
  5366. }
  5367. #region 包装
  5368. /// <summary>
  5369. /// 查询包装信息
  5370. /// </summary>
  5371. /// <param name="JsonData"></param>
  5372. /// <returns></returns>
  5373. public static object ContainerGet(ICSContainer JsonData)
  5374. {
  5375. var language = LanguageHelper.GetName("WMSAPIInfo");
  5376. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5377. {
  5378. conn.Open();
  5379. SqlTransaction sqlTran = conn.BeginTransaction();
  5380. SqlCommand cmd = new SqlCommand();
  5381. cmd.Transaction = sqlTran;
  5382. cmd.Connection = conn;
  5383. try
  5384. {
  5385. string sql = string.Empty;
  5386. //目标包装
  5387. if (JsonData.ToContainerCode != null)
  5388. {
  5389. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  5390. BEGIN
  5391. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  5392. RETURN
  5393. END
  5394. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  5395. sql = string.Format(sql, JsonData.ToContainerCode, JsonData.WorkPoint);
  5396. }
  5397. ///原包装
  5398. else if (JsonData.FromContainerCode != null)
  5399. {
  5400. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  5401. BEGIN
  5402. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  5403. RETURN
  5404. END
  5405. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  5406. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  5407. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  5408. BEGIN
  5409. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  5410. RETURN
  5411. END
  5412. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  5413. sql = string.Format(sql, JsonData.FromContainerCode, JsonData.WorkPoint);
  5414. }
  5415. else
  5416. {
  5417. throw new Exception(language.GetNameByCode("WMSAPIInfo029"));//"请传入包装条码!");
  5418. }
  5419. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  5420. cmd.Transaction.Commit();
  5421. return table;
  5422. }
  5423. catch (Exception ex)
  5424. {
  5425. if (cmd.Transaction != null)
  5426. cmd.Transaction.Rollback();
  5427. log.Error(ex.Message);
  5428. throw new Exception(ex.Message);
  5429. }
  5430. finally
  5431. {
  5432. if (conn.State == ConnectionState.Open)
  5433. {
  5434. conn.Close();
  5435. }
  5436. conn.Dispose();
  5437. }
  5438. }
  5439. }
  5440. /// <summary>
  5441. /// 修改包装信息
  5442. /// </summary>
  5443. /// <param name="JsonData"></param>
  5444. /// <returns></returns>
  5445. public static DataTable ContainerUpdate(List<ICSContainer> JsonData)
  5446. {
  5447. var language = LanguageHelper.GetName("WMSAPIInfo");
  5448. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5449. {
  5450. conn.Open();
  5451. SqlTransaction sqlTran = conn.BeginTransaction();
  5452. SqlCommand cmd = new SqlCommand();
  5453. cmd.Transaction = sqlTran;
  5454. cmd.Connection = conn;
  5455. try
  5456. {
  5457. string sql = string.Empty;
  5458. string codes = string.Empty;
  5459. foreach (ICSContainer container in JsonData)
  5460. {
  5461. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  5462. BEGIN
  5463. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  5464. RETURN
  5465. END
  5466. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  5467. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  5468. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  5469. BEGIN
  5470. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  5471. RETURN
  5472. END
  5473. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{2}' and WorkPoint='{1}')
  5474. BEGIN
  5475. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  5476. RETURN
  5477. END
  5478. UPDATE b SET ContainerID=c.ID
  5479. FROM ICSContainer a
  5480. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  5481. INNER JOIN ICSContainer c ON c.ContainerCODE ='{2}' and a.WorkPoint=c.WorkPoint
  5482. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}'";
  5483. sql = string.Format(sql, container.FromContainerCode, container.WorkPoint, container.ToContainerCode);
  5484. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5485. {
  5486. throw new Exception(language.GetNameByCode("WMSAPIInfo030"));//"包装更新失败!");
  5487. }
  5488. codes += "'" + container.ToContainerCode + container.WorkPoint + "',";
  5489. }
  5490. sql = @"SELECT a.ContainerCode, a.ContainerName,b.LotNo FROM ICSContainer a
  5491. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  5492. WHERE a.ContainerCODE+a.WorkPoint IN({0})";
  5493. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  5494. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  5495. cmd.Transaction.Commit();
  5496. return table;
  5497. }
  5498. catch (Exception ex)
  5499. {
  5500. if (cmd.Transaction != null)
  5501. cmd.Transaction.Rollback();
  5502. log.Error(ex.Message);
  5503. throw new Exception(ex.Message);
  5504. }
  5505. finally
  5506. {
  5507. if (conn.State == ConnectionState.Open)
  5508. {
  5509. conn.Close();
  5510. }
  5511. conn.Dispose();
  5512. }
  5513. }
  5514. }
  5515. #endregion
  5516. #region 盘点
  5517. /// <summary>
  5518. /// 创建盘点单
  5519. /// </summary>
  5520. /// <param name="JsonData"></param>
  5521. /// <returns></returns>
  5522. public static DataTable CheckCreate(List<ICSCheck> JsonData)
  5523. {
  5524. var language = LanguageHelper.GetName("WMSAPIInfo");
  5525. if (JsonData.Count <= 0)
  5526. {
  5527. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5528. }
  5529. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5530. {
  5531. conn.Open();
  5532. SqlTransaction sqlTran = conn.BeginTransaction();
  5533. SqlCommand cmd = new SqlCommand();
  5534. cmd.Transaction = sqlTran;
  5535. cmd.Connection = conn;
  5536. try
  5537. {
  5538. string Code = string.Empty;
  5539. string sql = string.Empty;
  5540. foreach (var item in JsonData)
  5541. {
  5542. if (string.IsNullOrEmpty(item.User))
  5543. {
  5544. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  5545. }
  5546. if (string.IsNullOrEmpty(item.WorkPoint))
  5547. {
  5548. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  5549. }
  5550. //获取单号
  5551. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  5552. BEGIN
  5553. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  5554. RETURN
  5555. END
  5556. DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  5557. SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck
  5558. WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date
  5559. IF @MaxNO IS NULL
  5560. BEGIN
  5561. SELECT @date+'00001' AS Code
  5562. END
  5563. ELSE
  5564. BEGIN
  5565. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  5566. END ";
  5567. sql = string.Format(sql, item.User, item.WorkPoint);
  5568. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5569. //创建盘点单
  5570. foreach (var itemInfo in item.detail)
  5571. {
  5572. int len = itemInfo.SelectLevel.Length;
  5573. sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE SUBSTRING(LocationCode,1,{4}) = '{1}')
  5574. BEGIN
  5575. RAISERROR('" + language.GetNameByCode("WMSAPIInfo460") + @"',16,1);
  5576. RETURN
  5577. END
  5578. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint)
  5579. SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location
  5580. FROM ICSWareHouseLotInfo a
  5581. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5582. WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
  5583. GROUP BY b.F_Account,b.F_RealName,b.F_Location";
  5584. sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len);
  5585. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5586. {
  5587. throw new Exception(language.GetNameByCode("WMSAPIInfo031"));//"盘点单创建失败!");
  5588. }
  5589. }
  5590. }
  5591. if (string.IsNullOrWhiteSpace(Code))
  5592. {
  5593. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单单号不能为空!");
  5594. }
  5595. #region 查询返回数据
  5596. sql = @"SELECT a.ID,a.CheckCode,a.SelectLevel,
  5597. a.Quantity,
  5598. a.Amount,
  5599. a.MUSER AS [User],
  5600. a.MTIME AS [MTime]
  5601. FROM ICSCheck a
  5602. WHERE a.CheckCode='{0}'";
  5603. sql = string.Format(sql, Code);
  5604. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5605. #endregion
  5606. cmd.Transaction.Commit();
  5607. return data;
  5608. }
  5609. catch (Exception ex)
  5610. {
  5611. if (cmd.Transaction != null)
  5612. cmd.Transaction.Rollback();
  5613. log.Error(ex.Message);
  5614. throw new Exception(ex.Message);
  5615. }
  5616. finally
  5617. {
  5618. if (conn.State == ConnectionState.Open)
  5619. {
  5620. conn.Close();
  5621. }
  5622. conn.Dispose();
  5623. }
  5624. }
  5625. }
  5626. /// <summary>
  5627. /// 盘点扫描
  5628. /// </summary>
  5629. /// <param name="JsonData"></param>
  5630. /// <returns></returns>
  5631. public static DataTable LOTCheckCreate(List<ICSCheck> JsonData)
  5632. {
  5633. var language = LanguageHelper.GetName("WMSAPIInfo");
  5634. if (JsonData.Count <= 0)
  5635. {
  5636. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5637. }
  5638. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5639. {
  5640. conn.Open();
  5641. SqlTransaction sqlTran = conn.BeginTransaction();
  5642. SqlCommand cmd = new SqlCommand();
  5643. cmd.Transaction = sqlTran;
  5644. cmd.Connection = conn;
  5645. try
  5646. {
  5647. string lots = string.Empty;
  5648. string sql = string.Empty;
  5649. int result = 0;
  5650. string Identification = Guid.NewGuid().ToString();
  5651. foreach (var item in JsonData)
  5652. {
  5653. if (string.IsNullOrEmpty(item.User))
  5654. {
  5655. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  5656. }
  5657. if (string.IsNullOrEmpty(item.WorkPoint))
  5658. {
  5659. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  5660. }
  5661. if (string.IsNullOrEmpty(item.CheckCode))
  5662. {
  5663. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单号不能为空!");
  5664. }
  5665. //校验
  5666. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  5667. BEGIN
  5668. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  5669. RETURN
  5670. END
  5671. IF NOT EXISTS(SELECT ID FROM ICSCheck WHERE CheckCode='{2}' AND WorkPoint='{1}')
  5672. BEGIN
  5673. RAISERROR('" + language.GetNameByCode("WMSAPIInfo075") + @"',16,1);
  5674. RETURN
  5675. END";
  5676. sql = string.Format(sql, item.User, item.WorkPoint, item.CheckCode);
  5677. DBHelper.ExecuteNonQuery(sql, cmd);
  5678. //创建盘点单
  5679. foreach (var itemInfo in item.detail)
  5680. {
  5681. sql = @"IF NOT EXISTS(SELECT LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{1}' AND WorkPoint='{3}')
  5682. BEGIN
  5683. RAISERROR('" + language.GetNameByCode("WMSAPIInfo076") + @"',16,1);
  5684. RETURN
  5685. END
  5686. IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  5687. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  5688. WHERE b.CheckCode='{0}' AND a.LotNo='{1}' AND a.WorkPoint='{3}')
  5689. BEGIN
  5690. IF ('{5}'='')
  5691. BEGIN
  5692. UPDATE a SET PrimaryQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  5693. FROM ICSCheckDetail a
  5694. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5695. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  5696. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  5697. END
  5698. ELSE IF ('{5}'='')
  5699. BEGIN
  5700. UPDATE a SET CheckQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  5701. FROM ICSCheckDetail a
  5702. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5703. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  5704. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  5705. END
  5706. ELSE
  5707. BEGIN
  5708. UPDATE a SET ReplayQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  5709. FROM ICSCheckDetail a
  5710. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5711. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  5712. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  5713. END
  5714. END
  5715. ELSE
  5716. BEGIN
  5717. IF ('{5}'='')
  5718. BEGIN
  5719. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  5720. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','{4}','0','0','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  5721. FROM ICSWareHouseLotInfo a
  5722. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5723. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  5724. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  5725. END
  5726. ELSE IF ('{5}'='')
  5727. BEGIN
  5728. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  5729. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','0','0','{4}','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  5730. FROM ICSWareHouseLotInfo a
  5731. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5732. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  5733. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  5734. END
  5735. ELSE
  5736. BEGIN
  5737. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  5738. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','{4}','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  5739. FROM ICSWareHouseLotInfo a
  5740. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5741. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  5742. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  5743. END
  5744. END";
  5745. sql = string.Format(sql, item.CheckCode, itemInfo.LotNo, item.User, item.WorkPoint, itemInfo.ActualQuantity, item.CheckKind);
  5746. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5747. {
  5748. throw new Exception(language.GetNameByCode("WMSAPIInfo033"));//"盘点扫描创建失败!");
  5749. }
  5750. #region 更新ICSCheckDetail表
  5751. //string strSql = @"UPDATE ICSCheckDetail Set";
  5752. //if (item.CheckKind == "初盘")
  5753. // strSql += @" PrimaryQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  5754. //else if (item.CheckKind == "复盘")
  5755. // strSql += @" ReplayQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  5756. //else
  5757. // strSql += @" CheckQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  5758. //strSql += @" where ToCheckNO='" + item.CheckCode + "' AND WorkPoint='" + item.WorkPoint + "'";
  5759. //cmd.CommandText = strSql;
  5760. //result = cmd.ExecuteNonQuery();
  5761. //if (result <= 0)
  5762. //{
  5763. // throw new Exception(language.GetNameByCode("WMSAPIInfo296"));//"盘点子表数量增加失败!");
  5764. //}
  5765. #endregion
  5766. #region 更新库存
  5767. if (item.UpdateWHLI)
  5768. {
  5769. ICSWareHouseLotInfoService.WareHouseLotInfoUpdate(Identification, item.CheckCode, "", itemInfo.LotNo, itemInfo.ActualQuantity, item.User, item.WorkPoint, TransTypeEnum.Check.GetDescription<DBValue>(), item.CheckKind, cmd, language);
  5770. }
  5771. #endregion
  5772. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  5773. }
  5774. if (string.IsNullOrWhiteSpace(lots))
  5775. {
  5776. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  5777. }
  5778. //sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  5779. // FROM ICSCheck a
  5780. // 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
  5781. // WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  5782. //sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  5783. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5784. //{
  5785. // throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  5786. //}
  5787. }
  5788. #region 查询返回数据
  5789. sql = @"SELECT x.ID,x.CheckID,y.WarehouseCode AS WHCode,x.LotNo,
  5790. y.InvCode,
  5791. inv.InvName,
  5792. inv.InvStd,
  5793. x.Quantity,x.PrimaryQuantity,x.PrimaryAmount,x.ReplayQuantity,x.ReplayAmount,x.CheckQuantity,x.CheckAmount,
  5794. inv.InvUnit,
  5795. x.MUSER AS [User],
  5796. x.MTIME AS [MTime]
  5797. FROM ICSCheckDetail x
  5798. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  5799. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  5800. WHERE x.LotNo+x.WorkPoint IN ({0})";
  5801. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  5802. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5803. #endregion
  5804. cmd.Transaction.Commit();
  5805. return data;
  5806. }
  5807. catch (Exception ex)
  5808. {
  5809. if (cmd.Transaction != null)
  5810. cmd.Transaction.Rollback();
  5811. log.Error(ex.Message);
  5812. throw new Exception(ex.Message);
  5813. }
  5814. finally
  5815. {
  5816. if (conn.State == ConnectionState.Open)
  5817. {
  5818. conn.Close();
  5819. }
  5820. conn.Dispose();
  5821. }
  5822. }
  5823. }
  5824. #endregion
  5825. #region 多语言
  5826. /// <summary>
  5827. /// 多语言查询
  5828. /// </summary>
  5829. /// <param name="JsonData"></param>
  5830. /// <returns></returns>
  5831. public static DataTable PromptInformationGet(WMSBarCoreModel JsonData)
  5832. {
  5833. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5834. {
  5835. conn.Open();
  5836. SqlCommand cmd = new SqlCommand();
  5837. cmd.Connection = conn;
  5838. try
  5839. {
  5840. string DefiniteLanguage = ICSDefiniteLanguageService.GetLanguage();
  5841. string sql = @"select " + DefiniteLanguage + " AS Name,Code from Sys_Language where 1=1";
  5842. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  5843. {
  5844. sql += " and Code LIKE '%{0}%'";
  5845. }
  5846. sql = string.Format(sql, JsonData.Code);
  5847. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5848. return data;
  5849. }
  5850. catch (Exception ex)
  5851. {
  5852. log.Error(ex.Message);
  5853. throw new Exception(ex.Message);
  5854. }
  5855. finally
  5856. {
  5857. if (conn.State == ConnectionState.Open)
  5858. {
  5859. conn.Close();
  5860. }
  5861. conn.Dispose();
  5862. }
  5863. }
  5864. }
  5865. #endregion
  5866. #region 仓库/库位
  5867. /// <summary>
  5868. /// 仓库/库位
  5869. /// </summary>
  5870. /// <param name="JsonData"></param>
  5871. /// <returns></returns>
  5872. public static DataTable LocationGet(ICSLocation JsonData)
  5873. {
  5874. var language = LanguageHelper.GetName("WMSAPIInfo");
  5875. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5876. {
  5877. conn.Open();
  5878. SqlTransaction sqlTran = conn.BeginTransaction();
  5879. SqlCommand cmd = new SqlCommand();
  5880. cmd.Transaction = sqlTran;
  5881. cmd.Connection = conn;
  5882. try
  5883. {
  5884. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode='{0}' AND a.WorkPoint='{1}')
  5885. BEGIN
  5886. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  5887. RETURN
  5888. END
  5889. 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}')
  5890. BEGIN
  5891. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  5892. RETURN
  5893. END
  5894. 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')
  5895. BEGIN
  5896. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  5897. RETURN
  5898. END
  5899. SELECT
  5900. LocationCode,
  5901. LocationName ,
  5902. WarehouseCode,
  5903. WarehouseName
  5904. FROM ICSLocation a
  5905. 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'";
  5906. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  5907. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5908. cmd.Transaction.Commit();
  5909. return data;
  5910. }
  5911. catch (Exception ex)
  5912. {
  5913. if (cmd.Transaction != null)
  5914. cmd.Transaction.Rollback();
  5915. log.Error(ex.Message);
  5916. throw new Exception(ex.Message);
  5917. }
  5918. finally
  5919. {
  5920. if (conn.State == ConnectionState.Open)
  5921. {
  5922. conn.Close();
  5923. }
  5924. conn.Dispose();
  5925. }
  5926. }
  5927. }
  5928. #endregion
  5929. #region 登陆
  5930. public static object CheckLogin(Sys_SRM_User userModel)
  5931. {
  5932. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5933. {
  5934. conn.Open();
  5935. SqlCommand cmd = new SqlCommand();
  5936. cmd.Connection = conn;
  5937. try
  5938. {
  5939. string sql = @"select F_Account from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  5940. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  5941. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  5942. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  5943. {
  5944. sql = @" select a.[F_Id] as UserId
  5945. ,[F_Account] as userCode
  5946. ,[F_RealName] as UserName
  5947. ,[F_NickName]
  5948. ,b.F_UserPassword
  5949. ,b.F_UserSecretkey
  5950. ,[F_HeadIcon]
  5951. ,[F_Gender]
  5952. ,[F_Birthday]
  5953. ,[F_MobilePhone]
  5954. ,[F_Email]
  5955. ,[F_WeChat]
  5956. ,[F_ManagerId]
  5957. ,[F_SecurityLevel]
  5958. ,[F_Signature]
  5959. ,[F_OrganizeId]
  5960. ,[F_DepartmentId]
  5961. ,[F_RoleId]
  5962. ,[F_DutyId]
  5963. ,[F_IsAdministrator]
  5964. ,[F_SortCode]
  5965. ,[F_DeleteMark]
  5966. ,[F_EnabledMark]
  5967. ,[F_Description]
  5968. ,[F_CreatorTime]
  5969. ,[F_CreatorUserId]
  5970. ,[F_LastModifyTime]
  5971. ,[F_LastModifyUserId]
  5972. ,[F_DeleteTime]
  5973. ,[F_DeleteUserId]
  5974. ,[F_Location] as WorkPoint
  5975. ,[F_VenCode]
  5976. from Sys_SRM_User a
  5977. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  5978. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  5979. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  5980. dt = DBHelper.SQlReturnData(sql, cmd);
  5981. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  5982. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  5983. foreach (var item in users)
  5984. {
  5985. //string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
  5986. string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  5987. if (dbPassword == item.F_UserPassword)
  5988. {
  5989. string json = JsonConvert.SerializeObject(dt);
  5990. List<Sys_SRM_User> userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  5991. return userLogOnEntity;
  5992. }
  5993. else
  5994. {
  5995. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI004"));//"密码不正确,请重新输入");
  5996. }
  5997. }
  5998. }
  5999. else
  6000. {
  6001. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI005"));//"用户名不存在,请重新输入!");
  6002. }
  6003. return null;
  6004. }
  6005. catch (Exception ex)
  6006. {
  6007. log.Error(ex.Message);
  6008. throw new Exception(ex.Message);
  6009. }
  6010. finally
  6011. {
  6012. if (conn.State == ConnectionState.Open)
  6013. {
  6014. conn.Close();
  6015. }
  6016. conn.Dispose();
  6017. }
  6018. }
  6019. }
  6020. #endregion
  6021. #region 获取调拨单
  6022. /// <summary>
  6023. /// 获取未发,未发完调拨单
  6024. /// </summary>
  6025. /// <param name="JsonData"></param>
  6026. /// <returns></returns>
  6027. public static DataTable TransCodemationGet(TransferDoc JsonData)
  6028. {
  6029. var language = LanguageHelper.GetName("WMSAPIInfo");
  6030. if (JsonData == null)
  6031. {
  6032. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6033. }
  6034. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6035. {
  6036. conn.Open();
  6037. SqlTransaction sqlTran = conn.BeginTransaction();
  6038. SqlCommand cmd = new SqlCommand();
  6039. cmd.Transaction = sqlTran;
  6040. cmd.Connection = conn;
  6041. try
  6042. {
  6043. string Workpoint = "";
  6044. Workpoint = JsonData.WorkPoint;
  6045. string sql = @"SELECT DISTINCT TransferNO as TransCode FROM ICSTransferApplication
  6046. WHERE WorkPoint='{0}' AND Quantity>ISNULL(TransferQuantity, 0) order by TransferNO desc";
  6047. sql = string.Format(sql, Workpoint);
  6048. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  6049. return table;
  6050. }
  6051. catch (Exception ex)
  6052. {
  6053. if (cmd.Transaction != null)
  6054. cmd.Transaction.Rollback();
  6055. log.Error(ex.Message);
  6056. throw new Exception(ex.Message);
  6057. }
  6058. finally
  6059. {
  6060. if (conn.State == ConnectionState.Open)
  6061. {
  6062. conn.Close();
  6063. }
  6064. conn.Dispose();
  6065. }
  6066. }
  6067. }
  6068. #endregion
  6069. #region 料架条码绑定/解绑
  6070. /// <summary>
  6071. /// 料架条码绑定
  6072. /// </summary>
  6073. /// <param name="JsonData"></param>
  6074. /// <returns></returns>
  6075. public static Result ContainerBindCreate(List<ICSContainerBind> JsonData)
  6076. {
  6077. var language = LanguageHelper.GetName("WMSAPIInfo");
  6078. DataTable table = new DataTable();
  6079. string msg = "";
  6080. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6081. {
  6082. conn.Open();
  6083. SqlCommand cmd = new SqlCommand();
  6084. cmd.Connection = conn;
  6085. try
  6086. {
  6087. Result res = new Result();
  6088. foreach (ICSContainerBind item in JsonData)
  6089. {
  6090. string TransType = item.TransType;
  6091. if (JsonData.Count <= 0)
  6092. {
  6093. msg = string.Format(language.GetNameByCode("WMSAPIInfo007"));//"传入数据为空!"
  6094. }
  6095. if (String.IsNullOrEmpty(item.WorkPoint))
  6096. {
  6097. msg = string.Format(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  6098. }
  6099. if (String.IsNullOrEmpty(item.LotNo))
  6100. {
  6101. msg = string.Format(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  6102. }
  6103. if (String.IsNullOrEmpty(item.ContainerCode))
  6104. {
  6105. msg = string.Format(language.GetNameByCode("WMSAPIInfo197"));//"料架不能为空!"
  6106. }
  6107. if (TransType != TransTypeEnum.ContainerBind.GetDescription() && TransType != TransTypeEnum.ContainerUnBind.GetDescription())
  6108. {
  6109. msg = string.Format(language.GetNameByCode("WMSAPIInfo199"));//"操作类型错误!"
  6110. }
  6111. if (item.ContainerType == "窄巷道叉车(木托盘)" && item.LocationCode == "")
  6112. {
  6113. msg = string.Format(language.GetNameByCode("WMSAPIInfo203"));//"推荐库位不能为空!"
  6114. }
  6115. if (msg != "")
  6116. {
  6117. res.Success = false;
  6118. res.Message = msg;// "接口调用失败!";
  6119. return res;
  6120. }
  6121. else
  6122. {
  6123. if (TransType == TransTypeEnum.ContainerBind.GetDescription())
  6124. {
  6125. //料架条码绑定
  6126. ICSWareHouseLotInfoService.ContainerBind(item.LotNo, item.ContainerCode, item.ContainerType, item.User, item.WorkPoint, cmd, language);
  6127. }
  6128. else
  6129. {
  6130. //料架条码解绑
  6131. ICSWareHouseLotInfoService.ContainerUnBind(item.ContainerCode, item.WorkPoint, cmd, language);
  6132. }
  6133. }
  6134. }
  6135. res.Success = true;
  6136. res.Message = msg;// "接口调用成功!";
  6137. return res;
  6138. }
  6139. catch (Exception ex)
  6140. {
  6141. log.Error(ex.Message);
  6142. throw new Exception(ex.Message);
  6143. }
  6144. finally
  6145. {
  6146. if (conn.State == ConnectionState.Open)
  6147. {
  6148. conn.Close();
  6149. }
  6150. conn.Dispose();
  6151. }
  6152. }
  6153. }
  6154. #endregion
  6155. }
  6156. }