纽威

7987 lines
444 KiB

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