|
|
@ -26,14 +26,22 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report |
|
|
|
public string MaterialDesc { set; get; } |
|
|
|
|
|
|
|
|
|
|
|
[ExporterHeader(DisplayName = "通用编码(生产码)", IsBold = true)] |
|
|
|
public string VinCode { set; get; } |
|
|
|
[ExporterHeader(DisplayName = "库位", IsBold = true)] |
|
|
|
public string ErpToLoc { set; get; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ExporterHeader(DisplayName = "库存余额数量", IsBold = true)] |
|
|
|
[ExporterHeader(DisplayName = "往年数量", IsBold = true)] |
|
|
|
public string HistoryQty { set; get; } |
|
|
|
|
|
|
|
[ExporterHeader(DisplayName = "当年数量", IsBold = true)] |
|
|
|
public string BalanceQty { set; get; } |
|
|
|
[ExporterHeader(DisplayName = "有结无发合计", IsBold = true)] |
|
|
|
|
|
|
|
[ExporterHeader(DisplayName = "库存余额数量", IsBold = true)] |
|
|
|
public string InventQty { set; get; } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ExporterHeader(DisplayName = "有结无发合计", IsBold = true)] |
|
|
|
public string SettleQty { set; get; } |
|
|
|
|
|
|
|
[ExporterHeader(DisplayName = "1月发票", IsBold = true)] |
|
|
@ -327,70 +335,109 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report |
|
|
|
//"drop table #temp_js\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"; |
|
|
|
"\n" + |
|
|
|
"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" + |
|
|
|
"\n" + |
|
|
|
"select * into #temp_history from\n" + |
|
|
|
"(\n" + |
|
|
|
"SELECT ErpToLoc,RealPartCode,SUM(Qty) Qty FROM Set_VmiLog WHERE VERSION <=cast(@BeforeYear as varchar(50))+'12' GROUP BY ErpToLoc,RealPartCode\n" + |
|
|
|
") t3\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 isnull(tt1.ErpToLoc,tt2.ErpToLoc) ErpToLoc,isnull(tt1.RealPartCode,tt2.RealPartCode) RealPartCode\n" + |
|
|
|
",ISNULL(tt2.Qty,0) HistoryQty\n" + |
|
|
|
",isnull(tt1.BalanceQty,0) BalanceQty\n" + |
|
|
|
",ISNULL(tt2.Qty,0) +\n" + |
|
|
|
"isnull(tt1.BalanceQty,0) InventQty\n" + |
|
|
|
",isnull(tt1.January ,0) January\n" + |
|
|
|
",isnull(tt1.SettleJanuary ,0) SettleJanuary\n" + |
|
|
|
",isnull(tt1.February ,0) February\n" + |
|
|
|
",isnull(tt1.SettleFebruary ,0) SettleFebruary\n" + |
|
|
|
",isnull(tt1.March ,0) March\n" + |
|
|
|
",isnull(tt1.SettleMarch ,0) SettleMarch\n" + |
|
|
|
",isnull(tt1.April ,0) April\n" + |
|
|
|
",isnull(tt1.SettleApril ,0) SettleApril\n" + |
|
|
|
",isnull(tt1.May ,0) May\n" + |
|
|
|
",isnull(tt1.SettleMay ,0) SettleMay\n" + |
|
|
|
",isnull(tt1.June ,0) June\n" + |
|
|
|
",isnull(tt1.SettleJune ,0) SettleJune\n" + |
|
|
|
",isnull(tt1.July ,0) July\n" + |
|
|
|
",isnull(tt1.SettleJuly ,0) SettleJuly\n" + |
|
|
|
",isnull(tt1.August ,0) August\n" + |
|
|
|
",isnull(tt1.SettleAugust ,0) SettleAugust\n" + |
|
|
|
",isnull(tt1.September ,0) September\n" + |
|
|
|
",isnull(tt1.SettleSeptember ,0) SettleSeptember\n" + |
|
|
|
",isnull(tt1.October ,0) October\n" + |
|
|
|
",isnull(tt1.SettleOctober ,0) SettleOctober\n" + |
|
|
|
",isnull(tt1.November ,0) November\n" + |
|
|
|
",isnull(tt1.SettleNovember ,0) SettleNovember\n" + |
|
|
|
",isnull(tt1.December ,0) December\n" + |
|
|
|
",isnull(tt1.SettleDecember ,0) SettleDecember\n" + |
|
|
|
"from\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" + |
|
|
|
") tt1\n" + |
|
|
|
"full join #temp_history tt2 on tt1.RealPartCode=tt2.RealPartCode and tt1.ErpToLoc=tt2.ErpToLoc\n" + |
|
|
|
"drop table #temp_js\n" + |
|
|
|
"drop table #temp_bh\n" + |
|
|
|
"drop table #temp_history\n"; |
|
|
|
|
|
|
|
|
|
|
|
var query = string.Format(sql, p_year); |
|
|
@ -398,6 +445,22 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report |
|
|
|
var entities = DbConnection.Query<BalanceSum>(query,null,null,false,1200,null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var list=DbConnection.Query<BalanceSum>("select distinct ErpMaterialCode RealPartCode, MaterialDesc from Set_relationship").ToList(); |
|
|
|
|
|
|
|
foreach (var itm in entities) |
|
|
|
{ |
|
|
|
var first= list.FirstOrDefault(p => p.RealPartCode == itm.RealPartCode); |
|
|
|
if (first != null) |
|
|
|
{ |
|
|
|
itm.MaterialDesc = first.MaterialDesc; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return entities.ToList(); |
|
|
|
} |
|
|
|
|
|
|
|