纽威
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.

5265 lines
295 KiB

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