纽威

7984 lines
443 KiB

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