Browse Source

添加税率,修改按年统计

master
学 赵 12 months ago
parent
commit
6cde8b78e7
  1. 1
      code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/appsettings.json
  2. 14
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs
  3. 484
      code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/BalanceSum/BalanceSumDapperRepository.cs

1
code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/appsettings.json

@ -62,6 +62,7 @@
} }
] ]
}, },
"Tax": "0.13",
"RabbitMQ": { "RabbitMQ": {
"Connections": { "Connections": {

14
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.Data.SqlClient; using System.Data.SqlClient;
@ -77,6 +77,9 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
private readonly TaskJobService _service; private readonly TaskJobService _service;
private readonly Volo.Abp.ObjectMapping.IObjectMapper _maper; private readonly Volo.Abp.ObjectMapping.IObjectMapper _maper;
protected readonly IExcelImportAppService _excelImportService; protected readonly IExcelImportAppService _excelImportService;
private readonly IConfiguration _config;
public VmiAppService(IConfiguration cfg, public VmiAppService(IConfiguration cfg,
IServiceProvider serviceProvider, IServiceProvider serviceProvider,
IGuidGenerator guidGenerator, IGuidGenerator guidGenerator,
@ -89,12 +92,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
ICurrentUser currentUser, ICurrentUser currentUser,
ILogger<VmiAppService> logger, ILogger<VmiAppService> logger,
IExcelImportAppService excelImportService, IExcelImportAppService excelImportService,
TaskJobService service TaskJobService service,
IConfiguration config
) )
{ {
_maper = maper; _config = config;
this._codeRepository = codeRepository; this._codeRepository = codeRepository;
this._cfg = cfg; this._cfg = cfg;
this._guidGenerator = guidGenerator; this._guidGenerator = guidGenerator;
@ -108,6 +112,10 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
_service = service; _service = service;
LinqToDBForEFTools.Initialize(); LinqToDBForEFTools.Initialize();
_excelImportService = excelImportService; _excelImportService = excelImportService;
string tax = config["Tax"];
} }
/// <summary> /// <summary>

484
code/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/BalanceSum/BalanceSumDapperRepository.cs

@ -117,216 +117,280 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
/// <returns></returns> /// <returns></returns>
public virtual List<BalanceSum> GetBalanceSum(string p_year) public virtual List<BalanceSum> GetBalanceSum(string p_year)
{ {
var sql = "declare @lastyear as varchar(50)\n" + //var sql = "declare @lastyear as varchar(50)\n" +
"declare @lastTime as varchar(50)\n" + //"declare @lastTime as varchar(50)\n" +
"declare @BeforeYear as varchar(50)\n" + //"declare @BeforeYear as varchar(50)\n" +
"Set @lastyear='{0}'\n" + //"Set @lastyear='{0}'\n" +
"Set @BeforeYear=CAST(@lastyear as int)-1\n" + //"Set @BeforeYear=CAST(@lastyear as int)-1\n" +
"Set @lastTime=dateadd(ms,-3,DATEADD(yy,DATEDIFF(yy,0,@lastyear+'01'+'01')+1, 0))\n" + //"Set @lastTime=dateadd(ms,-3,DATEADD(yy,DATEDIFF(yy,0,@lastyear+'01'+'01')+1, 0))\n" +
"select * into #temp_js from (\n" + //"select * into #temp_js from (\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'01' version1 from (\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'01' version1 from (\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@BeforeYear+'-12-26 08:00:00' AND BillTime<=@lastyear+'-01-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@BeforeYear+'-12-26 08:00:00' AND BillTime<=@lastyear+'-01-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'02' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'02' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-01-26 08:00:00' AND BillTime<=@lastyear+'-02-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-01-26 08:00:00' AND BillTime<=@lastyear+'-02-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'03' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'03' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-02-26 08:00:00' AND BillTime<=@lastyear+'-03-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-02-26 08:00:00' AND BillTime<=@lastyear+'-03-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'04' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'04' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-03-26 08:00:00' AND BillTime<=@lastyear+'-04-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-03-26 08:00:00' AND BillTime<=@lastyear+'-04-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'05' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'05' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-04-26 08:00:00' AND BillTime<=@lastyear+'-05-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-04-26 08:00:00' AND BillTime<=@lastyear+'-05-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'06' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'06' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-05-26 08:00:00' AND BillTime<=@lastyear+'-06-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-05-26 08:00:00' AND BillTime<=@lastyear+'-06-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'07' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'07' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-06-26 08:00:00' AND BillTime<=@lastyear+'-07-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-06-26 08:00:00' AND BillTime<=@lastyear+'-07-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'09' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'09' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-07-26 08:00:00' AND BillTime<=@lastyear+'-08-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-07-26 08:00:00' AND BillTime<=@lastyear+'-08-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'09' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'09' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-08-26 08:00:00' AND BillTime<=@lastyear+'-09-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-08-26 08:00:00' AND BillTime<=@lastyear+'-09-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"union all\n" + //"union all\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'10' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'10' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-09-26 08:00:00' AND BillTime<=@lastyear+'-10-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-09-26 08:00:00' AND BillTime<=@lastyear+'-10-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"union all\n" + //"union all\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'11' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'11' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-10-26 08:00:00' AND BillTime<=@lastyear+'-11-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-10-26 08:00:00' AND BillTime<=@lastyear+'-11-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"union all\n" + //"union all\n" +
"select sum(changedQty) changedqty,RealPartCode,ErpToLoc,@lastyear+'12' version1 from\n" + //"select sum(changedQty) changedqty,RealPartCode,ErpToLoc,@lastyear+'12' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-11-26 08:00:00' AND BillTime<=@lastyear+'-12-26 07:59:59' and (LogType>200 OR LogType<200)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-11-26 08:00:00' AND BillTime<=@lastyear+'-12-26 07:59:59' and (LogType>200 OR LogType<200)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"union all\n" + //"union all\n" +
"select sum(changedQty) changedqty,RealPartCode,ErpToLoc, version1 from\n" + //"select sum(changedQty) changedqty,RealPartCode,ErpToLoc, version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc,FORMAT(BillTime,'yyyyMM') version1\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc,FORMAT(BillTime,'yyyyMM') version1\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where LogType=200\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where LogType=200\n" +
") a group by RealPartCode,ErpToLoc,version1\n" + //") a group by RealPartCode,ErpToLoc,version1\n" +
") temp\n" + //") temp\n" +
"PIVOT ( SUM( changedqty )\n" + //"PIVOT ( SUM( changedqty )\n" +
"FOR VERSION1 IN ([{0}01],[{0}02],[{0}03],[{0}04],[{0}05],[{0}06],[{0}07],[{0}08],[{0}09],[{0}10],[{0}11],[{0}12]) ) b\n" + //"FOR VERSION1 IN ([{0}01],[{0}02],[{0}03],[{0}04],[{0}05],[{0}06],[{0}07],[{0}08],[{0}09],[{0}10],[{0}11],[{0}12]) ) b\n" +
"select * into #temp_bh from (\n" + //"select * into #temp_bh from (\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'01' version1 from (\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'01' version1 from (\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@BeforeYear+'-12-26 08:00:00' AND BillTime<=@lastyear+'-01-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@BeforeYear+'-12-26 08:00:00' AND BillTime<=@lastyear+'-01-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'02' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'02' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-01-26 08:00:00' AND BillTime<=@lastyear+'-02-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-01-26 08:00:00' AND BillTime<=@lastyear+'-02-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'03' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'03' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-02-26 08:00:00' AND BillTime<=@lastyear+'-03-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-02-26 08:00:00' AND BillTime<=@lastyear+'-03-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'04' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'04' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-03-26 08:00:00' AND BillTime<=@lastyear+'-04-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-03-26 08:00:00' AND BillTime<=@lastyear+'-04-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'05' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'05' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-04-26 08:00:00' AND BillTime<=@lastyear+'-05-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-04-26 08:00:00' AND BillTime<=@lastyear+'-05-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'06' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'06' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-05-26 08:00:00' AND BillTime<=@lastyear+'-06-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-05-26 08:00:00' AND BillTime<=@lastyear+'-06-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'07' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'07' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-06-26 08:00:00' AND BillTime<=@lastyear+'-07-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-06-26 08:00:00' AND BillTime<=@lastyear+'-07-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'08' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'08' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-07-26 08:00:00' AND BillTime<=@lastyear+'-08-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-07-26 08:00:00' AND BillTime<=@lastyear+'-08-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"UNION ALL\n" + //"UNION ALL\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'09' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'09' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-08-26 08:00:00' AND BillTime<=@lastyear+'-09-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-08-26 08:00:00' AND BillTime<=@lastyear+'-09-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"union all\n" + //"union all\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'10' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'10' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-09-26 08:00:00' AND BillTime<=@lastyear+'-10-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-09-26 08:00:00' AND BillTime<=@lastyear+'-10-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"union all\n" + //"union all\n" +
"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'11' version1 from\n" + //"select sum(changedQty) ChangedQty,RealPartCode,ErpToLoc,@lastyear+'11' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-10-26 08:00:00' AND BillTime<=@lastyear+'-11-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-10-26 08:00:00' AND BillTime<=@lastyear+'-11-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"union all\n" + //"union all\n" +
"select sum(changedQty) changedqty,RealPartCode,ErpToLoc,@lastyear+'12' version1 from\n" + //"select sum(changedQty) changedqty,RealPartCode,ErpToLoc,@lastyear+'12' version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-11-26 08:00:00' AND BillTime<=@lastyear+'-12-26 07:59:59' and (LogType=500)\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where BillTime>=@lastyear+'-11-26 08:00:00' AND BillTime<=@lastyear+'-12-26 07:59:59' and (LogType=500)\n" +
") a group by RealPartCode,ErpToLoc\n" + //") a group by RealPartCode,ErpToLoc\n" +
"union all\n" + //"union all\n" +
"select sum(changedQty) changedqty,RealPartCode,ErpToLoc, version1 from\n" + //"select sum(changedQty) changedqty,RealPartCode,ErpToLoc, version1 from\n" +
"(\n" + //"(\n" +
"SELECT ChangedQty,RealPartCode,ErpToLoc,FORMAT(BillTime,'yyyyMM') version1\n" + //"SELECT ChangedQty,RealPartCode,ErpToLoc,FORMAT(BillTime,'yyyyMM') version1\n" +
"FROM [BQ_SA].[dbo].[Set_VmiLog] where LogType=200 and ReMark ='有结算无发运'\n" + //"FROM [BQ_SA].[dbo].[Set_VmiLog] where LogType=200 and ReMark ='有结算无发运'\n" +
") a group by RealPartCode,ErpToLoc,version1\n" + //") a group by RealPartCode,ErpToLoc,version1\n" +
") temp\n" + //") temp\n" +
"\n" + //"\n" +
"PIVOT ( SUM( changedqty )\n" + //"PIVOT ( SUM( changedqty )\n" +
"FOR VERSION1 IN ([{0}01],[{0}02],[{0}03],[{0}04],[{0}05],[{0}06],[{0}07],[{0}08],[{0}09],[{0}10],[{0}11],[{0}12]) ) b\n" + //"FOR VERSION1 IN ([{0}01],[{0}02],[{0}03],[{0}04],[{0}05],[{0}06],[{0}07],[{0}08],[{0}09],[{0}10],[{0}11],[{0}12]) ) b\n" +
"select\n" + //"select\n" +
"isnull(a.ErpToLoc,b.ErpToLoc) ErpToLoc,\n" + //"isnull(a.ErpToLoc,b.ErpToLoc) ErpToLoc,\n" +
"Isnull(b.RealPartCode,a.RealPartCode) RealPartCode,\n" + //"Isnull(b.RealPartCode,a.RealPartCode) RealPartCode,\n" +
"isnull(a.[{0}01],0)+\n" + //"isnull(a.[{0}01],0)+\n" +
"isnull(a.[{0}02],0)+\n" + //"isnull(a.[{0}02],0)+\n" +
"isnull(a.[{0}03],0)+\n" + //"isnull(a.[{0}03],0)+\n" +
"isnull(a.[{0}04],0)+\n" + //"isnull(a.[{0}04],0)+\n" +
"isnull(a.[{0}05],0)+\n" + //"isnull(a.[{0}05],0)+\n" +
"isnull(a.[{0}06],0)+\n" + //"isnull(a.[{0}06],0)+\n" +
"isnull(a.[{0}07],0)+\n" + //"isnull(a.[{0}07],0)+\n" +
"isnull(a.[{0}08],0)+\n" + //"isnull(a.[{0}08],0)+\n" +
"isnull(a.[{0}09],0)+\n" + //"isnull(a.[{0}09],0)+\n" +
"isnull(a.[{0}10],0)+\n" + //"isnull(a.[{0}10],0)+\n" +
"isnull(a.[{0}11],0)+\n" + //"isnull(a.[{0}11],0)+\n" +
"isnull(a.[{0}12],0) BalanceQty ,\n" + //"isnull(a.[{0}12],0) BalanceQty ,\n" +
"isnull(b.[{0}01],0) +\n" + //"isnull(b.[{0}01],0) +\n" +
"isnull(b.[{0}02],0) +\n" + //"isnull(b.[{0}02],0) +\n" +
"isnull(b.[{0}03],0) +\n" + //"isnull(b.[{0}03],0) +\n" +
"isnull(b.[{0}04],0) +\n" + //"isnull(b.[{0}04],0) +\n" +
"isnull(b.[{0}05],0) +\n" + //"isnull(b.[{0}05],0) +\n" +
"isnull(b.[{0}06],0) +\n" + //"isnull(b.[{0}06],0) +\n" +
"isnull(b.[{0}07],0) +\n" + //"isnull(b.[{0}07],0) +\n" +
"isnull(b.[{0}08],0) +\n" + //"isnull(b.[{0}08],0) +\n" +
"isnull(b.[{0}09],0) +\n" + //"isnull(b.[{0}09],0) +\n" +
"isnull(b.[{0}10],0) +\n" + //"isnull(b.[{0}10],0) +\n" +
"isnull(b.[{0}11],0) +\n" + //"isnull(b.[{0}11],0) +\n" +
"isnull(b.[{0}12],0) SettleQty,\n" + //"isnull(b.[{0}12],0) SettleQty,\n" +
"isnull(a.[{0}01],0) January,isnull(b.[{0}01],0) SettleJanuary,\n" + //"isnull(a.[{0}01],0) January,isnull(b.[{0}01],0) SettleJanuary,\n" +
"isnull(a.[{0}02],0) February,isnull(b.[{0}02],0) SettleFebruary,\n" + //"isnull(a.[{0}02],0) February,isnull(b.[{0}02],0) SettleFebruary,\n" +
"isnull(a.[{0}03],0) March,isnull(b.[{0}03],0) SettleMarch,\n" + //"isnull(a.[{0}03],0) March,isnull(b.[{0}03],0) SettleMarch,\n" +
"isnull(a.[{0}04],0) April,isnull(b.[{0}04],0) SettleApril,\n" + //"isnull(a.[{0}04],0) April,isnull(b.[{0}04],0) SettleApril,\n" +
"isnull(a.[{0}05],0) May,isnull(b.[{0}05],0) SettleMay,\n" + //"isnull(a.[{0}05],0) May,isnull(b.[{0}05],0) SettleMay,\n" +
"isnull(a.[{0}06],0) June,isnull(b.[{0}06],0) SettleJune,\n" + //"isnull(a.[{0}06],0) June,isnull(b.[{0}06],0) SettleJune,\n" +
"isnull(a.[{0}07],0) July,isnull(b.[{0}07],0) SettleJuly,\n" + //"isnull(a.[{0}07],0) July,isnull(b.[{0}07],0) SettleJuly,\n" +
"isnull(a.[{0}08],0) August,isnull(b.[{0}08],0) SettleAugust,\n" + //"isnull(a.[{0}08],0) August,isnull(b.[{0}08],0) SettleAugust,\n" +
"isnull(a.[{0}09],0) September,isnull(b.[{0}09],0) SettleSeptember,\n" + //"isnull(a.[{0}09],0) September,isnull(b.[{0}09],0) SettleSeptember,\n" +
"isnull(a.[{0}10],0) October,isnull(b.[{0}10],0) SettleOctober,\n" + //"isnull(a.[{0}10],0) October,isnull(b.[{0}10],0) SettleOctober,\n" +
"isnull(a.[{0}11],0) November,isnull(b.[{0}11],0) SettleNovember,\n" + //"isnull(a.[{0}11],0) November,isnull(b.[{0}11],0) SettleNovember,\n" +
"isnull(a.[{0}12],0) December,isnull(b.[{0}12],0) SettleDecember \n" + //"isnull(a.[{0}12],0) December,isnull(b.[{0}12],0) SettleDecember \n" +
"from #temp_js a full join #temp_bh b on a.ErpToLoc=b.ErpToLoc and a.RealPartCode=b.RealPartCode\n" + //"from #temp_js a full join #temp_bh b on a.ErpToLoc=b.ErpToLoc and a.RealPartCode=b.RealPartCode\n" +
"drop table #temp_js\n" + //"drop table #temp_js\n" +
"drop table #temp_bh\n"; //"drop table #temp_bh\n";
var sql=
"declare @lastyear as varchar(50)\n" +
"declare @lastTime as varchar(50)\n" +
"declare @BeforeYear as varchar(50)\n" +
"Set @lastyear='{0}'\n" +
"Set @BeforeYear=CAST(@lastyear as int)-1\n" +
"Set @lastTime=dateadd(ms,-3,DATEADD(yy,DATEDIFF(yy,0,@lastyear+'01'+'01')+1, 0))\n" +
"select * into #temp_js from (\n" +
"select\n" +
"version,ErpToLoc,realpartcode,changedQty from Set_VmiLog\n" +
") temp\n" +
"PIVOT ( SUM( changedqty )\n" +
"FOR VERSION IN ([{0}01],[{0}02],[{0}03],[{0}04],[{0}05],[{0}06],[{0}07],[{0}08],[{0}09],[{0}10],[{0}11],[{0}12]) ) b\n" +
"select * into #temp_bh from (\n" +
"select\n" +
"version,ErpToLoc,realpartcode,changedQty from Set_VmiLog where LogType=500\n" +
"union all\n" +
"select version,ErpToLoc,realpartcode,changedQty from Set_VmiLog where LogType=200 and ReMark ='有结算无发运'\n" +
"\n" +
") temp\n" +
"\n" +
"PIVOT ( SUM( changedqty )\n" +
"FOR VERSION IN ([{0}01],[{0}02],[{0}03],[{0}04],[{0}05],[{0}06],[{0}07],[{0}08],[{0}09],[{0}10],[{0}11],[{0}12]) ) b\n" +
"select\n" +
"isnull(a.ErpToLoc,b.ErpToLoc) ErpToLoc,\n" +
"Isnull(b.RealPartCode,a.RealPartCode) RealPartCode,\n" +
"isnull(a.[{0}01],0)+\n" +
"isnull(a.[{0}02],0)+\n" +
"isnull(a.[{0}03],0)+\n" +
"isnull(a.[{0}04],0)+\n" +
"isnull(a.[{0}05],0)+\n" +
"isnull(a.[{0}06],0)+\n" +
"isnull(a.[{0}07],0)+\n" +
"isnull(a.[{0}08],0)+\n" +
"isnull(a.[{0}09],0)+\n" +
"isnull(a.[{0}10],0)+\n" +
"isnull(a.[{0}11],0)+\n" +
"isnull(a.[{0}12],0) BalanceQty ,\n" +
"isnull(b.[{0}01],0) +\n" +
"isnull(b.[{0}02],0) +\n" +
"isnull(b.[{0}03],0) +\n" +
"isnull(b.[{0}04],0) +\n" +
"isnull(b.[{0}05],0) +\n" +
"isnull(b.[{0}06],0) +\n" +
"isnull(b.[{0}07],0) +\n" +
"isnull(b.[{0}08],0) +\n" +
"isnull(b.[{0}09],0) +\n" +
"isnull(b.[{0}10],0) +\n" +
"isnull(b.[{0}11],0) +\n" +
"isnull(b.[{0}12],0) SettleQty,\n" +
"isnull(a.[{0}01],0) January,isnull(b.[{0}01],0) SettleJanuary,\n" +
"isnull(a.[{0}02],0) February,isnull(b.[{0}02],0) SettleFebruary,\n" +
"isnull(a.[{0}03],0) March,isnull(b.[{0}03],0) SettleMarch,\n" +
"isnull(a.[{0}04],0) April,isnull(b.[{0}04],0) SettleApril,\n" +
"isnull(a.[{0}05],0) May,isnull(b.[{0}05],0) SettleMay,\n" +
"isnull(a.[{0}06],0) June,isnull(b.[{0}06],0) SettleJune,\n" +
"isnull(a.[{0}07],0) July,isnull(b.[{0}07],0) SettleJuly,\n" +
"isnull(a.[{0}08],0) August,isnull(b.[{0}08],0) SettleAugust,\n" +
"isnull(a.[{0}09],0) September,isnull(b.[{0}09],0) SettleSeptember,\n" +
"isnull(a.[{0}10],0) October,isnull(b.[{0}10],0) SettleOctober,\n" +
"isnull(a.[{0}11],0) November,isnull(b.[{0}11],0) SettleNovember,\n" +
"isnull(a.[{0}12],0) December,isnull(b.[{0}12],0) SettleDecember\n" +
"from #temp_js a full join #temp_bh b on a.ErpToLoc=b.ErpToLoc and a.RealPartCode=b.RealPartCode\n" +
"drop table #temp_js\n" +
"drop table #temp_bh;\n";
var query = string.Format(sql, p_year); var query = string.Format(sql, p_year);

Loading…
Cancel
Save