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.

132 lines
7.6 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 ICSWareHouseLotInfoLogApp : 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 MTIME >= '" + queryParam["StartDate"].ToString() + "' ";
  37. }
  38. if (!string.IsNullOrWhiteSpace(queryParam["EndDate"].ToString()))
  39. {
  40. whereSql += " and MTIME < '" + queryParam["EndDate"].ToString() + "' ";
  41. }
  42. if (!string.IsNullOrWhiteSpace(queryParam["InvCode"].ToString()))
  43. {
  44. whereSql2 += " and b.InvCode like '%" + queryParam["InvCode"].ToString() + "%' ";
  45. }
  46. if (!string.IsNullOrWhiteSpace(queryParam["InvName"].ToString()))
  47. {
  48. whereSql2 += " and b.InvName like '%" + queryParam["InvName"].ToString() + "%' ";
  49. }
  50. if (!string.IsNullOrWhiteSpace(queryParam["InvStd"].ToString()))
  51. {
  52. whereSql2 += " and b.InvStd like '%" + queryParam["InvStd"].ToString() + "%' ";
  53. }
  54. if (!string.IsNullOrWhiteSpace(queryParam["WHCode"].ToString()))
  55. {
  56. whereSql2 += " and e.WarehouseCode like '%" + queryParam["WHCode"].ToString() + "%' ";
  57. }
  58. }
  59. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  60. {
  61. whereSql2 += " and b.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  62. }
  63. #region [SQL]
  64. string sql = $@"SELECT b.InvCode,b.InvName,b.InvStd,b.ClassCode,b.ClassName,b.InvUnit,b.EATTRIBUTE5 as OldInvCode,e.WarehouseCode,e.WarehouseName,ISnull(g.QCQuantity,0) QCQuantity,Isnull(d.SQuantity,0) SQuantity,Isnull(f.FQuantity,0) FQuantity,ISNULL(C.Quantity, 0) as Quantity FROM
  65. ICSInventory b
  66. left JOIN (SELECT invCode,workPoint,WarehouseCode,SUM(Quantity) as Quantity FROM ICSWareHouseLotInfo GROUP BY invCode,workPoint,WarehouseCode) c ON c.InvCode=b.InvCode AND b.WorkPoint=c.WorkPoint
  67. left JOIN ICSWarehouse e ON c.WarehouseCode=e.WarehouseCode AND c.WorkPoint=e.WorkPoint
  68. left JOIN (SELECT invCode,workPoint,SUM(Quantity) as SQuantity,TOWarehouseCode AS WarehouseCode FROM ICSWareHouseLotInfoLog WHERE TransType='2' AND BusinessCode!='31' AND BusinessCode!='32' {whereSql} GROUP BY invCode,workPoint,TOWarehouseCode) d ON d.InvCode=b.InvCode AND d.workPoint=b.WorkPoint AND c.WarehouseCode=d.WarehouseCode
  69. left JOIN (SELECT invCode,workPoint,SUM(Quantity) as FQuantity,FromWarehouseCode AS WarehouseCode FROM ICSWareHouseLotInfoLog WHERE TransType='3' AND BusinessCode!='31' AND BusinessCode!='32' {whereSql} GROUP BY invCode,workPoint,FromWarehouseCode) f ON f.InvCode=b.InvCode AND f.workPoint=b.WorkPoint AND c.WarehouseCode=f.WarehouseCode
  70. left JOIN (SELECT invCode,workPoint,SUM(Quantity) as QCQuantity,TOWarehouseCode AS WarehouseCode FROM ICSWareHouseLotInfoLog WHERE TransType='1' {whereSql} GROUP BY invCode,workPoint,TOWarehouseCode) g ON g.InvCode=b.InvCode AND g.workPoint=b.WorkPoint AND c.WarehouseCode=g.WarehouseCode where ( d.SQuantity<>0 or f.FQuantity<>0 ) {whereSql2}";
  71. #endregion
  72. return Repository().FindTablePageBySql(sql.ToString(), parameter.ToArray(), ref jqgridparam);
  73. }
  74. public DataTable StatementExportAll(string StartDate, string EndDate, string InvCode, string WHCode, string InvName, string InvStd)
  75. {
  76. string TableCode = string.Empty;
  77. string whereSql = string.Empty;
  78. string whereSql2 = string.Empty;
  79. if (!string.IsNullOrWhiteSpace(StartDate))
  80. {
  81. whereSql += " and MTIME >= '" + StartDate + "' ";
  82. }
  83. if (!string.IsNullOrWhiteSpace(EndDate))
  84. {
  85. whereSql += " and MTIME < '" + EndDate + "' ";
  86. }
  87. if (!string.IsNullOrWhiteSpace(InvCode))
  88. {
  89. whereSql2 += " and b.InvCode like '%" + InvCode + "%' ";
  90. }
  91. if (!string.IsNullOrWhiteSpace(InvName))
  92. {
  93. whereSql2 += " and b.InvName like '%" + InvName + "%' ";
  94. }
  95. if (!string.IsNullOrWhiteSpace(InvStd))
  96. {
  97. whereSql2 += " and b.InvStd like '%" + InvStd + "%' ";
  98. }
  99. if (!string.IsNullOrWhiteSpace(WHCode))
  100. {
  101. whereSql2 += " and e.WarehouseCode like '%" + WHCode + "%' ";
  102. }
  103. if (NFine.Code.OperatorProvider.Provider.GetCurrent().RoleEnCode != "admin")
  104. {
  105. whereSql2 += " and b.WorkPoint='" + NFine.Code.OperatorProvider.Provider.GetCurrent().Location + "'";
  106. }
  107. #region [SQL]
  108. string sql = $@"SELECT b.InvCode AS 物料编码,b.InvName AS 物料名称,b.InvStd as 物料规格 ,b.ClassCode AS 大类编码,b.ClassName AS 大类名称,e.WarehouseCode as 仓库编码,e.WarehouseName as 仓库名称,ISnull(g.QCQuantity, 0) 期初数量 ,Isnull(d.SQuantity, 0) 收料数量,Isnull(f.FQuantity, 0) 发料数量,ISNULL(C.Quantity, 0) as 库存数量 FROM
  109. ICSInventory b
  110. left JOIN (SELECT invCode,workPoint,WarehouseCode,SUM(Quantity) as Quantity FROM ICSWareHouseLotInfo GROUP BY invCode,workPoint,WarehouseCode) c ON c.InvCode=b.InvCode AND b.WorkPoint=c.WorkPoint
  111. left JOIN ICSWarehouse e ON c.WarehouseCode=e.WarehouseCode AND c.WorkPoint=e.WorkPoint
  112. left JOIN (SELECT invCode,workPoint,SUM(Quantity) as SQuantity,TOWarehouseCode AS WarehouseCode FROM ICSWareHouseLotInfoLog WHERE TransType='2' AND BusinessCode!='31' AND BusinessCode!='32' {whereSql} GROUP BY invCode,workPoint,TOWarehouseCode) d ON d.InvCode=b.InvCode AND d.workPoint=b.WorkPoint AND c.WarehouseCode=d.WarehouseCode
  113. left JOIN (SELECT invCode,workPoint,SUM(Quantity) as FQuantity,FromWarehouseCode AS WarehouseCode FROM ICSWareHouseLotInfoLog WHERE TransType='3' AND BusinessCode!='31' AND BusinessCode!='32' {whereSql} GROUP BY invCode,workPoint,FromWarehouseCode) f ON f.InvCode=b.InvCode AND f.workPoint=b.WorkPoint AND c.WarehouseCode=f.WarehouseCode
  114. left JOIN (SELECT invCode,workPoint,SUM(Quantity) as QCQuantity,TOWarehouseCode AS WarehouseCode FROM ICSWareHouseLotInfoLog WHERE TransType='1' {whereSql} GROUP BY invCode,workPoint,TOWarehouseCode) g ON g.InvCode=b.InvCode AND g.workPoint=b.WorkPoint AND c.WarehouseCode=g.WarehouseCode where ( d.SQuantity<>0 or f.FQuantity<>0 ) {whereSql2}";
  115. #endregion
  116. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  117. return dt;
  118. }
  119. }
  120. }