Skip to content

Commit 8f79896

Browse files
committed
feat: 669
Merged PR 231: filtri tipo contratto Related work items: #669
1 parent 62b0b84 commit 8f79896

File tree

41 files changed

+458
-201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+458
-201
lines changed

src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/Persistence/DbContextFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System.Data;
2+
using Azure.Core;
3+
using Azure.Identity;
24
using Microsoft.Data.SqlClient;
35
using PortaleFatture.BE.Infrastructure.Common.Persistence.Schemas;
46

@@ -18,7 +20,7 @@ public async Task<IDbContext> Create(
1820
IsolationLevel isolationLevel = IsolationLevel.ReadCommitted,
1921
CancellationToken ct = default)
2022
{
21-
var conn = new SqlConnection(_connectionString);
23+
var conn = new SqlConnection(_connectionString);
2224
await conn.OpenAsync(ct);
2325
return new DbContext(conn, _schema, transactional, isolationLevel);
2426
}

src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/SEND/DatiRel/Dto/RelQueryDto.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ public class RelQueryDto
1212
public byte? Caricata { get; set; }
1313
public string? Azione { get; set; }
1414
public string[]? EntiIds { get; set; } = null;
15-
public string? FlagConguaglio { get; set; }
15+
public string? FlagConguaglio { get; set; }
16+
public int? FkIdTipoContratto { get; set; }
1617
}

src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/SEND/DatiRel/Queries/Persistence/Builder/RelTestataQuadraturaSQLBuilder.cs

