纽威

7156 lines
399 KiB

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