纽威
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5613 lines
322 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 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
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
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
2 years ago
2 years ago
3 years ago
2 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
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 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
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
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
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
2 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
3 years ago
3 years ago
3 years ago
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
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
3 years ago
3 years ago
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
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
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
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
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
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
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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
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
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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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
3 years ago
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
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
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
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
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
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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. using ICSSoft.Common;
  2. using ICSSoft.Entity;
  3. using Newtonsoft.Json;
  4. using NFine.Code;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data;
  8. using System.Data.SqlClient;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace ICSSoft.DataProject
  14. {
  15. /// <summary>
  16. /// 使用中
  17. /// 提交业务处理
  18. /// </summary>
  19. public class ICSSubmitService
  20. {
  21. private static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  22. private static string connString = System.Configuration.ConfigurationManager.AppSettings["ConnStr"];
  23. #region 源头单据信息
  24. /// <summary>
  25. /// 源头单据信息
  26. /// </summary>
  27. /// <param name="JsonData"></param>
  28. /// <returns></returns>
  29. public static DataTable TransInformationGet(WMSSourceDocumentModel JsonData)
  30. {
  31. var language = LanguageHelper.GetName("WMSAPIInfo");
  32. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  33. {
  34. conn.Open();
  35. SqlCommand cmd = new SqlCommand();
  36. cmd.Connection = conn;
  37. try
  38. {
  39. if (string.IsNullOrEmpty(JsonData.TransCode))
  40. {
  41. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  42. }
  43. else if (string.IsNullOrEmpty(JsonData.TransType))
  44. {
  45. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  46. }
  47. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  48. {
  49. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  50. }
  51. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  52. {
  53. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  54. }
  55. string TransType = JsonData.TransType;
  56. #region SLQ
  57. string sqlCheck = @"IF NOT EXISTS(SELECT a.ID FROM {1} WHERE {2})
  58. BEGIN
  59. RAISERROR('" + language.GetNameByCode("WMSAPIInfo035") + @"',16,1);
  60. RETURN
  61. END
  62. ";
  63. string sql = @"SELECT a.ID,
  64. {0}
  65. convert(varchar(100),'') AS LocationCode,
  66. convert(varchar(100),'') AS LotNo,
  67. convert(varchar(10),'') AS ToWarehouseCode,
  68. 0 AS LocationQty,
  69. 0 AS isMatched,
  70. a.InvCode,
  71. inv.InvName,
  72. inv.InvStd,
  73. a.Quantity,
  74. inv.InvUnit,
  75. a.Amount,
  76. a.WHCode,
  77. inv.AmountUnit,
  78. wh.WarehouseName AS WHName,
  79. ISNULL(ext.ProjectCode, '') AS ProjectCode,
  80. a.ExtensionID,
  81. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
  82. ISNULL(ext.Version, '') AS Version,
  83. ISNULL(ext.Brand, '') AS Brand,
  84. ISNULL(ext.cFree1, '') AS cFree1,
  85. ISNULL(ext.cFree2, '') AS cFree2,
  86. ISNULL(ext.cFree3, '') AS cFree3,
  87. ISNULL(ext.cFree4, '') AS cFree4,
  88. ISNULL(ext.cFree5, '') AS cFree5,
  89. ISNULL(ext.cFree6, '') AS cFree6,
  90. ISNULL(ext.cFree7, '') AS cFree7,
  91. ISNULL(ext.cFree8, '') AS cFree8,
  92. ISNULL(ext.cFree9, '') AS cFree9,
  93. ISNULL(ext.cFree10, '') AS cFree10,
  94. a.MUSER AS [User],
  95. a.MTIME AS [MTime]
  96. FROM {1}
  97. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  98. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  99. LEFT JOIN ICSWarehouse wh ON a.WHCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  100. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WHCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  101. WHERE {2} ";
  102. #endregion
  103. bool isDeliveryNotice = false; //送货、到货、含委外
  104. string columns = string.Empty; //查询源头单据表的特殊列名
  105. string tableName = string.Empty; //查询源头单据表名
  106. string where = string.Empty; //查询源头单据的过滤条件
  107. bool isMerge = false; //合并发料
  108. string columnsMerge = string.Empty; //合并发料查询源头单据表的特殊列名
  109. string tableNameMerge = string.Empty; //合并发料查询源头单据表名
  110. #region 出库
  111. #region 采购退货
  112. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  113. {
  114. isDeliveryNotice = true;
  115. columns = @"a.DNCode AS TransCode,
  116. a.DNDetailID AS DetailID,
  117. a.DNType AS Type,
  118. a.Sequence AS TransSequence,
  119. a.RCVQuantity AS IssueQuantity,
  120. a.Quantity,
  121. a.Amount,
  122. a.MUSER AS [User],
  123. a.MTIME AS [MTime],";
  124. tableName = @"ICSDeliveryNotice a ";
  125. where = @" a.DNCode='{0}' AND a.WorkPoint='{1}' AND a.DNType='2' ";
  126. }
  127. #endregion
  128. #region 委外发料(合并发料)
  129. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  130. {
  131. isMerge = true;
  132. columnsMerge = @"mer.MergeID+'~'+b.OOCode AS TransCode,
  133. a.PickID AS DetailID,
  134. a.SupplyType AS Type,
  135. b.Sequence+'~'+a.Sequence AS TransSequence,
  136. a.IssueQuantity AS IssueQuantity,";
  137. tableNameMerge = @"ICSOOPick a
  138. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint
  139. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  140. columns = @"b.OOCode AS TransCode,
  141. a.PickID AS DetailID,
  142. a.SupplyType AS Type,
  143. b.Sequence+'~'+a.Sequence AS TransSequence,
  144. a.IssueQuantity AS IssueQuantity,";
  145. tableName = @"ICSOOPick a
  146. INNER JOIN ICSOutsourcingOrder b ON a.OODetailID=b.OODetailID AND a.WorkPoint=b.WorkPoint ";
  147. where = @" b.OOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' ";
  148. }
  149. #endregion
  150. #region 委外退货
  151. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  152. {
  153. isDeliveryNotice = true;
  154. columns = @"a.ODNCode AS TransCode,
  155. a.ODNDetailID AS DetailID,
  156. a.ODNType AS Type,
  157. a.Sequence AS TransSequence,
  158. a.RCVQuantity AS IssueQuantity,
  159. a.Quantity,
  160. a.Amount,
  161. a.MUSER AS [User],
  162. a.MTIME AS [MTime],";
  163. tableName = @"ICSODeliveryNotice a ";
  164. where = @" a.ODNCode='{0}' AND a.WorkPoint='{1}' AND a.ODNType='2' ";
  165. }
  166. #endregion
  167. #region 生产发料(合并发料)
  168. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  169. {
  170. isMerge = true;
  171. columnsMerge = @"mer.MergeID+'~'+b.MOCode AS TransCode,
  172. a.PickID AS DetailID,
  173. a.SupplyType AS Type,
  174. b.Sequence+'~'+a.Sequence AS TransSequence,
  175. a.IssueQuantity AS IssueQuantity,";
  176. tableNameMerge = @"ICSMOPick a
  177. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint
  178. INNER JOIN ICSMOPickMerge mer ON a.PickID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  179. columns = @"b.MOCode AS TransCode,
  180. a.PickID AS DetailID,
  181. a.SupplyType AS Type,
  182. b.Sequence+'~'+a.Sequence AS TransSequence,
  183. a.IssueQuantity AS IssueQuantity,";
  184. tableName = @"ICSMOPick a
  185. INNER JOIN ICSMO b ON a.MODetailID=b.MODetailID AND a.WorkPoint=b.WorkPoint ";
  186. where = @" b.MOCode='{0}' AND a.WorkPoint='{1}' AND a.SupplyType='3' ";
  187. }
  188. #endregion
  189. #region 销售出库(合并发料)
  190. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  191. {
  192. isMerge = true;
  193. columnsMerge = @"mer.MergeID+'~'+a.SDNCode AS TransCode,
  194. a.SDNDetailID AS DetailID,
  195. a.Type,
  196. a.Sequence AS TransSequence,
  197. a.SDNQuantity AS IssueQuantity,";
  198. tableNameMerge = @"ICSSDN a
  199. INNER JOIN ICSMOPickMerge mer ON a.SDNDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  200. columns = @"a.SDNCode AS TransCode,
  201. a.SDNDetailID AS DetailID,
  202. a.Type,
  203. a.Sequence AS TransSequence,
  204. a.SDNQuantity AS IssueQuantity,";
  205. tableName = @"ICSSDN a ";
  206. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='1' ";
  207. }
  208. #endregion
  209. #region 盘点
  210. else if (TransType == TransTypeEnum.Check.GetDescription())
  211. {
  212. #region SLQ
  213. sql = @"SELECT a.ID,
  214. {0}
  215. a.Quantity,
  216. a.SelectLevel AS LocationCode,
  217. a.Amount,
  218. a.MUSER AS [User],
  219. a.MTIME AS [MTime]
  220. FROM {1}
  221. WHERE {2} ";
  222. #endregion
  223. columns = @"a.CheckCode AS TransCode,
  224. a.ID,
  225. '' AS Type,";
  226. tableName = @"ICSCheck a ";
  227. where = @" a.CheckCode='{0}' AND a.WorkPoint='{1}' ";
  228. }
  229. #endregion
  230. #region 一步调拨(合并发料)
  231. else if (TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription())
  232. {
  233. isMerge = true;
  234. columnsMerge = @"mer.MergeID+'~'+a.TransferNO AS TransCode,
  235. a.TransferDetailID AS DetailID,
  236. '' AS Type,
  237. a.Sequence AS TransSequence,
  238. a.TransferQuantity AS IssueQuantity,
  239. a.ToWarehouseCode,";
  240. tableNameMerge = @"ICSTransfer a
  241. INNER JOIN ICSMOPickMerge mer ON a.TransferDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  242. #region SLQ
  243. sql = @"SELECT a.ID,
  244. {0}
  245. convert(varchar(100),'') AS LocationCode,
  246. convert(varchar(100),'') AS LotNo,
  247. 0 AS LocationQty,
  248. 0 AS isMatched,
  249. a.InvCode,
  250. inv.InvName,
  251. inv.InvStd,
  252. a.Quantity,
  253. inv.InvUnit,
  254. a.Amount,
  255. a.FromWarehouseCode AS WHCode,
  256. inv.AmountUnit,
  257. wh.WarehouseName AS WHName,
  258. a.ExtensionID,
  259. ext.ProjectCode,
  260. CASE WHEN (invBat.BatchEnable IS NULL AND ISNULL(inv.BatchEnable, '0')='1') OR ISNULL(invBat.BatchEnable, '0')='1' THEN ISNULL(ext.BatchCode, '') ELSE '' END AS BatchCode,
  261. ext.Version,
  262. ext.Brand,
  263. ext.cFree1,
  264. ext.cFree2,
  265. ext.cFree3,
  266. ext.cFree4,
  267. ext.cFree5,
  268. ext.cFree6,
  269. ext.cFree7,
  270. ext.cFree8,
  271. ext.cFree9,
  272. ext.cFree10,
  273. a.MUSER AS [User],
  274. a.MTIME AS [MTime]
  275. FROM {1}
  276. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  277. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  278. LEFT JOIN ICSWarehouse wh ON a.FromWarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  279. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.FromWarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  280. WHERE {2} ";
  281. #endregion
  282. columns = @"a.TransferNO AS TransCode,
  283. a.TransferDetailID AS DetailID,
  284. '' AS Type,
  285. a.Sequence AS TransSequence,
  286. a.TransferQuantity AS IssueQuantity,
  287. a.ToWarehouseCode,";
  288. tableName = @"ICSTransfer a ";
  289. where = @" a.TransferNO='{0}' AND a.WorkPoint='{1}' AND a.Status='1' ";
  290. }
  291. #endregion
  292. #region 调拨(合并发料)
  293. else if (TransType == TransTypeEnum.StepTransferDocIn.GetDescription())
  294. {
  295. }
  296. #endregion
  297. #region 两步调出(合并发料)
  298. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  299. {
  300. isMerge = true;
  301. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  302. a.OutDetailID AS DetailID,
  303. '' AS Type,
  304. a.Sequence AS TransSequence,
  305. a.OutQuantity AS IssueQuantity,";
  306. tableNameMerge = @"ICSOtherOut a
  307. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint
  308. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  309. columns = @"a.OutCode AS TransCode,
  310. a.OutDetailID AS DetailID,
  311. '' AS Type,
  312. a.Sequence AS TransSequence,
  313. a.OutQuantity AS IssueQuantity,";
  314. tableName = @"ICSOtherOut a
  315. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  316. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' ";
  317. }
  318. #endregion
  319. #region 其他出库(合并发料)
  320. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  321. {
  322. isMerge = true;
  323. columnsMerge = @"mer.MergeID+'~'+a.OutCode AS TransCode,
  324. a.OutDetailID AS DetailID,
  325. '' AS Type,
  326. a.Sequence AS TransSequence,
  327. a.OutQuantity AS IssueQuantity,";
  328. tableNameMerge = @"ICSOtherOut a
  329. INNER JOIN ICSMOPickMerge mer ON a.OutDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  330. columns = @"a.OutCode AS TransCode,
  331. a.OutDetailID AS DetailID,
  332. '' AS Type,
  333. a.Sequence AS TransSequence,
  334. a.OutQuantity AS IssueQuantity,";
  335. tableName = @"ICSOtherOut a ";
  336. where = @" a.OutCode='{0}' AND a.WorkPoint='{1}' ";
  337. }
  338. #endregion
  339. #region 领料申请单发料(合并发料)
  340. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  341. {
  342. isMerge = true;
  343. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  344. a.ApplyDetailID AS DetailID,
  345. a.Type,
  346. a.Sequence AS TransSequence,
  347. a.IssueQuantity AS IssueQuantity,";
  348. tableNameMerge = @"ICSMOApply a
  349. INNER JOIN ICSMOPickMerge mer ON a.ApplyDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  350. columns = @"a.ApplyCode AS TransCode,
  351. a.ApplyDetailID AS DetailID,
  352. a.Type,
  353. a.Sequence AS TransSequence,
  354. a.IssueQuantity AS IssueQuantity,";
  355. tableName = @"ICSMOApply a ";
  356. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' ";
  357. }
  358. #endregion
  359. #region 委外领料申请单发料(合并发料)
  360. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  361. {
  362. isMerge = true;
  363. columnsMerge = @"mer.MergeID+'~'+a.ApplyCode AS TransCode,
  364. a.ApplyDetailID AS DetailID,
  365. a.Type,
  366. a.Sequence AS TransSequence,
  367. a.IssueQuantity AS IssueQuantity,";
  368. tableNameMerge = @"ICSOApply a
  369. INNER JOIN ICSMOPickMerge mer ON a.ApplyDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  370. columns = @"a.ApplyCode AS TransCode,
  371. a.ApplyDetailID AS DetailID,
  372. a.Type,
  373. a.Sequence AS TransSequence,
  374. a.IssueQuantity AS IssueQuantity,";
  375. tableName = @"ICSOApply a ";
  376. where = @" a.ApplyCode='{0}' AND a.WorkPoint='{1}' ";
  377. }
  378. #endregion
  379. #region 开立材料出库(合并发料)
  380. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  381. {
  382. isMerge = true;
  383. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  384. a.IssueDetailID AS DetailID,
  385. a.Type,
  386. a.Sequence AS TransSequence,
  387. a.IssueQuantity AS IssueQuantity,";
  388. tableNameMerge = @"ICSMOIssue a
  389. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  390. columns = @"a.IssueCode AS TransCode,
  391. a.IssueDetailID AS DetailID,
  392. a.Type,
  393. a.Sequence AS TransSequence,
  394. a.IssueQuantity AS IssueQuantity,";
  395. tableName = @"ICSMOIssue a ";
  396. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' ";
  397. }
  398. #endregion
  399. #region 开立委外材料出库(合并发料)
  400. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  401. {
  402. isMerge = true;
  403. columnsMerge = @"mer.MergeID+'~'+a.IssueCode AS TransCode,
  404. a.IssueDetailID AS DetailID,
  405. a.Type,
  406. a.Sequence AS TransSequence,
  407. a.IssueQuantity AS IssueQuantity,";
  408. tableNameMerge = @"ICSOIssue a
  409. INNER JOIN ICSMOPickMerge mer ON a.IssueDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  410. columns = @"a.IssueCode AS TransCode,
  411. a.IssueDetailID AS DetailID,
  412. a.Type,
  413. a.Sequence AS TransSequence,
  414. a.IssueQuantity AS IssueQuantity,";
  415. tableName = @"ICSOIssue a ";
  416. where = @" a.IssueCode='{0}' AND a.WorkPoint='{1}' ";
  417. }
  418. #endregion
  419. #region 开立红字入库单
  420. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  421. {
  422. columns = @"a.RCVCode AS TransCode,
  423. a.RCVDetailID AS DetailID,
  424. a.Type,
  425. a.Sequence AS TransSequence,
  426. a.RCVQuantity AS IssueQuantity,";
  427. tableName = @"ICSPurchaseReceive a ";
  428. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  429. }
  430. #endregion
  431. #region 开立委外红字入库单
  432. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  433. {
  434. columns = @"a.RCVCode AS TransCode,
  435. a.RCVDetailID AS DetailID,
  436. a.Type,
  437. a.Sequence AS TransSequence,
  438. a.RCVQuantity AS IssueQuantity,";
  439. tableName = @"ICSOutsourcingReceive a ";
  440. where = @" a.RCVCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  441. }
  442. #endregion
  443. #region 借用(合并发料)
  444. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  445. {
  446. isMerge = true;
  447. columnsMerge = @"mer.MergeID+'~'+a.BrrowCode AS TransCode,
  448. a.BrrowDetailID AS DetailID,
  449. '' AS Type,
  450. a.Sequence AS TransSequence,
  451. a.BrrowQuantity AS IssueQuantity,";
  452. tableNameMerge = @"ICSBrrow a
  453. INNER JOIN ICSMOPickMerge mer ON a.BrrowDetailID=mer.SourceID AND a.WorkPoint=mer.WorkPoint";
  454. columns = @"a.BrrowCode AS TransCode,
  455. a.BrrowDetailID AS DetailID,
  456. '' AS Type,
  457. a.Sequence AS TransSequence,
  458. a.BrrowQuantity AS IssueQuantity,";
  459. tableName = @"ICSBrrow a ";
  460. where = @" a.BrrowCode='{0}' AND a.WorkPoint='{1}' ";
  461. }
  462. #endregion
  463. #region 送货单
  464. else if (TransType == TransTypeEnum.ASN.GetDescription())
  465. {
  466. isDeliveryNotice = true;
  467. columns = @"asn.ASNCode AS TransCode,
  468. asn.ID AS DetailID,
  469. asn.LotNo,
  470. '' AS Type,
  471. asn.Sequence AS TransSequence,
  472. asn.DNQuantity AS IssueQuantity,
  473. asn.Quantity,
  474. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  475. asn.MUSER AS [User],
  476. asn.MTIME AS [MTime],";
  477. tableName = @"ICSInventoryLot a
  478. INNER JOIN ICSASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  479. where = @" asn.ASNCode='{0}' AND a.WorkPoint='{1}' ";
  480. }
  481. #endregion
  482. #region 委外送货单
  483. else if (TransType == TransTypeEnum.OASN.GetDescription())
  484. {
  485. isDeliveryNotice = true;
  486. columns = @"asn.OASNCode AS TransCode,
  487. asn.ID AS DetailID,
  488. asn.LotNo,
  489. '' AS Type,
  490. asn.Sequence AS TransSequence,
  491. asn.ODNQuantity AS IssueQuantity,
  492. asn.Quantity,
  493. asn.Quantity*(a.Amount/a.Quantity) AS Amount,
  494. asn.MUSER AS [User],
  495. asn.MTIME AS [MTime],";
  496. tableName = @"ICSInventoryLot a
  497. INNER JOIN ICSOASNDetail asn ON a.LotNo=asn.LotNo AND a.WorkPoint=asn.WorkPoint ";
  498. where = @" asn.OASNCode='{0}' AND a.WorkPoint='{1}' ";
  499. }
  500. #endregion
  501. #endregion
  502. #region 入库
  503. #region 采购入库
  504. else if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  505. {
  506. }
  507. #endregion
  508. #region 审核的到货单
  509. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  510. {
  511. }
  512. #endregion
  513. #region 采购拒收
  514. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  515. {
  516. }
  517. #endregion
  518. #region 审核的委外到货单
  519. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  520. {
  521. }
  522. #endregion
  523. #region 委外拒收
  524. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  525. {
  526. }
  527. #endregion
  528. #region 委外退料
  529. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  530. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  531. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  532. {
  533. }
  534. #endregion
  535. #region 委外入库
  536. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  537. {
  538. }
  539. #endregion
  540. #region 生产退料
  541. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  542. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  543. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  544. {
  545. }
  546. #endregion
  547. #region 生产入库
  548. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  549. {
  550. }
  551. #endregion
  552. #region 开立的生产入库单
  553. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  554. {
  555. }
  556. #endregion
  557. #region 返工工单
  558. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  559. {
  560. }
  561. #endregion
  562. #region 销售退货
  563. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  564. {
  565. }
  566. #endregion
  567. #region 两步调入
  568. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  569. {
  570. columns = @"a.InCode AS TransCode,
  571. a.InDetailID AS DetailID,
  572. '' AS Type,
  573. a.Sequence AS TransSequence,
  574. a.InQuantity AS IssueQuantity,";
  575. tableName = @"ICSOtherIn a
  576. INNER JOIN ICSTransfer tra ON a.TransferDetailID=tra.TransferDetailID AND a.WorkPoint=tra.WorkPoint ";
  577. where = @" a.InCode='{0}' AND a.WorkPoint='{1}' ";
  578. }
  579. #endregion
  580. #region 销售退货-原条码
  581. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  582. {
  583. columns = @"a.SDNCode AS TransCode,
  584. a.SDNDetailID AS DetailID,
  585. a.Type,
  586. a.Sequence AS TransSequence,
  587. a.SDNQuantity AS IssueQuantity,";
  588. tableName = @"ICSSDN a ";
  589. where = @" a.SDNCode='{0}' AND a.WorkPoint='{1}' AND a.Type='2' ";
  590. }
  591. #endregion
  592. #region 其他入库
  593. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  594. {
  595. }
  596. #endregion
  597. #region 拆卸单
  598. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  599. {
  600. columns = @"a.DABDOCCode AS TransCode,
  601. a.DABDOCDetailID AS DetailID,
  602. a.DABDOCType AS Type,
  603. a.Sequence AS TransSequence,
  604. a.DABDOCQuantity AS IssueQuantity,";
  605. tableName = @"ICSDisassemblyDoc a";
  606. where = @" a.DABDOCCode='{0}' AND a.WorkPoint='{1}' AND a.DABDOCType='2' ";
  607. }
  608. #endregion
  609. #region 归还
  610. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  611. {
  612. }
  613. #endregion
  614. #endregion
  615. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName) || string.IsNullOrWhiteSpace(where))
  616. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  617. #region 判断是否启用匹配库位
  618. string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode'and F_EnabledMark = '1'";
  619. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  620. if (flag != null && flag.Rows.Count > 0)
  621. //if (true)
  622. {
  623. sql = @"select * into #maintemp from (" + sql + @")a
  624. select * into #resulttemp from #maintemp
  625. truncate table #resulttemp
  626. 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,
  627. isnull(ext.Brand,'')as Brand,
  628. isnull(ext.cFree1,'')as cFree1,
  629. isnull(ext.cFree2,'') cFree2,
  630. isnull(ext.cFree3,'') cFree3,
  631. isnull(ext.cFree4,'') cFree4,
  632. isnull(ext.cFree5,'') cFree5,
  633. isnull(ext.cFree6,'') cFree6,
  634. isnull(ext.cFree7,'') cFree7,
  635. isnull(ext.cFree8,'') cFree8,
  636. isnull(ext.cFree9,'') cFree9,
  637. isnull(ext.cFree10,'') cFree10,ISNULL(ext.BatchCode, '') BatchCode into #barcodetemp
  638. from ICSWareHouseLotInfo a INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  639. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  640. LEFT JOIN
  641. (select invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE from #maintemp
  642. group by invcode,ProjectCode,BatchCode,Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10,WHCODE) b on a.invcode = b.invcode
  643. where (a.warehousecode = b.whcode or ISNULL(b.whcode,'')='') and a.Quantity-a.lockQuantity>0 and
  644. isnull(ext.ProjectCode,'') = b.ProjectCode and isnull(ext.Version,'')=b.Version and
  645. isnull(ext.Brand,'') =b.Brand and
  646. isnull(ext.cFree1,'')=b.cFree1 and
  647. isnull(ext.cFree2,'')=b.cFree2 and
  648. isnull(ext.cFree3,'')=b.cFree3 and
  649. isnull(ext.cFree4,'')=b.cFree4 and
  650. isnull(ext.cFree5,'')=b.cFree5 and
  651. isnull(ext.cFree6,'')=b.cFree6 and
  652. isnull(ext.cFree7,'')=b.cFree7 and
  653. isnull(ext.cFree8,'')=b.cFree8 and
  654. isnull(ext.cFree9,'')=b.cFree9 and
  655. isnull(ext.cFree10,'')=b.cFree10 and
  656. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =ext.BatchCode) or isnull(b.BatchCode,'') ='')
  657. BEGIN
  658. DECLARE @transSequence VARCHAR(50);--
  659. DECLARE @qty decimal(18, 4);--
  660. DECLARE @needqty decimal(18, 4);--
  661. DECLARE @lotno VARCHAR(50);--
  662. DECLARE @locationcode VARCHAR(50);--
  663. DECLARE @WHCode VARCHAR(50);--
  664. DECLARE @invcode VARCHAR(50);--
  665. DECLARE @issueQuantity decimal(18, 4);
  666. DECLARE tempCursor CURSOR FOR (select transSequence from #maintemp); --tempCursor
  667. OPEN tempCursor; --
  668. FETCH NEXT FROM tempCursor INTO @transSequence; --
  669. WHILE @@fetch_status=0
  670. BEGIN
  671. select @needqty=Quantity,@issueQuantity=issueQuantity from #maintemp where transSequence = @transSequence
  672. PRINT @transSequence
  673. WHILE @needqty>0
  674. BEGIN
  675. 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
  676. 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
  677. and ((isnull(b.ProjectCode,'')<>'' and b.ProjectCode = a.ProjectCode) or isnull(b.ProjectCode,'') ='') and
  678. ((isnull(b.Version,'')<>'' and b.Version = a.Version) or isnull(b.Version,'') ='') and
  679. ((isnull(b.Brand,'')<>'' and b.Brand = a.Brand )or isnull(b.Brand,'') ='') and
  680. ((isnull(b.cFree1,'')<>'' and b.cFree1 =a.cFree1) or isnull(b.cFree1,'') ='') and
  681. ((isnull(b.cFree2,'')<>'' and b.cFree2 =a.cFree2 )or isnull(b.cFree2,'') ='') and
  682. ((isnull(b.cFree3,'')<>'' and b.cFree3 =a.cFree3 )or isnull(b.cFree3,'') ='') and
  683. ((isnull(b.cFree4,'')<>'' and b.cFree4 =a.cFree4 )or isnull(b.cFree4,'') ='') and
  684. ((isnull(b.cFree5,'')<>'' and b.cFree5 =a.cFree5) or isnull(b.cFree5,'') ='') and
  685. ((isnull(b.cFree6,'')<>'' and b.cFree6 =a.cFree6 )or isnull(b.cFree6,'') ='') and
  686. ((isnull(b.cFree7,'')<>'' and b.cFree7 =a.cFree7) or isnull(b.cFree7,'') ='') and
  687. ((isnull(b.cFree8,'')<>'' and b.cFree8 =a.cFree8) or isnull(b.cFree8,'') ='') and
  688. ((isnull(b.cFree9,'')<>'' and b.cFree9 =a.cFree9) or isnull(b.cFree9,'') ='') and
  689. ((isnull(b.cFree10,'')<>'' and b.cFree10 =a.cFree10) or isnull(b.cFree10,'') ='') and
  690. ((isnull(b.BatchCode,'')<>'' and b.BatchCode =a.BatchCode) or isnull(b.BatchCode,'') ='')ORDER BY mtime,locationcode
  691. IF(@needqty-@issueQuantity-@qty>=0 and ISNULL(@lotno, '')<>'')
  692. BEGIN
  693. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  694. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotNo,
  695. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  696. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  697. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),@qty,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  698. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  699. delete from #barcodetemp where lotno = @lotno
  700. SET @needqty=@needqty-@qty
  701. END
  702. ELSE if(@needqty-@issueQuantity-@qty<0 and ISNULL(@lotno, '')<>''and @needqty-@issueQuantity>0)
  703. BEGIN
  704. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  705. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  706. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  707. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  708. 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, ''),
  709. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  710. update #barcodetemp set quantity = @qty-@needqty+-@issueQuantity where lotno = @lotno
  711. SET @needqty=@needqty-@issueQuantity-@qty
  712. END
  713. ELSE
  714. BEGIN
  715. insert INTO #resulttemp (id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  716. Amount,[User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,LocationQty,isMatched,AmountUnit,lotno,
  717. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10)
  718. SELECT id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  719. ISNULL(Amount, 0),[User],[MTime],InvCode,InvName,ISNULL(InvStd, ''),InvUnit,isnull(@WHCode,''),isnull(ToWarehouseCode,''),isnull(@LocationCode,''),0 ,1,ISNULL(AmountUnit, ''),ISNULL(@lotno, ''),
  720. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 from #maintemp where #maintemp.transSequence = @transSequence
  721. SET @needqty=0
  722. END
  723. END
  724. FETCH NEXT FROM tempCursor INTO @transSequence;
  725. END
  726. CLOSE tempCursor
  727. DEALLOCATE tempCursor
  728. END
  729. select id,TransCode,DetailID,Type,TransSequence,IssueQuantity,Quantity,
  730. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,sum(LocationQty)as LocationQty,isMatched,AmountUnit,--lotno,
  731. 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,
  732. [User],[MTime],InvCode,InvName,InvStd,InvUnit,WHCode,ToWarehouseCode,LocationCode,isMatched,AmountUnit,--lotno,
  733. WHName,ExtensionID,ProjectCode,BatchCode, Version,Brand,cFree1,cFree2,cFree3,cFree4,cFree5,cFree6,cFree7,cFree8,cFree9,cFree10 ORDER BY locationcode ASC ,InvCode ASC
  734. DROP table #maintemp
  735. DROP table #resulttemp
  736. DROP table #barcodetemp";
  737. }
  738. #endregion
  739. if (isDeliveryNotice)//送货、到货、含委外
  740. {
  741. #region SLQ
  742. sql = sqlCheck + @"SELECT a.ID,
  743. {0}
  744. a.InvCode,
  745. inv.InvName,
  746. inv.InvStd,
  747. inv.InvUnit,
  748. '' AS WHCode,
  749. inv.AmountUnit,
  750. '' AS WHName,
  751. a.ExtensionID,
  752. ext.ProjectCode,
  753. CASE WHEN ISNULL(inv.BatchEnable, '0')='1' THEN ext.BatchCode ELSE '' END AS BatchCode,
  754. ext.Version,
  755. ext.Brand,
  756. ext.cFree1,
  757. ext.cFree2,
  758. ext.cFree3,
  759. ext.cFree4,
  760. ext.cFree5,
  761. ext.cFree6,
  762. ext.cFree7,
  763. ext.cFree8,
  764. ext.cFree9,
  765. ext.cFree10
  766. FROM {1}
  767. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  768. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  769. WHERE {2} ";
  770. #endregion
  771. }
  772. else if(isMerge)//合并发料
  773. {
  774. #region SLQ
  775. string sqlMerge = "SELECT ID FROM ICSMOPickMerge WHERE MergeID='"+ JsonData.TransCode + "' AND WorkPoint='"+ JsonData.WorkPoint + "'";
  776. DataTable sign = DBHelper.SQlReturnData(sqlMerge, cmd);
  777. if (sign != null && flag.Rows.Count > 0)
  778. {
  779. string whereMerge = string.Format("mer.MergeID='{0}' AND mer.WorkPoint='{1}'", JsonData.TransCode, JsonData.WorkPoint);
  780. sql = string.Format(sql, columnsMerge, tableNameMerge, whereMerge, JsonData.TransCode, JsonData.WorkPoint);
  781. }
  782. else
  783. {
  784. sql = @" BEGIN
  785. IF EXISTS(SELECT a.ID FROM {1} INNER JOIN ICSMOPickMerge c ON a.ID=c.SourceID AND a.WorkPoint=c.WorkPoint WHERE {2})
  786. BEGIN
  787. RAISERROR('" + language.GetNameByCode("WMSAPIInfo194") + @"',16,1);
  788. RETURN
  789. END
  790. " + sqlCheck + sql + @"
  791. END";
  792. }
  793. #endregion
  794. }
  795. else
  796. {
  797. sql = sqlCheck + sql;
  798. }
  799. where = string.Format(where, JsonData.TransCode, JsonData.WorkPoint);
  800. sql = string.Format(sql, columns, tableName, where, JsonData.TransCode);
  801. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  802. return table;
  803. }
  804. catch (Exception ex)
  805. {
  806. log.Error(ex.Message);
  807. throw new Exception(ex.Message);
  808. }
  809. finally
  810. {
  811. if (conn.State == ConnectionState.Open)
  812. {
  813. conn.Close();
  814. }
  815. conn.Dispose();
  816. }
  817. }
  818. }
  819. #endregion
  820. #region 条码信息
  821. /// <summary>
  822. /// 条码信息
  823. /// </summary>
  824. /// <param name="JsonData"></param>
  825. /// <returns></returns>
  826. public static Result BarCodeInformationGet(BarCodeModel JsonData)
  827. {
  828. var language = LanguageHelper.GetName("WMSAPIInfo");
  829. DataTable table = new DataTable();
  830. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  831. {
  832. conn.Open();
  833. SqlCommand cmd = new SqlCommand();
  834. cmd.Connection = conn;
  835. try
  836. {
  837. string ScanType = DBHelper.ScanTypeCheck(JsonData.Code, JsonData.WorkPoint, cmd);
  838. if (string.IsNullOrEmpty(JsonData.Code))
  839. {
  840. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  841. }
  842. else if (string.IsNullOrEmpty(JsonData.TransType))
  843. {
  844. throw new Exception(language.GetNameByCode("WMSAPIInfo002"));//"单据类型不能为空!"
  845. }
  846. else if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), JsonData.TransType))
  847. {
  848. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"单据类型不存在!"
  849. }
  850. else if (string.IsNullOrEmpty(JsonData.WorkPoint))
  851. {
  852. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  853. }
  854. string TransType = JsonData.TransType;
  855. string sql = "";
  856. string Losql = "";
  857. string sqlNew = "";
  858. #region SLQ
  859. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  860. {
  861. //Losql = @"SELECT a.ID,
  862. // con.ContainerCode,
  863. // con.ContainerName,
  864. // a.LotNo,
  865. // a.InvCode,
  866. // inv.InvName,
  867. // inv.InvStd,
  868. // inv.InvUnit,
  869. // inv.LotEnable,
  870. // {0}
  871. // inv.AmountUnit,
  872. // ext.ID AS ExtensionID,
  873. // ext.ProjectCode,
  874. // ext.Version,
  875. // ext.Brand,
  876. // ext.cFree1,
  877. // ext.cFree2,
  878. // ext.cFree3,
  879. // ext.cFree4,
  880. // ext.cFree5,
  881. // ext.cFree6,
  882. // ext.cFree7,
  883. // ext.cFree8,
  884. // ext.cFree9,
  885. // ext.cFree10,
  886. // a.MUSER AS [User],
  887. // a.MTIME AS [MTime]
  888. // FROM {1}
  889. // LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  890. // LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  891. // INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  892. // WHERE a.Quantity>0 and a.WorkPoint='{3}'";
  893. Losql = @"DECLARE @aa VARCHAR(MAX)
  894. DECLARE @bb VARCHAR(MAX)
  895. DECLARE @cc VARCHAR(MAX)
  896. DECLARE @b VARCHAR(MAX)
  897. set @b =
  898. 'SELECT a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,
  899. inv.InvName,
  900. inv.InvStd,
  901. inv.InvUnit,
  902. inv.LotEnable,
  903. s.WarehouseCode,sum(a.Quantity) as Qty,s.sumQty,
  904. inv.AmountUnit,
  905. ext.ID AS ExtensionID,
  906. ext.ProjectCode,
  907. ext.Version,
  908. ext.Brand,
  909. ext.cFree1,
  910. ext.cFree2,
  911. ext.cFree3,
  912. ext.cFree4,
  913. ext.cFree5,
  914. ext.cFree6,
  915. ext.cFree7,
  916. ext.cFree8,
  917. ext.cFree9,
  918. ext.cFree10,
  919. a.MUSER AS [User],
  920. a.MTIME AS [MTime]
  921. FROM ICSWareHouseLotInfo a
  922. LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  923. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  924. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  925. LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode from ICSWareHouseLotInfo group by WarehouseCode,INVCode)s ON a.INVCode=s.INVCode
  926. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  927. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  928. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  929. WHERE a.Quantity>0 and a.WorkPoint=''{3}'' and'
  930. select @aa=id from ICSWareHouseLotInfo where LotNo='{2}'
  931. IF @aa IS NOT NULL
  932. BEGIN
  933. set @b = @b+' lot.invcode IN(SELECT invcode FROM ICSWareHouseLotInfo where LotNo=''{2}'')
  934. 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,
  935. 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
  936. '
  937. END
  938. select @bb=id from ICSLocation where LocationCode='{2}'
  939. IF @bb IS not NULL
  940. BEGIN
  941. set @b = @b+' a.WarehouseCode=s.WarehouseCode and a.LocationCode=''{2}''
  942. 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,
  943. 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'
  944. END
  945. select @cc=id from ICSInventory where invcode='{2}'
  946. IF @cc IS not NULL
  947. BEGIN
  948. set @b = @b+' a.WarehouseCode=s.WarehouseCode and inv.invcode=''{2}''
  949. 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,
  950. 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'
  951. END
  952. exec(@b)
  953. ";
  954. }
  955. else
  956. {
  957. if (ScanType == "LOTNO")
  958. {
  959. sql = @"SELECT a.ID,
  960. con.ContainerCode,
  961. con.ContainerName,
  962. a.LotNo,
  963. a.InvCode,
  964. inv.InvName,
  965. inv.InvStd,
  966. inv.InvUnit,
  967. inv.LotEnable,
  968. {0}
  969. inv.AmountUnit,
  970. ext.ID AS ExtensionID,
  971. ext.ProjectCode,
  972. ext.Version,
  973. ext.Brand,
  974. ext.cFree1,
  975. ext.cFree2,
  976. ext.cFree3,
  977. ext.cFree4,
  978. ext.cFree5,
  979. ext.cFree6,
  980. ext.cFree7,
  981. ext.cFree8,
  982. ext.cFree9,
  983. ext.cFree10,
  984. a.MUSER AS [User],
  985. a.MTIME AS [MTime]
  986. FROM {1}
  987. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  988. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  989. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  990. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' ";
  991. }
  992. else
  993. {
  994. sql = @"SELECT a.ID,
  995. con.ContainerCode,
  996. con.ContainerName,
  997. a.LotNo,
  998. a.InvCode,
  999. inv.InvName,
  1000. inv.InvStd,
  1001. inv.InvUnit,
  1002. {0}
  1003. inv.AmountUnit,
  1004. ext.ID AS ExtensionID,
  1005. ext.ProjectCode,
  1006. ext.Version,
  1007. ext.Brand,
  1008. ext.cFree1,
  1009. ext.cFree2,
  1010. ext.cFree3,
  1011. ext.cFree4,
  1012. ext.cFree5,
  1013. ext.cFree6,
  1014. ext.cFree7,
  1015. ext.cFree8,
  1016. ext.cFree9,
  1017. ext.cFree10,
  1018. a.MUSER AS [User],
  1019. a.MTIME AS [MTime]
  1020. FROM {1}
  1021. LEFT JOIN ICSContainerLot conlot ON a.LotNo=conlot.LotNo AND a.WorkPoint=conlot.WorkPoint
  1022. LEFT JOIN ICSBomALL bom ON bom.ID=conlot.ContainerID
  1023. LEFT JOIN ICSContainer con ON conlot.ContainerID=con.ID AND conlot.WorkPoint=con.WorkPoint
  1024. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  1025. WHERE bom.ContainerCode='{2}' AND a.WorkPoint='{3}' ";
  1026. }
  1027. }
  1028. #endregion
  1029. bool isOut = false; //出库标记
  1030. string columns = string.Empty; //查询源头单据表的特殊列名
  1031. string tableName = string.Empty; //查询源头单据表名
  1032. string where = string.Empty; //排序
  1033. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription() //采购退货
  1034. || TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription() //委外发料
  1035. || TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription() //委外退货
  1036. || TransType == TransTypeEnum.MOIssueDoc.GetDescription() //生产发料
  1037. || TransType == TransTypeEnum.SalesShipmentDoc.GetDescription() //销售出库
  1038. || TransType == TransTypeEnum.OneStepTransferDocIn.GetDescription() //一步调拨
  1039. || TransType == TransTypeEnum.StepTransferDocIn.GetDescription() //调拨
  1040. || TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription() //两步调出
  1041. || TransType == TransTypeEnum.OtherOutDoc.GetDescription() //其他出库
  1042. || TransType == TransTypeEnum.Check.GetDescription() //盘点
  1043. || TransType == TransTypeEnum.MOApply.GetDescription() //领料申请单
  1044. || TransType == TransTypeEnum.OOApply.GetDescription() //委外领料申请单
  1045. || TransType == TransTypeEnum.MOIssue.GetDescription() //开立材料出库单
  1046. || TransType == TransTypeEnum.OOIssue.GetDescription() //开立委外材料出库单
  1047. || TransType == TransTypeEnum.PurchaseReceive.GetDescription() //开立红字入库单
  1048. || TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription()//开立委外红字入库单
  1049. || TransType == TransTypeEnum.BrrowDoc.GetDescription() //借用
  1050. || TransType == TransTypeEnum.TransferLibrary.GetDescription() //移库
  1051. //|| TransType == TransTypeEnum.DisassemblyDoc.GetDescription() //拆卸单(散件生成条码入库)
  1052. )
  1053. {
  1054. isOut = true;
  1055. }
  1056. //库位查询
  1057. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  1058. {
  1059. // 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, " +
  1060. // "ext.cFree1,ext.cFree2,ext.cFree3,ext.cFree4,ext.cFree5,ext.cFree6,ext.cFree7,ext.cFree8,ext.cFree9,ext.cFree10,a.MUSER ,a.MTIME";
  1061. // columns = @"s.WarehouseCode, inv.INVCODE,inv.INVNAME,inv.INVSTD,sum(a.Quantity) as Qty,s.sumQty,";
  1062. // tableName = @"ICSWareHouseLotInfo a
  1063. //LEFT JOIN ICSLocation b ON a.LocationCode = b.LocationCode and a.WorkPoint=b.WorkPoint
  1064. //INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1065. //INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1066. //LEFT JOIN (select SUM(Quantity) AS sumQty,WarehouseCode,INVCode from ICSWareHouseLotInfo group by WarehouseCode,INVCode)s
  1067. //ON a.INVCode=s.INVCode ";
  1068. }
  1069. else
  1070. {
  1071. //两步调入条码
  1072. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1073. {
  1074. if (string.IsNullOrEmpty(JsonData.TransCode))
  1075. {
  1076. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1077. }
  1078. if (ScanType == "LOTNO")
  1079. {
  1080. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSOtherIn Otin
  1081. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  1082. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  1083. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  1084. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1085. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND Otin.InCode = '" + JsonData.TransCode + @"')
  1086. BEGIN
  1087. RAISERROR('" + language.GetNameByCode("WMSAPIInfo036") + @"',16,1);
  1088. RETURN
  1089. END
  1090. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  1091. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1092. 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,
  1093. 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";
  1094. columns = @"SUM(log.Quantity) AS Quantity,
  1095. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1096. a.WarehouseCode AS WHCode,
  1097. wh.WarehouseName AS WHName,
  1098. a.LocationCode,
  1099. loc.LocationName,
  1100. 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,";
  1101. tableName = @"ICSOtherIn Otin
  1102. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  1103. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  1104. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  1105. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1106. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1107. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1108. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1109. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1110. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1111. }
  1112. else
  1113. {
  1114. sql = @"WITH ICSBomALL AS
  1115. (
  1116. SELECT
  1117. ContainerCode AS TContainerCode,
  1118. ContainerCode AS PContainerCode,
  1119. ContainerCode AS ContainerCode,
  1120. ID,
  1121. ContainerID,
  1122. 0 AS [Level],
  1123. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1124. CAST('00001' AS nvarchar(MAX)) AS Sort
  1125. FROM ICSContainer
  1126. WHERE ContainerCode='{2}'
  1127. UNION ALL
  1128. SELECT
  1129. b.TContainerCode,
  1130. b.ContainerCode AS PContainerCode,
  1131. a.ContainerCode,
  1132. a.ID,
  1133. a.ContainerID,
  1134. b.[Level]+1 AS [Level],
  1135. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1136. 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
  1137. FROM
  1138. ICSContainer a
  1139. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1140. )
  1141. " + sql + "AND Otin.InCode = '" + JsonData.TransCode + @"'
  1142. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1143. 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,
  1144. 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";
  1145. columns = @"SUM(log.Quantity) AS Quantity,
  1146. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1147. a.WarehouseCode AS WHCode,
  1148. wh.WarehouseName AS WHName,
  1149. a.LocationCode,
  1150. loc.LocationName,
  1151. 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,";
  1152. tableName = @"ICSOtherIn Otin
  1153. INNER JOIN ICSTransfer tra ON Otin.TransferDetailID=tra.TransferDetailID AND Otin.WorkPoint=tra.WorkPoint
  1154. INNER JOIN ICSOtherOut out ON out.TransferDetailID=tra.TransferDetailID AND out.WorkPoint=tra.WorkPoint
  1155. INNER JOIN ICSWareHouseLotInfoLog log ON out.OutCode=log.TransCode AND out.Sequence=log.TransSequence AND out.WorkPoint=log.WorkPoint
  1156. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1157. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1158. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1159. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1160. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1161. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1162. }
  1163. }
  1164. //销售退货-原条码(可支持一个条码多次发货,汇总数量,目前加了限制:785-793行)
  1165. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1166. {
  1167. if (string.IsNullOrEmpty(JsonData.TransCode))
  1168. {
  1169. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1170. }
  1171. if (ScanType == "LOTNO")
  1172. {
  1173. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSSDN sdn
  1174. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  1175. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1176. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1')
  1177. BEGIN
  1178. RAISERROR('" + language.GetNameByCode("WMSAPIInfo037") + @"',16,1);
  1179. RETURN
  1180. END
  1181. IF EXISTS(SELECT log.LotNo FROM ICSSDN sdn
  1182. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  1183. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1184. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND sdn.Type='1' AND log.BusinessCode='19'
  1185. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  1186. BEGIN
  1187. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo191"), "{2}") + @"',16,1);
  1188. RETURN
  1189. END
  1190. " + sql + @"AND sdn.Type='1'
  1191. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1192. 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,
  1193. 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";
  1194. columns = @"SUM(log.Quantity) AS Quantity,
  1195. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1196. a.WarehouseCode AS WHCode,
  1197. wh.WarehouseName AS WHName,
  1198. a.LocationCode,
  1199. loc.LocationName,
  1200. 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,";
  1201. tableName = @"ICSSDN sdn
  1202. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  1203. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1204. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1205. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1206. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1207. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1208. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1209. }
  1210. else
  1211. {
  1212. sql = @"WITH ICSBomALL AS
  1213. (
  1214. SELECT
  1215. ContainerCode AS TContainerCode,
  1216. ContainerCode AS PContainerCode,
  1217. ContainerCode AS ContainerCode,
  1218. ID,
  1219. ContainerID,
  1220. 0 AS [Level],
  1221. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1222. CAST('00001' AS nvarchar(MAX)) AS Sort
  1223. FROM ICSContainer
  1224. WHERE ContainerCode='{2}'
  1225. UNION ALL
  1226. SELECT
  1227. b.TContainerCode,
  1228. b.ContainerCode AS PContainerCode,
  1229. a.ContainerCode,
  1230. a.ID,
  1231. a.ContainerID,
  1232. b.[Level]+1 AS [Level],
  1233. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1234. 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
  1235. FROM
  1236. ICSContainer a
  1237. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1238. )
  1239. " + sql + @"AND sdn.Type='1'
  1240. GROUP BY a.ID,con.ContainerCode,con.ContainerName,a.LotNo,a.InvCode,inv.InvName,inv.InvStd,inv.InvUnit,a.WarehouseCode,
  1241. 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,
  1242. 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";
  1243. columns = @"SUM(log.Quantity) AS Quantity,
  1244. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1245. a.WarehouseCode AS WHCode,
  1246. wh.WarehouseName AS WHName,
  1247. a.LocationCode,
  1248. loc.LocationName,
  1249. 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,";
  1250. tableName = @"ICSSDN sdn
  1251. INNER JOIN ICSWareHouseLotInfoLog log ON sdn.SDNCode=log.TransCode AND sdn.Sequence=log.TransSequence AND sdn.WorkPoint=log.WorkPoint
  1252. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1253. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1254. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1255. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1256. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1257. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1258. }
  1259. }
  1260. //生产(委外)退料-原条码+新条码
  1261. //先校验日志里面是否有原条码(同一种类型的条码只能发一次料才能原条码退,不然更新源头单据数量有问题,根据LogID判断是否原条码退回),如果没有查询新条码
  1262. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1263. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1264. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription()
  1265. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1266. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1267. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1268. {
  1269. string type = "13";
  1270. string msglanguage = "WMSAPIInfo185";
  1271. if (TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription())
  1272. {
  1273. type = "14";
  1274. msglanguage = "WMSAPIInfo186";
  1275. }
  1276. else if (TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1277. {
  1278. type = "15";
  1279. msglanguage = "WMSAPIInfo187";
  1280. }
  1281. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription())
  1282. {
  1283. type = "5";
  1284. msglanguage = "WMSAPIInfo188";
  1285. }
  1286. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription())
  1287. {
  1288. type = "6";
  1289. msglanguage = "WMSAPIInfo189";
  1290. }
  1291. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1292. {
  1293. type = "7";
  1294. msglanguage = "WMSAPIInfo190";
  1295. }
  1296. #region 新条码
  1297. if (ScanType == "LOTNO")
  1298. {
  1299. sqlNew = @"IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1300. BEGIN
  1301. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  1302. RETURN
  1303. END
  1304. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1305. BEGIN
  1306. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  1307. RETURN
  1308. END
  1309. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  1310. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1311. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  1312. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1'AND ins.LotNo IS NULL))
  1313. BEGIN
  1314. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  1315. RETURN
  1316. END
  1317. " + sql;
  1318. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1319. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1320. '' AS WHCode,
  1321. '' AS WHName,
  1322. '' AS LocationCode,
  1323. '' AS LocationName,
  1324. ext.BatchCode AS BatchCode,";
  1325. tableName = @"ICSInventoryLot a
  1326. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1327. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1328. }
  1329. else
  1330. {
  1331. sqlNew = @"WITH ICSBomALL AS
  1332. (
  1333. SELECT
  1334. ContainerCode AS TContainerCode,
  1335. ContainerCode AS PContainerCode,
  1336. ContainerCode AS ContainerCode,
  1337. ID,
  1338. ContainerID,
  1339. 0 AS [Level],
  1340. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1341. CAST('00001' AS nvarchar(MAX)) AS Sort
  1342. FROM ICSContainer
  1343. WHERE ContainerCode='{2}'
  1344. UNION ALL
  1345. SELECT
  1346. b.TContainerCode,
  1347. b.ContainerCode AS PContainerCode,
  1348. a.ContainerCode,
  1349. a.ID,
  1350. a.ContainerID,
  1351. b.[Level]+1 AS [Level],
  1352. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1353. 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
  1354. FROM
  1355. ICSContainer a
  1356. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1357. )
  1358. " + sql;
  1359. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1360. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1361. '' AS WHCode,
  1362. '' AS WHName,
  1363. '' AS LocationCode,
  1364. '' AS LocationName,
  1365. ext.BatchCode AS BatchCode,";
  1366. tableName = @"ICSInventoryLot a
  1367. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1368. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1369. }
  1370. sqlNew = string.Format(sqlNew, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  1371. #endregion
  1372. #region 原条码
  1373. if (ScanType == "LOTNO")
  1374. {
  1375. 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,
  1376. 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,
  1377. 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
  1378. ";
  1379. sql = @"IF EXISTS(" + sql + @")
  1380. BEGIN
  1381. " + sql + @"
  1382. END
  1383. ELSE
  1384. BEGIN
  1385. " + sqlNew + @"
  1386. END";
  1387. sql = @"IF EXISTS(SELECT log.LotNo FROM ICSWareHouseLotInfoLog log
  1388. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1389. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND log.BusinessCode='" + type + @"'
  1390. GROUP BY log.LotNo HAVING COUNT(log.LotNo)>=2)
  1391. BEGIN
  1392. RAISERROR('" + string.Format(language.GetNameByCode(msglanguage), "{2}") + @"',16,1);
  1393. RETURN
  1394. END
  1395. " + sql;
  1396. columns = @"SUM(log.Quantity) AS Quantity,
  1397. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1398. a.WarehouseCode AS WHCode,
  1399. wh.WarehouseName AS WHName,
  1400. a.LocationCode,
  1401. loc.LocationName,
  1402. log.ID AS LogID,
  1403. 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,";
  1404. tableName = @"ICSWareHouseLotInfoLog log
  1405. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1406. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1407. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1408. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1409. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1410. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1411. }
  1412. else
  1413. {
  1414. 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,
  1415. 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,
  1416. 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
  1417. ";
  1418. sql = @"IF EXISTS(" + sql + @")
  1419. BEGIN
  1420. " + sql + @"
  1421. END
  1422. ELSE
  1423. BEGIN
  1424. " + sqlNew + @"
  1425. END";
  1426. sql = @"WITH ICSBomALL AS
  1427. (
  1428. SELECT
  1429. ContainerCode AS TContainerCode,
  1430. ContainerCode AS PContainerCode,
  1431. ContainerCode AS ContainerCode,
  1432. ID,
  1433. ContainerID,
  1434. 0 AS [Level],
  1435. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1436. CAST('00001' AS nvarchar(MAX)) AS Sort
  1437. FROM ICSContainer
  1438. WHERE ContainerCode='{2}'
  1439. UNION ALL
  1440. SELECT
  1441. b.TContainerCode,
  1442. b.ContainerCode AS PContainerCode,
  1443. a.ContainerCode,
  1444. a.ID,
  1445. a.ContainerID,
  1446. b.[Level]+1 AS [Level],
  1447. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1448. 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
  1449. FROM
  1450. ICSContainer a
  1451. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1452. )
  1453. " + sql;
  1454. columns = @"SUM(log.Quantity) AS Quantity,
  1455. SUM(log.Quantity*(lot.Amount/lot.Quantity)) AS Amount,
  1456. a.WarehouseCode AS WHCode,
  1457. wh.WarehouseName AS WHName,
  1458. a.LocationCode,
  1459. loc.LocationName,
  1460. log.ID AS LogID,
  1461. 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,";
  1462. tableName = @"ICSWareHouseLotInfoLog log
  1463. INNER JOIN ICSWareHouseLotInfo a ON a.LotNo=log.LotNo AND a.WorkPoint=log.WorkPoint
  1464. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1465. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1466. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1467. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1468. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1469. }
  1470. #endregion
  1471. }
  1472. //分批
  1473. else if (TransType == TransTypeEnum.LOTSplit.GetDescription() || TransType == TransTypeEnum.LOTMerge.GetDescription())
  1474. {
  1475. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  1476. BEGIN
  1477. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  1478. RETURN
  1479. END
  1480. " + sql;
  1481. columns = @"a.Quantity,
  1482. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  1483. a.WarehouseCode AS WHCode,
  1484. wh.WarehouseName AS WHName,
  1485. a.LocationCode,
  1486. loc.LocationName,
  1487. 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,
  1488. ISNULL(split.SplitLotNo, a.LotNo+'-1') AS SplitLotNo,";
  1489. tableName = @"ICSWareHouseLotInfo a
  1490. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1491. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1492. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1493. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1494. 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
  1495. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1496. }
  1497. //出库条码
  1498. else if (isOut)
  1499. {
  1500. if (ScanType == "LOTNO")
  1501. {
  1502. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND a.Quantity>0)
  1503. BEGIN
  1504. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"',16,1);
  1505. RETURN
  1506. END
  1507. " + sql;
  1508. columns = @"a.Quantity,
  1509. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  1510. a.WarehouseCode AS WHCode,
  1511. wh.WarehouseName AS WHName,
  1512. a.LocationCode,
  1513. loc.LocationName,
  1514. 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,";
  1515. tableName = @"ICSWareHouseLotInfo a
  1516. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1517. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1518. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1519. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1520. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint";
  1521. }
  1522. else
  1523. {
  1524. sql = @"
  1525. WITH ICSBomALL AS
  1526. (
  1527. SELECT
  1528. ContainerCode AS TContainerCode,
  1529. ContainerCode AS PContainerCode,
  1530. ContainerCode AS ContainerCode,
  1531. ID,
  1532. ContainerID,
  1533. 0 AS [Level],
  1534. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1535. CAST('00001' AS nvarchar(MAX)) AS Sort
  1536. FROM ICSContainer
  1537. WHERE ContainerCode='{2}'
  1538. UNION ALL
  1539. SELECT
  1540. b.TContainerCode,
  1541. b.ContainerCode AS PContainerCode,
  1542. a.ContainerCode,
  1543. a.ID,
  1544. a.ContainerID,
  1545. b.[Level]+1 AS [Level],
  1546. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1547. 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
  1548. FROM
  1549. ICSContainer a
  1550. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1551. )
  1552. " + sql;
  1553. columns = @"a.Quantity,
  1554. a.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  1555. a.WarehouseCode AS WHCode,
  1556. wh.WarehouseName AS WHName,
  1557. a.LocationCode,
  1558. loc.LocationName,
  1559. 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,";
  1560. tableName = @"ICSWareHouseLotInfo a
  1561. INNER JOIN ICSInventoryLot lot ON a.LotNo=lot.LotNo AND a.WorkPoint=lot.WorkPoint
  1562. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  1563. INNER JOIN ICSWarehouse wh ON a.WarehouseCode=wh.WarehouseCode AND a.WorkPoint=wh.WorkPoint
  1564. INNER JOIN ICSLocation loc ON a.LocationCode=loc.LocationCode AND a.WorkPoint=loc.WorkPoint
  1565. LEFT JOIN ICSInventoryBatchEnable invBat ON a.InvCode=invBat.InvCode AND a.WarehouseCode=invBat.WHCode AND a.WorkPoint=invBat.WorkPoint
  1566. ";
  1567. }
  1568. }
  1569. //入库条码
  1570. else
  1571. {
  1572. if (ScanType == "LOTNO")
  1573. {
  1574. sql = @"
  1575. IF NOT EXISTS(SELECT a.ID FROM ICSInventoryLot a WHERE a.LotNo = '{2}' AND a.WorkPoint = '{3}')
  1576. BEGIN
  1577. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo038"), "{2}") + @"', 16, 1);
  1578. RETURN
  1579. END
  1580. IF EXISTS(SELECT a.ID FROM ICSWareHouseLotInfo a WHERE a.LotNo='{2}' AND a.WorkPoint='{3}')
  1581. BEGIN
  1582. RAISERROR('" + language.GetNameByCode("WMSAPIInfo039") + @"',16,1);
  1583. RETURN
  1584. END
  1585. IF EXISTS(SELECT a.ID FROM ICSInventoryLot a
  1586. INNER JOIN ICSInventory b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  1587. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint
  1588. LEFT JOIN ICSInventoryLotDetail c ON a.LotNo=c.LotNo AND a.WorkPoint=c.WorkPoint
  1589. WHERE a.LotNo='{2}' AND a.WorkPoint='{3}' AND (b.InvIQC='1'AND ins.LotNo IS NULL) AND c.TransCode NOT LIKE 'RD%')
  1590. BEGIN
  1591. RAISERROR('" + language.GetNameByCode("WMSAPIInfo040") + @"',16,1);
  1592. RETURN
  1593. END
  1594. " + sql;
  1595. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1596. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1597. '' AS WHCode,
  1598. '' AS WHName,
  1599. '' AS LocationCode,
  1600. '' AS LocationName,
  1601. ext.BatchCode AS BatchCode,";
  1602. tableName = @"ICSInventoryLot a
  1603. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1604. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1605. }
  1606. else
  1607. {
  1608. sql = @"
  1609. WITH ICSBomALL AS
  1610. (
  1611. SELECT
  1612. ContainerCode AS TContainerCode,
  1613. ContainerCode AS PContainerCode,
  1614. ContainerCode AS ContainerCode,
  1615. ID,
  1616. ContainerID,
  1617. 0 AS [Level],
  1618. CAST(1 AS nvarchar(MAX)) AS SortSeq,
  1619. CAST('00001' AS nvarchar(MAX)) AS Sort
  1620. FROM ICSContainer
  1621. WHERE ContainerCode='{2}'
  1622. UNION ALL
  1623. SELECT
  1624. b.TContainerCode,
  1625. b.ContainerCode AS PContainerCode,
  1626. a.ContainerCode,
  1627. a.ID,
  1628. a.ContainerID,
  1629. b.[Level]+1 AS [Level],
  1630. CAST(b.SortSeq AS nvarchar(MAX))+'.'+CAST(row_number() over (order by a.ContainerCode) AS nvarchar(MAX)) AS SortSeq,
  1631. 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
  1632. FROM
  1633. ICSContainer a
  1634. INNER JOIN ICSBomALL b ON a.ID=b.ContainerID
  1635. )
  1636. " + sql;
  1637. columns = @"ISNULL(ins.QualifiedQuantity+ins.WaiveQuantity, a.Quantity) AS Quantity,
  1638. a.Quantity*(a.Amount/a.Quantity) AS Amount,
  1639. '' AS WHCode,
  1640. '' AS WHName,
  1641. '' AS LocationCode,
  1642. '' AS LocationName,
  1643. ext.BatchCode AS BatchCode,";
  1644. tableName = @"ICSInventoryLot a
  1645. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  1646. LEFT JOIN ICSInspection ins ON a.LotNo=ins.LotNo AND a.WorkPoint=ins.WorkPoint";
  1647. }
  1648. }
  1649. }
  1650. if (TransType != TransTypeEnum.LocationSeatch.GetDescription())
  1651. {
  1652. if (string.IsNullOrWhiteSpace(columns) || string.IsNullOrWhiteSpace(tableName))
  1653. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));
  1654. }
  1655. if (TransType == TransTypeEnum.LocationSeatch.GetDescription())
  1656. {
  1657. Losql = string.Format(Losql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  1658. table = DBHelper.SQlReturnData(Losql, cmd);
  1659. }
  1660. else
  1661. {
  1662. sql = string.Format(sql, columns, tableName, JsonData.Code, JsonData.WorkPoint);
  1663. table = DBHelper.SQlReturnData(sql, cmd);
  1664. }
  1665. if (table == null || table.Rows.Count <= 0)
  1666. throw new Exception(language.GetNameByCode("WMSAPIInfo008"));//"未查询到条码数据!"
  1667. #region 出库检验是否符合源头单据
  1668. string msg = string.Empty;
  1669. bool isLimit = false;
  1670. string sqlCheckSign = @"select F_EnabledMark from Sys_SRM_Items where F_EnCode = 'OutWithLocationCode' and F_EnabledMark = '1'";
  1671. DataTable flag = DBHelper.SQlReturnData(sqlCheckSign, cmd);
  1672. if (isOut) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
  1673. {//&& TransType != TransTypeEnum.TransferLibrary.GetDescription()
  1674. string Lot = "";
  1675. string workP = "";
  1676. if (TransType == TransTypeEnum.TransferLibrary.GetDescription())
  1677. {
  1678. foreach (DataRow drLot in table.Rows)
  1679. {
  1680. Lot = drLot["LotNo"].ToString();
  1681. sql = @"SELECT WarehouseCode FROM ICSWareHouseLotInfo a WHERE LotNo='{0}' AND WorkPoint='{1}'";
  1682. sql = string.Format(sql, Lot, JsonData.WorkPoint);
  1683. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  1684. if (dt == null || dt.Rows.Count <= 0)
  1685. {
  1686. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo171"), Lot));
  1687. }
  1688. string whcode = dt.Rows[0]["WarehouseCode"].ToString();
  1689. if (!JsonData.WHCode.Equals(whcode))
  1690. {
  1691. throw new Exception(string.Format(language.GetNameByCode("WMSAPIInfo395"), JsonData.WHCode, whcode));
  1692. }
  1693. }
  1694. }
  1695. else if(TransType != TransTypeEnum.LocationSeatch.GetDescription())
  1696. {
  1697. if (string.IsNullOrEmpty(JsonData.TransCode))
  1698. {
  1699. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1700. }
  1701. WMSSourceDocumentModel model = new WMSSourceDocumentModel();
  1702. model.TransCode = JsonData.TransCode;
  1703. model.TransType = JsonData.TransType;
  1704. model.WorkPoint = JsonData.WorkPoint;
  1705. DataTable TransData = TransInformationGet(model);
  1706. DataView dataView = TransData.DefaultView;
  1707. foreach (DataRow drLot in table.Rows)
  1708. {
  1709. Lot = drLot["LotNo"].ToString();
  1710. //盘点不需要对比以下属性
  1711. if (TransType == TransTypeEnum.Check.GetDescription())
  1712. continue;
  1713. string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
  1714. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
  1715. rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
  1716. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
  1717. rowFilter += " AND (LEN(ISNULL(ProjectCode,''))<=0 OR (LEN(ISNULL(ProjectCode,''))>0 AND ProjectCode='" + drLot["ProjectCode"] + "'))";
  1718. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo043"), Lot, drLot["ProjectCode"]));
  1719. rowFilter += "AND (LEN(ISNULL(BatchCode,''))<=0 OR (LEN(ISNULL(BatchCode,''))>0 AND BatchCode='" + drLot["BatchCode"] + "'))";
  1720. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo044"), Lot, drLot["BatchCode"]));
  1721. rowFilter += "AND (LEN(ISNULL(Version,''))<=0 OR (LEN(ISNULL(Version,''))>0 AND Version='" + drLot["Version"] + "'))";
  1722. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo045"), Lot, drLot["Version"]));
  1723. rowFilter += "AND (LEN(ISNULL(Brand,''))<=0 OR (LEN(ISNULL(Brand,''))>0 AND Brand='" + drLot["Brand"] + "'))";
  1724. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo046"), Lot, drLot["Brand"]));
  1725. rowFilter += "AND (LEN(ISNULL(cFree1,''))<=0 OR (LEN(ISNULL(cFree1,''))>0 AND cFree1='" + drLot["cFree1"] + "'))";
  1726. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo047"), Lot, drLot["cFree1"]));
  1727. rowFilter += "AND (LEN(ISNULL(cFree2,''))<=0 OR (LEN(ISNULL(cFree2,''))>0 AND cFree2='" + drLot["cFree2"] + "'))";
  1728. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo048"), Lot, drLot["cFree2"]));
  1729. rowFilter += "AND (LEN(ISNULL(cFree3,''))<=0 OR (LEN(ISNULL(cFree3,''))>0 AND cFree3='" + drLot["cFree3"] + "'))";
  1730. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo049"), Lot, drLot["cFree3"]));
  1731. rowFilter += "AND (LEN(ISNULL(cFree4,''))<=0 OR (LEN(ISNULL(cFree4,''))>0 AND cFree4='" + drLot["cFree4"] + "'))";
  1732. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo050"), Lot, drLot["cFree4"]));
  1733. rowFilter += "AND (LEN(ISNULL(cFree5,''))<=0 OR (LEN(ISNULL(cFree5,''))>0 AND cFree5='" + drLot["cFree5"] + "'))";
  1734. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo051"), Lot, drLot["cFree5"]));
  1735. rowFilter += "AND (LEN(ISNULL(cFree6,''))<=0 OR (LEN(ISNULL(cFree6,''))>0 AND cFree6='" + drLot["cFree6"] + "'))";
  1736. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo052"), Lot, drLot["cFree6"]));
  1737. rowFilter += "AND (LEN(ISNULL(cFree7,''))<=0 OR (LEN(ISNULL(cFree7,''))>0 AND cFree7='" + drLot["cFree7"] + "'))";
  1738. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo053"), Lot, drLot["cFree7"]));
  1739. rowFilter += "AND (LEN(ISNULL(cFree8,''))<=0 OR (LEN(ISNULL(cFree8,''))>0 AND cFree8='" + drLot["cFree8"] + "'))";
  1740. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo054"), Lot, drLot["cFree8"]));
  1741. rowFilter += "AND (LEN(ISNULL(cFree9,''))<=0 OR (LEN(ISNULL(cFree9,''))>0 AND cFree9='" + drLot["cFree9"] + "'))";
  1742. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo055"), Lot, drLot["cFree9"]));
  1743. rowFilter += "AND (LEN(ISNULL(cFree10,''))<=0 OR (LEN(ISNULL(cFree10,''))>0 AND cFree10='" + drLot["cFree10"] + "'))";
  1744. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo056"), Lot, drLot["cFree10"]));
  1745. if (flag != null && flag.Rows.Count > 0)
  1746. {
  1747. rowFilter += " AND LocationCode='" + drLot["LocationCode"] + "'";
  1748. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["LocationCode"]));
  1749. }
  1750. //保质期管理
  1751. var resultEffective = Effective(Lot, JsonData.WorkPoint, cmd, language);
  1752. //0 - 已经是最早的批次
  1753. //1 - 不管控
  1754. //2 - 提醒
  1755. //3 - 限制
  1756. if (resultEffective == "2")
  1757. {
  1758. msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
  1759. }
  1760. else if (resultEffective == "3")
  1761. {
  1762. msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
  1763. isLimit = true;
  1764. }
  1765. //先进先出判断
  1766. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, cmd, language);
  1767. //0 - 已经是最早的批次
  1768. //1 - 不管控
  1769. //2 - 提醒
  1770. //3 - 限制
  1771. if (result == "2")
  1772. {
  1773. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  1774. }
  1775. else if (result == "3")
  1776. {
  1777. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  1778. isLimit = true;
  1779. }
  1780. }
  1781. }
  1782. }
  1783. #endregion
  1784. //return table;
  1785. Result res = new Result();
  1786. res.Success = true;
  1787. res.Message = msg;// "接口调用成功!";
  1788. if (!isLimit)
  1789. res.Data = table;
  1790. return res;
  1791. //出库时
  1792. //Message无值、Data有值,可直接处理
  1793. //Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
  1794. //Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
  1795. }
  1796. catch (Exception ex)
  1797. {
  1798. log.Error(ex.Message);
  1799. throw new Exception(ex.Message);
  1800. }
  1801. finally
  1802. {
  1803. if (conn.State == ConnectionState.Open)
  1804. {
  1805. conn.Close();
  1806. }
  1807. conn.Dispose();
  1808. }
  1809. }
  1810. }
  1811. /// <summary>
  1812. /// 校验条码对应的物料、自由项等信息是否与源头单据匹配
  1813. /// </summary>
  1814. private static void CheckTrans(DataView dataView, string rowFilter, string message)
  1815. {
  1816. dataView.RowFilter = rowFilter;
  1817. if (dataView == null || dataView.Count <= 0)
  1818. throw new Exception(message);
  1819. }
  1820. #endregion
  1821. /// <summary>
  1822. /// 上架
  1823. /// </summary>BusinessCode,TransType 两个类型
  1824. /// <param name="JsonData"></param>
  1825. /// <returns></returns>
  1826. public static DataTable LOTStockCreate(List<LOTStockUpCreateIModel> JsonData)
  1827. {
  1828. var language = LanguageHelper.GetName("WMSAPIInfo");
  1829. if (JsonData.Count <= 0)
  1830. {
  1831. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  1832. }
  1833. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1834. {
  1835. conn.Open();
  1836. SqlTransaction sqlTran = conn.BeginTransaction();
  1837. SqlCommand cmd = new SqlCommand();
  1838. cmd.Transaction = sqlTran;
  1839. cmd.Connection = conn;
  1840. string BusinessCode = string.Empty;
  1841. try
  1842. {
  1843. string TransType = string.Empty;
  1844. string Identification = Guid.NewGuid().ToString();
  1845. foreach (var item in JsonData)
  1846. {
  1847. TransType = item.TransType;
  1848. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  1849. {
  1850. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  1851. }
  1852. string WHTransType = "2";
  1853. foreach (var itemInfo in item.detail)
  1854. {
  1855. #region 两步调入
  1856. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1857. {
  1858. //更新源头单据数量
  1859. ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1860. //入库
  1861. ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  1862. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  1863. }
  1864. #endregion
  1865. #region 销售退货-原条码
  1866. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1867. {
  1868. //更新源头单据数量
  1869. ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1870. //入库
  1871. BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription<DBValue>();
  1872. //入库
  1873. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  1874. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode);
  1875. //更新日志表源头单据信息
  1876. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  1877. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' AND TransCode='' AND TransSequence=''";
  1878. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  1879. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1880. {
  1881. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  1882. }
  1883. }
  1884. #endregion
  1885. else
  1886. {
  1887. #region 采购入库
  1888. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1889. {
  1890. //更新源头单据数量
  1891. ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1892. BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription<DBValue>();
  1893. }
  1894. #endregion
  1895. #region 审核的到货单
  1896. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1897. {
  1898. //更新源头单据数量
  1899. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1900. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  1901. }
  1902. #endregion
  1903. #region 采购拒收
  1904. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1905. {
  1906. //更新源头单据数量
  1907. ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1908. BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription<DBValue>();
  1909. }
  1910. #endregion
  1911. #region 审核的委外到货单
  1912. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1913. {
  1914. //更新源头单据数量
  1915. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1916. BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  1917. }
  1918. #endregion
  1919. #region 委外拒收
  1920. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1921. {
  1922. //更新源头单据数量
  1923. ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1924. BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription<DBValue>();
  1925. }
  1926. #endregion
  1927. #region 委外退料
  1928. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1929. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1930. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1931. {
  1932. //更新源头单据数量
  1933. ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1934. BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  1935. }
  1936. #endregion
  1937. #region 返工工单
  1938. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1939. {
  1940. //更新源头单据数量
  1941. ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>(), cmd, language);
  1942. BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>();
  1943. }
  1944. #endregion
  1945. #region 委外入库
  1946. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1947. {
  1948. //更新源头单据数量
  1949. ICSOutsourcingService.OutsourcingReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1950. BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>();
  1951. }
  1952. #endregion
  1953. #region 生产退料
  1954. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1955. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1956. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1957. {
  1958. //更新源头单据数量
  1959. ICSManufactureService.MOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1960. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  1961. }
  1962. #endregion
  1963. #region 生产入库
  1964. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1965. {
  1966. //更新源头单据数量
  1967. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1968. BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  1969. }
  1970. #endregion
  1971. #region 开立的生产入库单
  1972. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1973. {
  1974. //更新源头单据数量
  1975. ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1976. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  1977. }
  1978. #endregion
  1979. #region 销售退货
  1980. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1981. {
  1982. //更新源头单据数量
  1983. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1984. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  1985. }
  1986. #endregion
  1987. #region 其他入库
  1988. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1989. {
  1990. //更新源头单据数量
  1991. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1992. BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  1993. }
  1994. #endregion
  1995. #region 拆卸单
  1996. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1997. {
  1998. ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1999. WHTransType = "11";
  2000. BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription<DBValue>();
  2001. }
  2002. #endregion
  2003. #region 归还
  2004. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  2005. {
  2006. //更新源头单据数量
  2007. ICSWareHouseService.ReturnDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  2008. BusinessCode = TransTypeEnum.ReturnDoc.GetDescription<DBValue>();
  2009. }
  2010. #endregion
  2011. else
  2012. {
  2013. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2014. }
  2015. //入库
  2016. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  2017. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language,itemInfo.LogID,itemInfo.InvCode + itemInfo.WarehouseCode);
  2018. }
  2019. }
  2020. #region 拆卸单
  2021. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  2022. {
  2023. //更新套件锁定数量
  2024. ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
  2025. }
  2026. #endregion}
  2027. }
  2028. //上传ERP
  2029. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2030. {
  2031. //采购入库
  2032. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  2033. ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  2034. //审核的到货单
  2035. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  2036. ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  2037. //采购拒收
  2038. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  2039. ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  2040. //审核的委外到货单
  2041. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  2042. ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language, BusinessCode);
  2043. //委外拒收
  2044. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  2045. ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language, BusinessCode);
  2046. //委外退料
  2047. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  2048. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  2049. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  2050. ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2051. //委外入库
  2052. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  2053. ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language, BusinessCode);
  2054. //生产退料
  2055. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  2056. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  2057. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  2058. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2059. //生产入库
  2060. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  2061. ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language,BusinessCode);
  2062. //开立的生产入库单
  2063. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  2064. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  2065. //返工工单
  2066. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  2067. ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language, BusinessCode);
  2068. //销售退货
  2069. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  2070. ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2071. //两步调入
  2072. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  2073. ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language, BusinessCode);
  2074. //销售退货-原条码
  2075. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  2076. ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language, BusinessCode);
  2077. //其他入库
  2078. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  2079. ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language, BusinessCode);
  2080. //拆卸单
  2081. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  2082. ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language, BusinessCode);
  2083. //归还
  2084. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  2085. ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language, BusinessCode);
  2086. }
  2087. DataTable table = GetData(Identification, 1, cmd);
  2088. cmd.Transaction.Commit();
  2089. return table;
  2090. }
  2091. catch (Exception ex)
  2092. {
  2093. if (cmd.Transaction != null)
  2094. cmd.Transaction.Rollback();
  2095. log.Error(ex.Message);
  2096. throw new Exception(ex.Message);
  2097. }
  2098. finally
  2099. {
  2100. if (conn.State == ConnectionState.Open)
  2101. {
  2102. conn.Close();
  2103. }
  2104. conn.Dispose();
  2105. }
  2106. }
  2107. }
  2108. /// <summary>
  2109. /// 下架
  2110. /// </summary>
  2111. /// <param name="JsonData"></param>
  2112. /// <returns></returns>
  2113. public static DataTable LOTStockDownCreate(List<LOTStockModel> JsonData)
  2114. {
  2115. String PrintEnable = "";
  2116. var language = LanguageHelper.GetName("WMSAPIInfo");
  2117. if (JsonData.Count <= 0)
  2118. {
  2119. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2120. }
  2121. List<LOTStockModelList> model = new List<LOTStockModelList>();
  2122. DataTable printTable = new DataTable();
  2123. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2124. {
  2125. conn.Open();
  2126. SqlTransaction sqlTran = conn.BeginTransaction();
  2127. SqlCommand cmd = new SqlCommand();
  2128. cmd.Transaction = sqlTran;
  2129. cmd.Connection = conn;
  2130. string BusinessCode = string.Empty;
  2131. try
  2132. {
  2133. string TransType = string.Empty;
  2134. string Identification = Guid.NewGuid().ToString();
  2135. foreach (var item in JsonData)
  2136. {
  2137. TransType = item.TransType;
  2138. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  2139. {
  2140. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2141. }
  2142. else if (string.IsNullOrEmpty(item.TransCode))
  2143. {
  2144. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2145. }
  2146. string[] trans = item.TransCode.Split('~');
  2147. string MergeID = "";
  2148. if (trans.Length == 2)
  2149. {
  2150. MergeID = trans[0];
  2151. item.TransCode = trans[1];
  2152. }
  2153. #region 采购退货
  2154. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2155. {
  2156. BusinessCode = TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>();
  2157. //更新源头单据数量
  2158. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2159. foreach (var itemInfo in item.detail)
  2160. {
  2161. //出库
  2162. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2163. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language);
  2164. }
  2165. }
  2166. #endregion
  2167. #region 委外发料
  2168. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2169. {
  2170. BusinessCode = TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>();
  2171. //更新源头单据数量
  2172. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2173. foreach (var itemInfo in item.detail)
  2174. {
  2175. //出库
  2176. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2177. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2178. }
  2179. }
  2180. #endregion
  2181. #region 委外退货
  2182. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2183. {
  2184. BusinessCode = TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>();
  2185. //更新源头单据数量
  2186. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2187. foreach (var itemInfo in item.detail)
  2188. {
  2189. //出库
  2190. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2191. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language);
  2192. }
  2193. }
  2194. #endregion
  2195. #region 生产发料
  2196. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2197. {
  2198. BusinessCode = TransTypeEnum.MOIssueDoc.GetDescription<DBValue>();
  2199. //更新源头单据数量
  2200. ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2201. foreach (var itemInfo in item.detail)
  2202. {
  2203. //出库
  2204. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2205. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2206. }
  2207. }
  2208. #endregion
  2209. #region 销售出库
  2210. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2211. {
  2212. BusinessCode = TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>();
  2213. //更新源头单据数量
  2214. ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2215. foreach (var itemInfo in item.detail)
  2216. {
  2217. //出库
  2218. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2219. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2220. }
  2221. }
  2222. #endregion
  2223. #region 两步调出
  2224. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2225. {
  2226. BusinessCode = TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>();
  2227. //更新源头单据数量
  2228. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2229. foreach (var itemInfo in item.detail)
  2230. {
  2231. //出库
  2232. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2233. item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, MergeID);
  2234. }
  2235. }
  2236. #endregion
  2237. #region 其他出库
  2238. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2239. {
  2240. BusinessCode = TransTypeEnum.OtherOutDoc.GetDescription<DBValue>();
  2241. //更新源头单据数量
  2242. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2243. foreach (var itemInfo in item.detail)
  2244. {
  2245. //出库
  2246. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2247. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2248. }
  2249. }
  2250. #endregion
  2251. #region 领料申请单发料
  2252. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  2253. {
  2254. BusinessCode = TransTypeEnum.MOApply.GetDescription<DBValue>();
  2255. //更新源头单据数量
  2256. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2257. foreach (var itemInfo in item.detail)
  2258. {
  2259. //出库
  2260. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2261. item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  2262. }
  2263. }
  2264. #endregion
  2265. #region 委外领料申请单发料
  2266. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  2267. {
  2268. BusinessCode = TransTypeEnum.OOApply.GetDescription<DBValue>();
  2269. //更新源头单据数量
  2270. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2271. foreach (var itemInfo in item.detail)
  2272. {
  2273. //出库
  2274. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2275. item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language,MergeID);
  2276. }
  2277. }
  2278. #endregion
  2279. #region 开立材料出库
  2280. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2281. {
  2282. BusinessCode = TransTypeEnum.MOIssue.GetDescription<DBValue>();
  2283. //更新源头单据数量
  2284. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2285. foreach (var itemInfo in item.detail)
  2286. {
  2287. //出库
  2288. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2289. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  2290. }
  2291. }
  2292. #endregion
  2293. #region 开立委外材料出库
  2294. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2295. {
  2296. BusinessCode = TransTypeEnum.OOIssue.GetDescription<DBValue>();
  2297. //更新源头单据数量
  2298. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2299. foreach (var itemInfo in item.detail)
  2300. {
  2301. //出库
  2302. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2303. item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  2304. }
  2305. }
  2306. #endregion
  2307. #region 开立红字入库单
  2308. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2309. {
  2310. BusinessCode = TransTypeEnum.PurchaseReceive.GetDescription<DBValue>();
  2311. //更新源头单据数量
  2312. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2313. foreach (var itemInfo in item.detail)
  2314. {
  2315. //出库
  2316. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2317. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language);
  2318. }
  2319. }
  2320. #endregion
  2321. #region 开立委外红字入库单
  2322. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2323. {
  2324. BusinessCode = TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>();
  2325. //更新源头单据数量
  2326. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2327. foreach (var itemInfo in item.detail)
  2328. {
  2329. //出库
  2330. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2331. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language);
  2332. }
  2333. }
  2334. #endregion
  2335. #region 借用
  2336. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2337. {
  2338. BusinessCode = TransTypeEnum.BrrowDoc.GetDescription<DBValue>();
  2339. //更新源头单据数量
  2340. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2341. foreach (var itemInfo in item.detail)
  2342. {
  2343. //出库
  2344. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2345. item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2346. }
  2347. }
  2348. #endregion
  2349. else
  2350. {
  2351. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2352. }
  2353. }
  2354. //上传ERP
  2355. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2356. {
  2357. //采购退货
  2358. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2359. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language,BusinessCode);
  2360. //委外发料
  2361. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2362. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  2363. //委外退货
  2364. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2365. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language, BusinessCode);
  2366. //生产发料
  2367. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2368. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language, BusinessCode);
  2369. //销售出库
  2370. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2371. ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language, BusinessCode);
  2372. //两步调出
  2373. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2374. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language, BusinessCode);
  2375. //其他出库
  2376. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2377. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language, BusinessCode);
  2378. //领料申请单发料
  2379. if (TransType == TransTypeEnum.MOApply.GetDescription())
  2380. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  2381. //委外领料申请单发料
  2382. if (TransType == TransTypeEnum.OOApply.GetDescription())
  2383. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language, BusinessCode);
  2384. //开立材料出库
  2385. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2386. ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  2387. //开立委外材料出库
  2388. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2389. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language, BusinessCode);
  2390. //开立红字入库单
  2391. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2392. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language, BusinessCode);
  2393. //开立委外红字入库单
  2394. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2395. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language, BusinessCode);
  2396. //借用
  2397. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2398. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language, BusinessCode);
  2399. }
  2400. if (!printTable.Equals("{}"))
  2401. {
  2402. cmd.Transaction.Commit();
  2403. return printTable;
  2404. }
  2405. else
  2406. {
  2407. DataTable table = GetData(Identification, 2, cmd);
  2408. cmd.Transaction.Commit();
  2409. return table;
  2410. }
  2411. }
  2412. catch (Exception ex)
  2413. {
  2414. if (cmd.Transaction != null)
  2415. cmd.Transaction.Rollback();
  2416. log.Error(ex.Message);
  2417. throw new Exception(ex.Message);
  2418. }
  2419. finally
  2420. {
  2421. if (conn.State == ConnectionState.Open)
  2422. {
  2423. conn.Close();
  2424. }
  2425. conn.Dispose();
  2426. }
  2427. }
  2428. }
  2429. #region 采购
  2430. /// <summary>
  2431. /// 采购到货
  2432. /// </summary>
  2433. /// <param name="JsonData"></param>
  2434. /// <returns></returns>
  2435. public static DataTable DeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  2436. {
  2437. var language = LanguageHelper.GetName("WMSAPIInfo");
  2438. if (JsonData.Count <= 0)
  2439. {
  2440. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2441. }
  2442. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2443. {
  2444. conn.Open();
  2445. SqlTransaction sqlTran = conn.BeginTransaction();
  2446. SqlCommand cmd = new SqlCommand();
  2447. cmd.Transaction = sqlTran;
  2448. cmd.Connection = conn;
  2449. try
  2450. {
  2451. string asncodes = string.Empty;
  2452. string sql = string.Empty;
  2453. foreach (var item in JsonData)
  2454. {
  2455. if (string.IsNullOrEmpty(item.ASNCode))
  2456. {
  2457. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
  2458. }
  2459. //获取单号
  2460. sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  2461. BEGIN
  2462. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  2463. RETURN
  2464. END
  2465. DECLARE @Status VARCHAR(10)
  2466. SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  2467. IF (@Status IS NULL)
  2468. BEGIN
  2469. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  2470. RETURN
  2471. END
  2472. ELSE IF (@Status!='2')
  2473. BEGIN
  2474. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  2475. RETURN
  2476. END
  2477. DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2478. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2479. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2480. IF @MaxNO IS NULL
  2481. BEGIN
  2482. SELECT @date+'00001' AS Code
  2483. END
  2484. ELSE
  2485. BEGIN
  2486. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2487. END ";
  2488. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  2489. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2490. //修改送货单到货数量
  2491. foreach (var itemInfo in item.detail)
  2492. {
  2493. sql = @"UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
  2494. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2495. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  2496. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2497. {
  2498. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
  2499. }
  2500. }
  2501. //创建到货单信息
  2502. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  2503. BEGIN
  2504. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  2505. RETURN
  2506. END
  2507. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2508. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2509. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2510. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2511. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2512. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  2513. '1',b.InvCode,SUM(a.DNQuantity),'0','0',
  2514. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  2515. d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,
  2516. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode
  2517. FROM ICSASNDetail a
  2518. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2519. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  2520. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  2521. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  2522. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}'
  2523. 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";
  2524. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode);
  2525. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2526. {
  2527. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  2528. }
  2529. ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  2530. asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
  2531. }
  2532. if (string.IsNullOrWhiteSpace(asncodes))
  2533. {
  2534. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  2535. }
  2536. #region 查询返回数据
  2537. sql = @"SELECT
  2538. n.POCode,
  2539. n.Sequence AS POSequence,
  2540. a.ASNCode,
  2541. a.DNCode,
  2542. a.Sequence,
  2543. a.VenCode,
  2544. a.DepCode,
  2545. a.InvCode,
  2546. inv.InvName,
  2547. inv.InvStd,
  2548. a.Quantity,
  2549. inv.InvUnit,
  2550. a.Amount,
  2551. inv.AmountUnit,
  2552. a.RCVQuantity,
  2553. a.UnitPrice,
  2554. a.Currency,
  2555. a.POID,
  2556. a.PODetailID,
  2557. a.DNID,
  2558. a.DNDetailID,
  2559. ext.ProjectCode,
  2560. ext.BatchCode,
  2561. ext.Version,
  2562. ext.Brand,
  2563. ext.cFree1,
  2564. ext.cFree2,
  2565. ext.cFree3,
  2566. ext.cFree4,
  2567. ext.cFree5,
  2568. ext.cFree6,
  2569. ext.cFree7,
  2570. ext.cFree8,
  2571. ext.cFree9,
  2572. ext.cFree10,
  2573. a.MUSER AS [User],
  2574. a.MTIME AS [MTime]
  2575. FROM ICSDeliveryNotice a
  2576. INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
  2577. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2578. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2579. WHERE a.ASNCode+a.WorkPoint IN ({0})";
  2580. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  2581. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2582. #endregion
  2583. cmd.Transaction.Commit();
  2584. return data;
  2585. }
  2586. catch (Exception ex)
  2587. {
  2588. if (cmd.Transaction != null)
  2589. cmd.Transaction.Rollback();
  2590. log.Error(ex.Message);
  2591. throw new Exception(ex.Message);
  2592. }
  2593. finally
  2594. {
  2595. if (conn.State == ConnectionState.Open)
  2596. {
  2597. conn.Close();
  2598. }
  2599. conn.Dispose();
  2600. }
  2601. }
  2602. }
  2603. /// <summary>
  2604. /// 采购拒收
  2605. /// </summary>
  2606. /// <param name="JsonData"></param>
  2607. /// <returns></returns>
  2608. public static DataTable PurchaseRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  2609. {
  2610. var language = LanguageHelper.GetName("WMSAPIInfo");
  2611. if (JsonData.Count <= 0)
  2612. {
  2613. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2614. }
  2615. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2616. {
  2617. conn.Open();
  2618. SqlTransaction sqlTran = conn.BeginTransaction();
  2619. SqlCommand cmd = new SqlCommand();
  2620. cmd.Transaction = sqlTran;
  2621. cmd.Connection = conn;
  2622. try
  2623. {
  2624. string lots = string.Empty;
  2625. string sql = string.Empty;
  2626. foreach (var item in JsonData)
  2627. {
  2628. if (string.IsNullOrEmpty(item.DNCode))
  2629. {
  2630. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  2631. }
  2632. //获取单号
  2633. sql = @"DECLARE @Status VARCHAR(10)
  2634. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  2635. IF (@Status IS NULL)
  2636. BEGIN
  2637. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  2638. RETURN
  2639. END
  2640. ELSE IF (@Status!='2')
  2641. BEGIN
  2642. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  2643. RETURN
  2644. END
  2645. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2646. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2647. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2648. IF @MaxNO IS NULL
  2649. BEGIN
  2650. SELECT @date+'00001' AS Code
  2651. END
  2652. ELSE
  2653. BEGIN
  2654. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2655. END ";
  2656. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  2657. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2658. //修改送货单到货数量
  2659. foreach (var itemInfo in item.detail)
  2660. {
  2661. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  2662. BEGIN
  2663. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  2664. RETURN
  2665. END
  2666. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  2667. BEGIN
  2668. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  2669. RETURN
  2670. END
  2671. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2672. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2673. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2674. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2675. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2676. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  2677. '3',d.InvCode,'{7}', '{8}', 0,
  2678. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  2679. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  2680. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  2681. FROM ICSDeliveryNotice a
  2682. INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  2683. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  2684. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  2685. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  2686. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  2687. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  2688. WHERE a.DNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  2689. 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);
  2690. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2691. {
  2692. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  2693. }
  2694. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  2695. }
  2696. ICSPurchaseService.PurchaseRejectDocInNewERP(item.DNCode, Code, item.WorkPoint, cmd, language);
  2697. }
  2698. if (string.IsNullOrWhiteSpace(lots))
  2699. {
  2700. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  2701. }
  2702. #region 查询返回数据
  2703. sql = @"SELECT
  2704. n.DNCode,
  2705. n.Sequence,
  2706. a.DNCode AS RJTCode,
  2707. a.Sequence AS RJTSequence,
  2708. a.VenCode,
  2709. a.DepCode,
  2710. a.InvCode,
  2711. inv.InvName,
  2712. inv.InvStd,
  2713. a.Quantity,
  2714. inv.InvUnit,
  2715. a.Amount,
  2716. inv.AmountUnit,
  2717. a.RCVQuantity,
  2718. a.UnitPrice,
  2719. a.Currency,
  2720. a.POID,
  2721. a.PODetailID,
  2722. a.DNID,
  2723. a.DNDetailID,
  2724. ext.ProjectCode,
  2725. ext.BatchCode,
  2726. ext.Version,
  2727. ext.Brand,
  2728. ext.cFree1,
  2729. ext.cFree2,
  2730. ext.cFree3,
  2731. ext.cFree4,
  2732. ext.cFree5,
  2733. ext.cFree6,
  2734. ext.cFree7,
  2735. ext.cFree8,
  2736. ext.cFree9,
  2737. ext.cFree10,
  2738. a.MUSER AS [User],
  2739. a.MTIME AS [MTime]
  2740. FROM ICSDeliveryNotice a
  2741. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  2742. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2743. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2744. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  2745. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  2746. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2747. #endregion
  2748. cmd.Transaction.Commit();
  2749. return data;
  2750. }
  2751. catch (Exception ex)
  2752. {
  2753. if (cmd.Transaction != null)
  2754. cmd.Transaction.Rollback();
  2755. log.Error(ex.Message);
  2756. throw new Exception(ex.Message);
  2757. }
  2758. finally
  2759. {
  2760. if (conn.State == ConnectionState.Open)
  2761. {
  2762. conn.Close();
  2763. }
  2764. conn.Dispose();
  2765. }
  2766. }
  2767. }
  2768. #endregion
  2769. #region 委外
  2770. /// <summary>
  2771. /// 委外退料 新建
  2772. /// </summary>
  2773. /// <param name="JsonData"></param>
  2774. /// <returns></returns>
  2775. public static DataTable OutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  2776. {
  2777. var language = LanguageHelper.GetName("WMSAPIInfo");
  2778. if (JsonData.Count <= 0)
  2779. {
  2780. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2781. }
  2782. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2783. {
  2784. conn.Open();
  2785. SqlTransaction sqlTran = conn.BeginTransaction();
  2786. SqlCommand cmd = new SqlCommand();
  2787. cmd.Transaction = sqlTran;
  2788. cmd.Connection = conn;
  2789. try
  2790. {
  2791. string codes = string.Empty;
  2792. string sql = string.Empty;
  2793. foreach (var item in JsonData)
  2794. {
  2795. //获取单号
  2796. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2797. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  2798. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  2799. IF @MaxNO IS NULL
  2800. BEGIN
  2801. SELECT @date+'00001' AS Code
  2802. END
  2803. ELSE
  2804. BEGIN
  2805. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2806. END ";
  2807. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2808. //创建主表
  2809. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  2810. BEGIN
  2811. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2812. RETURN
  2813. END
  2814. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2815. 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}','')";
  2816. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  2817. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2818. {
  2819. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  2820. }
  2821. foreach (var itemInfo in item.detail)
  2822. {
  2823. //创建子表
  2824. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  2825. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  2826. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  2827. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  2828. '{4}','{5}',0,'{6}','{7}',
  2829. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  2830. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  2831. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2832. {
  2833. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  2834. }
  2835. }
  2836. //校验退料数量是否超出领料数量
  2837. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  2838. DBHelper.ExecuteNonQuery(sql, cmd);
  2839. codes += "'" + Code + item.WorkPoint + "',";
  2840. }
  2841. if (string.IsNullOrWhiteSpace(codes))
  2842. {
  2843. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2844. }
  2845. #region 查询返回数据
  2846. sql = @"SELECT a.OApplyNegCode,
  2847. c.WHCode,
  2848. c.Memo,
  2849. d.Name AS Status,
  2850. a.Sequence,
  2851. a.InvCode,
  2852. inv.InvName,
  2853. inv.InvStd,
  2854. a.Quantity,
  2855. inv.InvUnit,
  2856. a.Amount,
  2857. inv.AmountUnit,
  2858. a.IssueNegQuantity,
  2859. ext.ProjectCode,
  2860. ext.BatchCode,
  2861. ext.Version,
  2862. ext.Brand,
  2863. ext.cFree1,
  2864. ext.cFree2,
  2865. ext.cFree3,
  2866. ext.cFree4,
  2867. ext.cFree5,
  2868. ext.cFree6,
  2869. ext.cFree7,
  2870. ext.cFree8,
  2871. ext.cFree9,
  2872. ext.cFree10,
  2873. a.MUSER AS [User],
  2874. a.MTIME AS [MTime]
  2875. FROM ICSOApplyNegDetail a
  2876. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2877. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  2878. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2879. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2880. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  2881. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  2882. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2883. #endregion
  2884. cmd.Transaction.Commit();
  2885. return data;
  2886. }
  2887. catch (Exception ex)
  2888. {
  2889. if (cmd.Transaction != null)
  2890. cmd.Transaction.Rollback();
  2891. log.Error(ex.Message);
  2892. throw new Exception(ex.Message);
  2893. }
  2894. finally
  2895. {
  2896. if (conn.State == ConnectionState.Open)
  2897. {
  2898. conn.Close();
  2899. }
  2900. conn.Dispose();
  2901. }
  2902. }
  2903. }
  2904. private static string CheckOutsourcingIssueDoc(string Type, string Code, string WorkPoint, Dictionary<string, string> language)
  2905. {
  2906. string sql = string.Empty;
  2907. if (Type == "1")
  2908. {
  2909. sql = @"DECLARE @PickID VARCHAR(10)
  2910. SELECT @PickID=b.PickID
  2911. FROM ICSOApplyNegDetail a
  2912. INNER JOIN ICSOOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  2913. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2914. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2915. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2916. FROM ICSOApplyNegDetail a
  2917. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2918. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2919. GROUP BY b.PickID
  2920. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2921. IF (@PickID IS NOT NULL)
  2922. BEGIN
  2923. DECLARE @InvCode VARCHAR(100)
  2924. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  2925. RAISERROR(@InvCode,16,1);
  2926. RETURN
  2927. END ";
  2928. }
  2929. else if (Type == "2")
  2930. {
  2931. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  2932. SELECT @ApplyDetailID=b.ApplyDetailID
  2933. FROM ICSOApplyNegDetail a
  2934. INNER JOIN ICSOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  2935. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2936. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2937. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2938. FROM ICSOApplyNegDetail a
  2939. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2940. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2941. GROUP BY b.ApplyDetailID
  2942. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2943. IF (@ApplyDetailID IS NOT NULL)
  2944. BEGIN
  2945. DECLARE @InvCode VARCHAR(100)
  2946. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  2947. RAISERROR(@InvCode,16,1);
  2948. RETURN
  2949. END ";
  2950. }
  2951. else if (Type == "3")
  2952. {
  2953. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  2954. SELECT @IssueDetailID=b.IssueDetailID
  2955. FROM ICSOApplyNegDetail a
  2956. INNER JOIN ICSOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  2957. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2958. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2959. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2960. FROM ICSOApplyNegDetail a
  2961. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2962. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2963. GROUP BY b.IssueDetailID
  2964. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2965. IF (@IssueDetailID IS NOT NULL)
  2966. BEGIN
  2967. DECLARE @InvCode VARCHAR(100)
  2968. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  2969. RAISERROR(@InvCode,16,1);
  2970. RETURN
  2971. END ";
  2972. }
  2973. else
  2974. {
  2975. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  2976. }
  2977. sql = string.Format(sql, Code, WorkPoint, Type);
  2978. return sql;
  2979. }
  2980. /// <summary>
  2981. /// 委外退料 修改
  2982. /// </summary>
  2983. /// <param name="JsonData"></param>
  2984. /// <returns></returns>
  2985. public static DataTable OutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  2986. {
  2987. var language = LanguageHelper.GetName("WMSAPIInfo");
  2988. if (JsonData.Count <= 0)
  2989. {
  2990. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2991. }
  2992. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2993. {
  2994. conn.Open();
  2995. SqlTransaction sqlTran = conn.BeginTransaction();
  2996. SqlCommand cmd = new SqlCommand();
  2997. cmd.Transaction = sqlTran;
  2998. cmd.Connection = conn;
  2999. try
  3000. {
  3001. string sql = string.Empty;
  3002. string Code = string.Empty;
  3003. string ids = string.Empty;
  3004. foreach (var item in JsonData)
  3005. {
  3006. //主表修改
  3007. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  3008. BEGIN
  3009. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  3010. RETURN
  3011. END
  3012. DECLARE @Status VARCHAR(10)
  3013. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  3014. IF (@Status IS NULL)
  3015. BEGIN
  3016. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  3017. RETURN
  3018. END
  3019. ELSE IF (@Status!='1')
  3020. BEGIN
  3021. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  3022. RETURN
  3023. END
  3024. 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}' ";
  3025. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  3026. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3027. {
  3028. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  3029. }
  3030. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  3031. if (detail > 0)
  3032. {
  3033. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  3034. sql = string.Format(sql, item.id, item.WorkPoint);
  3035. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3036. }
  3037. foreach (var itemInfo in item.detail)
  3038. {
  3039. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  3040. {
  3041. //创建子表
  3042. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  3043. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3044. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3045. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3046. '{4}','{5}',0,'{6}','{7}',
  3047. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3048. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3049. }
  3050. else
  3051. {
  3052. //子表修改
  3053. 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}'";
  3054. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  3055. }
  3056. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3057. {
  3058. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  3059. }
  3060. }
  3061. //校验退料数量是否超出领料数量
  3062. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  3063. DBHelper.ExecuteNonQuery(sql, cmd);
  3064. ids += "'" + item.id + "',";
  3065. }
  3066. if (string.IsNullOrWhiteSpace(ids))
  3067. {
  3068. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3069. }
  3070. #region 查询返回数据
  3071. sql = @"SELECT a.OApplyNegCode,
  3072. c.WHCode,
  3073. c.Memo,
  3074. d.Name AS Status,
  3075. a.Sequence,
  3076. a.InvCode,
  3077. inv.InvName,
  3078. inv.InvStd,
  3079. a.Quantity,
  3080. inv.InvUnit,
  3081. a.Amount,
  3082. inv.AmountUnit,
  3083. a.IssueNegQuantity,
  3084. ext.ProjectCode,
  3085. ext.BatchCode,
  3086. ext.Version,
  3087. ext.Brand,
  3088. ext.cFree1,
  3089. ext.cFree2,
  3090. ext.cFree3,
  3091. ext.cFree4,
  3092. ext.cFree5,
  3093. ext.cFree6,
  3094. ext.cFree7,
  3095. ext.cFree8,
  3096. ext.cFree9,
  3097. ext.cFree10,
  3098. a.MUSER AS [User],
  3099. a.MTIME AS [MTime]
  3100. FROM ICSOApplyNegDetail a
  3101. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3102. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3103. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3104. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3105. WHERE c.ID IN ({0})";
  3106. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3107. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3108. #endregion
  3109. cmd.Transaction.Commit();
  3110. return data;
  3111. }
  3112. catch (Exception ex)
  3113. {
  3114. if (cmd.Transaction != null)
  3115. cmd.Transaction.Rollback();
  3116. log.Error(ex.Message);
  3117. throw new Exception(ex.Message);
  3118. }
  3119. finally
  3120. {
  3121. if (conn.State == ConnectionState.Open)
  3122. {
  3123. conn.Close();
  3124. }
  3125. conn.Dispose();
  3126. }
  3127. }
  3128. }
  3129. /// <summary>
  3130. /// 委外退料审核
  3131. /// </summary>
  3132. /// <param name="JsonData"></param>
  3133. /// <returns></returns>
  3134. public static DataTable OutsourcingIssueDoNegativeApplyApprove(List<ICSUser> JsonData)
  3135. {
  3136. var language = LanguageHelper.GetName("WMSAPIInfo");
  3137. if (JsonData.Count <= 0)
  3138. {
  3139. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3140. }
  3141. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3142. {
  3143. conn.Open();
  3144. SqlTransaction sqlTran = conn.BeginTransaction();
  3145. SqlCommand cmd = new SqlCommand();
  3146. cmd.Transaction = sqlTran;
  3147. cmd.Connection = conn;
  3148. try
  3149. {
  3150. string sql = string.Empty;
  3151. string ids = string.Empty;
  3152. foreach (var item in JsonData)
  3153. {
  3154. if (string.IsNullOrEmpty(item.ID))
  3155. {
  3156. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  3157. }
  3158. if (string.IsNullOrEmpty(item.User))
  3159. {
  3160. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  3161. }
  3162. if (item.MTime <= new DateTime(2000, 1, 1))
  3163. {
  3164. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  3165. }
  3166. //获取单号
  3167. sql = @"DECLARE @Status VARCHAR(10)
  3168. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  3169. IF (@Status IS NULL)
  3170. BEGIN
  3171. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  3172. RETURN
  3173. END
  3174. ELSE IF (@Status!='1')
  3175. BEGIN
  3176. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  3177. RETURN
  3178. END
  3179. update ICSOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  3180. sql = string.Format(sql, item.ID, item.User, item.MTime);
  3181. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3182. {
  3183. throw new Exception(language.GetNameByCode("WMSAPIInfo021"));//"委外退料申请单审核失败!");
  3184. }
  3185. ids += "'" + item.ID + "',";
  3186. }
  3187. if (string.IsNullOrWhiteSpace(ids))
  3188. {
  3189. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3190. }
  3191. #region 查询返回数据
  3192. sql = @"SELECT a.OApplyNegCode,
  3193. c.WHCode,
  3194. c.Memo,
  3195. d.Name AS Status,
  3196. a.Sequence,
  3197. a.InvCode,
  3198. inv.InvName,
  3199. inv.InvStd,
  3200. a.Quantity,
  3201. inv.InvUnit,
  3202. a.Amount,
  3203. inv.AmountUnit,
  3204. a.IssueNegQuantity,
  3205. ext.ProjectCode,
  3206. ext.BatchCode,
  3207. ext.Version,
  3208. ext.Brand,
  3209. ext.cFree1,
  3210. ext.cFree2,
  3211. ext.cFree3,
  3212. ext.cFree4,
  3213. ext.cFree5,
  3214. ext.cFree6,
  3215. ext.cFree7,
  3216. ext.cFree8,
  3217. ext.cFree9,
  3218. ext.cFree10,
  3219. a.MUSER AS [User],
  3220. a.MTIME AS [MTime]
  3221. FROM ICSOApplyNegDetail a
  3222. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  3223. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3224. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3225. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3226. WHERE c.ID IN ({0})";
  3227. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3228. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3229. #endregion
  3230. cmd.Transaction.Commit();
  3231. return data;
  3232. }
  3233. catch (Exception ex)
  3234. {
  3235. if (cmd.Transaction != null)
  3236. cmd.Transaction.Rollback();
  3237. log.Error(ex.Message);
  3238. throw new Exception(ex.Message);
  3239. }
  3240. finally
  3241. {
  3242. if (conn.State == ConnectionState.Open)
  3243. {
  3244. conn.Close();
  3245. }
  3246. conn.Dispose();
  3247. }
  3248. }
  3249. }
  3250. /// <summary>
  3251. /// 委外到货
  3252. /// </summary>
  3253. /// <param name="JsonData"></param>
  3254. /// <returns></returns>
  3255. public static DataTable OutsourcingDeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  3256. {
  3257. var language = LanguageHelper.GetName("WMSAPIInfo");
  3258. if (JsonData.Count <= 0)
  3259. {
  3260. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3261. }
  3262. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3263. {
  3264. conn.Open();
  3265. SqlTransaction sqlTran = conn.BeginTransaction();
  3266. SqlCommand cmd = new SqlCommand();
  3267. cmd.Transaction = sqlTran;
  3268. cmd.Connection = conn;
  3269. try
  3270. {
  3271. string asncodes = string.Empty;
  3272. string sql = string.Empty;
  3273. foreach (var item in JsonData)
  3274. {
  3275. if (string.IsNullOrEmpty(item.OASNCode))
  3276. {
  3277. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!");
  3278. }
  3279. //获取单号
  3280. sql = @"IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.OASNCode='{0}' AND ODNType = '1' AND a.WorkPoint='{1}')
  3281. BEGIN
  3282. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  3283. RETURN
  3284. END
  3285. DECLARE @Status VARCHAR(10)
  3286. SELECT @Status=Status FROM ICSOASN WHERE OASNCode='{0}' and WorkPoint='{1}'
  3287. IF (@Status IS NULL)
  3288. BEGIN
  3289. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  3290. RETURN
  3291. END
  3292. ELSE IF (@Status!='2')
  3293. BEGIN
  3294. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  3295. RETURN
  3296. END
  3297. DECLARE @MaxNO INT,@date varchar(20)='ODN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3298. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3299. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3300. IF @MaxNO IS NULL
  3301. BEGIN
  3302. SELECT @date+'00001' AS Code
  3303. END
  3304. ELSE
  3305. BEGIN
  3306. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3307. END ";
  3308. sql = string.Format(sql, item.OASNCode, item.WorkPoint);
  3309. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3310. //修改送货单到货数量
  3311. foreach (var itemInfo in item.detail)
  3312. {
  3313. sql = @"UPDATE ICSOASNDetail SET ODNQuantity=ISNULL(ODNQuantity, 0)+'{2}'
  3314. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3315. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  3316. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3317. {
  3318. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"委外送货单子表信息更新失败!");
  3319. }
  3320. }
  3321. //创建到货单信息
  3322. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  3323. BEGIN
  3324. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  3325. RETURN
  3326. END
  3327. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3328. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3329. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3330. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3331. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3332. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  3333. '1',b.InvCode,SUM(a.ODNQuantity),'0','0',
  3334. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  3335. d.OOID,d.OODetailID,newid(),newid(),b.ExtensionID,
  3336. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.OASNCode
  3337. FROM ICSOASNDetail a
  3338. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3339. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  3340. INNER JOIN ICSOutsourcingOrder d ON c.TransCode=d.OOCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  3341. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  3342. WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
  3343. 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";
  3344. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.OASNCode);
  3345. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3346. {
  3347. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  3348. }
  3349. ICSOutsourcingService.OutsourcingDeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  3350. asncodes += "'" + item.OASNCode + item.WorkPoint + "',";
  3351. }
  3352. if (string.IsNullOrWhiteSpace(asncodes))
  3353. {
  3354. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  3355. }
  3356. #region 查询返回数据
  3357. sql = @"SELECT
  3358. n.OOCode,
  3359. n.Sequence AS OOSequence,
  3360. a.OASNCode,
  3361. a.ODNCode,
  3362. a.Sequence,
  3363. a.VenCode,
  3364. a.DepCode,
  3365. a.InvCode,
  3366. inv.InvName,
  3367. inv.InvStd,
  3368. a.Quantity,
  3369. inv.InvUnit,
  3370. a.Amount,
  3371. inv.AmountUnit,
  3372. a.RCVQuantity,
  3373. a.UnitPrice,
  3374. a.Currency,
  3375. a.OOID,
  3376. a.OODetailID,
  3377. a.ODNID,
  3378. a.ODNDetailID,
  3379. ext.ProjectCode,
  3380. ext.BatchCode,
  3381. ext.Version,
  3382. ext.Brand,
  3383. ext.cFree1,
  3384. ext.cFree2,
  3385. ext.cFree3,
  3386. ext.cFree4,
  3387. ext.cFree5,
  3388. ext.cFree6,
  3389. ext.cFree7,
  3390. ext.cFree8,
  3391. ext.cFree9,
  3392. ext.cFree10,
  3393. a.MUSER AS [User],
  3394. a.MTIME AS [MTime]
  3395. FROM ICSODeliveryNotice a
  3396. INNER JOIN ICSOutsourcingOrder n ON a.OOID =n.OOID AND a.OODetailID=n.OODetailID AND a.WorkPoint=n.WorkPoint
  3397. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3398. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3399. WHERE a.OASNCode+a.WorkPoint IN ({0})";
  3400. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  3401. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3402. #endregion
  3403. cmd.Transaction.Commit();
  3404. return data;
  3405. }
  3406. catch (Exception ex)
  3407. {
  3408. if (cmd.Transaction != null)
  3409. cmd.Transaction.Rollback();
  3410. log.Error(ex.Message);
  3411. throw new Exception(ex.Message);
  3412. }
  3413. finally
  3414. {
  3415. if (conn.State == ConnectionState.Open)
  3416. {
  3417. conn.Close();
  3418. }
  3419. conn.Dispose();
  3420. }
  3421. }
  3422. }
  3423. /// <summary>
  3424. /// 委外拒收
  3425. /// </summary>
  3426. /// <param name="JsonData"></param>
  3427. /// <returns></returns>
  3428. public static DataTable OutsourcingRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  3429. {
  3430. var language = LanguageHelper.GetName("WMSAPIInfo");
  3431. if (JsonData.Count <= 0)
  3432. {
  3433. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3434. }
  3435. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3436. {
  3437. conn.Open();
  3438. SqlTransaction sqlTran = conn.BeginTransaction();
  3439. SqlCommand cmd = new SqlCommand();
  3440. cmd.Transaction = sqlTran;
  3441. cmd.Connection = conn;
  3442. try
  3443. {
  3444. string lots = string.Empty;
  3445. string sql = string.Empty;
  3446. foreach (var item in JsonData)
  3447. {
  3448. if (string.IsNullOrEmpty(item.ODNCode))
  3449. {
  3450. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  3451. }
  3452. //获取单号
  3453. sql = @"DECLARE @Status VARCHAR(10)
  3454. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  3455. IF (@Status IS NULL)
  3456. BEGIN
  3457. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  3458. RETURN
  3459. END
  3460. ELSE IF (@Status!='2')
  3461. BEGIN
  3462. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  3463. RETURN
  3464. END
  3465. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3466. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3467. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3468. IF @MaxNO IS NULL
  3469. BEGIN
  3470. SELECT @date+'00001' AS Code
  3471. END
  3472. ELSE
  3473. BEGIN
  3474. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3475. END ";
  3476. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  3477. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3478. //修改送货单到货数量
  3479. foreach (var itemInfo in item.detail)
  3480. {
  3481. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  3482. BEGIN
  3483. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  3484. RETURN
  3485. END
  3486. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  3487. BEGIN
  3488. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  3489. RETURN
  3490. END
  3491. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3492. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3493. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3494. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3495. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3496. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  3497. '3',d.InvCode,'{7}', '{8}', 0,
  3498. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  3499. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  3500. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  3501. FROM ICSODeliveryNotice a
  3502. INNER JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  3503. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  3504. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  3505. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND a.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  3506. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  3507. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  3508. WHERE a.ODNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  3509. 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);
  3510. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3511. {
  3512. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  3513. }
  3514. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  3515. }
  3516. ICSOutsourcingService.OutsourcingRejectDocInNewERP(item.ODNCode, Code, item.WorkPoint, cmd, language);
  3517. }
  3518. if (string.IsNullOrWhiteSpace(lots))
  3519. {
  3520. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  3521. }
  3522. #region 查询返回数据
  3523. sql = @"SELECT
  3524. n.ODNCode,
  3525. n.Sequence,
  3526. a.ODNCode AS RJTCode,
  3527. a.Sequence AS RJTSequence,
  3528. a.VenCode,
  3529. a.DepCode,
  3530. a.InvCode,
  3531. inv.InvName,
  3532. inv.InvStd,
  3533. a.Quantity,
  3534. inv.InvUnit,
  3535. a.Amount,
  3536. inv.AmountUnit,
  3537. a.RCVQuantity,
  3538. a.UnitPrice,
  3539. a.Currency,
  3540. a.OOID,
  3541. a.OODetailID,
  3542. a.ODNID,
  3543. a.ODNDetailID,
  3544. ext.ProjectCode,
  3545. ext.BatchCode,
  3546. ext.Version,
  3547. ext.Brand,
  3548. ext.cFree1,
  3549. ext.cFree2,
  3550. ext.cFree3,
  3551. ext.cFree4,
  3552. ext.cFree5,
  3553. ext.cFree6,
  3554. ext.cFree7,
  3555. ext.cFree8,
  3556. ext.cFree9,
  3557. ext.cFree10,
  3558. a.MUSER AS [User],
  3559. a.MTIME AS [MTime]
  3560. FROM ICSODeliveryNotice a
  3561. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  3562. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3563. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3564. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  3565. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  3566. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3567. #endregion
  3568. cmd.Transaction.Commit();
  3569. return data;
  3570. }
  3571. catch (Exception ex)
  3572. {
  3573. if (cmd.Transaction != null)
  3574. cmd.Transaction.Rollback();
  3575. log.Error(ex.Message);
  3576. throw new Exception(ex.Message);
  3577. }
  3578. finally
  3579. {
  3580. if (conn.State == ConnectionState.Open)
  3581. {
  3582. conn.Close();
  3583. }
  3584. conn.Dispose();
  3585. }
  3586. }
  3587. }
  3588. #endregion
  3589. #region 生产
  3590. /// <summary>
  3591. /// 生产退料 新建
  3592. /// </summary>
  3593. /// <param name="JsonData"></param>
  3594. /// <returns></returns>
  3595. public static DataTable MOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  3596. {
  3597. var language = LanguageHelper.GetName("WMSAPIInfo");
  3598. if (JsonData.Count <= 0)
  3599. {
  3600. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3601. }
  3602. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3603. {
  3604. conn.Open();
  3605. SqlTransaction sqlTran = conn.BeginTransaction();
  3606. SqlCommand cmd = new SqlCommand();
  3607. cmd.Transaction = sqlTran;
  3608. cmd.Connection = conn;
  3609. try
  3610. {
  3611. string codes = string.Empty;
  3612. string sql = string.Empty;
  3613. foreach (var item in JsonData)
  3614. {
  3615. //获取单号
  3616. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3617. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  3618. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  3619. IF @MaxNO IS NULL
  3620. BEGIN
  3621. SELECT @date+'00001' AS Code
  3622. END
  3623. ELSE
  3624. BEGIN
  3625. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3626. END ";
  3627. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3628. //创建主表
  3629. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  3630. BEGIN
  3631. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3632. RETURN
  3633. END
  3634. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3635. 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}','')";
  3636. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  3637. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3638. {
  3639. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  3640. }
  3641. foreach (var itemInfo in item.detail)
  3642. {
  3643. //创建子表
  3644. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  3645. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3646. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3647. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3648. '{4}','{5}',0,'{6}','{7}',
  3649. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3650. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3651. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3652. {
  3653. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  3654. }
  3655. }
  3656. //校验退料数量是否超出领料数量
  3657. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  3658. DBHelper.ExecuteNonQuery(sql, cmd);
  3659. codes += "'" + Code + item.WorkPoint + "',";
  3660. }
  3661. if (string.IsNullOrWhiteSpace(codes))
  3662. {
  3663. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3664. }
  3665. #region 查询返回数据
  3666. sql = @"SELECT a.ApplyNegCode,
  3667. c.WHCode,
  3668. c.Memo,
  3669. d.Name AS Status,
  3670. a.Sequence,
  3671. a.InvCode,
  3672. inv.InvName,
  3673. inv.InvStd,
  3674. a.Quantity,
  3675. inv.InvUnit,
  3676. a.Amount,
  3677. inv.AmountUnit,
  3678. a.IssueNegQuantity,
  3679. ext.ProjectCode,
  3680. ext.BatchCode,
  3681. ext.Version,
  3682. ext.Brand,
  3683. ext.cFree1,
  3684. ext.cFree2,
  3685. ext.cFree3,
  3686. ext.cFree4,
  3687. ext.cFree5,
  3688. ext.cFree6,
  3689. ext.cFree7,
  3690. ext.cFree8,
  3691. ext.cFree9,
  3692. ext.cFree10,
  3693. a.MUSER AS [User],
  3694. a.MTIME AS [MTime]
  3695. FROM ICSMOApplyNegDetail a
  3696. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3697. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3698. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3699. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3700. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  3701. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  3702. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3703. #endregion
  3704. cmd.Transaction.Commit();
  3705. return data;
  3706. }
  3707. catch (Exception ex)
  3708. {
  3709. if (cmd.Transaction != null)
  3710. cmd.Transaction.Rollback();
  3711. log.Error(ex.Message);
  3712. throw new Exception(ex.Message);
  3713. }
  3714. finally
  3715. {
  3716. if (conn.State == ConnectionState.Open)
  3717. {
  3718. conn.Close();
  3719. }
  3720. conn.Dispose();
  3721. }
  3722. }
  3723. }
  3724. private static string CheckMOIssueDoc(string Type, string ID, string WorkPoint, Dictionary<string, string> language)
  3725. {
  3726. string sql = string.Empty;
  3727. if (Type == "1")
  3728. {
  3729. sql = @"DECLARE @PickID VARCHAR(10)
  3730. SELECT @PickID=b.PickID
  3731. FROM ICSMOApplyNegDetail a
  3732. INNER JOIN ICSMOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  3733. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3734. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3735. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3736. FROM ICSMOApplyNegDetail a
  3737. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3738. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3739. GROUP BY b.PickID
  3740. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3741. IF (@PickID IS NOT NULL)
  3742. BEGIN
  3743. DECLARE @InvCode VARCHAR(100)
  3744. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  3745. RAISERROR(@InvCode,16,1);
  3746. RETURN
  3747. END ";
  3748. }
  3749. else if (Type == "2")
  3750. {
  3751. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  3752. SELECT @ApplyDetailID=b.ApplyDetailID
  3753. FROM ICSMOApplyNegDetail a
  3754. INNER JOIN ICSMOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  3755. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3756. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3757. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3758. FROM ICSMOApplyNegDetail a
  3759. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3760. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3761. GROUP BY b.ApplyDetailID
  3762. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3763. IF (@ApplyDetailID IS NOT NULL)
  3764. BEGIN
  3765. DECLARE @InvCode VARCHAR(100)
  3766. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  3767. RAISERROR(@InvCode,16,1);
  3768. RETURN
  3769. END ";
  3770. }
  3771. else if (Type == "3")
  3772. {
  3773. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  3774. SELECT @IssueDetailID=b.IssueDetailID
  3775. FROM ICSMOApplyNegDetail a
  3776. INNER JOIN ICSMOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  3777. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3778. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3779. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3780. FROM ICSMOApplyNegDetail a
  3781. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3782. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3783. GROUP BY b.IssueDetailID
  3784. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3785. IF (@IssueDetailID IS NOT NULL)
  3786. BEGIN
  3787. DECLARE @InvCode VARCHAR(100)
  3788. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  3789. RAISERROR(@InvCode,16,1);
  3790. RETURN
  3791. END ";
  3792. }
  3793. else
  3794. {
  3795. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  3796. }
  3797. sql = string.Format(sql, ID, WorkPoint, Type);
  3798. return sql;
  3799. }
  3800. /// <summary>
  3801. /// 生产退料 修改
  3802. /// </summary>
  3803. /// <param name="JsonData"></param>
  3804. /// <returns></returns>
  3805. public static DataTable MOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  3806. {
  3807. var language = LanguageHelper.GetName("WMSAPIInfo");
  3808. if (JsonData.Count <= 0)
  3809. {
  3810. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3811. }
  3812. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3813. {
  3814. conn.Open();
  3815. SqlTransaction sqlTran = conn.BeginTransaction();
  3816. SqlCommand cmd = new SqlCommand();
  3817. cmd.Transaction = sqlTran;
  3818. cmd.Connection = conn;
  3819. try
  3820. {
  3821. string sql = string.Empty;
  3822. string Code = string.Empty;
  3823. string ids = string.Empty;
  3824. foreach (var item in JsonData)
  3825. {
  3826. //主表修改
  3827. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  3828. BEGIN
  3829. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  3830. RETURN
  3831. END
  3832. DECLARE @Status VARCHAR(10)
  3833. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  3834. IF (@Status IS NULL)
  3835. BEGIN
  3836. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  3837. RETURN
  3838. END
  3839. ELSE IF (@Status!='1')
  3840. BEGIN
  3841. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  3842. RETURN
  3843. END
  3844. 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}' ";
  3845. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint);
  3846. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3847. {
  3848. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  3849. }
  3850. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  3851. if (detail > 0)
  3852. {
  3853. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  3854. sql = string.Format(sql, item.ID, item.WorkPoint);
  3855. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3856. }
  3857. foreach (var itemInfo in item.detail)
  3858. {
  3859. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  3860. {
  3861. //创建子表
  3862. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3863. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3864. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3865. '{4}','{5}',0,'{6}','{7}',
  3866. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3867. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3868. }
  3869. else
  3870. {
  3871. //子表修改
  3872. 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}'";
  3873. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  3874. }
  3875. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3876. {
  3877. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  3878. }
  3879. }
  3880. //校验退料数量是否超出领料数量
  3881. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  3882. DBHelper.ExecuteNonQuery(sql, cmd);
  3883. ids += "'" + item.ID + "',";
  3884. }
  3885. if (string.IsNullOrWhiteSpace(ids))
  3886. {
  3887. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3888. }
  3889. #region 查询返回数据
  3890. sql = @"SELECT a.ApplyNegCode,
  3891. c.WHCode,
  3892. c.Memo,
  3893. d.Name AS Status,
  3894. a.Sequence,
  3895. a.InvCode,
  3896. inv.InvName,
  3897. inv.InvStd,
  3898. a.Quantity,
  3899. inv.InvUnit,
  3900. a.Amount,
  3901. inv.AmountUnit,
  3902. a.IssueNegQuantity,
  3903. ext.ProjectCode,
  3904. ext.BatchCode,
  3905. ext.Version,
  3906. ext.Brand,
  3907. ext.cFree1,
  3908. ext.cFree2,
  3909. ext.cFree3,
  3910. ext.cFree4,
  3911. ext.cFree5,
  3912. ext.cFree6,
  3913. ext.cFree7,
  3914. ext.cFree8,
  3915. ext.cFree9,
  3916. ext.cFree10,
  3917. a.MUSER AS [User],
  3918. a.MTIME AS [MTime]
  3919. FROM ICSMOApplyNegDetail a
  3920. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3921. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3922. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3923. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3924. WHERE c.ID IN ({0})";
  3925. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3926. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3927. #endregion
  3928. cmd.Transaction.Commit();
  3929. return data;
  3930. }
  3931. catch (Exception ex)
  3932. {
  3933. if (cmd.Transaction != null)
  3934. cmd.Transaction.Rollback();
  3935. log.Error(ex.Message);
  3936. throw new Exception(ex.Message);
  3937. }
  3938. finally
  3939. {
  3940. if (conn.State == ConnectionState.Open)
  3941. {
  3942. conn.Close();
  3943. }
  3944. conn.Dispose();
  3945. }
  3946. }
  3947. }
  3948. /// <summary>
  3949. /// 生产退料审核
  3950. /// </summary>
  3951. /// <param name="JsonData"></param>
  3952. /// <returns></returns>
  3953. public static DataTable MOIssueDocNegativeApplyApprove(List<ICSUser> JsonData)
  3954. {
  3955. var language = LanguageHelper.GetName("WMSAPIInfo");
  3956. if (JsonData.Count <= 0)
  3957. {
  3958. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3959. }
  3960. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3961. {
  3962. conn.Open();
  3963. SqlTransaction sqlTran = conn.BeginTransaction();
  3964. SqlCommand cmd = new SqlCommand();
  3965. cmd.Transaction = sqlTran;
  3966. cmd.Connection = conn;
  3967. try
  3968. {
  3969. string sql = string.Empty;
  3970. string ids = string.Empty;
  3971. foreach (var item in JsonData)
  3972. {
  3973. if (string.IsNullOrEmpty(item.ID))
  3974. {
  3975. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  3976. }
  3977. if (string.IsNullOrEmpty(item.User))
  3978. {
  3979. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  3980. }
  3981. if (item.MTime <= new DateTime(2000, 1, 1))
  3982. {
  3983. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  3984. }
  3985. //获取单号
  3986. sql = @"DECLARE @Status VARCHAR(10)
  3987. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  3988. IF (@Status IS NULL)
  3989. BEGIN
  3990. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  3991. RETURN
  3992. END
  3993. ELSE IF (@Status!='1')
  3994. BEGIN
  3995. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  3996. RETURN
  3997. END
  3998. update ICSMOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  3999. sql = string.Format(sql, item.ID, item.User, item.MTime);
  4000. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4001. {
  4002. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  4003. }
  4004. ids += "'" + item.ID + "',";
  4005. }
  4006. if (string.IsNullOrWhiteSpace(ids))
  4007. {
  4008. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  4009. }
  4010. #region 查询返回数据
  4011. sql = @"SELECT a.ApplyNegCode,
  4012. c.WHCode,
  4013. c.Memo,
  4014. d.Name AS Status,
  4015. a.Sequence,
  4016. a.InvCode,
  4017. inv.InvName,
  4018. inv.InvStd,
  4019. a.Quantity,
  4020. inv.InvUnit,
  4021. a.Amount,
  4022. inv.AmountUnit,
  4023. a.IssueNegQuantity,
  4024. ext.ProjectCode,
  4025. ext.BatchCode,
  4026. ext.Version,
  4027. ext.Brand,
  4028. ext.cFree1,
  4029. ext.cFree2,
  4030. ext.cFree3,
  4031. ext.cFree4,
  4032. ext.cFree5,
  4033. ext.cFree6,
  4034. ext.cFree7,
  4035. ext.cFree8,
  4036. ext.cFree9,
  4037. ext.cFree10,
  4038. a.MUSER AS [User],
  4039. a.MTIME AS [MTime]
  4040. FROM ICSMOApplyNegDetail a
  4041. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  4042. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  4043. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  4044. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  4045. WHERE c.ID IN ({0})";
  4046. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  4047. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4048. #endregion
  4049. cmd.Transaction.Commit();
  4050. return data;
  4051. }
  4052. catch (Exception ex)
  4053. {
  4054. if (cmd.Transaction != null)
  4055. cmd.Transaction.Rollback();
  4056. log.Error(ex.Message);
  4057. throw new Exception(ex.Message);
  4058. }
  4059. finally
  4060. {
  4061. if (conn.State == ConnectionState.Open)
  4062. {
  4063. conn.Close();
  4064. }
  4065. conn.Dispose();
  4066. }
  4067. }
  4068. }
  4069. #endregion
  4070. #region 一步调拨
  4071. /// <summary>
  4072. /// 一步调拨
  4073. /// </summary>
  4074. /// <param name="JsonData"></param>
  4075. /// <returns></returns>
  4076. public static DataTable OneStepTransferDocIn(List<TransferDoc> JsonData)
  4077. {
  4078. var language = LanguageHelper.GetName("WMSAPIInfo");
  4079. if (JsonData.Count <= 0)
  4080. {
  4081. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4082. }
  4083. DataTable printTable = new DataTable();
  4084. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4085. {
  4086. conn.Open();
  4087. SqlTransaction sqlTran = conn.BeginTransaction();
  4088. SqlCommand cmd = new SqlCommand();
  4089. cmd.Transaction = sqlTran;
  4090. cmd.Connection = conn;
  4091. string BusinessCode = string.Empty;
  4092. try
  4093. {
  4094. string sql = string.Empty;
  4095. string Identification = Guid.NewGuid().ToString();
  4096. foreach (var item in JsonData)
  4097. {
  4098. if (string.IsNullOrEmpty(item.TransCode))
  4099. {
  4100. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨单号不能为空!");
  4101. }
  4102. string[] trans = item.TransCode.Split('~');
  4103. string MergeID = "";
  4104. if (trans.Length == 2)
  4105. {
  4106. MergeID = trans[0];
  4107. item.TransCode = trans[1];
  4108. }
  4109. //验证信息
  4110. sql = @"DECLARE @Status VARCHAR(10)
  4111. SELECT @Status=Status FROM ICSTransfer WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  4112. IF (@Status IS NULL)
  4113. BEGIN
  4114. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  4115. RETURN
  4116. END
  4117. ELSE IF (@Status!='1')
  4118. BEGIN
  4119. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  4120. RETURN
  4121. END";
  4122. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  4123. DBHelper.ExecuteNonQuery(sql, cmd);
  4124. foreach (var itemInfo in item.Detail)
  4125. {
  4126. //验证仓库库位信息
  4127. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4128. BEGIN
  4129. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4130. RETURN
  4131. END
  4132. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4133. BEGIN
  4134. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4135. RETURN
  4136. END
  4137. IF NOT EXISTS(SELECT a.ID
  4138. FROM ICSWareHouse a
  4139. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4140. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4141. BEGIN
  4142. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4143. RETURN
  4144. END";
  4145. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4146. DBHelper.ExecuteNonQuery(sql, cmd);
  4147. BusinessCode = TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>();
  4148. //更新源头单据信息
  4149. ICSWareHouseService.OneStepTransferDocIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  4150. //更新条码信息
  4151. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4152. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4153. }
  4154. }
  4155. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4156. if (!printTable.Equals("{}"))
  4157. {
  4158. cmd.Transaction.Commit();
  4159. return printTable;
  4160. }
  4161. else
  4162. {
  4163. DataTable table = GetData(Identification, 3, cmd);
  4164. cmd.Transaction.Commit();
  4165. return table;
  4166. }
  4167. }
  4168. catch (Exception ex)
  4169. {
  4170. if (cmd.Transaction != null)
  4171. cmd.Transaction.Rollback();
  4172. log.Error(ex.Message);
  4173. throw new Exception(ex.Message);
  4174. }
  4175. finally
  4176. {
  4177. if (conn.State == ConnectionState.Open)
  4178. {
  4179. conn.Close();
  4180. }
  4181. conn.Dispose();
  4182. }
  4183. }
  4184. }
  4185. #endregion
  4186. #region 调拨
  4187. /// <summary>
  4188. /// 调拨
  4189. /// </summary>
  4190. /// <param name="JsonData"></param>
  4191. /// <returns></returns>
  4192. public static DataTable TransferDocCreate(List<TransferDoc> JsonData)
  4193. {
  4194. var language = LanguageHelper.GetName("WMSAPIInfo");
  4195. if (JsonData.Count <= 0)
  4196. {
  4197. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4198. }
  4199. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4200. {
  4201. conn.Open();
  4202. SqlTransaction sqlTran = conn.BeginTransaction();
  4203. SqlCommand cmd = new SqlCommand();
  4204. cmd.Transaction = sqlTran;
  4205. cmd.Connection = conn;
  4206. string BusinessCode = string.Empty;
  4207. try
  4208. {
  4209. string sql = string.Empty;
  4210. string Identification = Guid.NewGuid().ToString();
  4211. foreach (var item in JsonData)
  4212. {
  4213. string MergeID = "";
  4214. foreach (var itemInfo in item.Detail)
  4215. {
  4216. //验证仓库库位信息
  4217. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4218. BEGIN
  4219. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4220. RETURN
  4221. END
  4222. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4223. BEGIN
  4224. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  4225. RETURN
  4226. END
  4227. IF NOT EXISTS(SELECT a.ID
  4228. FROM ICSWareHouse a
  4229. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4230. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4231. BEGIN
  4232. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4233. RETURN
  4234. END";
  4235. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  4236. DBHelper.ExecuteNonQuery(sql, cmd);
  4237. BusinessCode = TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>();
  4238. //更新条码信息
  4239. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  4240. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  4241. }
  4242. }
  4243. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferDocIn.GetDescription(), Identification, cmd, language, BusinessCode);
  4244. DataTable table = GetData(Identification, 3, cmd);
  4245. cmd.Transaction.Commit();
  4246. return table;
  4247. }
  4248. catch (Exception ex)
  4249. {
  4250. if (cmd.Transaction != null)
  4251. cmd.Transaction.Rollback();
  4252. log.Error(ex.Message);
  4253. throw new Exception(ex.Message);
  4254. }
  4255. finally
  4256. {
  4257. if (conn.State == ConnectionState.Open)
  4258. {
  4259. conn.Close();
  4260. }
  4261. conn.Dispose();
  4262. }
  4263. }
  4264. }
  4265. #endregion
  4266. #region 移库
  4267. /// <summary>
  4268. /// 移库
  4269. /// </summary>
  4270. /// <param name="JsonData"></param>
  4271. /// <returns></returns>
  4272. public static DataTable LibraryUpdate(List<ICSLibraryModel> JsonData)
  4273. {
  4274. var language = LanguageHelper.GetName("WMSAPIInfo");
  4275. if (JsonData.Count <= 0)
  4276. {
  4277. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4278. }
  4279. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4280. {
  4281. conn.Open();
  4282. SqlTransaction sqlTran = conn.BeginTransaction();
  4283. SqlCommand cmd = new SqlCommand();
  4284. cmd.Transaction = sqlTran;
  4285. cmd.Connection = conn;
  4286. try
  4287. {
  4288. string sql = string.Empty;
  4289. string Identification = Guid.NewGuid().ToString();
  4290. foreach (var item in JsonData)
  4291. {
  4292. if (string.IsNullOrEmpty(item.LotNo))
  4293. {
  4294. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4295. }
  4296. //验证仓库库位信息
  4297. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  4298. BEGIN
  4299. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  4300. RETURN
  4301. END
  4302. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  4303. BEGIN
  4304. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  4305. RETURN
  4306. END
  4307. IF NOT EXISTS(SELECT a.ID
  4308. FROM ICSWareHouse a
  4309. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  4310. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  4311. BEGIN
  4312. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  4313. RETURN
  4314. END";
  4315. sql = string.Format(sql, item.WarehouseCode, item.WorkPoint, item.LocationCode);
  4316. DBHelper.ExecuteNonQuery(sql, cmd);
  4317. //更新条码信息
  4318. ICSWareHouseLotInfoService.WareHouseLotInfoLibrary(Identification, item.TransCode, item.TransSequence, item.WarehouseCode, item.LocationCode, item.LotNo,
  4319. item.User, item.WorkPoint, "7", "29", cmd, language);
  4320. }
  4321. DataTable table = GetData(Identification, 3, cmd);
  4322. cmd.Transaction.Commit();
  4323. return table;
  4324. }
  4325. catch (Exception ex)
  4326. {
  4327. if (cmd.Transaction != null)
  4328. cmd.Transaction.Rollback();
  4329. log.Error(ex.Message);
  4330. throw new Exception(ex.Message);
  4331. }
  4332. finally
  4333. {
  4334. if (conn.State == ConnectionState.Open)
  4335. {
  4336. conn.Close();
  4337. }
  4338. conn.Dispose();
  4339. }
  4340. }
  4341. }
  4342. #endregion
  4343. #region 合并
  4344. /// <summary>
  4345. /// 合并
  4346. /// </summary>
  4347. /// <param name="JsonData"></param>
  4348. /// <returns></returns>
  4349. public static DataTable LOTMergeCreate(List<LOTCreateIModel> JsonData)
  4350. {
  4351. var language = LanguageHelper.GetName("WMSAPIInfo");
  4352. if (JsonData.Count <= 0)
  4353. {
  4354. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4355. }
  4356. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4357. {
  4358. conn.Open();
  4359. SqlTransaction sqlTran = conn.BeginTransaction();
  4360. SqlCommand cmd = new SqlCommand();
  4361. cmd.Transaction = sqlTran;
  4362. cmd.Connection = conn;
  4363. try
  4364. {
  4365. string Identification = Guid.NewGuid().ToString();
  4366. foreach (var item in JsonData)
  4367. {
  4368. if (string.IsNullOrEmpty(item.LotNo))
  4369. {
  4370. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4371. }
  4372. else if (item.detail.Count <= 0)
  4373. {
  4374. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  4375. }
  4376. //合并前日志
  4377. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  4378. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  4379. foreach (var info in item.detail)
  4380. {
  4381. //合并前日志
  4382. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, info.CurrentLotNo, item.User, item.WorkPoint, "5",
  4383. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  4384. //更新条码信息
  4385. ICSWareHouseLotInfoService.WareHouseLotInfoMerge(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "5",
  4386. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  4387. }
  4388. //合并后日志
  4389. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  4390. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  4391. }
  4392. DataTable table = GetData(Identification, 1, cmd);
  4393. cmd.Transaction.Commit();
  4394. return table;
  4395. }
  4396. catch (Exception ex)
  4397. {
  4398. if (cmd.Transaction != null)
  4399. cmd.Transaction.Rollback();
  4400. log.Error(ex.Message);
  4401. throw new Exception(ex.Message);
  4402. }
  4403. finally
  4404. {
  4405. if (conn.State == ConnectionState.Open)
  4406. {
  4407. conn.Close();
  4408. }
  4409. conn.Dispose();
  4410. }
  4411. }
  4412. }
  4413. #endregion
  4414. #region 拆分
  4415. /// <summary>
  4416. /// 拆分
  4417. /// </summary>
  4418. /// <param name="JsonData"></param>
  4419. /// <returns></returns>
  4420. public static DataTable LOTSplitCreate(List<LOTCreateIModel> JsonData)
  4421. {
  4422. var language = LanguageHelper.GetName("WMSAPIInfo");
  4423. if (JsonData.Count <= 0)
  4424. {
  4425. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4426. }
  4427. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4428. {
  4429. conn.Open();
  4430. SqlTransaction sqlTran = conn.BeginTransaction();
  4431. SqlCommand cmd = new SqlCommand();
  4432. cmd.Transaction = sqlTran;
  4433. cmd.Connection = conn;
  4434. try
  4435. {
  4436. string Identification = Guid.NewGuid().ToString();
  4437. foreach (var item in JsonData)
  4438. {
  4439. if (string.IsNullOrEmpty(item.LotNo))
  4440. {
  4441. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4442. }
  4443. else if (item.detail.Count <= 0)
  4444. {
  4445. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  4446. }
  4447. //拆分前日志
  4448. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  4449. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(), cmd, language);
  4450. foreach (var info in item.detail)
  4451. {
  4452. //更新条码信息
  4453. ICSWareHouseLotInfoService.WareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  4454. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  4455. }
  4456. //拆分后日志
  4457. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  4458. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  4459. }
  4460. DataTable table = GetData(Identification, 1, cmd);
  4461. cmd.Transaction.Commit();
  4462. return table;
  4463. }
  4464. catch (Exception ex)
  4465. {
  4466. if (cmd.Transaction != null)
  4467. cmd.Transaction.Rollback();
  4468. log.Error(ex.Message);
  4469. throw new Exception(ex.Message);
  4470. }
  4471. finally
  4472. {
  4473. if (conn.State == ConnectionState.Open)
  4474. {
  4475. conn.Close();
  4476. }
  4477. conn.Dispose();
  4478. }
  4479. }
  4480. }
  4481. #endregion
  4482. /// <summary>
  4483. /// 获取出入库记录信息
  4484. /// </summary>
  4485. /// <param name="Identification"></param>
  4486. /// <param name="type">1:入库,2:出库,3:调拨</param>
  4487. /// <param name="cmd"></param>
  4488. /// <returns></returns>
  4489. private static DataTable GetData(string Identification, int type, SqlCommand cmd)
  4490. {
  4491. #region SLQ
  4492. string sql = @"SELECT log.ID,
  4493. log.TransCode,
  4494. log.TransSequence,
  4495. log.LotNo,
  4496. log.InvCode,
  4497. inv.InvName,
  4498. inv.InvStd,
  4499. log.Quantity,
  4500. inv.InvUnit,
  4501. log.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  4502. inv.AmountUnit,
  4503. {1}
  4504. ext.ProjectCode,
  4505. 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,
  4506. ext.Version,
  4507. ext.Brand,
  4508. ext.cFree1,
  4509. ext.cFree2,
  4510. ext.cFree3,
  4511. ext.cFree4,
  4512. ext.cFree5,
  4513. ext.cFree6,
  4514. ext.cFree7,
  4515. ext.cFree8,
  4516. ext.cFree9,
  4517. ext.cFree10,
  4518. type.Name AS TransType,
  4519. log.MUSER AS [User],
  4520. log.MTIME AS [MTime]
  4521. FROM ICSWareHouseLotInfoLog log
  4522. LEFT JOIN ICSType type ON type.TableCode='ICSWareHouseLotInfoLog' AND type.ColumnCode='BusinessCode' AND log.BusinessCode=type.Code AND log.WorkPoint=type.WorkPoint
  4523. INNER JOIN ICSInventoryLot lot ON log.LotNo=lot.LotNo AND log.WorkPoint=lot.WorkPoint
  4524. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4525. INNER JOIN ICSInventory inv ON log.InvCode=inv.InvCode AND log.WorkPoint=inv.WorkPoint
  4526. {2}
  4527. LEFT JOIN ICSInventoryBatchEnable invBat ON log.InvCode=invBat.InvCode AND log.FromWarehouseCode=invBat.WHCode AND log.WorkPoint=invBat.WorkPoint
  4528. WHERE log.Identification='{0}'";
  4529. #endregion
  4530. string columns = @"log.ToWarehouseCode AS WHCode,
  4531. log.ToLocationCode AS LocationCode,
  4532. wh.WarehouseName AS WHName,
  4533. loc.LocationName AS LocationName,";
  4534. string tables = @"INNER JOIN ICSWarehouse wh ON log.ToWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4535. INNER JOIN ICSLocation loc ON log.ToLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  4536. if (type == 2)//出库
  4537. {
  4538. columns = @"log.FromWarehouseCode AS WHCode,
  4539. log.FromLocationCode AS LocationCode,
  4540. wh.WarehouseName AS WHName,
  4541. loc.LocationName AS LocationName,";
  4542. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4543. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  4544. }
  4545. else if (type == 3)//调拨
  4546. {
  4547. columns = @"log.FromWarehouseCode AS FromWHCode,
  4548. log.FromLocationCode,
  4549. wh.WarehouseName AS FromWHName,
  4550. loc.LocationName AS FromLocationName,
  4551. log.ToWarehouseCode AS ToWHCode,
  4552. log.ToLocationCode,
  4553. whto.WarehouseName AS ToWHName,
  4554. locto.LocationName AS ToLocationName,";
  4555. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4556. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint
  4557. INNER JOIN ICSWarehouse whto ON log.ToWarehouseCode=whto.WarehouseCode AND log.WorkPoint=whto.WorkPoint
  4558. INNER JOIN ICSLocation locto ON log.ToLocationCode=locto.LocationCode AND log.WorkPoint=locto.WorkPoint";
  4559. }
  4560. sql = string.Format(sql, Identification, columns, tables);
  4561. return DBHelper.SQlReturnData(sql, cmd);
  4562. }
  4563. /// <summary>
  4564. /// 先进先出批次管控
  4565. /// </summary>
  4566. /// <param name="LotNo"></param>
  4567. /// <param name="WorkPoitCode"></param>
  4568. /// <param name="cmd"></param>
  4569. /// <returns></returns>
  4570. public static string CanOut(string LotNo, string WorkPoitCode, string ScanLotCode, SqlCommand cmd, Dictionary<string, string> language)
  4571. {
  4572. try
  4573. {
  4574. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  4575. string sql = @"DECLARE @CountNO INT,@Days INT
  4576. SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
  4577. SET @CountNO=(
  4578. SELECT COUNT(a.LotNO) FROM ICSWareHouseLotInfo a
  4579. INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO AND a.WorkPoint=b.WorkPoint
  4580. WHERE a.WorkPoint='{1}' AND ISNULL(a.Quantity,0)>0 AND 1=1
  4581. AND CONVERT(varchar(100), a.InDate, 23)<
  4582. (SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), x.InDate, 23)) FROM ICSWareHouseLotInfo x
  4583. INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
  4584. WHERE x.LotNO='{0}' AND x.WorkPoint='{1}' AND y.INVCode=b.INVCode AND y.ExtensionID=b.ExtensionID)
  4585. )
  4586. IF @CountNO>0
  4587. BEGIN
  4588. SELECT TOP 1 CASE a.F_ItemCode WHEN 'FIFO01' THEN '1' WHEN 'FIFO02' THEN '2' ELSE '3' END AS Type
  4589. FROM Sys_SRM_ItemsDetail a
  4590. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  4591. WHERE b.F_EnCode='FIFO' AND a.F_EnabledMark='1'
  4592. ORDER BY a.F_SortCode DESC
  4593. END
  4594. ELSE
  4595. BEGIN
  4596. SELECT @CountNO
  4597. END";
  4598. //0 - 已经是最早的批次
  4599. //1 - 不管控
  4600. //2 - 提醒
  4601. //3 - 限制
  4602. sql = string.Format(sql, LotNo, WorkPoitCode);
  4603. if (!string.IsNullOrWhiteSpace(ScanLotCode))
  4604. {
  4605. sql = sql.Replace("1=1", "a.LotNO NOT IN (" + ScanLotCode + ")");
  4606. }
  4607. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4608. if (string.IsNullOrWhiteSpace(res))
  4609. {
  4610. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  4611. }
  4612. else
  4613. return res;
  4614. }
  4615. catch (Exception ex)
  4616. {
  4617. throw new Exception(ex.Message);
  4618. }
  4619. }
  4620. /// <summary>
  4621. /// 保质期管控
  4622. /// </summary>
  4623. /// <param name="LotNo"></param>
  4624. /// <param name="WorkPoitCode"></param>
  4625. /// <param name="cmd"></param>
  4626. /// <returns></returns>
  4627. public static string Effective(string LotNo, string WorkPoitCode, SqlCommand cmd, Dictionary<string, string> language)
  4628. {
  4629. try
  4630. {
  4631. string sql = @"DECLARE @CountNO INT,@Days INT,@CurrentDays INT
  4632. SELECT @CountNO=EffectiveEnable,@Days=EffectiveDays,@CurrentDays=DATEDIFF(DAY, GETDATE(), b.ExpirationDate) FROM ICSInventory a
  4633. INNER JOIN ICSInventoryLot b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  4634. INNER JOIN ICSWareHouseLotInfo c ON b.LotNO=c.LotNO AND b.WorkPoint=c.WorkPoint
  4635. WHERE b.LotNO='{0}' AND b.WorkPoint='{1}'
  4636. IF @CountNO='1' AND @CurrentDays<0
  4637. BEGIN
  4638. SELECT TOP 1 CASE a.F_ItemCode WHEN 'Effective01' THEN '1' WHEN 'Effective02' THEN '2' ELSE '3' END AS Type
  4639. FROM Sys_SRM_ItemsDetail a
  4640. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  4641. WHERE b.F_EnCode='Effective' AND a.F_EnabledMark='1'
  4642. ORDER BY a.F_SortCode DESC
  4643. END
  4644. ELSE
  4645. BEGIN
  4646. SELECT @CountNO
  4647. END";
  4648. //0 - 已经是最早的批次
  4649. //1 - 不管控
  4650. //2 - 提醒
  4651. //3 - 限制
  4652. sql = string.Format(sql, LotNo, WorkPoitCode);
  4653. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4654. if (string.IsNullOrWhiteSpace(res))
  4655. {
  4656. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  4657. }
  4658. else
  4659. return res;
  4660. }
  4661. catch (Exception ex)
  4662. {
  4663. throw new Exception(ex.Message);
  4664. }
  4665. }
  4666. #region 包装
  4667. /// <summary>
  4668. /// 查询包装信息
  4669. /// </summary>
  4670. /// <param name="JsonData"></param>
  4671. /// <returns></returns>
  4672. public static object ContainerGet(ICSContainer JsonData)
  4673. {
  4674. var language = LanguageHelper.GetName("WMSAPIInfo");
  4675. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4676. {
  4677. conn.Open();
  4678. SqlTransaction sqlTran = conn.BeginTransaction();
  4679. SqlCommand cmd = new SqlCommand();
  4680. cmd.Transaction = sqlTran;
  4681. cmd.Connection = conn;
  4682. try
  4683. {
  4684. string sql = string.Empty;
  4685. //目标包装
  4686. if (JsonData.ToContainerCode != null)
  4687. {
  4688. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4689. BEGIN
  4690. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4691. RETURN
  4692. END
  4693. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  4694. sql = string.Format(sql, JsonData.ToContainerCode, JsonData.WorkPoint);
  4695. }
  4696. ///原包装
  4697. else if (JsonData.FromContainerCode != null)
  4698. {
  4699. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4700. BEGIN
  4701. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4702. RETURN
  4703. END
  4704. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  4705. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4706. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  4707. BEGIN
  4708. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  4709. RETURN
  4710. END
  4711. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  4712. sql = string.Format(sql, JsonData.FromContainerCode, JsonData.WorkPoint);
  4713. }
  4714. else
  4715. {
  4716. throw new Exception(language.GetNameByCode("WMSAPIInfo029"));//"请传入包装条码!");
  4717. }
  4718. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  4719. cmd.Transaction.Commit();
  4720. return table;
  4721. }
  4722. catch (Exception ex)
  4723. {
  4724. if (cmd.Transaction != null)
  4725. cmd.Transaction.Rollback();
  4726. log.Error(ex.Message);
  4727. throw new Exception(ex.Message);
  4728. }
  4729. finally
  4730. {
  4731. if (conn.State == ConnectionState.Open)
  4732. {
  4733. conn.Close();
  4734. }
  4735. conn.Dispose();
  4736. }
  4737. }
  4738. }
  4739. /// <summary>
  4740. /// 修改包装信息
  4741. /// </summary>
  4742. /// <param name="JsonData"></param>
  4743. /// <returns></returns>
  4744. public static DataTable ContainerUpdate(List<ICSContainer> JsonData)
  4745. {
  4746. var language = LanguageHelper.GetName("WMSAPIInfo");
  4747. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4748. {
  4749. conn.Open();
  4750. SqlTransaction sqlTran = conn.BeginTransaction();
  4751. SqlCommand cmd = new SqlCommand();
  4752. cmd.Transaction = sqlTran;
  4753. cmd.Connection = conn;
  4754. try
  4755. {
  4756. string sql = string.Empty;
  4757. string codes = string.Empty;
  4758. foreach (ICSContainer container in JsonData)
  4759. {
  4760. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4761. BEGIN
  4762. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4763. RETURN
  4764. END
  4765. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  4766. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4767. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  4768. BEGIN
  4769. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  4770. RETURN
  4771. END
  4772. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{2}' and WorkPoint='{1}')
  4773. BEGIN
  4774. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  4775. RETURN
  4776. END
  4777. UPDATE b SET ContainerID=c.ID
  4778. FROM ICSContainer a
  4779. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4780. INNER JOIN ICSContainer c ON c.ContainerCODE ='{2}' and a.WorkPoint=c.WorkPoint
  4781. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}'";
  4782. sql = string.Format(sql, container.FromContainerCode, container.WorkPoint, container.ToContainerCode);
  4783. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4784. {
  4785. throw new Exception(language.GetNameByCode("WMSAPIInfo030"));//"包装更新失败!");
  4786. }
  4787. codes += "'" + container.ToContainerCode + container.WorkPoint + "',";
  4788. }
  4789. sql = @"SELECT a.ContainerCode, a.ContainerName,b.LotNo FROM ICSContainer a
  4790. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4791. WHERE a.ContainerCODE+a.WorkPoint IN({0})";
  4792. sql = string.Format(sql, codes.Substring(0,codes.Length - 1));
  4793. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  4794. cmd.Transaction.Commit();
  4795. return table;
  4796. }
  4797. catch (Exception ex)
  4798. {
  4799. if (cmd.Transaction != null)
  4800. cmd.Transaction.Rollback();
  4801. log.Error(ex.Message);
  4802. throw new Exception(ex.Message);
  4803. }
  4804. finally
  4805. {
  4806. if (conn.State == ConnectionState.Open)
  4807. {
  4808. conn.Close();
  4809. }
  4810. conn.Dispose();
  4811. }
  4812. }
  4813. }
  4814. #endregion
  4815. #region 盘点
  4816. /// <summary>
  4817. /// 创建盘点单
  4818. /// </summary>
  4819. /// <param name="JsonData"></param>
  4820. /// <returns></returns>
  4821. public static DataTable CheckCreate(List<ICSCheck> JsonData)
  4822. {
  4823. var language = LanguageHelper.GetName("WMSAPIInfo");
  4824. if (JsonData.Count <= 0)
  4825. {
  4826. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4827. }
  4828. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4829. {
  4830. conn.Open();
  4831. SqlTransaction sqlTran = conn.BeginTransaction();
  4832. SqlCommand cmd = new SqlCommand();
  4833. cmd.Transaction = sqlTran;
  4834. cmd.Connection = conn;
  4835. try
  4836. {
  4837. string Code = string.Empty;
  4838. string sql = string.Empty;
  4839. foreach (var item in JsonData)
  4840. {
  4841. if (string.IsNullOrEmpty(item.User))
  4842. {
  4843. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  4844. }
  4845. if (string.IsNullOrEmpty(item.WorkPoint))
  4846. {
  4847. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  4848. }
  4849. //获取单号
  4850. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  4851. BEGIN
  4852. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  4853. RETURN
  4854. END
  4855. DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  4856. SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck
  4857. WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date
  4858. IF @MaxNO IS NULL
  4859. BEGIN
  4860. SELECT @date+'00001' AS Code
  4861. END
  4862. ELSE
  4863. BEGIN
  4864. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  4865. END ";
  4866. sql = string.Format(sql, item.User, item.WorkPoint);
  4867. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4868. //创建盘点单
  4869. foreach (var itemInfo in item.detail)
  4870. {
  4871. int len = itemInfo.SelectLevel.Length;
  4872. sql = @"IF NOT EXISTS(SELECT id FROM ICSWareHouseLotInfo WHERE SUBSTRING(LocationCode,1,{4}) = '{1}')
  4873. BEGIN
  4874. RAISERROR('" + language.GetNameByCode("WMSAPIInfo460") + @"',16,1);
  4875. RETURN
  4876. END
  4877. INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint)
  4878. SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location
  4879. FROM ICSWareHouseLotInfo a
  4880. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4881. WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
  4882. GROUP BY b.F_Account,b.F_RealName,b.F_Location";
  4883. sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len);
  4884. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4885. {
  4886. throw new Exception(language.GetNameByCode("WMSAPIInfo031"));//"盘点单创建失败!");
  4887. }
  4888. }
  4889. }
  4890. if (string.IsNullOrWhiteSpace(Code))
  4891. {
  4892. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单单号不能为空!");
  4893. }
  4894. #region 查询返回数据
  4895. sql = @"SELECT a.ID,a.CheckCode,a.SelectLevel,
  4896. a.Quantity,
  4897. a.Amount,
  4898. a.MUSER AS [User],
  4899. a.MTIME AS [MTime]
  4900. FROM ICSCheck a
  4901. WHERE a.CheckCode='{0}'";
  4902. sql = string.Format(sql, Code);
  4903. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4904. #endregion
  4905. cmd.Transaction.Commit();
  4906. return data;
  4907. }
  4908. catch (Exception ex)
  4909. {
  4910. if (cmd.Transaction != null)
  4911. cmd.Transaction.Rollback();
  4912. log.Error(ex.Message);
  4913. throw new Exception(ex.Message);
  4914. }
  4915. finally
  4916. {
  4917. if (conn.State == ConnectionState.Open)
  4918. {
  4919. conn.Close();
  4920. }
  4921. conn.Dispose();
  4922. }
  4923. }
  4924. }
  4925. /// <summary>
  4926. /// 盘点扫描
  4927. /// </summary>
  4928. /// <param name="JsonData"></param>
  4929. /// <returns></returns>
  4930. public static DataTable LOTCheckCreate(List<ICSCheck> JsonData)
  4931. {
  4932. var language = LanguageHelper.GetName("WMSAPIInfo");
  4933. if (JsonData.Count <= 0)
  4934. {
  4935. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4936. }
  4937. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4938. {
  4939. conn.Open();
  4940. SqlTransaction sqlTran = conn.BeginTransaction();
  4941. SqlCommand cmd = new SqlCommand();
  4942. cmd.Transaction = sqlTran;
  4943. cmd.Connection = conn;
  4944. try
  4945. {
  4946. string lots = string.Empty;
  4947. string sql = string.Empty;
  4948. int result = 0;
  4949. string Identification = Guid.NewGuid().ToString();
  4950. foreach (var item in JsonData)
  4951. {
  4952. if (string.IsNullOrEmpty(item.User))
  4953. {
  4954. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  4955. }
  4956. if (string.IsNullOrEmpty(item.WorkPoint))
  4957. {
  4958. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  4959. }
  4960. if (string.IsNullOrEmpty(item.CheckCode))
  4961. {
  4962. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单号不能为空!");
  4963. }
  4964. //校验
  4965. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  4966. BEGIN
  4967. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  4968. RETURN
  4969. END
  4970. IF NOT EXISTS(SELECT ID FROM ICSCheck WHERE CheckCode='{2}' AND WorkPoint='{1}')
  4971. BEGIN
  4972. RAISERROR('" + language.GetNameByCode("WMSAPIInfo075") + @"',16,1);
  4973. RETURN
  4974. END";
  4975. sql = string.Format(sql, item.User, item.WorkPoint, item.CheckCode);
  4976. DBHelper.ExecuteNonQuery(sql, cmd);
  4977. //创建盘点单
  4978. foreach (var itemInfo in item.detail)
  4979. {
  4980. sql = @"IF NOT EXISTS(SELECT LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{1}' AND WorkPoint='{3}')
  4981. BEGIN
  4982. RAISERROR('" + language.GetNameByCode("WMSAPIInfo076") + @"',16,1);
  4983. RETURN
  4984. END
  4985. IF EXISTS(SELECT LotNo FROM ICSCheckDetail a
  4986. LEFT JOIN ICSCheck b ON a.CheckID=b.ID AND a.WorkPoint=b.WorkPoint
  4987. WHERE b.CheckCode='{0}' AND a.LotNo='{1}' AND a.WorkPoint='{3}')
  4988. BEGIN
  4989. IF ('{5}'='')
  4990. BEGIN
  4991. UPDATE a SET PrimaryQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  4992. FROM ICSCheckDetail a
  4993. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4994. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  4995. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  4996. END
  4997. ELSE IF ('{5}'='')
  4998. BEGIN
  4999. UPDATE a SET CheckQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  5000. FROM ICSCheckDetail a
  5001. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5002. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  5003. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  5004. END
  5005. ELSE
  5006. BEGIN
  5007. UPDATE a SET ReplayQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  5008. FROM ICSCheckDetail a
  5009. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5010. LEFT JOIN ICSCheck c ON a.CheckID=c.ID AND a.WorkPoint=c.WorkPoint
  5011. WHERE c.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  5012. END
  5013. END
  5014. ELSE
  5015. BEGIN
  5016. IF ('{5}'='')
  5017. BEGIN
  5018. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  5019. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','{4}','0','0','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  5020. FROM ICSWareHouseLotInfo a
  5021. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5022. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  5023. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  5024. END
  5025. ELSE IF ('{5}'='')
  5026. BEGIN
  5027. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  5028. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','0','0','{4}','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  5029. FROM ICSWareHouseLotInfo a
  5030. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5031. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  5032. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  5033. END
  5034. ELSE
  5035. BEGIN
  5036. INSERT INTO ICSCheckDetail (ID,CheckID,LotNo,Quantity,Amount,PrimaryQuantity,PrimaryAmount,ReplayQuantity,ReplayAmount,CheckQuantity,CheckAmount,MUSER,MUSERName,MTIME,WorkPoint)
  5037. SELECT NEWID(),c.ID,a.LotNo,a.Quantity,'0','0','0','{4}','0','0','0',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  5038. FROM ICSWareHouseLotInfo a
  5039. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  5040. LEFT JOIN ICSCheck c ON SUBSTRING(a.LocationCode,1,len(c.SelectLevel))=c.SelectLevel
  5041. WHERE a.LotNo='{1}' and a.WorkPoint='{3}' and c.CheckCode='{0}'
  5042. END
  5043. END";
  5044. sql = string.Format(sql, item.CheckCode, itemInfo.LotNo, item.User, item.WorkPoint, itemInfo.ActualQuantity, item.CheckKind);
  5045. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5046. {
  5047. throw new Exception(language.GetNameByCode("WMSAPIInfo033"));//"盘点扫描创建失败!");
  5048. }
  5049. #region 更新ICSCheckDetail表
  5050. //string strSql = @"UPDATE ICSCheckDetail Set";
  5051. //if (item.CheckKind == "初盘")
  5052. // strSql += @" PrimaryQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  5053. //else if (item.CheckKind == "复盘")
  5054. // strSql += @" ReplayQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  5055. //else
  5056. // strSql += @" CheckQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  5057. //strSql += @" where ToCheckNO='" + item.CheckCode + "' AND WorkPoint='" + item.WorkPoint + "'";
  5058. //cmd.CommandText = strSql;
  5059. //result = cmd.ExecuteNonQuery();
  5060. //if (result <= 0)
  5061. //{
  5062. // throw new Exception(language.GetNameByCode("WMSAPIInfo296"));//"盘点子表数量增加失败!");
  5063. //}
  5064. #endregion
  5065. #region 更新库存
  5066. if (item.UpdateWHLI)
  5067. {
  5068. ICSWareHouseLotInfoService.WareHouseLotInfoUpdate(Identification, item.CheckCode, "", itemInfo.LotNo, itemInfo.ActualQuantity, item.User, item.WorkPoint, TransTypeEnum.Check.GetDescription<DBValue>(), item.CheckKind, cmd, language);
  5069. }
  5070. #endregion
  5071. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  5072. }
  5073. if (string.IsNullOrWhiteSpace(lots))
  5074. {
  5075. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  5076. }
  5077. //sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  5078. // FROM ICSCheck a
  5079. // 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
  5080. // WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  5081. //sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  5082. //if (!DBHelper.ExecuteNonQuery(sql, cmd))
  5083. //{
  5084. // throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  5085. //}
  5086. }
  5087. #region 查询返回数据
  5088. sql = @"SELECT x.ID,x.CheckID,y.WarehouseCode AS WHCode,x.LotNo,
  5089. y.InvCode,
  5090. inv.InvName,
  5091. inv.InvStd,
  5092. x.Quantity,x.PrimaryQuantity,x.PrimaryAmount,x.ReplayQuantity,x.ReplayAmount,x.CheckQuantity,x.CheckAmount,
  5093. inv.InvUnit,
  5094. x.MUSER AS [User],
  5095. x.MTIME AS [MTime]
  5096. FROM ICSCheckDetail x
  5097. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  5098. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  5099. WHERE x.LotNo+x.WorkPoint IN ({0})";
  5100. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  5101. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5102. #endregion
  5103. cmd.Transaction.Commit();
  5104. return data;
  5105. }
  5106. catch (Exception ex)
  5107. {
  5108. if (cmd.Transaction != null)
  5109. cmd.Transaction.Rollback();
  5110. log.Error(ex.Message);
  5111. throw new Exception(ex.Message);
  5112. }
  5113. finally
  5114. {
  5115. if (conn.State == ConnectionState.Open)
  5116. {
  5117. conn.Close();
  5118. }
  5119. conn.Dispose();
  5120. }
  5121. }
  5122. }
  5123. #endregion
  5124. #region 多语言
  5125. /// <summary>
  5126. /// 多语言查询
  5127. /// </summary>
  5128. /// <param name="JsonData"></param>
  5129. /// <returns></returns>
  5130. public static DataTable PromptInformationGet(WMSBarCoreModel JsonData)
  5131. {
  5132. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5133. {
  5134. conn.Open();
  5135. SqlCommand cmd = new SqlCommand();
  5136. cmd.Connection = conn;
  5137. try
  5138. {
  5139. string DefiniteLanguage = ICSDefiniteLanguageService.GetLanguage();
  5140. string sql = @"select " + DefiniteLanguage + " AS Name,Code from Sys_Language where 1=1";
  5141. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  5142. {
  5143. sql += " and Code LIKE '%{0}%'";
  5144. }
  5145. sql = string.Format(sql, JsonData.Code);
  5146. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5147. return data;
  5148. }
  5149. catch (Exception ex)
  5150. {
  5151. log.Error(ex.Message);
  5152. throw new Exception(ex.Message);
  5153. }
  5154. finally
  5155. {
  5156. if (conn.State == ConnectionState.Open)
  5157. {
  5158. conn.Close();
  5159. }
  5160. conn.Dispose();
  5161. }
  5162. }
  5163. }
  5164. #endregion
  5165. #region 仓库/库位
  5166. /// <summary>
  5167. /// 仓库/库位
  5168. /// </summary>
  5169. /// <param name="JsonData"></param>
  5170. /// <returns></returns>
  5171. public static DataTable LocationGet(ICSLocation JsonData)
  5172. {
  5173. var language = LanguageHelper.GetName("WMSAPIInfo");
  5174. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5175. {
  5176. conn.Open();
  5177. SqlTransaction sqlTran = conn.BeginTransaction();
  5178. SqlCommand cmd = new SqlCommand();
  5179. cmd.Transaction = sqlTran;
  5180. cmd.Connection = conn;
  5181. try
  5182. {
  5183. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode='{0}' AND a.WorkPoint='{1}')
  5184. BEGIN
  5185. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  5186. RETURN
  5187. END
  5188. 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}')
  5189. BEGIN
  5190. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  5191. RETURN
  5192. END
  5193. 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')
  5194. BEGIN
  5195. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  5196. RETURN
  5197. END
  5198. SELECT
  5199. LocationCode,
  5200. LocationName ,
  5201. WarehouseCode,
  5202. WarehouseName
  5203. FROM ICSLocation a
  5204. 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'";
  5205. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  5206. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  5207. cmd.Transaction.Commit();
  5208. return data;
  5209. }
  5210. catch (Exception ex)
  5211. {
  5212. if (cmd.Transaction != null)
  5213. cmd.Transaction.Rollback();
  5214. log.Error(ex.Message);
  5215. throw new Exception(ex.Message);
  5216. }
  5217. finally
  5218. {
  5219. if (conn.State == ConnectionState.Open)
  5220. {
  5221. conn.Close();
  5222. }
  5223. conn.Dispose();
  5224. }
  5225. }
  5226. }
  5227. #endregion
  5228. #region 登陆
  5229. public static object CheckLogin(Sys_SRM_User userModel)
  5230. {
  5231. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  5232. {
  5233. conn.Open();
  5234. SqlCommand cmd = new SqlCommand();
  5235. cmd.Connection = conn;
  5236. try
  5237. {
  5238. string sql = @"select F_Account from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  5239. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  5240. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  5241. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  5242. {
  5243. sql = @" select a.[F_Id] as UserId
  5244. ,[F_Account] as userCode
  5245. ,[F_RealName] as UserName
  5246. ,[F_NickName]
  5247. ,b.F_UserPassword
  5248. ,b.F_UserSecretkey
  5249. ,[F_HeadIcon]
  5250. ,[F_Gender]
  5251. ,[F_Birthday]
  5252. ,[F_MobilePhone]
  5253. ,[F_Email]
  5254. ,[F_WeChat]
  5255. ,[F_ManagerId]
  5256. ,[F_SecurityLevel]
  5257. ,[F_Signature]
  5258. ,[F_OrganizeId]
  5259. ,[F_DepartmentId]
  5260. ,[F_RoleId]
  5261. ,[F_DutyId]
  5262. ,[F_IsAdministrator]
  5263. ,[F_SortCode]
  5264. ,[F_DeleteMark]
  5265. ,[F_EnabledMark]
  5266. ,[F_Description]
  5267. ,[F_CreatorTime]
  5268. ,[F_CreatorUserId]
  5269. ,[F_LastModifyTime]
  5270. ,[F_LastModifyUserId]
  5271. ,[F_DeleteTime]
  5272. ,[F_DeleteUserId]
  5273. ,[F_Location] as WorkPoint
  5274. ,[F_VenCode]
  5275. from Sys_SRM_User a
  5276. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  5277. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  5278. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  5279. dt = DBHelper.SQlReturnData(sql, cmd);
  5280. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  5281. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  5282. foreach (var item in users)
  5283. {
  5284. //string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
  5285. string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  5286. if (dbPassword == item.F_UserPassword)
  5287. {
  5288. string json = JsonConvert.SerializeObject(dt);
  5289. List<Sys_SRM_User> userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  5290. return userLogOnEntity;
  5291. }
  5292. else
  5293. {
  5294. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI004"));//"密码不正确,请重新输入");
  5295. }
  5296. }
  5297. }
  5298. else
  5299. {
  5300. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI005"));//"用户名不存在,请重新输入!");
  5301. }
  5302. return null;
  5303. }
  5304. catch (Exception ex)
  5305. {
  5306. log.Error(ex.Message);
  5307. throw new Exception(ex.Message);
  5308. }
  5309. finally
  5310. {
  5311. if (conn.State == ConnectionState.Open)
  5312. {
  5313. conn.Close();
  5314. }
  5315. conn.Dispose();
  5316. }
  5317. }
  5318. }
  5319. #endregion
  5320. }
  5321. }