From d3f8a36f0f833368feb6f1ad65fd42f5d8edc3b4 Mon Sep 17 00:00:00 2001 From: 44673626 <44673626@qq.com> Date: Sat, 30 Apr 2022 18:15:14 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=A2=E6=97=97=E7=9C=8B=E6=9D=BF=E6=98=8E?= =?UTF-8?q?=E7=BB=86=E8=BE=93=E5=87=BA=E8=A1=A8=E3=80=81=E6=9C=89=E7=BB=93?= =?UTF-8?q?=E7=AE=97=E6=97=A0=E5=8F=91=E8=B4=A7=E3=80=81=E7=BA=A2=E6=97=97?= =?UTF-8?q?=E6=9C=AA=E7=BB=93=E6=98=8E=E7=BB=86=E8=BE=93=E5=87=BA=E4=B8=AD?= =?UTF-8?q?=E5=8F=91=E8=BF=90=E8=A1=A8=E9=83=BD=E6=9B=B4=E6=94=B9=E4=B8=BA?= =?UTF-8?q?WMS=E4=B8=AD=E8=A1=A8[CPAT=5FWMS].[dbo].[V=5FHQ=5FKENDETAIL]?= =?UTF-8?q?=EF=BC=8C=E9=80=80=E8=B4=A7=E8=A1=A8=E6=9B=B4=E6=94=B9=E4=B8=BA?= =?UTF-8?q?[CPAT=5FWMS].[dbo].[V=5FRETURN=5FSUM]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReportServices/ReportMakeService.cs | 1 + .../HQHSettledDetailDapperRepository.cs | 1579 ++++++++++------- .../Report/KanbanUnSettledDapperRepository.cs | 101 +- .../SettleSparePartDapperReportRepository.cs | 238 ++- .../HQHSettledDetailDiffExportService.cs | 2 + 5 files changed, 1233 insertions(+), 688 deletions(-) diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs index 24e00057..a46ff900 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs @@ -734,6 +734,7 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices [HttpPost] [Route("HQHSettledDetailDiffExportService")] [DisableRequestSizeLimit] + [UnitOfWork(false)] public async Task HQHSettledDetailDiffExportServiceMake( HQKanbanRequestDto input ) diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQHSettledDetailDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQHSettledDetailDapperRepository.cs index 3f7d8032..1c96c304 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQHSettledDetailDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQHSettledDetailDapperRepository.cs @@ -2,12 +2,14 @@ using Magicodes.ExporterAndImporter.Core; using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Repositories.Dapper; using Volo.Abp.EntityFrameworkCore; +using Volo.Abp.Uow; namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report { @@ -52,6 +54,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report /// /// /// + [UnitOfWork(false)] public virtual List GetInvoiceSettledDetailDiffReportList(string version, string materialCode, string begin, string end, string materialGroup) { @@ -69,101 +72,102 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report //} - string str = "SELECT\n" + - " isnull( temp1.交货单号, '' ) 交货单号,\n" + - " temp1.交货时间,\n" + - " temp1.[工厂],\n" + - " temp1.收货仓库,\n" + - " temp1.收货仓库描述,\n" + - " temp1.订货看板编号,\n" + - " temp1.订货零件号,\n" + - " temp1.验收单日期,\n" + - " temp1.Sap编码,\n" + - " temp1.看板编号,\n" + - " temp1.物料组,\n" + - " temp1.零件中文名称,\n" + - " temp1.发货数量,\n" + - " temp1.外部单号,\n" + - " temp1.结算数量,\n" + - " temp3.Price AS 结算单价,\n" + - " --( temp1.[结算数量] * ISNULL( temp3.Price, 0 ) ) AS 结算金额,\n" + - " ISNULL( temp1.结算金额, 0 ) AS 结算金额,\n" + - " isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + - " isnull( temp1.发货数量, 0 ) - ISNULL( temp4.Qty, 0 ) AS 实际发货数量,\n" + - " ( isnull( temp1.发货数量, 0 ) - ISNULL( temp4.Qty, 0 ) ) * isnull( TEMP2.Price, 0 ) AS 实际发货总金额,\n" + - " ( isnull( temp1.发货数量, 0 ) - ISNULL( temp4.Qty, 0 ) - isnull( temp1.[结算数量], 0 ) ) AS 量差,\n" + - " ISNULL( temp3.Price, 0 ) - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + - " ( ISNULL( temp3.Price, 0 ) - ISNULL( TEMP2.Price, 0 ) ) * temp1.结算数量 AS 差异总金额 ,\n" + - " temp4.Qty 退货数量 \n" + - "FROM\n" + - " (\n" + - " SELECT\n" + - " '' AS 交货单号,\n" + - " NULL AS 交货时间,\n" + - " a.StorageLocation AS 收货仓库,\n" + - " a.StorageLocationDesc AS 收货仓库描述,\n" + - " a.HQHKanBan AS 订货看板编号,\n" + - " a.MaterialCode AS 订货零件号,\n" + - " c.MaterialCode Sap编码,\n" + - " a.MaterialCode 结算物料代码,\n" + - " c.MaterialDesc AS 零件中文名称,\n" + - " isnull( b.Qty, 0 ) AS 发货数量,\n" + - " a.[ExternalKanbanNumber] AS 外部单号,\n" + - " isnull( a.Qty, 0 ) AS 结算数量,\n" + - " C.EstimateTypeDesc AS 物料组,\n" + - " a.Factory AS 工厂,\n" + - " '' AS 看板编号,\n" + - " '' AS 验收单日期, \n" + - " isnull( a.Amt, 0 ) AS 结算金额\n" + - " FROM\n" + - " (\n" + - " SELECT SUM\n" + - " ( Qty ) AS Qty,\n" + - " HQHKanBan,\n" + - " MaterialCode,\n" + - " Version,\n" + - " StorageLocation,\n" + - " StorageLocationDesc,\n" + - " Factory,\n" + - " ExternalKanbanNumber,Amt \n" + - " FROM\n" + - " Set_HQ_H_Platform \n" + - " GROUP BY\n" + - " HQHKanBan,\n" + - " MaterialCode,\n" + - " Version,\n" + - " StorageLocation,\n" + - " StorageLocationDesc,\n" + - " Factory,\n" + - " ExternalKanbanNumber,Amt \n" + - " ) AS a\n" + - " INNER JOIN ( SELECT SUM ( Qty ) AS Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY Kanban, MaterialCode ) AS b ON a.HQHKanBan = b.Kanban \n" + - " AND a.MaterialCode = b.MaterialCode\n" + - " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + - " WHERE\n" + - " ( a.Version= '{0}' AND a.HQHKanBan IS NOT NULL ) \n" + - " AND a.HQHKanBan <> 'BJ' \n" + - " ) AS temp1\n" + - " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" + - " LEFT JOIN (\n" + - " SELECT\n" + - " ROUND( SUM ( Amt ) / SUM ( Qty ), 4 ) price,\n" + - " HQHKanBan,\n" + - " MaterialCode,\n" + - " Version \n" + - " FROM\n" + - " Set_HQ_H_Platform \n" + - " WHERE\n" + - " Version = '{0}' \n" + - " AND HQHKanBan <> 'BJ' \n" + - " GROUP BY\n" + - " HQHKanBan,\n" + - " MaterialCode,\n" + - " Version \n" + - " ) AS TEMP3 ON temp1.[结算物料代码] = TEMP3.MaterialCode \n" + - " AND temp1.订货看板编号 = TEMP3.HQHKanBan\n" + - " LEFT JOIN set_backQty temp4 ON temp1.订货看板编号 = temp4.Code \n" + - " AND temp1.Sap编码= temp4.MaterialCode"; + #region 第二次更改 + //string str = "SELECT\n" + + //" isnull( temp1.交货单号, '' ) 交货单号,\n" + + //" temp1.交货时间,\n" + + //" temp1.[工厂],\n" + + //" temp1.收货仓库,\n" + + //" temp1.收货仓库描述,\n" + + //" temp1.订货看板编号,\n" + + //" temp1.订货零件号,\n" + + //" temp1.验收单日期,\n" + + //" temp1.Sap编码,\n" + + //" temp1.看板编号,\n" + + //" temp1.物料组,\n" + + //" temp1.零件中文名称,\n" + + //" temp1.发货数量,\n" + + //" temp1.外部单号,\n" + + //" temp1.结算数量,\n" + + //" temp3.Price AS 结算单价,\n" + + //" --( temp1.[结算数量] * ISNULL( temp3.Price, 0 ) ) AS 结算金额,\n" + + //" ISNULL( temp1.结算金额, 0 ) AS 结算金额,\n" + + //" isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + + //" isnull( temp1.发货数量, 0 ) - ISNULL( temp4.Qty, 0 ) AS 实际发货数量,\n" + + //" ( isnull( temp1.发货数量, 0 ) - ISNULL( temp4.Qty, 0 ) ) * isnull( TEMP2.Price, 0 ) AS 实际发货总金额,\n" + + //" ( isnull( temp1.发货数量, 0 ) - ISNULL( temp4.Qty, 0 ) - isnull( temp1.[结算数量], 0 ) ) AS 量差,\n" + + //" ISNULL( temp3.Price, 0 ) - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + + //" ( ISNULL( temp3.Price, 0 ) - ISNULL( TEMP2.Price, 0 ) ) * temp1.结算数量 AS 差异总金额 ,\n" + + //" temp4.Qty 退货数量 \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" '' AS 交货单号,\n" + + //" NULL AS 交货时间,\n" + + //" a.StorageLocation AS 收货仓库,\n" + + //" a.StorageLocationDesc AS 收货仓库描述,\n" + + //" a.HQHKanBan AS 订货看板编号,\n" + + //" a.MaterialCode AS 订货零件号,\n" + + //" c.MaterialCode Sap编码,\n" + + //" a.MaterialCode 结算物料代码,\n" + + //" c.MaterialDesc AS 零件中文名称,\n" + + //" isnull( b.Qty, 0 ) AS 发货数量,\n" + + //" a.[ExternalKanbanNumber] AS 外部单号,\n" + + //" isnull( a.Qty, 0 ) AS 结算数量,\n" + + //" C.EstimateTypeDesc AS 物料组,\n" + + //" a.Factory AS 工厂,\n" + + //" '' AS 看板编号,\n" + + //" '' AS 验收单日期, \n" + + //" isnull( a.Amt, 0 ) AS 结算金额\n" + + //" FROM\n" + + //" (\n" + + //" SELECT SUM\n" + + //" ( Qty ) AS Qty,\n" + + //" HQHKanBan,\n" + + //" MaterialCode,\n" + + //" Version,\n" + + //" StorageLocation,\n" + + //" StorageLocationDesc,\n" + + //" Factory,\n" + + //" ExternalKanbanNumber,Amt \n" + + //" FROM\n" + + //" Set_HQ_H_Platform \n" + + //" GROUP BY\n" + + //" HQHKanBan,\n" + + //" MaterialCode,\n" + + //" Version,\n" + + //" StorageLocation,\n" + + //" StorageLocationDesc,\n" + + //" Factory,\n" + + //" ExternalKanbanNumber,Amt \n" + + //" ) AS a\n" + + //" INNER JOIN ( SELECT SUM ( Qty ) AS Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY Kanban, MaterialCode ) AS b ON a.HQHKanBan = b.Kanban \n" + + //" AND a.MaterialCode = b.MaterialCode\n" + + //" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + + //" WHERE\n" + + //" ( a.Version= '{0}' AND a.HQHKanBan IS NOT NULL ) \n" + + //" AND a.HQHKanBan <> 'BJ' \n" + + //" ) AS temp1\n" + + //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" + + //" LEFT JOIN (\n" + + //" SELECT\n" + + //" ROUND( SUM ( Amt ) / SUM ( Qty ), 4 ) price,\n" + + //" HQHKanBan,\n" + + //" MaterialCode,\n" + + //" Version \n" + + //" FROM\n" + + //" Set_HQ_H_Platform \n" + + //" WHERE\n" + + //" Version = '{0}' \n" + + //" AND HQHKanBan <> 'BJ' \n" + + //" GROUP BY\n" + + //" HQHKanBan,\n" + + //" MaterialCode,\n" + + //" Version \n" + + //" ) AS TEMP3 ON temp1.[结算物料代码] = TEMP3.MaterialCode \n" + + //" AND temp1.订货看板编号 = TEMP3.HQHKanBan\n" + + //" LEFT JOIN set_backQty temp4 ON temp1.订货看板编号 = temp4.Code \n" + + //" AND temp1.Sap编码= temp4.MaterialCode"; //string str = "SELECT\n" + @@ -259,55 +263,49 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report //" AND temp1.订货看板编号 = TEMP3.HQHKanBan\n" + //" LEFT JOIN set_backQty temp4 ON temp1.订货看板编号 = temp4.Code \n" + //" AND temp1.Sap编码= temp4.MaterialCode"; + #endregion + //var sql2 = "SELECT\n" + + //" a.WmsBillNum,\n" + + //" t1.MaterialCode MaterialCode,\n" + + //" a.Kanban ,\n" + + // " A.LastModificationTime WmsDate \n" + + //"FROM\n" + + //" Set_HQ_H_Kanban A\n" + + //" INNER JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT(*)> 1 ) B ON A.Kanban = B.Kanban \n" + + //" AND A.MaterialCode = B.MaterialCode " + + //" left join Set_material t1 on a.MaterialCode=t1.CustomerPartCode "; - //var _sql = string.Format(str, version, condition); - var _sql = string.Format(str, version); - - - - var sql2 = "SELECT\n" + - " a.WmsBillNum,\n" + - " t1.MaterialCode MaterialCode,\n" + - " a.Kanban ,\n" + - " A.LastModificationTime WmsDate \n" + - "FROM\n" + - " Set_HQ_H_Kanban A\n" + - " INNER JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT(*)> 1 ) B ON A.Kanban = B.Kanban \n" + - " AND A.MaterialCode = B.MaterialCode " + - " left join Set_material t1 on a.MaterialCode=t1.CustomerPartCode "; - - var listCompare= DbConnection.Query(sql2); - - + //var listCompare = DbConnection.Query(sql2); + var listCompare = DbConnection.Query("[dbo].[p_hq_unsettle_inner]", null, null, true, 1200, CommandType.StoredProcedure); - var sql3 = "SELECT\n" + - " a.WmsBillNum,\n" + - " t1.MaterialCode MaterialCode,\n" + - " a.Kanban,\n" + - " A.LastModificationTime WmsDate \n" + - "FROM\n" + - " Set_HQ_H_Kanban A\n" + - " LEFT JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT(*)> 1 ) B ON A.Kanban = B.Kanban \n" + - " AND A.MaterialCode = B.MaterialCode \n" + - " left join Set_material t1 on a.MaterialCode=t1.CustomerPartCode \n"+ - "WHERE\n" + - " B.Kanban IS NULL"; + //var sql3 = "SELECT\n" + + //" a.WmsBillNum,\n" + + //" t1.MaterialCode MaterialCode,\n" + + //" a.Kanban,\n" + + //" A.LastModificationTime WmsDate \n" + + //"FROM\n" + + //" Set_HQ_H_Kanban A\n" + + //" LEFT JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT(*)> 1 ) B ON A.Kanban = B.Kanban \n" + + //" AND A.MaterialCode = B.MaterialCode \n" + + //" left join Set_material t1 on a.MaterialCode=t1.CustomerPartCode \n" + + //"WHERE\n" + + //" B.Kanban IS NULL"; - var listCompare1 = DbConnection.Query(sql3); + var listCompare1 = DbConnection.Query("[dbo].[p_hq_unsettle_leftjoin]", null, null, true, 1200, CommandType.StoredProcedure); - var sql10= "SELECT DISTINCT\n" + + var sql10 = "SELECT DISTINCT\n" + " t1.* \n" + "FROM\n" + " (\n" + @@ -391,7 +389,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report var first = _lscopy.FirstOrDefault(p => p.HQHKanBan == itm.HQHKanBan && p.MaterialCode == itm.MaterialCode); if (first != null) { - first.KanbanNumber +="," +itm.KanbanNumber; + first.KanbanNumber += "," + itm.KanbanNumber; first.AcceptanceDate += "," + itm.AcceptanceDate; first.ExternalKanbanNumber += "," + itm.ExternalKanbanNumber; } @@ -444,7 +442,9 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report _ls.Add(itm); } - var _query = DbConnection.Query(_sql, null, null, true, 1200, null); + //var _query = DbConnection.Query(_sql, null, null, true, 1200, null); + //又变了,要求发运和退货直接去比对WMS发运和退货视图 + var _query = DbConnection.Query("[dbo].[p_hq_unsettle]", new { version = version }, null, true, 1200, CommandType.StoredProcedure); _list = _query.ToList(); @@ -472,6 +472,16 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report } + public virtual List GetNOInvoiceSettledDetailDiffReportList(string version, string materialCode, string begin, string end, string materialGroup) + { + + List _list = new List(); + var _query = DbConnection.Query("[dbo].[p_hq_unsettle_settleNofayun]", new { version = version }, null, true, 1200, CommandType.StoredProcedure); + _list = _query.ToList(); + return _list; + + } + /// /// 有结算无发货报表,同时按照财务要求“看板号为空”也要归为未结当中,所以做了UNION ALL /// @@ -481,167 +491,397 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report /// /// /// - public virtual List GetNOInvoiceSettledDetailDiffReportList(string version, string materialCode, string begin, string end, string materialGroup) + public virtual List GetNOInvoiceSettledDetailDiffReportList_org(string version, string materialCode, string begin, string end, string materialGroup) { - List _list = new List(); + List _list = new List(); - string str = "SELECT\n" + - " aaaa.* \n" + - "FROM\n" + - " (\n" + - " SELECT\n" + - " temp1.交货时间,\n" + - " isnull( temp1.交货单号, '' ) 交货单号,\n" + - " temp1.[工厂],\n" + - " temp1.收货仓库,\n" + - " temp1.收货仓库描述,\n" + - " temp1.订货看板编号,\n" + - " temp1.订货零件号,\n" + - " temp1.验收单日期,\n" + - " temp1.Sap编码,\n" + - " temp1.看板编号,\n" + - " temp1.物料组,\n" + - " temp1.零件中文名称,\n" + - " temp1.发货数量,\n" + - " temp1.发货状态,\n" + - " temp1.外部单号,\n" + - " temp1.结算数量,\n" + - " temp1.结算单价,\n" + - " temp1.结算金额,\n" + - " isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + - " isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" + - " 0 AS 数量差异,\n" + - " temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + - " ( temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.结算数量 AS 差异总金额 \n" + - " FROM\n" + - " (\n" + - " SELECT\n" + - " b.WmsBillNum AS 交货单号,\n" + - " CONVERT ( VARCHAR ( 100 ), b.LastModificationTime, 23 ) AS 交货时间,\n" + - " a.StorageLocation AS 收货仓库,\n" + - " a.StorageLocationDesc AS 收货仓库描述,\n" + - " a.HQHKanBan AS 订货看板编号,\n" + - " a.MaterialCode AS 订货零件号,\n" + - " c.MaterialCode Sap编码,\n" + - " c.MaterialDesc AS 零件中文名称,\n" + - " isnull( b.Qty, 0 ) AS 发货数量,\n" + - " isnull( b.State, 0 ) AS 发货状态,\n" + - " a.ExternalKanbanNumber AS 外部单号,\n" + - " isnull( a.Qty, 0 ) AS 结算数量,\n" + - " isnull( a.Price, 0 ) AS 结算单价,\n" + - " isnull( a.Amt, 0 ) AS 结算金额 ,\n" + - " C.EstimateTypeDesc AS 物料组,\n" + - " a.Factory AS 工厂,\n" + - " a.KanbanNumber AS 看板编号,\n" + - " CONVERT ( VARCHAR ( 100 ), a.AcceptanceDate, 23 ) AS 验收单日期 \n" + - " FROM\n" + - " ( SELECT * FROM Set_HQ_H_Platform WHERE HQHKanBan <> 'BJ' AND Version = '{0}' ) AS a\n" + - " LEFT OUTER JOIN Set_HQ_H_Kanban AS b ON a.HQHKanBan = b.Kanban \n" + - " AND a.MaterialCode = b.MaterialCode\n" + - " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + - " WHERE\n" + - " b.Kanban IS NULL \n" + - " AND b.MaterialCode IS NULL \n" + - " ) AS temp1\n" + - " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode \n" + - " ) aaaa UNION ALL\n" + - "SELECT\n" + - " ccc.* \n" + - "FROM\n" + - " (\n" + - " SELECT\n" + - " isnull( temp1.交货单号, '' ) 交货单号,\n" + - " temp1.交货时间,\n" + - " temp1.[工厂],\n" + - " temp1.收货仓库,\n" + - " temp1.收货仓库描述,\n" + - " temp1.订货看板编号,\n" + - " temp1.订货零件号,\n" + - " temp1.验收单日期,\n" + - " temp1.Sap编码,\n" + - " temp1.看板编号,\n" + - " temp1.物料组,\n" + - " temp1.零件中文名称,\n" + - " temp1.发货数量,\n" + - " temp1.发货状态,\n" + - " temp1.外部单号,\n" + - " temp1.结算数量,\n" + - " temp3.Price AS 结算单价,\n" + - " ( temp1.[结算数量] * ISNULL( temp3.Price, 0 ) ) AS 结算金额,\n" + - " isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + - " isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" + - " ( isnull( temp1.发货数量, 0 ) - isnull( temp1.[结算数量], 0 ) ) AS 数量差异,\n" + - " ISNULL( temp3.Price, 0 ) - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + - " ( ISNULL( temp3.Price, 0 ) - ISNULL( TEMP2.Price, 0 ) ) * temp1.结算数量 AS 差异总金额 \n" + - " FROM\n" + - " (\n" + - " SELECT\n" + - " '' AS 交货单号,\n" + - " NULL AS 交货时间,\n" + - " a.StorageLocation AS 收货仓库,\n" + - " a.StorageLocationDesc AS 收货仓库描述,\n" + - " '' AS 订货看板编号,\n" + - " a.MaterialCode AS 订货零件号,\n" + - " c.MaterialCode Sap编码,\n" + - " a.MaterialCode 结算物料代码,\n" + - " c.MaterialDesc AS 零件中文名称,\n" + - " 0 AS 发货数量,\n" + - " 0 AS 发货状态,\n" + - " a.ExternalKanbanNumber AS 外部单号,\n" + - " isnull( a.Qty, 0 ) AS 结算数量,\n" + - " C.EstimateTypeDesc AS 物料组,\n" + - " a.Factory AS 工厂,\n" + - " '' AS 看板编号,\n" + - " '' AS 验收单日期 \n" + - " FROM\n" + - " (\n" + - " SELECT SUM\n" + - " ( Qty ) AS Qty,\n" + - " MaterialCode,\n" + - " Version,\n" + - " StorageLocation,\n" + - " StorageLocationDesc,\n" + - " Factory,\n" + - " ExternalKanbanNumber \n" + - " FROM\n" + - " Set_HQ_H_Platform \n" + - " WHERE\n" + - " HQHKanBan IS NULL \n" + - " GROUP BY\n" + - " MaterialCode,\n" + - " Version,\n" + - " StorageLocation,\n" + - " StorageLocationDesc,\n" + - " Factory,\n" + - " ExternalKanbanNumber \n" + - " ) AS a\n" + - " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + - " WHERE\n" + - " a.Version= '{0}' \n" + - " ) AS temp1\n" + - " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" + - " LEFT JOIN (\n" + - " SELECT\n" + - " ROUND( SUM ( Amt ) / SUM ( Qty ), 4 ) price,\n" + - " MaterialCode,\n" + - " Version \n" + - " FROM\n" + - " Set_HQ_H_Platform \n" + - " WHERE\n" + - " HQHKanBan IS NULL \n" + - " AND Version = '{0}' \n" + - " GROUP BY\n" + - " MaterialCode,\n" + - " Version \n" + - " ) AS TEMP3 ON temp1.[结算物料代码] = TEMP3.MaterialCode \n" + - " ) ccc"; + #region 需求又变了 + //string str = " SELECT\n" + + //" * INTO #TMP3 \n" + + //"FROM\n" + + //" ( SELECT [看板号] kanban, [客户零件号] [MaterialCode], [WMS交货单号] WmsBillNum, [WMS发货数量] Qty, [WMS上线时间] [LastModificationTime], [WMS上线时间] [CreationTime] FROM [192.168.0.63].[CPAT_WMS].[dbo].[V_HQ_KENDETAIL] ) T;\n" + + //" SELECT \n" + + //" aaaa.* \n" + + //" FROM \n" + + //" ( \n" + + //" SELECT \n" + + //" temp1.交货时间, \n" + + //" isnull( temp1.交货单号, '' ) 交货单号, \n" + + //" temp1.[工厂], \n" + + //" temp1.收货仓库, \n" + + //" temp1.收货仓库描述, \n" + + //" temp1.订货看板编号, \n" + + //" temp1.订货零件号, \n" + + //" temp1.验收单日期, \n" + + //" temp1.Sap编码, \n" + + //" temp1.看板编号, \n" + + //" temp1.物料组, \n" + + //" temp1.零件中文名称, \n" + + //" temp1.发货数量, \n" + + //" --temp1.发货状态, \n" + + //" temp1.外部单号, \n" + + //" temp1.结算数量, \n" + + //" temp1.结算单价, \n" + + //" temp1.结算金额, \n" + + //" isnull( TEMP2.Price, 0 ) AS 发货定价, \n" + + //" isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额, \n" + + //" 0 AS 数量差异, \n" + + //" temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异, \n" + + //" ( temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.结算数量 AS 差异总金额 \n" + + //" FROM \n" + + //" ( \n" + + //" SELECT \n" + + //" b.WmsBillNum AS 交货单号, \n" + + //" CONVERT ( VARCHAR ( 100 ), b.LastModificationTime, 23 ) AS 交货时间, \n" + + //" a.StorageLocation AS 收货仓库, \n" + + //" a.StorageLocationDesc AS 收货仓库描述, \n" + + //" a.HQHKanBan AS 订货看板编号, \n" + + //" a.MaterialCode AS 订货零件号, \n" + + //" c.MaterialCode Sap编码, \n" + + //" c.MaterialDesc AS 零件中文名称, \n" + + //" isnull( b.Qty, 0 ) AS 发货数量, \n" + + //" --isnull( b.State, 0 ) AS 发货状态, \n" + + //" a.ExternalKanbanNumber AS 外部单号, \n" + + //" isnull( a.Qty, 0 ) AS 结算数量, \n" + + //" isnull( a.Price, 0 ) AS 结算单价, \n" + + //" isnull( a.Amt, 0 ) AS 结算金额 , \n" + + //" C.EstimateTypeDesc AS 物料组, \n" + + //" a.Factory AS 工厂, \n" + + //" a.KanbanNumber AS 看板编号, \n" + + //" CONVERT ( VARCHAR ( 100 ), a.AcceptanceDate, 23 ) AS 验收单日期 \n" + + //" FROM \n" + + //" ( SELECT * FROM Set_HQ_H_Platform WHERE HQHKanBan <> 'BJ' AND Version = '{0}' ) AS a \n" + + //" LEFT OUTER JOIN #TMP3 AS b ON a.HQHKanBan = b.Kanban \n" + + //" AND a.MaterialCode = b.MaterialCode \n" + + //" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + + //" WHERE \n" + + //" b.Kanban IS NULL \n" + + //" AND b.MaterialCode IS NULL \n" + + //" ) AS temp1 \n" + + //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode \n" + + //" ) aaaa UNION ALL \n" + + //" SELECT \n" + + //" ccc.* \n" + + //" FROM \n" + + //" ( \n" + + //" SELECT \n" + + //" isnull( temp1.交货单号, '' ) 交货单号, \n" + + //" temp1.交货时间, \n" + + //" temp1.[工厂], \n" + + //" temp1.收货仓库, \n" + + //" temp1.收货仓库描述, \n" + + //" temp1.订货看板编号, \n" + + //" temp1.订货零件号, \n" + + //" temp1.验收单日期, \n" + + //" temp1.Sap编码, \n" + + //" temp1.看板编号, \n" + + //" temp1.物料组, \n" + + //" temp1.零件中文名称, \n" + + //" temp1.发货数量, \n" + + //" --temp1.发货状态, \n" + + //" temp1.外部单号, \n" + + //" temp1.结算数量, \n" + + //" temp3.Price AS 结算单价, \n" + + //" ( temp1.[结算数量] * ISNULL( temp3.Price, 0 ) ) AS 结算金额, \n" + + //" isnull( TEMP2.Price, 0 ) AS 发货定价, \n" + + //" isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额, \n" + + //" ( isnull( temp1.发货数量, 0 ) - isnull( temp1.[结算数量], 0 ) ) AS 数量差异, \n" + + //" ISNULL( temp3.Price, 0 ) - ISNULL( TEMP2.Price, 0 ) AS 单价差异, \n" + + //" ( ISNULL( temp3.Price, 0 ) - ISNULL( TEMP2.Price, 0 ) ) * temp1.结算数量 AS 差异总金额 \n" + + //" FROM \n" + + //" ( \n" + + //" SELECT \n" + + //" '' AS 交货单号, \n" + + //" NULL AS 交货时间, \n" + + //" a.StorageLocation AS 收货仓库, \n" + + //" a.StorageLocationDesc AS 收货仓库描述, \n" + + //" '' AS 订货看板编号, \n" + + //" a.MaterialCode AS 订货零件号, \n" + + //" c.MaterialCode Sap编码, \n" + + //" a.MaterialCode 结算物料代码, \n" + + //" c.MaterialDesc AS 零件中文名称, \n" + + //" 0 AS 发货数量, \n" + + //" --0 AS 发货状态, \n" + + //" a.ExternalKanbanNumber AS 外部单号, \n" + + //" isnull( a.Qty, 0 ) AS 结算数量, \n" + + //" C.EstimateTypeDesc AS 物料组, \n" + + //" a.Factory AS 工厂, \n" + + //" '' AS 看板编号, \n" + + //" '' AS 验收单日期 \n" + + //" FROM \n" + + //" ( \n" + + //" SELECT SUM \n" + + //" ( Qty ) AS Qty, \n" + + //" MaterialCode, \n" + + //" Version, \n" + + //" StorageLocation, \n" + + //" StorageLocationDesc, \n" + + //" Factory, \n" + + //" ExternalKanbanNumber \n" + + //" FROM \n" + + //" Set_HQ_H_Platform \n" + + //" WHERE \n" + + //" HQHKanBan IS NULL \n" + + //" GROUP BY \n" + + //" MaterialCode, \n" + + //" Version, \n" + + //" StorageLocation, \n" + + //" StorageLocationDesc, \n" + + //" Factory, \n" + + //" ExternalKanbanNumber \n" + + //" ) AS a \n" + + //" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + + //" WHERE \n" + + //" a.Version= '{0}' \n" + + //" ) AS temp1 \n" + + //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode \n" + + //" LEFT JOIN ( \n" + + //" SELECT \n" + + //" ROUND( SUM ( Amt ) / SUM ( Qty ), 4 ) price, \n" + + //" MaterialCode, \n" + + //" Version \n" + + //" FROM \n" + + //" Set_HQ_H_Platform \n" + + //" WHERE \n" + + //" HQHKanBan IS NULL \n" + + //" AND Version = '{0}' \n" + + //" GROUP BY \n" + + //" MaterialCode, \n" + + //" Version \n" + + //" ) AS TEMP3 ON temp1.[结算物料代码] = TEMP3.MaterialCode \n" + + //" ) ccc ;\n" + + //" DROP TABLE #TMP3;"; - - var _sql = string.Format(str, version); + #endregion - var _query = DbConnection.Query(_sql, null, null, true, 1200, null); + #region 发运表又变了 + //string str = "SELECT\n" + + //" aaaa.* \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" temp1.交货时间,\n" + + //" isnull( temp1.交货单号, '' ) 交货单号,\n" + + //" temp1.[工厂],\n" + + //" temp1.收货仓库,\n" + + //" temp1.收货仓库描述,\n" + + //" temp1.订货看板编号,\n" + + //" temp1.订货零件号,\n" + + //" temp1.验收单日期,\n" + + //" temp1.Sap编码,\n" + + //" temp1.看板编号,\n" + + //" temp1.物料组,\n" + + //" temp1.零件中文名称,\n" + + //" temp1.发货数量,\n" + + //" temp1.发货状态,\n" + + //" temp1.外部单号,\n" + + //" temp1.结算数量,\n" + + //" temp1.结算单价,\n" + + //" temp1.结算金额,\n" + + //" isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + + //" isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" + + //" 0 AS 数量差异,\n" + + //" temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + + //" ( temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.结算数量 AS 差异总金额 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" b.WmsBillNum AS 交货单号,\n" + + //" CONVERT ( VARCHAR ( 100 ), b.LastModificationTime, 23 ) AS 交货时间,\n" + + //" a.StorageLocation AS 收货仓库,\n" + + //" a.StorageLocationDesc AS 收货仓库描述,\n" + + //" a.HQHKanBan AS 订货看板编号,\n" + + //" a.MaterialCode AS 订货零件号,\n" + + //" c.MaterialCode Sap编码,\n" + + //" c.MaterialDesc AS 零件中文名称,\n" + + //" isnull( b.Qty, 0 ) AS 发货数量,\n" + + //" isnull( b.State, 0 ) AS 发货状态,\n" + + //" a.ExternalKanbanNumber AS 外部单号,\n" + + //" isnull( a.Qty, 0 ) AS 结算数量,\n" + + //" isnull( a.Price, 0 ) AS 结算单价,\n" + + //" isnull( a.Amt, 0 ) AS 结算金额 ,\n" + + //" C.EstimateTypeDesc AS 物料组,\n" + + //" a.Factory AS 工厂,\n" + + //" a.KanbanNumber AS 看板编号,\n" + + //" CONVERT ( VARCHAR ( 100 ), a.AcceptanceDate, 23 ) AS 验收单日期 \n" + + //" FROM\n" + + //" ( SELECT * FROM Set_HQ_H_Platform WHERE HQHKanBan <> 'BJ' AND Version = '{0}' ) AS a\n" + + //" LEFT OUTER JOIN Set_HQ_H_Kanban AS b ON a.HQHKanBan = b.Kanban \n" + + //" AND a.MaterialCode = b.MaterialCode\n" + + //" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + + //" WHERE\n" + + //" b.Kanban IS NULL \n" + + //" AND b.MaterialCode IS NULL \n" + + //" ) AS temp1\n" + + //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode \n" + + //" ) aaaa UNION ALL\n" + + //"SELECT\n" + + //" ccc.* \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" isnull( temp1.交货单号, '' ) 交货单号,\n" + + //" temp1.交货时间,\n" + + //" temp1.[工厂],\n" + + //" temp1.收货仓库,\n" + + //" temp1.收货仓库描述,\n" + + //" temp1.订货看板编号,\n" + + //" temp1.订货零件号,\n" + + //" temp1.验收单日期,\n" + + //" temp1.Sap编码,\n" + + //" temp1.看板编号,\n" + + //" temp1.物料组,\n" + + //" temp1.零件中文名称,\n" + + //" temp1.发货数量,\n" + + //" temp1.发货状态,\n" + + //" temp1.外部单号,\n" + + //" temp1.结算数量,\n" + + //" temp3.Price AS 结算单价,\n" + + //" ( temp1.[结算数量] * ISNULL( temp3.Price, 0 ) ) AS 结算金额,\n" + + //" isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + + //" isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" + + //" ( isnull( temp1.发货数量, 0 ) - isnull( temp1.[结算数量], 0 ) ) AS 数量差异,\n" + + //" ISNULL( temp3.Price, 0 ) - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + + //" ( ISNULL( temp3.Price, 0 ) - ISNULL( TEMP2.Price, 0 ) ) * temp1.结算数量 AS 差异总金额 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" '' AS 交货单号,\n" + + //" NULL AS 交货时间,\n" + + //" a.StorageLocation AS 收货仓库,\n" + + //" a.StorageLocationDesc AS 收货仓库描述,\n" + + //" '' AS 订货看板编号,\n" + + //" a.MaterialCode AS 订货零件号,\n" + + //" c.MaterialCode Sap编码,\n" + + //" a.MaterialCode 结算物料代码,\n" + + //" c.MaterialDesc AS 零件中文名称,\n" + + //" 0 AS 发货数量,\n" + + //" 0 AS 发货状态,\n" + + //" a.ExternalKanbanNumber AS 外部单号,\n" + + //" isnull( a.Qty, 0 ) AS 结算数量,\n" + + //" C.EstimateTypeDesc AS 物料组,\n" + + //" a.Factory AS 工厂,\n" + + //" '' AS 看板编号,\n" + + //" '' AS 验收单日期 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT SUM\n" + + //" ( Qty ) AS Qty,\n" + + //" MaterialCode,\n" + + //" Version,\n" + + //" StorageLocation,\n" + + //" StorageLocationDesc,\n" + + //" Factory,\n" + + //" ExternalKanbanNumber \n" + + //" FROM\n" + + //" Set_HQ_H_Platform \n" + + //" WHERE\n" + + //" HQHKanBan IS NULL \n" + + //" GROUP BY\n" + + //" MaterialCode,\n" + + //" Version,\n" + + //" StorageLocation,\n" + + //" StorageLocationDesc,\n" + + //" Factory,\n" + + //" ExternalKanbanNumber \n" + + //" ) AS a\n" + + //" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + + //" WHERE\n" + + //" a.Version= '{0}' \n" + + //" ) AS temp1\n" + + //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" + + //" LEFT JOIN (\n" + + //" SELECT\n" + + //" ROUND( SUM ( Amt ) / SUM ( Qty ), 4 ) price,\n" + + //" MaterialCode,\n" + + //" Version \n" + + //" FROM\n" + + //" Set_HQ_H_Platform \n" + + //" WHERE\n" + + //" HQHKanBan IS NULL \n" + + //" AND Version = '{0}' \n" + + //" GROUP BY\n" + + //" MaterialCode,\n" + + //" Version \n" + + //" ) AS TEMP3 ON temp1.[结算物料代码] = TEMP3.MaterialCode \n" + + //" ) ccc"; + #endregion + + + //var _sql = string.Format(str, version); + + //var _query = DbConnection.Query(_sql, null, null, true, 1200, null); + var _query = DbConnection.Query("[dbo].[p_hq_unsettle_settleNofayun]", new { version = version }, null, true, 1200, CommandType.StoredProcedure); + _list = _query.ToList(); + return _list; + + } + + public virtual List GetReverseSettledDetailDiffReportList(string version, string materialCode, + string begin, string end, string materialGroup, string iscontionversion) + { + + List _list = new List(); + //var _query = DbConnection.Query(_sql, null, null, true, 1200, null); + var _query = DbConnection.Query("[dbo].[p_hq_unsettle_weijie]", new { begin = begin, end = end, version = version, iscontionversion = iscontionversion }, null, true, 1200, CommandType.StoredProcedure); _list = _query.ToList(); + + var listCompare = DbConnection.Query("[dbo].[p_hq_unsettle_inner]", null, null, true, 1200, CommandType.StoredProcedure); + + + var listCompare1 = DbConnection.Query("[dbo].[p_hq_unsettle_leftjoin]", null, null, true, 1200, CommandType.StoredProcedure); + + + //发运数据比较 + List _ls = new List(); + foreach (var itm in listCompare.ToList()) + { + var first = _ls.FirstOrDefault(p => p.Kanban == itm.Kanban && p.MaterialCode == itm.MaterialCode); + if (first != null) + { + if (!string.IsNullOrEmpty(itm.WmsDate)) + { + itm.WmsDate = DateTime.Parse(itm.WmsDate).ToShortDateString(); + } + + first.WmsBillNum += "," + itm.WmsBillNum; + first.WmsDate += "," + itm.WmsDate; + } + else + { + if (!string.IsNullOrEmpty(itm.WmsDate)) + { + itm.WmsDate = DateTime.Parse(itm.WmsDate).ToShortDateString(); + } + _ls.Add(itm); + } + + } + + foreach (var itm in listCompare1.ToList()) + { + if (!string.IsNullOrEmpty(itm.WmsDate)) + { + itm.WmsDate = DateTime.Parse(itm.WmsDate).ToShortDateString(); + } + _ls.Add(itm); + } + + + + //数据整合,相同看板号+物料号的交货单号合并成一行中以逗号分隔 + foreach (var itm1 in _list) + { + var itm = _ls.FirstOrDefault(p => p.Kanban == itm1.订货看板编号 && p.MaterialCode == itm1.Sap编码); + if (itm != null) + { + itm1.交货单号 = itm.WmsBillNum; + itm1.交货时间 = itm.WmsDate; + } + } + + return _list; } @@ -657,107 +897,342 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report /// /// /// - public virtual List GetReverseSettledDetailDiffReportList(string version, string materialCode, string begin, string end, string materialGroup, string iscontionversion) + public virtual List GetReverseSettledDetailDiffReportList_org(string version, string materialCode, string begin, string end, string materialGroup, string iscontionversion) { List _list = new List(); string condition = ""; - if (!string.IsNullOrEmpty(begin)) - { - condition += string.Format(" and a.LastModificationTime>='{0}' ", begin); - } - if (!string.IsNullOrEmpty(end)) - { - condition += string.Format(" and a.LastModificationTime<='{0}' ", end); - } + if (!string.IsNullOrEmpty(begin)) + { + condition += string.Format(" and a.LastModificationTime>='{0}' ", begin); + } + if (!string.IsNullOrEmpty(end)) + { + condition += string.Format(" and a.LastModificationTime<='{0}' ", end); + } + + string conditionDate = ""; + + if (!string.IsNullOrEmpty(begin)) + { + conditionDate += string.Format(" and LastModificationTime>='{0}' ", begin); + } + if (!string.IsNullOrEmpty(end)) + { + conditionDate += string.Format(" and LastModificationTime<='{0}' ", end); + } + + string contion = string.Empty; + //选中,是否过滤掉当期结算数据 + if (iscontionversion == "0") + { + contion += string.Format(" WHERE Version <'{0}' and State = 2 ", version);//默认选中 + } + else + { + contion += " WHERE 1=1 and State = 2 ";//去掉勾选 + } + + string str = " SELECT\n" + + " * INTO #TMP5 \n" + + "FROM\n" + + " ( SELECT [看板号] kanban, [客户零件号] [MaterialCode], [WMS交货单号] WmsBillNum, [WMS发货数量] Qty, [WMS上线时间] [LastModificationTime], [WMS上线时间] [CreationTime] FROM [192.168.0.63].[CPAT_WMS].[dbo].[V_HQ_KENDETAIL] ) T;\n" + + " SELECT \n" + + " * \n" + + " FROM \n" + + " ( \n" + + " SELECT \n" + + " isnull( temp1.交货单号, '' ) 交货单号, \n" + + " temp1.订货看板编号, \n" + + " temp1.订货零件号, \n" + + " temp1.Sap编码, \n" + + " temp1.[客户物料号], \n" + + " temp1.物料组, \n" + + " temp1.零件中文名称, \n" + + " temp1.发货数量, \n" + + " temp1.外部单号, \n" + + " temp1.结算数量, \n" + + " temp1.结算单价, \n" + + " temp1.结算金额, \n" + + " isnull( TEMP2.Price, 0 ) AS 发货定价, \n" + + " isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额, \n" + + " isnull( tt.Qty, 0 ) 退货数量, \n" + + " isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) AS 实际发货数量, \n" + + " isnull( temp1.发货数量, 0 ) - isnull( temp1.结算数量, 0 ) - isnull( tt.Qty, 0 ) AS 未结数量, \n" + + " temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异, \n" + + " ISNULL( TEMP2.Price, 0 ) * ( isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) ) AS 实际发货总金额 \n" + + " FROM \n" + + " ( \n" + + " SELECT \n" + + " '' AS 交货单号, \n" + + " a.Kanban AS 订货看板编号, \n" + + " b.MaterialCode AS 订货零件号, \n" + + " c.MaterialCode Sap编码, \n" + + " c.CustomerPartCode 客户物料号, \n" + + " c.MaterialDesc AS 零件中文名称, \n" + + " isnull( a.Qty, 0 ) AS 发货数量, \n" + + " '' AS 外部单号, \n" + + " isnull( b.Qty, 0 ) AS 结算数量, \n" + + " 0 AS 结算单价, \n" + + " 0 AS 结算金额 , \n" + + " C.EstimateTypeDesc AS 物料组 \n" + + " FROM \n" + + " ( \n" + + " SELECT \n" + + " Qty, \n" + + " Kanban, \n" + + " MaterialCode, \n" + + " sap \n" + + " FROM \n" + + " ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM #TMP5 WHERE 1 = 1 {1} GROUP BY kanban, MaterialCode ) temp1 \n" + + " LEFT OUTER JOIN ( SELECT MaterialCode sap, CustomerPartCode FROM Set_material ) AS temp2 ON temp1.MaterialCode = temp2.CustomerPartCode \n" + + " ) a \n" + + " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + + " LEFT OUTER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_WmsHQHKanbanOutPutDetial {0} GROUP BY Kanban, MaterialCode ) AS b ON a.Kanban = b.Kanban \n" + + " AND a.sap = b.MaterialCode \n" + + " WHERE \n" + + " b.Kanban IS NULL \n" + + " AND b.MaterialCode IS NULL \n" + + " ) AS temp1 \n" + + " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode \n" + + " LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" + + " AND temp1.订货看板编号 = tt.Code \n" + + " ) UNION1 UNION ALL \n" + + " SELECT \n" + + " * \n" + + " FROM \n" + + " ( \n" + + " SELECT \n" + + " isnull( temp1.交货单号, '' ) 交货单号, \n" + + " temp1.订货看板编号, \n" + + " temp1.订货零件号, \n" + + " temp1.Sap编码, \n" + + " temp1.[客户物料号], \n" + + " temp1.物料组, \n" + + " temp1.零件中文名称, \n" + + " temp1.发货数量, \n" + + " temp1.外部单号, \n" + + " temp1.结算数量, \n" + + " temp1.结算单价, \n" + + " temp1.结算金额, \n" + + " isnull( TEMP2.Price, 0 ) AS 发货定价, \n" + + " isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额, \n" + + " isnull( tt.Qty, 0 ) 退货数量, \n" + + " isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) AS 实际发货数量, \n" + + " isnull( temp1.发货数量, 0 ) - isnull( temp1.结算数量, 0 ) - isnull( tt.Qty, 0 ) AS 未结数量, \n" + + " temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异, \n" + + " ISNULL( TEMP2.Price, 0 ) * ( isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) ) AS 实际发货总金额 \n" + + " FROM \n" + + " ( \n" + + " SELECT \n" + + " '' AS 交货单号, \n" + + " a.Kanban AS 订货看板编号, \n" + + " b.MaterialCode AS 订货零件号, \n" + + " c.MaterialCode Sap编码, \n" + + " c.CustomerPartCode 客户物料号, \n" + + " c.MaterialDesc AS 零件中文名称, \n" + + " isnull( a.Qty, 0 ) AS 发货数量, \n" + + " '' AS 外部单号, \n" + + " isnull( b.Qty, 0 ) AS 结算数量, \n" + + " isnull( b.Price, 0 ) AS 结算单价, \n" + + " isnull( b.Qty, 0 ) * isnull( b.Price, 0 ) AS 结算金额 , \n" + + " C.EstimateTypeDesc AS 物料组 \n" + + " FROM \n" + + " ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM #TMP5 WHERE 1 = 1 {1} GROUP BY kanban, MaterialCode ) AS a \n" + + " INNER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode, Price FROM Set_WmsHQHKanbanOutPutDetial {0} GROUP BY Kanban, MaterialCode, Price ) AS b ON a.Kanban = b.Kanban \n" + + " AND a.MaterialCode = b.MaterialCode \n" + + " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + + " WHERE \n" + + " a.Qty> b.Qty \n" + + " ) AS temp1 \n" + + " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode \n" + + " LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" + + " AND temp1.订货看板编号 = tt.Code \n" + + " ) UNION2; \n" + + " DROP TABLE #TMP5;"; + + #region 要直接去比对WMS发运视图了 又变了 + //string str = "SELECT\n" + + //" * \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" isnull( temp1.交货单号, '' ) 交货单号,\n" + + //" temp1.订货看板编号,\n" + + //" temp1.订货零件号,\n" + + //" temp1.Sap编码,\n" + + //" temp1.[客户物料号],\n" + + //" temp1.物料组,\n" + + //" temp1.零件中文名称,\n" + + //" temp1.发货数量,\n" + + //" temp1.外部单号,\n" + + //" temp1.结算数量,\n" + + //" temp1.结算单价,\n" + + //" temp1.结算金额,\n" + + //" isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + + //" isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" + + //" isnull( tt.Qty, 0 ) 退货数量,\n" + + //" isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) AS 实际发货数量,\n" + + //" isnull( temp1.发货数量, 0 ) - isnull( temp1.结算数量, 0 ) - isnull( tt.Qty, 0 ) AS 未结数量,\n" + + //" temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + + //" ISNULL( TEMP2.Price, 0 ) * ( isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) ) AS 实际发货总金额 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" '' AS 交货单号,\n" + + //" a.Kanban AS 订货看板编号,\n" + + //" b.MaterialCode AS 订货零件号,\n" + + //" c.MaterialCode Sap编码,\n" + + //" c.CustomerPartCode 客户物料号,\n" + + //" c.MaterialDesc AS 零件中文名称,\n" + + //" isnull( a.Qty, 0 ) AS 发货数量,\n" + + //" '' AS 外部单号,\n" + + //" isnull( b.Qty, 0 ) AS 结算数量,\n" + + //" 0 AS 结算单价,\n" + + //" 0 AS 结算金额 ,\n" + + //" C.EstimateTypeDesc AS 物料组 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" Qty,\n" + + //" Kanban,\n" + + //" MaterialCode,\n" + + //" sap \n" + + //" FROM\n" + + //" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban WHERE 1 = 1 {1} GROUP BY kanban, MaterialCode ) temp1\n" + + //" LEFT OUTER JOIN ( SELECT MaterialCode sap, CustomerPartCode FROM Set_material ) AS temp2 ON temp1.MaterialCode = temp2.CustomerPartCode \n" + + //" ) a\n" + + //" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode\n" + + //" LEFT OUTER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_WmsHQHKanbanOutPutDetial {0} GROUP BY Kanban, MaterialCode ) AS b ON a.Kanban = b.Kanban \n" + + //" AND a.sap = b.MaterialCode \n" + + //" WHERE\n" + + //" b.Kanban IS NULL \n" + + //" AND b.MaterialCode IS NULL \n" + + //" ) AS temp1\n" + + //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" + + //" LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" + + //" AND temp1.订货看板编号 = tt.Code \n" + + //" ) UNION1 UNION ALL\n" + + //"SELECT\n" + + //" * \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" isnull( temp1.交货单号, '' ) 交货单号,\n" + + //" temp1.订货看板编号,\n" + + //" temp1.订货零件号,\n" + + //" temp1.Sap编码,\n" + + //" temp1.[客户物料号],\n" + + //" temp1.物料组,\n" + + //" temp1.零件中文名称,\n" + + //" temp1.发货数量,\n" + + //" temp1.外部单号,\n" + + //" temp1.结算数量,\n" + + //" temp1.结算单价,\n" + + //" temp1.结算金额,\n" + + //" isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + + //" isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" + + //" isnull( tt.Qty, 0 ) 退货数量,\n" + + //" isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) AS 实际发货数量,\n" + + //" isnull( temp1.发货数量, 0 ) - isnull( temp1.结算数量, 0 ) - isnull( tt.Qty, 0 ) AS 未结数量,\n" + + //" temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + + //" ISNULL( TEMP2.Price, 0 ) * ( isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) ) AS 实际发货总金额 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" '' AS 交货单号,\n" + + //" a.Kanban AS 订货看板编号,\n" + + //" b.MaterialCode AS 订货零件号,\n" + + //" c.MaterialCode Sap编码,\n" + + //" c.CustomerPartCode 客户物料号,\n" + + //" c.MaterialDesc AS 零件中文名称,\n" + + //" isnull( a.Qty, 0 ) AS 发货数量,\n" + + //" '' AS 外部单号,\n" + + //" isnull( b.Qty, 0 ) AS 结算数量,\n" + + //" isnull( b.Price, 0 ) AS 结算单价,\n" + + //" isnull( b.Qty, 0 ) * isnull( b.Price, 0 ) AS 结算金额 ,\n" + + //" C.EstimateTypeDesc AS 物料组 \n" + + //" FROM\n" + + //" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban WHERE 1 = 1 {1} GROUP BY kanban, MaterialCode ) AS a\n" + + //" INNER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode, Price FROM Set_WmsHQHKanbanOutPutDetial {0} GROUP BY Kanban, MaterialCode, Price ) AS b ON a.Kanban = b.Kanban \n" + + //" AND a.MaterialCode = b.MaterialCode\n" + + //" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + + //" WHERE\n" + + //" a.Qty> b.Qty \n" + + //" ) AS temp1\n" + + //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" + + //" LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" + + //" AND temp1.订货看板编号 = tt.Code \n" + + //" ) UNION2;"; + + #endregion - string conditionDate = ""; - if (!string.IsNullOrEmpty(begin)) - { - conditionDate += string.Format(" and LastModificationTime>='{0}' ", begin); - } - if (!string.IsNullOrEmpty(end)) - { - conditionDate += string.Format(" and LastModificationTime<='{0}' ", end); - } + #region 又更改规则了20220425 要求去比对出库单 + //string str = "SELECT\n" + + //" * \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" isnull( temp1.交货单号, '' ) 交货单号,\n" + + //" temp1.订货看板编号,\n" + + //" temp1.订货零件号,\n" + + //" temp1.Sap编码,\n" + + //" temp1.[客户物料号],\n" + + //" temp1.物料组,\n" + + //" temp1.零件中文名称,\n" + + //" temp1.发货数量,\n" + + //" temp1.外部单号,\n" + + //" temp1.结算数量,\n" + + //" temp1.结算单价,\n" + + //" temp1.结算金额,\n" + + //" isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + + //" isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" + + //" isnull( tt.Qty, 0 ) 退货数量,\n" + + //" isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) AS 实际发货数量,\n" + + //" isnull( temp1.发货数量, 0 ) - isnull( temp1.结算数量, 0 ) - isnull( tt.Qty, 0 ) AS 未结数量,\n" + + //" temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + + //" ISNULL( TEMP2.Price, 0 ) * ( isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) ) AS 实际发货总金额 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" '' AS 交货单号,\n" + + //" a.Kanban AS 订货看板编号,\n" + + //" b.MaterialCode AS 订货零件号,\n" + + //" c.MaterialCode Sap编码,\n" + + //" c.CustomerPartCode 客户物料号,\n" + + //" c.MaterialDesc AS 零件中文名称,\n" + + //" isnull( a.Qty, 0 ) AS 发货数量,\n" + + //" '' AS 外部单号,\n" + + //" isnull( b.Qty, 0 ) AS 结算数量,\n" + + //" 0 AS 结算单价,\n" + + //" 0 AS 结算金额 ,\n" + + //" C.EstimateTypeDesc AS 物料组 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" Qty,\n" + + //" Kanban,\n" + + //" MaterialCode,\n" + + //" sap \n" + + //" FROM\n" + + //" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban WHERE 1 = 1 {1} GROUP BY kanban, MaterialCode ) temp1\n" + + //" LEFT OUTER JOIN ( SELECT MaterialCode sap, CustomerPartCode FROM Set_material ) AS temp2 ON temp1.MaterialCode = temp2.CustomerPartCode \n" + + //" ) a\n" + + //" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode\n" + + //" LEFT OUTER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_WmsHQHKanbanOutPutDetial {0} GROUP BY Kanban, MaterialCode ) AS b ON a.Kanban = b.Kanban \n" + + //" AND a.sap = b.MaterialCode \n" + + //" WHERE\n" + + //" b.Kanban IS NULL \n" + + //" AND b.MaterialCode IS NULL \n" + + //" ) AS temp1\n" + + //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" + + //" LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" + + //" AND temp1.订货看板编号 = tt.Code \n" + + //" ) UNION1"; - string contion = string.Empty; - //选中,是否过滤掉当期结算数据 - if (iscontionversion == "0") - { - contion += string.Format(" WHERE Version <'{0}' and State = 2 ", version);//默认选中 - } - else - { - contion += " WHERE 1=1 and State = 2 ";//去掉勾选 - } - //又更改规则了20220425 要求去比对出库单 - string str = "SELECT\n" + - " * \n" + - "FROM\n" + - " (\n" + - " SELECT\n" + - " isnull( temp1.交货单号, '' ) 交货单号,\n" + - " temp1.订货看板编号,\n" + - " temp1.订货零件号,\n" + - " temp1.Sap编码,\n" + - " temp1.[客户物料号],\n" + - " temp1.物料组,\n" + - " temp1.零件中文名称,\n" + - " temp1.发货数量,\n" + - " temp1.外部单号,\n" + - " temp1.结算数量,\n" + - " temp1.结算单价,\n" + - " temp1.结算金额,\n" + - " isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + - " isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" + - " isnull( tt.Qty, 0 ) 退货数量,\n" + - " isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) AS 实际发货数量,\n" + - " isnull( temp1.发货数量, 0 ) - isnull( temp1.结算数量, 0 ) - isnull( tt.Qty, 0 ) AS 未结数量,\n" + - " temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + - " ISNULL( TEMP2.Price, 0 ) * ( isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) ) AS 实际发货总金额 \n" + - " FROM\n" + - " (\n" + - " SELECT\n" + - " '' AS 交货单号,\n" + - " a.Kanban AS 订货看板编号,\n" + - " b.MaterialCode AS 订货零件号,\n" + - " c.MaterialCode Sap编码,\n" + - " c.CustomerPartCode 客户物料号,\n" + - " c.MaterialDesc AS 零件中文名称,\n" + - " isnull( a.Qty, 0 ) AS 发货数量,\n" + - " '' AS 外部单号,\n" + - " isnull( b.Qty, 0 ) AS 结算数量,\n" + - " 0 AS 结算单价,\n" + - " 0 AS 结算金额 ,\n" + - " C.EstimateTypeDesc AS 物料组 \n" + - " FROM\n" + - " (\n" + - " SELECT\n" + - " Qty,\n" + - " Kanban,\n" + - " MaterialCode,\n" + - " sap \n" + - " FROM\n" + - " ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban WHERE 1 = 1 {1} GROUP BY kanban, MaterialCode ) temp1\n" + - " LEFT OUTER JOIN ( SELECT MaterialCode sap, CustomerPartCode FROM Set_material ) AS temp2 ON temp1.MaterialCode = temp2.CustomerPartCode \n" + - " ) a\n" + - " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode\n" + - " LEFT OUTER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_WmsHQHKanbanOutPutDetial {0} GROUP BY Kanban, MaterialCode ) AS b ON a.Kanban = b.Kanban \n" + - " AND a.sap = b.MaterialCode \n" + - " WHERE\n" + - " b.Kanban IS NULL \n" + - " AND b.MaterialCode IS NULL \n" + - " ) AS temp1\n" + - " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" + - " LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" + - " AND temp1.订货看板编号 = tt.Code \n" + - " ) UNION1"; - - #region 规则又变了 //更改:按照财务要求,将有发货有结算中发货数量大于结算数据的数据整合到未结报表中20220324,sum求和不带交货单号,后算出来 //string str = "SELECT\n" + //" * \n" + @@ -871,18 +1346,33 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report //发运数据中,查出看板号+物料号相同的重复数据 + //var sql2 = "SELECT\n" + + //" a.WmsBillNum,\n" + + //" t1.MaterialCode MaterialCode,\n" + + //" a.Kanban ,\n" + + //" A.LastModificationTime WmsDate \n" + + //"FROM\n" + + //" Set_HQ_H_Kanban A\n" + + //" INNER JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT ( * ) > 1 ) B ON A.Kanban = B.Kanban \n" + + //" AND A.MaterialCode = B.MaterialCode\n" + + //" LEFT JOIN Set_material t1 ON a.MaterialCode= t1.CustomerPartCode \n" + + //"WHERE\n" + + //" 1 = 1 {0} "; var sql2 = "SELECT\n" + - " a.WmsBillNum,\n" + - " t1.MaterialCode MaterialCode,\n" + - " a.Kanban ,\n" + - " A.LastModificationTime WmsDate \n" + - "FROM\n" + - " Set_HQ_H_Kanban A\n" + - " INNER JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT ( * ) > 1 ) B ON A.Kanban = B.Kanban \n" + - " AND A.MaterialCode = B.MaterialCode\n" + - " LEFT JOIN Set_material t1 ON a.MaterialCode= t1.CustomerPartCode \n" + - "WHERE\n" + - " 1 = 1 {0} "; + " * INTO #TMP6 \n" + + "FROM\n" + + " ( SELECT [看板号] kanban, [客户零件号] [MaterialCode], [WMS交货单号] WmsBillNum, [WMS发货数量] Qty, [WMS上线时间] [LastModificationTime], [WMS上线时间] [CreationTime] FROM [192.168.0.63].[CPAT_WMS].[dbo].[V_HQ_KENDETAIL] ) T;\n" + + "SELECT\n" + + " a.WmsBillNum,\n" + + " t1.MaterialCode MaterialCode,\n" + + " a.Kanban ,\n" + + " A.LastModificationTime WmsDate \n" + + "FROM\n" + + " #TMP A\n" + + " INNER JOIN ( SELECT wms.MaterialCode, wms.Kanban FROM #TMP6 wms GROUP BY wms.MaterialCode, wms.Kanban HAVING COUNT (*) > 1 ) B ON A.Kanban = B.Kanban \n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material t1 ON a.MaterialCode= t1.CustomerPartCode WHERE 1=1 {0};\n" + + "DROP TABLE #TMP6;"; var _sql2 = string.Format(sql2, condition); var listCompare = DbConnection.Query(_sql2); @@ -890,19 +1380,37 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report //查询发运表中,看权号+物料号没有重复的数据 + //var sql3 = "SELECT\n" + + //" a.WmsBillNum,\n" + + //" t1.MaterialCode MaterialCode,\n" + + //" a.Kanban,\n" + + //" A.LastModificationTime WmsDate \n" + + //"FROM\n" + + //" Set_HQ_H_Kanban A\n" + + //" LEFT JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT(*)> 1 ) B ON A.Kanban = B.Kanban \n" + + //" AND A.MaterialCode = B.MaterialCode \n" + + //" left join Set_material t1 on a.MaterialCode=t1.CustomerPartCode \n" + + + //"WHERE\n" + + //" B.Kanban IS NULL {0}"; + var sql3 = "SELECT\n" + + " * INTO #TMP7 \n" + + "FROM\n" + + " ( SELECT [看板号] kanban, [客户零件号] [MaterialCode], [WMS交货单号] WmsBillNum, [WMS发货数量] Qty, [WMS上线时间] [LastModificationTime], [WMS上线时间] [CreationTime] FROM [192.168.0.63].[CPAT_WMS].[dbo].[V_HQ_KENDETAIL] ) T;\n" + + "SELECT\n" + " a.WmsBillNum,\n" + " t1.MaterialCode MaterialCode,\n" + " a.Kanban,\n" + " A.LastModificationTime WmsDate \n" + "FROM\n" + - " Set_HQ_H_Kanban A\n" + - " LEFT JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT(*)> 1 ) B ON A.Kanban = B.Kanban \n" + - " AND A.MaterialCode = B.MaterialCode \n" + - " left join Set_material t1 on a.MaterialCode=t1.CustomerPartCode \n" + - + " # TMP1 A\n" + + " LEFT JOIN ( SELECT wms.MaterialCode, wms.Kanban FROM #TMP7 wms GROUP BY wms.MaterialCode, wms.Kanban HAVING COUNT (*) > 1 ) B ON A.Kanban = B.Kanban \n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material t1 ON a.MaterialCode= t1.CustomerPartCode \n" + "WHERE\n" + - " B.Kanban IS NULL {0}"; + " B.Kanban IS NULL {0};\n" + + "DROP TABLE #TMP7;"; var _sql3 = string.Format(sql3, condition); @@ -920,6 +1428,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report contionCompare += " WHERE 1=1 "; } + #region 规则更改了不用了 ////红旗结算数据中,看板号+物料号没有重复的数据 //var sql10 = "SELECT DISTINCT\n" + // " t1.* \n" + @@ -1045,6 +1554,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report //{ // _lscopy.Add(itm); //} + #endregion //发运数据比较 @@ -1108,235 +1618,8 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report } - /// - /// 原始红旗未结数据(不包括有发货有结算中发货大于结算的数据) - /// - /// - /// - /// - /// - /// - /// - /// - public virtual List GetOriginalSettledDetailDiffReportList(string version, string materialCode, string begin, string end, string materialGroup, string iscontionversion) - { - - List _list = new List(); - - string condition = " "; - - if (!string.IsNullOrEmpty(begin)) - { - condition += string.Format(" and a.LastModificationTime>='{0}' ", begin); - } - if (!string.IsNullOrEmpty(end)) - { - condition += string.Format(" and a.LastModificationTime<='{0}' ", end); - } - - string contion = string.Empty; - //选中,是否过滤掉当期结算数据 - if (iscontionversion == "0") - { - contion += string.Format(" WHERE Version <'{0}' ", version); - } - else - { - contion += " WHERE 1=1 "; - } - string str = "SELECT\n" + - " * \n" + - "FROM\n" + - " (\n" + - " SELECT\n" + - " temp1.交货时间,\n" + - " isnull( temp1.交货单号, '' ) 交货单号,\n" + - " temp1.收货仓库,\n" + - " temp1.收货仓库描述,\n" + - " temp1.订货看板编号,\n" + - " temp1.订货零件号,\n" + - " temp1.Sap编码,\n" + - " temp1.[客户物料号],\n" + - " temp1.物料组,\n" + - " temp1.零件中文名称,\n" + - " temp1.发货数量,\n" + - " temp1.发货状态,\n" + - " temp1.外部单号,\n" + - " temp1.结算数量,\n" + - " temp1.结算单价,\n" + - " temp1.结算金额,\n" + - " isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + - " isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" + - " isnull( tt.Qty, 0 ) 退货数量,\n" + - " isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) AS 数量差异,\n" + - " temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + - " ( temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) ) * ( isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) ) AS 差异总金额 \n" + - " FROM\n" + - " (\n" + - " SELECT\n" + - " a.WmsBillNum AS 交货单号,\n" + - " CONVERT ( VARCHAR ( 100 ), a.LastModificationTime, 23 ) AS 交货时间 ,\n" + - " b.StorageLocation AS 收货仓库,\n" + - " b.StorageLocationDesc AS 收货仓库描述,\n" + - " a.Kanban AS 订货看板编号,\n" + - " b.MaterialCode AS 订货零件号,\n" + - " c.MaterialCode Sap编码,\n" + - " c.CustomerPartCode 客户物料号,\n" + - " c.MaterialDesc AS 零件中文名称,\n" + - " isnull( a.Qty, 0 ) AS 发货数量,\n" + - " isnull( a.State, 0 ) AS 发货状态,\n" + - " b.ExternalKanbanNumber AS 外部单号,\n" + - " isnull( b.Qty, 0 ) AS 结算数量,\n" + - " isnull( b.Price, 0 ) AS 结算单价,\n" + - " isnull( b.Amt, 0 ) AS 结算金额 ,\n" + - " C.EstimateTypeDesc AS 物料组 \n" + - " FROM\n" + - " Set_HQ_H_Kanban AS a\n" + - " LEFT OUTER JOIN (select * from Set_HQ_H_Platform {0}) AS b ON a.Kanban = b.HQHKanBan \n" + - " AND a.MaterialCode = b.MaterialCode\n" + - " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + - " WHERE\n" + - " b.HQHKanBan IS NULL \n" + - " AND b.MaterialCode IS NULL {1}\n" + - " ) AS temp1\n" + - " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" + - " LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" + - " AND temp1.订货看板编号 = tt.Code \n" + - " ) UNION1 " ; - var _sql = string.Format(str, contion, condition); - - - var _query = DbConnection.Query(_sql, null, null, true, 1200, null); - _list = _query.ToList(); - - return _list; - - } - - /// - /// 有发货有结算数据且发货数量大于结算数量 - /// - /// - /// - /// - /// - /// - /// - /// - public virtual List GetInnerJoinSettledDetailDiffReportList(string version, string materialCode, string begin, string end, string materialGroup, string iscontionversion) - { - - List _list = new List(); - - string condition = " "; - - if (!string.IsNullOrEmpty(begin)) - { - condition += string.Format(" and a.LastModificationTime>='{0}' ", begin); - } - if (!string.IsNullOrEmpty(end)) - { - condition += string.Format(" and a.LastModificationTime<='{0}' ", end); - } - - string contion = string.Empty; - //选中,是否过滤掉当期结算数据 - if (iscontionversion == "0") - { - contion += string.Format(" WHERE Version <'{0}' ", version); - } - else - { - contion += " WHERE 1=1 "; - } - string str = "SELECT\n" + - " * \n" + - "FROM\n" + - " (\n" + - " SELECT\n" + - " temp1.交货时间,\n" + - " isnull( temp1.交货单号, '' ) 交货单号,\n" + - " temp1.订货看板编号,\n" + - " temp1.订货零件号,\n" + - " temp1.Sap编码,\n" + - " temp1.[客户物料号],\n" + - " temp1.物料组,\n" + - " temp1.零件中文名称,\n" + - " temp1.发货数量,\n" + - " temp1.外部单号,\n" + - " temp1.结算数量,\n" + - " temp1.结算单价,\n" + - " temp1.结算金额,\n" + - " isnull( TEMP2.Price, 0 ) AS 发货定价,\n" + - " isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" + - " isnull( tt.Qty, 0 ) 退货数量,\n" + - " isnull( temp1.发货数量, 0 ) - isnull( temp1.结算数量, 0 ) AS 数量差异,\n" + - " temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异,\n" + - " ( temp1.结算单价 - ISNULL( TEMP2.Price, 0 ) ) * ( isnull( temp1.发货数量, 0 ) - isnull( tt.Qty, 0 ) ) AS 差异总金额 \n" + - " FROM\n" + - " (\n" + - " SELECT\n" + - " a.WmsBillNum AS 交货单号,\n" + - " CONVERT ( VARCHAR ( 100 ), a.LastModificationTime, 23 ) AS 交货时间 ,\n" + - " a.Kanban AS 订货看板编号,\n" + - " b.MaterialCode AS 订货零件号,\n" + - " c.MaterialCode Sap编码,\n" + - " c.CustomerPartCode 客户物料号,\n" + - " c.MaterialDesc AS 零件中文名称,\n" + - " isnull( a.Qty, 0 ) AS 发货数量,\n" + - " '' AS 外部单号,\n" + - " isnull( b.Qty, 0 ) AS 结算数量,\n" + - " 0 AS 结算单价,\n" + - " 0 AS 结算金额 ,\n" + - " C.EstimateTypeDesc AS 物料组 \n" + - " FROM\n" + - " ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode, WmsBillNum, LastModificationTime FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode, WmsBillNum, LastModificationTime ) AS a\n" + - " INNER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform {0} GROUP BY HQHKanBan, MaterialCode ) AS b ON a.Kanban = b.HQHKanBan \n" + - " AND a.MaterialCode = b.MaterialCode\n" + - " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + - " WHERE\n" + - " a.Qty> b.Qty {1}\n" + - " ) AS temp1\n" + - " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" + - " LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" + - " AND temp1.订货看板编号 = tt.Code \n" + - " ) UNION2"; - var _sql = string.Format(str, contion, condition); - - - var _query = DbConnection.Query(_sql, null, null, true, 1200, null); - _list = _query.ToList(); - - return _list; - - } - - - public virtual List GetDiffQtyList(string version) - { - List _list = new List(); - var str = - "SELECT\n" + - " temp1.MaterialCode 客户物料号,\n" + - " temp1.HQHKanBan 看板号 ,\n" + - " temp1.SettleQty 结算数量,\n" + - " ISNULL(temp2.Qty,0) 发货数量,\n" + - " ( ISNULL(temp1.SettleQty,0) - ISNULL(temp2.Qty,0) ) 差异数量 \n" + - "FROM\n" + - " ( SELECT SUM ( Qty ) SettleQty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform WHERE version = '{0}' GROUP BY HQHKanBan, MaterialCode ) temp1\n" + - " LEFT JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY Kanban, MaterialCode ) temp2 ON temp1.HQHKanBan = temp2.Kanban \n" + - " AND temp1.MaterialCode = temp2.MaterialCode \n" + - "WHERE\n" + - " temp1.SettleQty!= ISNULL(temp2.Qty,0)"; - str = string.Format(str, version); - - var _query = DbConnection.Query(str, null, null, true, 1200, null); - _list = _query.ToList(); - - - return _list; - - } + + public virtual List GetSharePartSettledDetailDiffReportList(string version, string materialCode, string begin, string end, string materialGroup) { @@ -1656,6 +1939,56 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report + } + + public class HQHSettledDetailDiffDto + { + + [ExporterHeader(DisplayName = "工厂")] + public string 工厂 { set; get; } + + [ExporterHeader(DisplayName = "外部单号")] + public string 外部单号 { set; get; } + [ExporterHeader(DisplayName = "验收单日期")] + public string 验收单日期 { set; get; } + [ExporterHeader(DisplayName = "收货仓库")] + public string 收货仓库 { set; get; } + [ExporterHeader(DisplayName = "收货仓库描述")] + public string 收货仓库描述 { set; get; } + [ExporterHeader(DisplayName = "物料组(车型)")] + public string 物料组 { set; get; } + [ExporterHeader(DisplayName = "订货看板编号")] + public string 订货看板编号 { set; get; } + [ExporterHeader(DisplayName = "订货零件号")] + public string 订货零件号 { set; get; } + [ExporterHeader(DisplayName = "Sap编码")] + public string Sap编码 { set; get; } + [ExporterHeader(DisplayName = "零件中文名称")] + public string 零件中文名称 { set; get; } + + [ExporterHeader(DisplayName = "结算数量")] + public decimal 结算数量 { set; get; } + [ExporterHeader(DisplayName = "结算单价")] + public decimal 结算单价 { set; get; } + [ExporterHeader(DisplayName = "结算金额")] + public decimal 结算金额 { set; get; } + [ExporterHeader(DisplayName = "发货定价")] + public decimal 发货定价 { set; get; } + + [ExporterHeader(DisplayName = "单价差异")] + public decimal 单价差异 { set; get; } + [ExporterHeader(DisplayName = "差异总金额")] + public decimal 差异总金额 { set; get; } + + [ExporterHeader(DisplayName = "看板编号")] + public string 看板编号 { set; get; } + + + + + + + } diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs index cb0b52aa..df80f958 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs @@ -175,8 +175,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report { strDate += string.Format(" and WMSActualGoodsDate<='{0}' ", endtime); } - - + //财务又要把 有发货有结算,发货数量大于结算数量加上,又变了 string sql = "SELECT\n" + " * \n" + "FROM\n" + @@ -216,13 +215,105 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " ) TEMP1\n" + " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode \n" + " ) UNION1\n" + - " LEFT JOIN temp_vwkanban UNION2 ON UNION1.Kanban= UNION2.[看板号] \n" + + " LEFT JOIN temp_vwkanban UNION2 ON UNION1.Kanban= UNION2.[看板号] \n" + " AND UNION1.CustomerPartCode= UNION2.[客户零件号] \n" + " WHERE\n" + " UNION2.[看板号] IS NULL \n" + " AND UNION2.[客户零件号] IS NULL \n" + - " ) aaa \n" + - " WHERE 1=1"; + " ) UNION1 UNION ALL\n" + + "SELECT\n" + + " * \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " * \n" + + " FROM\n" + + " (\n" + + " SELECT\n" + + " TEMP1.*,\n" + + " TEMP2.Price,\n" + + " ROUND( TEMP2.Price * TEMP1.DiffQty, 2 ) AS DiffAMT \n" + + " FROM\n" + + " (\n" + + " SELECT\n" + + " '' WmsBillNum,\n" + + " NULL BeginDate,\n" + + " a.Kanban,\n" + + " C.MaterialCode SapCode,\n" + + " C.MaterialDesc,\n" + + " C.CustomerPartCode,\n" + + " C.EstimateTypeDesc MaterialGroup,\n" + + " ISNULL( B.Qty, 0 ) SettleQty,\n" + + " ISNULL( a.WMSDeliveryQty, 0 ) WMSDeliveryQty,\n" + + " isnull( tt.qty, 0 ) BackQty,\n" + + " ( ISNULL( a.WMSDeliveryQty, 0 ) - ISNULL( b.Qty, 0 ) - isnull( tt.qty, 0 ) ) AS DiffQty \n" + + " FROM\n" + + " ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, Kanban FROM Set_WMSKanBanSettle WHERE 1 = 1 {1} GROUP BY MaterialCode, Kanban ) A\n" + + " INNER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, Extend1 AS MaterialCode FROM Set_WmsKanbanOutPutDetial {0} GROUP BY Kanban, Extend1 ) B ON A.Kanban = B.Kanban \n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n" + + " LEFT JOIN set_backQty AS tt ON a.Kanban = tt.Code \n" + + " AND c.MaterialCode = tt.MaterialCode \n" + + " WHERE\n" + + " a.WMSDeliveryQty> B.Qty \n" + + " AND ( a.WMSDeliveryQty- tt.Qty ) != B.Qty \n" + + " ) TEMP1\n" + + " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode \n" + + " ) UNION1\n" + + " LEFT JOIN temp_vwkanban UNION2 ON UNION1.Kanban= UNION2.[看板号] \n" + + " AND UNION1.CustomerPartCode= UNION2.[客户零件号] \n" + + " WHERE\n" + + " UNION2.[看板号] IS NULL \n" + + " AND UNION2.[客户零件号] IS NULL \n" + + " ) UNION2"; + + //更改方案一 + //string sql = "SELECT\n" + + //" * \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" * \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" TEMP1.*,\n" + + //" TEMP2.Price,\n" + + //" ROUND( TEMP2.Price * TEMP1.DiffQty, 2 ) AS DiffAMT \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" '' WmsBillNum,\n" + + //" NULL BeginDate,\n" + + //" a.Kanban,\n" + + //" C.MaterialCode SapCode,\n" + + //" C.MaterialDesc,\n" + + //" C.CustomerPartCode,\n" + + //" C.EstimateTypeDesc MaterialGroup,\n" + + //" ISNULL( B.Qty, 0 ) SettleQty,\n" + + //" ISNULL( a.WMSDeliveryQty, 0 ) WMSDeliveryQty,\n" + + //" isnull( tt.qty, 0 ) BackQty,\n" + + //" ( ISNULL( a.WMSDeliveryQty, 0 ) - ISNULL( b.Qty, 0 ) - isnull( tt.qty, 0 ) ) AS DiffQty \n" + + //" FROM\n" + + //" ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, Kanban FROM Set_WMSKanBanSettle WHERE 1 = 1 {1} GROUP BY MaterialCode, Kanban ) A\n" + + //" LEFT JOIN ( SELECT SUM ( Qty ) Qty, Kanban, Extend1 AS MaterialCode FROM Set_WmsKanbanOutPutDetial {0} GROUP BY Kanban, Extend1 ) B ON A.Kanban = B.Kanban \n" + + //" AND A.MaterialCode = B.MaterialCode\n" + + //" LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n" + + //" LEFT JOIN set_backQty AS tt ON a.Kanban = tt.Code \n" + + //" AND c.MaterialCode = tt.MaterialCode \n" + + //" WHERE\n" + + //" B.Kanban IS NULL \n" + + //" AND B.MaterialCode IS NULL \n" + + //" ) TEMP1\n" + + //" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode \n" + + //" ) UNION1\n" + + //" LEFT JOIN temp_vwkanban UNION2 ON UNION1.Kanban= UNION2.[看板号] \n" + + //" AND UNION1.CustomerPartCode= UNION2.[客户零件号] \n" + + //" WHERE\n" + + //" UNION2.[看板号] IS NULL \n" + + //" AND UNION2.[客户零件号] IS NULL \n" + + //" ) aaa \n" + + //" WHERE 1=1"; diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePartDapperReportRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePartDapperReportRepository.cs index acefb77f..6d6cdb11 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePartDapperReportRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePartDapperReportRepository.cs @@ -679,67 +679,185 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report { conditionDate += string.Format(" and SpareDate<='{0}' ", endtime); } - + //第三次更改,财务又要求把有发货有结算,发货数量 大于 结算数量 加上 string sqlString = "SELECT\n" + - " * \n" + - "FROM\n" + - " (\n" + - " SELECT\n" + - " temp1.交货单号,\n" + - " temp1.交货日期,\n" + - " temp1.采购订单号,\n" + - " temp1.SAP编码,\n" + - " temp1.物料代码,\n" + - " temp1.物料描述,\n" + - " temp1.发货数量,\n" + - " temp1.开票数量,\n" + - " temp1.收货与交货差异,\n" + - " ISNULL( temp3.Qty, 0 ) 退货数量,\n" + - " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际发货数量,\n" + - " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) - ISNULL( temp1.开票数量, 0 ) 未结数量,\n" + - " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + - " ISNULL( TEMP2.Price, 0 ) * ( ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) ) 实际发货总金额 \n" + - " FROM\n" + - " (\n" + - " SELECT\n" + - " '' AS 交货单号,\n" + - " NULL AS 交货日期,\n" + - " a.PurchaseOrderNo AS 采购订单号,\n" + - " c.MaterialCode AS SAP编码,\n" + - " c.CustomerPartCode AS 物料代码,\n" + - " c.MaterialDesc AS 物料描述,\n" + - " c.EstimateTypeDesc AS 物料组,\n" + - " ISNULL( a.ReceiptQty, 0 ) AS 发货数量,\n" + - " ISNULL( b.Qty, 0 ) AS 开票数量,\n" + - " ( ISNULL( a.ReceiptQty, 0 ) - ISNULL( b.Qty, 0 ) ) AS 收货与交货差异 \n" + - " FROM\n" + - " (\n" + - " SELECT SUM\n" + - " ( ReceiptQty ) AS ReceiptQty,\n" + - " PurchaseOrderNo,\n" + - " MaterialCode,\n" + - " SapCode \n" + - " FROM\n" + - " Set_WMSSparePart \n" + - " WHERE\n" + - " PurchaseOrderNo IS NOT NULL \n" + - " AND PurchaseOrderNo != '' {0}\n" + - " GROUP BY\n" + - " PurchaseOrderNo,\n" + - " MaterialCode,\n" + - " SapCode \n" + - " ) AS a\n" + - " LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode\n" + - " LEFT JOIN ( SELECT SUM ( Qty ) Qty, OrderBillNum, MaterialCode FROM Set_WmsSharePart90OutPutDetial WHERE State = 2 GROUP BY OrderBillNum, MaterialCode ) AS b ON a.PurchaseOrderNo= b.OrderBillNum \n" + - " AND a.SapCode = b.MaterialCode \n" + - " WHERE\n" + - " b.OrderBillNum IS NULL \n" + - " AND b.MaterialCode IS NULL \n" + - " ) AS temp1\n" + - " LEFT JOIN ( SELECT * FROM set_backQty ) temp3 ON temp1.采购订单号 = temp3.Code \n" + - " AND temp1.SAP编码= temp3.MaterialCode\n" + - " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" + - " ) unint1"; +" * \n" + +"FROM\n" + +" (\n" + +" SELECT\n" + +" temp1.交货单号,\n" + +" temp1.交货日期,\n" + +" temp1.采购订单号,\n" + +" temp1.SAP编码,\n" + +" temp1.物料代码,\n" + +" temp1.物料描述,\n" + +" temp1.发货数量,\n" + +" temp1.开票数量,\n" + +" temp1.收货与交货差异,\n" + +" ISNULL( temp3.Qty, 0 ) 退货数量,\n" + +" ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际发货数量,\n" + +" ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) - ISNULL( temp1.开票数量, 0 ) 未结数量,\n" + +" ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + +" ISNULL( TEMP2.Price, 0 ) * ( ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) ) 实际发货总金额 \n" + +" FROM\n" + +" (\n" + +" SELECT\n" + +" '' AS 交货单号,\n" + +" NULL AS 交货日期,\n" + +" a.PurchaseOrderNo AS 采购订单号,\n" + +" c.MaterialCode AS SAP编码,\n" + +" c.CustomerPartCode AS 物料代码,\n" + +" c.MaterialDesc AS 物料描述,\n" + +" c.EstimateTypeDesc AS 物料组,\n" + +" ISNULL( a.ReceiptQty, 0 ) AS 发货数量,\n" + +" ISNULL( b.Qty, 0 ) AS 开票数量,\n" + +" ( ISNULL( a.ReceiptQty, 0 ) - ISNULL( b.Qty, 0 ) ) AS 收货与交货差异 \n" + +" FROM\n" + +" (\n" + +" SELECT SUM\n" + +" ( ReceiptQty ) AS ReceiptQty,\n" + +" PurchaseOrderNo,\n" + +" MaterialCode,\n" + +" SapCode \n" + +" FROM\n" + +" Set_WMSSparePart \n" + +" WHERE\n" + +" PurchaseOrderNo IS NOT NULL \n" + +" AND PurchaseOrderNo != '' {0}\n" + +" GROUP BY\n" + +" PurchaseOrderNo,\n" + +" MaterialCode,\n" + +" SapCode \n" + +" ) AS a\n" + +" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode\n" + +" LEFT JOIN ( SELECT SUM ( Qty ) Qty, OrderBillNum, MaterialCode FROM Set_WmsSharePart90OutPutDetial WHERE State = 2 GROUP BY OrderBillNum, MaterialCode ) AS b ON a.PurchaseOrderNo= b.OrderBillNum \n" + +" AND a.SapCode = b.MaterialCode \n" + +" WHERE\n" + +" b.OrderBillNum IS NULL \n" + +" AND b.MaterialCode IS NULL \n" + +" ) AS temp1\n" + +" LEFT JOIN ( SELECT * FROM set_backQty ) temp3 ON temp1.采购订单号 = temp3.Code \n" + +" AND temp1.SAP编码= temp3.MaterialCode\n" + +" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" + +" ) unint1 UNION ALL\n" + +"SELECT\n" + +" * \n" + +"FROM\n" + +" (\n" + +" SELECT\n" + +" temp1.交货单号,\n" + +" temp1.交货日期,\n" + +" temp1.采购订单号,\n" + +" temp1.SAP编码,\n" + +" temp1.物料代码,\n" + +" temp1.物料描述,\n" + +" temp1.发货数量,\n" + +" temp1.开票数量,\n" + +" temp1.收货与交货差异,\n" + +" ISNULL( temp3.Qty, 0 ) 退货数量,\n" + +" ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际发货数量,\n" + +" ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) - ISNULL( temp1.开票数量, 0 ) 未结数量,\n" + +" ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + +" ISNULL( TEMP2.Price, 0 ) * ( ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) ) 实际发货总金额 \n" + +" FROM\n" + +" (\n" + +" SELECT\n" + +" '' AS 交货单号,\n" + +" NULL AS 交货日期,\n" + +" a.PurchaseOrderNo AS 采购订单号,\n" + +" c.MaterialCode AS SAP编码,\n" + +" c.CustomerPartCode AS 物料代码,\n" + +" c.MaterialDesc AS 物料描述,\n" + +" c.EstimateTypeDesc AS 物料组,\n" + +" ISNULL( a.ReceiptQty, 0 ) AS 发货数量,\n" + +" ISNULL( b.ReceiptQty, 0 ) AS 开票数量,\n" + +" ( ISNULL( b.ReceiptQty, 0 ) - ISNULL( a.ReceiptQty, 0 ) ) AS 收货与交货差异 \n" + +" FROM\n" + +" (\n" + +" SELECT SUM\n" + +" ( ReceiptQty ) AS ReceiptQty,\n" + +" PurchaseOrderNo,\n" + +" MaterialCode \n" + +" FROM\n" + +" Set_WMSSparePart \n" + +" WHERE\n" + +" PurchaseOrderNo IS NOT NULL \n" + +" AND PurchaseOrderNo != '' {0}\n" + +" GROUP BY\n" + +" PurchaseOrderNo,\n" + +" MaterialCode \n" + +" ) a\n" + +" INNER JOIN ( SELECT SUM ( Qty ) ReceiptQty, OrderBillNum, MaterialCode FROM Set_WmsSharePart90OutPutDetial WHERE State = 2 GROUP BY OrderBillNum, MaterialCode ) AS b ON a.PurchaseOrderNo= b.OrderBillNum \n" + +" AND a.MaterialCode = b.MaterialCode\n" + +" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n" + +" WHERE\n" + +" a.ReceiptQty> b.ReceiptQty \n" + +" ) AS temp1\n" + +" LEFT JOIN ( SELECT * FROM set_backQty ) temp3 ON temp1.采购订单号 = temp3.Code \n" + +" AND temp1.SAP编码= temp3.MaterialCode\n" + +" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" + +" ) unint2;"; + + //string sqlString = "SELECT\n" + + //" * \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" temp1.交货单号,\n" + + //" temp1.交货日期,\n" + + //" temp1.采购订单号,\n" + + //" temp1.SAP编码,\n" + + //" temp1.物料代码,\n" + + //" temp1.物料描述,\n" + + //" temp1.发货数量,\n" + + //" temp1.开票数量,\n" + + //" temp1.收货与交货差异,\n" + + //" ISNULL( temp3.Qty, 0 ) 退货数量,\n" + + //" ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际发货数量,\n" + + //" ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) - ISNULL( temp1.开票数量, 0 ) 未结数量,\n" + + //" ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + + //" ISNULL( TEMP2.Price, 0 ) * ( ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) ) 实际发货总金额 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" '' AS 交货单号,\n" + + //" NULL AS 交货日期,\n" + + //" a.PurchaseOrderNo AS 采购订单号,\n" + + //" c.MaterialCode AS SAP编码,\n" + + //" c.CustomerPartCode AS 物料代码,\n" + + //" c.MaterialDesc AS 物料描述,\n" + + //" c.EstimateTypeDesc AS 物料组,\n" + + //" ISNULL( a.ReceiptQty, 0 ) AS 发货数量,\n" + + //" ISNULL( b.Qty, 0 ) AS 开票数量,\n" + + //" ( ISNULL( a.ReceiptQty, 0 ) - ISNULL( b.Qty, 0 ) ) AS 收货与交货差异 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT SUM\n" + + //" ( ReceiptQty ) AS ReceiptQty,\n" + + //" PurchaseOrderNo,\n" + + //" MaterialCode,\n" + + //" SapCode \n" + + //" FROM\n" + + //" Set_WMSSparePart \n" + + //" WHERE\n" + + //" PurchaseOrderNo IS NOT NULL \n" + + //" AND PurchaseOrderNo != '' {0}\n" + + //" GROUP BY\n" + + //" PurchaseOrderNo,\n" + + //" MaterialCode,\n" + + //" SapCode \n" + + //" ) AS a\n" + + //" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode\n" + + //" LEFT JOIN ( SELECT SUM ( Qty ) Qty, OrderBillNum, MaterialCode FROM Set_WmsSharePart90OutPutDetial WHERE State = 2 GROUP BY OrderBillNum, MaterialCode ) AS b ON a.PurchaseOrderNo= b.OrderBillNum \n" + + //" AND a.SapCode = b.MaterialCode \n" + + //" WHERE\n" + + //" b.OrderBillNum IS NULL \n" + + //" AND b.MaterialCode IS NULL \n" + + //" ) AS temp1\n" + + //" LEFT JOIN ( SELECT * FROM set_backQty ) temp3 ON temp1.采购订单号 = temp3.Code \n" + + //" AND temp1.SAP编码= temp3.MaterialCode\n" + + //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" + + //" ) unint1"; #region old //string sqlString = "SELECT\n" + diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/HQHSettledDetailDiffExportService.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/HQHSettledDetailDiffExportService.cs index a503771f..32aa200c 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/HQHSettledDetailDiffExportService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/HQHSettledDetailDiffExportService.cs @@ -9,6 +9,7 @@ using TaskJob.EventArgs; using TaskJob.Interfaces; using Volo.Abp.BlobStoring; using Volo.Abp.DependencyInjection; +using Volo.Abp.Uow; using Win.Sfs.BaseData.ImportExcelCommon; using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; @@ -44,6 +45,7 @@ namespace SettleAccount.Job.Services.Report _dapperRepository = dapperRepository; } + [UnitOfWork(false)] public string ExportFile(Guid id, List exportName, List p_list) { var _filename = exportName.FirstOrDefault();