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

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