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

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