Lines changed: 102 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ SELECT Count(nc.[internal_organization_id])
77
FROM [pfd].[NotificheCount] as nc
88
left outer join pfd.Enti as e
99
ON e.InternalIstitutionId = nc.internal_organization_id
10+
left outer join pfd.Contratti as cc
11+
ON cc.internalistitutionid = e.InternalIstitutionId
1012
left outer join pfd.RelTestata as r
1113
ON r.internal_organization_id = nc.internal_organization_id
1214
AND r.contract_id = nc.contract_id
1315
AND r.year= nc.year
1416
AND r.month = nc.month
15-
AND r.TipologiaFattura = @TipologiaFattura
17+
AND (@TipologiaFattura IS NULL OR r.TipologiaFattura = @TipologiaFattura)
1618
left outer join pfd.ContestazioniStorico as c
1719
ON c.internal_organization_id = nc.internal_organization_id
1820
AND c.contract_id = nc.contract_id
1921
AND c.year= nc.year
2022
AND c.month = nc.month
21-
AND c.TipologiaFattura=@TipologiaFattura
23+
AND (@TipologiaFattura IS NULL OR c.TipologiaFattura = @TipologiaFattura)
2224
";
2325
private static string _sqlNoTipologiaFattura = @"
2426
SELECT
@@ -33,6 +35,7 @@ nc.[internal_organization_id] as IdEnte
3335
,nc.[TotaleNotificheDigitali] as NotificheTotaleNotificheDigitali
3436
,nc.[Totale] as NotificheTotale
3537
,nc.[TotaleNotificheAnalogiche] + nc.[TotaleNotificheDigitali] as NotificheTotaleNotifiche
38+
,r.TipologiaFattura as RelTipologiaFattura
3639
,r.TotaleAnalogico as RelTotaleAnalogico
3740
,r.TotaleDigitale as RelTotaleDigitale
3841
,r.TotaleNotificheAnalogiche as RelTotaleNotificheAnalogiche
@@ -45,6 +48,7 @@ nc.[internal_organization_id] as IdEnte
4548
,r.AsseverazioneTotaleNotificheDigitali as RelAsseTotaleNotificheDigitali
4649
,r.AsseverazioneTotale as RelAsseTotale
4750
,ISNULL(r.AsseverazioneTotaleNotificheAnalogiche,0) + ISNULL(r.AsseverazioneTotaleNotificheDigitali,0) as RelAsseTotaleNotifiche
51+
,r.TipologiaFattura as TipologiaFattura
4852
,ISNULL(c.[TotaleAnalogico],0) as ContestazioniTotaleAnalogico
4953
,ISNULL(c.[TotaleDigitale],0) as ContestazioniTotaleDigitale
5054
,ISNULL(c.[TotaleNotificheAnalogiche],0) as ContestazioniTotaleNotificheAnalogiche
@@ -61,12 +65,32 @@ nc.[internal_organization_id] as IdEnte
6165
FROM [pfd].[NotificheCount] as nc
6266
left outer join pfd.Enti as e
6367
ON e.InternalIstitutionId = nc.internal_organization_id
68+
left outer join pfd.Contratti as cc
69+
ON cc.internalistitutionid = e.InternalIstitutionId
6470
left outer join
6571
(SELECT
72+
rt.[internal_organization_id]
73+
,rt.[contract_id]
74+
,rt.[year]
75+
,rt.[month]
76+
,rt.[TipologiaFattura]
77+
,rt.[TotaleAnalogico]
78+
,rt.[TotaleDigitale]
79+
,rt.[TotaleNotificheAnalogiche]
80+
,rt.[TotaleNotificheDigitali]
81+
,rt.[Totale]
82+
,rt.[AsseverazioneTotaleAnalogico]
83+
,rt.[AsseverazioneTotaleDigitale]
84+
,rt.[AsseverazioneTotaleNotificheAnalogiche]
85+
,rt.[AsseverazioneTotaleNotificheDigitali]
86+
,rt.[AsseverazioneTotale]
87+
FROM (
88+
SELECT
6689
[internal_organization_id]
6790
,[contract_id]
6891
,[year]
69-
,[month]
92+
,[month]
93+
,[TipologiaFattura]
7094
,SUM(ISNULL([TotaleAnalogico],0)) as [TotaleAnalogico]
7195
,SUM(ISNULL([TotaleDigitale],0)) as [TotaleDigitale]
7296
,SUM(ISNULL([TotaleNotificheAnalogiche],0)) as [TotaleNotificheAnalogiche]
@@ -77,14 +101,27 @@ left outer join
77101
,SUM(ISNULL([AsseverazioneTotaleNotificheAnalogiche],0)) as [AsseverazioneTotaleNotificheAnalogiche]
78102
,SUM(ISNULL([AsseverazioneTotaleNotificheDigitali],0)) as [AsseverazioneTotaleNotificheDigitali]
79103
,SUM(ISNULL([AsseverazioneTotale],0)) as [AsseverazioneTotale]
80-
from pfd.RelTestata
81-
group by [internal_organization_id],[contract_id],[year], [month]) r
104+
, ROW_NUMBER() OVER (PARTITION BY internal_organization_id, contract_id, year, month
105+
ORDER BY
106+
(CASE
107+
WHEN TipologiaFattura = 'PRIMO SALDO' THEN 'A'
108+
WHEN TipologiaFattura = 'SECONDO SALDO' THEN 'B'
109+
WHEN TipologiaFattura = 'VAR. SEMESTRALE' THEN 'C'
110+
ELSE 'Z'
111+
END) DESC
112+
) AS RowNum
113+
FROM pfd.RelTestata
114+
GROUP BY [internal_organization_id],[contract_id],[year], [month], [TipologiaFattura]
115+
) rt
116+
WHERE rt.RowNum = 1
117+
) r
82118
ON r.internal_organization_id = nc.internal_organization_id AND r.contract_id = nc.contract_id and r.year = nc.year and r.month = nc.month
83119
left outer join
84120
(SELECT cr.internal_organization_id
85121
,cr.contract_id
86122
,cr.year
87123
,cr.month
124+
,cr.TipologiaFattura
88125
,ISNULL(cr.[TotaleAnalogico],0) as [TotaleAnalogico]
89126
,ISNULL(cr.[TotaleDigitale],0) as [TotaleDigitale]
90127
,ISNULL(cr.[TotaleNotificheAnalogiche],0) as [TotaleNotificheAnalogiche]
@@ -107,67 +144,74 @@ left outer join
107144
,[TipologiaFattura]
108145
, ROW_NUMBER() OVER (PARTITION BY internal_organization_id, contract_id,year,month ORDER BY
109146
(CASE WHEN TipologiaFattura = 'PRIMO SALDO' THEN 'A'
110-
WHEN TipologiaFattura = 'SECONDO SALDO' THEN 'B'
147+
WHEN TipologiaFattura = 'SECONDO SALDO' THEN 'B'
148+
WHEN TipologiaFattura = 'VAR. SEMESTRALE' THEN 'C'
149+
ELSE 'Z'
111150
END) DESC) AS RowNum
112151
FROM [pfd].ContestazioniStorico
113152
) as cr
114153
WHERE RowNum = 1) c
115-
ON c.internal_organization_id = r.internal_organization_id and c.contract_id = r.contract_id and c.year = r.year and c.month = r.month
154+
ON c.internal_organization_id = nc.internal_organization_id
155+
and c.contract_id = nc.contract_id
156+
and c.year = nc.year
157+
and c.month = nc.month
116158
";
117159
private static string _sql = @"
118160
SELECT
119-
nc.[internal_organization_id] as IdEnte
120-
,e.description as RagioneSociale
121-
,nc.[contract_id] as IdContratto
122-
,r.TipologiaFattura as TipologiaFattura
123-
,nc.[year] as Anno
124-
,nc.[month] as Mese
125-
,ISNULL(c.[TotaleAnalogico],0) as ContestazioniTotaleAnalogico
126-
,ISNULL(c.[TotaleDigitale],0) as ContestazioniTotaleDigitale
127-
,ISNULL(c.[TotaleNotificheAnalogiche],0) as ContestazioniTotaleNotificheAnalogiche
128-
,ISNULL(c.[TotaleNotificheDigitali],0) as ContestazioniTotaleNotificheDigitali
129-
,ISNULL(c.[Totale],0) as ContestazioniTotale
130-
,ISNULL(c.[TotaleNotificheAnalogiche],0) + ISNULL(c.[TotaleNotificheDigitali],0) as ContestazioniNotificheTotale
131-
,ISNULL(r.[TotaleAnalogico],0) as RelTotaleAnalogico
132-
,ISNULL(r.[TotaleDigitale],0) as RelTotaleDigitale
133-
,ISNULL(r.[TotaleNotificheAnalogiche],0) as RelTotaleNotificheAnalogiche
134-
,ISNULL(r.[TotaleNotificheDigitali],0) as RelTotaleNotificheDigitali
135-
,ISNULL(r.[Totale],0) as RelTotale
136-
,ISNULL(r.[TotaleNotificheAnalogiche],0) + ISNULL(r.[TotaleNotificheDigitali],0) as RelTotaleNotifiche
137-
,ISNULL([AsseverazioneTotaleAnalogico],0) as RelAsseTotaleAnalogico
138-
,ISNULL([AsseverazioneTotaleDigitale],0) as RelAsseTotaleDigitale
139-
,ISNULL([AsseverazioneTotaleNotificheAnalogiche],0) as RelAsseTotaleNotificheAnalogiche
140-
,ISNULL([AsseverazioneTotaleNotificheDigitali],0) as RelAsseTotaleNotificheDigitali
141-
,ISNULL([AsseverazioneTotaleNotificheAnalogiche],0) + ISNULL([AsseverazioneTotaleNotificheDigitali],0) as RelAsseTotaleNotifiche
142-
,ISNULL([AsseverazioneTotale],0) as RelAsseTotale
143-
,nc.[TotaleAnalogico] as NotificheTotaleAnalogico
144-
,nc.[TotaleDigitale] as NotificheTotaleDigitale
145-
,nc.[TotaleNotificheAnalogiche] as NotificheTotaleNotificheAnalogiche
146-
,nc.[TotaleNotificheDigitali] as NotificheTotaleNotificheDigitali
147-
,nc.[Totale] as NotificheTotale
148-
,nc.[TotaleNotificheAnalogiche] + nc.[TotaleNotificheDigitali] as NotificheTotaleNotifiche
149-
,nc.[TotaleAnalogico] - ISNULL(c.[TotaleAnalogico],0) - ISNULL(r.[TotaleAnalogico],0) - ISNULL(r.[AsseverazioneTotaleAnalogico],0) as DiffTotaleAnalogico
150-
,nc.[TotaleDigitale] - ISNULL(c.[TotaleDigitale],0) - ISNULL(r.[TotaleDigitale],0)- ISNULL(r.[AsseverazioneTotaleDigitale],0) as DiffTotaleDigitale
151-
,nc.[TotaleNotificheAnalogiche] - ISNULL(c.[TotaleNotificheAnalogiche],0) - ISNULL(r.[TotaleNotificheAnalogiche],0) - ISNULL(r.[AsseverazioneTotaleNotificheAnalogiche],0) as DiffTotaleNotificheAnalogiche
152-
,nc.[TotaleNotificheDigitali] - ISNULL(c.[TotaleNotificheDigitali],0) - ISNULL(r.[TotaleNotificheDigitali],0) - ISNULL(r.[AsseverazioneTotaleNotificheDigitali],0) as DiffTotaleNotificheDigitali
153-
,nc.[Totale] - ISNULL(c.[Totale],0) - ISNULL(r.[Totale],0)- ISNULL(r.[AsseverazioneTotale],0) as DiffTotale
154-
,nc.TotaleNotificheDigitali + nc.TotaleNotificheAnalogiche - ISNULL(c.TotaleNotificheDigitali,0)- ISNULL(c.TotaleNotificheAnalogiche,0) - ISNULL(r.TotaleNotificheDigitali,0) - ISNULL(r.TotaleNotificheAnalogiche,0) - ISNULL(r.AsseverazioneTotaleNotificheAnalogiche,0) - ISNULL(r.AsseverazioneTotaleNotificheAnalogiche,0) as DiffTotaleNotificheZero
161+
nc.[internal_organization_id] as IdEnte
162+
,e.description as RagioneSociale
163+
,nc.[contract_id] as IdContratto
164+
,r.TipologiaFattura as TipologiaFattura
165+
,nc.[year] as Anno
166+
,nc.[month] as Mese
167+
,ISNULL(c.[TotaleAnalogico],0) as ContestazioniTotaleAnalogico
168+
,ISNULL(c.[TotaleDigitale],0) as ContestazioniTotaleDigitale
169+
,ISNULL(c.[TotaleNotificheAnalogiche],0) as ContestazioniTotaleNotificheAnalogiche
170+
,ISNULL(c.[TotaleNotificheDigitali],0) as ContestazioniTotaleNotificheDigitali
171+
,ISNULL(c.[Totale],0) as ContestazioniTotale
172+
,ISNULL(c.[TotaleNotificheAnalogiche],0) + ISNULL(c.[TotaleNotificheDigitali],0) as ContestazioniNotificheTotale
173+
,ISNULL(r.[TotaleAnalogico],0) as RelTotaleAnalogico
174+
,ISNULL(r.[TotaleDigitale],0) as RelTotaleDigitale
175+
,ISNULL(r.[TotaleNotificheAnalogiche],0) as RelTotaleNotificheAnalogiche
176+
,ISNULL(r.[TotaleNotificheDigitali],0) as RelTotaleNotificheDigitali
177+
,ISNULL(r.[Totale],0) as RelTotale
178+
,ISNULL(r.[TotaleNotificheAnalogiche],0) + ISNULL(r.[TotaleNotificheDigitali],0) as RelTotaleNotifiche
179+
,ISNULL([AsseverazioneTotaleAnalogico],0) as RelAsseTotaleAnalogico
180+
,ISNULL([AsseverazioneTotaleDigitale],0) as RelAsseTotaleDigitale
181+
,ISNULL([AsseverazioneTotaleNotificheAnalogiche],0) as RelAsseTotaleNotificheAnalogiche
182+
,ISNULL([AsseverazioneTotaleNotificheDigitali],0) as RelAsseTotaleNotificheDigitali
183+
,ISNULL([AsseverazioneTotaleNotificheAnalogiche],0) + ISNULL([AsseverazioneTotaleNotificheDigitali],0) as RelAsseTotaleNotifiche
184+
,ISNULL([AsseverazioneTotale],0) as RelAsseTotale
185+
,nc.[TotaleAnalogico] as NotificheTotaleAnalogico
186+
,nc.[TotaleDigitale] as NotificheTotaleDigitale
187+
,nc.[TotaleNotificheAnalogiche] as NotificheTotaleNotificheAnalogiche
188+
,nc.[TotaleNotificheDigitali] as NotificheTotaleNotificheDigitali
189+
,nc.[Totale] as NotificheTotale
190+
,nc.[TotaleNotificheAnalogiche] + nc.[TotaleNotificheDigitali] as NotificheTotaleNotifiche
191+
,nc.[TotaleAnalogico] - ISNULL(c.[TotaleAnalogico],0) - ISNULL(r.[TotaleAnalogico],0) - ISNULL(r.[AsseverazioneTotaleAnalogico],0) as DiffTotaleAnalogico
192+
,nc.[TotaleDigitale] - ISNULL(c.[TotaleDigitale],0) - ISNULL(r.[TotaleDigitale],0)- ISNULL(r.[AsseverazioneTotaleDigitale],0) as DiffTotaleDigitale
193+
,nc.[TotaleNotificheAnalogiche] - ISNULL(c.[TotaleNotificheAnalogiche],0) - ISNULL(r.[TotaleNotificheAnalogiche],0) - ISNULL(r.[AsseverazioneTotaleNotificheAnalogiche],0) as DiffTotaleNotificheAnalogiche
194+
,nc.[TotaleNotificheDigitali] - ISNULL(c.[TotaleNotificheDigitali],0) - ISNULL(r.[TotaleNotificheDigitali],0) - ISNULL(r.[AsseverazioneTotaleNotificheDigitali],0) as DiffTotaleNotificheDigitali
195+
,nc.[Totale] - ISNULL(c.[Totale],0) - ISNULL(r.[Totale],0)- ISNULL(r.[AsseverazioneTotale],0) as DiffTotale
196+
,nc.TotaleNotificheDigitali + nc.TotaleNotificheAnalogiche - ISNULL(c.TotaleNotificheDigitali,0)- ISNULL(c.TotaleNotificheAnalogiche,0) - ISNULL(r.TotaleNotificheDigitali,0) - ISNULL(r.TotaleNotificheAnalogiche,0) - ISNULL(r.AsseverazioneTotaleNotificheAnalogiche,0) - ISNULL(r.AsseverazioneTotaleNotificheAnalogiche,0) as DiffTotaleNotificheZero
155197
156-
FROM [pfd].[NotificheCount] as nc
157-
left outer join pfd.Enti as e
158-
ON e.InternalIstitutionId = nc.internal_organization_id
159-
left outer join pfd.RelTestata as r
160-
ON r.internal_organization_id = nc.internal_organization_id
161-
AND r.contract_id = nc.contract_id
162-
AND r.year= nc.year
163-
AND r.month = nc.month
164-
AND r.TipologiaFattura=@TipologiaFattura
165-
left outer join pfd.ContestazioniStorico as c
166-
ON c.internal_organization_id = nc.internal_organization_id
167-
AND c.contract_id = nc.contract_id
168-
AND c.year= nc.year
169-
AND c.month = nc.month
170-
AND c.TipologiaFattura=@TipologiaFattura
198+
FROM [pfd].[NotificheCount] as nc
199+
INNER JOIN pfd.RelTestata as r
200+
ON r.internal_organization_id = nc.internal_organization_id
201+
AND r.contract_id = nc.contract_id
202+
AND r.year = nc.year
203+
AND r.month = nc.month
204+
AND (@TipologiaFattura IS NULL OR r.TipologiaFattura = @TipologiaFattura)
205+
LEFT OUTER JOIN pfd.Enti as e
206+
ON e.InternalIstitutionId = nc.internal_organization_id
207+
LEFT OUTER JOIN pfd.Contratti as cc
208+
ON cc.internalistitutionid = e.InternalIstitutionId
209+
LEFT OUTER JOIN pfd.ContestazioniStorico as c
210+
ON c.internal_organization_id = nc.internal_organization_id
211+
AND c.contract_id = nc.contract_id
212+
AND c.year = nc.year
213+
AND c.month = nc.month
214+
AND (@TipologiaFattura IS NULL OR c.TipologiaFattura = @TipologiaFattura)
171215
";
172216

