You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
9.7 KiB

3 weeks ago
  1. using NFine.Data.Extensions;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using NFine.Code;
  9. using NFine.Repository;
  10. using System.Data.Common;
  11. using NFine.Domain._03_Entity.SRM;
  12. using ICS.Application.Entity;
  13. using Newtonsoft.Json;
  14. using System.Configuration;
  15. using System.Data.SqlClient;
  16. using ICS.Data;
  17. using Newtonsoft.Json.Linq;
  18. using System.Web.UI.WebControls;
  19. using static NFine.Code.Net;
  20. namespace NFine.Application.DHAY
  21. {
  22. public class ICSOtherInOutApp : RepositoryFactory<ICSVendor>
  23. {
  24. public static DataTable Invmes = new DataTable();
  25. public DataTable GetList(string queryJson, ref Pagination jqgridparam)
  26. {
  27. DataTable dt = new DataTable();
  28. var queryParam = queryJson.ToJObject();
  29. List<DbParameter> parameter = new List<DbParameter>();
  30. string whereSql = string.Empty;
  31. string whereSql2 = string.Empty;
  32. if (!string.IsNullOrWhiteSpace(queryJson))
  33. {
  34. if (!string.IsNullOrWhiteSpace(queryParam["StartDate"].ToString()))
  35. {
  36. whereSql += " and a.MTIME >= '" + queryParam["StartDate"].ToString() + "' ";
  37. }
  38. if (!string.IsNullOrWhiteSpace(queryParam["EndDate"].ToString()))
  39. {
  40. whereSql += " and a.MTIME < '" + queryParam["EndDate"].ToString() + "' ";
  41. }
  42. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  43. {
  44. whereSql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  45. }
  46. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  47. {
  48. whereSql += " and e.WarehouseCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  49. }
  50. if (!string.IsNullOrWhiteSpace(queryParam["LocationCode"].ToString()))
  51. {
  52. whereSql += $" and (a.FromLocationCode like '%{queryParam["LocationCode"]}%' OR a.ToLocationCode like '%{queryParam["LocationCode"]}%') ";
  53. }
  54. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  55. {
  56. whereSql += " and c.BatchCode like '%" + queryParam["BatchCode"].ToString() + "%' ";
  57. }
  58. }
  59. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  60. {
  61. whereSql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  62. }
  63. #region [SQL]
  64. string sql = $@"SELECT DISTINCT e.WarehouseCode
  65. AS WHCode,e.WarehouseName as WHName,a.InvCode,d.InvName,c.BatchCode ,d.ID as InvID,case when isnull(a.FromLocationCode,'')='' then a.ToLocationCode ELSE a.FromLocationCode END LocationCode
  66. from ICSWareHouseLotInfoLog a
  67. INNER JOIN ICSInventoryLot b ON a.LotNo=b.LotNo AND a.WorkPoint=b.WorkPoint
  68. INNER JOIN ICSExtension c ON b.ExtensionID=c.ID AND b.WorkPoint=c.WorkPoint
  69. INNER JOIN ICSInventory d ON a.InvCode=d.InvCode AND a.WorkPoint=d.WorkPoint
  70. INNER JOIN ICSWarehouse e ON e.WorkPoint=a.WorkPoint AND (e.WarehouseCode=a.FromWarehouseCode OR e.WarehouseCode=a.ToWarehouseCode)
  71. WHERE (a.BusinessCode='24' OR a.BusinessCode='25') {whereSql}";
  72. #endregion
  73. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  74. }
  75. public DataTable GetDetails(string queryJson, ref Pagination jqgridparam,string ID)
  76. {
  77. DataTable dt = new DataTable();
  78. var queryParam = queryJson.ToJObject();
  79. List<DbParameter> parameter = new List<DbParameter>();
  80. string whereSql = string.Empty;
  81. string whereSql2 = string.Empty;
  82. if (!string.IsNullOrWhiteSpace(queryJson))
  83. {
  84. if (!string.IsNullOrWhiteSpace(queryParam["StartDate"].ToString()))
  85. {
  86. whereSql += " and a.MTIME >= '" + queryParam["StartDate"].ToString() + "' ";
  87. }
  88. if (!string.IsNullOrWhiteSpace(queryParam["EndDate"].ToString()))
  89. {
  90. whereSql += " and a.MTIME < '" + queryParam["EndDate"].ToString() + "' ";
  91. }
  92. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  93. {
  94. whereSql += " and a.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  95. }
  96. if (!string.IsNullOrWhiteSpace(queryParam["BatchCode"].ToString()))
  97. {
  98. whereSql += " and f.BatchCode= '" + queryParam["BatchCode"].ToString() + "' ";
  99. }
  100. if (!string.IsNullOrWhiteSpace(queryParam["LocationCode"].ToString()))
  101. {
  102. whereSql += $" and (b.FromLocationCode like '%{queryParam["LocationCode"]}%' OR b.ToLocationCode like '%{queryParam["LocationCode"]}%') ";
  103. }
  104. }
  105. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  106. {
  107. whereSql += " and a.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  108. }
  109. #region [SQL]
  110. string sql = $@"SELECT a.ID, a.InvCode,a.InvName,a.InvStd,b.TransCode ,b.MTIME ,b.Quantity,f.BatchCode,d.WarehouseCode AS WHCode,d.WarehouseName AS WHName,b.FromLocationCode LocationCode
  111. FROM ICSInventory a
  112. INNER JOIN ICSWareHouseLotInfoLog b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint AND b.BusinessCode='24' AND b.FromWarehouseCode='{queryParam["WHCode"]}' --
  113. INNER JOIN ICSWarehouse d ON a.WorkPoint=d.WorkPoint AND d.WarehouseCode=b.FromWarehouseCode
  114. INNER JOIN ICSInventoryLot e ON e.LotNo=b.LotNo AND a.WorkPoint=e.WorkPoint
  115. INNER JOIN ICSExtension f ON e.ExtensionID=f.ID AND f.WorkPoint=a.WorkPoint
  116. WHERE a.ID='{ID}' {whereSql}
  117. UNION ALL
  118. SELECT a.ID, a.InvCode,a.InvName,a.InvStd,b.TransCode , b.MTIME ,b.Quantity,f.BatchCode,d.WarehouseCode AS WHCode,d.WarehouseName AS WHName,b.ToLocationCode LocationCode
  119. FROM ICSInventory a
  120. INNER JOIN ICSWareHouseLotInfoLog b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint AND b.BusinessCode='25' AND b.ToWarehouseCode='{queryParam["WHCode"]}' --
  121. INNER JOIN ICSWarehouse d ON a.WorkPoint=d.WorkPoint AND d.WarehouseCode=b.ToWarehouseCode
  122. INNER JOIN ICSInventoryLot e ON e.LotNo=b.LotNo AND a.WorkPoint=e.WorkPoint
  123. INNER JOIN ICSExtension f ON e.ExtensionID=f.ID AND f.WorkPoint=a.WorkPoint
  124. WHERE a.ID='{ID}' {whereSql}";
  125. #endregion
  126. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  127. }
  128. public DataTable StatementExportAll(string StartDate, string EndDate, string InvCode, string WHCode,string LocationCode, string BatchCode)
  129. {
  130. string TableCode = string.Empty;
  131. string whereSql = string.Empty;
  132. if (!string.IsNullOrWhiteSpace(StartDate))
  133. {
  134. whereSql += " and a.MTIME >= '" + StartDate + "' ";
  135. }
  136. if (!string.IsNullOrWhiteSpace(EndDate))
  137. {
  138. whereSql += " and a.MTIME < '" + EndDate + "' ";
  139. }
  140. if (!string.IsNullOrWhiteSpace(InvCode))
  141. {
  142. whereSql += " and b.InvCode like '%" + InvCode + "%' ";
  143. }
  144. if (!string.IsNullOrWhiteSpace(WHCode))
  145. {
  146. whereSql += " and d.WarehouseCode like '%" + WHCode + "%' ";
  147. }
  148. if (!string.IsNullOrWhiteSpace(LocationCode))
  149. {
  150. whereSql += $" and (b.FromLocationCode like '%{LocationCode}%' OR b.ToLocationCode like '%{LocationCode}%') ";
  151. }
  152. if (!string.IsNullOrWhiteSpace(BatchCode))
  153. {
  154. whereSql += " and f.BatchCode like '%" + BatchCode + "%' ";
  155. }
  156. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  157. {
  158. whereSql += " and b.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  159. }
  160. #region [SQL]
  161. string sql = $@"SELECT a.InvCode 物料编码,a.InvName 物料名称,a.InvStd 规格型号,d.WarehouseCode 仓库编码,d.WarehouseName 仓库名称,b.FromLocationCode 库位代码,f.BatchCode 批次,b.TransCode '杂发/收单号',b.Quantity 数量 ,b.MTIME 时间
  162. FROM ICSInventory a
  163. INNER JOIN ICSWareHouseLotInfoLog b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint AND b.BusinessCode='24'
  164. INNER JOIN ICSWarehouse d ON a.WorkPoint=d.WorkPoint AND d.WarehouseCode=b.FromWarehouseCode
  165. INNER JOIN ICSInventoryLot e ON e.LotNo=b.LotNo AND a.WorkPoint=e.WorkPoint
  166. INNER JOIN ICSExtension f ON e.ExtensionID=f.ID AND f.WorkPoint=a.WorkPoint
  167. WHERE 1=1 {whereSql}
  168. UNION ALL
  169. SELECT a.InvCode ,a.InvName ,a.InvStd ,d.WarehouseCode ,d.WarehouseName ,b.ToLocationCode ,f.BatchCode ,b.TransCode '/',b.Quantity , b.MTIME
  170. FROM ICSInventory a
  171. INNER JOIN ICSWareHouseLotInfoLog b ON a.InvCode=b.InvCode AND a.WorkPoint=b.WorkPoint AND b.BusinessCode='25'
  172. INNER JOIN ICSWarehouse d ON a.WorkPoint=d.WorkPoint AND d.WarehouseCode=b.ToWarehouseCode
  173. INNER JOIN ICSInventoryLot e ON e.LotNo=b.LotNo AND a.WorkPoint=e.WorkPoint
  174. INNER JOIN ICSExtension f ON e.ExtensionID=f.ID AND f.WorkPoint=a.WorkPoint
  175. WHERE 1=1 {whereSql}";
  176. #endregion
  177. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  178. return dt;
  179. }
  180. }
  181. }