纽威

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