173217
private static string _offSet = " OFFSET (@page-1)*@size ROWS FETCH NEXT @size ROWS ONLY";

src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/SEND/DatiRel/Queries/Persistence/Builder/RelTestataSQLBuilder.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ SELECT Count(internal_organization_id)
5151
FROM [pfd].[RelTestata] t
5252
inner join pfd.Enti e
5353
on e.InternalIstitutionId =t.internal_organization_id
54+
left outer join pfd.Contratti c
55+
on c.internalistitutionid = e.InternalIstitutionId
5456
";
5557
private static string _sql = @"
5658
SELECT [internal_organization_id] as IdEnte
5759
,[description] as RagioneSociale
5860
,[contract_id] as IdContratto
5961
,[TipologiaFattura]
60-
,[year] as anno
61-
,[month] as mese
62+
,t.[year] as anno
63+
,t.[month] as mese
6264
,[TotaleAnalogico]
6365
,[TotaleDigitale]
6466
,[TotaleNotificheAnalogiche]
@@ -80,7 +82,9 @@ SELECT [internal_organization_id] as IdEnte
8082
,[FlagConguaglio]
8183
FROM [pfd].[RelTestata] t
8284
inner join pfd.Enti e
83-
on e.InternalIstitutionId =t.internal_organization_id
85+
on e.InternalIstitutionId =internal_organization_id
86+
left outer join pfd.Contratti c
87+
on c.internalistitutionid = e.InternalIstitutionId
8488
";
8589

