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

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