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

5200 lines
290 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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
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.TransferLibrary.GetDescription()) // && TransType != TransTypeEnum.LOTSplit.GetDescription()
  1407. {
  1408. if (string.IsNullOrEmpty(JsonData.TransCode))
  1409. {
  1410. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1411. }
  1412. WMSSourceDocumentModel model = new WMSSourceDocumentModel();
  1413. model.TransCode = JsonData.TransCode;
  1414. model.TransType = JsonData.TransType;
  1415. model.WorkPoint = JsonData.WorkPoint;
  1416. DataTable TransData = TransInformationGet(model);
  1417. DataView dataView = TransData.DefaultView;
  1418. foreach (DataRow drLot in table.Rows)
  1419. {
  1420. string Lot = drLot["LotNo"].ToString();
  1421. string rowFilter = "InvCode='" + drLot["InvCode"] + "'";
  1422. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo041"), Lot, drLot["InvCode"]));
  1423. rowFilter += " AND (LEN(ISNULL(WHCode,''))<=0 OR (LEN(ISNULL(WHCode,''))>0 AND WHCode='" + drLot["WHCode"] + "'))";
  1424. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo042"), Lot, drLot["WHCode"]));
  1425. //盘点不需要对比以下属性
  1426. if (TransType == TransTypeEnum.Check.GetDescription())
  1427. continue;
  1428. rowFilter += " AND (LEN(ISNULL(ProjectCode,''))<=0 OR (LEN(ISNULL(ProjectCode,''))>0 AND ProjectCode='" + drLot["ProjectCode"] + "'))";
  1429. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo043"), Lot, drLot["ProjectCode"]));
  1430. rowFilter += "AND (LEN(ISNULL(BatchCode,''))<=0 OR (LEN(ISNULL(BatchCode,''))>0 AND BatchCode='" + drLot["BatchCode"] + "'))";
  1431. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo044"), Lot, drLot["BatchCode"]));
  1432. rowFilter += "AND (LEN(ISNULL(Version,''))<=0 OR (LEN(ISNULL(Version,''))>0 AND Version='" + drLot["Version"] + "'))";
  1433. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo045"), Lot, drLot["Version"]));
  1434. rowFilter += "AND (LEN(ISNULL(Brand,''))<=0 OR (LEN(ISNULL(Brand,''))>0 AND Brand='" + drLot["Brand"] + "'))";
  1435. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo046"), Lot, drLot["Brand"]));
  1436. rowFilter += "AND (LEN(ISNULL(cFree1,''))<=0 OR (LEN(ISNULL(cFree1,''))>0 AND cFree1='" + drLot["cFree1"] + "'))";
  1437. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo047"), Lot, drLot["cFree1"]));
  1438. rowFilter += "AND (LEN(ISNULL(cFree2,''))<=0 OR (LEN(ISNULL(cFree2,''))>0 AND cFree2='" + drLot["cFree2"] + "'))";
  1439. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo048"), Lot, drLot["cFree2"]));
  1440. rowFilter += "AND (LEN(ISNULL(cFree3,''))<=0 OR (LEN(ISNULL(cFree3,''))>0 AND cFree3='" + drLot["cFree3"] + "'))";
  1441. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo049"), Lot, drLot["cFree3"]));
  1442. rowFilter += "AND (LEN(ISNULL(cFree4,''))<=0 OR (LEN(ISNULL(cFree4,''))>0 AND cFree4='" + drLot["cFree4"] + "'))";
  1443. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo050"), Lot, drLot["cFree4"]));
  1444. rowFilter += "AND (LEN(ISNULL(cFree5,''))<=0 OR (LEN(ISNULL(cFree5,''))>0 AND cFree5='" + drLot["cFree5"] + "'))";
  1445. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo051"), Lot, drLot["cFree5"]));
  1446. rowFilter += "AND (LEN(ISNULL(cFree6,''))<=0 OR (LEN(ISNULL(cFree6,''))>0 AND cFree6='" + drLot["cFree6"] + "'))";
  1447. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo052"), Lot, drLot["cFree6"]));
  1448. rowFilter += "AND (LEN(ISNULL(cFree7,''))<=0 OR (LEN(ISNULL(cFree7,''))>0 AND cFree7='" + drLot["cFree7"] + "'))";
  1449. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo053"), Lot, drLot["cFree7"]));
  1450. rowFilter += "AND (LEN(ISNULL(cFree8,''))<=0 OR (LEN(ISNULL(cFree8,''))>0 AND cFree8='" + drLot["cFree8"] + "'))";
  1451. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo054"), Lot, drLot["cFree8"]));
  1452. rowFilter += "AND (LEN(ISNULL(cFree9,''))<=0 OR (LEN(ISNULL(cFree9,''))>0 AND cFree9='" + drLot["cFree9"] + "'))";
  1453. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo055"), Lot, drLot["cFree9"]));
  1454. rowFilter += "AND (LEN(ISNULL(cFree10,''))<=0 OR (LEN(ISNULL(cFree10,''))>0 AND cFree10='" + drLot["cFree10"] + "'))";
  1455. CheckTrans(dataView, rowFilter, string.Format(language.GetNameByCode("WMSAPIInfo056"), Lot, drLot["cFree10"]));
  1456. //保质期管理
  1457. var resultEffective = Effective(Lot, JsonData.WorkPoint, cmd, language);
  1458. //0 - 已经是最早的批次
  1459. //1 - 不管控
  1460. //2 - 提醒
  1461. //3 - 限制
  1462. if (resultEffective == "2")
  1463. {
  1464. msg += string.Format(language.GetNameByCode("WMSAPIInfo181"), Lot) + Environment.NewLine;
  1465. }
  1466. else if (resultEffective == "3")
  1467. {
  1468. msg += string.Format(language.GetNameByCode("WMSAPIInfo182"), Lot) + Environment.NewLine;
  1469. isLimit = true;
  1470. }
  1471. //先进先出判断
  1472. var result = CanOut(Lot, JsonData.WorkPoint, JsonData.ScanLotCode, cmd, language);
  1473. //0 - 已经是最早的批次
  1474. //1 - 不管控
  1475. //2 - 提醒
  1476. //3 - 限制
  1477. if (result == "2")
  1478. {
  1479. msg += string.Format(language.GetNameByCode("WMSAPIInfo178"), Lot) + Environment.NewLine;
  1480. }
  1481. else if (result == "3")
  1482. {
  1483. msg += string.Format(language.GetNameByCode("WMSAPIInfo179"), Lot) + Environment.NewLine;
  1484. isLimit = true;
  1485. }
  1486. }
  1487. }
  1488. #endregion
  1489. //return table;
  1490. Result res = new Result();
  1491. res.Success = true;
  1492. res.Message = msg;// "接口调用成功!";
  1493. if (!isLimit)
  1494. res.Data = table;
  1495. return res;
  1496. //出库时
  1497. //Message无值、Data有值,可直接处理
  1498. //Message有值、Data有值,弹出提醒框(可点击确定、取消,确定后继续出库,取消后不处理这批条码),显示Message信息
  1499. //Message有值、Data无值,弹出警告框(只能点击确定,且不处理这批条码),显示Message信息
  1500. }
  1501. catch (Exception ex)
  1502. {
  1503. log.Error(ex.Message);
  1504. throw new Exception(ex.Message);
  1505. }
  1506. finally
  1507. {
  1508. if (conn.State == ConnectionState.Open)
  1509. {
  1510. conn.Close();
  1511. }
  1512. conn.Dispose();
  1513. }
  1514. }
  1515. }
  1516. /// <summary>
  1517. /// 校验条码对应的物料、自由项等信息是否与源头单据匹配
  1518. /// </summary>
  1519. private static void CheckTrans(DataView dataView, string rowFilter, string message)
  1520. {
  1521. dataView.RowFilter = rowFilter;
  1522. if (dataView == null || dataView.Count <= 0)
  1523. throw new Exception(message);
  1524. }
  1525. #endregion
  1526. /// <summary>
  1527. /// 上架
  1528. /// </summary>BusinessCode,TransType 两个类型
  1529. /// <param name="JsonData"></param>
  1530. /// <returns></returns>
  1531. public static DataTable LOTStockCreate(List<LOTStockUpCreateIModel> JsonData)
  1532. {
  1533. var language = LanguageHelper.GetName("WMSAPIInfo");
  1534. if (JsonData.Count <= 0)
  1535. {
  1536. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  1537. }
  1538. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1539. {
  1540. conn.Open();
  1541. SqlTransaction sqlTran = conn.BeginTransaction();
  1542. SqlCommand cmd = new SqlCommand();
  1543. cmd.Transaction = sqlTran;
  1544. cmd.Connection = conn;
  1545. try
  1546. {
  1547. string TransType = string.Empty;
  1548. string Identification = Guid.NewGuid().ToString();
  1549. foreach (var item in JsonData)
  1550. {
  1551. TransType = item.TransType;
  1552. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  1553. {
  1554. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  1555. }
  1556. string WHTransType = "2";
  1557. string BusinessCode = string.Empty;
  1558. foreach (var itemInfo in item.detail)
  1559. {
  1560. #region 两步调入
  1561. if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1562. {
  1563. //更新源头单据数量
  1564. ICSWareHouseService.TwoStepTransferDocIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1565. //入库
  1566. ICSWareHouseLotInfoService.WareHouseLotInfoTwoStepTransferDocIn(Identification, itemInfo.TransCode, itemInfo.TransSequence,
  1567. itemInfo.WarehouseCode, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity, item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocIn.GetDescription<DBValue>(), cmd, language);
  1568. }
  1569. #endregion
  1570. #region 销售退货-原条码
  1571. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1572. {
  1573. //更新源头单据数量
  1574. ICSSalesService.SalesReturnBackIn(itemInfo.TransCode, itemInfo.TransSequence, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1575. //入库
  1576. BusinessCode = TransTypeEnum.SalesReturnBack.GetDescription<DBValue>();
  1577. //入库
  1578. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  1579. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language, itemInfo.LogID, itemInfo.InvCode + itemInfo.WarehouseCode);
  1580. //更新日志表源头单据信息
  1581. string sql = @"UPDATE ICSWareHouseLotInfoLog SET TransCode='{3}',TransSequence='{4}'
  1582. WHERE LotNo='{0}' AND WorkPoint='{1}' AND Identification='{2}' AND TransCode='' AND TransSequence=''";
  1583. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, Identification, itemInfo.TransCode, itemInfo.TransSequence);
  1584. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  1585. {
  1586. throw new Exception(language.GetNameByCode("WMSAPIInfo143"));//"销售退货单更新失败!");
  1587. }
  1588. }
  1589. #endregion
  1590. else
  1591. {
  1592. #region 采购入库
  1593. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1594. {
  1595. //更新源头单据数量
  1596. ICSPurchaseService.PurchaseReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1597. BusinessCode = TransTypeEnum.PurchaseReceiveDoc.GetDescription<DBValue>();
  1598. }
  1599. #endregion
  1600. #region 审核的到货单
  1601. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1602. {
  1603. //更新源头单据数量
  1604. ICSPurchaseService.DeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1605. BusinessCode = TransTypeEnum.DeliveryNotice.GetDescription<DBValue>();
  1606. }
  1607. #endregion
  1608. #region 采购拒收
  1609. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1610. {
  1611. //更新源头单据数量
  1612. ICSPurchaseService.PurchaseRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1613. BusinessCode = TransTypeEnum.PurchaseRejectDoc.GetDescription<DBValue>();
  1614. }
  1615. #endregion
  1616. #region 审核的委外到货单
  1617. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1618. {
  1619. //更新源头单据数量
  1620. ICSOutsourcingService.ODeliveryNoticeIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1621. BusinessCode = TransTypeEnum.ODeliveryNotice.GetDescription<DBValue>();
  1622. }
  1623. #endregion
  1624. #region 委外拒收
  1625. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1626. {
  1627. //更新源头单据数量
  1628. ICSOutsourcingService.OutsourcingRejectDocIn(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1629. BusinessCode = TransTypeEnum.OutsourcingRejectDoc.GetDescription<DBValue>();
  1630. }
  1631. #endregion
  1632. #region 委外退料
  1633. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1634. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1635. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1636. {
  1637. //更新源头单据数量
  1638. ICSOutsourcingService.OutsourcingIssueDoNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1639. BusinessCode = TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription<DBValue>();
  1640. }
  1641. #endregion
  1642. #region 返工工单
  1643. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1644. {
  1645. //更新源头单据数量
  1646. ICSManufactureService.ReWorkReceiveMo(itemInfo.LotNo, itemInfo.Quantity, itemInfo.WarehouseCode, itemInfo.LocationCode, item.WorkPoint, item.User, TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>(), cmd, language);
  1647. BusinessCode = TransTypeEnum.ReWorkReceiveMo.GetDescription<DBValue>();
  1648. }
  1649. #endregion
  1650. #region 委外入库
  1651. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1652. {
  1653. //更新源头单据数量
  1654. ICSOutsourcingService.OutsourcingReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1655. BusinessCode = TransTypeEnum.OutsourcingReceiveDoc.GetDescription<DBValue>();
  1656. }
  1657. #endregion
  1658. #region 生产退料
  1659. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1660. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1661. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1662. {
  1663. //更新源头单据数量
  1664. ICSManufactureService.MOIssueDocNegative(TransType, itemInfo.LogID, itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1665. BusinessCode = TransTypeEnum.MOIssueDocNegative.GetDescription<DBValue>();
  1666. }
  1667. #endregion
  1668. #region 生产入库
  1669. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1670. {
  1671. //更新源头单据数量
  1672. ICSManufactureService.ManufactureReceiveDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1673. BusinessCode = TransTypeEnum.ManufactureReceiveDoc.GetDescription<DBValue>();
  1674. }
  1675. #endregion
  1676. #region 开立的生产入库单
  1677. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1678. {
  1679. //更新源头单据数量
  1680. ICSManufactureService.ManufactureReceive(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1681. BusinessCode = TransTypeEnum.ManufactureReceive.GetDescription<DBValue>();
  1682. }
  1683. #endregion
  1684. #region 销售退货
  1685. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1686. {
  1687. //更新源头单据数量
  1688. ICSSalesService.SalesShipmentDocNegative(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1689. BusinessCode = TransTypeEnum.SalesShipmentDocNegative.GetDescription<DBValue>();
  1690. }
  1691. #endregion
  1692. #region 其他入库
  1693. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1694. {
  1695. //更新源头单据数量
  1696. ICSWareHouseService.OtherInDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1697. BusinessCode = TransTypeEnum.OtherInDoc.GetDescription<DBValue>();
  1698. }
  1699. #endregion
  1700. #region 拆卸单
  1701. else if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1702. {
  1703. ICSWareHouseService.DisassemblyDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1704. WHTransType = "11";
  1705. BusinessCode = TransTypeEnum.DisassemblyDoc.GetDescription<DBValue>();
  1706. }
  1707. #endregion
  1708. #region 归还
  1709. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1710. {
  1711. //更新源头单据数量
  1712. ICSWareHouseService.ReturnDoc(itemInfo.LotNo, itemInfo.Quantity, item.WorkPoint, cmd, language);
  1713. BusinessCode = TransTypeEnum.ReturnDoc.GetDescription<DBValue>();
  1714. }
  1715. #endregion
  1716. else
  1717. {
  1718. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  1719. }
  1720. //入库
  1721. ICSWareHouseLotInfoService.WareHouseLotInfoUp(Identification, itemInfo.LocationCode, itemInfo.LotNo, itemInfo.Quantity,
  1722. item.User, item.WorkPoint, WHTransType, BusinessCode, cmd, language,itemInfo.LogID,itemInfo.InvCode + itemInfo.WarehouseCode);
  1723. }
  1724. }
  1725. #region 拆卸单
  1726. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1727. {
  1728. //更新套件锁定数量
  1729. ICSWareHouseService.DisassemblyDoc(Identification, cmd, language);
  1730. }
  1731. #endregion}
  1732. }
  1733. //上传ERP
  1734. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  1735. {
  1736. //采购入库
  1737. if (TransType == TransTypeEnum.PurchaseReceiveDoc.GetDescription())
  1738. ICSPurchaseService.PurchaseReceiveDocERP(TransType, Identification, cmd, language);
  1739. //审核的到货单
  1740. else if (TransType == TransTypeEnum.DeliveryNotice.GetDescription())
  1741. ICSPurchaseService.DeliveryNoticeInERP(TransType, Identification, cmd, language);
  1742. //采购拒收
  1743. else if (TransType == TransTypeEnum.PurchaseRejectDoc.GetDescription())
  1744. ICSPurchaseService.PurchaseRejectDocInERP(TransType, Identification, cmd, language);
  1745. //审核的委外到货单
  1746. else if (TransType == TransTypeEnum.ODeliveryNotice.GetDescription())
  1747. ICSOutsourcingService.ODeliveryNoticeInERP(TransType, Identification, cmd, language);
  1748. //委外拒收
  1749. else if (TransType == TransTypeEnum.OutsourcingRejectDoc.GetDescription())
  1750. ICSOutsourcingService.OutsourcingRejectDocInERP(TransType, Identification, cmd, language);
  1751. //委外退料
  1752. else if (TransType == TransTypeEnum.ICSOutsourcingIssueDoNegative.GetDescription()
  1753. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeApply.GetDescription()
  1754. || TransType == TransTypeEnum.ICSOutsourcingIssueDoNegativeIssue.GetDescription())
  1755. ICSOutsourcingService.OutsourcingIssueDoNegativeERP(TransType, Identification, cmd, language);
  1756. //委外入库
  1757. else if (TransType == TransTypeEnum.OutsourcingReceiveDoc.GetDescription())
  1758. ICSOutsourcingService.OutsourcingReceiveDocERP(TransType, Identification, cmd, language);
  1759. //生产退料
  1760. else if (TransType == TransTypeEnum.MOIssueDocNegative.GetDescription()
  1761. || TransType == TransTypeEnum.MOIssueDocNegativeApply.GetDescription()
  1762. || TransType == TransTypeEnum.MOIssueDocNegativeIssue.GetDescription())
  1763. ICSManufactureService.MOIssueDocNegativeERP(TransType, Identification, cmd, language);
  1764. //生产入库
  1765. else if (TransType == TransTypeEnum.ManufactureReceiveDoc.GetDescription())
  1766. ICSManufactureService.ManufactureReceiveDocERP(TransType, Identification, cmd, language);
  1767. //开立的生产入库单
  1768. else if (TransType == TransTypeEnum.ManufactureReceive.GetDescription())
  1769. ICSManufactureService.ManufactureReceiveERP(TransType, Identification, cmd, language);
  1770. //返工工单
  1771. else if (TransType == TransTypeEnum.ReWorkReceiveMo.GetDescription())
  1772. ICSManufactureService.ReWorkReceiveMoERP(TransType, Identification, cmd, language);
  1773. //销售退货
  1774. else if (TransType == TransTypeEnum.SalesShipmentDocNegative.GetDescription())
  1775. ICSSalesService.SalesShipmentDocNegativeERP(TransType, Identification, cmd, language);
  1776. //两步调入
  1777. else if (TransType == TransTypeEnum.TwoStepTransferDocIn.GetDescription())
  1778. ICSWareHouseService.TwoStepTransferDocInERP(TransType, Identification, cmd, language);
  1779. //销售退货-原条码
  1780. else if (TransType == TransTypeEnum.SalesReturnBack.GetDescription())
  1781. ICSSalesService.SalesReturnBackInERP(TransType, Identification, cmd, language);
  1782. //其他入库
  1783. else if (TransType == TransTypeEnum.OtherInDoc.GetDescription())
  1784. ICSWareHouseService.OtherInDocERP(TransType, Identification, cmd, language);
  1785. //拆卸单
  1786. if (TransType == TransTypeEnum.DisassemblyDoc.GetDescription())
  1787. ICSWareHouseService.DisassemblyDocERP(TransType, Identification, cmd, language);
  1788. //归还
  1789. else if (TransType == TransTypeEnum.ReturnDoc.GetDescription())
  1790. ICSWareHouseService.ReturnDocERP(TransType, Identification, cmd, language);
  1791. }
  1792. DataTable table = GetData(Identification, 1, cmd);
  1793. cmd.Transaction.Commit();
  1794. return table;
  1795. }
  1796. catch (Exception ex)
  1797. {
  1798. if (cmd.Transaction != null)
  1799. cmd.Transaction.Rollback();
  1800. log.Error(ex.Message);
  1801. throw new Exception(ex.Message);
  1802. }
  1803. finally
  1804. {
  1805. if (conn.State == ConnectionState.Open)
  1806. {
  1807. conn.Close();
  1808. }
  1809. conn.Dispose();
  1810. }
  1811. }
  1812. }
  1813. /// <summary>
  1814. /// 下架
  1815. /// </summary>
  1816. /// <param name="JsonData"></param>
  1817. /// <returns></returns>
  1818. public static DataTable LOTStockDownCreate(List<LOTStockModel> JsonData)
  1819. {
  1820. String PrintEnable = "";
  1821. var language = LanguageHelper.GetName("WMSAPIInfo");
  1822. if (JsonData.Count <= 0)
  1823. {
  1824. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  1825. }
  1826. List<LOTStockModelList> model = new List<LOTStockModelList>();
  1827. DataTable printTable = new DataTable();
  1828. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  1829. {
  1830. conn.Open();
  1831. SqlTransaction sqlTran = conn.BeginTransaction();
  1832. SqlCommand cmd = new SqlCommand();
  1833. cmd.Transaction = sqlTran;
  1834. cmd.Connection = conn;
  1835. try
  1836. {
  1837. string TransType = string.Empty;
  1838. string Identification = Guid.NewGuid().ToString();
  1839. foreach (var item in JsonData)
  1840. {
  1841. TransType = item.TransType;
  1842. if (!EnumHelper.HasDescriptions(typeof(TransTypeEnum), TransType))
  1843. {
  1844. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  1845. }
  1846. else if (string.IsNullOrEmpty(item.TransCode))
  1847. {
  1848. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  1849. }
  1850. string[] trans = item.TransCode.Split('~');
  1851. string MergeID = "";
  1852. if (trans.Length == 2)
  1853. {
  1854. MergeID = trans[0];
  1855. item.TransCode = trans[1];
  1856. }
  1857. #region 采购退货
  1858. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  1859. {
  1860. //更新源头单据数量
  1861. ICSPurchaseService.PurchaseReceiveDoctNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1862. foreach (var itemInfo in item.detail)
  1863. {
  1864. //出库
  1865. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1866. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription<DBValue>(), cmd, language);
  1867. }
  1868. }
  1869. #endregion
  1870. #region 委外发料
  1871. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  1872. {
  1873. //更新源头单据数量
  1874. ICSOutsourcingService.OutsourcingIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1875. foreach (var itemInfo in item.detail)
  1876. {
  1877. //出库
  1878. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1879. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  1880. }
  1881. }
  1882. #endregion
  1883. #region 委外退货
  1884. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  1885. {
  1886. //更新源头单据数量
  1887. ICSOutsourcingService.OutsourcingReturnBack(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1888. foreach (var itemInfo in item.detail)
  1889. {
  1890. //出库
  1891. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1892. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReturnBack.GetDescription<DBValue>(), cmd, language);
  1893. }
  1894. }
  1895. #endregion
  1896. #region 生产发料
  1897. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  1898. {
  1899. //更新源头单据数量
  1900. ICSManufactureService.MOIssueDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1901. foreach (var itemInfo in item.detail)
  1902. {
  1903. //出库
  1904. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1905. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssueDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  1906. }
  1907. }
  1908. #endregion
  1909. #region 销售出库
  1910. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  1911. {
  1912. //更新源头单据数量
  1913. ICSSalesService.SalesShipmentDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1914. foreach (var itemInfo in item.detail)
  1915. {
  1916. //出库
  1917. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1918. item.User, item.WorkPoint, "3", TransTypeEnum.SalesShipmentDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  1919. }
  1920. }
  1921. #endregion
  1922. #region 两步调出
  1923. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  1924. {
  1925. //更新源头单据数量
  1926. ICSWareHouseService.TwoStepTransferDocOut(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1927. foreach (var itemInfo in item.detail)
  1928. {
  1929. //出库
  1930. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1931. item.User, item.WorkPoint, "6", TransTypeEnum.TwoStepTransferDocOut.GetDescription<DBValue>(), cmd, language, MergeID);
  1932. }
  1933. }
  1934. #endregion
  1935. #region 其他出库
  1936. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  1937. {
  1938. //更新源头单据数量
  1939. ICSWareHouseService.OtherOutDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1940. foreach (var itemInfo in item.detail)
  1941. {
  1942. //出库
  1943. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1944. item.User, item.WorkPoint, "3", TransTypeEnum.OtherOutDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  1945. }
  1946. }
  1947. #endregion
  1948. #region 领料申请单发料
  1949. else if (TransType == TransTypeEnum.MOApply.GetDescription())
  1950. {
  1951. //更新源头单据数量
  1952. ICSManufactureService.MOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1953. foreach (var itemInfo in item.detail)
  1954. {
  1955. //出库
  1956. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1957. item.User, item.WorkPoint, "3", TransTypeEnum.MOApply.GetDescription<DBValue>(), cmd, language, MergeID);
  1958. }
  1959. }
  1960. #endregion
  1961. #region 委外领料申请单发料
  1962. else if (TransType == TransTypeEnum.OOApply.GetDescription())
  1963. {
  1964. //更新源头单据数量
  1965. ICSOutsourcingService.OOApply(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1966. foreach (var itemInfo in item.detail)
  1967. {
  1968. //出库
  1969. printTable = ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1970. item.User, item.WorkPoint, "3", TransTypeEnum.OOApply.GetDescription<DBValue>(), cmd, language,MergeID);
  1971. }
  1972. }
  1973. #endregion
  1974. #region 开立材料出库
  1975. else if (TransType == TransTypeEnum.MOIssue.GetDescription())
  1976. {
  1977. //更新源头单据数量
  1978. ICSManufactureService.MOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1979. foreach (var itemInfo in item.detail)
  1980. {
  1981. //出库
  1982. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1983. item.User, item.WorkPoint, "3", TransTypeEnum.MOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  1984. }
  1985. }
  1986. #endregion
  1987. #region 开立委外材料出库
  1988. else if (TransType == TransTypeEnum.OOIssue.GetDescription())
  1989. {
  1990. //更新源头单据数量
  1991. ICSOutsourcingService.OOIssue(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  1992. foreach (var itemInfo in item.detail)
  1993. {
  1994. //出库
  1995. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  1996. item.User, item.WorkPoint, "3", TransTypeEnum.OOIssue.GetDescription<DBValue>(), cmd, language, MergeID);
  1997. }
  1998. }
  1999. #endregion
  2000. #region 开立红字入库单
  2001. else if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2002. {
  2003. //更新源头单据数量
  2004. ICSPurchaseService.PurchaseReceive(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2005. foreach (var itemInfo in item.detail)
  2006. {
  2007. //出库
  2008. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2009. item.User, item.WorkPoint, "3", TransTypeEnum.PurchaseReceive.GetDescription<DBValue>(), cmd, language);
  2010. }
  2011. }
  2012. #endregion
  2013. #region 开立委外红字入库单
  2014. else if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2015. {
  2016. //更新源头单据数量
  2017. ICSOutsourcingService.OutsourcingReceiveDocNegative(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2018. foreach (var itemInfo in item.detail)
  2019. {
  2020. //出库
  2021. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2022. item.User, item.WorkPoint, "3", TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription<DBValue>(), cmd, language);
  2023. }
  2024. }
  2025. #endregion
  2026. #region 借用
  2027. else if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2028. {
  2029. //更新源头单据数量
  2030. ICSWareHouseService.BrrowDoc(item.TransCode, item.TransSequence, item.Quantity, item.WorkPoint, cmd, language);
  2031. foreach (var itemInfo in item.detail)
  2032. {
  2033. //出库
  2034. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoDown(Identification, item.TransCode, item.TransSequence, itemInfo.LotNo, itemInfo.CurrentQuantity,
  2035. item.User, item.WorkPoint, "3", TransTypeEnum.BrrowDoc.GetDescription<DBValue>(), cmd, language, MergeID);
  2036. }
  2037. }
  2038. #endregion
  2039. else
  2040. {
  2041. throw new Exception(LanguageHelper.GetNameSingle("WMSAPIInfo003"));//"单据类型不存在!"
  2042. }
  2043. }
  2044. //上传ERP
  2045. if (Convert.ToBoolean(System.Configuration.ConfigurationManager.AppSettings["UploadERP"]))
  2046. {
  2047. //采购退货
  2048. if (TransType == TransTypeEnum.PurchaseReceiveDoctNegative.GetDescription())
  2049. ICSPurchaseService.PurchaseReceiveDoctNegativeERP(TransType, Identification, cmd, language);
  2050. //委外发料
  2051. else if (TransType == TransTypeEnum.OutsourcingIssueDoc.GetDescription())
  2052. ICSOutsourcingService.OutsourcingIssueDocERP(TransType, Identification, cmd, language);
  2053. //委外退货
  2054. else if (TransType == TransTypeEnum.OutsourcingReturnBack.GetDescription())
  2055. ICSOutsourcingService.OutsourcingReturnBackERP(TransType, Identification, cmd, language);
  2056. //生产发料
  2057. else if (TransType == TransTypeEnum.MOIssueDoc.GetDescription())
  2058. ICSManufactureService.MOIssueDocERP(TransType, Identification, cmd, language);
  2059. //销售出库
  2060. else if (TransType == TransTypeEnum.SalesShipmentDoc.GetDescription())
  2061. ICSSalesService.SalesShipmentDocERP(TransType, Identification, cmd, language);
  2062. //两步调出
  2063. else if (TransType == TransTypeEnum.TwoStepTransferDocOut.GetDescription())
  2064. ICSWareHouseService.TwoStepTransferDocOutERP(TransType, Identification, cmd, language);
  2065. //其他出库
  2066. else if (TransType == TransTypeEnum.OtherOutDoc.GetDescription())
  2067. ICSWareHouseService.OtherOutDocERP(TransType, Identification, cmd, language);
  2068. //领料申请单发料
  2069. if (TransType == TransTypeEnum.MOApply.GetDescription())
  2070. ICSManufactureService.MOApplyERP(TransType, Identification, cmd, language);
  2071. //委外领料申请单发料
  2072. if (TransType == TransTypeEnum.OOApply.GetDescription())
  2073. ICSOutsourcingService.OOApplyERP(TransType, Identification, cmd, language);
  2074. //开立材料出库
  2075. if (TransType == TransTypeEnum.MOIssue.GetDescription())
  2076. ICSManufactureService.MOIssueERP(TransType, Identification, cmd, language);
  2077. //开立委外材料出库
  2078. if (TransType == TransTypeEnum.OOIssue.GetDescription())
  2079. ICSOutsourcingService.OOIssueERP(TransType, Identification, cmd, language);
  2080. //开立红字入库单
  2081. if (TransType == TransTypeEnum.PurchaseReceive.GetDescription())
  2082. ICSPurchaseService.PurchaseReceiveERP(TransType, Identification, cmd, language);
  2083. //开立委外红字入库单
  2084. if (TransType == TransTypeEnum.OutsourcingReceiveDocNegative.GetDescription())
  2085. ICSOutsourcingService.OutsourcingReceiveDocNegativeERP(TransType, Identification, cmd, language);
  2086. //借用
  2087. if (TransType == TransTypeEnum.BrrowDoc.GetDescription())
  2088. ICSWareHouseService.BrrowDocERP(TransType, Identification, cmd, language);
  2089. }
  2090. if (!printTable.Equals("{}"))
  2091. {
  2092. cmd.Transaction.Commit();
  2093. return printTable;
  2094. }
  2095. else
  2096. {
  2097. DataTable table = GetData(Identification, 2, cmd);
  2098. cmd.Transaction.Commit();
  2099. return table;
  2100. }
  2101. }
  2102. catch (Exception ex)
  2103. {
  2104. if (cmd.Transaction != null)
  2105. cmd.Transaction.Rollback();
  2106. log.Error(ex.Message);
  2107. throw new Exception(ex.Message);
  2108. }
  2109. finally
  2110. {
  2111. if (conn.State == ConnectionState.Open)
  2112. {
  2113. conn.Close();
  2114. }
  2115. conn.Dispose();
  2116. }
  2117. }
  2118. }
  2119. #region 采购
  2120. /// <summary>
  2121. /// 采购到货
  2122. /// </summary>
  2123. /// <param name="JsonData"></param>
  2124. /// <returns></returns>
  2125. public static DataTable DeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  2126. {
  2127. var language = LanguageHelper.GetName("WMSAPIInfo");
  2128. if (JsonData.Count <= 0)
  2129. {
  2130. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2131. }
  2132. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2133. {
  2134. conn.Open();
  2135. SqlTransaction sqlTran = conn.BeginTransaction();
  2136. SqlCommand cmd = new SqlCommand();
  2137. cmd.Transaction = sqlTran;
  2138. cmd.Connection = conn;
  2139. try
  2140. {
  2141. string asncodes = string.Empty;
  2142. string sql = string.Empty;
  2143. foreach (var item in JsonData)
  2144. {
  2145. if (string.IsNullOrEmpty(item.ASNCode))
  2146. {
  2147. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!"
  2148. }
  2149. //获取单号
  2150. sql = @"IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.ASNCode='{0}' AND DNType = '1' AND a.WorkPoint='{1}')
  2151. BEGIN
  2152. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  2153. RETURN
  2154. END
  2155. DECLARE @Status VARCHAR(10)
  2156. SELECT @Status=Status FROM ICSASN WHERE ASNCode='{0}' and WorkPoint='{1}'
  2157. IF (@Status IS NULL)
  2158. BEGIN
  2159. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  2160. RETURN
  2161. END
  2162. ELSE IF (@Status!='2')
  2163. BEGIN
  2164. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  2165. RETURN
  2166. END
  2167. DECLARE @MaxNO INT,@date varchar(20)='DN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2168. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2169. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2170. IF @MaxNO IS NULL
  2171. BEGIN
  2172. SELECT @date+'00001' AS Code
  2173. END
  2174. ELSE
  2175. BEGIN
  2176. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2177. END ";
  2178. sql = string.Format(sql, item.ASNCode, item.WorkPoint);
  2179. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2180. //修改送货单到货数量
  2181. foreach (var itemInfo in item.detail)
  2182. {
  2183. sql = @"UPDATE ICSASNDetail SET DNQuantity=ISNULL(DNQuantity, 0)+'{2}'
  2184. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  2185. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  2186. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2187. {
  2188. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"送货单子表信息更新失败!");
  2189. }
  2190. }
  2191. //创建到货单信息
  2192. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  2193. BEGIN
  2194. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  2195. RETURN
  2196. END
  2197. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2198. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2199. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2200. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2201. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2202. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  2203. '1',b.InvCode,SUM(a.DNQuantity),'0','0',
  2204. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  2205. d.POID,d.PODetailID,newid(),newid(),b.ExtensionID,
  2206. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.ASNCode
  2207. FROM ICSASNDetail a
  2208. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  2209. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  2210. INNER JOIN ICSPurchaseOrder d ON c.TransCode=d.POCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  2211. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  2212. WHERE a.ASNCode='{3}' AND a.WorkPoint='{2}'
  2213. 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";
  2214. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.ASNCode);
  2215. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2216. {
  2217. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  2218. }
  2219. ICSPurchaseService.DeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  2220. asncodes += "'" + item.ASNCode + item.WorkPoint + "',";
  2221. }
  2222. if (string.IsNullOrWhiteSpace(asncodes))
  2223. {
  2224. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  2225. }
  2226. #region 查询返回数据
  2227. sql = @"SELECT
  2228. n.POCode,
  2229. n.Sequence AS POSequence,
  2230. a.ASNCode,
  2231. a.DNCode,
  2232. a.Sequence,
  2233. a.VenCode,
  2234. a.DepCode,
  2235. a.InvCode,
  2236. inv.InvName,
  2237. inv.InvStd,
  2238. a.Quantity,
  2239. inv.InvUnit,
  2240. a.Amount,
  2241. inv.AmountUnit,
  2242. a.RCVQuantity,
  2243. a.UnitPrice,
  2244. a.Currency,
  2245. a.POID,
  2246. a.PODetailID,
  2247. a.DNID,
  2248. a.DNDetailID,
  2249. ext.ProjectCode,
  2250. ext.BatchCode,
  2251. ext.Version,
  2252. ext.Brand,
  2253. ext.cFree1,
  2254. ext.cFree2,
  2255. ext.cFree3,
  2256. ext.cFree4,
  2257. ext.cFree5,
  2258. ext.cFree6,
  2259. ext.cFree7,
  2260. ext.cFree8,
  2261. ext.cFree9,
  2262. ext.cFree10,
  2263. a.MUSER AS [User],
  2264. a.MTIME AS [MTime]
  2265. FROM ICSDeliveryNotice a
  2266. INNER JOIN ICSPurchaseOrder n ON a.POID =n.POID AND a.PODetailID=n.PODetailID AND a.WorkPoint=n.WorkPoint
  2267. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2268. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2269. WHERE a.ASNCode+a.WorkPoint IN ({0})";
  2270. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  2271. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2272. #endregion
  2273. cmd.Transaction.Commit();
  2274. return data;
  2275. }
  2276. catch (Exception ex)
  2277. {
  2278. if (cmd.Transaction != null)
  2279. cmd.Transaction.Rollback();
  2280. log.Error(ex.Message);
  2281. throw new Exception(ex.Message);
  2282. }
  2283. finally
  2284. {
  2285. if (conn.State == ConnectionState.Open)
  2286. {
  2287. conn.Close();
  2288. }
  2289. conn.Dispose();
  2290. }
  2291. }
  2292. }
  2293. /// <summary>
  2294. /// 采购拒收
  2295. /// </summary>
  2296. /// <param name="JsonData"></param>
  2297. /// <returns></returns>
  2298. public static DataTable PurchaseRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  2299. {
  2300. var language = LanguageHelper.GetName("WMSAPIInfo");
  2301. if (JsonData.Count <= 0)
  2302. {
  2303. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2304. }
  2305. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2306. {
  2307. conn.Open();
  2308. SqlTransaction sqlTran = conn.BeginTransaction();
  2309. SqlCommand cmd = new SqlCommand();
  2310. cmd.Transaction = sqlTran;
  2311. cmd.Connection = conn;
  2312. try
  2313. {
  2314. string lots = string.Empty;
  2315. string sql = string.Empty;
  2316. foreach (var item in JsonData)
  2317. {
  2318. if (string.IsNullOrEmpty(item.DNCode))
  2319. {
  2320. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  2321. }
  2322. //获取单号
  2323. sql = @"DECLARE @Status VARCHAR(10)
  2324. SELECT @Status=Status FROM ICSDeliveryNotice WHERE DNCode='{0}' and DNType='1' and WorkPoint='{1}'
  2325. IF (@Status IS NULL)
  2326. BEGIN
  2327. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  2328. RETURN
  2329. END
  2330. ELSE IF (@Status!='2')
  2331. BEGIN
  2332. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  2333. RETURN
  2334. END
  2335. DECLARE @MaxNO INT,@date varchar(20)='RJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2336. SELECT @MaxNO=SUBSTRING(MAX(DNCode),LEN(@date)+1,LEN(MAX(DNCode))-LEN(@date))+1 FROM ICSDeliveryNotice
  2337. WHERE SUBSTRING(DNCode, 1, LEN(@date))=@date
  2338. IF @MaxNO IS NULL
  2339. BEGIN
  2340. SELECT @date+'00001' AS Code
  2341. END
  2342. ELSE
  2343. BEGIN
  2344. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2345. END ";
  2346. sql = string.Format(sql, item.DNCode, item.WorkPoint);
  2347. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2348. //修改送货单到货数量
  2349. foreach (var itemInfo in item.detail)
  2350. {
  2351. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  2352. BEGIN
  2353. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  2354. RETURN
  2355. END
  2356. IF EXISTS(SELECT a.ID FROM ICSDeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND DNType = '3' AND a.WorkPoint='{2}')
  2357. BEGIN
  2358. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  2359. RETURN
  2360. END
  2361. INSERT INTO ICSDeliveryNotice(ID,DNCode,Sequence,VenCode,DepCode,
  2362. DNType,InvCode,Quantity,Amount,RCVQuantity,
  2363. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  2364. POID,PODetailID,DNID,DNDetailID,ExtensionID,
  2365. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,ASNCode)
  2366. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  2367. '3',d.InvCode,'{7}', '{8}', 0,
  2368. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  2369. a.DNID,a.DNDetailID, '0', '0', a.ExtensionID,
  2370. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  2371. FROM ICSDeliveryNotice a
  2372. INNER JOIN ICSASNDetail b ON a.ASNCode=b.ASNCode AND a.WorkPoint=b.WorkPoint
  2373. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  2374. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  2375. INNER JOIN ICSPurchaseOrder n ON m.TransCode =n.POCode AND m.TransSequence=n.Sequence AND a.PODetailID=n.PODetailID AND m.WorkPoint=n.WorkPoint
  2376. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  2377. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  2378. WHERE a.DNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  2379. 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);
  2380. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2381. {
  2382. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  2383. }
  2384. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  2385. }
  2386. }
  2387. if (string.IsNullOrWhiteSpace(lots))
  2388. {
  2389. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  2390. }
  2391. #region 查询返回数据
  2392. sql = @"SELECT
  2393. n.DNCode,
  2394. n.Sequence,
  2395. a.DNCode AS RJTCode,
  2396. a.Sequence AS RJTSequence,
  2397. a.VenCode,
  2398. a.DepCode,
  2399. a.InvCode,
  2400. inv.InvName,
  2401. inv.InvStd,
  2402. a.Quantity,
  2403. inv.InvUnit,
  2404. a.Amount,
  2405. inv.AmountUnit,
  2406. a.RCVQuantity,
  2407. a.UnitPrice,
  2408. a.Currency,
  2409. a.POID,
  2410. a.PODetailID,
  2411. a.DNID,
  2412. a.DNDetailID,
  2413. ext.ProjectCode,
  2414. ext.BatchCode,
  2415. ext.Version,
  2416. ext.Brand,
  2417. ext.cFree1,
  2418. ext.cFree2,
  2419. ext.cFree3,
  2420. ext.cFree4,
  2421. ext.cFree5,
  2422. ext.cFree6,
  2423. ext.cFree7,
  2424. ext.cFree8,
  2425. ext.cFree9,
  2426. ext.cFree10,
  2427. a.MUSER AS [User],
  2428. a.MTIME AS [MTime]
  2429. FROM ICSDeliveryNotice a
  2430. INNER JOIN ICSDeliveryNotice n ON a.POID =n.DNID AND a.PODetailID=n.DNDetailID AND a.WorkPoint=n.WorkPoint
  2431. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2432. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2433. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  2434. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  2435. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2436. #endregion
  2437. cmd.Transaction.Commit();
  2438. return data;
  2439. }
  2440. catch (Exception ex)
  2441. {
  2442. if (cmd.Transaction != null)
  2443. cmd.Transaction.Rollback();
  2444. log.Error(ex.Message);
  2445. throw new Exception(ex.Message);
  2446. }
  2447. finally
  2448. {
  2449. if (conn.State == ConnectionState.Open)
  2450. {
  2451. conn.Close();
  2452. }
  2453. conn.Dispose();
  2454. }
  2455. }
  2456. }
  2457. #endregion
  2458. #region 委外
  2459. /// <summary>
  2460. /// 委外退料 新建
  2461. /// </summary>
  2462. /// <param name="JsonData"></param>
  2463. /// <returns></returns>
  2464. public static DataTable OutsourcingIssueDoNegativeApplyCreate(List<ICSOApplyNeg> JsonData)
  2465. {
  2466. var language = LanguageHelper.GetName("WMSAPIInfo");
  2467. if (JsonData.Count <= 0)
  2468. {
  2469. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2470. }
  2471. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2472. {
  2473. conn.Open();
  2474. SqlTransaction sqlTran = conn.BeginTransaction();
  2475. SqlCommand cmd = new SqlCommand();
  2476. cmd.Transaction = sqlTran;
  2477. cmd.Connection = conn;
  2478. try
  2479. {
  2480. string codes = string.Empty;
  2481. string sql = string.Empty;
  2482. foreach (var item in JsonData)
  2483. {
  2484. //获取单号
  2485. sql = @"DECLARE @MaxNO INT,@date varchar(20)='OOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2486. SELECT @MaxNO=SUBSTRING(MAX(OApplyNegCode),LEN(@date)+1,LEN(MAX(OApplyNegCode))-LEN(@date))+1 FROM ICSOApplyNeg
  2487. WHERE SUBSTRING(OApplyNegCode, 1, LEN(@date))=@date
  2488. IF @MaxNO IS NULL
  2489. BEGIN
  2490. SELECT @date+'00001' AS Code
  2491. END
  2492. ELSE
  2493. BEGIN
  2494. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2495. END ";
  2496. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2497. //创建主表
  2498. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  2499. BEGIN
  2500. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  2501. RETURN
  2502. END
  2503. INSERT INTO ICSOApplyNeg(ID,OApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  2504. 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}','')";
  2505. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  2506. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2507. {
  2508. throw new Exception(language.GetNameByCode("WMSAPIInfo014"));//"委外退料单信息创建失败!");
  2509. }
  2510. foreach (var itemInfo in item.detail)
  2511. {
  2512. //创建子表
  2513. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  2514. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  2515. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  2516. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  2517. '{4}','{5}',0,'{6}','{7}',
  2518. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  2519. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  2520. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2521. {
  2522. throw new Exception(language.GetNameByCode("WMSAPIInfo015"));//"委外退料单子表信息创建失败!");
  2523. }
  2524. }
  2525. //校验退料数量是否超出领料数量
  2526. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  2527. DBHelper.ExecuteNonQuery(sql, cmd);
  2528. codes += "'" + Code + item.WorkPoint + "',";
  2529. }
  2530. if (string.IsNullOrWhiteSpace(codes))
  2531. {
  2532. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  2533. }
  2534. #region 查询返回数据
  2535. sql = @"SELECT a.OApplyNegCode,
  2536. c.WHCode,
  2537. c.Memo,
  2538. d.Name AS Status,
  2539. a.Sequence,
  2540. a.InvCode,
  2541. inv.InvName,
  2542. inv.InvStd,
  2543. a.Quantity,
  2544. inv.InvUnit,
  2545. a.Amount,
  2546. inv.AmountUnit,
  2547. a.IssueNegQuantity,
  2548. ext.ProjectCode,
  2549. ext.BatchCode,
  2550. ext.Version,
  2551. ext.Brand,
  2552. ext.cFree1,
  2553. ext.cFree2,
  2554. ext.cFree3,
  2555. ext.cFree4,
  2556. ext.cFree5,
  2557. ext.cFree6,
  2558. ext.cFree7,
  2559. ext.cFree8,
  2560. ext.cFree9,
  2561. ext.cFree10,
  2562. a.MUSER AS [User],
  2563. a.MTIME AS [MTime]
  2564. FROM ICSOApplyNegDetail a
  2565. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2566. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  2567. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2568. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2569. WHERE a.OApplyNegCode+a.WorkPoint IN ({0})";
  2570. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  2571. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2572. #endregion
  2573. cmd.Transaction.Commit();
  2574. return data;
  2575. }
  2576. catch (Exception ex)
  2577. {
  2578. if (cmd.Transaction != null)
  2579. cmd.Transaction.Rollback();
  2580. log.Error(ex.Message);
  2581. throw new Exception(ex.Message);
  2582. }
  2583. finally
  2584. {
  2585. if (conn.State == ConnectionState.Open)
  2586. {
  2587. conn.Close();
  2588. }
  2589. conn.Dispose();
  2590. }
  2591. }
  2592. }
  2593. private static string CheckOutsourcingIssueDoc(string Type, string Code, string WorkPoint, Dictionary<string, string> language)
  2594. {
  2595. string sql = string.Empty;
  2596. if (Type == "1")
  2597. {
  2598. sql = @"DECLARE @PickID VARCHAR(10)
  2599. SELECT @PickID=b.PickID
  2600. FROM ICSOApplyNegDetail a
  2601. INNER JOIN ICSOOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  2602. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2603. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2604. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2605. FROM ICSOApplyNegDetail a
  2606. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2607. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2608. GROUP BY b.PickID
  2609. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2610. IF (@PickID IS NOT NULL)
  2611. BEGIN
  2612. DECLARE @InvCode VARCHAR(100)
  2613. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  2614. RAISERROR(@InvCode,16,1);
  2615. RETURN
  2616. END ";
  2617. }
  2618. else if (Type == "2")
  2619. {
  2620. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  2621. SELECT @ApplyDetailID=b.ApplyDetailID
  2622. FROM ICSOApplyNegDetail a
  2623. INNER JOIN ICSOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  2624. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2625. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2626. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2627. FROM ICSOApplyNegDetail a
  2628. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2629. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2630. GROUP BY b.ApplyDetailID
  2631. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2632. IF (@ApplyDetailID IS NOT NULL)
  2633. BEGIN
  2634. DECLARE @InvCode VARCHAR(100)
  2635. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  2636. RAISERROR(@InvCode,16,1);
  2637. RETURN
  2638. END ";
  2639. }
  2640. else if (Type == "3")
  2641. {
  2642. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  2643. SELECT @IssueDetailID=b.IssueDetailID
  2644. FROM ICSOApplyNegDetail a
  2645. INNER JOIN ICSOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  2646. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2647. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  2648. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  2649. FROM ICSOApplyNegDetail a
  2650. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2651. WHERE c.OApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  2652. GROUP BY b.IssueDetailID
  2653. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  2654. IF (@IssueDetailID IS NOT NULL)
  2655. BEGIN
  2656. DECLARE @InvCode VARCHAR(100)
  2657. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  2658. RAISERROR(@InvCode,16,1);
  2659. RETURN
  2660. END ";
  2661. }
  2662. else
  2663. {
  2664. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  2665. }
  2666. sql = string.Format(sql, Code, WorkPoint, Type);
  2667. return sql;
  2668. }
  2669. /// <summary>
  2670. /// 委外退料 修改
  2671. /// </summary>
  2672. /// <param name="JsonData"></param>
  2673. /// <returns></returns>
  2674. public static DataTable OutsourcingIssueDoNegativeApplyUpdate(List<ICSOApplyNeg> JsonData)
  2675. {
  2676. var language = LanguageHelper.GetName("WMSAPIInfo");
  2677. if (JsonData.Count <= 0)
  2678. {
  2679. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2680. }
  2681. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2682. {
  2683. conn.Open();
  2684. SqlTransaction sqlTran = conn.BeginTransaction();
  2685. SqlCommand cmd = new SqlCommand();
  2686. cmd.Transaction = sqlTran;
  2687. cmd.Connection = conn;
  2688. try
  2689. {
  2690. string sql = string.Empty;
  2691. string Code = string.Empty;
  2692. string ids = string.Empty;
  2693. foreach (var item in JsonData)
  2694. {
  2695. //主表修改
  2696. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  2697. BEGIN
  2698. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  2699. RETURN
  2700. END
  2701. DECLARE @Status VARCHAR(10)
  2702. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  2703. IF (@Status IS NULL)
  2704. BEGIN
  2705. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  2706. RETURN
  2707. END
  2708. ELSE IF (@Status!='1')
  2709. BEGIN
  2710. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  2711. RETURN
  2712. END
  2713. 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}' ";
  2714. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.id, item.WorkPoint);
  2715. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2716. {
  2717. throw new Exception(language.GetNameByCode("WMSAPIInfo016"));//"委外退料单信息修改失败!");
  2718. }
  2719. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  2720. if (detail > 0)
  2721. {
  2722. sql = @"SELECT OApplyNegCode FROM ICSOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  2723. sql = string.Format(sql, item.id, item.WorkPoint);
  2724. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2725. }
  2726. foreach (var itemInfo in item.detail)
  2727. {
  2728. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  2729. {
  2730. //创建子表
  2731. sql = @"INSERT INTO ICSOApplyNegDetail(ID,OApplyNegCode,Sequence,SourceDetailID,InvCode,
  2732. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  2733. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  2734. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  2735. '{4}','{5}',0,'{6}','{7}',
  2736. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  2737. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  2738. }
  2739. else
  2740. {
  2741. //子表修改
  2742. 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}'";
  2743. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  2744. }
  2745. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2746. {
  2747. throw new Exception(language.GetNameByCode("WMSAPIInfo017"));//"委外退料单子表信息修改失败!");
  2748. }
  2749. }
  2750. //校验退料数量是否超出领料数量
  2751. sql = CheckOutsourcingIssueDoc(item.Type, Code, item.WorkPoint, language);
  2752. DBHelper.ExecuteNonQuery(sql, cmd);
  2753. ids += "'" + item.id + "',";
  2754. }
  2755. if (string.IsNullOrWhiteSpace(ids))
  2756. {
  2757. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  2758. }
  2759. #region 查询返回数据
  2760. sql = @"SELECT a.OApplyNegCode,
  2761. c.WHCode,
  2762. c.Memo,
  2763. d.Name AS Status,
  2764. a.Sequence,
  2765. a.InvCode,
  2766. inv.InvName,
  2767. inv.InvStd,
  2768. a.Quantity,
  2769. inv.InvUnit,
  2770. a.Amount,
  2771. inv.AmountUnit,
  2772. a.IssueNegQuantity,
  2773. ext.ProjectCode,
  2774. ext.BatchCode,
  2775. ext.Version,
  2776. ext.Brand,
  2777. ext.cFree1,
  2778. ext.cFree2,
  2779. ext.cFree3,
  2780. ext.cFree4,
  2781. ext.cFree5,
  2782. ext.cFree6,
  2783. ext.cFree7,
  2784. ext.cFree8,
  2785. ext.cFree9,
  2786. ext.cFree10,
  2787. a.MUSER AS [User],
  2788. a.MTIME AS [MTime]
  2789. FROM ICSOApplyNegDetail a
  2790. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2791. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  2792. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2793. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2794. WHERE c.ID IN ({0})";
  2795. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  2796. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2797. #endregion
  2798. cmd.Transaction.Commit();
  2799. return data;
  2800. }
  2801. catch (Exception ex)
  2802. {
  2803. if (cmd.Transaction != null)
  2804. cmd.Transaction.Rollback();
  2805. log.Error(ex.Message);
  2806. throw new Exception(ex.Message);
  2807. }
  2808. finally
  2809. {
  2810. if (conn.State == ConnectionState.Open)
  2811. {
  2812. conn.Close();
  2813. }
  2814. conn.Dispose();
  2815. }
  2816. }
  2817. }
  2818. /// <summary>
  2819. /// 委外退料审核
  2820. /// </summary>
  2821. /// <param name="JsonData"></param>
  2822. /// <returns></returns>
  2823. public static DataTable OutsourcingIssueDoNegativeApplyApprove(List<ICSUser> JsonData)
  2824. {
  2825. var language = LanguageHelper.GetName("WMSAPIInfo");
  2826. if (JsonData.Count <= 0)
  2827. {
  2828. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2829. }
  2830. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2831. {
  2832. conn.Open();
  2833. SqlTransaction sqlTran = conn.BeginTransaction();
  2834. SqlCommand cmd = new SqlCommand();
  2835. cmd.Transaction = sqlTran;
  2836. cmd.Connection = conn;
  2837. try
  2838. {
  2839. string sql = string.Empty;
  2840. string ids = string.Empty;
  2841. foreach (var item in JsonData)
  2842. {
  2843. if (string.IsNullOrEmpty(item.ID))
  2844. {
  2845. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  2846. }
  2847. if (string.IsNullOrEmpty(item.User))
  2848. {
  2849. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  2850. }
  2851. if (item.MTime <= new DateTime(2000, 1, 1))
  2852. {
  2853. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  2854. }
  2855. //获取单号
  2856. sql = @"DECLARE @Status VARCHAR(10)
  2857. SELECT @Status=Status FROM ICSOApplyNeg WHERE ID='{0}'
  2858. IF (@Status IS NULL)
  2859. BEGIN
  2860. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  2861. RETURN
  2862. END
  2863. ELSE IF (@Status!='1')
  2864. BEGIN
  2865. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  2866. RETURN
  2867. END
  2868. update ICSOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  2869. sql = string.Format(sql, item.ID, item.User, item.MTime);
  2870. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  2871. {
  2872. throw new Exception(language.GetNameByCode("WMSAPIInfo021"));//"委外退料申请单审核失败!");
  2873. }
  2874. ids += "'" + item.ID + "',";
  2875. }
  2876. if (string.IsNullOrWhiteSpace(ids))
  2877. {
  2878. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  2879. }
  2880. #region 查询返回数据
  2881. sql = @"SELECT a.OApplyNegCode,
  2882. c.WHCode,
  2883. c.Memo,
  2884. d.Name AS Status,
  2885. a.Sequence,
  2886. a.InvCode,
  2887. inv.InvName,
  2888. inv.InvStd,
  2889. a.Quantity,
  2890. inv.InvUnit,
  2891. a.Amount,
  2892. inv.AmountUnit,
  2893. a.IssueNegQuantity,
  2894. ext.ProjectCode,
  2895. ext.BatchCode,
  2896. ext.Version,
  2897. ext.Brand,
  2898. ext.cFree1,
  2899. ext.cFree2,
  2900. ext.cFree3,
  2901. ext.cFree4,
  2902. ext.cFree5,
  2903. ext.cFree6,
  2904. ext.cFree7,
  2905. ext.cFree8,
  2906. ext.cFree9,
  2907. ext.cFree10,
  2908. a.MUSER AS [User],
  2909. a.MTIME AS [MTime]
  2910. FROM ICSOApplyNegDetail a
  2911. INNER JOIN ICSOApplyNeg c ON a.OApplyNegCode=c.OApplyNegCode AND a.WorkPoint=c.WorkPoint
  2912. LEFT JOIN ICSType d ON d.TableCode='ICSOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  2913. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  2914. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  2915. WHERE c.ID IN ({0})";
  2916. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  2917. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  2918. #endregion
  2919. cmd.Transaction.Commit();
  2920. return data;
  2921. }
  2922. catch (Exception ex)
  2923. {
  2924. if (cmd.Transaction != null)
  2925. cmd.Transaction.Rollback();
  2926. log.Error(ex.Message);
  2927. throw new Exception(ex.Message);
  2928. }
  2929. finally
  2930. {
  2931. if (conn.State == ConnectionState.Open)
  2932. {
  2933. conn.Close();
  2934. }
  2935. conn.Dispose();
  2936. }
  2937. }
  2938. }
  2939. /// <summary>
  2940. /// 委外到货
  2941. /// </summary>
  2942. /// <param name="JsonData"></param>
  2943. /// <returns></returns>
  2944. public static DataTable OutsourcingDeliveryNoticeCreate(List<ICSDeliveryNotice> JsonData)
  2945. {
  2946. var language = LanguageHelper.GetName("WMSAPIInfo");
  2947. if (JsonData.Count <= 0)
  2948. {
  2949. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  2950. }
  2951. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  2952. {
  2953. conn.Open();
  2954. SqlTransaction sqlTran = conn.BeginTransaction();
  2955. SqlCommand cmd = new SqlCommand();
  2956. cmd.Transaction = sqlTran;
  2957. cmd.Connection = conn;
  2958. try
  2959. {
  2960. string asncodes = string.Empty;
  2961. string sql = string.Empty;
  2962. foreach (var item in JsonData)
  2963. {
  2964. if (string.IsNullOrEmpty(item.OASNCode))
  2965. {
  2966. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"送货单号不能为空!");
  2967. }
  2968. //获取单号
  2969. sql = @"IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.OASNCode='{0}' AND ODNType = '1' AND a.WorkPoint='{1}')
  2970. BEGIN
  2971. RAISERROR('" + language.GetNameByCode("WMSAPIInfo057") + @"',16,1);
  2972. RETURN
  2973. END
  2974. DECLARE @Status VARCHAR(10)
  2975. SELECT @Status=Status FROM ICSOASN WHERE OASNCode='{0}' and WorkPoint='{1}'
  2976. IF (@Status IS NULL)
  2977. BEGIN
  2978. RAISERROR('" + language.GetNameByCode("WMSAPIInfo058") + @"',16,1);
  2979. RETURN
  2980. END
  2981. ELSE IF (@Status!='2')
  2982. BEGIN
  2983. RAISERROR('" + language.GetNameByCode("WMSAPIInfo059") + @"',16,1);
  2984. RETURN
  2985. END
  2986. DECLARE @MaxNO INT,@date varchar(20)='ODN'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  2987. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  2988. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  2989. IF @MaxNO IS NULL
  2990. BEGIN
  2991. SELECT @date+'00001' AS Code
  2992. END
  2993. ELSE
  2994. BEGIN
  2995. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  2996. END ";
  2997. sql = string.Format(sql, item.OASNCode, item.WorkPoint);
  2998. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  2999. //修改送货单到货数量
  3000. foreach (var itemInfo in item.detail)
  3001. {
  3002. sql = @"UPDATE ICSOASNDetail SET ODNQuantity=ISNULL(ODNQuantity, 0)+'{2}'
  3003. WHERE LotNo='{0}' AND WorkPoint='{1}'";
  3004. sql = string.Format(sql, itemInfo.LotNo, item.WorkPoint, itemInfo.Quantity);
  3005. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3006. {
  3007. throw new Exception(language.GetNameByCode("WMSAPIInfo010")); //"委外送货单子表信息更新失败!");
  3008. }
  3009. }
  3010. //创建到货单信息
  3011. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{2}')
  3012. BEGIN
  3013. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  3014. RETURN
  3015. END
  3016. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3017. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3018. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3019. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3020. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3021. SELECT NEWID(),'{0}',row_number() OVER (ORDER BY b.InvCode),d.VenCode,d.DepCode,
  3022. '1',b.InvCode,SUM(a.ODNQuantity),'0','0',
  3023. d.UnitPrice,d.Currency,'2',e.F_Account,GETDATE(),
  3024. d.OOID,d.OODetailID,newid(),newid(),b.ExtensionID,
  3025. e.F_Account,e.F_RealName,GETDATE(),a.WorkPoint,'',a.OASNCode
  3026. FROM ICSOASNDetail a
  3027. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  3028. INNER JOIN ICSInventoryLotDetail c ON b.LotNo=c.LotNo AND b.WorkPoint=c.WorkPoint
  3029. INNER JOIN ICSOutsourcingOrder d ON c.TransCode=d.OOCode AND c.TransSequence=d.Sequence AND c.WorkPoint=d.WorkPoint
  3030. INNER JOIN Sys_SRM_User e ON e.F_Account='{1}' AND e.F_Location='{2}'
  3031. WHERE a.OASNCode='{3}' AND a.WorkPoint='{2}'
  3032. 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";
  3033. sql = string.Format(sql, Code, item.User, item.WorkPoint, item.OASNCode);
  3034. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3035. {
  3036. throw new Exception(language.GetNameByCode("WMSAPIInfo011")); //"到货单信息创建失败!");
  3037. }
  3038. ICSOutsourcingService.OutsourcingDeliveryNoticeERP(Code, item.WorkPoint, cmd, language);
  3039. asncodes += "'" + item.OASNCode + item.WorkPoint + "',";
  3040. }
  3041. if (string.IsNullOrWhiteSpace(asncodes))
  3042. {
  3043. throw new Exception(language.GetNameByCode("WMSAPIInfo009"));//"请传入送货单信息!");
  3044. }
  3045. #region 查询返回数据
  3046. sql = @"SELECT
  3047. n.OOCode,
  3048. n.Sequence AS OOSequence,
  3049. a.OASNCode,
  3050. a.ODNCode,
  3051. a.Sequence,
  3052. a.VenCode,
  3053. a.DepCode,
  3054. a.InvCode,
  3055. inv.InvName,
  3056. inv.InvStd,
  3057. a.Quantity,
  3058. inv.InvUnit,
  3059. a.Amount,
  3060. inv.AmountUnit,
  3061. a.RCVQuantity,
  3062. a.UnitPrice,
  3063. a.Currency,
  3064. a.OOID,
  3065. a.OODetailID,
  3066. a.ODNID,
  3067. a.ODNDetailID,
  3068. ext.ProjectCode,
  3069. ext.BatchCode,
  3070. ext.Version,
  3071. ext.Brand,
  3072. ext.cFree1,
  3073. ext.cFree2,
  3074. ext.cFree3,
  3075. ext.cFree4,
  3076. ext.cFree5,
  3077. ext.cFree6,
  3078. ext.cFree7,
  3079. ext.cFree8,
  3080. ext.cFree9,
  3081. ext.cFree10,
  3082. a.MUSER AS [User],
  3083. a.MTIME AS [MTime]
  3084. FROM ICSODeliveryNotice a
  3085. INNER JOIN ICSOutsourcingOrder n ON a.OOID =n.OOID AND a.OODetailID=n.OODetailID AND a.WorkPoint=n.WorkPoint
  3086. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3087. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3088. WHERE a.OASNCode+a.WorkPoint IN ({0})";
  3089. sql = string.Format(sql, asncodes.Substring(0, asncodes.Length - 1));
  3090. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3091. #endregion
  3092. cmd.Transaction.Commit();
  3093. return data;
  3094. }
  3095. catch (Exception ex)
  3096. {
  3097. if (cmd.Transaction != null)
  3098. cmd.Transaction.Rollback();
  3099. log.Error(ex.Message);
  3100. throw new Exception(ex.Message);
  3101. }
  3102. finally
  3103. {
  3104. if (conn.State == ConnectionState.Open)
  3105. {
  3106. conn.Close();
  3107. }
  3108. conn.Dispose();
  3109. }
  3110. }
  3111. }
  3112. /// <summary>
  3113. /// 委外拒收
  3114. /// </summary>
  3115. /// <param name="JsonData"></param>
  3116. /// <returns></returns>
  3117. public static DataTable OutsourcingRejectDocCreate(List<ICSDeliveryNotice> JsonData)
  3118. {
  3119. var language = LanguageHelper.GetName("WMSAPIInfo");
  3120. if (JsonData.Count <= 0)
  3121. {
  3122. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3123. }
  3124. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3125. {
  3126. conn.Open();
  3127. SqlTransaction sqlTran = conn.BeginTransaction();
  3128. SqlCommand cmd = new SqlCommand();
  3129. cmd.Transaction = sqlTran;
  3130. cmd.Connection = conn;
  3131. try
  3132. {
  3133. string lots = string.Empty;
  3134. string sql = string.Empty;
  3135. foreach (var item in JsonData)
  3136. {
  3137. if (string.IsNullOrEmpty(item.ODNCode))
  3138. {
  3139. throw new Exception(language.GetNameByCode("WMSAPIInfo012"));//"到货单号不能为空!");
  3140. }
  3141. //获取单号
  3142. sql = @"DECLARE @Status VARCHAR(10)
  3143. SELECT @Status=Status FROM ICSODeliveryNotice WHERE ODNCode='{0}' and ODNType='1' and WorkPoint='{1}'
  3144. IF (@Status IS NULL)
  3145. BEGIN
  3146. RAISERROR('" + language.GetNameByCode("WMSAPIInfo061") + @"',16,1);
  3147. RETURN
  3148. END
  3149. ELSE IF (@Status!='2')
  3150. BEGIN
  3151. RAISERROR('" + language.GetNameByCode("WMSAPIInfo062") + @"',16,1);
  3152. RETURN
  3153. END
  3154. DECLARE @MaxNO INT,@date varchar(20)='ORJT'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3155. SELECT @MaxNO=SUBSTRING(MAX(ODNCode),LEN(@date)+1,LEN(MAX(ODNCode))-LEN(@date))+1 FROM ICSODeliveryNotice
  3156. WHERE SUBSTRING(ODNCode, 1, LEN(@date))=@date
  3157. IF @MaxNO IS NULL
  3158. BEGIN
  3159. SELECT @date+'00001' AS Code
  3160. END
  3161. ELSE
  3162. BEGIN
  3163. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3164. END ";
  3165. sql = string.Format(sql, item.ODNCode, item.WorkPoint);
  3166. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3167. //修改送货单到货数量
  3168. foreach (var itemInfo in item.detail)
  3169. {
  3170. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{3}' AND F_Location='{2}')
  3171. BEGIN
  3172. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{3}") + @"',16,1);
  3173. RETURN
  3174. END
  3175. IF EXISTS(SELECT a.ID FROM ICSODeliveryNotice a WHERE a.EATTRIBUTE1='{1}' AND ODNType = '3' AND a.WorkPoint='{2}')
  3176. BEGIN
  3177. RAISERROR('" + language.GetNameByCode("WMSAPIInfo063") + @"',16,1);
  3178. RETURN
  3179. END
  3180. INSERT INTO ICSODeliveryNotice(ID,ODNCode,Sequence,VenCode,DepCode,
  3181. ODNType,InvCode,Quantity,Amount,RCVQuantity,
  3182. UnitPrice,Currency,Status,CreatePerson,CreateDateTime,
  3183. OOID,OODetailID,ODNID,ODNDetailID,ExtensionID,
  3184. MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1,OASNCode)
  3185. SELECT NEWID(),'{4}', '{11}', '{5}', '{6}',
  3186. '3',d.InvCode,'{7}', '{8}', 0,
  3187. '{9}', '{10}', '2', e.F_Account, SYSDATETIME(),
  3188. a.ODNID,a.ODNDetailID, '0', '0', a.ExtensionID,
  3189. e.F_Account,e.F_RealName, SYSDATETIME(), a.WorkPoint, b.LOTNO,''
  3190. FROM ICSODeliveryNotice a
  3191. INNER JOIN ICSOASNDetail b ON a.OASNCode=b.OASNCode AND a.WorkPoint=b.WorkPoint
  3192. INNER JOIN ICSInventoryLot d ON b.LotNo=d.LotNo AND a.InvCode=d.InvCode AND b.WorkPoint=d.WorkPoint
  3193. INNER JOIN ICSInventoryLotDetail m on d.LotNo=m.LotNo and d.WorkPoint=m.WorkPoint
  3194. INNER JOIN ICSOutsourcingOrder n ON m.TransCode =n.OOCode AND m.TransSequence=n.Sequence AND a.OODetailID=n.OODetailID AND m.WorkPoint=n.WorkPoint
  3195. INNER JOIN ICSInspection h ON h.LotNo=b.LotNo AND h.WorkPoint=b.WorkPoint
  3196. INNER JOIN Sys_SRM_User e ON e.F_Account='{3}' AND e.F_Location='{2}'
  3197. WHERE a.ODNCode='{0}' and b.LOTNO='{1}' AND a.WorkPoint='{2}'";
  3198. 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);
  3199. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3200. {
  3201. throw new Exception(language.GetNameByCode("WMSAPIInfo013"));//"拒收单创建失败!");
  3202. }
  3203. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  3204. }
  3205. }
  3206. if (string.IsNullOrWhiteSpace(lots))
  3207. {
  3208. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  3209. }
  3210. #region 查询返回数据
  3211. sql = @"SELECT
  3212. n.ODNCode,
  3213. n.Sequence,
  3214. a.ODNCode AS RJTCode,
  3215. a.Sequence AS RJTSequence,
  3216. a.VenCode,
  3217. a.DepCode,
  3218. a.InvCode,
  3219. inv.InvName,
  3220. inv.InvStd,
  3221. a.Quantity,
  3222. inv.InvUnit,
  3223. a.Amount,
  3224. inv.AmountUnit,
  3225. a.RCVQuantity,
  3226. a.UnitPrice,
  3227. a.Currency,
  3228. a.OOID,
  3229. a.OODetailID,
  3230. a.ODNID,
  3231. a.ODNDetailID,
  3232. ext.ProjectCode,
  3233. ext.BatchCode,
  3234. ext.Version,
  3235. ext.Brand,
  3236. ext.cFree1,
  3237. ext.cFree2,
  3238. ext.cFree3,
  3239. ext.cFree4,
  3240. ext.cFree5,
  3241. ext.cFree6,
  3242. ext.cFree7,
  3243. ext.cFree8,
  3244. ext.cFree9,
  3245. ext.cFree10,
  3246. a.MUSER AS [User],
  3247. a.MTIME AS [MTime]
  3248. FROM ICSODeliveryNotice a
  3249. INNER JOIN ICSODeliveryNotice n ON a.OOID =n.ODNID AND a.OODetailID=n.ODNDetailID AND a.WorkPoint=n.WorkPoint
  3250. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3251. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3252. WHERE a.EATTRIBUTE1+a.WorkPoint IN ({0})";
  3253. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  3254. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3255. #endregion
  3256. cmd.Transaction.Commit();
  3257. return data;
  3258. }
  3259. catch (Exception ex)
  3260. {
  3261. if (cmd.Transaction != null)
  3262. cmd.Transaction.Rollback();
  3263. log.Error(ex.Message);
  3264. throw new Exception(ex.Message);
  3265. }
  3266. finally
  3267. {
  3268. if (conn.State == ConnectionState.Open)
  3269. {
  3270. conn.Close();
  3271. }
  3272. conn.Dispose();
  3273. }
  3274. }
  3275. }
  3276. #endregion
  3277. #region 生产
  3278. /// <summary>
  3279. /// 生产退料 新建
  3280. /// </summary>
  3281. /// <param name="JsonData"></param>
  3282. /// <returns></returns>
  3283. public static DataTable MOIssueDocNegativeApplyCreate(List<ICSMOApplyNeg> JsonData)
  3284. {
  3285. var language = LanguageHelper.GetName("WMSAPIInfo");
  3286. if (JsonData.Count <= 0)
  3287. {
  3288. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3289. }
  3290. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3291. {
  3292. conn.Open();
  3293. SqlTransaction sqlTran = conn.BeginTransaction();
  3294. SqlCommand cmd = new SqlCommand();
  3295. cmd.Transaction = sqlTran;
  3296. cmd.Connection = conn;
  3297. try
  3298. {
  3299. string codes = string.Empty;
  3300. string sql = string.Empty;
  3301. foreach (var item in JsonData)
  3302. {
  3303. //获取单号
  3304. sql = @"DECLARE @MaxNO INT,@date varchar(20)='MOIA'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  3305. SELECT @MaxNO=SUBSTRING(MAX(ApplyNegCode),LEN(@date)+1,LEN(MAX(ApplyNegCode))-LEN(@date))+1 FROM ICSMOApplyNeg
  3306. WHERE SUBSTRING(ApplyNegCode, 1, LEN(@date))=@date
  3307. IF @MaxNO IS NULL
  3308. BEGIN
  3309. SELECT @date+'00001' AS Code
  3310. END
  3311. ELSE
  3312. BEGIN
  3313. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  3314. END ";
  3315. string Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3316. //创建主表
  3317. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{2}' AND F_Location='{4}')
  3318. BEGIN
  3319. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{2}") + @"',16,1);
  3320. RETURN
  3321. END
  3322. INSERT INTO ICSMOApplyNeg(ID,ApplyNegCode,WHCode,Status,Type,Memo,CreatePerson,CreateDateTime,MUSER,MUSERName,MTIME,WorkPoint,EATTRIBUTE1)
  3323. 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}','')";
  3324. sql = string.Format(sql, Code, item.WHCode, item.User, item.MTime, item.WorkPoint, item.Type);
  3325. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3326. {
  3327. throw new Exception(language.GetNameByCode("WMSAPIInfo022"));//"生产退料单信息创建失败!");
  3328. }
  3329. foreach (var itemInfo in item.detail)
  3330. {
  3331. //创建子表
  3332. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,
  3333. Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3334. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3335. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3336. '{4}','{5}',0,'{6}','{7}',
  3337. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3338. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3339. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3340. {
  3341. throw new Exception(language.GetNameByCode("WMSAPIInfo023"));//"生产退料单子表信息创建失败!");
  3342. }
  3343. }
  3344. //校验退料数量是否超出领料数量
  3345. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  3346. DBHelper.ExecuteNonQuery(sql, cmd);
  3347. codes += "'" + Code + item.WorkPoint + "',";
  3348. }
  3349. if (string.IsNullOrWhiteSpace(codes))
  3350. {
  3351. throw new Exception(language.GetNameByCode("WMSAPIInfo001"));//"单据号不能为空!"
  3352. }
  3353. #region 查询返回数据
  3354. sql = @"SELECT a.ApplyNegCode,
  3355. c.WHCode,
  3356. c.Memo,
  3357. d.Name AS Status,
  3358. a.Sequence,
  3359. a.InvCode,
  3360. inv.InvName,
  3361. inv.InvStd,
  3362. a.Quantity,
  3363. inv.InvUnit,
  3364. a.Amount,
  3365. inv.AmountUnit,
  3366. a.IssueNegQuantity,
  3367. ext.ProjectCode,
  3368. ext.BatchCode,
  3369. ext.Version,
  3370. ext.Brand,
  3371. ext.cFree1,
  3372. ext.cFree2,
  3373. ext.cFree3,
  3374. ext.cFree4,
  3375. ext.cFree5,
  3376. ext.cFree6,
  3377. ext.cFree7,
  3378. ext.cFree8,
  3379. ext.cFree9,
  3380. ext.cFree10,
  3381. a.MUSER AS [User],
  3382. a.MTIME AS [MTime]
  3383. FROM ICSMOApplyNegDetail a
  3384. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3385. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3386. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3387. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3388. WHERE a.ApplyNegCode+a.WorkPoint IN ({0})";
  3389. sql = string.Format(sql, codes.Substring(0, codes.Length - 1));
  3390. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3391. #endregion
  3392. cmd.Transaction.Commit();
  3393. return data;
  3394. }
  3395. catch (Exception ex)
  3396. {
  3397. if (cmd.Transaction != null)
  3398. cmd.Transaction.Rollback();
  3399. log.Error(ex.Message);
  3400. throw new Exception(ex.Message);
  3401. }
  3402. finally
  3403. {
  3404. if (conn.State == ConnectionState.Open)
  3405. {
  3406. conn.Close();
  3407. }
  3408. conn.Dispose();
  3409. }
  3410. }
  3411. }
  3412. private static string CheckMOIssueDoc(string Type, string ID, string WorkPoint, Dictionary<string, string> language)
  3413. {
  3414. string sql = string.Empty;
  3415. if (Type == "1")
  3416. {
  3417. sql = @"DECLARE @PickID VARCHAR(10)
  3418. SELECT @PickID=b.PickID
  3419. FROM ICSMOApplyNegDetail a
  3420. INNER JOIN ICSMOPick b ON a.SourceDetailID=b.PickID AND a.WorkPoint=b.WorkPoint
  3421. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3422. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3423. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3424. FROM ICSMOApplyNegDetail a
  3425. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3426. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3427. GROUP BY b.PickID
  3428. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3429. IF (@PickID IS NOT NULL)
  3430. BEGIN
  3431. DECLARE @InvCode VARCHAR(100)
  3432. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOPick WHERE PickID=@PickID AND WorkPoint='{1}'
  3433. RAISERROR(@InvCode,16,1);
  3434. RETURN
  3435. END ";
  3436. }
  3437. else if (Type == "2")
  3438. {
  3439. sql = @"DECLARE @ApplyDetailID VARCHAR(10)
  3440. SELECT @ApplyDetailID=b.ApplyDetailID
  3441. FROM ICSMOApplyNegDetail a
  3442. INNER JOIN ICSMOApply b ON a.SourceDetailID=b.ApplyDetailID AND a.WorkPoint=b.WorkPoint
  3443. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3444. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3445. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3446. FROM ICSMOApplyNegDetail a
  3447. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3448. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3449. GROUP BY b.ApplyDetailID
  3450. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3451. IF (@ApplyDetailID IS NOT NULL)
  3452. BEGIN
  3453. DECLARE @InvCode VARCHAR(100)
  3454. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOApply WHERE ApplyDetailID=@ApplyDetailID AND WorkPoint='{1}'
  3455. RAISERROR(@InvCode,16,1);
  3456. RETURN
  3457. END ";
  3458. }
  3459. else if (Type == "3")
  3460. {
  3461. sql = @"DECLARE @IssueDetailID VARCHAR(10)
  3462. SELECT @IssueDetailID=b.IssueDetailID
  3463. FROM ICSMOApplyNegDetail a
  3464. INNER JOIN ICSMOIssue b ON a.SourceDetailID=b.IssueDetailID AND a.WorkPoint=b.WorkPoint
  3465. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3466. WHERE c.Type='{2}' AND a.WorkPoint='{1}'
  3467. AND a.SourceDetailID IN (SELECT a.SourceDetailID
  3468. FROM ICSMOApplyNegDetail a
  3469. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3470. WHERE c.ApplyNegCode='{0}' AND c.Type='{2}' AND a.WorkPoint='{1}')
  3471. GROUP BY b.IssueDetailID
  3472. HAVING MAX(b.Quantity)<SUM(a.Quantity)
  3473. IF (@IssueDetailID IS NOT NULL)
  3474. BEGIN
  3475. DECLARE @InvCode VARCHAR(100)
  3476. SELECT @InvCode='" + language.GetNameByCode("WMSAPIInfo064") + @"' FROM ICSMOIssue WHERE IssueDetailID=@IssueDetailID AND WorkPoint='{1}'
  3477. RAISERROR(@InvCode,16,1);
  3478. RETURN
  3479. END ";
  3480. }
  3481. else
  3482. {
  3483. throw new Exception(language.GetNameByCode("WMSAPIInfo003"));//"类型不符!");
  3484. }
  3485. sql = string.Format(sql, ID, WorkPoint, Type);
  3486. return sql;
  3487. }
  3488. /// <summary>
  3489. /// 生产退料 修改
  3490. /// </summary>
  3491. /// <param name="JsonData"></param>
  3492. /// <returns></returns>
  3493. public static DataTable MOIssueDocNegativeApplyUpdate(List<ICSMOApplyNeg> JsonData)
  3494. {
  3495. var language = LanguageHelper.GetName("WMSAPIInfo");
  3496. if (JsonData.Count <= 0)
  3497. {
  3498. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3499. }
  3500. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3501. {
  3502. conn.Open();
  3503. SqlTransaction sqlTran = conn.BeginTransaction();
  3504. SqlCommand cmd = new SqlCommand();
  3505. cmd.Transaction = sqlTran;
  3506. cmd.Connection = conn;
  3507. try
  3508. {
  3509. string sql = string.Empty;
  3510. string Code = string.Empty;
  3511. string ids = string.Empty;
  3512. foreach (var item in JsonData)
  3513. {
  3514. //主表修改
  3515. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{1}' AND F_Location='{4}')
  3516. BEGIN
  3517. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo060"), "{1}") + @"',16,1);
  3518. RETURN
  3519. END
  3520. DECLARE @Status VARCHAR(10)
  3521. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{3}' and WorkPoint='{4}'
  3522. IF (@Status IS NULL)
  3523. BEGIN
  3524. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo065"), "{3}") + @"',16,1);
  3525. RETURN
  3526. END
  3527. ELSE IF (@Status!='1')
  3528. BEGIN
  3529. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo066"), "{3}") + @"',16,1);
  3530. RETURN
  3531. END
  3532. 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}' ";
  3533. sql = string.Format(sql, item.WHCode, item.User, item.MTime, item.ID, item.WorkPoint);
  3534. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3535. {
  3536. throw new Exception(language.GetNameByCode("WMSAPIInfo024"));//"生产退料单信息修改失败!");
  3537. }
  3538. var detail = item.detail.Where(a => a.DetailID.Length <= 0).Count();
  3539. if (detail > 0)
  3540. {
  3541. sql = @"SELECT ApplyNegCode FROM ICSMOApplyNeg where ID='{0}' and WorkPoint='{1}'";
  3542. sql = string.Format(sql, item.ID, item.WorkPoint);
  3543. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  3544. }
  3545. foreach (var itemInfo in item.detail)
  3546. {
  3547. if (string.IsNullOrWhiteSpace(itemInfo.DetailID))
  3548. {
  3549. //创建子表
  3550. sql = @"INSERT INTO ICSMOApplyNegDetail(ID,ApplyNegCode,Sequence,SourceDetailID,InvCode,Quantity,Amount,IssueNegQuantity,ExtensionID,MUSER,
  3551. MUSERName,MTIME,WorkPoint,EATTRIBUTE)
  3552. VALUES (NEWID(),'{0}','{1}','{2}','{3}',
  3553. '{4}','{5}',0,'{6}','{7}',
  3554. (select F_RealName from Sys_SRM_User where F_Account='{7}' and F_Location='{8}'),SYSDATETIME(),'{8}','')";
  3555. sql = string.Format(sql, Code, itemInfo.Sequence, itemInfo.SourceDetailID, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.ExtensionID, item.User, item.WorkPoint);
  3556. }
  3557. else
  3558. {
  3559. //子表修改
  3560. 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}'";
  3561. sql = string.Format(sql, itemInfo.InvCode, itemInfo.Quantity, itemInfo.Amount, itemInfo.SourceDetailID, itemInfo.DetailID, item.WorkPoint, item.User);
  3562. }
  3563. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3564. {
  3565. throw new Exception(language.GetNameByCode("WMSAPIInfo025"));//"生产退料单子表信息修改失败!");
  3566. }
  3567. }
  3568. //校验退料数量是否超出领料数量
  3569. sql = CheckMOIssueDoc(item.Type, item.ID, item.WorkPoint, language);
  3570. DBHelper.ExecuteNonQuery(sql, cmd);
  3571. ids += "'" + item.ID + "',";
  3572. }
  3573. if (string.IsNullOrWhiteSpace(ids))
  3574. {
  3575. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3576. }
  3577. #region 查询返回数据
  3578. sql = @"SELECT a.ApplyNegCode,
  3579. c.WHCode,
  3580. c.Memo,
  3581. d.Name AS Status,
  3582. a.Sequence,
  3583. a.InvCode,
  3584. inv.InvName,
  3585. inv.InvStd,
  3586. a.Quantity,
  3587. inv.InvUnit,
  3588. a.Amount,
  3589. inv.AmountUnit,
  3590. a.IssueNegQuantity,
  3591. ext.ProjectCode,
  3592. ext.BatchCode,
  3593. ext.Version,
  3594. ext.Brand,
  3595. ext.cFree1,
  3596. ext.cFree2,
  3597. ext.cFree3,
  3598. ext.cFree4,
  3599. ext.cFree5,
  3600. ext.cFree6,
  3601. ext.cFree7,
  3602. ext.cFree8,
  3603. ext.cFree9,
  3604. ext.cFree10,
  3605. a.MUSER AS [User],
  3606. a.MTIME AS [MTime]
  3607. FROM ICSMOApplyNegDetail a
  3608. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3609. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3610. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3611. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3612. WHERE c.ID IN ({0})";
  3613. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3614. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3615. #endregion
  3616. cmd.Transaction.Commit();
  3617. return data;
  3618. }
  3619. catch (Exception ex)
  3620. {
  3621. if (cmd.Transaction != null)
  3622. cmd.Transaction.Rollback();
  3623. log.Error(ex.Message);
  3624. throw new Exception(ex.Message);
  3625. }
  3626. finally
  3627. {
  3628. if (conn.State == ConnectionState.Open)
  3629. {
  3630. conn.Close();
  3631. }
  3632. conn.Dispose();
  3633. }
  3634. }
  3635. }
  3636. /// <summary>
  3637. /// 生产退料审核
  3638. /// </summary>
  3639. /// <param name="JsonData"></param>
  3640. /// <returns></returns>
  3641. public static DataTable MOIssueDocNegativeApplyApprove(List<ICSUser> JsonData)
  3642. {
  3643. var language = LanguageHelper.GetName("WMSAPIInfo");
  3644. if (JsonData.Count <= 0)
  3645. {
  3646. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3647. }
  3648. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3649. {
  3650. conn.Open();
  3651. SqlTransaction sqlTran = conn.BeginTransaction();
  3652. SqlCommand cmd = new SqlCommand();
  3653. cmd.Transaction = sqlTran;
  3654. cmd.Connection = conn;
  3655. try
  3656. {
  3657. string sql = string.Empty;
  3658. string ids = string.Empty;
  3659. foreach (var item in JsonData)
  3660. {
  3661. if (string.IsNullOrEmpty(item.ID))
  3662. {
  3663. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"单据ID不能为空!");
  3664. }
  3665. if (string.IsNullOrEmpty(item.User))
  3666. {
  3667. throw new Exception(language.GetNameByCode("WMSAPIInfo019"));//"操作人不能为空!");
  3668. }
  3669. if (item.MTime <= new DateTime(2000, 1, 1))
  3670. {
  3671. throw new Exception(language.GetNameByCode("WMSAPIInfo020"));//"操作时间不能为空!");
  3672. }
  3673. //获取单号
  3674. sql = @"DECLARE @Status VARCHAR(10)
  3675. SELECT @Status=Status FROM ICSMOApplyNeg WHERE ID='{0}'
  3676. IF (@Status IS NULL)
  3677. BEGIN
  3678. RAISERROR('" + language.GetNameByCode("WMSAPIInfo065") + @"',16,1);
  3679. RETURN
  3680. END
  3681. ELSE IF (@Status!='1')
  3682. BEGIN
  3683. RAISERROR('" + language.GetNameByCode("WMSAPIInfo066") + @"',16,1);
  3684. RETURN
  3685. END
  3686. update ICSMOApplyNeg set Status='2',MUSER='{1}',MTIME='{2}' where ID='{0}'";
  3687. sql = string.Format(sql, item.ID, item.User, item.MTime);
  3688. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  3689. {
  3690. throw new Exception(language.GetNameByCode("WMSAPIInfo026"));//"生产退料申请单审核失败!");
  3691. }
  3692. ids += "'" + item.ID + "',";
  3693. }
  3694. if (string.IsNullOrWhiteSpace(ids))
  3695. {
  3696. throw new Exception(language.GetNameByCode("WMSAPIInfo006"));//"ID不能为空!"
  3697. }
  3698. #region 查询返回数据
  3699. sql = @"SELECT a.ApplyNegCode,
  3700. c.WHCode,
  3701. c.Memo,
  3702. d.Name AS Status,
  3703. a.Sequence,
  3704. a.InvCode,
  3705. inv.InvName,
  3706. inv.InvStd,
  3707. a.Quantity,
  3708. inv.InvUnit,
  3709. a.Amount,
  3710. inv.AmountUnit,
  3711. a.IssueNegQuantity,
  3712. ext.ProjectCode,
  3713. ext.BatchCode,
  3714. ext.Version,
  3715. ext.Brand,
  3716. ext.cFree1,
  3717. ext.cFree2,
  3718. ext.cFree3,
  3719. ext.cFree4,
  3720. ext.cFree5,
  3721. ext.cFree6,
  3722. ext.cFree7,
  3723. ext.cFree8,
  3724. ext.cFree9,
  3725. ext.cFree10,
  3726. a.MUSER AS [User],
  3727. a.MTIME AS [MTime]
  3728. FROM ICSMOApplyNegDetail a
  3729. INNER JOIN ICSMOApplyNeg c ON a.ApplyNegCode=c.ApplyNegCode AND a.WorkPoint=c.WorkPoint
  3730. LEFT JOIN ICSType d ON d.TableCode='ICSMOApplyNeg' AND d.ColumnCode='Status' AND c.Status=d.Code AND c.WorkPoint=d.WorkPoint
  3731. INNER JOIN ICSExtension ext ON a.ExtensionID=ext.ID AND a.WorkPoint=ext.WorkPoint
  3732. INNER JOIN ICSInventory inv ON a.InvCode=inv.InvCode AND a.WorkPoint=inv.WorkPoint
  3733. WHERE c.ID IN ({0})";
  3734. sql = string.Format(sql, ids.Substring(0, ids.Length - 1));
  3735. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  3736. #endregion
  3737. cmd.Transaction.Commit();
  3738. return data;
  3739. }
  3740. catch (Exception ex)
  3741. {
  3742. if (cmd.Transaction != null)
  3743. cmd.Transaction.Rollback();
  3744. log.Error(ex.Message);
  3745. throw new Exception(ex.Message);
  3746. }
  3747. finally
  3748. {
  3749. if (conn.State == ConnectionState.Open)
  3750. {
  3751. conn.Close();
  3752. }
  3753. conn.Dispose();
  3754. }
  3755. }
  3756. }
  3757. #endregion
  3758. #region 一步调拨
  3759. /// <summary>
  3760. /// 一步调拨
  3761. /// </summary>
  3762. /// <param name="JsonData"></param>
  3763. /// <returns></returns>
  3764. public static DataTable OneStepTransferDocIn(List<TransferDoc> JsonData)
  3765. {
  3766. var language = LanguageHelper.GetName("WMSAPIInfo");
  3767. if (JsonData.Count <= 0)
  3768. {
  3769. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3770. }
  3771. DataTable printTable = new DataTable();
  3772. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3773. {
  3774. conn.Open();
  3775. SqlTransaction sqlTran = conn.BeginTransaction();
  3776. SqlCommand cmd = new SqlCommand();
  3777. cmd.Transaction = sqlTran;
  3778. cmd.Connection = conn;
  3779. try
  3780. {
  3781. string sql = string.Empty;
  3782. string Identification = Guid.NewGuid().ToString();
  3783. foreach (var item in JsonData)
  3784. {
  3785. if (string.IsNullOrEmpty(item.TransCode))
  3786. {
  3787. throw new Exception(language.GetNameByCode("WMSAPIInfo027"));//"调拨单号不能为空!");
  3788. }
  3789. string[] trans = item.TransCode.Split('~');
  3790. string MergeID = "";
  3791. if (trans.Length == 2)
  3792. {
  3793. MergeID = trans[0];
  3794. item.TransCode = trans[1];
  3795. }
  3796. //验证信息
  3797. sql = @"DECLARE @Status VARCHAR(10)
  3798. SELECT @Status=Status FROM ICSTransfer WHERE TransferNO='{0}' and WorkPoint='{1}' AND Type = '1'
  3799. IF (@Status IS NULL)
  3800. BEGIN
  3801. RAISERROR('" + language.GetNameByCode("WMSAPIInfo067") + @"',16,1);
  3802. RETURN
  3803. END
  3804. ELSE IF (@Status!='1')
  3805. BEGIN
  3806. RAISERROR('" + language.GetNameByCode("WMSAPIInfo068") + @"',16,1);
  3807. RETURN
  3808. END";
  3809. sql = string.Format(sql, item.TransCode, item.WorkPoint);
  3810. DBHelper.ExecuteNonQuery(sql, cmd);
  3811. foreach (var itemInfo in item.Detail)
  3812. {
  3813. //验证仓库库位信息
  3814. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  3815. BEGIN
  3816. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  3817. RETURN
  3818. END
  3819. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  3820. BEGIN
  3821. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  3822. RETURN
  3823. END
  3824. IF NOT EXISTS(SELECT a.ID
  3825. FROM ICSWareHouse a
  3826. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  3827. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  3828. BEGIN
  3829. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  3830. RETURN
  3831. END";
  3832. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  3833. DBHelper.ExecuteNonQuery(sql, cmd);
  3834. //更新源头单据信息
  3835. ICSWareHouseService.OneStepTransferDocIn(item.TransCode, item.TransSequence, item.WorkPoint, itemInfo.CurrentQuantity, cmd, language);
  3836. //更新条码信息
  3837. printTable=ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  3838. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.OneStepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  3839. }
  3840. }
  3841. ICSWareHouseService.OneStepTransferDocInERP(TransTypeEnum.OneStepTransferDocIn.GetDescription(), Identification, cmd, language);
  3842. if (!printTable.Equals("{}"))
  3843. {
  3844. cmd.Transaction.Commit();
  3845. return printTable;
  3846. }
  3847. else
  3848. {
  3849. DataTable table = GetData(Identification, 3, cmd);
  3850. cmd.Transaction.Commit();
  3851. return table;
  3852. }
  3853. }
  3854. catch (Exception ex)
  3855. {
  3856. if (cmd.Transaction != null)
  3857. cmd.Transaction.Rollback();
  3858. log.Error(ex.Message);
  3859. throw new Exception(ex.Message);
  3860. }
  3861. finally
  3862. {
  3863. if (conn.State == ConnectionState.Open)
  3864. {
  3865. conn.Close();
  3866. }
  3867. conn.Dispose();
  3868. }
  3869. }
  3870. }
  3871. #endregion
  3872. #region 调拨
  3873. /// <summary>
  3874. /// 调拨
  3875. /// </summary>
  3876. /// <param name="JsonData"></param>
  3877. /// <returns></returns>
  3878. public static DataTable TransferDocCreate(List<TransferDoc> JsonData)
  3879. {
  3880. var language = LanguageHelper.GetName("WMSAPIInfo");
  3881. if (JsonData.Count <= 0)
  3882. {
  3883. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3884. }
  3885. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3886. {
  3887. conn.Open();
  3888. SqlTransaction sqlTran = conn.BeginTransaction();
  3889. SqlCommand cmd = new SqlCommand();
  3890. cmd.Transaction = sqlTran;
  3891. cmd.Connection = conn;
  3892. try
  3893. {
  3894. string sql = string.Empty;
  3895. string Identification = Guid.NewGuid().ToString();
  3896. foreach (var item in JsonData)
  3897. {
  3898. string MergeID = "";
  3899. foreach (var itemInfo in item.Detail)
  3900. {
  3901. //验证仓库库位信息
  3902. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  3903. BEGIN
  3904. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  3905. RETURN
  3906. END
  3907. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  3908. BEGIN
  3909. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo070"), "{2}") + @"',16,1);
  3910. RETURN
  3911. END
  3912. IF NOT EXISTS(SELECT a.ID
  3913. FROM ICSWareHouse a
  3914. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  3915. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  3916. BEGIN
  3917. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  3918. RETURN
  3919. END";
  3920. sql = string.Format(sql, itemInfo.WarehouseCode, item.WorkPoint, itemInfo.LocationCode);
  3921. DBHelper.ExecuteNonQuery(sql, cmd);
  3922. //更新条码信息
  3923. ICSWareHouseLotInfoService.WareHouseLotInfoTransfer(Identification, item.TransCode, item.TransSequence, itemInfo.WarehouseCode, itemInfo.LocationCode,
  3924. itemInfo.LotNo, itemInfo.CurrentQuantity, item.User, item.WorkPoint, "6", TransTypeEnum.StepTransferDocIn.GetDescription<DBValue>(), cmd, language, MergeID);
  3925. }
  3926. }
  3927. ICSWareHouseService.StepTransferDocInERP(TransTypeEnum.StepTransferDocIn.GetDescription(), Identification, cmd, language);
  3928. DataTable table = GetData(Identification, 3, cmd);
  3929. cmd.Transaction.Commit();
  3930. return table;
  3931. }
  3932. catch (Exception ex)
  3933. {
  3934. if (cmd.Transaction != null)
  3935. cmd.Transaction.Rollback();
  3936. log.Error(ex.Message);
  3937. throw new Exception(ex.Message);
  3938. }
  3939. finally
  3940. {
  3941. if (conn.State == ConnectionState.Open)
  3942. {
  3943. conn.Close();
  3944. }
  3945. conn.Dispose();
  3946. }
  3947. }
  3948. }
  3949. #endregion
  3950. #region 移库
  3951. /// <summary>
  3952. /// 移库
  3953. /// </summary>
  3954. /// <param name="JsonData"></param>
  3955. /// <returns></returns>
  3956. public static DataTable LibraryUpdate(List<ICSLibraryModel> JsonData)
  3957. {
  3958. var language = LanguageHelper.GetName("WMSAPIInfo");
  3959. if (JsonData.Count <= 0)
  3960. {
  3961. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  3962. }
  3963. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  3964. {
  3965. conn.Open();
  3966. SqlTransaction sqlTran = conn.BeginTransaction();
  3967. SqlCommand cmd = new SqlCommand();
  3968. cmd.Transaction = sqlTran;
  3969. cmd.Connection = conn;
  3970. try
  3971. {
  3972. string sql = string.Empty;
  3973. string Identification = Guid.NewGuid().ToString();
  3974. foreach (var item in JsonData)
  3975. {
  3976. if (string.IsNullOrEmpty(item.LotNo))
  3977. {
  3978. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  3979. }
  3980. //验证仓库库位信息
  3981. sql = @"IF NOT EXISTS(SELECT a.ID FROM ICSWareHouse a WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}')
  3982. BEGIN
  3983. RAISERROR('" + language.GetNameByCode("WMSAPIInfo069") + @"',16,1);
  3984. RETURN
  3985. END
  3986. IF NOT EXISTS(SELECT a.ID FROM ICSLocation a WHERE a.LocationCode='{2}' AND a.WorkPoint='{1}')
  3987. BEGIN
  3988. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  3989. RETURN
  3990. END
  3991. IF NOT EXISTS(SELECT a.ID
  3992. FROM ICSWareHouse a
  3993. INNER JOIN ICSLocation b ON a.ID=b.WHID AND a.WorkPoint=b.WorkPoint
  3994. WHERE a.WarehouseCode='{0}' AND a.WorkPoint='{1}' AND b.LocationCode='{2}')
  3995. BEGIN
  3996. RAISERROR('" + language.GetNameByCode("WMSAPIInfo071") + @"',16,1);
  3997. RETURN
  3998. END";
  3999. sql = string.Format(sql, item.WarehouseCode, item.WorkPoint, item.LocationCode);
  4000. DBHelper.ExecuteNonQuery(sql, cmd);
  4001. //更新条码信息
  4002. ICSWareHouseLotInfoService.WareHouseLotInfoLibrary(Identification, item.TransCode, item.TransSequence, item.WarehouseCode, item.LocationCode, item.LotNo,
  4003. item.User, item.WorkPoint, "7", "29", cmd, language);
  4004. }
  4005. DataTable table = GetData(Identification, 3, cmd);
  4006. cmd.Transaction.Commit();
  4007. return table;
  4008. }
  4009. catch (Exception ex)
  4010. {
  4011. if (cmd.Transaction != null)
  4012. cmd.Transaction.Rollback();
  4013. log.Error(ex.Message);
  4014. throw new Exception(ex.Message);
  4015. }
  4016. finally
  4017. {
  4018. if (conn.State == ConnectionState.Open)
  4019. {
  4020. conn.Close();
  4021. }
  4022. conn.Dispose();
  4023. }
  4024. }
  4025. }
  4026. #endregion
  4027. #region 合并
  4028. /// <summary>
  4029. /// 合并
  4030. /// </summary>
  4031. /// <param name="JsonData"></param>
  4032. /// <returns></returns>
  4033. public static DataTable LOTMergeCreate(List<LOTCreateIModel> JsonData)
  4034. {
  4035. var language = LanguageHelper.GetName("WMSAPIInfo");
  4036. if (JsonData.Count <= 0)
  4037. {
  4038. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4039. }
  4040. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4041. {
  4042. conn.Open();
  4043. SqlTransaction sqlTran = conn.BeginTransaction();
  4044. SqlCommand cmd = new SqlCommand();
  4045. cmd.Transaction = sqlTran;
  4046. cmd.Connection = conn;
  4047. try
  4048. {
  4049. string Identification = Guid.NewGuid().ToString();
  4050. foreach (var item in JsonData)
  4051. {
  4052. if (string.IsNullOrEmpty(item.LotNo))
  4053. {
  4054. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4055. }
  4056. else if (item.detail.Count <= 0)
  4057. {
  4058. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  4059. }
  4060. //合并前日志
  4061. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  4062. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  4063. foreach (var info in item.detail)
  4064. {
  4065. //合并前日志
  4066. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, info.CurrentLotNo, item.User, item.WorkPoint, "5",
  4067. TransTypeEnum.LOTMergeBefore.GetDescription<DBValue>(), cmd, language);
  4068. //更新条码信息
  4069. ICSWareHouseLotInfoService.WareHouseLotInfoMerge(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "5",
  4070. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  4071. }
  4072. //合并后日志
  4073. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "5",
  4074. TransTypeEnum.LOTMergeAfter.GetDescription<DBValue>(), cmd, language);
  4075. }
  4076. DataTable table = GetData(Identification, 1, cmd);
  4077. cmd.Transaction.Commit();
  4078. return table;
  4079. }
  4080. catch (Exception ex)
  4081. {
  4082. if (cmd.Transaction != null)
  4083. cmd.Transaction.Rollback();
  4084. log.Error(ex.Message);
  4085. throw new Exception(ex.Message);
  4086. }
  4087. finally
  4088. {
  4089. if (conn.State == ConnectionState.Open)
  4090. {
  4091. conn.Close();
  4092. }
  4093. conn.Dispose();
  4094. }
  4095. }
  4096. }
  4097. #endregion
  4098. #region 拆分
  4099. /// <summary>
  4100. /// 拆分
  4101. /// </summary>
  4102. /// <param name="JsonData"></param>
  4103. /// <returns></returns>
  4104. public static DataTable LOTSplitCreate(List<LOTCreateIModel> JsonData)
  4105. {
  4106. var language = LanguageHelper.GetName("WMSAPIInfo");
  4107. if (JsonData.Count <= 0)
  4108. {
  4109. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4110. }
  4111. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4112. {
  4113. conn.Open();
  4114. SqlTransaction sqlTran = conn.BeginTransaction();
  4115. SqlCommand cmd = new SqlCommand();
  4116. cmd.Transaction = sqlTran;
  4117. cmd.Connection = conn;
  4118. try
  4119. {
  4120. string Identification = Guid.NewGuid().ToString();
  4121. foreach (var item in JsonData)
  4122. {
  4123. if (string.IsNullOrEmpty(item.LotNo))
  4124. {
  4125. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"条码不能为空!"
  4126. }
  4127. else if (item.detail.Count <= 0)
  4128. {
  4129. throw new Exception(language.GetNameByCode("WMSAPIInfo028"));//"明细信息不能为空!");
  4130. }
  4131. //拆分前日志
  4132. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  4133. TransTypeEnum.LOTSplitBefore.GetDescription<DBValue>(), cmd, language);
  4134. foreach (var info in item.detail)
  4135. {
  4136. //更新条码信息
  4137. ICSWareHouseLotInfoService.WareHouseLotInfoSplit(Identification, item.LotNo, info.CurrentLotNo, info.CurrentQuantity, item.User, item.WorkPoint, "4",
  4138. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  4139. }
  4140. //拆分后日志
  4141. ICSWareHouseLotInfoService.WareHouseLotInfoLog(Identification, item.LotNo, item.User, item.WorkPoint, "4",
  4142. TransTypeEnum.LOTSplitAfter.GetDescription<DBValue>(), cmd, language);
  4143. }
  4144. DataTable table = GetData(Identification, 1, cmd);
  4145. cmd.Transaction.Commit();
  4146. return table;
  4147. }
  4148. catch (Exception ex)
  4149. {
  4150. if (cmd.Transaction != null)
  4151. cmd.Transaction.Rollback();
  4152. log.Error(ex.Message);
  4153. throw new Exception(ex.Message);
  4154. }
  4155. finally
  4156. {
  4157. if (conn.State == ConnectionState.Open)
  4158. {
  4159. conn.Close();
  4160. }
  4161. conn.Dispose();
  4162. }
  4163. }
  4164. }
  4165. #endregion
  4166. /// <summary>
  4167. /// 获取出入库记录信息
  4168. /// </summary>
  4169. /// <param name="Identification"></param>
  4170. /// <param name="type">1:入库,2:出库,3:调拨</param>
  4171. /// <param name="cmd"></param>
  4172. /// <returns></returns>
  4173. private static DataTable GetData(string Identification, int type, SqlCommand cmd)
  4174. {
  4175. #region SLQ
  4176. string sql = @"SELECT log.ID,
  4177. log.TransCode,
  4178. log.TransSequence,
  4179. log.LotNo,
  4180. log.InvCode,
  4181. inv.InvName,
  4182. inv.InvStd,
  4183. log.Quantity,
  4184. inv.InvUnit,
  4185. log.Quantity*(lot.Amount/lot.Quantity) AS Amount,
  4186. inv.AmountUnit,
  4187. {1}
  4188. ext.ProjectCode,
  4189. 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,
  4190. ext.Version,
  4191. ext.Brand,
  4192. ext.cFree1,
  4193. ext.cFree2,
  4194. ext.cFree3,
  4195. ext.cFree4,
  4196. ext.cFree5,
  4197. ext.cFree6,
  4198. ext.cFree7,
  4199. ext.cFree8,
  4200. ext.cFree9,
  4201. ext.cFree10,
  4202. type.Name AS TransType,
  4203. log.MUSER AS [User],
  4204. log.MTIME AS [MTime]
  4205. FROM ICSWareHouseLotInfoLog log
  4206. LEFT JOIN ICSType type ON type.TableCode='ICSWareHouseLotInfoLog' AND type.ColumnCode='BusinessCode' AND log.BusinessCode=type.Code AND log.WorkPoint=type.WorkPoint
  4207. INNER JOIN ICSInventoryLot lot ON log.LotNo=lot.LotNo AND log.WorkPoint=lot.WorkPoint
  4208. INNER JOIN ICSExtension ext ON lot.ExtensionID=ext.ID AND lot.WorkPoint=ext.WorkPoint
  4209. INNER JOIN ICSInventory inv ON log.InvCode=inv.InvCode AND log.WorkPoint=inv.WorkPoint
  4210. {2}
  4211. LEFT JOIN ICSInventoryBatchEnable invBat ON log.InvCode=invBat.InvCode AND log.FromWarehouseCode=invBat.WHCode AND log.WorkPoint=invBat.WorkPoint
  4212. WHERE log.Identification='{0}'";
  4213. #endregion
  4214. string columns = @"log.ToWarehouseCode AS WHCode,
  4215. log.ToLocationCode AS LocationCode,
  4216. wh.WarehouseName AS WHName,
  4217. loc.LocationName AS LocationName,";
  4218. string tables = @"INNER JOIN ICSWarehouse wh ON log.ToWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4219. INNER JOIN ICSLocation loc ON log.ToLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  4220. if (type == 2)//出库
  4221. {
  4222. columns = @"log.FromWarehouseCode AS WHCode,
  4223. log.FromLocationCode AS LocationCode,
  4224. wh.WarehouseName AS WHName,
  4225. loc.LocationName AS LocationName,";
  4226. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4227. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint";
  4228. }
  4229. else if (type == 3)//调拨
  4230. {
  4231. columns = @"log.FromWarehouseCode AS FromWHCode,
  4232. log.FromLocationCode,
  4233. wh.WarehouseName AS FromWHName,
  4234. loc.LocationName AS FromLocationName,
  4235. log.ToWarehouseCode AS ToWHCode,
  4236. log.ToLocationCode,
  4237. whto.WarehouseName AS ToWHName,
  4238. locto.LocationName AS ToLocationName,";
  4239. tables = @"INNER JOIN ICSWarehouse wh ON log.FromWarehouseCode=wh.WarehouseCode AND log.WorkPoint=wh.WorkPoint
  4240. INNER JOIN ICSLocation loc ON log.FromLocationCode=loc.LocationCode AND log.WorkPoint=loc.WorkPoint
  4241. INNER JOIN ICSWarehouse whto ON log.ToWarehouseCode=whto.WarehouseCode AND log.WorkPoint=whto.WorkPoint
  4242. INNER JOIN ICSLocation locto ON log.ToLocationCode=locto.LocationCode AND log.WorkPoint=locto.WorkPoint";
  4243. }
  4244. sql = string.Format(sql, Identification, columns, tables);
  4245. return DBHelper.SQlReturnData(sql, cmd);
  4246. }
  4247. /// <summary>
  4248. /// 先进先出批次管控
  4249. /// </summary>
  4250. /// <param name="LotNo"></param>
  4251. /// <param name="WorkPoitCode"></param>
  4252. /// <param name="cmd"></param>
  4253. /// <returns></returns>
  4254. public static string CanOut(string LotNo, string WorkPoitCode, string ScanLotCode, SqlCommand cmd, Dictionary<string, string> language)
  4255. {
  4256. try
  4257. {
  4258. //根据Sys_SRM_Items.F_Description备注列维护的提前天数,比如维护的是1,最早条码是2022.5.16,现在扫描2022.5.17的条码也能出库,扫描2022.5.18的条码不能直接出,需要校验以下逻辑
  4259. string sql = @"DECLARE @CountNO INT,@Days INT
  4260. SELECT @Days=F_Description FROM Sys_SRM_Items WHERE F_EnCode='FIFO'
  4261. SET @CountNO=(
  4262. SELECT COUNT(a.LotNO) FROM ICSWareHouseLotInfo a
  4263. INNER JOIN ICSInventoryLot b ON a.LotNO=b.LotNO AND a.WorkPoint=b.WorkPoint
  4264. WHERE a.WorkPoint='{1}' AND ISNULL(a.Quantity,0)>0 AND 1=1
  4265. AND CONVERT(varchar(100), a.InDate, 23)<
  4266. (SELECT DATEADD(DAY, -@Days, CONVERT(varchar(100), x.InDate, 23)) FROM ICSWareHouseLotInfo x
  4267. INNER JOIN ICSInventoryLot y ON x.LotNO=y.LotNO AND x.WorkPoint=y.WorkPoint
  4268. WHERE x.LotNO='{0}' AND x.WorkPoint='{1}' AND y.INVCode=b.INVCode AND y.ExtensionID=b.ExtensionID)
  4269. )
  4270. IF @CountNO>0
  4271. BEGIN
  4272. SELECT TOP 1 CASE a.F_ItemCode WHEN 'FIFO01' THEN '1' WHEN 'FIFO02' THEN '2' ELSE '3' END AS Type
  4273. FROM Sys_SRM_ItemsDetail a
  4274. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  4275. WHERE b.F_EnCode='FIFO' AND a.F_EnabledMark='1'
  4276. ORDER BY a.F_SortCode DESC
  4277. END
  4278. ELSE
  4279. BEGIN
  4280. SELECT @CountNO
  4281. END";
  4282. //0 - 已经是最早的批次
  4283. //1 - 不管控
  4284. //2 - 提醒
  4285. //3 - 限制
  4286. sql = string.Format(sql, LotNo, WorkPoitCode);
  4287. if (!string.IsNullOrWhiteSpace(ScanLotCode))
  4288. {
  4289. sql = sql.Replace("1=1", "a.LotNO NOT IN (" + ScanLotCode + ")");
  4290. }
  4291. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4292. if (string.IsNullOrWhiteSpace(res))
  4293. {
  4294. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  4295. }
  4296. else
  4297. return res;
  4298. }
  4299. catch (Exception ex)
  4300. {
  4301. throw new Exception(ex.Message);
  4302. }
  4303. }
  4304. /// <summary>
  4305. /// 保质期管控
  4306. /// </summary>
  4307. /// <param name="LotNo"></param>
  4308. /// <param name="WorkPoitCode"></param>
  4309. /// <param name="cmd"></param>
  4310. /// <returns></returns>
  4311. public static string Effective(string LotNo, string WorkPoitCode, SqlCommand cmd, Dictionary<string, string> language)
  4312. {
  4313. try
  4314. {
  4315. string sql = @"DECLARE @CountNO INT,@Days INT,@CurrentDays INT
  4316. SELECT @CountNO=EffectiveEnable,@Days=EffectiveDays,@CurrentDays=DATEDIFF(DAY, GETDATE(), b.ExpirationDate) FROM ICSInventory a
  4317. INNER JOIN ICSInventoryLot b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint
  4318. INNER JOIN ICSWareHouseLotInfo c ON b.LotNO=c.LotNO AND b.WorkPoint=c.WorkPoint
  4319. WHERE b.LotNO='{0}' AND b.WorkPoint='{1}'
  4320. IF @CountNO='1' AND @CurrentDays<0
  4321. BEGIN
  4322. SELECT TOP 1 CASE a.F_ItemCode WHEN 'Effective01' THEN '1' WHEN 'Effective02' THEN '2' ELSE '3' END AS Type
  4323. FROM Sys_SRM_ItemsDetail a
  4324. INNER JOIN Sys_SRM_Items b ON a.F_ItemId=b.F_Id
  4325. WHERE b.F_EnCode='Effective' AND a.F_EnabledMark='1'
  4326. ORDER BY a.F_SortCode DESC
  4327. END
  4328. ELSE
  4329. BEGIN
  4330. SELECT @CountNO
  4331. END";
  4332. //0 - 已经是最早的批次
  4333. //1 - 不管控
  4334. //2 - 提醒
  4335. //3 - 限制
  4336. sql = string.Format(sql, LotNo, WorkPoitCode);
  4337. var res = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4338. if (string.IsNullOrWhiteSpace(res))
  4339. {
  4340. throw new Exception(language.GetNameByCode("WMSAPIInfo183"));//"查询管控信息失败!");
  4341. }
  4342. else
  4343. return res;
  4344. }
  4345. catch (Exception ex)
  4346. {
  4347. throw new Exception(ex.Message);
  4348. }
  4349. }
  4350. #region 包装
  4351. /// <summary>
  4352. /// 查询包装信息
  4353. /// </summary>
  4354. /// <param name="JsonData"></param>
  4355. /// <returns></returns>
  4356. public static object ContainerGet(ICSContainer JsonData)
  4357. {
  4358. var language = LanguageHelper.GetName("WMSAPIInfo");
  4359. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4360. {
  4361. conn.Open();
  4362. SqlTransaction sqlTran = conn.BeginTransaction();
  4363. SqlCommand cmd = new SqlCommand();
  4364. cmd.Transaction = sqlTran;
  4365. cmd.Connection = conn;
  4366. try
  4367. {
  4368. string sql = string.Empty;
  4369. //目标包装
  4370. if (JsonData.ToContainerCode != null)
  4371. {
  4372. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4373. BEGIN
  4374. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4375. RETURN
  4376. END
  4377. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  4378. sql = string.Format(sql, JsonData.ToContainerCode, JsonData.WorkPoint);
  4379. }
  4380. ///原包装
  4381. else if (JsonData.FromContainerCode != null)
  4382. {
  4383. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4384. BEGIN
  4385. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4386. RETURN
  4387. END
  4388. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  4389. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4390. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  4391. BEGIN
  4392. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  4393. RETURN
  4394. END
  4395. SELECT ContainerCode,ContainerName FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}'";
  4396. sql = string.Format(sql, JsonData.FromContainerCode, JsonData.WorkPoint);
  4397. }
  4398. else
  4399. {
  4400. throw new Exception(language.GetNameByCode("WMSAPIInfo029"));//"请传入包装条码!");
  4401. }
  4402. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  4403. cmd.Transaction.Commit();
  4404. return table;
  4405. }
  4406. catch (Exception ex)
  4407. {
  4408. if (cmd.Transaction != null)
  4409. cmd.Transaction.Rollback();
  4410. log.Error(ex.Message);
  4411. throw new Exception(ex.Message);
  4412. }
  4413. finally
  4414. {
  4415. if (conn.State == ConnectionState.Open)
  4416. {
  4417. conn.Close();
  4418. }
  4419. conn.Dispose();
  4420. }
  4421. }
  4422. }
  4423. /// <summary>
  4424. /// 修改包装信息
  4425. /// </summary>
  4426. /// <param name="JsonData"></param>
  4427. /// <returns></returns>
  4428. public static DataTable ContainerUpdate(List<ICSContainer> JsonData)
  4429. {
  4430. var language = LanguageHelper.GetName("WMSAPIInfo");
  4431. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4432. {
  4433. conn.Open();
  4434. SqlTransaction sqlTran = conn.BeginTransaction();
  4435. SqlCommand cmd = new SqlCommand();
  4436. cmd.Transaction = sqlTran;
  4437. cmd.Connection = conn;
  4438. try
  4439. {
  4440. string sql = string.Empty;
  4441. string codes = string.Empty;
  4442. foreach (ICSContainer container in JsonData)
  4443. {
  4444. sql = @"IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{0}' and WorkPoint='{1}')
  4445. BEGIN
  4446. RAISERROR('" + language.GetNameByCode("WMSAPIInfo072") + @"',16,1);
  4447. RETURN
  4448. END
  4449. IF NOT EXISTS(SELECT a.ID FROM ICSContainer a
  4450. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4451. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}')
  4452. BEGIN
  4453. RAISERROR('" + language.GetNameByCode("WMSAPIInfo073") + @"',16,1);
  4454. RETURN
  4455. END
  4456. IF NOT EXISTS(SELECT ID FROM ICSContainer WHERE ContainerCODE ='{2}' and WorkPoint='{1}')
  4457. BEGIN
  4458. RAISERROR('" + string.Format(language.GetNameByCode("WMSAPIInfo072"), "{2}") + @"',16,1);
  4459. RETURN
  4460. END
  4461. UPDATE b SET ContainerID=c.ID
  4462. FROM ICSContainer a
  4463. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4464. INNER JOIN ICSContainer c ON c.ContainerCODE ='{2}' and a.WorkPoint=c.WorkPoint
  4465. WHERE a.ContainerCODE ='{0}' and a.WorkPoint='{1}'";
  4466. sql = string.Format(sql, container.FromContainerCode, container.WorkPoint, container.ToContainerCode);
  4467. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4468. {
  4469. throw new Exception(language.GetNameByCode("WMSAPIInfo030"));//"包装更新失败!");
  4470. }
  4471. codes += "'" + container.ToContainerCode + container.WorkPoint + "',";
  4472. }
  4473. sql = @"SELECT a.ContainerCode, a.ContainerName,b.LotNo FROM ICSContainer a
  4474. INNER JOIN ICSContainerLot b ON a.ID=b.ContainerID
  4475. WHERE a.ContainerCODE+a.WorkPoint IN({0})";
  4476. sql = string.Format(sql, codes.Substring(0,codes.Length - 1));
  4477. DataTable table = DBHelper.SQlReturnData(sql, cmd);
  4478. cmd.Transaction.Commit();
  4479. return table;
  4480. }
  4481. catch (Exception ex)
  4482. {
  4483. if (cmd.Transaction != null)
  4484. cmd.Transaction.Rollback();
  4485. log.Error(ex.Message);
  4486. throw new Exception(ex.Message);
  4487. }
  4488. finally
  4489. {
  4490. if (conn.State == ConnectionState.Open)
  4491. {
  4492. conn.Close();
  4493. }
  4494. conn.Dispose();
  4495. }
  4496. }
  4497. }
  4498. #endregion
  4499. #region 盘点
  4500. /// <summary>
  4501. /// 创建盘点单
  4502. /// </summary>
  4503. /// <param name="JsonData"></param>
  4504. /// <returns></returns>
  4505. public static DataTable CheckCreate(List<ICSCheck> JsonData)
  4506. {
  4507. var language = LanguageHelper.GetName("WMSAPIInfo");
  4508. if (JsonData.Count <= 0)
  4509. {
  4510. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4511. }
  4512. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4513. {
  4514. conn.Open();
  4515. SqlTransaction sqlTran = conn.BeginTransaction();
  4516. SqlCommand cmd = new SqlCommand();
  4517. cmd.Transaction = sqlTran;
  4518. cmd.Connection = conn;
  4519. try
  4520. {
  4521. string Code = string.Empty;
  4522. string sql = string.Empty;
  4523. foreach (var item in JsonData)
  4524. {
  4525. if (string.IsNullOrEmpty(item.User))
  4526. {
  4527. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  4528. }
  4529. if (string.IsNullOrEmpty(item.WorkPoint))
  4530. {
  4531. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  4532. }
  4533. //获取单号
  4534. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  4535. BEGIN
  4536. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  4537. RETURN
  4538. END
  4539. DECLARE @MaxNO INT,@date varchar(20)='CHK'+SUBSTRING(CONVERT(varchar(8), GETDATE(), 112), 1, 8)
  4540. SELECT @MaxNO=SUBSTRING(MAX(CheckCode),LEN(@date)+1,LEN(MAX(CheckCode))-LEN(@date))+1 FROM ICSCheck
  4541. WHERE SUBSTRING(CheckCode, 1, LEN(@date))=@date
  4542. IF @MaxNO IS NULL
  4543. BEGIN
  4544. SELECT @date+'00001' AS Code
  4545. END
  4546. ELSE
  4547. BEGIN
  4548. SELECT @date+REPLICATE('0',5-LEN(@MaxNO))+CAST(@MaxNO AS nvarchar(10)) AS Code
  4549. END ";
  4550. sql = string.Format(sql, item.User, item.WorkPoint);
  4551. Code = DBHelper.ExecuteScalar(sql, cmd).ToString();
  4552. //创建盘点单
  4553. foreach (var itemInfo in item.detail)
  4554. {
  4555. int len = itemInfo.SelectLevel.Length;
  4556. sql = @"INSERT INTO ICSCheck (ID,CheckCode,SelectLevel,Status,Quantity,Amount,MUSER,MUSERName,MTIME,WorkPoint)
  4557. SELECT NEWID(),'{0}','{1}','2',SUM(a.Quantity),0,b.F_Account,b.F_RealName,GETDATE(),b.F_Location
  4558. FROM ICSWareHouseLotInfo a
  4559. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4560. WHERE SUBSTRING(a.LocationCode,1,{4}) = '{1}'
  4561. GROUP BY b.F_Account,b.F_RealName,b.F_Location";
  4562. sql = string.Format(sql, Code, itemInfo.SelectLevel, item.User, item.WorkPoint, len);
  4563. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4564. {
  4565. throw new Exception(language.GetNameByCode("WMSAPIInfo031"));//"盘点单创建失败!");
  4566. }
  4567. }
  4568. }
  4569. if (string.IsNullOrWhiteSpace(Code))
  4570. {
  4571. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单单号不能为空!");
  4572. }
  4573. #region 查询返回数据
  4574. sql = @"SELECT a.ID,a.CheckCode,a.SelectLevel,
  4575. a.Quantity,
  4576. a.Amount,
  4577. a.MUSER AS [User],
  4578. a.MTIME AS [MTime]
  4579. FROM ICSCheck a
  4580. WHERE a.CheckCode='{0}'";
  4581. sql = string.Format(sql, Code);
  4582. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4583. #endregion
  4584. cmd.Transaction.Commit();
  4585. return data;
  4586. }
  4587. catch (Exception ex)
  4588. {
  4589. if (cmd.Transaction != null)
  4590. cmd.Transaction.Rollback();
  4591. log.Error(ex.Message);
  4592. throw new Exception(ex.Message);
  4593. }
  4594. finally
  4595. {
  4596. if (conn.State == ConnectionState.Open)
  4597. {
  4598. conn.Close();
  4599. }
  4600. conn.Dispose();
  4601. }
  4602. }
  4603. }
  4604. /// <summary>
  4605. /// 盘点扫描
  4606. /// </summary>
  4607. /// <param name="JsonData"></param>
  4608. /// <returns></returns>
  4609. public static DataTable LOTCheckCreate(List<ICSCheck> JsonData)
  4610. {
  4611. var language = LanguageHelper.GetName("WMSAPIInfo");
  4612. if (JsonData.Count <= 0)
  4613. {
  4614. throw new Exception(language.GetNameByCode("WMSAPIInfo007"));//"传送数据为空!"
  4615. }
  4616. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4617. {
  4618. conn.Open();
  4619. SqlTransaction sqlTran = conn.BeginTransaction();
  4620. SqlCommand cmd = new SqlCommand();
  4621. cmd.Transaction = sqlTran;
  4622. cmd.Connection = conn;
  4623. try
  4624. {
  4625. string lots = string.Empty;
  4626. string sql = string.Empty;
  4627. int result = 0;
  4628. string Identification = Guid.NewGuid().ToString();
  4629. foreach (var item in JsonData)
  4630. {
  4631. if (string.IsNullOrEmpty(item.User))
  4632. {
  4633. throw new Exception(language.GetNameByCode("WMSAPIInfo018"));//"操作人不能为空!");
  4634. }
  4635. if (string.IsNullOrEmpty(item.WorkPoint))
  4636. {
  4637. throw new Exception(language.GetNameByCode("WMSAPIInfo004"));//"站点不能为空!"
  4638. }
  4639. if (string.IsNullOrEmpty(item.CheckCode))
  4640. {
  4641. throw new Exception(language.GetNameByCode("WMSAPIInfo032"));//"盘点单号不能为空!");
  4642. }
  4643. //校验
  4644. sql = @"IF NOT EXISTS(SELECT F_Account FROM Sys_SRM_User WHERE F_Account='{0}' AND F_Location='{1}')
  4645. BEGIN
  4646. RAISERROR('" + language.GetNameByCode("WMSAPIInfo060") + @"',16,1);
  4647. RETURN
  4648. END
  4649. IF NOT EXISTS(SELECT ID FROM ICSCheck WHERE CheckCode='{2}' AND WorkPoint='{1}')
  4650. BEGIN
  4651. RAISERROR('" + language.GetNameByCode("WMSAPIInfo075") + @"',16,1);
  4652. RETURN
  4653. END";
  4654. sql = string.Format(sql, item.User, item.WorkPoint, item.CheckCode);
  4655. DBHelper.ExecuteNonQuery(sql, cmd);
  4656. //创建盘点单
  4657. foreach (var itemInfo in item.detail)
  4658. {
  4659. sql = @"IF NOT EXISTS(SELECT LotNo FROM ICSWareHouseLotInfo WHERE LotNo='{1}' AND WorkPoint='{3}')
  4660. BEGIN
  4661. RAISERROR('" + language.GetNameByCode("WMSAPIInfo076") + @"',16,1);
  4662. RETURN
  4663. END
  4664. IF EXISTS(SELECT LotNo FROM ICSCheckDetail WHERE CheckCode='{0}' AND LotNo='{1}' AND WorkPoint='{3}')
  4665. BEGIN
  4666. UPDATE a SET ActualQuantity='{4}',MUSER=b.F_Account,MUSERName=b.F_RealName,MTIME=GETDATE()
  4667. FROM ICSCheckDetail a
  4668. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4669. WHERE a.CheckCode='{0}' AND a.LotNo='{1}' and a.WorkPoint='{3}'
  4670. END
  4671. ELSE
  4672. BEGIN
  4673. INSERT INTO ICSCheckDetail (ID,CheckCode,LotNo,Quantity,ActualQuantity,MUSER,MUSERName,MTIME,WorkPoint)
  4674. SELECT NEWID(),'{0}',a.LotNo,a.Quantity,'{4}',b.F_Account,b.F_RealName,GETDATE(),a.WorkPoint
  4675. FROM ICSWareHouseLotInfo a
  4676. INNER JOIN Sys_SRM_User b ON b.F_Account='{2}' AND b.F_Location='{3}'
  4677. WHERE a.LotNo='{1}' and a.WorkPoint='{3}'
  4678. END";
  4679. sql = string.Format(sql, item.CheckCode, itemInfo.LotNo, item.User, item.WorkPoint, itemInfo.ActualQuantity);
  4680. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4681. {
  4682. throw new Exception(language.GetNameByCode("WMSAPIInfo033"));//"盘点扫描创建失败!");
  4683. }
  4684. #region 更新ICSCheckDetail表
  4685. string strSql = @"UPDATE ICSCheckDetail Set";
  4686. if (item.CheckKind == "初盘")
  4687. strSql += @" PrimaryQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  4688. else if (item.CheckKind == "复盘")
  4689. strSql += @" ReplayQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  4690. else
  4691. strSql += @" CheckQuantity+=" + Convert.ToDecimal(itemInfo.ActualQuantity);
  4692. strSql += @" where ToCheckNO='" + item.CheckCode + "' AND WorkPoint='" + item.WorkPoint + "'";
  4693. cmd.CommandText = strSql;
  4694. result = cmd.ExecuteNonQuery();
  4695. if (result <= 0)
  4696. {
  4697. throw new Exception(language.GetNameByCode("WMSAPIInfo296"));//"盘点子表数量增加失败!");
  4698. }
  4699. #endregion
  4700. #region 更新库存
  4701. if (item.UpdateWHLI)
  4702. {
  4703. ICSWareHouseLotInfoService.WareHouseLotInfoUpdate(Identification, item.CheckCode, "", itemInfo.LotNo, itemInfo.ActualQuantity, item.User, item.WorkPoint, "9", cmd, language);
  4704. }
  4705. #endregion
  4706. lots += "'" + itemInfo.LotNo + item.WorkPoint + "',";
  4707. }
  4708. if (string.IsNullOrWhiteSpace(lots))
  4709. {
  4710. throw new Exception(language.GetNameByCode("WMSAPIInfo005"));//"请传入条码信息!");
  4711. }
  4712. sql = @"UPDATE a SET ActualQuantity=b.ActualQuantity
  4713. FROM ICSCheck a
  4714. 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
  4715. WHERE a.CheckCode='{0}' and a.WorkPoint='{1}'";
  4716. sql = string.Format(sql, item.CheckCode, item.WorkPoint, lots.Substring(0, lots.Length - 1));
  4717. if (!DBHelper.ExecuteNonQuery(sql, cmd))
  4718. {
  4719. throw new Exception(language.GetNameByCode("WMSAPIInfo034"));//"盘点扫描更新盘点单失败!");
  4720. }
  4721. }
  4722. #region 查询返回数据
  4723. sql = @"SELECT x.ID,x.CheckCode,y.WarehouseCode AS WHCode,x.LotNo,
  4724. y.InvCode,
  4725. inv.InvName,
  4726. inv.InvStd,
  4727. x.Quantity,x.ActualQuantity,
  4728. inv.InvUnit,
  4729. x.MUSER AS [User],
  4730. x.MTIME AS [MTime]
  4731. FROM ICSCheckDetail x
  4732. INNER JOIN ICSWareHouseLotInfo y ON x.LotNo=y.LotNo AND x.WorkPoint=y.WorkPoint
  4733. INNER JOIN ICSInventory inv ON y.InvCode=inv.InvCode AND y.WorkPoint=inv.WorkPoint
  4734. WHERE x.LotNo+x.WorkPoint IN ({0})";
  4735. sql = string.Format(sql, lots.Substring(0, lots.Length - 1));
  4736. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4737. #endregion
  4738. cmd.Transaction.Commit();
  4739. return data;
  4740. }
  4741. catch (Exception ex)
  4742. {
  4743. if (cmd.Transaction != null)
  4744. cmd.Transaction.Rollback();
  4745. log.Error(ex.Message);
  4746. throw new Exception(ex.Message);
  4747. }
  4748. finally
  4749. {
  4750. if (conn.State == ConnectionState.Open)
  4751. {
  4752. conn.Close();
  4753. }
  4754. conn.Dispose();
  4755. }
  4756. }
  4757. }
  4758. #endregion
  4759. #region 多语言
  4760. /// <summary>
  4761. /// 多语言查询
  4762. /// </summary>
  4763. /// <param name="JsonData"></param>
  4764. /// <returns></returns>
  4765. public static DataTable PromptInformationGet(WMSBarCoreModel JsonData)
  4766. {
  4767. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4768. {
  4769. conn.Open();
  4770. SqlCommand cmd = new SqlCommand();
  4771. cmd.Connection = conn;
  4772. try
  4773. {
  4774. string sql = @"select cnValue AS Name,Code from Sys_Language where 1=1";
  4775. if (!string.IsNullOrWhiteSpace(JsonData.Code))
  4776. {
  4777. sql += " and Code LIKE '%{0}%'";
  4778. }
  4779. sql = string.Format(sql, JsonData.Code);
  4780. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4781. return data;
  4782. }
  4783. catch (Exception ex)
  4784. {
  4785. log.Error(ex.Message);
  4786. throw new Exception(ex.Message);
  4787. }
  4788. finally
  4789. {
  4790. if (conn.State == ConnectionState.Open)
  4791. {
  4792. conn.Close();
  4793. }
  4794. conn.Dispose();
  4795. }
  4796. }
  4797. }
  4798. #endregion
  4799. #region 仓库/库位
  4800. /// <summary>
  4801. /// 仓库/库位
  4802. /// </summary>
  4803. /// <param name="JsonData"></param>
  4804. /// <returns></returns>
  4805. public static DataTable LocationGet(ICSLocation JsonData)
  4806. {
  4807. var language = LanguageHelper.GetName("WMSAPIInfo");
  4808. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4809. {
  4810. conn.Open();
  4811. SqlTransaction sqlTran = conn.BeginTransaction();
  4812. SqlCommand cmd = new SqlCommand();
  4813. cmd.Transaction = sqlTran;
  4814. cmd.Connection = conn;
  4815. try
  4816. {
  4817. string sql = @"IF NOT EXISTS(SELECT LocationCode FROM ICSLocation a where LocationCode='{0}' AND a.WorkPoint='{1}')
  4818. BEGIN
  4819. RAISERROR('" + language.GetNameByCode("WMSAPIInfo070") + @"',16,1);
  4820. RETURN
  4821. END
  4822. 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}')
  4823. BEGIN
  4824. RAISERROR('" + language.GetNameByCode("WMSAPIInfo077") + @"',16,1);
  4825. RETURN
  4826. END
  4827. 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')
  4828. BEGIN
  4829. RAISERROR('" + language.GetNameByCode("WMSAPIInfo078") + @"',16,1);
  4830. RETURN
  4831. END
  4832. SELECT
  4833. LocationCode,
  4834. LocationName ,
  4835. WarehouseCode,
  4836. WarehouseName
  4837. FROM ICSLocation a
  4838. 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'";
  4839. sql = string.Format(sql, JsonData.LocationCode, JsonData.WorkPoint);
  4840. DataTable data = DBHelper.SQlReturnData(sql, cmd);
  4841. cmd.Transaction.Commit();
  4842. return data;
  4843. }
  4844. catch (Exception ex)
  4845. {
  4846. if (cmd.Transaction != null)
  4847. cmd.Transaction.Rollback();
  4848. log.Error(ex.Message);
  4849. throw new Exception(ex.Message);
  4850. }
  4851. finally
  4852. {
  4853. if (conn.State == ConnectionState.Open)
  4854. {
  4855. conn.Close();
  4856. }
  4857. conn.Dispose();
  4858. }
  4859. }
  4860. }
  4861. #endregion
  4862. #region 登陆
  4863. public static object CheckLogin(Sys_SRM_User userModel)
  4864. {
  4865. using (SqlConnection conn = new System.Data.SqlClient.SqlConnection(connString))
  4866. {
  4867. conn.Open();
  4868. SqlCommand cmd = new SqlCommand();
  4869. cmd.Connection = conn;
  4870. try
  4871. {
  4872. string sql = @"select F_Account from Sys_SRM_User where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";//已经启用的账号
  4873. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  4874. DataTable dt = DBHelper.SQlReturnData(sql, cmd);
  4875. if (dt != null && dt.Rows.Count > 0)//查询的数据不为空
  4876. {
  4877. sql = @" select a.[F_Id] as UserId
  4878. ,[F_Account] as userCode
  4879. ,[F_RealName] as UserName
  4880. ,[F_NickName]
  4881. ,b.F_UserPassword
  4882. ,b.F_UserSecretkey
  4883. ,[F_HeadIcon]
  4884. ,[F_Gender]
  4885. ,[F_Birthday]
  4886. ,[F_MobilePhone]
  4887. ,[F_Email]
  4888. ,[F_WeChat]
  4889. ,[F_ManagerId]
  4890. ,[F_SecurityLevel]
  4891. ,[F_Signature]
  4892. ,[F_OrganizeId]
  4893. ,[F_DepartmentId]
  4894. ,[F_RoleId]
  4895. ,[F_DutyId]
  4896. ,[F_IsAdministrator]
  4897. ,[F_SortCode]
  4898. ,[F_DeleteMark]
  4899. ,[F_EnabledMark]
  4900. ,[F_Description]
  4901. ,[F_CreatorTime]
  4902. ,[F_CreatorUserId]
  4903. ,[F_LastModifyTime]
  4904. ,[F_LastModifyUserId]
  4905. ,[F_DeleteTime]
  4906. ,[F_DeleteUserId]
  4907. ,[F_Location] as WorkPoint
  4908. ,[F_VenCode]
  4909. from Sys_SRM_User a
  4910. left join Sys_SRM_UserLogOn b on b.F_UserId=a.F_Id
  4911. where F_Account='{0}' and F_Location='{1}' and F_EnabledMark='1'";
  4912. sql = string.Format(sql, userModel.UserCode, userModel.WorkPoint);
  4913. dt = DBHelper.SQlReturnData(sql, cmd);
  4914. IList<UserLogOnEntity> users = DBHelper.ModelConvertHelper<UserLogOnEntity>.ConvertToModel(dt);
  4915. // string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  4916. foreach (var item in users)
  4917. {
  4918. //string UserPassword = Md5.md5(DESEncrypt.Encrypt(userModel.F_UserPassword.ToLower()),16).ToLower();
  4919. string dbPassword = Md5.md5(DESEncrypt.Encrypt(userModel.UserPassword.ToLower(), item.F_UserSecretkey.ToLower()).ToLower(), 32).ToLower();
  4920. if (dbPassword == item.F_UserPassword)
  4921. {
  4922. string json = JsonConvert.SerializeObject(dt);
  4923. List<Sys_SRM_User> userLogOnEntity = JsonConvert.DeserializeObject<List<Sys_SRM_User>>(json);
  4924. return userLogOnEntity;
  4925. }
  4926. else
  4927. {
  4928. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI004"));//"密码不正确,请重新输入");
  4929. }
  4930. }
  4931. }
  4932. else
  4933. {
  4934. throw new Exception(LanguageHelper.GetNameSingle("WMSAPI005"));//"用户名不存在,请重新输入!");
  4935. }
  4936. return null;
  4937. }
  4938. catch (Exception ex)
  4939. {
  4940. log.Error(ex.Message);
  4941. throw new Exception(ex.Message);
  4942. }
  4943. finally
  4944. {
  4945. if (conn.State == ConnectionState.Open)
  4946. {
  4947. conn.Close();
  4948. }
  4949. conn.Dispose();
  4950. }
  4951. }
  4952. }
  4953. #endregion
  4954. }
  4955. }