8690
private static string _sqlDettaglio = @"
@@ -125,9 +129,14 @@ public static string OffSet()
125129
return _offSet;
126130
}
127131

132+
public static string OrderByPagoPA()
133+
{
134+
return " ORDER BY t.year DESC, t.month, [Totale] DESC";
135+
}
136+
128137
public static string OrderBy()
129138
{
130-
return " ORDER BY year DESC, month, [Totale] DESC";
139+
return " ORDER BY t.year DESC, t.month, [Totale] DESC";
131140
}
132141

133142
public static string SelectAll()

src/Infrastructure/PortaleFatture.BE.Infrastructure/Common/SEND/DatiRel/Queries/Persistence/RelTestataQueryGetByIdEntePersistence.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Data;
22
using PortaleFatture.BE.Infrastructure.Common.Persistence;
33
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Dto;
4-
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries;
54
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence.Builder;
65

76
namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiRel.Queries.Persistence;
@@ -35,9 +34,9 @@ public class RelTestataQueryGetByIdEntePersistence(RelTestataQueryGetByIdEnte co
3534
where += " AND caricata=@caricata";
3635

3736
if (anno.HasValue)
38-
where += " AND year=@anno";
37+
where += " AND t.year=@anno";
3938
if (mese.HasValue)
40-
where += " AND month=@mese";
39+
where += " AND t.month=@mese";
4140
if (!string.IsNullOrEmpty(idContratto))
4241
where += " AND contract_id=@IdContratto";
4342

0 commit comments

Comments
 (0)