纽威

8188 lines
457 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
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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
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
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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
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. DataTable table = new DataTable();
  2644. cmd.Transaction.Commit();
  2645. return table;
  2646. }
  2647. catch (Exception ex)
  2648. {
  2649. if (cmd.Transaction != null)
  2650. cmd.Transaction.Rollback();
  2651. log.Error(ex.Message);
  2652. throw new Exception(ex.Message);
  2653. }
  2654. finally
  2655. {
  2656. if (conn.State == ConnectionState.Open)
  2657. {
  2658. conn.Close();
  2659. }
  2660. conn.Dispose();
  2661. }
  2662. }
  2663. }
  2664. /// <summary>
  2665. /// 上架(货柜)
  2666. /// </summary>BusinessCode,TransType 两个类型
  2667. /// <param name="JsonData"></param>
  2668. /// <returns></returns>
  2669. public static DataTable LOTStockCreateHG(LOTStockUpHGModel JsonData)
  2670. {
  2671. var language = LanguageHelper.GetName("WMSAPIInfo");
  2672. if (JsonData == null)
  2673. {
  2674. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2675. }
  2676. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2677. {
  2678. conn.Open();
  2679. SqlTransaction sqlTran = conn.BeginTransaction();
  2680. SqlCommand cmd = new SqlCommand();
  2681. cmd.Transaction = sqlTran;
  2682. cmd.Connection = conn;
  2683. string BusinessCode = string.Empty;
  2684. try
  2685. {
  2686. string TransType = string.Empty;
  2687. string Identification = Guid.NewGuid().ToString();
  2688. TransType = JsonData.DATA.Head[0].TransType;
  2689. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  2690. {
  2691. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2692. }
  2693. string WHTransType = "2";
  2694. foreach (var itemInfo in JsonData.DATA.Detail)
  2695. {
  2696. #region 审核的到货单
  2697. if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  2698. {
  2699. //更新源头单据数量
  2700. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, JsonData.DATA.Head[0].WorkPoint, cmd, language);
  2701. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  2702. }
  2703. #endregion
  2704. else
  2705. {
  2706. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2707. }
  2708. //入库
  2709. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  2710. itemInfo.User, JsonData.DATA.Head[0].WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode, DateTime.Now.ToString());
  2711. }
  2712. //上传ERP
  2713. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2714. {
  2715. //审核的到货单
  2716. if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  2717. ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  2718. }
  2719. DataTable table = GetData(Identification, 1, cmd);
  2720. cmd.Transaction.Commit();
  2721. return table;
  2722. }
  2723. catch (Exception ex)
  2724. {
  2725. if (cmd.Transaction != null)
  2726. cmd.Transaction.Rollback();
  2727. log.Error(ex.Message);
  2728. throw new Exception(ex.Message);
  2729. }
  2730. finally
  2731. {
  2732. if (conn.State == ConnectionState.Open)
  2733. {
  2734. conn.Close();
  2735. }
  2736. conn.Dispose();
  2737. }
  2738. }
  2739. }
  2740. /// <summary>
  2741. /// 叉车出入库
  2742. /// </summary>BusinessCode,TransType 两个类型
  2743. /// <param name="JsonData"></param>
  2744. /// <returns></returns>
  2745. public static DataTable LOTStockChangeForkLift(LOTStockForkLiftModel JsonData)
  2746. {
  2747. var language = LanguageHelper.GetName("WMSAPIInfo");
  2748. if (JsonData == null)
  2749. {
  2750. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2751. }
  2752. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2753. {
  2754. conn.Open();
  2755. SqlTransaction sqlTran = conn.BeginTransaction();
  2756. SqlCommand cmd = new SqlCommand();
  2757. cmd.Transaction = sqlTran;
  2758. cmd.Connection = conn;
  2759. string BusinessCode = string.Empty;
  2760. try
  2761. {
  2762. string TransType = string.Empty;
  2763. string Identification = Guid.NewGuid().ToString();
  2764. TransType = JsonData.TaskType;
  2765. if (TransType == "PTWY")
  2766. {
  2767. //更新源头单据数量
  2768. ICSPurchaseService.DeliveryNoticeForkLift(JsonData.PalletID, cmd, language);
  2769. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  2770. //入库
  2771. ICSWareHouseLotInfoService.WareHouseLotInfoUpForkLift(Identification, JsonData.DestBin, JsonData.PalletID,
  2772. "叉车", "采购入库-采购到货单", "2", cmd, language);
  2773. }
  2774. //上传ERP
  2775. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2776. {
  2777. //审核的到货单
  2778. if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  2779. ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, "2");
  2780. }
  2781. DataTable table = GetData(Identification, 1, cmd);
  2782. cmd.Transaction.Commit();
  2783. return table;
  2784. }
  2785. catch (Exception ex)
  2786. {
  2787. if (cmd.Transaction != null)
  2788. cmd.Transaction.Rollback();
  2789. log.Error(ex.Message);
  2790. throw new Exception(ex.Message);
  2791. }
  2792. finally
  2793. {
  2794. if (conn.State == ConnectionState.Open)
  2795. {
  2796. conn.Close();
  2797. }
  2798. conn.Dispose();
  2799. }
  2800. }
  2801. }
  2802. /// <summary>
  2803. /// 下架
  2804. /// </summary>
  2805. /// <param name="JsonData"></param>
  2806. /// <returns></returns>
  2807. public static DataTable LOTStockDownCreate(List<LOTStockModel> JsonData)
  2808. {
  2809. String PrintEnable = "";
  2810. var language = LanguageHelper.GetName("WMSAPIInfo");
  2811. if (JsonData.Count <= 0)
  2812. {
  2813. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2814. }
  2815. List<LOTStockModelList> model = new List<LOTStockModelList>();
  2816. DataTable printTable = new DataTable();
  2817. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2818. {
  2819. conn.Open();
  2820. SqlTransaction sqlTran = conn.BeginTransaction();
  2821. SqlCommand cmd = new SqlCommand();
  2822. cmd.Transaction = sqlTran;
  2823. cmd.Connection = conn;
  2824. string BusinessCode = string.Empty;
  2825. try
  2826. {
  2827. string TransType = string.Empty;
  2828. string Identification = Guid.NewGuid().ToString();
  2829. string SAPGZCode = string.Empty;
  2830. foreach (var item in JsonData)
  2831. {
  2832. TransType = item.TransType;
  2833. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  2834. {
  2835. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2836. }
  2837. else if (string.IsNullOrEmpty(item.TransCode))
  2838. {
  2839. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2840. }
  2841. string[] trans = item.TransCode.Split('~');
  2842. string MergeID = "";
  2843. if (trans.Length == 2)
  2844. {
  2845. MergeID = trans[0];
  2846. item.TransCode = trans[1];
  2847. }
  2848. #region 采购退货
  2849. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2850. {
  2851. BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>();
  2852. //更新源头单据数量
  2853. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2854. foreach (var itemInfo in item.detail)
  2855. {
  2856. //出库
  2857. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2858. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language);
  2859. }
  2860. }
  2861. #endregion
  2862. #region 委外发料
  2863. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2864. {
  2865. BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>();
  2866. //更新源头单据数量
  2867. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2868. foreach (var itemInfo in item.detail)
  2869. {
  2870. //出库
  2871. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2872. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2873. }
  2874. }
  2875. #endregion
  2876. #region 委外退货
  2877. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2878. {
  2879. BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>();
  2880. //更新源头单据数量
  2881. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2882. foreach (var itemInfo in item.detail)
  2883. {
  2884. //出库
  2885. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2886. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language);
  2887. }
  2888. }
  2889. #endregion
  2890. #region 生产发料
  2891. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2892. {
  2893. BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription<DBValue>();
  2894. //更新源头单据数量
  2895. ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2896. foreach (var itemInfo in item.detail)
  2897. {
  2898. //出库
  2899. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2900. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2901. }
  2902. }
  2903. #endregion
  2904. #region 销售出库
  2905. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2906. {
  2907. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  2908. //更新源头单据数量
  2909. ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2910. foreach (var itemInfo in item.detail)
  2911. {
  2912. //出库
  2913. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2914. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2915. }
  2916. }
  2917. #endregion
  2918. #region 两步调出
  2919. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2920. {
  2921. BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>();
  2922. //更新源头单据数量
  2923. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2924. foreach (var itemInfo in item.detail)
  2925. {
  2926. //出库
  2927. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2928. item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, MergeID);
  2929. }
  2930. }
  2931. #endregion
  2932. #region 其他出库
  2933. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2934. {
  2935. BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription<DBValue>();
  2936. //更新源头单据数量
  2937. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2938. foreach (var itemInfo in item.detail)
  2939. {
  2940. //出库
  2941. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2942. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2943. }
  2944. }
  2945. #endregion
  2946. #region 领料申请单发料
  2947. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  2948. {
  2949. BusinessCode = TransTypeEnum.MOApply.GetDescription<DBValue>();
  2950. //更新源头单据数量
  2951. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2952. foreach (var itemInfo in item.detail)
  2953. {
  2954. //出库
  2955. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2956. item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  2957. }
  2958. }
  2959. #endregion
  2960. #region 领料申请单发料(不扫描条码)
  2961. else if (TransType == TransTypeEnum.MOApplyWithOutLot.GetDescription())
  2962. {
  2963. BusinessCode = TransTypeEnum.MOApplyWithOutLot.GetDescription<DBValue>();
  2964. //更新源头单据数量
  2965. ICSManufactureService.MOApplyWithOutLot(item.TransCode, item.WorkPoint, cmd, language);
  2966. ICSWareHouseLotInfoService.WareHouseLotInfoDownWithOutLot(Identification, item.TransCode, item.User, item.WorkPoint, "3"
  2967. , TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  2968. }
  2969. #endregion
  2970. #region 领料申请单确认(更新确认人员到单据)
  2971. else if (TransType == TransTypeEnum.MOApplyToSAP.GetDescription())
  2972. {
  2973. //记录过账人员编码到单据表的MUSERNAME字段
  2974. ICSManufactureService.MOApplySaveUser(item.TransCode, item.User, item.WorkPoint, cmd, language);
  2975. }
  2976. #endregion
  2977. #region 委外领料申请单发料
  2978. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  2979. {
  2980. BusinessCode = TransTypeEnum.OOApply.GetDescription<DBValue>();
  2981. //更新源头单据数量
  2982. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2983. foreach (var itemInfo in item.detail)
  2984. {
  2985. //出库
  2986. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2987. item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  2988. }
  2989. }
  2990. #endregion
  2991. #region 开立材料出库
  2992. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2993. {
  2994. BusinessCode = TransTypeEnum.MOIssue.GetDescription<DBValue>();
  2995. //更新源头单据数量
  2996. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2997. foreach (var itemInfo in item.detail)
  2998. {
  2999. //出库
  3000. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  3001. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  3002. }
  3003. }
  3004. #endregion
  3005. #region 开立委外材料出库
  3006. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  3007. {
  3008. BusinessCode = TransTypeEnum.OOIssue.GetDescription<DBValue>();
  3009. //更新源头单据数量
  3010. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  3011. foreach (var itemInfo in item.detail)
  3012. {
  3013. //出库
  3014. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  3015. item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  3016. }
  3017. }
  3018. #endregion
  3019. #region 开立红字入库单
  3020. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  3021. {
  3022. BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription<DBValue>();
  3023. //更新源头单据数量
  3024. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  3025. foreach (var itemInfo in item.detail)
  3026. {
  3027. //出库
  3028. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  3029. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language);
  3030. }
  3031. }
  3032. #endregion
  3033. #region 开立委外红字入库单
  3034. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  3035. {
  3036. BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>();
  3037. //更新源头单据数量
  3038. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  3039. foreach (var itemInfo in item.detail)
  3040. {
  3041. //出库
  3042. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  3043. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language);
  3044. }
  3045. }
  3046. #endregion
  3047. #region 借用
  3048. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  3049. {
  3050. BusinessCode = TransTypeEnum.BrrowDoc.GetDescription<DBValue>();
  3051. //更新源头单据数量
  3052. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  3053. foreach (var itemInfo in item.detail)
  3054. {
  3055. //出库
  3056. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  3057. item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  3058. }
  3059. }
  3060. #endregion
  3061. else
  3062. {
  3063. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  3064. }
  3065. #region 出库单据增加验证,整单全部出库之后删除所有跟单据关联的占料信息,解锁占料数量
  3066. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription()
  3067. || TransType == TransTypeEnum.MOApply.GetDescription() || TransType == TransTypeEnum.OOApply.GetDescription()
  3068. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() || TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  3069. {
  3070. ICSWareHouseLotInfoService.MaterialOccpyCancel(TransType, item.TransCode, item.WorkPoint, cmd, language);
  3071. }
  3072. #endregion
  3073. }
  3074. //上传ERP
  3075. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  3076. {
  3077. //采购退货
  3078. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  3079. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  3080. //委外发料
  3081. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  3082. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  3083. //委外退货
  3084. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  3085. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
  3086. //生产发料
  3087. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  3088. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  3089. //销售出库
  3090. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  3091. ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode);
  3092. //两步调出
  3093. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  3094. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
  3095. //其他出库
  3096. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  3097. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  3098. //领料申请单发料
  3099. if (TransType == TransTypeEnum.MOApply.GetDescription() || TransType == TransTypeEnum.MOApplyWithOutLot.GetDescription())
  3100. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  3101. //领料申请单发料(过账SAP)
  3102. if (TransType == TransTypeEnum.MOApplyToSAP.GetDescription())
  3103. ICSManufactureService.MOApplySAPGZ(JsonData[0].TransCode, JsonData[0].User, JsonData[0].WorkPoint, cmd, language);
  3104. //委外领料申请单发料
  3105. if (TransType == TransTypeEnum.OOApply.GetDescription())
  3106. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  3107. //开立材料出库
  3108. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  3109. ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  3110. //开立委外材料出库
  3111. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  3112. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  3113. //开立红字入库单
  3114. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  3115. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  3116. //开立委外红字入库单
  3117. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  3118. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  3119. //借用
  3120. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  3121. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
  3122. }
  3123. if (!printTable.Equals("{}"))
  3124. {
  3125. cmd.Transaction.Commit();
  3126. return printTable;
  3127. }
  3128. else
  3129. {
  3130. //DataTable table = GetData(Identification, 2, cmd);
  3131. DataTable table = new DataTable();
  3132. cmd.Transaction.Commit();
  3133. return table;
  3134. }
  3135. }
  3136. catch (Exception ex)
  3137. {
  3138. if (cmd.Transaction != null)
  3139. cmd.Transaction.Rollback();
  3140. log.Error(ex.Message);
  3141. throw new Exception(ex.Message);
  3142. }
  3143. finally
  3144. {
  3145. if (conn.State == ConnectionState.Open)
  3146. {
  3147. conn.Close();
  3148. }
  3149. conn.Dispose();
  3150. }
  3151. }
  3152. }
  3153. /// <summary>
  3154. /// 下架(货柜)
  3155. /// </summary>
  3156. /// <param name="JsonData"></param>
  3157. /// <returns></returns>
  3158. public static DataTable LOTStockDownHGCreate(LOTStockDownHGModel JsonData, object InputJson)
  3159. {
  3160. String PrintEnable = "";
  3161. var language = LanguageHelper.GetName("WMSAPIInfo");
  3162. if (JsonData == null)
  3163. {
  3164. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3165. }
  3166. List<LOTStockDownHGModel> model = new List<LOTStockDownHGModel>();
  3167. DataTable printTable = new DataTable();
  3168. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3169. {
  3170. conn.Open();
  3171. SqlTransaction sqlTran = conn.BeginTransaction();
  3172. SqlCommand cmd = new SqlCommand();
  3173. cmd.Transaction = sqlTran;
  3174. cmd.Connection = conn;
  3175. string BusinessCode = string.Empty;
  3176. try
  3177. {
  3178. string TransType = string.Empty;
  3179. string Identification = Guid.NewGuid().ToString();
  3180. string SAPGZCode = string.Empty;
  3181. TransType = JsonData.DATA.EXP_ORDINI[0].ORD_DES;
  3182. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  3183. {
  3184. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  3185. }
  3186. else if (string.IsNullOrEmpty(JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE))
  3187. {
  3188. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3189. }
  3190. string[] trans = JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE.Split('~');
  3191. string MergeID = "";
  3192. if (trans.Length == 2)
  3193. {
  3194. MergeID = trans[0];
  3195. JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE = trans[1];
  3196. }
  3197. #region 审核的到货单
  3198. if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  3199. {
  3200. foreach (var itemInfo in JsonData.DATA.EXP_ORDINI_RIGHE_STO)
  3201. {
  3202. //更新源头单据数量
  3203. ICSPurchaseService.DeliveryNoticeInForHG(JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, itemInfo.STO_HOSTINF, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, cmd, language);
  3204. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  3205. //生成条码的同时入库
  3206. ICSWareHouseLotInfoService.WareHouseLotInfoUpForHG(Identification, JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, itemInfo.STO_HOSTINF
  3207. , itemInfo.STO_EFF_ARTICOLO, itemInfo.STO_EFF_QTA,
  3208. itemInfo.STO_EXE_OPERATORE, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, itemInfo.STO_CORRIDOIO, "2", BusinessCode, cmd, language);
  3209. }
  3210. }
  3211. #endregion
  3212. #region 开立的生产入库单
  3213. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  3214. {
  3215. foreach (var itemInfo in JsonData.DATA.EXP_ORDINI_RIGHE_STO)
  3216. {
  3217. //更新源头单据数量
  3218. ICSManufactureService.ManufactureReceiveForHG(JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, itemInfo.STO_HOSTINF, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, cmd, language);
  3219. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  3220. //入库
  3221. ICSWareHouseLotInfoService.WareHouseLotInfoUpForHG(Identification, JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, itemInfo.STO_HOSTINF
  3222. , itemInfo.STO_EFF_ARTICOLO, itemInfo.STO_EFF_QTA,
  3223. itemInfo.STO_EXE_OPERATORE, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, itemInfo.STO_CORRIDOIO, "2", BusinessCode, cmd, language);
  3224. }
  3225. }
  3226. #endregion
  3227. #region 生产退料
  3228. else if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  3229. {
  3230. foreach (var itemInfo in JsonData.DATA.EXP_ORDINI_RIGHE_STO)
  3231. {
  3232. //更新源头单据数量
  3233. ICSManufactureService.MOIssueDocNegativeHG(JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, itemInfo.STO_HOSTINF, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, cmd, language);
  3234. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  3235. //入库
  3236. ICSWareHouseLotInfoService.WareHouseLotInfoUpForHG(Identification, JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, itemInfo.STO_HOSTINF
  3237. , itemInfo.STO_EFF_ARTICOLO, itemInfo.STO_EFF_QTA,
  3238. itemInfo.STO_EXE_OPERATORE, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, itemInfo.STO_CORRIDOIO, "2", BusinessCode, cmd, language);
  3239. }
  3240. }
  3241. #endregion
  3242. #region 采购退货
  3243. else if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  3244. {
  3245. BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>();
  3246. //更新源头单据数量
  3247. ICSPurchaseService.PurchaseReceiveDoctNegativeHG(JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, cmd, language);
  3248. //出库
  3249. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDownHG(Identification, JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, JsonData.DATA.EXP_ORDINI_RIGHE_STO[0].STO_EXE_OPERATORE
  3250. , JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language);
  3251. }
  3252. #endregion
  3253. #region 领料申请单发料
  3254. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  3255. {
  3256. BusinessCode = TransTypeEnum.MOApply.GetDescription<DBValue>();
  3257. //更新源头单据数量
  3258. ICSManufactureService.MOApplyHG(JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, cmd, language);
  3259. //出库
  3260. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDownHG(Identification, JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, JsonData.DATA.EXP_ORDINI_RIGHE_STO[0].STO_EXE_OPERATORE
  3261. , JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  3262. }
  3263. #endregion
  3264. #region 委外领料申请单发料
  3265. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  3266. {
  3267. BusinessCode = TransTypeEnum.OOApply.GetDescription<DBValue>();
  3268. //更新源头单据数量
  3269. ICSOutsourcingService.OOApplyHG(JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, cmd, language);
  3270. //出库
  3271. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDownHG(Identification, JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, JsonData.DATA.EXP_ORDINI_RIGHE_STO[0].STO_EXE_OPERATORE
  3272. , JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  3273. }
  3274. #endregion
  3275. else
  3276. {
  3277. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  3278. }
  3279. //上传ERP
  3280. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  3281. {
  3282. //采购退货
  3283. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  3284. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  3285. //领料申请单发料
  3286. if (TransType == TransTypeEnum.MOApply.GetDescription())
  3287. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  3288. //委外领料申请单发料
  3289. if (TransType == TransTypeEnum.OOApply.GetDescription())
  3290. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  3291. //审核的到货单
  3292. if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  3293. ICSPurchaseService.DeliveryNoticeInERPHG(TransType, Identification, cmd, language, BusinessCode);
  3294. //开立的生产入库单
  3295. if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  3296. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  3297. //生产退料
  3298. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  3299. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  3300. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  3301. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  3302. }
  3303. #region 出库单据增加验证,整单全部出库之后删除所有跟单据关联的占料信息,解锁占料数量
  3304. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription()
  3305. || TransType == TransTypeEnum.MOApply.GetDescription() || TransType == TransTypeEnum.OOApply.GetDescription())
  3306. {
  3307. ICSWareHouseLotInfoService.MaterialOccpyCancel(TransType, JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE, cmd, language);
  3308. }
  3309. #endregion
  3310. if (!printTable.Equals("{}"))
  3311. {
  3312. cmd.Transaction.Commit();
  3313. return printTable;
  3314. }
  3315. else
  3316. {
  3317. //DataTable table = GetData(Identification, 2, cmd);
  3318. DataTable table = new DataTable();
  3319. cmd.Transaction.Commit();
  3320. return table;
  3321. }
  3322. }
  3323. catch (Exception ex)
  3324. {
  3325. if (cmd.Transaction != null)
  3326. cmd.Transaction.Rollback();
  3327. log.Error(ex.Message);
  3328. #region 保存传入JSON及报错信息
  3329. string errorsql = @"IF NOT EXISTS(SELECT DocNO FROM ICSHG_WMSEorrorLog WHERE DocNO='{0}' AND WorkPoint='{5}')
  3330. Insert into ICSHG_WMSEorrorLog
  3331. Values
  3332. (NEWID(),'{0}','{1}','{2}','{3}',GETDATE(),'{4}','{4}','{5}','','','')";
  3333. errorsql = string.Format(errorsql, JsonData.DATA.EXP_ORDINI[0].ORD_ORDINE, JsonData.DATA.EXP_ORDINI[0].ORD_DES, InputJson
  3334. , ex.Message, JsonData.DATA.EXP_ORDINI_RIGHE_STO[0].STO_EXE_OPERATORE, JsonData.DATA.EXP_ORDINI[0].ORD_CLIENTE);
  3335. DBHelper.ExecuteNonQuery(connString, CommandType.Text, errorsql);
  3336. #endregion
  3337. throw new Exception(ex.Message);
  3338. }
  3339. finally
  3340. {
  3341. if (conn.State == ConnectionState.Open)
  3342. {
  3343. conn.Close();
  3344. }
  3345. conn.Dispose();
  3346. }
  3347. }
  3348. }
  3349. #region 采购
  3350. /// <summary>
  3351. /// 采购到货
  3352. /// </summary>
  3353. /// <param name="JsonData"></param>
  3354. /// <returns></returns>
  3355. public static DataTable DeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  3356. {
  3357. var language = LanguageHelper.GetName("WMSAPIInfo");
  3358. if (JsonData.Count <= 0)
  3359. {
  3360. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3361. }
  3362. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3363. {
  3364. conn.Open();
  3365. SqlTransaction sqlTran = conn.BeginTransaction();
  3366. SqlCommand cmd = new SqlCommand();
  3367. cmd.Transaction = sqlTran;
  3368. cmd.Connection = conn;
  3369. try
  3370. {
  3371. string asncodes = string.Empty;
  3372. string sql = string.Empty;
  3373. foreach (var item in JsonData)
  3374. {
  3375. if (string.IsNullOrEmpty(item.ASNCode))
  3376. {
  3377. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
  3378. }
  3379. //获取单号
  3380. sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  3381. BEGIN
  3382. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  3383. RETURN
  3384. END
  3385. DECLARE @Status VARCHAR(10)
  3386. SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  3387. IF (@Status IS NULL)
  3388. BEGIN
  3389. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  3390. RETURN
  3391. END
  3392. ELSE IF (@Status!='2')
  3393. BEGIN
  3394. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  3395. RETURN
  3396. END
  3397. DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3398. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  3399. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  3400. IF @MaxNO IS NULL
  3401. BEGIN
  3402. SELECT @date+'00001' AS Code
  3403. END
  3404. ELSE
  3405. BEGIN
  3406. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3407. END ";
  3408. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  3409. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3410. //修改送货单到货数量
  3411. foreach (var itemInfo in item.detail)
  3412. {
  3413. sql = @"UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
  3414. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3415. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  3416. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3417. {
  3418. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
  3419. }
  3420. sql = @"UPDATE ICSInventoryLot SET Quantity='{2}'
  3421. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3422. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  3423. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3424. {
  3425. throw new Exception(language.GetNameByCode("WMSAPIInfo462")); //"条码表信息更新失败!");
  3426. }
  3427. }
  3428. //创建到货单信息
  3429. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  3430. BEGIN
  3431. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  3432. RETURN
  3433. END
  3434. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  3435. DNType,InvCode,Quantity,Amount,RCVQuantity,
  3436. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3437. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  3438. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  3439. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  3440. '1',b.InvCode,SUM(a.DNQuantity),'0','0',
  3441. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  3442. d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,
  3443. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode
  3444. FROM ICSASNDetail a
  3445. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3446. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  3447. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  3448. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  3449. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}'
  3450. 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";
  3451. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode);
  3452. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3453. {
  3454. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  3455. }
  3456. ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  3457. asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
  3458. }
  3459. if (string.IsNullOrWhiteSpace(asncodes))
  3460. {
  3461. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  3462. }
  3463. #region 查询返回数据
  3464. sql = @"SELECT
  3465. n.POCode,
  3466. n.Sequence AS POSequence,
  3467. a.ASNCode,
  3468. a.DNCode,
  3469. a.Sequence,
  3470. a.VenCode,
  3471. a.DepCode,
  3472. a.InvCode,
  3473. inv.InvName,
  3474. inv.InvStd,
  3475. a.Quantity,
  3476. inv.InvUnit,
  3477. a.Amount,
  3478. inv.AmountUnit,
  3479. a.RCVQuantity,
  3480. a.UnitPrice,
  3481. a.Currency,
  3482. a.POID,
  3483. a.PODetailID,
  3484. a.DNID,
  3485. a.DNDetailID,
  3486. ext.ProjectCode,
  3487. ext.BatchCode,
  3488. ext.Version,
  3489. ext.Brand,
  3490. ext.cFree1,
  3491. ext.cFree2,
  3492. ext.cFree3,
  3493. ext.cFree4,
  3494. ext.cFree5,
  3495. ext.cFree6,
  3496. ext.cFree7,
  3497. ext.cFree8,
  3498. ext.cFree9,
  3499. ext.cFree10,
  3500. a.MUSER AS [User],
  3501. a.MTIME AS [MTime]
  3502. FROM ICSDeliveryNotice a
  3503. INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
  3504. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3505. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3506. WHERE a.ASNCode+a.WorkPoint IN ({0})";
  3507. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  3508. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3509. #endregion
  3510. cmd.Transaction.Commit();
  3511. return data;
  3512. }
  3513. catch (Exception ex)
  3514. {
  3515. if (cmd.Transaction != null)
  3516. cmd.Transaction.Rollback();
  3517. log.Error(ex.Message);
  3518. throw new Exception(ex.Message);
  3519. }
  3520. finally
  3521. {
  3522. if (conn.State == ConnectionState.Open)
  3523. {
  3524. conn.Close();
  3525. }
  3526. conn.Dispose();
  3527. }
  3528. }
  3529. }
  3530. /// <summary>
  3531. /// 采购拒收
  3532. /// </summary>
  3533. /// <param name="JsonData"></param>
  3534. /// <returns></returns>
  3535. public static DataTable PurchaseRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  3536. {
  3537. var language = LanguageHelper.GetName("WMSAPIInfo");
  3538. if (JsonData.Count <= 0)
  3539. {
  3540. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3541. }
  3542. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3543. {
  3544. conn.Open();
  3545. SqlTransaction sqlTran = conn.BeginTransaction();
  3546. SqlCommand cmd = new SqlCommand();
  3547. cmd.Transaction = sqlTran;
  3548. cmd.Connection = conn;
  3549. try
  3550. {
  3551. string lots = string.Empty;
  3552. string sql = string.Empty;
  3553. foreach (var item in JsonData)
  3554. {
  3555. if (string.IsNullOrEmpty(item.DNCode))
  3556. {
  3557. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  3558. }
  3559. //获取单号
  3560. sql = @"DECLARE @Status VARCHAR(10)
  3561. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  3562. IF (@Status IS NULL)
  3563. BEGIN
  3564. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  3565. RETURN
  3566. END
  3567. ELSE IF (@Status!='2')
  3568. BEGIN
  3569. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  3570. RETURN
  3571. END
  3572. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3573. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  3574. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  3575. IF @MaxNO IS NULL
  3576. BEGIN
  3577. SELECT @date+'00001' AS Code
  3578. END
  3579. ELSE
  3580. BEGIN
  3581. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3582. END ";
  3583. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  3584. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3585. //修改送货单到货数量
  3586. foreach (var itemInfo in item.detail)
  3587. {
  3588. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  3589. BEGIN
  3590. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  3591. RETURN
  3592. END
  3593. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  3594. BEGIN
  3595. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  3596. RETURN
  3597. END
  3598. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  3599. DNType,InvCode,Quantity,Amount,RCVQuantity,
  3600. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3601. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  3602. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  3603. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  3604. '3',d.InvCode,'{7}', '{8}', 0,
  3605. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  3606. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  3607. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  3608. FROM ICSDeliveryNotice a
  3609. INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  3610. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  3611. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  3612. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  3613. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  3614. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  3615. WHERE a.DNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  3616. 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);
  3617. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3618. {
  3619. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  3620. }
  3621. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  3622. }
  3623. ICSPurchaseService.PurchaseRejectDocInNewERP(item.DNCode, Code, item.WorkPoint, cmd, language);
  3624. }
  3625. if (string.IsNullOrWhiteSpace(lots))
  3626. {
  3627. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  3628. }
  3629. #region 查询返回数据
  3630. sql = @"SELECT
  3631. n.DNCode,
  3632. n.Sequence,
  3633. a.DNCode AS RJTCode,
  3634. a.Sequence AS RJTSequence,
  3635. a.VenCode,
  3636. a.DepCode,
  3637. a.InvCode,
  3638. inv.InvName,
  3639. inv.InvStd,
  3640. a.Quantity,
  3641. inv.InvUnit,
  3642. a.Amount,
  3643. inv.AmountUnit,
  3644. a.RCVQuantity,
  3645. a.UnitPrice,
  3646. a.Currency,
  3647. a.POID,
  3648. a.PODetailID,
  3649. a.DNID,
  3650. a.DNDetailID,
  3651. ext.ProjectCode,
  3652. ext.BatchCode,
  3653. ext.Version,
  3654. ext.Brand,
  3655. ext.cFree1,
  3656. ext.cFree2,
  3657. ext.cFree3,
  3658. ext.cFree4,
  3659. ext.cFree5,
  3660. ext.cFree6,
  3661. ext.cFree7,
  3662. ext.cFree8,
  3663. ext.cFree9,
  3664. ext.cFree10,
  3665. a.MUSER AS [User],
  3666. a.MTIME AS [MTime]
  3667. FROM ICSDeliveryNotice a
  3668. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  3669. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3670. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3671. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  3672. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  3673. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3674. #endregion
  3675. cmd.Transaction.Commit();
  3676. return data;
  3677. }
  3678. catch (Exception ex)
  3679. {
  3680. if (cmd.Transaction != null)
  3681. cmd.Transaction.Rollback();
  3682. log.Error(ex.Message);
  3683. throw new Exception(ex.Message);
  3684. }
  3685. finally
  3686. {
  3687. if (conn.State == ConnectionState.Open)
  3688. {
  3689. conn.Close();
  3690. }
  3691. conn.Dispose();
  3692. }
  3693. }
  3694. }
  3695. #endregion
  3696. #region 委外
  3697. /// <summary>
  3698. /// 委外退料 新建
  3699. /// </summary>
  3700. /// <param name="JsonData"></param>
  3701. /// <returns></returns>
  3702. public static DataTable OutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  3703. {
  3704. var language = LanguageHelper.GetName("WMSAPIInfo");
  3705. if (JsonData.Count <= 0)
  3706. {
  3707. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3708. }
  3709. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3710. {
  3711. conn.Open();
  3712. SqlTransaction sqlTran = conn.BeginTransaction();
  3713. SqlCommand cmd = new SqlCommand();
  3714. cmd.Transaction = sqlTran;
  3715. cmd.Connection = conn;
  3716. try
  3717. {
  3718. string codes = string.Empty;
  3719. string sql = string.Empty;
  3720. foreach (var item in JsonData)
  3721. {
  3722. //获取单号
  3723. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3724. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  3725. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  3726. IF @MaxNO IS NULL
  3727. BEGIN
  3728. SELECT @date+'00001' AS Code
  3729. END
  3730. ELSE
  3731. BEGIN
  3732. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3733. END ";
  3734. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3735. //创建主表
  3736. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  3737. BEGIN
  3738. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3739. RETURN
  3740. END
  3741. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3742. 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}','')";
  3743. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  3744. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3745. {
  3746. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  3747. }
  3748. foreach (var itemInfo in item.detail)
  3749. {
  3750. //创建子表
  3751. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  3752. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3753. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3754. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3755. '{4}','{5}',0,'{6}','{7}',
  3756. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3757. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3758. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3759. {
  3760. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  3761. }
  3762. }
  3763. //校验退料数量是否超出领料数量
  3764. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  3765. DBHelper.ExecuteNonQuery(sql, cmd);
  3766. codes += "'" + Code + item.WorkPoint + "',";
  3767. }
  3768. if (string.IsNullOrWhiteSpace(codes))
  3769. {
  3770. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3771. }
  3772. #region 查询返回数据
  3773. sql = @"SELECT a.OApplyNegCode,
  3774. c.WHCode,
  3775. c.Memo,
  3776. d.Name AS Status,
  3777. a.Sequence,
  3778. a.InvCode,
  3779. inv.InvName,
  3780. inv.InvStd,
  3781. a.Quantity,
  3782. inv.InvUnit,
  3783. a.Amount,
  3784. inv.AmountUnit,
  3785. a.IssueNegQuantity,
  3786. ext.ProjectCode,
  3787. ext.BatchCode,
  3788. ext.Version,
  3789. ext.Brand,
  3790. ext.cFree1,
  3791. ext.cFree2,
  3792. ext.cFree3,
  3793. ext.cFree4,
  3794. ext.cFree5,
  3795. ext.cFree6,
  3796. ext.cFree7,
  3797. ext.cFree8,
  3798. ext.cFree9,
  3799. ext.cFree10,
  3800. a.MUSER AS [User],
  3801. a.MTIME AS [MTime]
  3802. FROM ICSOApplyNegDetail a
  3803. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3804. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3805. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3806. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3807. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  3808. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  3809. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3810. #endregion
  3811. cmd.Transaction.Commit();
  3812. return data;
  3813. }
  3814. catch (Exception ex)
  3815. {
  3816. if (cmd.Transaction != null)
  3817. cmd.Transaction.Rollback();
  3818. log.Error(ex.Message);
  3819. throw new Exception(ex.Message);
  3820. }
  3821. finally
  3822. {
  3823. if (conn.State == ConnectionState.Open)
  3824. {
  3825. conn.Close();
  3826. }
  3827. conn.Dispose();
  3828. }
  3829. }
  3830. }
  3831. private static string CheckOutsourcingIssueDoc(string Type, string Code, string WorkPoint, Dictionary<string, string> language)
  3832. {
  3833. string sql = string.Empty;
  3834. if (Type == "1")
  3835. {
  3836. sql = @"DECLARE @PickID VARCHAR(10)
  3837. SELECT @PickID=b.PickID
  3838. FROM ICSOApplyNegDetail a
  3839. INNER JOIN ICSOOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  3840. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3841. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3842. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3843. FROM ICSOApplyNegDetail a
  3844. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3845. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3846. GROUP BY b.PickID
  3847. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3848. IF (@PickID IS NOT NULL)
  3849. BEGIN
  3850. DECLARE @InvCode VARCHAR(100)
  3851. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  3852. RAISERROR(@InvCode,16,1);
  3853. RETURN
  3854. END ";
  3855. }
  3856. else if (Type == "2")
  3857. {
  3858. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  3859. SELECT @ApplyDetailID=b.ApplyDetailID
  3860. FROM ICSOApplyNegDetail a
  3861. INNER JOIN ICSOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  3862. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3863. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3864. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3865. FROM ICSOApplyNegDetail a
  3866. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3867. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3868. GROUP BY b.ApplyDetailID
  3869. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3870. IF (@ApplyDetailID IS NOT NULL)
  3871. BEGIN
  3872. DECLARE @InvCode VARCHAR(100)
  3873. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  3874. RAISERROR(@InvCode,16,1);
  3875. RETURN
  3876. END ";
  3877. }
  3878. else if (Type == "3")
  3879. {
  3880. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  3881. SELECT @IssueDetailID=b.IssueDetailID
  3882. FROM ICSOApplyNegDetail a
  3883. INNER JOIN ICSOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  3884. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3885. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3886. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3887. FROM ICSOApplyNegDetail a
  3888. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3889. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3890. GROUP BY b.IssueDetailID
  3891. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3892. IF (@IssueDetailID IS NOT NULL)
  3893. BEGIN
  3894. DECLARE @InvCode VARCHAR(100)
  3895. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  3896. RAISERROR(@InvCode,16,1);
  3897. RETURN
  3898. END ";
  3899. }
  3900. else
  3901. {
  3902. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  3903. }
  3904. sql = string.Format(sql, Code, WorkPoint, Type);
  3905. return sql;
  3906. }
  3907. /// <summary>
  3908. /// 委外退料 修改
  3909. /// </summary>
  3910. /// <param name="JsonData"></param>
  3911. /// <returns></returns>
  3912. public static DataTable OutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  3913. {
  3914. var language = LanguageHelper.GetName("WMSAPIInfo");
  3915. if (JsonData.Count <= 0)
  3916. {
  3917. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3918. }
  3919. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3920. {
  3921. conn.Open();
  3922. SqlTransaction sqlTran = conn.BeginTransaction();
  3923. SqlCommand cmd = new SqlCommand();
  3924. cmd.Transaction = sqlTran;
  3925. cmd.Connection = conn;
  3926. try
  3927. {
  3928. string sql = string.Empty;
  3929. string Code = string.Empty;
  3930. string ids = string.Empty;
  3931. foreach (var item in JsonData)
  3932. {
  3933. //主表修改
  3934. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  3935. BEGIN
  3936. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  3937. RETURN
  3938. END
  3939. DECLARE @Status VARCHAR(10)
  3940. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  3941. IF (@Status IS NULL)
  3942. BEGIN
  3943. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  3944. RETURN
  3945. END
  3946. ELSE IF (@Status!='1')
  3947. BEGIN
  3948. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  3949. RETURN
  3950. END
  3951. 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}' ";
  3952. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  3953. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3954. {
  3955. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  3956. }
  3957. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  3958. if (detail > 0)
  3959. {
  3960. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  3961. sql = string.Format(sql, item.id, item.WorkPoint);
  3962. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3963. }
  3964. foreach (var itemInfo in item.detail)
  3965. {
  3966. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  3967. {
  3968. //创建子表
  3969. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  3970. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3971. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3972. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3973. '{4}','{5}',0,'{6}','{7}',
  3974. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3975. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3976. }
  3977. else
  3978. {
  3979. //子表修改
  3980. 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}'";
  3981. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  3982. }
  3983. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3984. {
  3985. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  3986. }
  3987. }
  3988. //校验退料数量是否超出领料数量
  3989. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  3990. DBHelper.ExecuteNonQuery(sql, cmd);
  3991. ids += "'" + item.id + "',";
  3992. }
  3993. if (string.IsNullOrWhiteSpace(ids))
  3994. {
  3995. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3996. }
  3997. #region 查询返回数据
  3998. sql = @"SELECT a.OApplyNegCode,
  3999. c.WHCode,
  4000. c.Memo,
  4001. d.Name AS Status,
  4002. a.Sequence,
  4003. a.InvCode,
  4004. inv.InvName,
  4005. inv.InvStd,
  4006. a.Quantity,
  4007. inv.InvUnit,
  4008. a.Amount,
  4009. inv.AmountUnit,
  4010. a.IssueNegQuantity,
  4011. ext.ProjectCode,
  4012. ext.BatchCode,
  4013. ext.Version,
  4014. ext.Brand,
  4015. ext.cFree1,
  4016. ext.cFree2,
  4017. ext.cFree3,
  4018. ext.cFree4,
  4019. ext.cFree5,
  4020. ext.cFree6,
  4021. ext.cFree7,
  4022. ext.cFree8,
  4023. ext.cFree9,
  4024. ext.cFree10,
  4025. a.MUSER AS [User],
  4026. a.MTIME AS [MTime]
  4027. FROM ICSOApplyNegDetail a
  4028. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  4029. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4030. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4031. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4032. WHERE c.ID IN ({0})";
  4033. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  4034. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4035. #endregion
  4036. cmd.Transaction.Commit();
  4037. return data;
  4038. }
  4039. catch (Exception ex)
  4040. {
  4041. if (cmd.Transaction != null)
  4042. cmd.Transaction.Rollback();
  4043. log.Error(ex.Message);
  4044. throw new Exception(ex.Message);
  4045. }
  4046. finally
  4047. {
  4048. if (conn.State == ConnectionState.Open)
  4049. {
  4050. conn.Close();
  4051. }
  4052. conn.Dispose();
  4053. }
  4054. }
  4055. }
  4056. /// <summary>
  4057. /// 委外退料审核
  4058. /// </summary>
  4059. /// <param name="JsonData"></param>
  4060. /// <returns></returns>
  4061. public static DataTable OutsourcingIssueDoNegativeApplyApprove(List<ICSUser> JsonData)
  4062. {
  4063. var language = LanguageHelper.GetName("WMSAPIInfo");
  4064. if (JsonData.Count <= 0)
  4065. {
  4066. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4067. }
  4068. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4069. {
  4070. conn.Open();
  4071. SqlTransaction sqlTran = conn.BeginTransaction();
  4072. SqlCommand cmd = new SqlCommand();
  4073. cmd.Transaction = sqlTran;
  4074. cmd.Connection = conn;
  4075. try
  4076. {
  4077. string sql = string.Empty;
  4078. string ids = string.Empty;
  4079. foreach (var item in JsonData)
  4080. {
  4081. if (string.IsNullOrEmpty(item.ID))
  4082. {
  4083. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  4084. }
  4085. if (string.IsNullOrEmpty(item.User))
  4086. {
  4087. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  4088. }
  4089. if (item.MTime <= new DateTime(2000, 1, 1))
  4090. {
  4091. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  4092. }
  4093. //获取单号
  4094. sql = @"DECLARE @Status VARCHAR(10)
  4095. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  4096. IF (@Status IS NULL)
  4097. BEGIN
  4098. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  4099. RETURN
  4100. END
  4101. ELSE IF (@Status!='1')
  4102. BEGIN
  4103. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  4104. RETURN
  4105. END
  4106. update ICSOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  4107. sql = string.Format(sql, item.ID, item.User, item.MTime);
  4108. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4109. {
  4110. throw new Exception(language.GetNameByCode("WMSAPIInfo021"));//"委外退料申请单审核失败!");
  4111. }
  4112. ids += "'" + item.ID + "',";
  4113. }
  4114. if (string.IsNullOrWhiteSpace(ids))
  4115. {
  4116. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  4117. }
  4118. #region 查询返回数据
  4119. sql = @"SELECT a.OApplyNegCode,
  4120. c.WHCode,
  4121. c.Memo,
  4122. d.Name AS Status,
  4123. a.Sequence,
  4124. a.InvCode,
  4125. inv.InvName,
  4126. inv.InvStd,
  4127. a.Quantity,
  4128. inv.InvUnit,
  4129. a.Amount,
  4130. inv.AmountUnit,
  4131. a.IssueNegQuantity,
  4132. ext.ProjectCode,
  4133. ext.BatchCode,
  4134. ext.Version,
  4135. ext.Brand,
  4136. ext.cFree1,
  4137. ext.cFree2,
  4138. ext.cFree3,
  4139. ext.cFree4,
  4140. ext.cFree5,
  4141. ext.cFree6,
  4142. ext.cFree7,
  4143. ext.cFree8,
  4144. ext.cFree9,
  4145. ext.cFree10,
  4146. a.MUSER AS [User],
  4147. a.MTIME AS [MTime]
  4148. FROM ICSOApplyNegDetail a
  4149. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  4150. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4151. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4152. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4153. WHERE c.ID IN ({0})";
  4154. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  4155. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4156. #endregion
  4157. cmd.Transaction.Commit();
  4158. return data;
  4159. }
  4160. catch (Exception ex)
  4161. {
  4162. if (cmd.Transaction != null)
  4163. cmd.Transaction.Rollback();
  4164. log.Error(ex.Message);
  4165. throw new Exception(ex.Message);
  4166. }
  4167. finally
  4168. {
  4169. if (conn.State == ConnectionState.Open)
  4170. {
  4171. conn.Close();
  4172. }
  4173. conn.Dispose();
  4174. }
  4175. }
  4176. }
  4177. /// <summary>
  4178. /// 委外到货
  4179. /// </summary>
  4180. /// <param name="JsonData"></param>
  4181. /// <returns></returns>
  4182. public static DataTable OutsourcingDeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  4183. {
  4184. var language = LanguageHelper.GetName("WMSAPIInfo");
  4185. if (JsonData.Count <= 0)
  4186. {
  4187. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4188. }
  4189. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4190. {
  4191. conn.Open();
  4192. SqlTransaction sqlTran = conn.BeginTransaction();
  4193. SqlCommand cmd = new SqlCommand();
  4194. cmd.Transaction = sqlTran;
  4195. cmd.Connection = conn;
  4196. try
  4197. {
  4198. string asncodes = string.Empty;
  4199. string sql = string.Empty;
  4200. foreach (var item in JsonData)
  4201. {
  4202. if (string.IsNullOrEmpty(item.OASNCode))
  4203. {
  4204. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!");
  4205. }
  4206. //获取单号
  4207. sql = @"IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.OASNCode='{0}' AND ODNType = '1' AND a.WorkPoint='{1}')
  4208. BEGIN
  4209. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  4210. RETURN
  4211. END
  4212. DECLARE @Status VARCHAR(10)
  4213. SELECT @Status=Status FROM ICSOASN WHERE OASNCode='{0}' and WorkPoint='{1}'
  4214. IF (@Status IS NULL)
  4215. BEGIN
  4216. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  4217. RETURN
  4218. END
  4219. ELSE IF (@Status!='2')
  4220. BEGIN
  4221. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  4222. RETURN
  4223. END
  4224. DECLARE @MaxNO INT,@date varchar(20)='ODN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  4225. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  4226. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  4227. IF @MaxNO IS NULL
  4228. BEGIN
  4229. SELECT @date+'00001' AS Code
  4230. END
  4231. ELSE
  4232. BEGIN
  4233. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  4234. END ";
  4235. sql = string.Format(sql, item.OASNCode, item.WorkPoint);
  4236. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4237. //修改送货单到货数量
  4238. foreach (var itemInfo in item.detail)
  4239. {
  4240. sql = @"UPDATE ICSOASNDetail SET ODNQuantity=ISNULL(ODNQuantity, 0)+'{2}'
  4241. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  4242. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  4243. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4244. {
  4245. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"委外送货单子表信息更新失败!");
  4246. }
  4247. }
  4248. //创建到货单信息
  4249. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  4250. BEGIN
  4251. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  4252. RETURN
  4253. END
  4254. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  4255. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  4256. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  4257. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  4258. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  4259. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  4260. '1',b.InvCode,SUM(a.ODNQuantity),'0','0',
  4261. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  4262. d.OOID,d.OODetailID,newid(),newid(),b.ExtensionID,
  4263. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.OASNCode
  4264. FROM ICSOASNDetail a
  4265. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  4266. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  4267. INNER JOIN ICSOutsourcingOrder d ON c.TransCode=d.OOCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  4268. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  4269. WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
  4270. 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";
  4271. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.OASNCode);
  4272. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4273. {
  4274. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  4275. }
  4276. ICSOutsourcingService.OutsourcingDeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  4277. asncodes += "'" + item.OASNCode + item.WorkPoint + "',";
  4278. }
  4279. if (string.IsNullOrWhiteSpace(asncodes))
  4280. {
  4281. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  4282. }
  4283. #region 查询返回数据
  4284. sql = @"SELECT
  4285. n.OOCode,
  4286. n.Sequence AS OOSequence,
  4287. a.OASNCode,
  4288. a.ODNCode,
  4289. a.Sequence,
  4290. a.VenCode,
  4291. a.DepCode,
  4292. a.InvCode,
  4293. inv.InvName,
  4294. inv.InvStd,
  4295. a.Quantity,
  4296. inv.InvUnit,
  4297. a.Amount,
  4298. inv.AmountUnit,
  4299. a.RCVQuantity,
  4300. a.UnitPrice,
  4301. a.Currency,
  4302. a.OOID,
  4303. a.OODetailID,
  4304. a.ODNID,
  4305. a.ODNDetailID,
  4306. ext.ProjectCode,
  4307. ext.BatchCode,
  4308. ext.Version,
  4309. ext.Brand,
  4310. ext.cFree1,
  4311. ext.cFree2,
  4312. ext.cFree3,
  4313. ext.cFree4,
  4314. ext.cFree5,
  4315. ext.cFree6,
  4316. ext.cFree7,
  4317. ext.cFree8,
  4318. ext.cFree9,
  4319. ext.cFree10,
  4320. a.MUSER AS [User],
  4321. a.MTIME AS [MTime]
  4322. FROM ICSODeliveryNotice a
  4323. INNER JOIN ICSOutsourcingOrder n ON a.OOID =n.OOID AND a.OODetailID=n.OODetailID AND a.WorkPoint=n.WorkPoint
  4324. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4325. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4326. WHERE a.OASNCode+a.WorkPoint IN ({0})";
  4327. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  4328. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4329. #endregion
  4330. cmd.Transaction.Commit();
  4331. return data;
  4332. }
  4333. catch (Exception ex)
  4334. {
  4335. if (cmd.Transaction != null)
  4336. cmd.Transaction.Rollback();
  4337. log.Error(ex.Message);
  4338. throw new Exception(ex.Message);
  4339. }
  4340. finally
  4341. {
  4342. if (conn.State == ConnectionState.Open)
  4343. {
  4344. conn.Close();
  4345. }
  4346. conn.Dispose();
  4347. }
  4348. }
  4349. }
  4350. /// <summary>
  4351. /// 委外拒收
  4352. /// </summary>
  4353. /// <param name="JsonData"></param>
  4354. /// <returns></returns>
  4355. public static DataTable OutsourcingRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  4356. {
  4357. var language = LanguageHelper.GetName("WMSAPIInfo");
  4358. if (JsonData.Count <= 0)
  4359. {
  4360. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4361. }
  4362. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4363. {
  4364. conn.Open();
  4365. SqlTransaction sqlTran = conn.BeginTransaction();
  4366. SqlCommand cmd = new SqlCommand();
  4367. cmd.Transaction = sqlTran;
  4368. cmd.Connection = conn;
  4369. try
  4370. {
  4371. string lots = string.Empty;
  4372. string sql = string.Empty;
  4373. foreach (var item in JsonData)
  4374. {
  4375. if (string.IsNullOrEmpty(item.ODNCode))
  4376. {
  4377. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  4378. }
  4379. //获取单号
  4380. sql = @"DECLARE @Status VARCHAR(10)
  4381. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  4382. IF (@Status IS NULL)
  4383. BEGIN
  4384. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  4385. RETURN
  4386. END
  4387. ELSE IF (@Status!='2')
  4388. BEGIN
  4389. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  4390. RETURN
  4391. END
  4392. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  4393. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  4394. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  4395. IF @MaxNO IS NULL
  4396. BEGIN
  4397. SELECT @date+'00001' AS Code
  4398. END
  4399. ELSE
  4400. BEGIN
  4401. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  4402. END ";
  4403. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  4404. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4405. //修改送货单到货数量
  4406. foreach (var itemInfo in item.detail)
  4407. {
  4408. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  4409. BEGIN
  4410. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  4411. RETURN
  4412. END
  4413. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  4414. BEGIN
  4415. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  4416. RETURN
  4417. END
  4418. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  4419. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  4420. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  4421. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  4422. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  4423. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  4424. '3',d.InvCode,'{7}', '{8}', 0,
  4425. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  4426. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  4427. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  4428. FROM ICSODeliveryNotice a
  4429. INNER JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  4430. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  4431. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  4432. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND a.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  4433. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  4434. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  4435. WHERE a.ODNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  4436. 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);
  4437. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4438. {
  4439. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  4440. }
  4441. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  4442. }
  4443. ICSOutsourcingService.OutsourcingRejectDocInNewERP(item.ODNCode, Code, item.WorkPoint, cmd, language);
  4444. }
  4445. if (string.IsNullOrWhiteSpace(lots))
  4446. {
  4447. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  4448. }
  4449. #region 查询返回数据
  4450. sql = @"SELECT
  4451. n.ODNCode,
  4452. n.Sequence,
  4453. a.ODNCode AS RJTCode,
  4454. a.Sequence AS RJTSequence,
  4455. a.VenCode,
  4456. a.DepCode,
  4457. a.InvCode,
  4458. inv.InvName,
  4459. inv.InvStd,
  4460. a.Quantity,
  4461. inv.InvUnit,
  4462. a.Amount,
  4463. inv.AmountUnit,
  4464. a.RCVQuantity,
  4465. a.UnitPrice,
  4466. a.Currency,
  4467. a.OOID,
  4468. a.OODetailID,
  4469. a.ODNID,
  4470. a.ODNDetailID,
  4471. ext.ProjectCode,
  4472. ext.BatchCode,
  4473. ext.Version,
  4474. ext.Brand,
  4475. ext.cFree1,
  4476. ext.cFree2,
  4477. ext.cFree3,
  4478. ext.cFree4,
  4479. ext.cFree5,
  4480. ext.cFree6,
  4481. ext.cFree7,
  4482. ext.cFree8,
  4483. ext.cFree9,
  4484. ext.cFree10,
  4485. a.MUSER AS [User],
  4486. a.MTIME AS [MTime]
  4487. FROM ICSODeliveryNotice a
  4488. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  4489. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4490. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4491. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  4492. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  4493. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4494. #endregion
  4495. cmd.Transaction.Commit();
  4496. return data;
  4497. }
  4498. catch (Exception ex)
  4499. {
  4500. if (cmd.Transaction != null)
  4501. cmd.Transaction.Rollback();
  4502. log.Error(ex.Message);
  4503. throw new Exception(ex.Message);
  4504. }
  4505. finally
  4506. {
  4507. if (conn.State == ConnectionState.Open)
  4508. {
  4509. conn.Close();
  4510. }
  4511. conn.Dispose();
  4512. }
  4513. }
  4514. }
  4515. #endregion
  4516. #region 生产
  4517. /// <summary>
  4518. /// 生产退料 新建
  4519. /// </summary>
  4520. /// <param name="JsonData"></param>
  4521. /// <returns></returns>
  4522. public static DataTable MOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  4523. {
  4524. var language = LanguageHelper.GetName("WMSAPIInfo");
  4525. if (JsonData.Count <= 0)
  4526. {
  4527. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4528. }
  4529. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4530. {
  4531. conn.Open();
  4532. SqlTransaction sqlTran = conn.BeginTransaction();
  4533. SqlCommand cmd = new SqlCommand();
  4534. cmd.Transaction = sqlTran;
  4535. cmd.Connection = conn;
  4536. try
  4537. {
  4538. string codes = string.Empty;
  4539. string sql = string.Empty;
  4540. foreach (var item in JsonData)
  4541. {
  4542. //获取单号
  4543. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  4544. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  4545. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  4546. IF @MaxNO IS NULL
  4547. BEGIN
  4548. SELECT @date+'00001' AS Code
  4549. END
  4550. ELSE
  4551. BEGIN
  4552. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  4553. END ";
  4554. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4555. //创建主表
  4556. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  4557. BEGIN
  4558. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  4559. RETURN
  4560. END
  4561. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  4562. 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}','')";
  4563. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  4564. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4565. {
  4566. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  4567. }
  4568. foreach (var itemInfo in item.detail)
  4569. {
  4570. //创建子表
  4571. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  4572. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  4573. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  4574. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  4575. '{4}','{5}',0,'{6}','{7}',
  4576. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  4577. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  4578. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4579. {
  4580. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  4581. }
  4582. }
  4583. //校验退料数量是否超出领料数量
  4584. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  4585. DBHelper.ExecuteNonQuery(sql, cmd);
  4586. codes += "'" + Code + item.WorkPoint + "',";
  4587. }
  4588. if (string.IsNullOrWhiteSpace(codes))
  4589. {
  4590. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  4591. }
  4592. #region 查询返回数据
  4593. sql = @"SELECT a.ApplyNegCode,
  4594. c.WHCode,
  4595. c.Memo,
  4596. d.Name AS Status,
  4597. a.Sequence,
  4598. a.InvCode,
  4599. inv.InvName,
  4600. inv.InvStd,
  4601. a.Quantity,
  4602. inv.InvUnit,
  4603. a.Amount,
  4604. inv.AmountUnit,
  4605. a.IssueNegQuantity,
  4606. ext.ProjectCode,
  4607. ext.BatchCode,
  4608. ext.Version,
  4609. ext.Brand,
  4610. ext.cFree1,
  4611. ext.cFree2,
  4612. ext.cFree3,
  4613. ext.cFree4,
  4614. ext.cFree5,
  4615. ext.cFree6,
  4616. ext.cFree7,
  4617. ext.cFree8,
  4618. ext.cFree9,
  4619. ext.cFree10,
  4620. a.MUSER AS [User],
  4621. a.MTIME AS [MTime]
  4622. FROM ICSMOApplyNegDetail a
  4623. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4624. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4625. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4626. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4627. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  4628. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  4629. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4630. #endregion
  4631. cmd.Transaction.Commit();
  4632. return data;
  4633. }
  4634. catch (Exception ex)
  4635. {
  4636. if (cmd.Transaction != null)
  4637. cmd.Transaction.Rollback();
  4638. log.Error(ex.Message);
  4639. throw new Exception(ex.Message);
  4640. }
  4641. finally
  4642. {
  4643. if (conn.State == ConnectionState.Open)
  4644. {
  4645. conn.Close();
  4646. }
  4647. conn.Dispose();
  4648. }
  4649. }
  4650. }
  4651. private static string CheckMOIssueDoc(string Type, string ID, string WorkPoint, Dictionary<string, string> language)
  4652. {
  4653. string sql = string.Empty;
  4654. if (Type == "1")
  4655. {
  4656. sql = @"DECLARE @PickID VARCHAR(10)
  4657. SELECT @PickID=b.PickID
  4658. FROM ICSMOApplyNegDetail a
  4659. INNER JOIN ICSMOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  4660. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4661. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  4662. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  4663. FROM ICSMOApplyNegDetail a
  4664. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4665. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  4666. GROUP BY b.PickID
  4667. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  4668. IF (@PickID IS NOT NULL)
  4669. BEGIN
  4670. DECLARE @InvCode VARCHAR(100)
  4671. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  4672. RAISERROR(@InvCode,16,1);
  4673. RETURN
  4674. END ";
  4675. }
  4676. else if (Type == "2")
  4677. {
  4678. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  4679. SELECT @ApplyDetailID=b.ApplyDetailID
  4680. FROM ICSMOApplyNegDetail a
  4681. INNER JOIN ICSMOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  4682. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4683. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  4684. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  4685. FROM ICSMOApplyNegDetail a
  4686. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4687. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  4688. GROUP BY b.ApplyDetailID
  4689. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  4690. IF (@ApplyDetailID IS NOT NULL)
  4691. BEGIN
  4692. DECLARE @InvCode VARCHAR(100)
  4693. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  4694. RAISERROR(@InvCode,16,1);
  4695. RETURN
  4696. END ";
  4697. }
  4698. else if (Type == "3")
  4699. {
  4700. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  4701. SELECT @IssueDetailID=b.IssueDetailID
  4702. FROM ICSMOApplyNegDetail a
  4703. INNER JOIN ICSMOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  4704. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4705. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  4706. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  4707. FROM ICSMOApplyNegDetail a
  4708. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4709. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  4710. GROUP BY b.IssueDetailID
  4711. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  4712. IF (@IssueDetailID IS NOT NULL)
  4713. BEGIN
  4714. DECLARE @InvCode VARCHAR(100)
  4715. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  4716. RAISERROR(@InvCode,16,1);
  4717. RETURN
  4718. END ";
  4719. }
  4720. else
  4721. {
  4722. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  4723. }
  4724. sql = string.Format(sql, ID, WorkPoint, Type);
  4725. return sql;
  4726. }
  4727. /// <summary>
  4728. /// 生产退料 修改
  4729. /// </summary>
  4730. /// <param name="JsonData"></param>
  4731. /// <returns></returns>
  4732. public static DataTable MOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  4733. {
  4734. var language = LanguageHelper.GetName("WMSAPIInfo");
  4735. if (JsonData.Count <= 0)
  4736. {
  4737. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4738. }
  4739. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4740. {
  4741. conn.Open();
  4742. SqlTransaction sqlTran = conn.BeginTransaction();
  4743. SqlCommand cmd = new SqlCommand();
  4744. cmd.Transaction = sqlTran;
  4745. cmd.Connection = conn;
  4746. try
  4747. {
  4748. string sql = string.Empty;
  4749. string Code = string.Empty;
  4750. string ids = string.Empty;
  4751. foreach (var item in JsonData)
  4752. {
  4753. //主表修改
  4754. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  4755. BEGIN
  4756. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  4757. RETURN
  4758. END
  4759. DECLARE @Status VARCHAR(10)
  4760. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  4761. IF (@Status IS NULL)
  4762. BEGIN
  4763. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  4764. RETURN
  4765. END
  4766. ELSE IF (@Status!='1')
  4767. BEGIN
  4768. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  4769. RETURN
  4770. END
  4771. 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}' ";
  4772. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint);
  4773. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4774. {
  4775. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  4776. }
  4777. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  4778. if (detail > 0)
  4779. {
  4780. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  4781. sql = string.Format(sql, item.ID, item.WorkPoint);
  4782. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4783. }
  4784. foreach (var itemInfo in item.detail)
  4785. {
  4786. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  4787. {
  4788. //创建子表
  4789. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  4790. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  4791. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  4792. '{4}','{5}',0,'{6}','{7}',
  4793. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  4794. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  4795. }
  4796. else
  4797. {
  4798. //子表修改
  4799. 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}'";
  4800. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  4801. }
  4802. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4803. {
  4804. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  4805. }
  4806. }
  4807. //校验退料数量是否超出领料数量
  4808. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  4809. DBHelper.ExecuteNonQuery(sql, cmd);
  4810. ids += "'" + item.ID + "',";
  4811. }
  4812. if (string.IsNullOrWhiteSpace(ids))
  4813. {
  4814. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  4815. }
  4816. #region 查询返回数据
  4817. sql = @"SELECT a.ApplyNegCode,
  4818. c.WHCode,
  4819. c.Memo,
  4820. d.Name AS Status,
  4821. a.Sequence,
  4822. a.InvCode,
  4823. inv.InvName,
  4824. inv.InvStd,
  4825. a.Quantity,
  4826. inv.InvUnit,
  4827. a.Amount,
  4828. inv.AmountUnit,
  4829. a.IssueNegQuantity,
  4830. ext.ProjectCode,
  4831. ext.BatchCode,
  4832. ext.Version,
  4833. ext.Brand,
  4834. ext.cFree1,
  4835. ext.cFree2,
  4836. ext.cFree3,
  4837. ext.cFree4,
  4838. ext.cFree5,
  4839. ext.cFree6,
  4840. ext.cFree7,
  4841. ext.cFree8,
  4842. ext.cFree9,
  4843. ext.cFree10,
  4844. a.MUSER AS [User],
  4845. a.MTIME AS [MTime]
  4846. FROM ICSMOApplyNegDetail a
  4847. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4848. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4849. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4850. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4851. WHERE c.ID IN ({0})";
  4852. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  4853. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4854. #endregion
  4855. cmd.Transaction.Commit();
  4856. return data;
  4857. }
  4858. catch (Exception ex)
  4859. {
  4860. if (cmd.Transaction != null)
  4861. cmd.Transaction.Rollback();
  4862. log.Error(ex.Message);
  4863. throw new Exception(ex.Message);
  4864. }
  4865. finally
  4866. {
  4867. if (conn.State == ConnectionState.Open)
  4868. {
  4869. conn.Close();
  4870. }
  4871. conn.Dispose();
  4872. }
  4873. }
  4874. }
  4875. /// <summary>
  4876. /// 生产退料审核
  4877. /// </summary>
  4878. /// <param name="JsonData"></param>
  4879. /// <returns></returns>
  4880. public static DataTable MOIssueDocNegativeApplyApprove(List<ICSUser> JsonData)
  4881. {
  4882. var language = LanguageHelper.GetName("WMSAPIInfo");
  4883. if (JsonData.Count <= 0)
  4884. {
  4885. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4886. }
  4887. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4888. {
  4889. conn.Open();
  4890. SqlTransaction sqlTran = conn.BeginTransaction();
  4891. SqlCommand cmd = new SqlCommand();
  4892. cmd.Transaction = sqlTran;
  4893. cmd.Connection = conn;
  4894. try
  4895. {
  4896. string sql = string.Empty;
  4897. string ids = string.Empty;
  4898. foreach (var item in JsonData)
  4899. {
  4900. if (string.IsNullOrEmpty(item.ID))
  4901. {
  4902. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  4903. }
  4904. if (string.IsNullOrEmpty(item.User))
  4905. {
  4906. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  4907. }
  4908. if (item.MTime <= new DateTime(2000, 1, 1))
  4909. {
  4910. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  4911. }
  4912. //获取单号
  4913. sql = @"DECLARE @Status VARCHAR(10)
  4914. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  4915. IF (@Status IS NULL)
  4916. BEGIN
  4917. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  4918. RETURN
  4919. END
  4920. ELSE IF (@Status!='1')
  4921. BEGIN
  4922. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  4923. RETURN
  4924. END
  4925. update ICSMOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  4926. sql = string.Format(sql, item.ID, item.User, item.MTime);
  4927. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4928. {
  4929. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  4930. }
  4931. ids += "'" + item.ID + "',";
  4932. }
  4933. if (string.IsNullOrWhiteSpace(ids))
  4934. {
  4935. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  4936. }
  4937. #region 查询返回数据
  4938. sql = @"SELECT a.ApplyNegCode,
  4939. c.WHCode,
  4940. c.Memo,
  4941. d.Name AS Status,
  4942. a.Sequence,
  4943. a.InvCode,
  4944. inv.InvName,
  4945. inv.InvStd,
  4946. a.Quantity,
  4947. inv.InvUnit,
  4948. a.Amount,
  4949. inv.AmountUnit,
  4950. a.IssueNegQuantity,
  4951. ext.ProjectCode,
  4952. ext.BatchCode,
  4953. ext.Version,
  4954. ext.Brand,
  4955. ext.cFree1,
  4956. ext.cFree2,
  4957. ext.cFree3,
  4958. ext.cFree4,
  4959. ext.cFree5,
  4960. ext.cFree6,
  4961. ext.cFree7,
  4962. ext.cFree8,
  4963. ext.cFree9,
  4964. ext.cFree10,
  4965. a.MUSER AS [User],
  4966. a.MTIME AS [MTime]
  4967. FROM ICSMOApplyNegDetail a
  4968. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4969. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4970. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4971. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4972. WHERE c.ID IN ({0})";
  4973. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  4974. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4975. #endregion
  4976. cmd.Transaction.Commit();
  4977. return data;
  4978. }
  4979. catch (Exception ex)
  4980. {
  4981. if (cmd.Transaction != null)
  4982. cmd.Transaction.Rollback();
  4983. log.Error(ex.Message);
  4984. throw new Exception(ex.Message);
  4985. }
  4986. finally
  4987. {
  4988. if (conn.State == ConnectionState.Open)
  4989. {
  4990. conn.Close();
  4991. }
  4992. conn.Dispose();
  4993. }
  4994. }
  4995. }
  4996. #endregion
  4997. #region 一步调拨(调拨申请单)
  4998. /// <summary>
  4999. /// 一步调拨(调拨申请单)
  5000. /// </summary>
  5001. /// <param name="JsonData"></param>
  5002. /// <returns></returns>
  5003. public static DataTable OneStepTransferApplicationIn(List<TransferApplication> JsonData)
  5004. {
  5005. var language = LanguageHelper.GetName("WMSAPIInfo");
  5006. if (JsonData.Count <= 0)
  5007. {
  5008. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5009. }
  5010. DataTable printTable = new DataTable();
  5011. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5012. {
  5013. conn.Open();
  5014. SqlTransaction sqlTran = conn.BeginTransaction();
  5015. SqlCommand cmd = new SqlCommand();
  5016. cmd.Transaction = sqlTran;
  5017. cmd.Connection = conn;
  5018. string BusinessCode = string.Empty;
  5019. try
  5020. {
  5021. string sql = string.Empty;
  5022. string Identification = Guid.NewGuid().ToString();
  5023. foreach (var item in JsonData)
  5024. {
  5025. if (string.IsNullOrEmpty(item.TransCode))
  5026. {
  5027. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨申请单号不能为空!");
  5028. }
  5029. string[] trans = item.TransCode.Split('~');
  5030. string MergeID = "";
  5031. if (trans.Length == 2)
  5032. {
  5033. MergeID = trans[0];
  5034. item.TransCode = trans[1];
  5035. }
  5036. //验证信息
  5037. sql = @"DECLARE @Status VARCHAR(10)
  5038. SELECT @Status=Status FROM ICSTransferApplication WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  5039. IF (@Status IS NULL)
  5040. BEGIN
  5041. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  5042. RETURN
  5043. END
  5044. ELSE IF (@Status!='1')
  5045. BEGIN
  5046. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  5047. RETURN
  5048. END";
  5049. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  5050. DBHelper.ExecuteNonQuery(sql, cmd);
  5051. foreach (var itemInfo in item.Detail)
  5052. {
  5053. //验证仓库库位信息
  5054. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  5055. BEGIN
  5056. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  5057. RETURN
  5058. END
  5059. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  5060. BEGIN
  5061. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  5062. RETURN
  5063. END
  5064. IF NOT EXISTS(SELECT a.ID
  5065. FROM ICSWareHouse a
  5066. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  5067. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  5068. BEGIN
  5069. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  5070. RETURN
  5071. END";
  5072. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  5073. DBHelper.ExecuteNonQuery(sql, cmd);
  5074. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  5075. //更新源头单据信息
  5076. ICSWareHouseService.OneStepTransferApplicationIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  5077. //更新条码信息
  5078. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  5079. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  5080. }
  5081. }
  5082. //上传ERP
  5083. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  5084. {
  5085. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  5086. }
  5087. if (!printTable.Equals("{}"))
  5088. {
  5089. cmd.Transaction.Commit();
  5090. return printTable;
  5091. }
  5092. else
  5093. {
  5094. DataTable table = GetData(Identification, 3, cmd);
  5095. cmd.Transaction.Commit();
  5096. return table;
  5097. }
  5098. }
  5099. catch (Exception ex)
  5100. {
  5101. if (cmd.Transaction != null)
  5102. cmd.Transaction.Rollback();
  5103. log.Error(ex.Message);
  5104. throw new Exception(ex.Message);
  5105. }
  5106. finally
  5107. {
  5108. if (conn.State == ConnectionState.Open)
  5109. {
  5110. conn.Close();
  5111. }
  5112. conn.Dispose();
  5113. }
  5114. }
  5115. }
  5116. #endregion
  5117. #region 一步调拨
  5118. /// <summary>
  5119. /// 一步调拨
  5120. /// </summary>
  5121. /// <param name="JsonData"></param>
  5122. /// <returns></returns>
  5123. public static DataTable OneStepTransferDocIn(List<TransferDoc> JsonData)
  5124. {
  5125. var language = LanguageHelper.GetName("WMSAPIInfo");
  5126. if (JsonData.Count <= 0)
  5127. {
  5128. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5129. }
  5130. DataTable printTable = new DataTable();
  5131. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5132. {
  5133. conn.Open();
  5134. SqlTransaction sqlTran = conn.BeginTransaction();
  5135. SqlCommand cmd = new SqlCommand();
  5136. cmd.Transaction = sqlTran;
  5137. cmd.Connection = conn;
  5138. string BusinessCode = string.Empty;
  5139. try
  5140. {
  5141. string sql = string.Empty;
  5142. string Identification = Guid.NewGuid().ToString();
  5143. foreach (var item in JsonData)
  5144. {
  5145. if (string.IsNullOrEmpty(item.TransCode))
  5146. {
  5147. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨单号不能为空!");
  5148. }
  5149. string[] trans = item.TransCode.Split('~');
  5150. string MergeID = "";
  5151. if (trans.Length == 2)
  5152. {
  5153. MergeID = trans[0];
  5154. item.TransCode = trans[1];
  5155. }
  5156. //验证信息
  5157. //sql = @"DECLARE @Status VARCHAR(10)
  5158. // SELECT @Status=Status FROM ICSTransfer WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  5159. // IF (@Status IS NULL)
  5160. // BEGIN
  5161. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  5162. // RETURN
  5163. // END
  5164. // ELSE IF (@Status!='1')
  5165. // BEGIN
  5166. // RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  5167. // RETURN
  5168. // END";
  5169. //sql = string.Format(sql, item.TransCode, item.WorkPoint);
  5170. //DBHelper.ExecuteNonQuery(sql, cmd);
  5171. foreach (var itemInfo in item.Detail)
  5172. {
  5173. var tranferWorkpoint = string.Empty;
  5174. var checksql = $@"SELECT
  5175. top 1 a.EATTRIBUTE1
  5176. FROM
  5177. ICSTransfer a
  5178. WHERE
  5179. TransferNO = '{item.TransCode}'
  5180. AND Sequence = '{item.TransSequence}'
  5181. AND WorkPoint = '{item.WorkPoint}'
  5182. AND Type = '{item.TransType}'";
  5183. var workPoint = DBHelper.ExecuteScalar(checksql, cmd)?.ToString();
  5184. if (workPoint == null || workPoint == "")
  5185. {
  5186. tranferWorkpoint = item.WorkPoint;
  5187. }
  5188. else
  5189. {
  5190. tranferWorkpoint = workPoint.ToString();
  5191. }
  5192. //验证仓库库位信息
  5193. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  5194. BEGIN
  5195. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  5196. RETURN
  5197. END
  5198. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  5199. BEGIN
  5200. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  5201. RETURN
  5202. END
  5203. IF NOT EXISTS(SELECT a.ID
  5204. FROM ICSWareHouse a
  5205. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  5206. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  5207. BEGIN
  5208. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  5209. RETURN
  5210. END";
  5211. sql = string.Format(sql, itemInfo.WarehouseCode, tranferWorkpoint, itemInfo.LocationCode);
  5212. DBHelper.ExecuteNonQuery(sql, cmd);
  5213. BusinessCode = TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>();
  5214. //更新源头单据信息
  5215. ICSWareHouseService.OneStepTransferDocIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  5216. //更新条码信息
  5217. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  5218. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, item.TransType, TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  5219. }
  5220. }
  5221. //上传ERP
  5222. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  5223. {
  5224. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  5225. }
  5226. if (!printTable.Equals("{}"))
  5227. {
  5228. cmd.Transaction.Commit();
  5229. return printTable;
  5230. }
  5231. else
  5232. {
  5233. DataTable table = GetData(Identification, 3, cmd);
  5234. cmd.Transaction.Commit();
  5235. return table;
  5236. }
  5237. }
  5238. catch (Exception ex)
  5239. {
  5240. if (cmd.Transaction != null)
  5241. cmd.Transaction.Rollback();
  5242. log.Error(ex.Message);
  5243. throw new Exception(ex.Message);
  5244. }
  5245. finally
  5246. {
  5247. if (conn.State == ConnectionState.Open)
  5248. {
  5249. conn.Close();
  5250. }
  5251. conn.Dispose();
  5252. }
  5253. }
  5254. }
  5255. #endregion
  5256. #region 调拨
  5257. /// <summary>
  5258. /// 调拨
  5259. /// </summary>
  5260. /// <param name="JsonData"></param>
  5261. /// <returns></returns>
  5262. public static DataTable TransferDocCreate(List<TransferDoc> JsonData)
  5263. {
  5264. var language = LanguageHelper.GetName("WMSAPIInfo");
  5265. if (JsonData.Count <= 0)
  5266. {
  5267. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5268. }
  5269. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5270. {
  5271. conn.Open();
  5272. SqlTransaction sqlTran = conn.BeginTransaction();
  5273. SqlCommand cmd = new SqlCommand();
  5274. cmd.Transaction = sqlTran;
  5275. cmd.Connection = conn;
  5276. string BusinessCode = string.Empty;
  5277. try
  5278. {
  5279. string sql = string.Empty;
  5280. string Identification = Guid.NewGuid().ToString();
  5281. foreach (var item in JsonData)
  5282. {
  5283. string MergeID = "";
  5284. foreach (var itemInfo in item.Detail)
  5285. {
  5286. //验证仓库库位信息
  5287. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  5288. BEGIN
  5289. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  5290. RETURN
  5291. END
  5292. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  5293. BEGIN
  5294. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  5295. RETURN
  5296. END
  5297. IF NOT EXISTS(SELECT a.ID
  5298. FROM ICSWareHouse a
  5299. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  5300. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  5301. BEGIN
  5302. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  5303. RETURN
  5304. END";
  5305. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  5306. DBHelper.ExecuteNonQuery(sql, cmd);
  5307. BusinessCode = TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>();
  5308. //更新条码信息
  5309. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  5310. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  5311. }
  5312. }
  5313. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  5314. DataTable table = GetData(Identification, 3, cmd);
  5315. cmd.Transaction.Commit();
  5316. return table;
  5317. }
  5318. catch (Exception ex)
  5319. {
  5320. if (cmd.Transaction != null)
  5321. cmd.Transaction.Rollback();
  5322. log.Error(ex.Message);
  5323. throw new Exception(ex.Message);
  5324. }
  5325. finally
  5326. {
  5327. if (conn.State == ConnectionState.Open)
  5328. {
  5329. conn.Close();
  5330. }
  5331. conn.Dispose();
  5332. }
  5333. }
  5334. }
  5335. #endregion
  5336. #region 调拨申请单
  5337. /// <summary>
  5338. /// 调拨
  5339. /// </summary>
  5340. /// <param name="JsonData"></param>
  5341. /// <returns></returns>
  5342. public static DataTable TransferApplicationCreate(List<TransferApplication> JsonData)
  5343. {
  5344. var language = LanguageHelper.GetName("WMSAPIInfo");
  5345. if (JsonData.Count <= 0)
  5346. {
  5347. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5348. }
  5349. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5350. {
  5351. conn.Open();
  5352. SqlTransaction sqlTran = conn.BeginTransaction();
  5353. SqlCommand cmd = new SqlCommand();
  5354. cmd.Transaction = sqlTran;
  5355. cmd.Connection = conn;
  5356. string BusinessCode = string.Empty;
  5357. try
  5358. {
  5359. string sql = string.Empty;
  5360. string Identification = Guid.NewGuid().ToString();
  5361. foreach (var item in JsonData)
  5362. {
  5363. string MergeID = "";
  5364. foreach (var itemInfo in item.Detail)
  5365. {
  5366. //验证仓库库位信息
  5367. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  5368. BEGIN
  5369. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  5370. RETURN
  5371. END
  5372. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  5373. BEGIN
  5374. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  5375. RETURN
  5376. END
  5377. IF NOT EXISTS(SELECT a.ID
  5378. FROM ICSWareHouse a
  5379. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  5380. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  5381. BEGIN
  5382. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  5383. RETURN
  5384. END";
  5385. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  5386. DBHelper.ExecuteNonQuery(sql, cmd);
  5387. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  5388. //更新条码信息
  5389. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  5390. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  5391. }
  5392. }
  5393. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferApplicationIn.GetDescription(), Identification, cmd, language, BusinessCode);
  5394. DataTable table = GetData(Identification, 3, cmd);
  5395. cmd.Transaction.Commit();
  5396. return table;
  5397. }
  5398. catch (Exception ex)
  5399. {
  5400. if (cmd.Transaction != null)
  5401. cmd.Transaction.Rollback();
  5402. log.Error(ex.Message);
  5403. throw new Exception(ex.Message);
  5404. }
  5405. finally
  5406. {
  5407. if (conn.State == ConnectionState.Open)
  5408. {
  5409. conn.Close();
  5410. }
  5411. conn.Dispose();
  5412. }
  5413. }
  5414. }
  5415. #endregion
  5416. #region 调拨申请单
  5417. /// <summary>
  5418. /// 调拨申请单
  5419. /// </summary>
  5420. /// <param name="JsonData"></param>
  5421. /// <returns></returns>
  5422. public static DataTable TransferApplicationInCreate(List<TransferApplication> JsonData)
  5423. {
  5424. var language = LanguageHelper.GetName("WMSAPIInfo");
  5425. if (JsonData.Count <= 0)
  5426. {
  5427. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5428. }
  5429. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5430. {
  5431. conn.Open();
  5432. SqlTransaction sqlTran = conn.BeginTransaction();
  5433. SqlCommand cmd = new SqlCommand();
  5434. cmd.Transaction = sqlTran;
  5435. cmd.Connection = conn;
  5436. string BusinessCode = string.Empty;
  5437. try
  5438. {
  5439. string sql = string.Empty;
  5440. string Identification = Guid.NewGuid().ToString();
  5441. foreach (var item in JsonData)
  5442. {
  5443. string MergeID = "";
  5444. foreach (var itemInfo in item.Detail)
  5445. {
  5446. //验证仓库库位信息
  5447. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  5448. BEGIN
  5449. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  5450. RETURN
  5451. END
  5452. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  5453. BEGIN
  5454. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  5455. RETURN
  5456. END
  5457. IF NOT EXISTS(SELECT a.ID
  5458. FROM ICSWareHouse a
  5459. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  5460. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  5461. BEGIN
  5462. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  5463. RETURN
  5464. END
  5465. IF EXISTS(SELECT ID
  5466. FROM ICSWareHouseLotInfo
  5467. WHERE WarehouseCode='{0}' AND WorkPoint='{1}' AND LotNo='{3}')
  5468. BEGIN
  5469. RAISERROR('" + language.GetNameByCode("WMSAPIInfo355") + @"',16,1);
  5470. RETURN
  5471. END";
  5472. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode, itemInfo.LotNo);
  5473. DBHelper.ExecuteNonQuery(sql, cmd);
  5474. BusinessCode = TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>();
  5475. //更新源头单据信息
  5476. ICSWareHouseService.OneStepTransferApplicationIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  5477. //更新条码信息
  5478. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  5479. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "14", TransTypeEnum.StepTransferApplicationIn.GetDescription<DBValue>(), cmd, language, MergeID);
  5480. }
  5481. }
  5482. ICSWareHouseService.StepTransferApplicationERP(TransTypeEnum.StepTransferApplicationIn.GetDescription(), Identification, cmd, language, BusinessCode);
  5483. DataTable table = GetData(Identification, 3, cmd);
  5484. cmd.Transaction.Commit();
  5485. return table;
  5486. }
  5487. catch (Exception ex)
  5488. {
  5489. if (cmd.Transaction != null)
  5490. cmd.Transaction.Rollback();
  5491. log.Error(ex.Message);
  5492. throw new Exception(ex.Message);
  5493. }
  5494. finally
  5495. {
  5496. if (conn.State == ConnectionState.Open)
  5497. {
  5498. conn.Close();
  5499. }
  5500. conn.Dispose();
  5501. }
  5502. }
  5503. }
  5504. #endregion
  5505. #region 移库
  5506. /// <summary>
  5507. /// 移库
  5508. /// </summary>
  5509. /// <param name="JsonData"></param>
  5510. /// <returns></returns>
  5511. public static DataTable LibraryUpdate(List<ICSLibraryModel> JsonData)
  5512. {
  5513. var language = LanguageHelper.GetName("WMSAPIInfo");
  5514. if (JsonData.Count <= 0)
  5515. {
  5516. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5517. }
  5518. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5519. {
  5520. conn.Open();
  5521. SqlTransaction sqlTran = conn.BeginTransaction();
  5522. SqlCommand cmd = new SqlCommand();
  5523. cmd.Transaction = sqlTran;
  5524. cmd.Connection = conn;
  5525. try
  5526. {
  5527. string sql = string.Empty;
  5528. string Identification = Guid.NewGuid().ToString();
  5529. foreach (var item in JsonData)
  5530. {
  5531. if (string.IsNullOrEmpty(item.LotNo))
  5532. {
  5533. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  5534. }
  5535. string errorMessage = string.Format(language.GetNameByCode("WMSAPIInfo470"), item.LotNo);
  5536. //验证仓库库位信息
  5537. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  5538. BEGIN
  5539. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  5540. RETURN
  5541. END
  5542. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  5543. BEGIN
  5544. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  5545. RETURN
  5546. END
  5547. IF NOT EXISTS(SELECT a.ID
  5548. FROM ICSWareHouse a
  5549. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  5550. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  5551. BEGIN
  5552. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  5553. RETURN
  5554. END
  5555. IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND a.LockQuantity=0 AND a.LotNO='{4}')
  5556. BEGIN
  5557. RAISERROR('{3}',16,1);
  5558. RETURN
  5559. END";
  5560. sql = string.Format(sql, item.WarehouseCode, item.WorkPoint, item.LocationCode, errorMessage,item.LotNo);
  5561. DBHelper.ExecuteNonQuery(sql, cmd);
  5562. //更新条码信息
  5563. ICSWareHouseLotInfoService.WareHouseLotInfoLibrary(Identification, item.TransCode, item.TransSequence, item.WarehouseCode, item.LocationCode, item.LotNo,
  5564. item.User, item.WorkPoint, "7", "29", cmd, language);
  5565. }
  5566. DataTable table = GetData(Identification, 3, cmd);
  5567. cmd.Transaction.Commit();
  5568. return table;
  5569. }
  5570. catch (Exception ex)
  5571. {
  5572. if (cmd.Transaction != null)
  5573. cmd.Transaction.Rollback();
  5574. log.Error(ex.Message);
  5575. throw new Exception(ex.Message);
  5576. }
  5577. finally
  5578. {
  5579. if (conn.State == ConnectionState.Open)
  5580. {
  5581. conn.Close();
  5582. }
  5583. conn.Dispose();
  5584. }
  5585. }
  5586. }
  5587. #endregion
  5588. #region 合并
  5589. /// <summary>
  5590. /// 合并
  5591. /// </summary>
  5592. /// <param name="JsonData"></param>
  5593. /// <returns></returns>
  5594. public static DataTable LOTMergeCreate(List<LOTCreateIModel> JsonData)
  5595. {
  5596. var language = LanguageHelper.GetName("WMSAPIInfo");
  5597. if (JsonData.Count <= 0)
  5598. {
  5599. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5600. }
  5601. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5602. {
  5603. conn.Open();
  5604. SqlTransaction sqlTran = conn.BeginTransaction();
  5605. SqlCommand cmd = new SqlCommand();
  5606. cmd.Transaction = sqlTran;
  5607. cmd.Connection = conn;
  5608. try
  5609. {
  5610. string Identification = Guid.NewGuid().ToString();
  5611. foreach (var item in JsonData)
  5612. {
  5613. if (string.IsNullOrEmpty(item.LotNo))
  5614. {
  5615. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  5616. }
  5617. else if (item.detail.Count <= 0)
  5618. {
  5619. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  5620. }
  5621. //合并前日志
  5622. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  5623. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  5624. foreach (var info in item.detail)
  5625. {
  5626. //合并前日志
  5627. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, info.CurrentLotNo, item.User, item.WorkPoint, "5",
  5628. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  5629. //更新条码信息
  5630. ICSWareHouseLotInfoService.WareHouseLotInfoMerge(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "5",
  5631. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  5632. }
  5633. //合并后日志
  5634. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  5635. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  5636. }
  5637. DataTable table = GetData(Identification, 1, cmd);
  5638. cmd.Transaction.Commit();
  5639. return table;
  5640. }
  5641. catch (Exception ex)
  5642. {
  5643. if (cmd.Transaction != null)
  5644. cmd.Transaction.Rollback();
  5645. log.Error(ex.Message);
  5646. throw new Exception(ex.Message);
  5647. }
  5648. finally
  5649. {
  5650. if (conn.State == ConnectionState.Open)
  5651. {
  5652. conn.Close();
  5653. }
  5654. conn.Dispose();
  5655. }
  5656. }
  5657. }
  5658. #endregion
  5659. #region 拆分
  5660. /// <summary>
  5661. /// 拆分
  5662. /// </summary>
  5663. /// <param name="JsonData"></param>
  5664. /// <returns></returns>
  5665. public static DataTable LOTSplitCreate(List<LOTCreateIModel> JsonData)
  5666. {
  5667. var language = LanguageHelper.GetName("WMSAPIInfo");
  5668. DataTable printTable = new DataTable();
  5669. if (JsonData.Count <= 0)
  5670. {
  5671. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  5672. }
  5673. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5674. {
  5675. conn.Open();
  5676. SqlTransaction sqlTran = conn.BeginTransaction();
  5677. SqlCommand cmd = new SqlCommand();
  5678. cmd.Transaction = sqlTran;
  5679. cmd.Connection = conn;
  5680. try
  5681. {
  5682. string Identification = Guid.NewGuid().ToString();
  5683. foreach (var item in JsonData)
  5684. {
  5685. if (string.IsNullOrEmpty(item.LotNo))
  5686. {
  5687. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  5688. }
  5689. else if (item.detail.Count <= 0)
  5690. {
  5691. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  5692. }
  5693. //拆分前日志
  5694. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  5695. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(), cmd, language);
  5696. foreach (var info in item.detail)
  5697. {
  5698. //更新条码信息
  5699. ICSWareHouseLotInfoService.WareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  5700. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  5701. }
  5702. //拆分后日志
  5703. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  5704. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  5705. }
  5706. //DataTable table = GetData(Identification, 1, cmd);
  5707. //cmd.Transaction.Commit();
  5708. //return table;
  5709. if (!printTable.Equals("{}"))
  5710. {
  5711. cmd.Transaction.Commit();
  5712. return printTable;
  5713. }
  5714. else
  5715. {
  5716. DataTable table = GetData(Identification, 1, cmd);
  5717. cmd.Transaction.Commit();
  5718. return table;
  5719. }
  5720. }
  5721. catch (Exception ex)
  5722. {
  5723. if (cmd.Transaction != null)
  5724. cmd.Transaction.Rollback();
  5725. log.Error(ex.Message);
  5726. throw new Exception(ex.Message);
  5727. }
  5728. finally
  5729. {
  5730. if (conn.State == ConnectionState.Open)
  5731. {
  5732. conn.Close();
  5733. }
  5734. conn.Dispose();
  5735. }
  5736. }
  5737. }
  5738. #endregion
  5739. /// <summary>
  5740. /// 获取出入库记录信息
  5741. /// </summary>
  5742. /// <param name="Identification"></param>
  5743. /// <param name="type">1:入库,2:出库,3:调拨</param>
  5744. /// <param name="cmd"></param>
  5745. /// <returns></returns>
  5746. private static DataTable GetData(string Identification, int type, SqlCommand cmd)
  5747. {
  5748. #region SLQ
  5749. string sql = @"SELECT log.ID,
  5750. log.TransCode,
  5751. log.TransSequence,
  5752. log.LotNo,
  5753. log.InvCode,
  5754. inv.InvName,
  5755. inv.InvStd,
  5756. log.Quantity,
  5757. inv.InvUnit,
  5758. log.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  5759. inv.AmountUnit,
  5760. {1}
  5761. ext.ProjectCode,
  5762. 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,
  5763. ext.Version,
  5764. ext.Brand,
  5765. ext.cFree1,
  5766. ext.cFree2,
  5767. ext.cFree3,
  5768. ext.cFree4,
  5769. ext.cFree5,
  5770. ext.cFree6,
  5771. ext.cFree7,
  5772. ext.cFree8,
  5773. ext.cFree9,
  5774. ext.cFree10,
  5775. type.Name AS TransType,
  5776. log.MUSER AS [User],
  5777. log.MTIME AS [MTime]
  5778. FROM ICSWareHouseLotInfoLog log
  5779. LEFT JOIN ICSType type ON type.TableCode='ICSWareHouseLotInfoLog' AND type.ColumnCode='BusinessCode' AND log.BusinessCode=type.Code AND log.WorkPoint=type.WorkPoint
  5780. INNER JOIN ICSInventoryLot lot ON log.LotNo=lot.LotNo AND log.WorkPoint=lot.WorkPoint
  5781. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  5782. INNER JOIN ICSInventory inv ON log.InvCode=inv.InvCode AND log.WorkPoint=inv.WorkPoint
  5783. {2}
  5784. LEFT JOIN ICSInventoryBatchEnable invBat ON log.InvCode=invBat.InvCode AND log.FromWarehouseCode=invBat.WHCode AND log.WorkPoint=invBat.WorkPoint
  5785. WHERE log.Identification='{0}'";
  5786. #endregion
  5787. string columns = @"log.ToWarehouseCode AS WHCode,
  5788. log.ToLocationCode AS LocationCode,
  5789. wh.WarehouseName AS WHName,
  5790. loc.LocationName AS LocationName,";
  5791. string tables = @"INNER JOIN ICSWarehouse wh ON log.ToWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  5792. INNER JOIN ICSLocation loc ON log.ToLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  5793. if (type == 2)//出库
  5794. {
  5795. columns = @"log.FromWarehouseCode AS WHCode,
  5796. log.FromLocationCode AS LocationCode,
  5797. wh.WarehouseName AS WHName,
  5798. loc.LocationName AS LocationName,";
  5799. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  5800. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  5801. }
  5802. else if (type == 3)//调拨
  5803. {
  5804. columns = @"log.FromWarehouseCode AS FromWHCode,
  5805. log.FromLocationCode,
  5806. wh.WarehouseName AS FromWHName,
  5807. loc.LocationName AS FromLocationName,
  5808. log.ToWarehouseCode AS ToWHCode,
  5809. log.ToLocationCode,
  5810. whto.WarehouseName AS ToWHName,
  5811. locto.LocationName AS ToLocationName,";
  5812. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  5813. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint
  5814. INNER JOIN ICSWarehouse whto ON log.ToWarehouseCode=whto.WarehouseCode AND log.WorkPoint=whto.WorkPoint
  5815. INNER JOIN ICSLocation locto ON log.ToLocationCode=locto.LocationCode AND log.WorkPoint=locto.WorkPoint";
  5816. }
  5817. sql = string.Format(sql, Identification, columns, tables);
  5818. return DBHelper.SQlReturnData(sql, cmd);
  5819. }
  5820. /// <summary>
  5821. /// 先进先出批次管控
  5822. /// </summary>
  5823. /// <param name="LotNo"></param>
  5824. /// <param name="WorkPoitCode"></param>
  5825. /// <param name="cmd"></param>
  5826. /// <returns></returns>
  5827. public static string CanOut(string LotNo, string WorkPoitCode, string ScanLotCode, SqlCommand cmd, Dictionary<string, string> language)
  5828. {
  5829. try
  5830. {
  5831. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  5832. string sql = @"DECLARE @CountNO INT,@Days INT
  5833. SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
  5834. SET @CountNO=(
  5835. SELECT COUNT(a.LotNO) FROM ICSWareHouseLotInfo a
  5836. INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO AND a.WorkPoint=b.WorkPoint
  5837. WHERE a.WorkPoint='{1}' AND ISNULL(a.Quantity,0)>0 AND 1=1
  5838. AND CONVERT(varchar(100), a.InDate, 23)<
  5839. (SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), x.InDate, 23)) FROM ICSWareHouseLotInfo x
  5840. INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
  5841. WHERE x.LotNO='{0}' AND x.WorkPoint='{1}' AND y.INVCode=b.INVCode AND y.ExtensionID=b.ExtensionID)
  5842. )
  5843. IF @CountNO>0
  5844. BEGIN
  5845. SELECT TOP 1 CASE a.F_ItemCode WHEN 'FIFO01' THEN '1' WHEN 'FIFO02' THEN '2' ELSE '3' END AS Type
  5846. FROM Sys_SRM_ItemsDetail a
  5847. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  5848. WHERE b.F_EnCode='FIFO' AND a.F_EnabledMark='1'
  5849. ORDER BY a.F_SortCode DESC
  5850. END
  5851. ELSE
  5852. BEGIN
  5853. SELECT @CountNO
  5854. END";
  5855. //0 - 已经是最早的批次
  5856. //1 - 不管控
  5857. //2 - 提醒
  5858. //3 - 限制
  5859. sql = string.Format(sql, LotNo, WorkPoitCode);
  5860. if (!string.IsNullOrWhiteSpace(ScanLotCode))
  5861. {
  5862. sql = sql.Replace("1=1", "a.LotNO NOT IN (" + ScanLotCode + ")");
  5863. }
  5864. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5865. if (string.IsNullOrWhiteSpace(res))
  5866. {
  5867. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  5868. }
  5869. else
  5870. return res;
  5871. }
  5872. catch (Exception ex)
  5873. {
  5874. throw new Exception(ex.Message);
  5875. }
  5876. }
  5877. /// <summary>
  5878. /// 保质期管控
  5879. /// </summary>
  5880. /// <param name="LotNo"></param>
  5881. /// <param name="WorkPoitCode"></param>
  5882. /// <param name="cmd"></param>
  5883. /// <returns></returns>
  5884. public static string Effective(string LotNo, string WorkPoitCode, SqlCommand cmd, Dictionary<string, string> language)
  5885. {
  5886. try
  5887. {
  5888. string sql = @"DECLARE @CountNO INT,@Days INT,@CurrentDays INT
  5889. SELECT @CountNO=EffectiveEnable,@Days=EffectiveDays,@CurrentDays=DATEDIFF(DAY, GETDATE(), b.ExpirationDate) FROM ICSInventory a
  5890. INNER JOIN ICSInventoryLot b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  5891. INNER JOIN ICSWareHouseLotInfo c ON b.LotNO=c.LotNO AND b.WorkPoint=c.WorkPoint
  5892. WHERE b.LotNO='{0}' AND b.WorkPoint='{1}'
  5893. IF @CountNO='1' AND @CurrentDays<0
  5894. BEGIN
  5895. SELECT TOP 1 CASE a.F_ItemCode WHEN 'Effective01' THEN '1' WHEN 'Effective02' THEN '2' ELSE '3' END AS Type
  5896. FROM Sys_SRM_ItemsDetail a
  5897. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  5898. WHERE b.F_EnCode='Effective' AND a.F_EnabledMark='1'
  5899. ORDER BY a.F_SortCode DESC
  5900. END
  5901. ELSE
  5902. BEGIN
  5903. SELECT @CountNO
  5904. END";
  5905. //0 - 已经是最早的批次
  5906. //1 - 不管控
  5907. //2 - 提醒
  5908. //3 - 限制
  5909. sql = string.Format(sql, LotNo, WorkPoitCode);
  5910. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  5911. if (string.IsNullOrWhiteSpace(res))
  5912. {
  5913. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  5914. }
  5915. else
  5916. return res;
  5917. }
  5918. catch (Exception ex)
  5919. {
  5920. throw new Exception(ex.Message);
  5921. }
  5922. }
  5923. #region 包装
  5924. /// <summary>
  5925. /// 查询包装信息
  5926. /// </summary>
  5927. /// <param name="JsonData"></param>
  5928. /// <returns></returns>
  5929. public static object ContainerGet(ICSContainer JsonData)
  5930. {
  5931. var language = LanguageHelper.GetName("WMSAPIInfo");
  5932. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5933. {
  5934. conn.Open();
  5935. SqlTransaction sqlTran = conn.BeginTransaction();
  5936. SqlCommand cmd = new SqlCommand();
  5937. cmd.Transaction = sqlTran;
  5938. cmd.Connection = conn;
  5939. try
  5940. {
  5941. string sql = string.Empty;
  5942. //目标包装
  5943. if (JsonData.ToContainerCode != null)
  5944. {
  5945. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  5946. BEGIN
  5947. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  5948. RETURN
  5949. END
  5950. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  5951. sql = string.Format(sql, JsonData.ToContainerCode, JsonData.WorkPoint);
  5952. }
  5953. ///原包装
  5954. else if (JsonData.FromContainerCode != null)
  5955. {
  5956. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  5957. BEGIN
  5958. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  5959. RETURN
  5960. END
  5961. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  5962. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  5963. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  5964. BEGIN
  5965. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  5966. RETURN
  5967. END
  5968. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  5969. sql = string.Format(sql, JsonData.FromContainerCode, JsonData.WorkPoint);
  5970. }
  5971. else
  5972. {
  5973. throw new Exception(language.GetNameByCode("WMSAPIInfo029"));//"请传入包装条码!");
  5974. }
  5975. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  5976. cmd.Transaction.Commit();
  5977. return table;
  5978. }
  5979. catch (Exception ex)
  5980. {
  5981. if (cmd.Transaction != null)
  5982. cmd.Transaction.Rollback();
  5983. log.Error(ex.Message);
  5984. throw new Exception(ex.Message);
  5985. }
  5986. finally
  5987. {
  5988. if (conn.State == ConnectionState.Open)
  5989. {
  5990. conn.Close();
  5991. }
  5992. conn.Dispose();
  5993. }
  5994. }
  5995. }
  5996. /// <summary>
  5997. /// 修改包装信息
  5998. /// </summary>
  5999. /// <param name="JsonData"></param>
  6000. /// <returns></returns>
  6001. public static DataTable ContainerUpdate(List<ICSContainer> JsonData)
  6002. {
  6003. var language = LanguageHelper.GetName("WMSAPIInfo");
  6004. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6005. {
  6006. conn.Open();
  6007. SqlTransaction sqlTran = conn.BeginTransaction();
  6008. SqlCommand cmd = new SqlCommand();
  6009. cmd.Transaction = sqlTran;
  6010. cmd.Connection = conn;
  6011. try
  6012. {
  6013. string sql = string.Empty;
  6014. string codes = string.Empty;
  6015. foreach (ICSContainer container in JsonData)
  6016. {
  6017. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  6018. BEGIN
  6019. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  6020. RETURN
  6021. END
  6022. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  6023. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  6024. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  6025. BEGIN
  6026. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  6027. RETURN
  6028. END
  6029. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{2}' and WorkPoint='{1}')
  6030. BEGIN
  6031. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  6032. RETURN
  6033. END
  6034. UPDATE b SET ContainerID=c.ID
  6035. FROM ICSContainer a
  6036. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  6037. INNER JOIN ICSContainer c ON c.ContainerCODE ='{2}' and a.WorkPoint=c.WorkPoint
  6038. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}'";
  6039. sql = string.Format(sql, container.FromContainerCode, container.WorkPoint, container.ToContainerCode);
  6040. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6041. {
  6042. throw new Exception(language.GetNameByCode("WMSAPIInfo030"));//"包装更新失败!");
  6043. }
  6044. codes += "'" + container.ToContainerCode + container.WorkPoint + "',";
  6045. }
  6046. sql = @"SELECT a.ContainerCode, a.ContainerName,b.LotNo FROM ICSContainer a
  6047. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  6048. WHERE a.ContainerCODE+a.WorkPoint IN({0})";
  6049. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  6050. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  6051. cmd.Transaction.Commit();
  6052. return table;
  6053. }
  6054. catch (Exception ex)
  6055. {
  6056. if (cmd.Transaction != null)
  6057. cmd.Transaction.Rollback();
  6058. log.Error(ex.Message);
  6059. throw new Exception(ex.Message);
  6060. }
  6061. finally
  6062. {
  6063. if (conn.State == ConnectionState.Open)
  6064. {
  6065. conn.Close();
  6066. }
  6067. conn.Dispose();
  6068. }
  6069. }
  6070. }
  6071. #endregion
  6072. #region 盘点
  6073. /// <summary>
  6074. /// 创建盘点单
  6075. /// </summary>
  6076. /// <param name="JsonData"></param>
  6077. /// <returns></returns>
  6078. public static DataTable CheckCreate(List<ICSCheck> JsonData)
  6079. {
  6080. var language = LanguageHelper.GetName("WMSAPIInfo");
  6081. if (JsonData.Count <= 0)
  6082. {
  6083. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6084. }
  6085. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6086. {
  6087. conn.Open();
  6088. SqlTransaction sqlTran = conn.BeginTransaction();
  6089. SqlCommand cmd = new SqlCommand();
  6090. cmd.Transaction = sqlTran;
  6091. cmd.Connection = conn;
  6092. try
  6093. {
  6094. string Code = string.Empty;
  6095. string sql = string.Empty;
  6096. foreach (var item in JsonData)
  6097. {
  6098. if (string.IsNullOrEmpty(item.User))
  6099. {
  6100. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  6101. }
  6102. if (string.IsNullOrEmpty(item.WorkPoint))
  6103. {
  6104. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  6105. }
  6106. //获取单号
  6107. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  6108. BEGIN
  6109. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  6110. RETURN
  6111. END
  6112. DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  6113. SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck
  6114. WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date
  6115. IF @MaxNO IS NULL
  6116. BEGIN
  6117. SELECT @date+'00001' AS Code
  6118. END
  6119. ELSE
  6120. BEGIN
  6121. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  6122. END ";
  6123. sql = string.Format(sql, item.User, item.WorkPoint);
  6124. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  6125. //创建盘点单
  6126. foreach (var itemInfo in item.detail)
  6127. {
  6128. int len = itemInfo.SelectLevel.Length;
  6129. sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE SUBSTRING(LocationCode,1,{4}) = '{1}')
  6130. BEGIN
  6131. RAISERROR('" + language.GetNameByCode("WMSAPIInfo460") + @"',16,1);
  6132. RETURN
  6133. END
  6134. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint)
  6135. SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location
  6136. FROM ICSWareHouseLotInfo a
  6137. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  6138. WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
  6139. GROUP BY b.F_Account,b.F_RealName,b.F_Location";
  6140. sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len);
  6141. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6142. {
  6143. throw new Exception(language.GetNameByCode("WMSAPIInfo031"));//"盘点单创建失败!");
  6144. }
  6145. }
  6146. }
  6147. if (string.IsNullOrWhiteSpace(Code))
  6148. {
  6149. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单单号不能为空!");
  6150. }
  6151. #region 查询返回数据
  6152. sql = @"SELECT a.ID,a.CheckCode,a.SelectLevel,
  6153. a.Quantity,
  6154. a.Amount,
  6155. a.MUSER AS [User],
  6156. a.MTIME AS [MTime]
  6157. FROM ICSCheck a
  6158. WHERE a.CheckCode='{0}'";
  6159. sql = string.Format(sql, Code);
  6160. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6161. #endregion
  6162. cmd.Transaction.Commit();
  6163. return data;
  6164. }
  6165. catch (Exception ex)
  6166. {
  6167. if (cmd.Transaction != null)
  6168. cmd.Transaction.Rollback();
  6169. log.Error(ex.Message);
  6170. throw new Exception(ex.Message);
  6171. }
  6172. finally
  6173. {
  6174. if (conn.State == ConnectionState.Open)
  6175. {
  6176. conn.Close();
  6177. }
  6178. conn.Dispose();
  6179. }
  6180. }
  6181. }
  6182. /// <summary>
  6183. /// 盘点扫描
  6184. /// </summary>
  6185. /// <param name="JsonData"></param>
  6186. /// <returns></returns>
  6187. public static DataTable LOTCheckCreate(List<ICSCheck> JsonData)
  6188. {
  6189. var language = LanguageHelper.GetName("WMSAPIInfo");
  6190. if (JsonData.Count <= 0)
  6191. {
  6192. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6193. }
  6194. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6195. {
  6196. conn.Open();
  6197. SqlTransaction sqlTran = conn.BeginTransaction();
  6198. SqlCommand cmd = new SqlCommand();
  6199. cmd.Transaction = sqlTran;
  6200. cmd.Connection = conn;
  6201. try
  6202. {
  6203. string lots = string.Empty;
  6204. string sql = string.Empty;
  6205. int result = 0;
  6206. string Identification = Guid.NewGuid().ToString();
  6207. foreach (var item in JsonData)
  6208. {
  6209. if (string.IsNullOrEmpty(item.User))
  6210. {
  6211. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  6212. }
  6213. if (string.IsNullOrEmpty(item.WorkPoint))
  6214. {
  6215. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  6216. }
  6217. if (string.IsNullOrEmpty(item.CheckCode))
  6218. {
  6219. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单号不能为空!");
  6220. }
  6221. //校验
  6222. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  6223. BEGIN
  6224. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  6225. RETURN
  6226. END
  6227. IF NOT EXISTS(SELECT ID FROM ICSCheck WHERE CheckCode='{2}' AND WorkPoint='{1}')
  6228. BEGIN
  6229. RAISERROR('" + language.GetNameByCode("WMSAPIInfo075") + @"',16,1);
  6230. RETURN
  6231. END";
  6232. sql = string.Format(sql, item.User, item.WorkPoint, item.CheckCode);
  6233. DBHelper.ExecuteNonQuery(sql, cmd);
  6234. //创建盘点单
  6235. foreach (var itemInfo in item.detail)
  6236. {
  6237. sql = @"IF NOT EXISTS(SELECT LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{1}' AND WorkPoint='{3}')
  6238. BEGIN
  6239. RAISERROR('" + language.GetNameByCode("WMSAPIInfo076") + @"',16,1);
  6240. RETURN
  6241. END
  6242. IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  6243. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  6244. WHERE b.CheckCode='{0}' AND a.LotNo='{1}' AND a.WorkPoint='{3}')
  6245. BEGIN
  6246. IF ('{5}'='')
  6247. BEGIN
  6248. UPDATE a SET PrimaryQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  6249. FROM ICSCheckDetail a
  6250. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  6251. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  6252. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  6253. END
  6254. ELSE IF ('{5}'='')
  6255. BEGIN
  6256. UPDATE a SET CheckQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  6257. FROM ICSCheckDetail a
  6258. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  6259. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  6260. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  6261. END
  6262. ELSE
  6263. BEGIN
  6264. UPDATE a SET ReplayQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  6265. FROM ICSCheckDetail a
  6266. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  6267. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  6268. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  6269. END
  6270. END
  6271. ELSE
  6272. BEGIN
  6273. IF ('{5}'='')
  6274. BEGIN
  6275. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  6276. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','{4}','0','0','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  6277. FROM ICSWareHouseLotInfo a
  6278. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  6279. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  6280. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  6281. END
  6282. ELSE IF ('{5}'='')
  6283. BEGIN
  6284. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  6285. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','0','0','{4}','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  6286. FROM ICSWareHouseLotInfo a
  6287. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  6288. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  6289. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  6290. END
  6291. ELSE
  6292. BEGIN
  6293. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  6294. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','{4}','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  6295. FROM ICSWareHouseLotInfo a
  6296. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  6297. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  6298. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  6299. END
  6300. END";
  6301. sql = string.Format(sql, item.CheckCode, itemInfo.LotNo, item.User, item.WorkPoint, itemInfo.ActualQuantity, item.CheckKind);
  6302. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6303. {
  6304. throw new Exception(language.GetNameByCode("WMSAPIInfo033"));//"盘点扫描创建失败!");
  6305. }
  6306. #region 更新ICSCheckDetail表
  6307. //string strSql = @"UPDATE ICSCheckDetail Set";
  6308. //if (item.CheckKind == "初盘")
  6309. // strSql += @" PrimaryQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  6310. //else if (item.CheckKind == "复盘")
  6311. // strSql += @" ReplayQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  6312. //else
  6313. // strSql += @" CheckQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  6314. //strSql += @" where ToCheckNO='" + item.CheckCode + "' AND WorkPoint='" + item.WorkPoint + "'";
  6315. //cmd.CommandText = strSql;
  6316. //result = cmd.ExecuteNonQuery();
  6317. //if (result <= 0)
  6318. //{
  6319. // throw new Exception(language.GetNameByCode("WMSAPIInfo296"));//"盘点子表数量增加失败!");
  6320. //}
  6321. #endregion
  6322. #region 更新库存
  6323. if (item.UpdateWHLI)
  6324. {
  6325. ICSWareHouseLotInfoService.WareHouseLotInfoUpdate(Identification, item.CheckCode, "", itemInfo.LotNo, itemInfo.ActualQuantity, item.User, item.WorkPoint, TransTypeEnum.Check.GetDescription<DBValue>(), item.CheckKind, cmd, language);
  6326. }
  6327. #endregion
  6328. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  6329. }
  6330. if (string.IsNullOrWhiteSpace(lots))
  6331. {
  6332. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  6333. }
  6334. //sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  6335. // FROM ICSCheck a
  6336. // 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
  6337. // WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  6338. //sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  6339. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  6340. //{
  6341. // throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  6342. //}
  6343. }
  6344. #region 查询返回数据
  6345. sql = @"SELECT x.ID,x.CheckID,y.WarehouseCode AS WHCode,x.LotNo,
  6346. y.InvCode,
  6347. inv.InvName,
  6348. inv.InvStd,
  6349. x.Quantity,x.PrimaryQuantity,x.PrimaryAmount,x.ReplayQuantity,x.ReplayAmount,x.CheckQuantity,x.CheckAmount,
  6350. inv.InvUnit,
  6351. x.MUSER AS [User],
  6352. x.MTIME AS [MTime]
  6353. FROM ICSCheckDetail x
  6354. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  6355. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  6356. WHERE x.LotNo+x.WorkPoint IN ({0})";
  6357. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  6358. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6359. #endregion
  6360. cmd.Transaction.Commit();
  6361. return data;
  6362. }
  6363. catch (Exception ex)
  6364. {
  6365. if (cmd.Transaction != null)
  6366. cmd.Transaction.Rollback();
  6367. log.Error(ex.Message);
  6368. throw new Exception(ex.Message);
  6369. }
  6370. finally
  6371. {
  6372. if (conn.State == ConnectionState.Open)
  6373. {
  6374. conn.Close();
  6375. }
  6376. conn.Dispose();
  6377. }
  6378. }
  6379. }
  6380. #endregion
  6381. #region 多语言
  6382. /// <summary>
  6383. /// 多语言查询
  6384. /// </summary>
  6385. /// <param name="JsonData"></param>
  6386. /// <returns></returns>
  6387. public static DataTable PromptInformationGet(WMSBarCoreModel JsonData)
  6388. {
  6389. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6390. {
  6391. conn.Open();
  6392. SqlCommand cmd = new SqlCommand();
  6393. cmd.Connection = conn;
  6394. try
  6395. {
  6396. string DefiniteLanguage = ICSDefiniteLanguageService.GetLanguage();
  6397. string sql = @"select " + DefiniteLanguage + " AS Name,Code from Sys_Language where 1=1";
  6398. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  6399. {
  6400. sql += " and Code LIKE '%{0}%'";
  6401. }
  6402. sql = string.Format(sql, JsonData.Code);
  6403. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6404. return data;
  6405. }
  6406. catch (Exception ex)
  6407. {
  6408. log.Error(ex.Message);
  6409. throw new Exception(ex.Message);
  6410. }
  6411. finally
  6412. {
  6413. if (conn.State == ConnectionState.Open)
  6414. {
  6415. conn.Close();
  6416. }
  6417. conn.Dispose();
  6418. }
  6419. }
  6420. }
  6421. #endregion
  6422. #region 仓库/库位
  6423. /// <summary>
  6424. /// 仓库/库位
  6425. /// </summary>
  6426. /// <param name="JsonData"></param>
  6427. /// <returns></returns>
  6428. public static DataTable LocationGet(ICSLocation JsonData)
  6429. {
  6430. var language = LanguageHelper.GetName("WMSAPIInfo");
  6431. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6432. {
  6433. conn.Open();
  6434. SqlTransaction sqlTran = conn.BeginTransaction();
  6435. SqlCommand cmd = new SqlCommand();
  6436. cmd.Transaction = sqlTran;
  6437. cmd.Connection = conn;
  6438. try
  6439. {
  6440. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode='{0}' AND a.WorkPoint='{1}')
  6441. BEGIN
  6442. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  6443. RETURN
  6444. END
  6445. 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}')
  6446. BEGIN
  6447. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  6448. RETURN
  6449. END
  6450. 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')
  6451. BEGIN
  6452. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  6453. RETURN
  6454. END
  6455. SELECT
  6456. LocationCode,
  6457. LocationName ,
  6458. WarehouseCode,
  6459. WarehouseName
  6460. FROM ICSLocation a
  6461. 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'";
  6462. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  6463. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  6464. cmd.Transaction.Commit();
  6465. return data;
  6466. }
  6467. catch (Exception ex)
  6468. {
  6469. if (cmd.Transaction != null)
  6470. cmd.Transaction.Rollback();
  6471. log.Error(ex.Message);
  6472. throw new Exception(ex.Message);
  6473. }
  6474. finally
  6475. {
  6476. if (conn.State == ConnectionState.Open)
  6477. {
  6478. conn.Close();
  6479. }
  6480. conn.Dispose();
  6481. }
  6482. }
  6483. }
  6484. #endregion
  6485. #region 登陆
  6486. public static object CheckLogin(Sys_SRM_User userModel)
  6487. {
  6488. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6489. {
  6490. conn.Open();
  6491. SqlCommand cmd = new SqlCommand();
  6492. cmd.Connection = conn;
  6493. try
  6494. {
  6495. string sql = @"select F_Account from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  6496. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  6497. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  6498. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  6499. {
  6500. sql = @" select a.[F_Id] as UserId
  6501. ,[F_Account] as userCode
  6502. ,[F_RealName] as UserName
  6503. ,[F_NickName]
  6504. ,b.F_UserPassword
  6505. ,b.F_UserSecretkey
  6506. ,[F_HeadIcon]
  6507. ,[F_Gender]
  6508. ,[F_Birthday]
  6509. ,[F_MobilePhone]
  6510. ,[F_Email]
  6511. ,[F_WeChat]
  6512. ,[F_ManagerId]
  6513. ,[F_SecurityLevel]
  6514. ,[F_Signature]
  6515. ,[F_OrganizeId]
  6516. ,[F_DepartmentId]
  6517. ,[F_RoleId]
  6518. ,[F_DutyId]
  6519. ,[F_IsAdministrator]
  6520. ,[F_SortCode]
  6521. ,[F_DeleteMark]
  6522. ,[F_EnabledMark]
  6523. ,[F_Description]
  6524. ,[F_CreatorTime]
  6525. ,[F_CreatorUserId]
  6526. ,[F_LastModifyTime]
  6527. ,[F_LastModifyUserId]
  6528. ,[F_DeleteTime]
  6529. ,[F_DeleteUserId]
  6530. ,[F_Location] as WorkPoint
  6531. ,[F_VenCode]
  6532. from Sys_SRM_User a
  6533. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  6534. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  6535. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  6536. dt = DBHelper.SQlReturnData(sql, cmd);
  6537. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  6538. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  6539. foreach (var item in users)
  6540. {
  6541. //string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
  6542. string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  6543. if (dbPassword == item.F_UserPassword)
  6544. {
  6545. string json = JsonConvert.SerializeObject(dt);
  6546. List<Sys_SRM_User> userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  6547. return userLogOnEntity;
  6548. }
  6549. else
  6550. {
  6551. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI004"));//"密码不正确,请重新输入");
  6552. }
  6553. }
  6554. }
  6555. else
  6556. {
  6557. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI005"));//"用户名不存在,请重新输入!");
  6558. }
  6559. return null;
  6560. }
  6561. catch (Exception ex)
  6562. {
  6563. log.Error(ex.Message);
  6564. throw new Exception(ex.Message);
  6565. }
  6566. finally
  6567. {
  6568. if (conn.State == ConnectionState.Open)
  6569. {
  6570. conn.Close();
  6571. }
  6572. conn.Dispose();
  6573. }
  6574. }
  6575. }
  6576. #endregion
  6577. #region 用户确认
  6578. public static object UserCheck(Sys_SRM_User userModel)
  6579. {
  6580. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6581. {
  6582. conn.Open();
  6583. SqlCommand cmd = new SqlCommand();
  6584. cmd.Connection = conn;
  6585. try
  6586. {
  6587. string sql = @"select F_Account from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  6588. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  6589. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  6590. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  6591. {
  6592. sql = @" select a.[F_Id] as UserId
  6593. ,[F_Account] as userCode
  6594. ,[F_RealName] as UserName
  6595. ,[F_NickName]
  6596. ,b.F_UserPassword
  6597. ,b.F_UserSecretkey
  6598. ,[F_HeadIcon]
  6599. ,[F_Gender]
  6600. ,[F_Birthday]
  6601. ,[F_MobilePhone]
  6602. ,[F_Email]
  6603. ,[F_WeChat]
  6604. ,[F_ManagerId]
  6605. ,[F_SecurityLevel]
  6606. ,[F_Signature]
  6607. ,[F_OrganizeId]
  6608. ,[F_DepartmentId]
  6609. ,[F_RoleId]
  6610. ,[F_DutyId]
  6611. ,[F_IsAdministrator]
  6612. ,[F_SortCode]
  6613. ,[F_DeleteMark]
  6614. ,[F_EnabledMark]
  6615. ,[F_Description]
  6616. ,[F_CreatorTime]
  6617. ,[F_CreatorUserId]
  6618. ,[F_LastModifyTime]
  6619. ,[F_LastModifyUserId]
  6620. ,[F_DeleteTime]
  6621. ,[F_DeleteUserId]
  6622. ,[F_Location] as WorkPoint
  6623. ,[F_VenCode]
  6624. from Sys_SRM_User a
  6625. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  6626. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  6627. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  6628. dt = DBHelper.SQlReturnData(sql, cmd);
  6629. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  6630. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  6631. foreach (var item in users)
  6632. {
  6633. string json = JsonConvert.SerializeObject(dt);
  6634. List<Sys_SRM_User> userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  6635. return userLogOnEntity;
  6636. }
  6637. }
  6638. else
  6639. {
  6640. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI005"));//"用户名不存在,请重新输入!");
  6641. }
  6642. return null;
  6643. }
  6644. catch (Exception ex)
  6645. {
  6646. log.Error(ex.Message);
  6647. throw new Exception(ex.Message);
  6648. }
  6649. finally
  6650. {
  6651. if (conn.State == ConnectionState.Open)
  6652. {
  6653. conn.Close();
  6654. }
  6655. conn.Dispose();
  6656. }
  6657. }
  6658. }
  6659. #endregion
  6660. #region 获取调拨单
  6661. /// <summary>
  6662. /// 获取未发,未发完调拨单
  6663. /// </summary>
  6664. /// <param name="JsonData"></param>
  6665. /// <returns></returns>
  6666. public static DataTable TransCodemationGet(TransferDoc JsonData)
  6667. {
  6668. var language = LanguageHelper.GetName("WMSAPIInfo");
  6669. if (JsonData == null)
  6670. {
  6671. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  6672. }
  6673. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6674. {
  6675. conn.Open();
  6676. SqlTransaction sqlTran = conn.BeginTransaction();
  6677. SqlCommand cmd = new SqlCommand();
  6678. cmd.Transaction = sqlTran;
  6679. cmd.Connection = conn;
  6680. try
  6681. {
  6682. string Workpoint = "";
  6683. Workpoint = JsonData.WorkPoint;
  6684. string sql = @"SELECT DISTINCT TransferNO as TransCode FROM ICSTransferApplication
  6685. WHERE WorkPoint='{0}' AND Quantity>ISNULL(TransferQuantity, 0) order by TransferNO desc";
  6686. sql = string.Format(sql, Workpoint);
  6687. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  6688. return table;
  6689. }
  6690. catch (Exception ex)
  6691. {
  6692. if (cmd.Transaction != null)
  6693. cmd.Transaction.Rollback();
  6694. log.Error(ex.Message);
  6695. throw new Exception(ex.Message);
  6696. }
  6697. finally
  6698. {
  6699. if (conn.State == ConnectionState.Open)
  6700. {
  6701. conn.Close();
  6702. }
  6703. conn.Dispose();
  6704. }
  6705. }
  6706. }
  6707. #endregion
  6708. #region 料架条码绑定/解绑
  6709. /// <summary>
  6710. /// 料架条码绑定
  6711. /// </summary>
  6712. /// <param name="JsonData"></param>
  6713. /// <returns></returns>
  6714. public static Result ContainerBindCreate(List<ICSContainerBind> JsonData)
  6715. {
  6716. var language = LanguageHelper.GetName("WMSAPIInfo");
  6717. DataTable table = new DataTable();
  6718. string msg = "";
  6719. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6720. {
  6721. conn.Open();
  6722. SqlCommand cmd = new SqlCommand();
  6723. cmd.Connection = conn;
  6724. try
  6725. {
  6726. Result res = new Result();
  6727. foreach (ICSContainerBind item in JsonData)
  6728. {
  6729. string TransType = item.TransType;
  6730. if (JsonData.Count <= 0)
  6731. {
  6732. msg = string.Format(language.GetNameByCode("WMSAPIInfo007"));//"传入数据为空!"
  6733. }
  6734. if (String.IsNullOrEmpty(item.WorkPoint))
  6735. {
  6736. msg = string.Format(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  6737. }
  6738. if (String.IsNullOrEmpty(item.LotNo))
  6739. {
  6740. msg = string.Format(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  6741. }
  6742. if (String.IsNullOrEmpty(item.ContainerCode))
  6743. {
  6744. msg = string.Format(language.GetNameByCode("WMSAPIInfo197"));//"料架不能为空!"
  6745. }
  6746. if (TransType != TransTypeEnum.ContainerBind.GetDescription() && TransType != TransTypeEnum.ContainerUnBind.GetDescription())
  6747. {
  6748. msg = string.Format(language.GetNameByCode("WMSAPIInfo199"));//"操作类型错误!"
  6749. }
  6750. if (item.ContainerType == "窄巷道叉车(木托盘)" && item.RecomendBinCode == "")
  6751. {
  6752. msg = string.Format(language.GetNameByCode("WMSAPIInfo203"));//"推荐库位不能为空!"
  6753. }
  6754. if (item.LocationCode == "" && item.ContainerType != "窄巷道叉车(木托盘)")
  6755. {
  6756. msg = string.Format(language.GetNameByCode("WMSAPIInfo206"));//"位置编码不能为空!"
  6757. }
  6758. if (msg != "")
  6759. {
  6760. res.Success = false;
  6761. res.Message = msg;// "接口调用失败!";
  6762. return res;
  6763. }
  6764. else
  6765. {
  6766. if (TransType == TransTypeEnum.ContainerBind.GetDescription())
  6767. {
  6768. //料架条码绑定
  6769. ICSWareHouseLotInfoService.ContainerBind(item.LotNo, item.ContainerCode, item.ContainerType, item.LocationCode, item.RecomendBinCode, item.User, item.WorkPoint, cmd, language);
  6770. }
  6771. else
  6772. {
  6773. //料架条码解绑
  6774. ICSWareHouseLotInfoService.ContainerUnBind(item.ContainerCode, item.WorkPoint, cmd, language);
  6775. }
  6776. }
  6777. }
  6778. res.Success = true;
  6779. res.Message = msg;// "接口调用成功!";
  6780. return res;
  6781. }
  6782. catch (Exception ex)
  6783. {
  6784. if (cmd.Transaction != null)
  6785. cmd.Transaction.Rollback();
  6786. log.Error(ex.Message);
  6787. throw new Exception(ex.Message);
  6788. }
  6789. finally
  6790. {
  6791. if (conn.State == ConnectionState.Open)
  6792. {
  6793. conn.Close();
  6794. }
  6795. conn.Dispose();
  6796. }
  6797. }
  6798. }
  6799. #endregion
  6800. #region 通知AGV搬运
  6801. public static Result StartAGVTask(List<ICSContainerBind> JsonData)
  6802. {
  6803. var language = LanguageHelper.GetName("WMSAPIInfo");
  6804. DataTable table = new DataTable();
  6805. string msg = "";
  6806. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6807. {
  6808. conn.Open();
  6809. SqlCommand cmd = new SqlCommand();
  6810. cmd.Connection = conn;
  6811. try
  6812. {
  6813. Result res = new Result();
  6814. foreach (ICSContainerBind item in JsonData)
  6815. {
  6816. string TransType = item.TransType;
  6817. if (JsonData.Count <= 0)
  6818. {
  6819. msg = string.Format(language.GetNameByCode("WMSAPIInfo007"));//"传入数据为空!"
  6820. }
  6821. if (String.IsNullOrEmpty(item.WorkPoint))
  6822. {
  6823. msg = string.Format(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  6824. }
  6825. if (item.LocationCode == "")
  6826. {
  6827. msg = string.Format(language.GetNameByCode("WMSAPIInfo206"));//"位置编码不能为空!"
  6828. }
  6829. if (msg != "")
  6830. {
  6831. res.Success = false;
  6832. res.Message = msg;// "接口调用失败!";
  6833. return res;
  6834. }
  6835. else
  6836. {
  6837. //呼叫AGV开始搬运任务
  6838. ICSWareHouseLotInfoService.CallAGVStartTask(item.ContainerCode, item.TransType, item.LocationCode, item.User, item.WorkPoint, cmd, language);
  6839. }
  6840. }
  6841. res.Success = true;
  6842. res.Message = msg;// "接口调用成功!";
  6843. return res;
  6844. }
  6845. catch (Exception ex)
  6846. {
  6847. if (cmd.Transaction != null)
  6848. cmd.Transaction.Rollback();
  6849. log.Error(ex.Message);
  6850. throw new Exception(ex.Message);
  6851. }
  6852. finally
  6853. {
  6854. if (conn.State == ConnectionState.Open)
  6855. {
  6856. conn.Close();
  6857. }
  6858. conn.Dispose();
  6859. }
  6860. }
  6861. }
  6862. #endregion
  6863. #region 获取AGV绑定接口地址
  6864. public static string GetAGVBindUrl()
  6865. {
  6866. try
  6867. {
  6868. return ERPUrl.AGVBineURL;
  6869. }
  6870. catch (Exception ex)
  6871. {
  6872. throw new Exception(ex.Message);
  6873. }
  6874. }
  6875. #endregion
  6876. #region 获取AGV搬运接口地址
  6877. public static string GetAGVStartUrl()
  6878. {
  6879. try
  6880. {
  6881. return ERPUrl.AGVTaskStart;
  6882. }
  6883. catch (Exception ex)
  6884. {
  6885. throw new Exception(ex.Message);
  6886. }
  6887. }
  6888. #endregion
  6889. #region 获取AGV搬运的目标位置
  6890. public static Result GetAGVTaskPosition(List<ICSContainerBind> JsonData)
  6891. {
  6892. var language = LanguageHelper.GetName("WMSAPIInfo");
  6893. DataTable table = new DataTable();
  6894. string msg = "";
  6895. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6896. {
  6897. conn.Open();
  6898. SqlCommand cmd = new SqlCommand();
  6899. cmd.Connection = conn;
  6900. try
  6901. {
  6902. Result res = new Result();
  6903. string PostionCode = "";
  6904. foreach (ICSContainerBind item in JsonData)
  6905. {
  6906. string TransType = item.TransType;
  6907. if (JsonData.Count <= 0)
  6908. {
  6909. msg = string.Format(language.GetNameByCode("WMSAPIInfo007"));//"传入数据为空!"
  6910. }
  6911. if (String.IsNullOrEmpty(item.WorkPoint))
  6912. {
  6913. msg = string.Format(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  6914. }
  6915. if (item.LocationCode == "")
  6916. {
  6917. msg = string.Format(language.GetNameByCode("WMSAPIInfo206"));//"位置编码不能为空!"
  6918. }
  6919. if (msg != "")
  6920. {
  6921. res.Success = false;
  6922. res.Message = msg;// "接口调用失败!";
  6923. return res;
  6924. }
  6925. else
  6926. {
  6927. //呼叫AGV开始搬运任务
  6928. PostionCode = ICSWareHouseLotInfoService.GetAGVTaskPosition(item.LocationCode, item.User, item.WorkPoint, cmd, language);
  6929. }
  6930. }
  6931. res.Success = true;
  6932. res.Message = PostionCode;// "接口调用成功!";
  6933. return res;
  6934. }
  6935. catch (Exception ex)
  6936. {
  6937. if (cmd.Transaction != null)
  6938. cmd.Transaction.Rollback();
  6939. log.Error(ex.Message);
  6940. throw new Exception(ex.Message);
  6941. }
  6942. finally
  6943. {
  6944. if (conn.State == ConnectionState.Open)
  6945. {
  6946. conn.Close();
  6947. }
  6948. conn.Dispose();
  6949. }
  6950. }
  6951. }
  6952. #endregion
  6953. #region 形态转换源头单据信息
  6954. /// <summary>
  6955. /// 形态转换源头单据信息
  6956. /// </summary>
  6957. /// <param name="JsonData"></param>
  6958. /// <returns></returns>
  6959. public static DataTable MTTransInformationGet(WMSSourceDocumentModel JsonData)
  6960. {
  6961. var language = LanguageHelper.GetName("WMSAPIInfo");
  6962. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  6963. {
  6964. conn.Open();
  6965. SqlCommand cmd = new SqlCommand();
  6966. cmd.Connection = conn;
  6967. try
  6968. {
  6969. if (string.IsNullOrEmpty(JsonData.TransCode))
  6970. {
  6971. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  6972. }
  6973. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  6974. {
  6975. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  6976. }
  6977. string information = String.Format(language.GetNameByCode("WMSAPIInfo035"), "", "", "", JsonData.TransCode);
  6978. #region SLQ
  6979. string sql = $@"IF NOT EXISTS(SELECT a.ID FROM ICSMTDOC a WHERE a.MTDOCCode= '{JsonData.TransCode}'
  6980. AND a.WorkPoint= '{JsonData.WorkPoint}')
  6981. BEGIN
  6982. RAISERROR('{information}',16,1);
  6983. RETURN
  6984. END ;
  6985. SELECT a.ID,
  6986. a.MTDOCCode AS TransCode,
  6987. a.MTDOCQuantity,
  6988. a.EATTRIBUTE1 AS Type,
  6989. a.MTDOCType,
  6990. a.Sequence AS TransSequence,
  6991. a.MTDOCQuantity AS IssueQuantity,
  6992. convert(varchar(100),'') AS LocationCode,
  6993. convert(varchar(100),'') AS LotNo,
  6994. convert(varchar(10),'') AS ToWarehouseCode,
  6995. 0 AS LocationQty,
  6996. 0 AS isMatched,
  6997. a.INVCode AS InvCode,
  6998. inv.InvName,
  6999. inv.InvStd,
  7000. a.Quantity,
  7001. inv.InvUnit,
  7002. a.Amount,
  7003. a.WHCode,
  7004. inv.AmountUnit,
  7005. wh.WarehouseName AS WHName,
  7006. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  7007. a.ExtensionID,
  7008. 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,
  7009. ISNULL(ext.Version, '') AS Version,
  7010. ISNULL(ext.Brand, '') AS Brand,
  7011. ISNULL(ext.cFree1, '') AS cFree1,
  7012. ISNULL(ext.cFree2, '') AS cFree2,
  7013. ISNULL(ext.cFree3, '') AS cFree3,
  7014. ISNULL(ext.cFree4, '') AS cFree4,
  7015. ISNULL(ext.cFree5, '') AS cFree5,
  7016. ISNULL(ext.cFree6, '') AS cFree6,
  7017. ISNULL(ext.cFree7, '') AS cFree7,
  7018. ISNULL(ext.cFree8, '') AS cFree8,
  7019. ISNULL(ext.cFree9, '') AS cFree9,
  7020. ISNULL(ext.cFree10, '') AS cFree10,
  7021. a.MUSER AS [User],
  7022. a.MTIME AS [MTime]
  7023. FROM ICSMTDOC a
  7024. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  7025. INNER JOIN ICSInventory inv ON a.INVCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  7026. LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  7027. LEFT JOIN ICSInventoryBatchEnable invBat ON a.INVCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  7028. WHERE a.MTDOCCode= '{JsonData.TransCode}'
  7029. AND a.WorkPoint= '{JsonData.WorkPoint}'
  7030. AND a.MTDOCType='1' ";
  7031. #endregion
  7032. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  7033. return table;
  7034. }
  7035. catch (Exception ex)
  7036. {
  7037. log.Error(ex.Message);
  7038. throw new Exception(ex.Message);
  7039. }
  7040. finally
  7041. {
  7042. if (conn.State == ConnectionState.Open)
  7043. {
  7044. conn.Close();
  7045. }
  7046. conn.Dispose();
  7047. }
  7048. }
  7049. }
  7050. #endregion
  7051. #region 拣料信息
  7052. /// <summary>
  7053. /// 获取拣料信息
  7054. /// </summary>
  7055. /// <param name="JsonData"></param>
  7056. /// <returns></returns>
  7057. public static DataTable GetICSMOPickMergeTemp(WMSSourceDocumentModel JsonData)
  7058. {
  7059. var language = LanguageHelper.GetName("WMSAPIInfo");
  7060. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7061. {
  7062. conn.Open();
  7063. SqlCommand cmd = new SqlCommand();
  7064. cmd.Connection = conn;
  7065. try
  7066. {
  7067. if (string.IsNullOrEmpty(JsonData.TransCode))
  7068. {
  7069. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  7070. }
  7071. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  7072. {
  7073. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  7074. }
  7075. string information = String.Format(language.GetNameByCode("WMSAPIInfo035"), "", "", "", JsonData.TransCode);
  7076. #region SLQ
  7077. string sqls = "";
  7078. #region 工单领料
  7079. if (JsonData.TransType == TransTypeEnum.MOApply.GetDescription())
  7080. {
  7081. #region 工单领料SQL
  7082. sqls = @"select
  7083. 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
  7084. FROM
  7085. ICSMOApply 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.OOApply.GetDescription())
  7095. {
  7096. #region 委外领料SQL
  7097. sqls = sqls = @"select
  7098. a.ApplyCode 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. ICSOApply 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.ApplyCode in ('{0}') AND a.WorkPoint = '{1}'
  7112. GROUP BY a.ApplyCode,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.SalesShipmentDoc.GetDescription())
  7118. {
  7119. #region 销售发货SQL
  7120. sqls = @" select
  7121. a.SDNCode 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. ICSSDN 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.SDNCode in ('{0}') AND a.WorkPoint = '{1}'
  7135. GROUP BY a.SDNCode,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.OtherOutDoc.GetDescription())
  7141. {
  7142. #region 其它出库SQL
  7143. sqls = @" select
  7144. a.OutCode as Code,
  7145. a.InvCode,
  7146. b.InvName,
  7147. b.InvStd,
  7148. b.InvUnit,
  7149. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  7150. a.WhCode,
  7151. a.ExtensionID,
  7152. c.LocationCode
  7153. FROM
  7154. ICSOtherOut 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.WHCode=c.WHCode AND a.WorkPoint=c.WorkPoint
  7157. WHERE a.OutCode in ('{0}') AND a.WorkPoint = '{1}'
  7158. GROUP BY a.OutCode,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.WhCode,a.ExtensionID,c.LocationCode";
  7159. #endregion
  7160. }
  7161. #endregion
  7162. #region 物料调拨
  7163. if (JsonData.TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  7164. {
  7165. #region 物料调拨
  7166. sqls = @"select
  7167. a.TransferNO as Code,
  7168. a.InvCode,
  7169. b.InvName,
  7170. b.InvStd,
  7171. b.InvUnit,
  7172. SUM(ISNULL(a.Quantity, 0)) AS iQuantity,
  7173. a.FromWarehouseCode as WhCode,
  7174. a.ExtensionID,
  7175. c.LocationCode
  7176. FROM
  7177. ICSTransfer a
  7178. LEFT JOIN ICSINVENTORY b ON a.InvCode = b.InvCode AND a.WorkPoint=b.WorkPoint
  7179. LEFT JOIN ICSInventoryDetail c ON b.InvCode=c.INVCode AND a.FromWarehouseCode=c.WHCode AND a.WorkPoint=c.WorkPoint
  7180. WHERE a.TransferNO in ('{0}') AND a.WorkPoint = '{1}'
  7181. GROUP BY a.TransferNO,a.InvCode,b.InvName,b.InvStd,b.InvUnit,a.FromWarehouseCode,a.ExtensionID,c.LocationCode";
  7182. #endregion
  7183. }
  7184. #endregion
  7185. sqls = string.Format(sqls, JsonData.TransCode.ToString(), JsonData.WorkPoint.ToString());
  7186. #region sql
  7187. string sql = $@"SELECT row_number() over ( order by c.Code,c.InvCode,d.MTIME,d.LotNO) AS rowNo,
  7188. c.Code,
  7189. c.InvCode,
  7190. c.InvName,
  7191. c.InvStd,
  7192. c.InvUnit,
  7193. FLOOR(c.iQuantity) AS iQuantity,
  7194. c.WHCode AS WarehouseCode,
  7195. d.LotNO,
  7196. FLOOR(ISNULL(d.Quantity, 0)) AS QTY,
  7197. d.LocationCode AS LocationCode,
  7198. CONVERT(varchar(100),d.MTIME, 23) MTIME,
  7199. FLOOR(f.QTYTotal) QTYTotal
  7200. FROM
  7201. ({sqls}) c
  7202. left join (select d.WarehouseCode,d.Quantity,d.INVCode, m.LotNo, d.MTIME,d.LocationCode,m.ExtensionID
  7203. from ICSWareHouseLotInfo d ,ICSInventoryLot m
  7204. where d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  7205. and d.WorkPoint='{JsonData.WorkPoint.ToString()}' AND d.Quantity>0
  7206. --AND SUBSTRING(SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode)),0,CHARINDEX('-', SUBSTRING(d.LocationCode, CHARINDEX('-',d.LocationCode)+1, LEN(d.LocationCode))))
  7207. --Not IN(SELECT F_Define2 FROM Sys_SRM_ItemsDetail WHERE F_Define3='HGAreaConfig' AND F_Define1=d.WarehouseCode AND F_Define4=d.WorkPoint)
  7208. ) d
  7209. on c.InvCode=d.INVCode AND c.WhCode=d.WarehouseCode and d.ExtensionID=c.ExtensionID
  7210. 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
  7211. order by c.Code,c.InvCode,d.MTIME ";
  7212. #endregion
  7213. var dataset = DBHelper.SQlReturnDataSet(sql, cmd);
  7214. if (dataset.Tables.Count == 0)
  7215. return null;
  7216. DataTable table = dataset.Tables[0];
  7217. decimal qtyCount = 0;
  7218. bool remove = false;
  7219. List<int> removeList = new List<int>();
  7220. for (int i = 0; i < table.Rows.Count; i++)
  7221. {
  7222. if (i != 0
  7223. && (!table.Rows[i]["InvCode"].ToString().Equals(table.Rows[i - 1]["InvCode"].ToString())
  7224. || !table.Rows[i]["Code"].ToString().Equals(table.Rows[i - 1]["Code"].ToString()))
  7225. )
  7226. {
  7227. qtyCount = 0;
  7228. remove = false;
  7229. }
  7230. if (remove)
  7231. {
  7232. removeList.Add(i);
  7233. }
  7234. else
  7235. {
  7236. var lotQty = decimal.Parse(table.Rows[i]["QTY"].ToString());
  7237. var orderQty = decimal.Parse(table.Rows[i]["iQuantity"].ToString());
  7238. qtyCount += lotQty;
  7239. if (qtyCount >= orderQty)
  7240. {
  7241. remove = true;
  7242. }
  7243. }
  7244. }
  7245. if (removeList.Count > 0)
  7246. {
  7247. removeList.Reverse();
  7248. foreach (var item in removeList)
  7249. {
  7250. table.Rows.RemoveAt(item);
  7251. }
  7252. }
  7253. #endregion
  7254. //DataTable table = DBHelper.SQlReturnData(sql, cmd);
  7255. return table;
  7256. }
  7257. catch (Exception ex)
  7258. {
  7259. log.Error(ex.Message);
  7260. throw new Exception(ex.Message);
  7261. }
  7262. finally
  7263. {
  7264. if (conn.State == ConnectionState.Open)
  7265. {
  7266. conn.Close();
  7267. }
  7268. conn.Dispose();
  7269. }
  7270. }
  7271. }
  7272. #endregion
  7273. /// <summary>
  7274. /// 形态转换
  7275. /// <param name="JsonData"></param>
  7276. /// <returns></returns>
  7277. public static DataTable MTDocCreate(List<ICSMTDocModel> JsonData)
  7278. {
  7279. var language = LanguageHelper.GetName("WMSAPIInfo");
  7280. if (JsonData.Count <= 0)
  7281. {
  7282. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  7283. }
  7284. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7285. {
  7286. conn.Open();
  7287. SqlTransaction sqlTran = conn.BeginTransaction();
  7288. SqlCommand cmd = new SqlCommand();
  7289. cmd.Transaction = sqlTran;
  7290. cmd.Connection = conn;
  7291. string BusinessCode = string.Empty;
  7292. try
  7293. {
  7294. string TransType = string.Empty;
  7295. string Identification = Guid.NewGuid().ToString();
  7296. StringBuilder sql = new StringBuilder();
  7297. foreach (var item in JsonData)
  7298. {
  7299. string doc = $@"SELECT ExtensionID,INVCode,MTDOCType FROM ICSMTDOC a WHERE a.MTDOCCode= '{item.TransCode}' AND a.Sequence= '{item.TransSequence}' AND a.WorkPoint= '{item.WorkPoint}'";
  7300. DataTable dataTable = DBHelper.SQlReturnData(doc, cmd);
  7301. string afterInvCode = String.Empty;
  7302. string afterExtensionID = String.Empty;
  7303. string beforInvCode = String.Empty;
  7304. string beforExtensionID = String.Empty;
  7305. if (dataTable != null && dataTable.Rows.Count > 0)
  7306. {
  7307. if (dataTable.Rows[0]["MTDOCType"].ToString() == "1")
  7308. {
  7309. beforInvCode = dataTable.Rows[0]["INVCode"].ToString();
  7310. beforExtensionID = dataTable.Rows[0]["ExtensionID"].ToString();
  7311. afterInvCode = dataTable.Rows[1]["INVCode"].ToString();
  7312. afterExtensionID = dataTable.Rows[1]["ExtensionID"].ToString();
  7313. }
  7314. else
  7315. {
  7316. beforInvCode = dataTable.Rows[1]["INVCode"].ToString();
  7317. beforExtensionID = dataTable.Rows[1]["ExtensionID"].ToString();
  7318. afterInvCode = dataTable.Rows[0]["INVCode"].ToString();
  7319. afterExtensionID = dataTable.Rows[0]["ExtensionID"].ToString();
  7320. }
  7321. }
  7322. foreach (var data in item.DetailModels)
  7323. {
  7324. //修改源头单据
  7325. ICSWareHouseService.MTDoc(item.TransCode, item.TransSequence, item.User, data.Quantity, item.WorkPoint, cmd, language);
  7326. TransType = item.Type;
  7327. //单据类型 12:按单转移 13:按物料转移
  7328. if (TransType == "13")
  7329. {
  7330. //形态转换
  7331. sql.Append($@"UPDATE ICSWareHouseLotInfo SET InvCode='{afterInvCode}' WHERE LotNo='{data.LotNo}' AND WorkPoint='{item.WorkPoint}' AND InvCode='{beforInvCode}' AND WarehouseCode='{item.WHCode}';
  7332. UPDATE ICSInventoryLot SET InvCode='{afterInvCode}' WHERE LotNo='{data.LotNo}' AND InvCode='{beforInvCode}' AND WorkPoint='{item.WorkPoint}' AND ExtensionID='{beforExtensionID}';");
  7333. sql.Append($@"INSERT INTO [dbo].[ICSWareHouseLotInfoLog] ([ID], [Identification], [TransCode], [TransSequence], [LotNo], [InvCode], [FromWarehouseCode], [FromLocationCode], [ToWarehouseCode], [ToLocationCode], [Quantity], [Memo], [Lock], [TransType], [BusinessCode], [ERPUpload], [ERPID], [ERPDetailID], [ERPCode], [ERPSequence], [LogID], [MergeID], [MUSER], [MUSERName], [MTIME], [WorkPoint], [EATTRIBUTE1], [EATTRIBUTE2], [EATTRIBUTE3])
  7334. SELECT NEWID(), NEWID(), '{item.TransCode}', '{item.TransSequence}', '{data.LotNo}', '{beforInvCode}', {item.WHCode}, NULL, NULL, NULL, {data.Quantity}, NULL, '0', N'10', N'35', '0', NULL, NULL, NULL, NULL, NULL, NULL,f.F_Account ,f.F_RealName , SYSDATETIME(), '{item.WorkPoint}', NULL, NULL, '{beforExtensionID}' FROM Sys_SRM_User f WHERE f.F_Account='{item.User}' ;");
  7335. sql.Append($@"INSERT INTO [dbo].[ICSWareHouseLotInfoLog] ([ID], [Identification], [TransCode], [TransSequence], [LotNo], [InvCode], [FromWarehouseCode], [FromLocationCode], [ToWarehouseCode], [ToLocationCode], [Quantity], [Memo], [Lock], [TransType], [BusinessCode], [ERPUpload], [ERPID], [ERPDetailID], [ERPCode], [ERPSequence], [LogID], [MergeID], [MUSER], [MUSERName], [MTIME], [WorkPoint], [EATTRIBUTE1], [EATTRIBUTE2], [EATTRIBUTE3])
  7336. SELECT NEWID(), NEWID(), '{item.TransCode}', '{item.TransSequence}', '{data.LotNo}', '{afterInvCode}', {item.WHCode}, NULL, NULL, NULL, {data.Quantity}, NULL, '0', N'10', N'36', '0', NULL, NULL, NULL, NULL, NULL, NULL,f.F_Account ,f.F_RealName , SYSDATETIME(), '{item.WorkPoint}', NULL, NULL, '{beforExtensionID}' FROM Sys_SRM_User f WHERE f.F_Account='{item.User}' ;");
  7337. }
  7338. else if (TransType == "12")
  7339. {
  7340. sql.Append($@"UPDATE ICSInventoryLot SET ExtensionID='{afterExtensionID}' WHERE LotNo='{data.LotNo}' AND InvCode='{beforInvCode}' AND WorkPoint='{item.WorkPoint}' AND ExtensionID='{beforExtensionID}';");
  7341. sql.Append($@"INSERT INTO [dbo].[ICSWareHouseLotInfoLog] ([ID], [Identification], [TransCode], [TransSequence], [LotNo], [InvCode], [FromWarehouseCode], [FromLocationCode], [ToWarehouseCode], [ToLocationCode], [Quantity], [Memo], [Lock], [TransType], [BusinessCode], [ERPUpload], [ERPID], [ERPDetailID], [ERPCode], [ERPSequence], [LogID], [MergeID], [MUSER], [MUSERName], [MTIME], [WorkPoint], [EATTRIBUTE1], [EATTRIBUTE2], [EATTRIBUTE3])
  7342. SELECT NEWID(), NEWID(), '{item.TransCode}', '{item.TransSequence}', '{data.LotNo}', '{beforInvCode}', {item.WHCode}, NULL, NULL, NULL, {data.Quantity}, NULL, '0', N'10', N'35', '0', NULL, NULL, NULL, NULL, NULL, NULL,f.F_Account ,f.F_RealName , SYSDATETIME(), '{item.WorkPoint}', NULL, NULL, '{beforExtensionID}' FROM Sys_SRM_User f WHERE f.F_Account='{item.User}' ;");
  7343. sql.Append($@"INSERT INTO [dbo].[ICSWareHouseLotInfoLog] ([ID], [Identification], [TransCode], [TransSequence], [LotNo], [InvCode], [FromWarehouseCode], [FromLocationCode], [ToWarehouseCode], [ToLocationCode], [Quantity], [Memo], [Lock], [TransType], [BusinessCode], [ERPUpload], [ERPID], [ERPDetailID], [ERPCode], [ERPSequence], [LogID], [MergeID], [MUSER], [MUSERName], [MTIME], [WorkPoint], [EATTRIBUTE1], [EATTRIBUTE2], [EATTRIBUTE3])
  7344. SELECT NEWID(), NEWID(), '{item.TransCode}', '{item.TransSequence}', '{data.LotNo}', '{beforInvCode}', {item.WHCode}, NULL, NULL, NULL, {data.Quantity}, NULL, '0', N'10', N'36', '0', NULL, NULL, NULL, NULL, NULL, NULL,f.F_Account ,f.F_RealName , SYSDATETIME(), '{item.WorkPoint}', NULL, NULL, '{afterExtensionID}' FROM Sys_SRM_User f WHERE f.F_Account='{item.User}' ;");
  7345. }
  7346. else
  7347. {
  7348. throw new Exception("单据类型不存在");
  7349. }
  7350. //上传ERP
  7351. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  7352. {
  7353. ICSWareHouseService.MTDocDocERP(item.TransCode,cmd, language, item.WorkPoint);
  7354. }
  7355. }
  7356. }
  7357. DataTable table = DBHelper.SQlReturnData(sql.ToString(), cmd);
  7358. cmd.Transaction.Commit();
  7359. return table;
  7360. }
  7361. catch (Exception ex)
  7362. {
  7363. if (cmd.Transaction != null)
  7364. cmd.Transaction.Rollback();
  7365. log.Error(ex.Message);
  7366. throw new Exception(ex.Message);
  7367. }
  7368. finally
  7369. {
  7370. if (conn.State == ConnectionState.Open)
  7371. {
  7372. conn.Close();
  7373. }
  7374. conn.Dispose();
  7375. }
  7376. }
  7377. }
  7378. #region 根据源头单据获取占料信息
  7379. /// <summary>
  7380. /// 源头单据信息
  7381. /// </summary>
  7382. /// <param name="JsonData"></param>
  7383. /// <returns></returns>
  7384. public static DataTable MaterialOccupyGet(OccupyDocModel JsonData)
  7385. {
  7386. var language = LanguageHelper.GetName("WMSAPIInfo");
  7387. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7388. {
  7389. conn.Open();
  7390. SqlCommand cmd = new SqlCommand();
  7391. cmd.Connection = conn;
  7392. try
  7393. {
  7394. if (string.IsNullOrEmpty(JsonData.TransCode))
  7395. {
  7396. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  7397. }
  7398. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  7399. {
  7400. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  7401. }
  7402. string sql = @"select TransCode,TransSequence,LotNo,InvCode,Quantity from ICSWareHouseLotInfoLog
  7403. where TransType='15' AND TransCode='{0}' and WorkPoint='{1}'";
  7404. sql = string.Format(sql, JsonData.TransCode, JsonData.WorkPoint);
  7405. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  7406. if (table.Rows.Count == 0)
  7407. {
  7408. throw new Exception("单据尚未拣料,无法出库!");
  7409. }
  7410. return table;
  7411. }
  7412. catch (Exception ex)
  7413. {
  7414. log.Error(ex.Message);
  7415. throw new Exception(ex.Message);
  7416. }
  7417. finally
  7418. {
  7419. if (conn.State == ConnectionState.Open)
  7420. {
  7421. conn.Close();
  7422. }
  7423. conn.Dispose();
  7424. }
  7425. }
  7426. }
  7427. #endregion
  7428. #region 库位区域验证
  7429. /// <summary>
  7430. /// 库位区域验证
  7431. /// </summary>
  7432. /// <param name="JsonData"></param>
  7433. /// <returns></returns>
  7434. public static string CheckWHCode(BarCodeCheckModel JsonData)
  7435. {
  7436. var language = LanguageHelper.GetName("WMSAPIInfo");
  7437. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7438. {
  7439. conn.Open();
  7440. SqlCommand cmd = new SqlCommand();
  7441. cmd.Connection = conn;
  7442. try
  7443. {
  7444. if (string.IsNullOrEmpty(JsonData.TransType))
  7445. {
  7446. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  7447. }
  7448. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  7449. {
  7450. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  7451. }
  7452. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  7453. {
  7454. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  7455. }
  7456. string TransType = JsonData.TransType; //单据类型
  7457. var whCode = JsonData.LocationCode.Split('-').ToList();
  7458. #region SLQ
  7459. StringBuilder sql = new StringBuilder();
  7460. #endregion
  7461. string msg = "";
  7462. //WMSAPIInfo071
  7463. if (JsonData.TransCode == null || JsonData.TransCode == "")
  7464. {
  7465. #region 采购入库
  7466. var a = TransTypeEnum.DeliveryNotice.GetDescription();
  7467. if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  7468. {
  7469. sql.Append($@"SELECT a.LotNo ,d.LocationCode, c.WHCode
  7470. FROM
  7471. ICSInventoryLot a
  7472. inner JOIN ICSInventoryLotDetail b ON a.WorkPoint= b.WorkPoint
  7473. AND a.LotNo=b.LotNo
  7474. inner Join ICSInventoryDetail d ON d.INVCode=a.InvCode
  7475. AND d.WorkPoint=b.WorkPoint
  7476. inner JOIN ICSDeliveryNotice c ON c.DNCode= b.TransCode
  7477. AND c.WorkPoint= b.WorkPoint
  7478. AND c.InvCode= a.INVCode
  7479. AND c.Sequence= b.TransSequence
  7480. AND c.WHCode=d.WHCode
  7481. WHERE
  7482. b.WorkPoint= '{JsonData.WorkPoint}'
  7483. AND a.LotNo= '{JsonData.BarCode}'");
  7484. }
  7485. #endregion
  7486. #region 生产退料
  7487. if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  7488. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  7489. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  7490. {
  7491. sql.Append($@"SELECT a.LotNo ,d.LocationCode, c.WHCode
  7492. FROM
  7493. ICSInventoryLot a
  7494. inner JOIN ICSInventoryLotDetail b ON a.WorkPoint= b.WorkPoint
  7495. AND a.LotNo=b.LotNo
  7496. inner Join ICSInventoryDetail d ON d.INVCode=a.InvCode
  7497. AND d.WorkPoint=b.WorkPoint
  7498. inner JOIN ICSMOApplyNegDetail c ON c.ApplyNegCode= b.TransCode
  7499. AND c.WorkPoint= b.WorkPoint
  7500. AND c.InvCode= a.INVCode
  7501. AND c.Sequence= b.TransSequence
  7502. AND c.WHCode=d.WHCode
  7503. WHERE
  7504. b.WorkPoint= '{JsonData.WorkPoint}'
  7505. AND a.LotNo= '{JsonData.BarCode}'");
  7506. }
  7507. #endregion
  7508. #region 销售退货
  7509. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  7510. {
  7511. sql.Append($@"SELECT a.LotNo ,d.LocationCode, c.WHCode
  7512. FROM
  7513. ICSInventoryLot a
  7514. inner JOIN ICSInventoryLotDetail b ON a.WorkPoint= b.WorkPoint
  7515. AND a.LotNo=b.LotNo
  7516. inner Join ICSInventoryDetail d ON d.INVCode=a.InvCode
  7517. AND d.WorkPoint=b.WorkPoint
  7518. inner JOIN ICSSDN c ON c.SDNCode= b.TransCode
  7519. AND c.WorkPoint= b.WorkPoint
  7520. AND c.InvCode= a.INVCode
  7521. AND c.Sequence= b.TransSequence
  7522. AND c.WHCode=d.WHCode
  7523. WHERE
  7524. b.WorkPoint= '{JsonData.WorkPoint}'
  7525. AND a.LotNo= '{JsonData.BarCode}'");
  7526. }
  7527. #endregion
  7528. #region 其他入库
  7529. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  7530. {
  7531. sql.Append($@"SELECT a.LotNo ,d.LocationCode, c.WHCode
  7532. FROM
  7533. ICSInventoryLot a
  7534. inner JOIN ICSInventoryLotDetail b ON a.WorkPoint= b.WorkPoint
  7535. AND a.LotNo=b.LotNo
  7536. inner Join ICSInventoryDetail d ON d.INVCode=a.InvCode
  7537. AND d.WorkPoint=b.WorkPoint
  7538. inner JOIN ICSOtherIn c ON c.InCode= b.TransCode
  7539. AND c.WorkPoint= b.WorkPoint
  7540. AND c.InvCode= a.INVCode
  7541. AND c.Sequence= b.TransSequence
  7542. AND c.WHCode=d.WHCode
  7543. WHERE
  7544. b.WorkPoint= '{JsonData.WorkPoint}'
  7545. AND a.LotNo= '{JsonData.BarCode}'");
  7546. }
  7547. #endregion
  7548. }
  7549. else
  7550. {
  7551. #region 销售退货-原条码
  7552. if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  7553. {
  7554. sql.Append($@"SELECT a.LotNo ,d.LocationCode, c.WHCode
  7555. FROM
  7556. ICSInventoryLot a
  7557. inner Join ICSInventoryDetail d ON d.INVCode=a.InvCode
  7558. inner JOIN ICSSDN c ON c.InvCode= a.INVCode
  7559. AND c.WHCode=d.WHCode
  7560. AND c.Type='2'
  7561. WHERE
  7562. c.WorkPoint= '{JsonData.WorkPoint}'
  7563. AND a.LotNo= '{JsonData.BarCode}'
  7564. And c.SDNCode= '{JsonData.TransCode}' ");
  7565. }
  7566. #endregion
  7567. #region 调拨
  7568. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  7569. {
  7570. sql.Append($@"SELECT a.LotNo ,d.LocationCode, c.ToWarehouseCode as WHCode
  7571. FROM
  7572. ICSInventoryLot a
  7573. inner Join ICSInventoryDetail d ON d.INVCode=a.InvCode
  7574. inner JOIN ICSTransfer c ON c.INVCode= a.INVCode
  7575. AND c.ToWarehouseCode=d.WHCode
  7576. WHERE
  7577. c.WorkPoint= '{JsonData.WorkPoint}'
  7578. AND a.LotNo= '{JsonData.BarCode}'
  7579. And c.TransferNO= '{JsonData.TransCode}'");
  7580. }
  7581. #endregion
  7582. }
  7583. var dataset = DBHelper.SQlReturnDataSet(sql.ToString(), cmd);
  7584. if (dataset.Tables.Count == 0)
  7585. {
  7586. msg = "未查到条码库位区域信息";
  7587. return msg;
  7588. }
  7589. DataTable table = dataset.Tables[0];
  7590. if (table.Rows.Count == 0)
  7591. {
  7592. msg = "未查到条码库位区域信息";
  7593. return msg;
  7594. }
  7595. for (int i = 0; i < table.Rows.Count; i++)
  7596. {
  7597. //区域
  7598. var locationCode = table.Rows[i]["LocationCode"].ToString();
  7599. var Code = table.Rows[i]["WHCode"].ToString();
  7600. if (Code != whCode[0])
  7601. {
  7602. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo466"), Code, "", JsonData.LocationCode));
  7603. }
  7604. if (locationCode != whCode[1] && locationCode != null && locationCode != "")
  7605. {
  7606. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo465"), locationCode, "", JsonData.LocationCode));
  7607. }
  7608. }
  7609. msg = "验证成功";
  7610. return msg;
  7611. }
  7612. catch (Exception ex)
  7613. {
  7614. log.Error(ex.Message);
  7615. throw new Exception(ex.Message);
  7616. }
  7617. finally
  7618. {
  7619. if (conn.State == ConnectionState.Open)
  7620. {
  7621. conn.Close();
  7622. }
  7623. conn.Dispose();
  7624. }
  7625. }
  7626. }
  7627. #endregion
  7628. #region 根据物料 站点 仓库获取库存数量(返回物料号,销售凭证,销售凭证项号,站点,仓库,库位以及根据前面几个条件汇总的数量)
  7629. public static DataTable GetWHQuantityInfo(SAPGetWMSWHInfoModel JsonData)
  7630. {
  7631. var language = LanguageHelper.GetName("WMSAPIInfo");
  7632. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7633. {
  7634. conn.Open();
  7635. SqlCommand cmd = new SqlCommand();
  7636. cmd.Connection = conn;
  7637. try
  7638. {
  7639. if (string.IsNullOrEmpty(JsonData.INVCode) && string.IsNullOrEmpty(JsonData.WHCode) && string.IsNullOrEmpty(JsonData.WorkPoint))
  7640. {
  7641. throw new Exception("料号 工厂 库存地点至少需要传入一个!");//"单据号不能为空!"
  7642. }
  7643. string sql = @" select A.InvCode AS MATNR,ISNULL(C.ProjectCode,'') AS KDAUF,ISNULL(C.Brand,'') AS KDPOS
  7644. ,A.WorkPoint AS WERKS,A.WarehouseCode AS LGORT,A.LocationCode AS LocationCode
  7645. ,SUM(A.Quantity) AS Quantity from ICSWareHouseLotInfo A
  7646. INNER JOIN ICSInventoryLot B ON B.LotNo=A.LotNo AND B.WorkPoint=A.WorkPoint
  7647. INNER JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint
  7648. where 1=1 ";
  7649. if (!string.IsNullOrEmpty(JsonData.INVCode))
  7650. {
  7651. sql += $@" AND A.InvCode='{JsonData.INVCode}'";
  7652. }
  7653. if (!string.IsNullOrEmpty(JsonData.WHCode))
  7654. {
  7655. sql += $@" AND A.WarehouseCode='{JsonData.WHCode}'";
  7656. }
  7657. if (!string.IsNullOrEmpty(JsonData.WorkPoint))
  7658. {
  7659. sql += $@" AND A.WorkPoint='{JsonData.WorkPoint}'";
  7660. }
  7661. sql += @" GROUP BY A.InvCode,ISNULL(C.ProjectCode,''),ISNULL(C.Brand,''),A.WorkPoint,A.WarehouseCode,A.LocationCode";
  7662. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  7663. return table;
  7664. }
  7665. catch (Exception ex)
  7666. {
  7667. log.Error(ex.Message);
  7668. throw new Exception(ex.Message);
  7669. }
  7670. finally
  7671. {
  7672. if (conn.State == ConnectionState.Open)
  7673. {
  7674. conn.Close();
  7675. }
  7676. conn.Dispose();
  7677. }
  7678. }
  7679. }
  7680. #endregion
  7681. #region 根据物料 站点 仓库获取已拣配未过账数量(返回物料号,销售凭证,销售凭证项号,站点,仓库,以及根据前面几个条件汇总的数量)
  7682. public static DataTable GetWHInHandleInfo(SAPGetWMSWHInfoModel JsonData)
  7683. {
  7684. var language = LanguageHelper.GetName("WMSAPIInfo");
  7685. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  7686. {
  7687. conn.Open();
  7688. SqlCommand cmd = new SqlCommand();
  7689. cmd.Connection = conn;
  7690. try
  7691. {
  7692. if (string.IsNullOrEmpty(JsonData.INVCode) && string.IsNullOrEmpty(JsonData.WHCode) && string.IsNullOrEmpty(JsonData.WorkPoint))
  7693. {
  7694. throw new Exception("料号 工厂 库存地点至少需要传入一个!");//"单据号不能为空!"
  7695. }
  7696. string sql = @" CREATE TABLE #TEMP (DocNO nvarchar(50))
  7697. INSERT INTO #TEMP (DocNO)
  7698. SELECT ApplyCode AS DocNO
  7699. FROM ICSMOApply
  7700. GROUP BY ApplyCode
  7701. HAVING SUM(Quantity) <> SUM(IssueQuantity) AND SUM(IssueQuantity) != 0
  7702. UNION ALL
  7703. SELECT ApplyCode AS DocNO
  7704. FROM ICSOApply
  7705. GROUP BY ApplyCode
  7706. HAVING SUM(Quantity) <> SUM(IssueQuantity) AND SUM(IssueQuantity) != 0
  7707. UNION ALL
  7708. SELECT OutCode AS DocNO
  7709. FROM ICSOtherOut
  7710. GROUP BY OutCode
  7711. HAVING SUM(Quantity) <> SUM(OutQuantity) AND SUM(OutQuantity) != 0
  7712. UNION ALL
  7713. SELECT SDNCode AS DocNO
  7714. FROM ICSSDN
  7715. GROUP BY SDNCode
  7716. HAVING SUM(Quantity) <> SUM(SDNQuantity) AND SUM(SDNQuantity) != 0
  7717. UNION ALL
  7718. SELECT TransferNO AS DocNO
  7719. FROM ICSTransfer
  7720. GROUP BY TransferNO
  7721. HAVING SUM(Quantity) <> SUM(TransferQuantity) AND SUM(TransferQuantity) != 0
  7722. select A.InvCode AS MATNR,ISNULL(C.ProjectCode,'') AS KDAUF,ISNULL(C.Brand,'') AS KDPOS
  7723. ,A.WorkPoint AS WERKS,A.FromWarehouseCode AS LGORT,A.FromLocationCode AS LocationCode
  7724. ,SUM(A.Quantity) AS Quantity from ICSWareHouseLotInfoLog A
  7725. INNER JOIN ICSInventoryLot B ON B.LotNo=A.LotNo AND B.WorkPoint=A.WorkPoint
  7726. INNER JOIN ICSExtension C ON C.ID=B.ExtensionID AND C.WorkPoint=B.WorkPoint
  7727. where TransCode in (select DocNO from #temp)
  7728. and TransType=3 AND BusinessCode IN ('6','19','24','14','21') ";
  7729. if (!string.IsNullOrEmpty(JsonData.INVCode))
  7730. {
  7731. sql += $@" AND A.InvCode='{JsonData.INVCode}'";
  7732. }
  7733. if (!string.IsNullOrEmpty(JsonData.WHCode))
  7734. {
  7735. sql += $@" AND A.FromWarehouseCode='{JsonData.WHCode}'";
  7736. }
  7737. if (!string.IsNullOrEmpty(JsonData.WorkPoint))
  7738. {
  7739. sql += $@" AND A.WorkPoint='{JsonData.WorkPoint}'";
  7740. }
  7741. sql += @" GROUP BY A.InvCode,ISNULL(C.ProjectCode,''),ISNULL(C.Brand,''),A.WorkPoint,A.FromWarehouseCode,A.FromLocationCode
  7742. drop table #temp ";
  7743. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  7744. return table;
  7745. }
  7746. catch (Exception ex)
  7747. {
  7748. log.Error(ex.Message);
  7749. throw new Exception(ex.Message);
  7750. }
  7751. finally
  7752. {
  7753. if (conn.State == ConnectionState.Open)
  7754. {
  7755. conn.Close();
  7756. }
  7757. conn.Dispose();
  7758. }
  7759. }
  7760. }
  7761. #endregion
  7762. }
  7763. }